Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.12
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 12(raebu 4:23): # $Id: domainprefs.pm,v 1.160.6.118.2.11 2023/01/23 03:28:37 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: ###############################################################
30: ##############################################################
31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.30 raeburn 107: (official, unofficial, community, and textbook). In each case the radio buttons
108: allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.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.113 raeburn 177: use Net::CIDR;
1.1 raeburn 178:
1.155 raeburn 179: my $registered_cleanup;
180: my $modified_urls;
181:
1.1 raeburn 182: sub handler {
183: my $r=shift;
184: if ($r->header_only) {
185: &Apache::loncommon::content_type($r,'text/html');
186: $r->send_http_header;
187: return OK;
188: }
189:
1.91 raeburn 190: my $context = 'domain';
1.1 raeburn 191: my $dom = $env{'request.role.domain'};
1.5 albertel 192: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 193: if (&Apache::lonnet::allowed('mau',$dom)) {
194: &Apache::loncommon::content_type($r,'text/html');
195: $r->send_http_header;
196: } else {
197: $env{'user.error.msg'}=
198: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
199: return HTTP_NOT_ACCEPTABLE;
200: }
1.155 raeburn 201:
202: $registered_cleanup=0;
203: @{$modified_urls}=();
204:
1.1 raeburn 205: &Apache::lonhtmlcommon::clear_breadcrumbs();
206: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 207: ['phase','actions']);
1.30 raeburn 208: my $phase = 'pickactions';
1.3 raeburn 209: if ( exists($env{'form.phase'}) ) {
210: $phase = $env{'form.phase'};
211: }
1.150 raeburn 212: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 213: my %domconfig =
1.6 raeburn 214: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 215: 'quotas','autoenroll','autoupdate','autocreate',
216: 'directorysrch','usercreation','usermodification',
217: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 218: 'serverstatuses','requestcourses','helpsettings',
219: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113 raeburn 220: 'requestauthor','selfenrollment','inststatus',
1.160.6.118.2 5(raebur 221:2): 'passwords','ltitools','ltisec','wafproxy','ipaccess'],$dom);
6(raebur 222:2): my %encconfig =
223:2): &Apache::lonnet::get_dom('encconfig',['ltitools','linkprot'],$dom,undef,1);
1(raebur 224:1): if (ref($domconfig{'ltitools'}) eq 'HASH') {
225:1): if (ref($encconfig{'ltitools'}) eq 'HASH') {
226:1): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
227:1): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
228:1): foreach my $item ('key','secret') {
229:1): $domconfig{'ltitools'}{$id}{$item} = $encconfig{'ltitools'}{$id}{$item};
230:1): }
231:1): }
232:1): }
233:1): }
234:1): }
5(raebur 235:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
236:2): if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
237:2): if (ref($encconfig{'linkprot'}) eq 'HASH') {
238:2): foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
239:2): unless ($id =~ /^\d+$/) {
240:2): delete($domconfig{'ltisec'}{'linkprot'}{$id});
241:2): }
242:2): if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
243:2): (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
244:2): foreach my $item ('key','secret') {
245:2): $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
246:2): }
247:2): }
248:2): }
249:2): }
250:2): }
251:2): }
1.160.6.113 raeburn 252: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
253: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
254: 'contacts','usercreation','selfcreation','usermodification',
255: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 256: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.118.2 5(raebur 257:2): 'ltitools','selfenrollment','usersessions','lti');
1.160.6.7 raeburn 258: my %existing;
259: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
260: %existing = %{$domconfig{'loadbalancing'}};
261: }
262: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 263: push(@prefs_order,'loadbalancing');
264: }
1.30 raeburn 265: my %prefs = (
266: 'rolecolors' =>
267: { text => 'Default color schemes',
1.67 raeburn 268: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 269: header => [{col1 => 'Student Settings',
270: col2 => '',},
271: {col1 => 'Coordinator Settings',
272: col2 => '',},
273: {col1 => 'Author Settings',
274: col2 => '',},
275: {col1 => 'Administrator Settings',
276: col2 => '',}],
1.160.6.37 raeburn 277: print => \&print_rolecolors,
278: modify => \&modify_rolecolors,
1.30 raeburn 279: },
1.110 raeburn 280: 'login' =>
1.30 raeburn 281: { text => 'Log-in page options',
1.67 raeburn 282: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 283: header => [{col1 => 'Log-in Page Items',
284: col2 => '',},
285: {col1 => 'Log-in Help',
1.160.6.56 raeburn 286: col2 => 'Value'},
287: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 288: col2 => 'Value'},
289: {col1 => 'SSO',
290: col2 => 'Dual login: SSO and non-SSO options'},
291: ],
1.160.6.37 raeburn 292: print => \&print_login,
293: modify => \&modify_login,
1.30 raeburn 294: },
1.43 raeburn 295: 'defaults' =>
1.160.6.40 raeburn 296: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 297: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 298: header => [{col1 => 'Setting',
1.160.6.40 raeburn 299: col2 => 'Value'},
300: {col1 => 'Institutional user types',
1.160.6.118.2 8(raebur 301:2): col2 => 'Name displayed'},
302:2): {col1 => 'Mapping for missing usernames via standard log-in',
303:2): col2 => 'Rules in use'}],
1.160.6.37 raeburn 304: print => \&print_defaults,
305: modify => \&modify_defaults,
1.43 raeburn 306: },
1.160.6.113 raeburn 307: 'wafproxy' =>
308: { text => 'Web Application Firewall/Reverse Proxy',
309: help => 'Domain_Configuration_WAF_Proxy',
310: header => [{col1 => 'Domain(s)',
311: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
312: },
313: {col1 => 'Domain(s)',
314: col2 => 'WAF Configuration',}],
315: print => \&print_wafproxy,
316: modify => \&modify_wafproxy,
317: },
1.160.6.98 raeburn 318: 'passwords' =>
319: { text => 'Passwords (Internal authentication)',
320: help => 'Domain_Configuration_Passwords',
321: header => [{col1 => 'Resetting Forgotten Password',
322: col2 => 'Settings'},
323: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
324: col2 => 'Settings'},
325: {col1 => 'Rules for LON-CAPA Passwords',
326: col2 => 'Settings'},
327: {col1 => 'Course Owner Changing Student Passwords',
328: col2 => 'Settings'}],
329: print => \&print_passwords,
330: modify => \&modify_passwords,
331: },
1.30 raeburn 332: 'quotas' =>
1.160.6.118.2 10(raebu 333:22): { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 334: help => 'Domain_Configuration_Quotas',
1.77 raeburn 335: header => [{col1 => 'User affiliation',
1.72 raeburn 336: col2 => 'Available tools',
1.160.6.28 raeburn 337: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 338: print => \&print_quotas,
339: modify => \&modify_quotas,
1.30 raeburn 340: },
341: 'autoenroll' =>
342: { text => 'Auto-enrollment settings',
1.67 raeburn 343: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 344: header => [{col1 => 'Configuration setting',
345: col2 => 'Value(s)'}],
1.160.6.37 raeburn 346: print => \&print_autoenroll,
347: modify => \&modify_autoenroll,
1.30 raeburn 348: },
349: 'autoupdate' =>
350: { text => 'Auto-update settings',
1.67 raeburn 351: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 352: header => [{col1 => 'Setting',
353: col2 => 'Value',},
1.131 raeburn 354: {col1 => 'Setting',
355: col2 => 'Affiliation'},
1.43 raeburn 356: {col1 => 'User population',
1.160.6.35 raeburn 357: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 358: print => \&print_autoupdate,
359: modify => \&modify_autoupdate,
1.30 raeburn 360: },
1.125 raeburn 361: 'autocreate' =>
362: { text => 'Auto-course creation settings',
363: help => 'Domain_Configuration_Auto_Creation',
364: header => [{col1 => 'Configuration Setting',
365: col2 => 'Value',}],
1.160.6.37 raeburn 366: print => \&print_autocreate,
367: modify => \&modify_autocreate,
1.125 raeburn 368: },
1.30 raeburn 369: 'directorysrch' =>
1.160.6.72 raeburn 370: { text => 'Directory searches',
1.67 raeburn 371: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 372: header => [{col1 => 'Institutional Directory Setting',
373: col2 => 'Value',},
374: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 375: col2 => 'Value',}],
1.160.6.37 raeburn 376: print => \&print_directorysrch,
377: modify => \&modify_directorysrch,
1.30 raeburn 378: },
379: 'contacts' =>
1.160.6.78 raeburn 380: { text => 'E-mail addresses and helpform',
1.67 raeburn 381: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 382: header => [{col1 => 'Default e-mail addresses',
383: col2 => 'Value',},
384: {col1 => 'Recipient(s) for notifications',
385: col2 => 'Value',},
1.160.6.107 raeburn 386: {col1 => 'Nightly status check e-mail',
387: col2 => 'Settings',},
1.160.6.78 raeburn 388: {col1 => 'Ask helpdesk form settings',
389: col2 => 'Value',},],
1.160.6.37 raeburn 390: print => \&print_contacts,
391: modify => \&modify_contacts,
1.30 raeburn 392: },
393: 'usercreation' =>
394: { text => 'User creation',
1.67 raeburn 395: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 396: header => [{col1 => 'Format rule type',
397: col2 => 'Format rules in force'},
1.34 raeburn 398: {col1 => 'User account creation',
399: col2 => 'Usernames which may be created',},
1.30 raeburn 400: {col1 => 'Context',
1.43 raeburn 401: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 402: print => \&print_usercreation,
403: modify => \&modify_usercreation,
1.30 raeburn 404: },
1.160.6.34 raeburn 405: 'selfcreation' =>
406: { text => 'Users self-creating accounts',
407: help => 'Domain_Configuration_Self_Creation',
408: header => [{col1 => 'Self-creation with institutional username',
409: col2 => 'Enabled?'},
410: {col1 => 'Institutional user type (login/SSO self-creation)',
411: col2 => 'Information user can enter'},
1.160.6.93 raeburn 412: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 413: col2 => 'Settings'}],
1.160.6.37 raeburn 414: print => \&print_selfcreation,
415: modify => \&modify_selfcreation,
1.160.6.34 raeburn 416: },
1.69 raeburn 417: 'usermodification' =>
1.33 raeburn 418: { text => 'User modification',
1.67 raeburn 419: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 420: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 421: col2 => 'User information updatable in author context'},
1.33 raeburn 422: {col1 => 'Target user has role',
1.160.6.35 raeburn 423: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 424: print => \&print_usermodification,
425: modify => \&modify_usermodification,
1.33 raeburn 426: },
1.69 raeburn 427: 'scantron' =>
1.160.6.97 raeburn 428: { text => 'Bubblesheet format',
1.67 raeburn 429: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 430: header => [ {col1 => 'Bubblesheet format file',
431: col2 => ''},
432: {col1 => 'Bubblesheet data upload formats',
433: col2 => 'Settings'}],
1.160.6.37 raeburn 434: print => \&print_scantron,
435: modify => \&modify_scantron,
1.46 raeburn 436: },
1.86 raeburn 437: 'requestcourses' =>
438: {text => 'Request creation of courses',
439: help => 'Domain_Configuration_Request_Courses',
440: header => [{col1 => 'User affiliation',
1.102 raeburn 441: col2 => 'Availability/Processing of requests',},
442: {col1 => 'Setting',
1.160.6.30 raeburn 443: col2 => 'Value'},
444: {col1 => 'Available textbooks',
1.160.6.39 raeburn 445: col2 => ''},
1.160.6.46 raeburn 446: {col1 => 'Available templates',
447: col2 => ''},
1.160.6.39 raeburn 448: {col1 => 'Validation (not official courses)',
449: col2 => 'Value'},],
1.160.6.37 raeburn 450: print => \&print_quotas,
451: modify => \&modify_quotas,
1.86 raeburn 452: },
1.160.6.5 raeburn 453: 'requestauthor' =>
1.160.6.34 raeburn 454: {text => 'Request Authoring Space',
1.160.6.5 raeburn 455: help => 'Domain_Configuration_Request_Author',
456: header => [{col1 => 'User affiliation',
457: col2 => 'Availability/Processing of requests',},
458: {col1 => 'Setting',
459: col2 => 'Value'}],
1.160.6.37 raeburn 460: print => \&print_quotas,
461: modify => \&modify_quotas,
1.160.6.5 raeburn 462: },
1.69 raeburn 463: 'coursecategories' =>
1.120 raeburn 464: { text => 'Cataloging of courses/communities',
1.67 raeburn 465: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 466: header => [{col1 => 'Catalog type/availability',
467: col2 => '',},
468: {col1 => 'Category settings for standard catalog',
1.57 raeburn 469: col2 => '',},
470: {col1 => 'Categories',
471: col2 => '',
472: }],
1.160.6.37 raeburn 473: print => \&print_coursecategories,
474: modify => \&modify_coursecategories,
1.69 raeburn 475: },
476: 'serverstatuses' =>
1.77 raeburn 477: {text => 'Access to server status pages',
1.69 raeburn 478: help => 'Domain_Configuration_Server_Status',
479: header => [{col1 => 'Status Page',
480: col2 => 'Other named users',
481: col3 => 'Specific IPs',
482: }],
1.160.6.37 raeburn 483: print => \&print_serverstatuses,
484: modify => \&modify_serverstatuses,
1.69 raeburn 485: },
1.160.6.73 raeburn 486: 'helpsettings' =>
487: {text => 'Support settings',
488: help => 'Domain_Configuration_Help_Settings',
489: header => [{col1 => 'Help Page Settings (logged-in users)',
490: col2 => 'Value'},
491: {col1 => 'Helpdesk Roles',
492: col2 => 'Settings'},],
493: print => \&print_helpsettings,
494: modify => \&modify_helpsettings,
495: },
1.160.6.39 raeburn 496: 'coursedefaults' =>
1.160.6.16 raeburn 497: {text => 'Course/Community defaults',
498: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 499: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
500: col2 => 'Value',},
501: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 502: col2 => 'Value',},],
1.160.6.37 raeburn 503: print => \&print_coursedefaults,
504: modify => \&modify_coursedefaults,
505: },
1.160.6.39 raeburn 506: 'selfenrollment' =>
1.160.6.37 raeburn 507: {text => 'Self-enrollment in Course/Community',
508: help => 'Domain_Configuration_Selfenrollment',
509: header => [{col1 => 'Configuration Rights',
510: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
511: {col1 => 'Defaults',
512: col2 => 'Value'},
513: {col1 => 'Self-enrollment validation (optional)',
514: col2 => 'Value'},],
515: print => \&print_selfenrollment,
516: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 517: },
1.141 raeburn 518: 'usersessions' =>
1.145 raeburn 519: {text => 'User session hosting/offloading',
1.137 raeburn 520: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 521: header => [{col1 => 'Domain server',
522: col2 => 'Servers to offload sessions to when busy'},
523: {col1 => 'Hosting of users from other domains',
1.137 raeburn 524: col2 => 'Rules'},
525: {col1 => "Hosting domain's own users elsewhere",
526: col2 => 'Rules'}],
1.160.6.37 raeburn 527: print => \&print_usersessions,
528: modify => \&modify_usersessions,
1.137 raeburn 529: },
1.160.6.78 raeburn 530: 'loadbalancing' =>
1.160.6.7 raeburn 531: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 532: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 533: header => [{col1 => 'Balancers',
1.150 raeburn 534: col2 => 'Default destinations',
1.160.6.13 raeburn 535: col3 => 'User affiliation',
1.150 raeburn 536: col4 => 'Overrides'},
537: ],
1.160.6.37 raeburn 538: print => \&print_loadbalancing,
539: modify => \&modify_loadbalancing,
1.150 raeburn 540: },
1.160.6.118.2 1(raebur 541:1): 'ltitools' =>
542:1): {text => 'External Tools (LTI)',
543:1): help => 'Domain_Configuration_LTI_Tools',
544:1): header => [{col1 => 'Setting',
545:1): col2 => 'Value',}],
546:1): print => \&print_ltitools,
547:1): modify => \&modify_ltitools,
548:1): },
5(raebur 549:2): 'lti' =>
550:2): {text => 'LTI Link Protection and LTI Consumers',
551:2): help => 'Domain_Configuration_LTI_Provider',
552:2): header => [{col1 => 'Encryption of shared secrets',
553:2): col2 => 'Settings'},
554:2): {col1 => 'Rules for shared secrets',
555:2): col2 => 'Settings'},
556:2): {col1 => 'Link Protectors',
557:2): col2 => 'Settings'},],
558:2): print => \&print_lti,
559:2): modify => \&modify_lti,
560:2): },
1.160.6.113 raeburn 561: 'ipaccess' =>
562: {text => 'IP-based access control',
563: help => 'Domain_Configuration_IP_Access',
564: header => [{col1 => 'Setting',
565: col2 => 'Value'},],
566: print => \&print_ipaccess,
567: modify => \&modify_ipaccess,
568: },
1.3 raeburn 569: );
1.110 raeburn 570: if (keys(%servers) > 1) {
571: $prefs{'login'} = { text => 'Log-in page options',
572: help => 'Domain_Configuration_Login_Page',
573: header => [{col1 => 'Log-in Service',
574: col2 => 'Server Setting',},
575: {col1 => 'Log-in Page Items',
1.160.6.118.2 5(raebur 576:2): col2 => 'Settings'},
1.160.6.5 raeburn 577: {col1 => 'Log-in Help',
1.160.6.56 raeburn 578: col2 => 'Value'},
579: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 580: col2 => 'Value'},
581: {col1 => 'SSO',
582: col2 => 'Dual login: SSO and non-SSO options'},
583: ],
1.160.6.37 raeburn 584: print => \&print_login,
585: modify => \&modify_login,
1.110 raeburn 586: };
587: }
1.160.6.13 raeburn 588:
1.6 raeburn 589: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 590: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 591: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 592: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 593: text=>"Settings to display/modify"});
1.9 raeburn 594: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 595:
1.3 raeburn 596: if ($phase eq 'process') {
1.160.6.27 raeburn 597: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
598: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 599: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 600: $r->rflush();
1.160.6.27 raeburn 601: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 602: }
1.30 raeburn 603: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 604: my $js = &recaptcha_js().
1.160.6.40 raeburn 605: &toggle_display_js();
1.160.6.7 raeburn 606: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 607: my ($othertitle,$usertypes,$types) =
608: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 609: $js .= &lonbalance_targets_js($dom,$types,\%servers,
610: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 611: &new_spares_js().
612: &common_domprefs_js().
613: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 614: }
1.160.6.30 raeburn 615: if (grep(/^requestcourses$/,@actions)) {
616: my $javascript_validations;
617: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
618: $js .= <<END;
619: <script type="text/javascript">
620: $javascript_validations
621: </script>
622: $coursebrowserjs
623: END
1.160.6.113 raeburn 624: } elsif (grep(/^ipaccess$/,@actions)) {
625: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 626: }
1.160.6.93 raeburn 627: if (grep(/^selfcreation$/,@actions)) {
628: $js .= &selfcreate_javascript();
629: }
1.160.6.78 raeburn 630: if (grep(/^contacts$/,@actions)) {
631: $js .= &contacts_javascript();
632: }
1.160.6.97 raeburn 633: if (grep(/^scantron$/,@actions)) {
634: $js .= &scantron_javascript();
635: }
1.150 raeburn 636: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 637: } else {
1.160.6.11 raeburn 638: # check if domconfig user exists for the domain.
639: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 640: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 641: &config_check($dom,$confname,$servadm);
642: unless ($configuserok eq 'ok') {
643: &Apache::lonconfigsettings::print_header($r,$phase,$context);
644: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
645: $confname).
646: '<br />'
647: );
648: if ($switchserver) {
649: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
650: '<br />'.
651: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
652: '<br />'.
653: &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).
654: '<br />'.
655: &mt('To do that now, use the following link: [_1]',$switchserver)
656: );
657: } else {
658: $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.').
659: '<br />'.
660: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
661: );
662: }
663: $r->print(&Apache::loncommon::end_page());
664: return OK;
665: }
1.21 raeburn 666: if (keys(%domconfig) == 0) {
667: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 668: my @ids=&Apache::lonnet::current_machine_ids();
669: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 670: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 671: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 672: my $custom_img_count = 0;
673: foreach my $img (@loginimages) {
674: if ($designhash{$dom.'.login.'.$img} ne '') {
675: $custom_img_count ++;
676: }
677: }
678: foreach my $role (@roles) {
679: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
680: $custom_img_count ++;
681: }
682: }
683: if ($custom_img_count > 0) {
1.94 raeburn 684: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 685: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 686: $r->print(
687: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
688: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
689: &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 />'.
690: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
691: if ($switch_server) {
1.30 raeburn 692: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 693: }
1.91 raeburn 694: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 695: return OK;
696: }
697: }
698: }
1.91 raeburn 699: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 700: }
701: return OK;
702: }
703:
704: sub process_changes {
1.160.6.24 raeburn 705: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 706: my %domconfig;
707: if (ref($values) eq 'HASH') {
708: %domconfig = %{$values};
709: }
1.3 raeburn 710: my $output;
711: if ($action eq 'login') {
1.160.6.24 raeburn 712: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 713: } elsif ($action eq 'rolecolors') {
1.9 raeburn 714: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 715: $lastactref,%domconfig);
1.3 raeburn 716: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 717: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 718: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 719: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 720: } elsif ($action eq 'autoupdate') {
721: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 722: } elsif ($action eq 'autocreate') {
723: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 724: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 725: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 726: } elsif ($action eq 'usercreation') {
1.28 raeburn 727: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 728: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 729: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 730: } elsif ($action eq 'usermodification') {
731: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 732: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 733: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 734: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 735: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 736: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 737: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 738: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 739: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 740: } elsif ($action eq 'serverstatuses') {
741: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 742: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 743: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 744: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 745: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 746: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 747: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 748: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 749: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 750: } elsif ($action eq 'selfenrollment') {
751: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 752: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 753: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 754: } elsif ($action eq 'loadbalancing') {
755: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2 5(raebur 756:2): } elsif ($action eq 'lti') {
757:2): $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98 raeburn 758: } elsif ($action eq 'passwords') {
759: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.118.2 1(raebur 760:1): } elsif ($action eq 'ltitools') {
761:1): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.160.6.113 raeburn 762: } elsif ($action eq 'wafproxy') {
763: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
764: } elsif ($action eq 'ipaccess') {
765: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 766: }
767: return $output;
768: }
769:
770: sub print_config_box {
1.9 raeburn 771: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 772: my $rowtotal = 0;
1.49 raeburn 773: my $output;
774: if ($action eq 'coursecategories') {
775: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 776: } elsif ($action eq 'defaults') {
777: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 778: } elsif ($action eq 'passwords') {
1.160.6.118.2 5(raebur 779:2): $output = &passwords_javascript($action);
1.160.6.73 raeburn 780: } elsif ($action eq 'helpsettings') {
781: my (%privs,%levelscurrent);
782: my %full=();
783: my %levels=(
784: course => {},
785: domain => {},
786: system => {},
787: );
788: my $context = 'domain';
789: my $crstype = 'Course';
790: my $formname = 'display';
791: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
792: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
793: $output =
794: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
795: \@templateroles);
1.160.6.118.2 1(raebur 796:1): } elsif ($action eq 'ltitools') {
797:1): $output .= <itools_javascript($settings);
5(raebur 798:2): } elsif ($action eq 'lti') {
799:2): $output .= &passwords_javascript('secrets')."\n".
800:2): <i_javascript($dom,$settings);
1.160.6.113 raeburn 801: } elsif ($action eq 'wafproxy') {
802: $output .= &wafproxy_javascript($dom);
803: } elsif ($action eq 'autoupdate') {
804: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 805: } elsif ($action eq 'autoenroll') {
806: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 807: } elsif ($action eq 'login') {
808: $output .= &saml_javascript();
809: } elsif ($action eq 'ipaccess') {
810: $output .= &ipaccess_javascript($settings);
1.91 raeburn 811: }
1.160.6.40 raeburn 812: $output .=
1.30 raeburn 813: '<table class="LC_nested_outer">
1.3 raeburn 814: <tr>
1.160.6.113 raeburn 815: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 816: &mt($item->{text}).' '.
817: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
818: '</tr>';
1.30 raeburn 819: $rowtotal ++;
1.110 raeburn 820: my $numheaders = 1;
821: if (ref($item->{'header'}) eq 'ARRAY') {
822: $numheaders = scalar(@{$item->{'header'}});
823: }
824: if ($numheaders > 1) {
1.64 raeburn 825: my $colspan = '';
1.145 raeburn 826: my $rightcolspan = '';
1.160.6.104 raeburn 827: my $leftnobr = '';
1.160.6.42 raeburn 828: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 829: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 830: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 831: $colspan = ' colspan="2"';
832: }
1.145 raeburn 833: if ($action eq 'usersessions') {
834: $rightcolspan = ' colspan="3"';
835: }
1.160.6.104 raeburn 836: if ($action eq 'passwords') {
837: $leftnobr = ' LC_nobreak';
838: }
1.30 raeburn 839: $output .= '
1.3 raeburn 840: <tr>
841: <td>
842: <table class="LC_nested">
843: <tr class="LC_info_row">
1.160.6.104 raeburn 844: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 845: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 846: </tr>';
1.69 raeburn 847: $rowtotal ++;
1.160.6.37 raeburn 848: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 849: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 850: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2 5(raebur 851:2): ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') || ($action eq 'lti')) {
1.160.6.37 raeburn 852: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 853: } elsif ($action eq 'passwords') {
854: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 855: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 856: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 857: } elsif ($action eq 'scantron') {
858: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 859: } elsif ($action eq 'login') {
1.160.6.113 raeburn 860: if ($numheaders == 5) {
1.160.6.5 raeburn 861: $colspan = ' colspan="2"';
862: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
863: } else {
864: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
865: }
1.160.6.37 raeburn 866: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 867: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 868: } elsif ($action eq 'rolecolors') {
1.30 raeburn 869: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 870: }
1.30 raeburn 871: $output .= '
1.6 raeburn 872: </table>
873: </td>
874: </tr>
875: <tr>
876: <td>
877: <table class="LC_nested">
878: <tr class="LC_info_row">
1.160.6.37 raeburn 879: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 880: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 881: </tr>';
882: $rowtotal ++;
1.160.6.37 raeburn 883: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
884: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 885: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2 8(raebur 886:2): ($action eq 'contacts') || ($action eq 'passwords') ||
887:2): ($action eq 'defaults') || ($action eq 'lti')) {
1.160.6.42 raeburn 888: if ($action eq 'coursecategories') {
889: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
890: $colspan = ' colspan="2"';
1.160.6.98 raeburn 891: } elsif ($action eq 'passwords') {
892: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 893: } else {
894: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
895: }
896: $output .= '
1.63 raeburn 897: </table>
898: </td>
899: </tr>
900: <tr>
901: <td>
902: <table class="LC_nested">
903: <tr class="LC_info_row">
1.160.6.113 raeburn 904: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 905: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 906: </tr>'."\n";
907: if ($action eq 'coursecategories') {
908: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 909: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 910: if ($action eq 'passwords') {
911: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
912: } else {
913: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
914: }
915: $output .= '
1.160.6.98 raeburn 916: </tr>
917: </table>
918: </td>
919: </tr>
920: <tr>
921: <td>
922: <table class="LC_nested">
923: <tr class="LC_info_row">
1.160.6.113 raeburn 924: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 925: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 926: if ($action eq 'passwords') {
927: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
928: } else {
929: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
930: }
931: $output .= '
1.160.6.98 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>';
1.160.6.42 raeburn 936: } else {
937: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
938: }
1.63 raeburn 939: $rowtotal ++;
1.160.6.57 raeburn 940: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.118.2 8(raebur 941:2): ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
942:2): ($action eq 'wafproxy')) {
1.160.6.37 raeburn 943: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 944: } elsif ($action eq 'scantron') {
945: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 946: } elsif ($action eq 'login') {
1.160.6.113 raeburn 947: if ($numheaders == 5) {
1.160.6.5 raeburn 948: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
949: </table>
950: </td>
951: </tr>
952: <tr>
953: <td>
954: <table class="LC_nested">
955: <tr class="LC_info_row">
956: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 957: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 958: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
959: $rowtotal ++;
960: } else {
961: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
962: }
1.160.6.56 raeburn 963: $output .= '
964: </table>
965: </td>
966: </tr>
967: <tr>
968: <td>
969: <table class="LC_nested">
970: <tr class="LC_info_row">';
1.160.6.113 raeburn 971: if ($numheaders == 5) {
1.160.6.56 raeburn 972: $output .= '
973: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
974: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
975: </tr>';
976: } else {
977: $output .= '
978: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
979: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
980: </tr>';
981: }
982: $rowtotal ++;
1.160.6.113 raeburn 983: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
984: </table>
985: </td>
986: </tr>
987: <tr>
988: <td>
989: <table class="LC_nested">
990: <tr class="LC_info_row">';
991: if ($numheaders == 5) {
992: $output .= '
993: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
994: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
995: </tr>';
996: } else {
997: $output .= '
998: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
999: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1000: </tr>';
1001: }
1002: $rowtotal ++;
1003: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1004: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 1005: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1006: $rowtotal ++;
1007: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 1008: </table>
1009: </td>
1010: </tr>
1011: <tr>
1012: <td>
1013: <table class="LC_nested">
1014: <tr class="LC_info_row">
1015: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1016: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 1017: &textbookcourses_javascript($settings).
1018: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1019: </table>
1020: </td>
1021: </tr>
1022: <tr>
1023: <td>
1024: <table class="LC_nested">
1025: <tr class="LC_info_row">
1026: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1027: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1028: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 1029: </table>
1030: </td>
1031: </tr>
1032: <tr>
1033: <td>
1034: <table class="LC_nested">
1035: <tr class="LC_info_row">
1.160.6.46 raeburn 1036: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1037: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1038: </tr>'.
1039: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1040: } elsif ($action eq 'requestauthor') {
1041: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1042: $rowtotal ++;
1.122 jms 1043: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1044: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1045: </table>
1046: </td>
1047: </tr>
1048: <tr>
1049: <td>
1050: <table class="LC_nested">
1051: <tr class="LC_info_row">
1.69 raeburn 1052: <td class="LC_left_item"'.$colspan.' valign="top">'.
1053: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item" valign="top">'.
1055: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1056: </tr>'.
1.30 raeburn 1057: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1058: </table>
1059: </td>
1060: </tr>
1061: <tr>
1062: <td>
1063: <table class="LC_nested">
1064: <tr class="LC_info_row">
1.59 bisitz 1065: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1066: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1067: </tr>'.
1.30 raeburn 1068: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1069: $rowtotal += 2;
1.6 raeburn 1070: }
1.3 raeburn 1071: } else {
1.30 raeburn 1072: $output .= '
1.3 raeburn 1073: <tr>
1074: <td>
1075: <table class="LC_nested">
1.30 raeburn 1076: <tr class="LC_info_row">';
1.160.6.72 raeburn 1077: if ($action eq 'login') {
1.30 raeburn 1078: $output .= '
1.59 bisitz 1079: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1080: } elsif ($action eq 'serverstatuses') {
1081: $output .= '
1082: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1083: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1084:
1.6 raeburn 1085: } else {
1.30 raeburn 1086: $output .= '
1.69 raeburn 1087: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1088: }
1.72 raeburn 1089: if (defined($item->{'header'}->[0]->{'col3'})) {
1090: $output .= '<td class="LC_left_item" valign="top">'.
1091: &mt($item->{'header'}->[0]->{'col2'});
1092: if ($action eq 'serverstatuses') {
1093: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1094: }
1.69 raeburn 1095: } else {
1096: $output .= '<td class="LC_right_item" valign="top">'.
1097: &mt($item->{'header'}->[0]->{'col2'});
1098: }
1099: $output .= '</td>';
1100: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1101: if (defined($item->{'header'}->[0]->{'col4'})) {
1102: $output .= '<td class="LC_left_item" valign="top">'.
1103: &mt($item->{'header'}->[0]->{'col3'});
1104: } else {
1105: $output .= '<td class="LC_right_item" valign="top">'.
1106: &mt($item->{'header'}->[0]->{'col3'});
1107: }
1.69 raeburn 1108: if ($action eq 'serverstatuses') {
1109: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1110: }
1111: $output .= '</td>';
1.6 raeburn 1112: }
1.150 raeburn 1113: if ($item->{'header'}->[0]->{'col4'}) {
1114: $output .= '<td class="LC_right_item" valign="top">'.
1115: &mt($item->{'header'}->[0]->{'col4'});
1116: }
1.69 raeburn 1117: $output .= '</tr>';
1.48 raeburn 1118: $rowtotal ++;
1.160.6.5 raeburn 1119: if ($action eq 'quotas') {
1.86 raeburn 1120: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1121: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1122: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 1(raebur 1123:1): ($action eq 'ltitools') || ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1124: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1125: }
1.3 raeburn 1126: }
1.30 raeburn 1127: $output .= '
1.3 raeburn 1128: </table>
1129: </td>
1130: </tr>
1.30 raeburn 1131: </table><br />';
1132: return ($output,$rowtotal);
1.1 raeburn 1133: }
1134:
1.3 raeburn 1135: sub print_login {
1.160.6.5 raeburn 1136: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1137: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1138: my %choices = &login_choices();
1.160.6.113 raeburn 1139: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1140: %lt = &login_file_options();
1141: $switchserver = &check_switchserver($dom,$confname);
1142: }
1.110 raeburn 1143:
1.160.6.5 raeburn 1144: if ($caller eq 'service') {
1.149 raeburn 1145: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1146: my $choice = $choices{'disallowlogin'};
1147: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1148: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1149: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1150: '<th>'.$choices{'server'}.'</th>'.
1151: '<th>'.$choices{'serverpath'}.'</th>'.
1152: '<th>'.$choices{'custompath'}.'</th>'.
1153: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1154: my %disallowed;
1155: if (ref($settings) eq 'HASH') {
1156: if (ref($settings->{'loginvia'}) eq 'HASH') {
1157: %disallowed = %{$settings->{'loginvia'}};
1158: }
1159: }
1160: foreach my $lonhost (sort(keys(%servers))) {
1161: my $direct = 'selected="selected"';
1.128 raeburn 1162: if (ref($disallowed{$lonhost}) eq 'HASH') {
1163: if ($disallowed{$lonhost}{'server'} ne '') {
1164: $direct = '';
1165: }
1.110 raeburn 1166: }
1.115 raeburn 1167: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1168: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1169: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1170: '</option>';
1.160.6.13 raeburn 1171: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1172: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1173: my $selected = '';
1.128 raeburn 1174: if (ref($disallowed{$lonhost}) eq 'HASH') {
1175: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1176: $selected = 'selected="selected"';
1177: }
1.110 raeburn 1178: }
1179: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1180: $servers{$hostid}.'</option>';
1181: }
1.128 raeburn 1182: $datatable .= '</select></td>'.
1183: '<td><select name="'.$lonhost.'_serverpath">';
1184: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1185: my $pathname = $path;
1186: if ($path eq 'custom') {
1187: $pathname = &mt('Custom Path').' ->';
1188: }
1189: my $selected = '';
1190: if (ref($disallowed{$lonhost}) eq 'HASH') {
1191: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1192: $selected = 'selected="selected"';
1193: }
1194: } elsif ($path eq '') {
1195: $selected = 'selected="selected"';
1196: }
1197: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1198: }
1199: $datatable .= '</select></td>';
1200: my ($custom,$exempt);
1201: if (ref($disallowed{$lonhost}) eq 'HASH') {
1202: $custom = $disallowed{$lonhost}{'custompath'};
1203: $exempt = $disallowed{$lonhost}{'exempt'};
1204: }
1205: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1206: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1207: '</tr>';
1.110 raeburn 1208: }
1209: $datatable .= '</table></td></tr>';
1210: return $datatable;
1.160.6.5 raeburn 1211: } elsif ($caller eq 'page') {
1212: my %defaultchecked = (
1213: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1214: 'helpdesk' => 'on',
1.160.6.5 raeburn 1215: 'adminmail' => 'off',
1216: 'newuser' => 'off',
1217: );
1.160.6.14 raeburn 1218: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1219: my (%checkedon,%checkedoff);
1.42 raeburn 1220: foreach my $item (@toggles) {
1.160.6.5 raeburn 1221: if ($defaultchecked{$item} eq 'on') {
1222: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1223: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1224: } elsif ($defaultchecked{$item} eq 'off') {
1225: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1226: $checkedon{$item} = ' ';
1227: }
1.1 raeburn 1228: }
1.160.6.5 raeburn 1229: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1230:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1231: my @logintext = ('textcol','bgcol');
1232: my @bgs = ('pgbg','mainbg','sidebg');
1233: my @links = ('link','alink','vlink');
1234: my %designhash = &Apache::loncommon::get_domainconf($dom);
1235: my %defaultdesign = %Apache::loncommon::defaultdesign;
1236: my (%is_custom,%designs);
1237: my %defaults = (
1238: font => $defaultdesign{'login.font'},
1239: );
1.6 raeburn 1240: foreach my $item (@images) {
1.160.6.5 raeburn 1241: $defaults{$item} = $defaultdesign{'login.'.$item};
1242: $defaults{'showlogo'}{$item} = 1;
1243: }
1244: foreach my $item (@bgs) {
1245: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1246: }
1.41 raeburn 1247: foreach my $item (@logintext) {
1.160.6.5 raeburn 1248: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1249: }
1.160.6.5 raeburn 1250: foreach my $item (@links) {
1251: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1252: }
1.160.6.5 raeburn 1253: if (ref($settings) eq 'HASH') {
1254: foreach my $item (@toggles) {
1255: if ($settings->{$item} eq '1') {
1256: $checkedon{$item} = ' checked="checked" ';
1257: $checkedoff{$item} = ' ';
1258: } elsif ($settings->{$item} eq '0') {
1259: $checkedoff{$item} = ' checked="checked" ';
1260: $checkedon{$item} = ' ';
1261: }
1.6 raeburn 1262: }
1.160.6.5 raeburn 1263: foreach my $item (@images) {
1264: if (defined($settings->{$item})) {
1265: $designs{$item} = $settings->{$item};
1266: $is_custom{$item} = 1;
1267: }
1268: if (defined($settings->{'showlogo'}{$item})) {
1269: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1270: }
1271: }
1.160.6.118.2 2(raebur 1272:2): foreach my $item (@alttext) {
1273:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1274:2): if ($settings->{'alttext'}->{$item} ne '') {
1275:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1276:2): }
1277:2): }
1278:2): }
1.160.6.5 raeburn 1279: foreach my $item (@logintext) {
1280: if ($settings->{$item} ne '') {
1281: $designs{'logintext'}{$item} = $settings->{$item};
1282: $is_custom{$item} = 1;
1283: }
1284: }
1285: if ($settings->{'font'} ne '') {
1286: $designs{'font'} = $settings->{'font'};
1287: $is_custom{'font'} = 1;
1288: }
1289: foreach my $item (@bgs) {
1290: if ($settings->{$item} ne '') {
1291: $designs{'bgs'}{$item} = $settings->{$item};
1292: $is_custom{$item} = 1;
1293: }
1294: }
1295: foreach my $item (@links) {
1296: if ($settings->{$item} ne '') {
1297: $designs{'links'}{$item} = $settings->{$item};
1298: $is_custom{$item} = 1;
1299: }
1300: }
1301: } else {
1302: if ($designhash{$dom.'.login.font'} ne '') {
1303: $designs{'font'} = $designhash{$dom.'.login.font'};
1304: $is_custom{'font'} = 1;
1305: }
1306: foreach my $item (@images) {
1307: if ($designhash{$dom.'.login.'.$item} ne '') {
1308: $designs{$item} = $designhash{$dom.'.login.'.$item};
1309: $is_custom{$item} = 1;
1310: }
1311: }
1312: foreach my $item (@bgs) {
1313: if ($designhash{$dom.'.login.'.$item} ne '') {
1314: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1315: $is_custom{$item} = 1;
1316: }
1317: }
1318: foreach my $item (@links) {
1319: if ($designhash{$dom.'.login.'.$item} ne '') {
1320: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1321: $is_custom{$item} = 1;
1322: }
1.6 raeburn 1323: }
1324: }
1.160.6.5 raeburn 1325: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1326: logo => 'Institution Logo',
1327: domlogo => 'Domain Logo',
1328: login => 'Login box');
1329: my $itemcount = 1;
1330: foreach my $item (@toggles) {
1331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1332: $datatable .=
1333: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1334: '</td><td>'.
1335: '<span class="LC_nobreak"><label><input type="radio" name="'.
1336: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1337: '</label> <label><input type="radio" name="'.$item.'"'.
1338: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1339: '</tr>';
1340: $itemcount ++;
1.6 raeburn 1341: }
1.160.6.5 raeburn 1342: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1343: $datatable .= '</tr></table></td></tr>';
1344: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1345: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1346: my $itemcount = 1;
1347: $defaulturl = '/adm/loginproblems.html';
1348: $defaulttype = 'default';
1349: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1350: my @currlangs;
1351: if (ref($settings) eq 'HASH') {
1352: if (ref($settings->{'helpurl'}) eq 'HASH') {
1353: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1354: next if ($settings->{'helpurl'}{$key} eq '');
1355: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1356: $type{$key} = 'custom';
1357: unless ($key eq 'nolang') {
1358: push(@currlangs,$key);
1359: }
1360: }
1361: } elsif ($settings->{'helpurl'} ne '') {
1362: $type{'nolang'} = 'custom';
1363: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1364: }
1365: }
1.160.6.5 raeburn 1366: foreach my $lang ('nolang',sort(@currlangs)) {
1367: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1368: $datatable .= '<tr'.$css_class.'>';
1369: if ($url{$lang} eq '') {
1370: $url{$lang} = $defaulturl;
1371: }
1372: if ($type{$lang} eq '') {
1373: $type{$lang} = $defaulttype;
1374: }
1375: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1376: if ($lang eq 'nolang') {
1377: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1378: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1379: } else {
1380: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1381: $langchoices{$lang},
1382: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1383: }
1384: $datatable .= '</span></td>'."\n".
1385: '<td class="LC_left_item">';
1386: if ($type{$lang} eq 'custom') {
1387: $datatable .= '<span class="LC_nobreak"><label>'.
1388: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1389: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1390: } else {
1391: $datatable .= $lt{'upl'};
1392: }
1393: $datatable .='<br />';
1394: if ($switchserver) {
1395: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1396: } else {
1397: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1398: }
1.160.6.5 raeburn 1399: $datatable .= '</td></tr>';
1400: $itemcount ++;
1.6 raeburn 1401: }
1.160.6.5 raeburn 1402: my @addlangs;
1403: foreach my $lang (sort(keys(%langchoices))) {
1404: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1405: push(@addlangs,$lang);
1406: }
1407: if (@addlangs > 0) {
1408: my %toadd;
1409: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1410: $toadd{''} = &mt('Select');
1411: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1412: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1413: &mt('Add log-in help page for a specific language:').' '.
1414: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1415: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1416: if ($switchserver) {
1417: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1418: } else {
1419: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1420: }
1.160.6.5 raeburn 1421: $datatable .= '</td></tr>';
1422: $itemcount ++;
1.6 raeburn 1423: }
1.160.6.5 raeburn 1424: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1425: } elsif ($caller eq 'headtag') {
1426: my %domservers = &Apache::lonnet::get_servers($dom);
1427: my $choice = $choices{'headtag'};
1428: $css_class = ' class="LC_odd_row"';
1429: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1430: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1431: '<th>'.$choices{'current'}.'</th>'.
1432: '<th>'.$choices{'action'}.'</th>'.
1433: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1434: my (%currurls,%currexempt);
1435: if (ref($settings) eq 'HASH') {
1436: if (ref($settings->{'headtag'}) eq 'HASH') {
1437: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1438: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1439: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1440: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1441: }
1442: }
1443: }
1444: }
1445: foreach my $lonhost (sort(keys(%domservers))) {
1446: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1447: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1448: if ($currurls{$lonhost}) {
1449: $datatable .= '<td class="LC_right_item"><a href="'.
1450: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1451: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1452: '">'.$lt{'curr'}.'</a></td>'.
1453: '<td><span class="LC_nobreak"><label>'.
1454: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1455: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1456: } else {
1457: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1458: }
1459: $datatable .='<br />';
1460: if ($switchserver) {
1461: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1462: } else {
1463: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1464: }
1.160.6.87 raeburn 1465: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1466: }
1467: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1468: } elsif ($caller eq 'saml') {
1469: my %domservers = &Apache::lonnet::get_servers($dom);
1470: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1471: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1472: '<th>'.$choices{'samllanding'}.'</th>'.
1473: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.160.6.118.2 9(raebur 1474:2): my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.160.6.113 raeburn 1475: foreach my $lonhost (keys(%domservers)) {
1476: $samlurl{$lonhost} = '/adm/sso';
1477: $styleon{$lonhost} = 'display:none';
1478: $styleoff{$lonhost} = '';
1479: }
1.160.6.118.2 11(raebu 1480:23): if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.160.6.113 raeburn 1481: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1482: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1483: $saml{$lonhost} = 1;
1484: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1485: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1486: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1487: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1488: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 1489:2): $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 1490: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1491: $styleon{$lonhost} = '';
1492: $styleoff{$lonhost} = 'display:none';
1493: } else {
1494: $styleon{$lonhost} = 'display:none';
1495: $styleoff{$lonhost} = '';
1496: }
1497: }
1498: }
1499: my $itemcount = 1;
1500: foreach my $lonhost (sort(keys(%domservers))) {
1501: my $samlon = ' ';
1502: my $samloff = ' checked="checked" ';
1503: if ($saml{$lonhost}) {
1504: $samlon = $samloff;
1505: $samloff = ' ';
1506: }
1.160.6.118.2 9(raebur 1507:2): my $samlwinon = '';
1508:2): my $samlwinoff = ' checked="checked"';
1509:2): if ($samlwindow{$lonhost}) {
1510:2): $samlwinon = $samlwinoff;
1511:2): $samlwinoff = '';
1512:2): }
1.160.6.113 raeburn 1513: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1514: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1515: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1516: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1517: &mt('No').'</label>'.(' 'x2).
1518: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1519: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1520: &mt('Yes').'</label></span></td>'.
1521: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.160.6.118.2 9(raebur 1522:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.160.6.113 raeburn 1523: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.160.6.118.2 9(raebur 1524:2): '<th>'.&mt('Alt Text').'</th></tr>'.
1525:2): '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.160.6.113 raeburn 1526: $samltext{$lonhost}.'" /></td><td>';
1527: if ($samlimg{$lonhost}) {
1528: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1529: '<span class="LC_nobreak"><label>'.
1530: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1531: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1532: } else {
1533: $datatable .= $lt{'upl'};
1534: }
1535: $datatable .='<br />';
1536: if ($switchserver) {
1537: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1538: } else {
1539: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1540: }
1541: $datatable .= '</td>'.
1.160.6.118.2 9(raebur 1542:2): '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1543:2): 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1544:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1545:2): '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1546:2): '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1547:2): '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1548:2): '<tr'.$css_class.'>'.
1549:2): '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.160.6.113 raeburn 1550: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.160.6.118.2 9(raebur 1551:2): '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.160.6.113 raeburn 1552: $samltitle{$lonhost}.'</textarea></td>'.
1.160.6.118.2 9(raebur 1553:2): '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1554:2): &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1555:2): 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1556:2): '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.160.6.113 raeburn 1557: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1558: '</table></td>'.
1559: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1560: $itemcount ++;
1561: }
1562: $datatable .= '</table></td></tr>';
1.1 raeburn 1563: }
1.6 raeburn 1564: return $datatable;
1565: }
1566:
1567: sub login_choices {
1568: my %choices =
1569: &Apache::lonlocal::texthash (
1.116 bisitz 1570: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1571: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1572: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1573: disallowlogin => "Login page requests redirected",
1574: hostid => "Server",
1.128 raeburn 1575: server => "Redirect to:",
1576: serverpath => "Path",
1577: custompath => "Custom",
1578: exempt => "Exempt IP(s)",
1.110 raeburn 1579: directlogin => "No redirect",
1580: newuser => "Link to create a user account",
1581: img => "Header",
1582: logo => "Main Logo",
1583: domlogo => "Domain Logo",
1584: login => "Log-in Header",
1585: textcol => "Text color",
1586: bgcol => "Box color",
1587: bgs => "Background colors",
1588: links => "Link colors",
1589: font => "Font color",
1590: pgbg => "Header",
1591: mainbg => "Page",
1592: sidebg => "Login box",
1593: link => "Link",
1594: alink => "Active link",
1595: vlink => "Visited link",
1.160.6.56 raeburn 1596: headtag => "Custom markup",
1597: action => "Action",
1598: current => "Current",
1.160.6.113 raeburn 1599: samllanding => "Dual login?",
1600: samloptions => "Options",
1.160.6.118.2 2(raebur 1601:2): alttext => "Alt text",
1.6 raeburn 1602: );
1603: return %choices;
1604: }
1605:
1.160.6.113 raeburn 1606: sub login_file_options {
1607: return &Apache::lonlocal::texthash(
1608: del => 'Delete?',
1609: rep => 'Replace:',
1610: upl => 'Upload:',
1611: curr => 'View contents',
1612: default => 'Default',
1613: custom => 'Custom',
1614: none => 'None',
1615: );
1616: }
1617:
1618: sub print_ipaccess {
1619: my ($dom,$settings,$rowtotal) = @_;
1620: my $css_class;
1621: my $itemcount = 0;
1622: my $datatable;
1623: my %ordered;
1624: if (ref($settings) eq 'HASH') {
1625: foreach my $item (keys(%{$settings})) {
1626: if (ref($settings->{$item}) eq 'HASH') {
1627: my $num = $settings->{$item}{'order'};
1628: if ($num eq '') {
1629: $num = scalar(keys(%{$settings}));
1630: }
1631: $ordered{$num} = $item;
1632: }
1633: }
1634: }
1635: my $maxnum = scalar(keys(%ordered));
1636: if (keys(%ordered)) {
1637: my @items = sort { $a <=> $b } keys(%ordered);
1638: for (my $i=0; $i<@items; $i++) {
1639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1640: my $item = $ordered{$items[$i]};
1641: my ($name,$ipranges,%commblocks,%courses);
1642: if (ref($settings->{$item}) eq 'HASH') {
1643: $name = $settings->{$item}->{'name'};
1644: $ipranges = $settings->{$item}->{'ip'};
1645: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1646: %commblocks = %{$settings->{$item}->{'commblocks'}};
1647: }
1648: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1649: %courses = %{$settings->{$item}->{'courses'}};
1650: }
1651: }
1652: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1653: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1654: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1655: for (my $k=0; $k<=$maxnum; $k++) {
1656: my $vpos = $k+1;
1657: my $selstr;
1658: if ($k == $i) {
1659: $selstr = ' selected="selected" ';
1660: }
1661: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1662: }
1663: $datatable .= '</select>'.(' 'x2).
1664: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1665: &mt('Delete?').'</label></span></td>'.
1666: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1667: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1668: '</td></tr>';
1669: $itemcount ++;
1670: }
1671: }
1672: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1673: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1674: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1675: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1676: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1677: for (my $k=0; $k<$maxnum+1; $k++) {
1678: my $vpos = $k+1;
1679: my $selstr;
1680: if ($k == $maxnum) {
1681: $selstr = ' selected="selected" ';
1682: }
1683: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1684: }
1685: $datatable .= '</select> '."\n".
1686: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1687: '<td colspan="2">'.
1688: &ipaccess_options('add',$itemcount,$dom).
1689: '</td>'."\n".
1690: '</tr>'."\n";
1691: $$rowtotal ++;
1692: return $datatable;
1693: }
1694:
1695: sub ipaccess_options {
1696: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1697: my (%currblocks,%currcourses,$output);
1698: if (ref($blocksref) eq 'HASH') {
1699: %currblocks = %{$blocksref};
1700: }
1701: if (ref($coursesref) eq 'HASH') {
1702: %currcourses = %{$coursesref};
1703: }
1704: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1705: '<span class="LC_nobreak">'.&mt('Name').': '.
1706: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1707: '</span></fieldset>'.
1708: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1709: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1710: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1711: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1712: $ipranges.'</textarea></fieldset>'.
1713: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1714: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1715: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1716: '<table>';
1717: foreach my $cid (sort(keys(%currcourses))) {
1718: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1719: $output .= '<tr><td><span class="LC_nobreak">'.
1720: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1721: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1722: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1723: }
1724: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1725: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1726: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1727: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1728: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1729: '</span></td></tr></table>'."\n".
1730: '</fieldset>';
1731: return $output;
1732: }
1733:
1734: sub blocker_checkboxes {
1735: my ($num,$blocks) = @_;
1736: my ($typeorder,$types) = &commblocktype_text();
1737: my $numinrow = 6;
1738: my $output = '<table>';
1739: for (my $i=0; $i<@{$typeorder}; $i++) {
1740: my $block = $typeorder->[$i];
1741: my $blockstatus;
1742: if (ref($blocks) eq 'HASH') {
1743: if ($blocks->{$block} eq 'on') {
1744: $blockstatus = 'checked="checked"';
1745: }
1746: }
1747: my $rem = $i%($numinrow);
1748: if ($rem == 0) {
1749: if ($i > 0) {
1750: $output .= '</tr>';
1751: }
1752: $output .= '<tr>';
1753: }
1754: if ($i == scalar(@{$typeorder})-1) {
1755: my $colsleft = $numinrow-$rem;
1756: if ($colsleft > 1) {
1757: $output .= '<td colspan="'.$colsleft.'">';
1758: } else {
1759: $output .= '<td>';
1760: }
1761: } else {
1762: $output .= '<td>';
1763: }
1764: my $item = 'ipaccess_block_'.$num;
1765: if ($blockstatus) {
1766: $blockstatus = ' '.$blockstatus;
1767: }
1768: $output .= '<span class="LC_nobreak"><label>'."\n".
1769: '<input type="checkbox" name="'.$item.'"'.
1770: $blockstatus.' value="'.$block.'"'.' />'.
1771: $types->{$block}.'</label></span>'."\n".
1772: '<br /></td>';
1773: }
1774: $output .= '</tr></table>';
1775: return $output;
1776: }
1777:
1778: sub commblocktype_text {
1779: my %types = &Apache::lonlocal::texthash(
1780: 'com' => 'Messaging',
1781: 'chat' => 'Chat Room',
1782: 'boards' => 'Discussion',
1783: 'port' => 'Portfolio',
1784: 'groups' => 'Groups',
1785: 'blogs' => 'Blogs',
1786: 'about' => 'User Information',
1787: 'printout' => 'Printouts',
1788: 'passwd' => 'Change Password',
1789: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1790: 'search' => 'Course search',
1791: 'wishlist' => 'Stored links',
1792: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1793: );
1.160.6.115 raeburn 1794: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1795: return ($typeorder,\%types);
1796: }
1797:
1.6 raeburn 1798: sub print_rolecolors {
1.30 raeburn 1799: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1800: my %choices = &color_font_choices();
1801: my @bgs = ('pgbg','tabbg','sidebg');
1802: my @links = ('link','alink','vlink');
1803: my @images = ('img');
1804: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1805: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1806: my %defaultdesign = %Apache::loncommon::defaultdesign;
1807: my (%is_custom,%designs);
1.160.6.22 raeburn 1808: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1809: if (ref($settings) eq 'HASH') {
1810: if (ref($settings->{$role}) eq 'HASH') {
1811: if ($settings->{$role}->{'img'} ne '') {
1812: $designs{'img'} = $settings->{$role}->{'img'};
1813: $is_custom{'img'} = 1;
1814: }
1815: if ($settings->{$role}->{'font'} ne '') {
1816: $designs{'font'} = $settings->{$role}->{'font'};
1817: $is_custom{'font'} = 1;
1818: }
1.97 tempelho 1819: if ($settings->{$role}->{'fontmenu'} ne '') {
1820: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1821: $is_custom{'fontmenu'} = 1;
1822: }
1.6 raeburn 1823: foreach my $item (@bgs) {
1824: if ($settings->{$role}->{$item} ne '') {
1825: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1826: $is_custom{$item} = 1;
1827: }
1828: }
1829: foreach my $item (@links) {
1830: if ($settings->{$role}->{$item} ne '') {
1831: $designs{'links'}{$item} = $settings->{$role}->{$item};
1832: $is_custom{$item} = 1;
1833: }
1834: }
1835: }
1836: } else {
1837: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1838: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1839: $is_custom{'img'} = 1;
1840: }
1.97 tempelho 1841: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1842: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1843: $is_custom{'fontmenu'} = 1;
1844: }
1.6 raeburn 1845: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1846: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1847: $is_custom{'font'} = 1;
1848: }
1849: foreach my $item (@bgs) {
1850: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1851: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1852: $is_custom{$item} = 1;
1853:
1854: }
1855: }
1856: foreach my $item (@links) {
1857: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1858: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1859: $is_custom{$item} = 1;
1860: }
1861: }
1862: }
1863: my $itemcount = 1;
1.30 raeburn 1864: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1865: $datatable .= '</tr></table></td></tr>';
1866: return $datatable;
1867: }
1868:
1.160.6.22 raeburn 1869: sub role_defaults {
1870: my ($role,$bgs,$links,$images,$logintext) = @_;
1871: my %defaults;
1872: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1873: return %defaults;
1874: }
1875: my %defaultdesign = %Apache::loncommon::defaultdesign;
1876: if ($role eq 'login') {
1877: %defaults = (
1878: font => $defaultdesign{$role.'.font'},
1879: );
1880: if (ref($logintext) eq 'ARRAY') {
1881: foreach my $item (@{$logintext}) {
1882: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1883: }
1884: }
1885: foreach my $item (@{$images}) {
1886: $defaults{'showlogo'}{$item} = 1;
1887: }
1888: } else {
1889: %defaults = (
1890: img => $defaultdesign{$role.'.img'},
1891: font => $defaultdesign{$role.'.font'},
1892: fontmenu => $defaultdesign{$role.'.fontmenu'},
1893: );
1894: }
1895: foreach my $item (@{$bgs}) {
1896: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1897: }
1898: foreach my $item (@{$links}) {
1899: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1900: }
1901: foreach my $item (@{$images}) {
1902: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1903: }
1904: return %defaults;
1905: }
1906:
1.6 raeburn 1907: sub display_color_options {
1.9 raeburn 1908: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1909: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1910: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1911: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1912: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1913: '<td>'.$choices->{'font'}.'</td>';
1914: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1915: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1916: } else {
1917: $datatable .= '<td> </td>';
1918: }
1.160.6.9 raeburn 1919: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1920:
1.8 raeburn 1921: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1922: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1923: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1924: ' </span></td></tr>';
1.107 raeburn 1925: unless ($role eq 'login') {
1926: $datatable .= '<tr'.$css_class.'>'.
1927: '<td>'.$choices->{'fontmenu'}.'</td>';
1928: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1929: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1930: } else {
1931: $datatable .= '<td> </td>';
1932: }
1.160.6.22 raeburn 1933: $current_color = $designs->{'fontmenu'} ?
1934: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1935: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1936: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1937: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1938: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1939: ' </span></td></tr>';
1.97 tempelho 1940: }
1.9 raeburn 1941: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1942: foreach my $img (@{$images}) {
1.18 albertel 1943: $itemcount ++;
1.6 raeburn 1944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1945: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1946: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 1947:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1948: if ($role eq 'login') {
1949: if ($img eq 'login') {
1950: $login_hdr_pick =
1.135 bisitz 1951: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1952: $logincolors =
1953: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1954: $designs,$defaults);
1.160.6.118.2 2(raebur 1955:2): } else {
1956:2): if ($img ne 'domlogo') {
1957:2): $datatable.= &logo_display_options($img,$defaults,$designs);
1958:2): }
1959:2): if (ref($designs->{'alttext'}) eq 'HASH') {
1960:2): $alttext = $designs->{'alttext'}{$img};
1961:2): }
1.70 raeburn 1962: }
1963: }
1964: $datatable .= '</td>';
1.6 raeburn 1965: if ($designs->{$img} ne '') {
1966: $imgfile = $designs->{$img};
1.18 albertel 1967: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1968: } else {
1969: $imgfile = $defaults->{$img};
1970: }
1971: if ($imgfile) {
1.9 raeburn 1972: my ($showfile,$fullsize);
1973: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1974: my $urldir = $1;
1975: my $filename = $2;
1976: my @info = &Apache::lonnet::stat_file($designs->{$img});
1977: if (@info) {
1978: my $thumbfile = 'tn-'.$filename;
1979: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1980: if (@thumb) {
1981: $showfile = $urldir.'/'.$thumbfile;
1982: } else {
1983: $showfile = $imgfile;
1984: }
1985: } else {
1986: $showfile = '';
1987: }
1988: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1989: $showfile = $imgfile;
1.6 raeburn 1990: my $imgdir = $1;
1991: my $filename = $2;
1.159 raeburn 1992: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1993: $showfile = "/$imgdir/tn-".$filename;
1994: } else {
1.159 raeburn 1995: my $input = $londocroot.$imgfile;
1996: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1997: if (!-e $output) {
1.9 raeburn 1998: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1999: my ($fullwidth,$fullheight) = &check_dimensions($input);
2000: if ($fullwidth ne '' && $fullheight ne '') {
2001: if ($fullwidth > $width && $fullheight > $height) {
2002: my $size = $width.'x'.$height;
1.160.6.88 raeburn 2003: my @args = ('convert','-sample',$size,$input,$output);
2004: system({$args[0]} @args);
1.159 raeburn 2005: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2006: }
2007: }
1.6 raeburn 2008: }
2009: }
1.16 raeburn 2010: }
1.6 raeburn 2011: if ($showfile) {
1.40 raeburn 2012: if ($showfile =~ m{^/(adm|res)/}) {
2013: if ($showfile =~ m{^/res/}) {
2014: my $local_showfile =
2015: &Apache::lonnet::filelocation('',$showfile);
2016: &Apache::lonnet::repcopy($local_showfile);
2017: }
2018: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2019: }
2020: if ($imgfile) {
2021: if ($imgfile =~ m{^/(adm|res)/}) {
2022: if ($imgfile =~ m{^/res/}) {
2023: my $local_imgfile =
2024: &Apache::lonnet::filelocation('',$imgfile);
2025: &Apache::lonnet::repcopy($local_imgfile);
2026: }
2027: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2028: } else {
2029: $fullsize = $imgfile;
2030: }
2031: }
1.41 raeburn 2032: $datatable .= '<td>';
2033: if ($img eq 'login') {
1.135 bisitz 2034: $datatable .= $login_hdr_pick;
2035: }
1.41 raeburn 2036: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2037: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2038: } else {
1.160.6.22 raeburn 2039: $datatable .= '<td> </td><td class="LC_left_item">'.
2040: &mt('Upload:').'<br />';
1.6 raeburn 2041: }
2042: } else {
1.160.6.22 raeburn 2043: $datatable .= '<td> </td><td class="LC_left_item">'.
2044: &mt('Upload:').'<br />';
1.6 raeburn 2045: }
1.9 raeburn 2046: if ($switchserver) {
2047: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2048: } else {
1.135 bisitz 2049: if ($img ne 'login') { # suppress file selection for Log-in header
2050: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2051: }
1.9 raeburn 2052: }
1.160.6.118.2 2(raebur 2053:2): if (($role eq 'login') && ($img ne 'login')) {
2054:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2055:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2056:2): '</label></span>';
2057:2): }
1.9 raeburn 2058: $datatable .= '</td></tr>';
1.6 raeburn 2059: }
2060: $itemcount ++;
2061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2062: $datatable .= '<tr'.$css_class.'>'.
2063: '<td>'.$choices->{'bgs'}.'</td>';
2064: my $bgs_def;
2065: foreach my $item (@{$bgs}) {
2066: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2067: $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 2068: }
2069: }
2070: if ($bgs_def) {
1.8 raeburn 2071: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2072: } else {
2073: $datatable .= '<td> </td>';
2074: }
2075: $datatable .= '<td class="LC_right_item">'.
2076: '<table border="0"><tr>';
1.160.6.13 raeburn 2077:
1.6 raeburn 2078: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2079: $datatable .= '<td align="center">'.$choices->{$item};
2080: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2081: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2082: $datatable .= ' ';
1.6 raeburn 2083: }
1.160.6.9 raeburn 2084: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2085: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2086: }
2087: $datatable .= '</tr></table></td></tr>';
2088: $itemcount ++;
2089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2090: $datatable .= '<tr'.$css_class.'>'.
2091: '<td>'.$choices->{'links'}.'</td>';
2092: my $links_def;
2093: foreach my $item (@{$links}) {
2094: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2095: $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 2096: }
2097: }
2098: if ($links_def) {
1.8 raeburn 2099: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2100: } else {
2101: $datatable .= '<td> </td>';
2102: }
2103: $datatable .= '<td class="LC_right_item">'.
2104: '<table border="0"><tr>';
2105: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2106: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2107: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2108: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2109: $datatable.=' ';
1.6 raeburn 2110: }
1.160.6.9 raeburn 2111: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2112: '" /></td>';
2113: }
1.30 raeburn 2114: $$rowtotal += $itemcount;
1.3 raeburn 2115: return $datatable;
2116: }
2117:
1.70 raeburn 2118: sub logo_display_options {
2119: my ($img,$defaults,$designs) = @_;
2120: my $checkedon;
2121: if (ref($defaults) eq 'HASH') {
2122: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2123: if ($defaults->{'showlogo'}{$img}) {
2124: $checkedon = 'checked="checked" ';
2125: }
2126: }
2127: }
2128: if (ref($designs) eq 'HASH') {
2129: if (ref($designs->{'showlogo'}) eq 'HASH') {
2130: if (defined($designs->{'showlogo'}{$img})) {
2131: if ($designs->{'showlogo'}{$img} == 0) {
2132: $checkedon = '';
2133: } elsif ($designs->{'showlogo'}{$img} == 1) {
2134: $checkedon = 'checked="checked" ';
2135: }
2136: }
2137: }
2138: }
2139: return '<br /><label> <input type="checkbox" name="'.
2140: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2141: &mt('show').'</label>'."\n";
2142: }
2143:
1.41 raeburn 2144: sub login_header_options {
1.135 bisitz 2145: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2146: my $output = '';
1.41 raeburn 2147: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2148: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2149: if (!$is_custom->{'textcol'}) {
2150: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2151: ' ';
2152: }
2153: if (!$is_custom->{'bgcol'}) {
2154: $output .= $choices->{'bgcol'}.': '.
2155: '<span id="css_'.$role.'_font" style="background-color: '.
2156: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2157: }
2158: $output .= '<br />';
2159: }
2160: $output .='<br />';
2161: return $output;
2162: }
2163:
2164: sub login_text_colors {
1.160.6.22 raeburn 2165: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2166: my $color_menu = '<table border="0"><tr>';
2167: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2168: $color_menu .= '<td align="center">'.$choices->{$item};
2169: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2170: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2171: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2172: }
2173: $color_menu .= '</tr></table><br />';
2174: return $color_menu;
2175: }
2176:
2177: sub image_changes {
2178: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2179: my $output;
1.135 bisitz 2180: if ($img eq 'login') {
1.160.6.87 raeburn 2181: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2182: } elsif (!$is_custom) {
1.70 raeburn 2183: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2184: $output = &mt('Default image:').'<br />';
1.41 raeburn 2185: } else {
1.160.6.87 raeburn 2186: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2187: }
2188: }
1.160.6.87 raeburn 2189: if ($img ne 'login') {
1.135 bisitz 2190: if ($img_import) {
2191: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2192: }
2193: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2194: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2195: if ($is_custom) {
2196: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2197: '<input type="checkbox" name="'.
2198: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2199: '</label> '.&mt('Replace:').'</span><br />';
2200: } else {
1.160.6.22 raeburn 2201: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2202: }
1.41 raeburn 2203: }
2204: return $output;
2205: }
2206:
1.3 raeburn 2207: sub print_quotas {
1.86 raeburn 2208: my ($dom,$settings,$rowtotal,$action) = @_;
2209: my $context;
2210: if ($action eq 'quotas') {
2211: $context = 'tools';
2212: } else {
2213: $context = $action;
2214: }
1.160.6.20 raeburn 2215: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2216: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2217: my $typecount = 0;
1.101 raeburn 2218: my ($css_class,%titles);
1.86 raeburn 2219: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2220: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2221: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2222: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2223: %titles = &courserequest_titles();
1.160.6.5 raeburn 2224: } elsif ($context eq 'requestauthor') {
2225: @usertools = ('author');
2226: @options = ('norequest','approval','automatic');
2227: %titles = &authorrequest_titles();
1.86 raeburn 2228: } else {
1.160.6.118.2 10(raebu 2229:22): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2230: %titles = &tool_titles();
1.86 raeburn 2231: }
1.26 raeburn 2232: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2233: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2234: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2235: unless (($context eq 'requestcourses') ||
2236: ($context eq 'requestauthor')) {
1.86 raeburn 2237: if (ref($settings) eq 'HASH') {
2238: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2239: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2240: } else {
2241: $currdefquota = $settings->{$type};
2242: }
1.160.6.20 raeburn 2243: if (ref($settings->{authorquota}) eq 'HASH') {
2244: $currauthorquota = $settings->{authorquota}->{$type};
2245: }
1.78 raeburn 2246: }
1.72 raeburn 2247: }
1.3 raeburn 2248: if (defined($usertypes->{$type})) {
2249: $typecount ++;
2250: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2251: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2252: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2253: '<td class="LC_left_item">';
1.101 raeburn 2254: if ($context eq 'requestcourses') {
2255: $datatable .= '<table><tr>';
2256: }
2257: my %cell;
1.72 raeburn 2258: foreach my $item (@usertools) {
1.101 raeburn 2259: if ($context eq 'requestcourses') {
2260: my ($curroption,$currlimit);
2261: if (ref($settings) eq 'HASH') {
2262: if (ref($settings->{$item}) eq 'HASH') {
2263: $curroption = $settings->{$item}->{$type};
2264: if ($curroption =~ /^autolimit=(\d*)$/) {
2265: $currlimit = $1;
2266: }
2267: }
2268: }
2269: if (!$curroption) {
2270: $curroption = 'norequest';
2271: }
2272: $datatable .= '<th>'.$titles{$item}.'</th>';
2273: foreach my $option (@options) {
2274: my $val = $option;
2275: if ($option eq 'norequest') {
2276: $val = 0;
2277: }
2278: if ($option eq 'validate') {
2279: my $canvalidate = 0;
2280: if (ref($validations{$item}) eq 'HASH') {
2281: if ($validations{$item}{$type}) {
2282: $canvalidate = 1;
2283: }
2284: }
2285: next if (!$canvalidate);
2286: }
2287: my $checked = '';
2288: if ($option eq $curroption) {
2289: $checked = ' checked="checked"';
2290: } elsif ($option eq 'autolimit') {
2291: if ($curroption =~ /^autolimit/) {
2292: $checked = ' checked="checked"';
2293: }
2294: }
2295: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2296: '<input type="radio" name="crsreq_'.$item.
2297: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2298: $titles{$option}.'</label>';
1.101 raeburn 2299: if ($option eq 'autolimit') {
1.127 raeburn 2300: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2301: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2302: 'value="'.$currlimit.'" />';
1.101 raeburn 2303: }
1.127 raeburn 2304: $cell{$item} .= '</span> ';
1.103 raeburn 2305: if ($option eq 'autolimit') {
1.127 raeburn 2306: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2307: }
1.101 raeburn 2308: }
1.160.6.5 raeburn 2309: } elsif ($context eq 'requestauthor') {
2310: my $curroption;
2311: if (ref($settings) eq 'HASH') {
2312: $curroption = $settings->{$type};
2313: }
2314: if (!$curroption) {
2315: $curroption = 'norequest';
2316: }
2317: foreach my $option (@options) {
2318: my $val = $option;
2319: if ($option eq 'norequest') {
2320: $val = 0;
2321: }
2322: my $checked = '';
2323: if ($option eq $curroption) {
2324: $checked = ' checked="checked"';
2325: }
2326: $datatable .= '<span class="LC_nobreak"><label>'.
2327: '<input type="radio" name="authorreq_'.$type.
2328: '" value="'.$val.'"'.$checked.' />'.
2329: $titles{$option}.'</label></span> ';
2330: }
1.101 raeburn 2331: } else {
2332: my $checked = 'checked="checked" ';
1.160.6.118.2 10(raebu 2333:22): if ($item eq 'timezone') {
2334:22): $checked = '';
2335:22): }
1.101 raeburn 2336: if (ref($settings) eq 'HASH') {
2337: if (ref($settings->{$item}) eq 'HASH') {
1.160.6.118.2 10(raebu 2338:22): if (!$settings->{$item}->{$type}) {
1.101 raeburn 2339: $checked = '';
2340: } elsif ($settings->{$item}->{$type} == 1) {
2341: $checked = 'checked="checked" ';
2342: }
1.78 raeburn 2343: }
1.72 raeburn 2344: }
1.101 raeburn 2345: $datatable .= '<span class="LC_nobreak"><label>'.
2346: '<input type="checkbox" name="'.$context.'_'.$item.
2347: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2348: '</label></span> ';
1.72 raeburn 2349: }
1.101 raeburn 2350: }
2351: if ($context eq 'requestcourses') {
2352: $datatable .= '</tr><tr>';
2353: foreach my $item (@usertools) {
1.106 raeburn 2354: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2355: }
2356: $datatable .= '</tr></table>';
1.72 raeburn 2357: }
1.86 raeburn 2358: $datatable .= '</td>';
1.160.6.5 raeburn 2359: unless (($context eq 'requestcourses') ||
2360: ($context eq 'requestauthor')) {
1.86 raeburn 2361: $datatable .=
1.160.6.20 raeburn 2362: '<td class="LC_right_item">'.
2363: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2364: '<input type="text" name="quota_'.$type.
1.72 raeburn 2365: '" value="'.$currdefquota.
1.160.6.20 raeburn 2366: '" size="5" /></span>'.(' ' x 2).
2367: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2368: '<input type="text" name="authorquota_'.$type.
2369: '" value="'.$currauthorquota.
2370: '" size="5" /></span></td>';
1.86 raeburn 2371: }
2372: $datatable .= '</tr>';
1.3 raeburn 2373: }
2374: }
2375: }
1.160.6.5 raeburn 2376: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2377: $defaultquota = '20';
1.160.6.20 raeburn 2378: $authorquota = '500';
1.86 raeburn 2379: if (ref($settings) eq 'HASH') {
2380: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2381: $defaultquota = $settings->{'defaultquota'}->{'default'};
2382: } elsif (defined($settings->{'default'})) {
2383: $defaultquota = $settings->{'default'};
2384: }
1.160.6.20 raeburn 2385: if (ref($settings->{'authorquota'}) eq 'HASH') {
2386: $authorquota = $settings->{'authorquota'}->{'default'};
2387: }
1.3 raeburn 2388: }
2389: }
2390: $typecount ++;
2391: $css_class = $typecount%2?' class="LC_odd_row"':'';
2392: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2393: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2394: '<td class="LC_left_item">';
1.101 raeburn 2395: if ($context eq 'requestcourses') {
2396: $datatable .= '<table><tr>';
2397: }
2398: my %defcell;
1.72 raeburn 2399: foreach my $item (@usertools) {
1.101 raeburn 2400: if ($context eq 'requestcourses') {
2401: my ($curroption,$currlimit);
2402: if (ref($settings) eq 'HASH') {
2403: if (ref($settings->{$item}) eq 'HASH') {
2404: $curroption = $settings->{$item}->{'default'};
2405: if ($curroption =~ /^autolimit=(\d*)$/) {
2406: $currlimit = $1;
2407: }
2408: }
2409: }
2410: if (!$curroption) {
2411: $curroption = 'norequest';
2412: }
2413: $datatable .= '<th>'.$titles{$item}.'</th>';
2414: foreach my $option (@options) {
2415: my $val = $option;
2416: if ($option eq 'norequest') {
2417: $val = 0;
2418: }
2419: if ($option eq 'validate') {
2420: my $canvalidate = 0;
2421: if (ref($validations{$item}) eq 'HASH') {
2422: if ($validations{$item}{'default'}) {
2423: $canvalidate = 1;
2424: }
2425: }
2426: next if (!$canvalidate);
2427: }
2428: my $checked = '';
2429: if ($option eq $curroption) {
2430: $checked = ' checked="checked"';
2431: } elsif ($option eq 'autolimit') {
2432: if ($curroption =~ /^autolimit/) {
2433: $checked = ' checked="checked"';
2434: }
2435: }
2436: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2437: '<input type="radio" name="crsreq_'.$item.
2438: '_default" value="'.$val.'"'.$checked.' />'.
2439: $titles{$option}.'</label>';
2440: if ($option eq 'autolimit') {
1.127 raeburn 2441: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2442: $item.'_limit_default" size="1" '.
2443: 'value="'.$currlimit.'" />';
2444: }
1.127 raeburn 2445: $defcell{$item} .= '</span> ';
1.104 raeburn 2446: if ($option eq 'autolimit') {
1.127 raeburn 2447: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2448: }
1.101 raeburn 2449: }
1.160.6.5 raeburn 2450: } elsif ($context eq 'requestauthor') {
2451: my $curroption;
2452: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2453: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2454: }
2455: if (!$curroption) {
2456: $curroption = 'norequest';
2457: }
2458: foreach my $option (@options) {
2459: my $val = $option;
2460: if ($option eq 'norequest') {
2461: $val = 0;
2462: }
2463: my $checked = '';
2464: if ($option eq $curroption) {
2465: $checked = ' checked="checked"';
2466: }
2467: $datatable .= '<span class="LC_nobreak"><label>'.
2468: '<input type="radio" name="authorreq_default"'.
2469: ' value="'.$val.'"'.$checked.' />'.
2470: $titles{$option}.'</label></span> ';
2471: }
1.101 raeburn 2472: } else {
2473: my $checked = 'checked="checked" ';
2474: if (ref($settings) eq 'HASH') {
2475: if (ref($settings->{$item}) eq 'HASH') {
2476: if ($settings->{$item}->{'default'} == 0) {
2477: $checked = '';
2478: } elsif ($settings->{$item}->{'default'} == 1) {
2479: $checked = 'checked="checked" ';
2480: }
1.78 raeburn 2481: }
1.72 raeburn 2482: }
1.101 raeburn 2483: $datatable .= '<span class="LC_nobreak"><label>'.
2484: '<input type="checkbox" name="'.$context.'_'.$item.
2485: '" value="default" '.$checked.'/>'.$titles{$item}.
2486: '</label></span> ';
2487: }
2488: }
2489: if ($context eq 'requestcourses') {
2490: $datatable .= '</tr><tr>';
2491: foreach my $item (@usertools) {
1.106 raeburn 2492: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2493: }
1.101 raeburn 2494: $datatable .= '</tr></table>';
1.72 raeburn 2495: }
1.86 raeburn 2496: $datatable .= '</td>';
1.160.6.5 raeburn 2497: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2498: $datatable .= '<td class="LC_right_item">'.
2499: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2500: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2501: $defaultquota.'" size="5" /></span>'.(' ' x2).
2502: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2503: '<input type="text" name="authorquota" value="'.
2504: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2505: }
2506: $datatable .= '</tr>';
1.72 raeburn 2507: $typecount ++;
2508: $css_class = $typecount%2?' class="LC_odd_row"':'';
2509: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2510: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2511: if ($context eq 'requestcourses') {
1.109 raeburn 2512: $datatable .= &mt('(overrides affiliation, if set)').
2513: '</td>'.
2514: '<td class="LC_left_item">'.
2515: '<table><tr>';
1.101 raeburn 2516: } else {
1.109 raeburn 2517: $datatable .= &mt('(overrides affiliation, if checked)').
2518: '</td>'.
2519: '<td class="LC_left_item" colspan="2">'.
2520: '<br />';
1.101 raeburn 2521: }
2522: my %advcell;
1.72 raeburn 2523: foreach my $item (@usertools) {
1.101 raeburn 2524: if ($context eq 'requestcourses') {
2525: my ($curroption,$currlimit);
2526: if (ref($settings) eq 'HASH') {
2527: if (ref($settings->{$item}) eq 'HASH') {
2528: $curroption = $settings->{$item}->{'_LC_adv'};
2529: if ($curroption =~ /^autolimit=(\d*)$/) {
2530: $currlimit = $1;
2531: }
2532: }
2533: }
2534: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2535: my $checked = '';
2536: if ($curroption eq '') {
2537: $checked = ' checked="checked"';
2538: }
2539: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2540: '<input type="radio" name="crsreq_'.$item.
2541: '__LC_adv" value=""'.$checked.' />'.
2542: &mt('No override set').'</label></span> ';
1.101 raeburn 2543: foreach my $option (@options) {
2544: my $val = $option;
2545: if ($option eq 'norequest') {
2546: $val = 0;
2547: }
2548: if ($option eq 'validate') {
2549: my $canvalidate = 0;
2550: if (ref($validations{$item}) eq 'HASH') {
2551: if ($validations{$item}{'_LC_adv'}) {
2552: $canvalidate = 1;
2553: }
2554: }
2555: next if (!$canvalidate);
2556: }
2557: my $checked = '';
1.104 raeburn 2558: if ($val eq $curroption) {
1.101 raeburn 2559: $checked = ' checked="checked"';
2560: } elsif ($option eq 'autolimit') {
2561: if ($curroption =~ /^autolimit/) {
2562: $checked = ' checked="checked"';
2563: }
2564: }
2565: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2566: '<input type="radio" name="crsreq_'.$item.
2567: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2568: $titles{$option}.'</label>';
2569: if ($option eq 'autolimit') {
1.127 raeburn 2570: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2571: $item.'_limit__LC_adv" size="1" '.
2572: 'value="'.$currlimit.'" />';
2573: }
1.127 raeburn 2574: $advcell{$item} .= '</span> ';
1.104 raeburn 2575: if ($option eq 'autolimit') {
1.127 raeburn 2576: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2577: }
1.101 raeburn 2578: }
1.160.6.5 raeburn 2579: } elsif ($context eq 'requestauthor') {
2580: my $curroption;
2581: if (ref($settings) eq 'HASH') {
2582: $curroption = $settings->{'_LC_adv'};
2583: }
2584: my $checked = '';
2585: if ($curroption eq '') {
2586: $checked = ' checked="checked"';
2587: }
2588: $datatable .= '<span class="LC_nobreak"><label>'.
2589: '<input type="radio" name="authorreq__LC_adv"'.
2590: ' value=""'.$checked.' />'.
2591: &mt('No override set').'</label></span> ';
2592: foreach my $option (@options) {
2593: my $val = $option;
2594: if ($option eq 'norequest') {
2595: $val = 0;
2596: }
2597: my $checked = '';
2598: if ($val eq $curroption) {
2599: $checked = ' checked="checked"';
2600: }
2601: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2602: '<input type="radio" name="authorreq__LC_adv"'.
2603: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2604: $titles{$option}.'</label></span> ';
2605: }
1.101 raeburn 2606: } else {
2607: my $checked = 'checked="checked" ';
2608: if (ref($settings) eq 'HASH') {
2609: if (ref($settings->{$item}) eq 'HASH') {
2610: if ($settings->{$item}->{'_LC_adv'} == 0) {
2611: $checked = '';
2612: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2613: $checked = 'checked="checked" ';
2614: }
1.79 raeburn 2615: }
1.72 raeburn 2616: }
1.101 raeburn 2617: $datatable .= '<span class="LC_nobreak"><label>'.
2618: '<input type="checkbox" name="'.$context.'_'.$item.
2619: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2620: '</label></span> ';
2621: }
2622: }
2623: if ($context eq 'requestcourses') {
2624: $datatable .= '</tr><tr>';
2625: foreach my $item (@usertools) {
1.106 raeburn 2626: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2627: }
1.101 raeburn 2628: $datatable .= '</tr></table>';
1.72 raeburn 2629: }
1.98 raeburn 2630: $datatable .= '</td></tr>';
1.30 raeburn 2631: $$rowtotal += $typecount;
1.3 raeburn 2632: return $datatable;
2633: }
2634:
1.160.6.5 raeburn 2635: sub print_requestmail {
1.160.6.93 raeburn 2636: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2637: my ($now,$datatable,%currapp);
1.102 raeburn 2638: $now = time;
2639: if (ref($settings) eq 'HASH') {
2640: if (ref($settings->{'notify'}) eq 'HASH') {
2641: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2642: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2643: }
2644: }
2645: }
1.160.6.16 raeburn 2646: my $numinrow = 2;
1.160.6.34 raeburn 2647: my $css_class;
1.160.6.93 raeburn 2648: if ($$rowtotal%2) {
2649: $css_class = 'LC_odd_row';
2650: }
2651: if ($customcss) {
2652: $css_class .= " $customcss";
2653: }
2654: $css_class =~ s/^\s+//;
2655: if ($css_class) {
2656: $css_class = ' class="'.$css_class.'"';
2657: }
2658: if ($rowstyle) {
2659: $css_class .= ' style="'.$rowstyle.'"';
2660: }
1.160.6.5 raeburn 2661: my $text;
2662: if ($action eq 'requestcourses') {
2663: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2664: } elsif ($action eq 'requestauthor') {
2665: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2666: } else {
1.160.6.34 raeburn 2667: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2668: }
1.160.6.34 raeburn 2669: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2670: ' <td>'.$text.'</td>'.
1.102 raeburn 2671: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2672: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2673: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2674: if ($numdc > 0) {
2675: $datatable .= $table;
1.102 raeburn 2676: } else {
2677: $datatable .= &mt('There are no active Domain Coordinators');
2678: }
2679: $datatable .='</td></tr>';
2680: return $datatable;
2681: }
2682:
1.160.6.30 raeburn 2683: sub print_studentcode {
2684: my ($settings,$rowtotal) = @_;
2685: my $rownum = 0;
2686: my ($output,%current);
2687: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2688: if (ref($settings) eq 'HASH') {
2689: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2690: foreach my $type (@crstypes) {
2691: $current{$type} = $settings->{'uniquecode'}{$type};
2692: }
1.160.6.30 raeburn 2693: }
2694: }
2695: $output .= '<tr>'.
2696: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2697: '<td class="LC_left_item">';
2698: foreach my $type (@crstypes) {
2699: my $check = ' ';
2700: if ($current{$type}) {
2701: $check = ' checked="checked" ';
2702: }
2703: $output .= '<span class="LC_nobreak"><label>'.
2704: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2705: &mt($type).'</label></span>'.(' 'x2).' ';
2706: }
2707: $output .= '</td></tr>';
2708: $$rowtotal ++;
2709: return $output;
2710: }
2711:
2712: sub print_textbookcourses {
1.160.6.46 raeburn 2713: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2714: my $rownum = 0;
2715: my $css_class;
2716: my $itemcount = 1;
2717: my $maxnum = 0;
2718: my $bookshash;
2719: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2720: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2721: }
2722: my %ordered;
2723: if (ref($bookshash) eq 'HASH') {
2724: foreach my $item (keys(%{$bookshash})) {
2725: if (ref($bookshash->{$item}) eq 'HASH') {
2726: my $num = $bookshash->{$item}{'order'};
2727: $ordered{$num} = $item;
2728: }
2729: }
2730: }
2731: my $confname = $dom.'-domainconfig';
2732: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2733: my $maxnum = scalar(keys(%ordered));
2734: my $datatable;
1.160.6.30 raeburn 2735: if (keys(%ordered)) {
2736: my @items = sort { $a <=> $b } keys(%ordered);
2737: for (my $i=0; $i<@items; $i++) {
2738: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2739: my $key = $ordered{$items[$i]};
2740: my %coursehash=&Apache::lonnet::coursedescription($key);
2741: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2742: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2743: if (ref($bookshash->{$key}) eq 'HASH') {
2744: $subject = $bookshash->{$key}->{'subject'};
2745: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2746: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2747: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2748: $author = $bookshash->{$key}->{'author'};
2749: $image = $bookshash->{$key}->{'image'};
2750: if ($image ne '') {
2751: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2752: my $imagethumb = "$path/tn-".$imagefile;
2753: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2754: }
1.160.6.30 raeburn 2755: }
2756: }
1.160.6.46 raeburn 2757: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2758: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2759: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2760: for (my $k=0; $k<=$maxnum; $k++) {
2761: my $vpos = $k+1;
2762: my $selstr;
2763: if ($k == $i) {
2764: $selstr = ' selected="selected" ';
2765: }
2766: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2767: }
2768: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2769: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2770: &mt('Delete?').'</label></span></td>'.
2771: '<td colspan="2">'.
1.160.6.46 raeburn 2772: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2773: (' 'x2).
1.160.6.46 raeburn 2774: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2775: if ($type eq 'textbooks') {
2776: $datatable .= (' 'x2).
1.160.6.47 raeburn 2777: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2778: (' 'x2).
1.160.6.46 raeburn 2779: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2780: (' 'x2).
2781: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2782: if ($image) {
1.160.6.114 raeburn 2783: $datatable .= $imgsrc.
1.160.6.46 raeburn 2784: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2785: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2786: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2787: }
2788: if ($switchserver) {
2789: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2790: } else {
2791: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2792: }
1.160.6.30 raeburn 2793: }
1.160.6.46 raeburn 2794: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2795: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2796: $coursetitle.'</span></td></tr>'."\n";
2797: $itemcount ++;
2798: }
2799: }
2800: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2801: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2802: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2803: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2804: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2805: for (my $k=0; $k<$maxnum+1; $k++) {
2806: my $vpos = $k+1;
2807: my $selstr;
2808: if ($k == $maxnum) {
2809: $selstr = ' selected="selected" ';
2810: }
2811: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2812: }
2813: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2814: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2815: '<td colspan="2">'.
1.160.6.46 raeburn 2816: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2817: (' 'x2).
1.160.6.46 raeburn 2818: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2819: (' 'x2);
2820: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2821: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2822: (' 'x2).
2823: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2824: (' 'x2).
2825: '<span class="LC_nobreak">'.&mt('Image:').' ';
2826: if ($switchserver) {
2827: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2828: } else {
2829: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2830: }
1.160.6.87 raeburn 2831: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2832: }
1.160.6.87 raeburn 2833: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2834: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2835: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2836: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2837: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2838: '</span></td>'."\n".
2839: '</tr>'."\n";
2840: $itemcount ++;
2841: return $datatable;
2842: }
2843:
2844: sub textbookcourses_javascript {
1.160.6.46 raeburn 2845: my ($settings) = @_;
2846: return unless(ref($settings) eq 'HASH');
2847: my (%ordered,%total,%jstext);
2848: foreach my $type ('textbooks','templates') {
2849: $total{$type} = 0;
2850: if (ref($settings->{$type}) eq 'HASH') {
2851: foreach my $item (keys(%{$settings->{$type}})) {
2852: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2853: my $num = $settings->{$type}->{$item}{'order'};
2854: $ordered{$type}{$num} = $item;
2855: }
2856: }
2857: $total{$type} = scalar(keys(%{$settings->{$type}}));
2858: }
2859: my @jsarray = ();
2860: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2861: push(@jsarray,$ordered{$type}{$item});
2862: }
2863: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2864: }
2865: return <<"ENDSCRIPT";
2866: <script type="text/javascript">
2867: // <![CDATA[
1.160.6.46 raeburn 2868: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2869: var changedVal;
1.160.6.46 raeburn 2870: $jstext{'textbooks'};
2871: $jstext{'templates'};
2872: var newpos;
2873: var maxh;
2874: if (caller == 'textbooks') {
2875: newpos = 'textbooks_addbook_pos';
2876: maxh = 1 + $total{'textbooks'};
2877: } else {
2878: newpos = 'templates_addbook_pos';
2879: maxh = 1 + $total{'templates'};
2880: }
1.160.6.30 raeburn 2881: var current = new Array;
2882: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2883: if (item == newpos) {
2884: changedVal = newitemVal;
2885: } else {
2886: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2887: current[newitemVal] = newpos;
2888: }
1.160.6.46 raeburn 2889: if (caller == 'textbooks') {
2890: for (var i=0; i<textbooks.length; i++) {
2891: var elementName = 'textbooks_'+textbooks[i];
2892: if (elementName != item) {
2893: if (form.elements[elementName]) {
2894: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2895: current[currVal] = elementName;
2896: }
2897: }
2898: }
2899: }
2900: if (caller == 'templates') {
2901: for (var i=0; i<templates.length; i++) {
2902: var elementName = 'templates_'+templates[i];
2903: if (elementName != item) {
2904: if (form.elements[elementName]) {
2905: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2906: current[currVal] = elementName;
2907: }
1.160.6.30 raeburn 2908: }
2909: }
2910: }
2911: var oldVal;
2912: for (var j=0; j<maxh; j++) {
2913: if (current[j] == undefined) {
2914: oldVal = j;
2915: }
2916: }
2917: if (oldVal < changedVal) {
2918: for (var k=oldVal+1; k<=changedVal ; k++) {
2919: var elementName = current[k];
2920: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2921: }
2922: } else {
2923: for (var k=changedVal; k<oldVal; k++) {
2924: var elementName = current[k];
2925: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2926: }
2927: }
2928: return;
2929: }
2930:
2931: // ]]>
2932: </script>
2933:
2934: ENDSCRIPT
2935: }
2936:
1.160.6.118.2 1(raebur 2937:1): sub ltitools_javascript {
2938:1): my ($settings) = @_;
2939:1): my $togglejs = <itools_toggle_js();
2940:1): unless (ref($settings) eq 'HASH') {
2941:1): return $togglejs;
2942:1): }
2943:1): my (%ordered,$total,%jstext);
2944:1): $total = 0;
2945:1): foreach my $item (keys(%{$settings})) {
2946:1): if (ref($settings->{$item}) eq 'HASH') {
2947:1): my $num = $settings->{$item}{'order'};
2948:1): $ordered{$num} = $item;
2949:1): }
2950:1): }
2951:1): $total = scalar(keys(%{$settings}));
2952:1): my @jsarray = ();
2953:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2954:1): push(@jsarray,$ordered{$item});
2955:1): }
2956:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2957:1): return <<"ENDSCRIPT";
2958:1): <script type="text/javascript">
2959:1): // <![CDATA[
2960:1): function reorderLTITools(form,item) {
2961:1): var changedVal;
2962:1): $jstext
2963:1): var newpos = 'ltitools_add_pos';
2964:1): var maxh = 1 + $total;
2965:1): var current = new Array;
2966:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2967:1): if (item == newpos) {
2968:1): changedVal = newitemVal;
2969:1): } else {
2970:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2971:1): current[newitemVal] = newpos;
2972:1): }
2973:1): for (var i=0; i<ltitools.length; i++) {
2974:1): var elementName = 'ltitools_'+ltitools[i];
2975:1): if (elementName != item) {
2976:1): if (form.elements[elementName]) {
2977:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2978:1): current[currVal] = elementName;
2979:1): }
2980:1): }
2981:1): }
2982:1): var oldVal;
2983:1): for (var j=0; j<maxh; j++) {
2984:1): if (current[j] == undefined) {
2985:1): oldVal = j;
2986:1): }
2987:1): }
2988:1): if (oldVal < changedVal) {
2989:1): for (var k=oldVal+1; k<=changedVal ; k++) {
2990:1): var elementName = current[k];
2991:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2992:1): }
2993:1): } else {
2994:1): for (var k=changedVal; k<oldVal; k++) {
2995:1): var elementName = current[k];
2996:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2997:1): }
2998:1): }
2999:1): return;
3000:1): }
3001:1):
3002:1): // ]]>
3003:1): </script>
3004:1):
3005:1): $togglejs
3006:1):
3007:1): ENDSCRIPT
3008:1): }
3009:1):
3010:1): sub ltitools_toggle_js {
3011:1): return <<"ENDSCRIPT";
3012:1): <script type="text/javascript">
3013:1): // <![CDATA[
3014:1):
3015:1): function toggleLTITools(form,setting,item) {
3016:1): var radioname = '';
3017:1): var divid = '';
3018:1): if (setting == 'user') {
3019:1): divid = 'ltitools_'+setting+'_div_'+item;
3020:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3021:1): if (document.getElementById(divid)) {
3022:1): if (document.getElementById(checkid)) {
3023:1): if (document.getElementById(checkid).checked) {
3024:1): document.getElementById(divid).style.display = 'inline-block';
3025:1): } else {
3026:1): document.getElementById(divid).style.display = 'none';
3027:1): }
3028:1): }
3029:1): }
3030:1): }
3031:1): return;
3032:1): }
3033:1): // ]]>
3034:1): </script>
3035:1):
3036:1): ENDSCRIPT
3037:1): }
3038:1):
1.160.6.113 raeburn 3039: sub wafproxy_javascript {
3040: my ($dom) = @_;
3041: return <<"ENDSCRIPT";
3042: <script type="text/javascript">
3043: // <![CDATA[
3044: function updateWAF() {
3045: if (document.getElementById('wafproxy_remoteip')) {
3046: var wafremote = 0;
3047: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3048: wafremote = 1;
3049: }
3050: var fields = new Array('header','trust');
3051: for (var i=0; i<fields.length; i++) {
3052: if (document.getElementById('wafproxy_'+fields[i])) {
3053: if (wafremote == 1) {
3054: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3055: }
3056: else {
3057: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3058: }
3059: }
3060: }
3061: if (document.getElementById('wafproxyranges_$dom')) {
3062: if (wafremote == 1) {
3063: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3064: } else {
3065: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3066: if (document.display.wafproxy_vpnaccess[i].checked) {
3067: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3068: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3069: }
3070: }
3071: }
3072: }
3073: }
3074: }
3075: return;
3076: }
3077:
3078: function checkWAF() {
3079: if (document.getElementById('wafproxy_remoteip')) {
3080: var wafvpn = 0;
3081: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3082: if (document.display.wafproxy_vpnaccess[i].checked) {
3083: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3084: wafvpn = 1;
3085: }
3086: break;
3087: }
3088: }
3089: var vpn = new Array('vpnint','vpnext');
3090: for (var i=0; i<vpn.length; i++) {
3091: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3092: if (wafvpn == 1) {
3093: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3094: }
3095: else {
3096: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3097: }
3098: }
3099: }
3100: if (document.getElementById('wafproxyranges_$dom')) {
3101: if (wafvpn == 1) {
3102: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3103: }
3104: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3105: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3106: }
3107: }
3108: }
3109: return;
3110: }
3111:
3112: function toggleWAF() {
3113: if (document.getElementById('wafproxy_table')) {
3114: var wafproxy = 0;
3115: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3116: if (document.display.wafproxy_${dom}[i].checked) {
3117: if (document.display.wafproxy_${dom}[i].value == 1) {
3118: wafproxy = 1;
3119: break;
3120: }
3121: }
3122: }
3123: if (wafproxy == 1) {
3124: document.getElementById('wafproxy_table').style.display='inline';
3125: }
3126: else {
3127: document.getElementById('wafproxy_table').style.display='none';
3128: }
3129: if (document.getElementById('wafproxyrow_${dom}')) {
3130: if (wafproxy == 1) {
3131: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3132: }
3133: else {
3134: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3135: }
3136: }
3137: if (document.getElementById('nowafproxyrow_$dom')) {
3138: if (wafproxy == 1) {
3139: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3140: }
3141: else {
3142: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3143: }
3144: }
3145: }
3146: return;
3147: }
3148: // ]]>
3149: </script>
3150:
3151: ENDSCRIPT
3152: }
3153:
1.160.6.118.2 5(raebur 3154:2): sub lti_javascript {
3155:2): my ($dom,$settings) = @_;
3156:2): my $togglejs = <i_toggle_js($dom);
3157:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
3158:2): return <<"ENDSCRIPT";
3159:2): <script type="text/javascript">
3160:2): // <![CDATA[
3161:2):
3162:2): $linkprot_js
3163:2):
3164:2): // ]]>
3165:2): </script>
3166:2):
3167:2): $togglejs
3168:2):
3169:2): ENDSCRIPT
3170:2): }
3171:2):
3172:2): sub lti_toggle_js {
3173:2): my ($dom) = @_;
3174:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3175:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3176:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3177:2): return <<"ENDSCRIPT";
3178:2): <script type="text/javascript">
3179:2): // <![CDATA[
5(raebur 3180:2): function toggleLTIEncKey(form) {
3181:2): var shownhosts = new Array();
3182:2): var hiddenhosts = new Array();
3183:2): var forcourse = new Array($course_servers);
3184:2): var fromdomain = '$primary';
3185:2): var crsradio = form.elements['ltisec_crslinkprot'];
3186:2): if (crsradio.length) {
3187:2): for (var i=0; i<crsradio.length; i++) {
3188:2): if (crsradio[i].checked) {
3189:2): if (crsradio[i].value == 1) {
3190:2): if (forcourse.length > 0) {
3191:2): for (var j=0; j<forcourse.length; j++) {
3192:2): if (!shownhosts.includes(forcourse[j])) {
3193:2): shownhosts.push(forcourse[j]);
3194:2): }
3195:2): }
3196:2): }
3197:2): } else {
3198:2): if (forcourse.length > 0) {
3199:2): for (var j=0; j<forcourse.length; j++) {
3200:2): if (!hiddenhosts.includes(forcourse[j])) {
3201:2): hiddenhosts.push(forcourse[j]);
3202:2): }
3203:2): }
3204:2): }
3205:2): }
3206:2): }
3207:2): }
3208:2): }
3209:2): var domradio = form.elements['ltisec_domlinkprot'];
3210:2): if (domradio.length) {
3211:2): for (var i=0; i<domradio.length; i++) {
3212:2): if (domradio[i].checked) {
3213:2): if (domradio[i].value == 1) {
3214:2): if (!shownhosts.includes(fromdomain)) {
3215:2): shownhosts.push(fromdomain);
3216:2): }
3217:2): } else {
3218:2): if (!hiddenhosts.includes(fromdomain)) {
3219:2): hiddenhosts.push(fromdomain);
3220:2): }
3221:2): }
3222:2): }
3223:2): }
3224:2): }
3225:2): if (shownhosts.length > 0) {
3226:2): for (var i=0; i<shownhosts.length; i++) {
3227:2): if (document.getElementById('ltisec_info_'+shownhosts[i])) {
3228:2): document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
3229:2): }
3230:2): }
3231:2): if (document.getElementById('ltisec_noprivkey')) {
3232:2): document.getElementById('ltisec_noprivkey').style.display = 'none';
3233:2): }
3234:2): } else {
3235:2): if (document.getElementById('ltisec_noprivkey')) {
3236:2): document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
3237:2): }
3238:2): }
3239:2): if (hiddenhosts.length > 0) {
3240:2): for (var i=0; i<hiddenhosts.length; i++) {
3241:2): if (!shownhosts.includes(hiddenhosts[i])) {
3242:2): if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
3243:2): document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
3244:2): }
3245:2): }
3246:2): }
3247:2): }
3248:2): return;
3249:2): }
3250:2):
3251:2): function togglePrivKey(form,hostid) {
3252:2): var radioname = '';
3253:2): var currdivid = '';
3254:2): var newdivid = '';
3255:2): if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
3256:2): (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
3257:2): currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
3258:2): newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
3259:2): radioname = form.elements['ltisec_changeprivkey_'+hostid];
3260:2): if (radioname) {
3261:2): if (radioname.length > 0) {
3262:2): var setvis;
3263:2): for (var i=0; i<radioname.length; i++) {
3264:2): if (radioname[i].checked == true) {
3265:2): if (radioname[i].value == 1) {
3266:2): newdivid.style.display = 'inline-block';
3267:2): currdivid.style.display = 'none';
3268:2): setvis = 1;
3269:2): }
3270:2): break;
3271:2): }
3272:2): }
3273:2): if (!setvis) {
3274:2): newdivid.style.display = 'none';
3275:2): currdivid.style.display = 'inline-block';
3276:2): }
3277:2): }
3278:2): }
3279:2): }
3280:2): }
3281:2):
3282:2): // ]]>
3283:2): </script>
3284:2):
3285:2): ENDSCRIPT
3286:2): }
3287:2):
1.160.6.113 raeburn 3288: sub autoupdate_javascript {
3289: return <<"ENDSCRIPT";
3290: <script type="text/javascript">
3291: // <![CDATA[
3292: function toggleLastActiveDays(form) {
3293: var radioname = 'lastactive';
3294: var divid = 'lastactive_div';
3295: var num = form.elements[radioname].length;
3296: if (num) {
3297: var setvis = '';
3298: for (var i=0; i<num; i++) {
3299: if (form.elements[radioname][i].checked) {
3300: if (form.elements[radioname][i].value == '1') {
3301: if (document.getElementById(divid)) {
3302: document.getElementById(divid).style.display = 'inline-block';
3303: }
3304: setvis = 1;
3305: }
3306: break;
3307: }
3308: }
3309: if (!setvis) {
3310: if (document.getElementById(divid)) {
3311: document.getElementById(divid).style.display = 'none';
3312: }
3313: }
3314: }
3315: return;
3316: }
3317: // ]]>
3318: </script>
3319:
3320: ENDSCRIPT
3321: }
3322:
1.160.6.116 raeburn 3323: sub autoenroll_javascript {
3324: return <<"ENDSCRIPT";
3325: <script type="text/javascript">
3326: // <![CDATA[
3327: function toggleFailsafe(form) {
3328: var radioname = 'autoenroll_failsafe';
3329: var divid = 'autoenroll_failsafe_div';
3330: var num = form.elements[radioname].length;
3331: if (num) {
3332: var setvis = '';
3333: for (var i=0; i<num; i++) {
3334: if (form.elements[radioname][i].checked) {
3335: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3336: if (document.getElementById(divid)) {
3337: document.getElementById(divid).style.display = 'inline-block';
3338: }
3339: setvis = 1;
3340: }
3341: break;
3342: }
3343: }
3344: if (!setvis) {
3345: if (document.getElementById(divid)) {
3346: document.getElementById(divid).style.display = 'none';
3347: }
3348: }
3349: }
3350: return;
3351: }
3352: // ]]>
3353: </script>
3354:
3355: ENDSCRIPT
3356: }
3357:
1.160.6.113 raeburn 3358: sub saml_javascript {
3359: return <<"ENDSCRIPT";
3360: <script type="text/javascript">
3361: // <![CDATA[
3362: function toggleSamlOptions(form,hostid) {
3363: var radioname = 'saml_'+hostid;
3364: var tablecellon = 'samloptionson_'+hostid;
3365: var tablecelloff = 'samloptionsoff_'+hostid;
3366: var num = form.elements[radioname].length;
3367: if (num) {
3368: var setvis = '';
3369: for (var i=0; i<num; i++) {
3370: if (form.elements[radioname][i].checked) {
3371: if (form.elements[radioname][i].value == '1') {
3372: if (document.getElementById(tablecellon)) {
3373: document.getElementById(tablecellon).style.display='';
3374: }
3375: if (document.getElementById(tablecelloff)) {
3376: document.getElementById(tablecelloff).style.display='none';
3377: }
3378: setvis = 1;
3379: }
3380: break;
3381: }
3382: }
3383: if (!setvis) {
3384: if (document.getElementById(tablecellon)) {
3385: document.getElementById(tablecellon).style.display='none';
3386: }
3387: if (document.getElementById(tablecelloff)) {
3388: document.getElementById(tablecelloff).style.display='';
3389: }
3390: }
3391: }
3392: return;
3393: }
3394: // ]]>
3395: </script>
3396:
3397: ENDSCRIPT
3398: }
3399:
3400: sub ipaccess_javascript {
3401: my ($settings) = @_;
3402: my (%ordered,$total,%jstext);
3403: $total = 0;
3404: if (ref($settings) eq 'HASH') {
3405: foreach my $item (keys(%{$settings})) {
3406: if (ref($settings->{$item}) eq 'HASH') {
3407: my $num = $settings->{$item}{'order'};
3408: $ordered{$num} = $item;
3409: }
3410: }
3411: $total = scalar(keys(%{$settings}));
3412: }
3413: my @jsarray = ();
3414: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3415: push(@jsarray,$ordered{$item});
3416: }
3417: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3418: return <<"ENDSCRIPT";
3419: <script type="text/javascript">
3420: // <![CDATA[
3421: function reorderIPaccess(form,item) {
3422: var changedVal;
3423: $jstext
3424: var newpos = 'ipaccess_pos_add';
3425: var maxh = 1 + $total;
3426: var current = new Array;
3427: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3428: if (item == newpos) {
3429: changedVal = newitemVal;
3430: } else {
3431: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3432: current[newitemVal] = newpos;
3433: }
3434: for (var i=0; i<ipaccess.length; i++) {
3435: var elementName = 'ipaccess_pos_'+ipaccess[i];
3436: if (elementName != item) {
3437: if (form.elements[elementName]) {
3438: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3439: current[currVal] = elementName;
3440: }
3441: }
3442: }
3443: var oldVal;
3444: for (var j=0; j<maxh; j++) {
3445: if (current[j] == undefined) {
3446: oldVal = j;
3447: }
3448: }
3449: if (oldVal < changedVal) {
3450: for (var k=oldVal+1; k<=changedVal ; k++) {
3451: var elementName = current[k];
3452: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3453: }
3454: } else {
3455: for (var k=changedVal; k<oldVal; k++) {
3456: var elementName = current[k];
3457: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3458: }
3459: }
3460: return;
3461: }
3462: // ]]>
3463: </script>
3464:
3465: ENDSCRIPT
3466: }
3467:
1.3 raeburn 3468: sub print_autoenroll {
1.30 raeburn 3469: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3470: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3471: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3472: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3473: $failsafesty = 'none';
3474: %failsafechecked = (
3475: off => ' checked="checked"',
3476: );
1.3 raeburn 3477: if (ref($settings) eq 'HASH') {
3478: if (exists($settings->{'run'})) {
3479: if ($settings->{'run'} eq '0') {
3480: $runoff = ' checked="checked" ';
3481: $runon = ' ';
3482: } else {
3483: $runon = ' checked="checked" ';
3484: $runoff = ' ';
3485: }
3486: } else {
3487: if ($autorun) {
3488: $runon = ' checked="checked" ';
3489: $runoff = ' ';
3490: } else {
3491: $runoff = ' checked="checked" ';
3492: $runon = ' ';
3493: }
3494: }
1.129 raeburn 3495: if (exists($settings->{'co-owners'})) {
3496: if ($settings->{'co-owners'} eq '0') {
3497: $coownersoff = ' checked="checked" ';
3498: $coownerson = ' ';
3499: } else {
3500: $coownerson = ' checked="checked" ';
3501: $coownersoff = ' ';
3502: }
3503: } else {
3504: $coownersoff = ' checked="checked" ';
3505: $coownerson = ' ';
3506: }
1.3 raeburn 3507: if (exists($settings->{'sender_domain'})) {
3508: $defdom = $settings->{'sender_domain'};
3509: }
1.160.6.116 raeburn 3510: if (exists($settings->{'failsafe'})) {
3511: $failsafe = $settings->{'failsafe'};
3512: if ($failsafe eq 'zero') {
3513: $failsafechecked{'zero'} = ' checked="checked"';
3514: $failsafechecked{'off'} = '';
3515: $failsafesty = 'inline-block';
3516: } elsif ($failsafe eq 'any') {
3517: $failsafechecked{'any'} = ' checked="checked"';
3518: $failsafechecked{'off'} = '';
3519: }
3520: $autofailsafe = $settings->{'autofailsafe'};
3521: } elsif (exists($settings->{'autofailsafe'})) {
3522: $autofailsafe = $settings->{'autofailsafe'};
3523: if ($autofailsafe ne '') {
3524: $failsafechecked{'zero'} = ' checked="checked"';
3525: $failsafe = 'zero';
3526: $failsafechecked{'off'} = '';
3527: }
1.160.6.68 raeburn 3528: }
1.14 raeburn 3529: } else {
3530: if ($autorun) {
3531: $runon = ' checked="checked" ';
3532: $runoff = ' ';
3533: } else {
3534: $runoff = ' checked="checked" ';
3535: $runon = ' ';
3536: }
1.3 raeburn 3537: }
3538: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3539: my $notif_sender;
3540: if (ref($settings) eq 'HASH') {
3541: $notif_sender = $settings->{'sender_uname'};
3542: }
1.3 raeburn 3543: my $datatable='<tr class="LC_odd_row">'.
3544: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3545: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3546: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3547: $runon.' value="1" />'.&mt('Yes').'</label> '.
3548: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3549: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3550: '</tr><tr>'.
3551: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3552: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3553: &mt('username').': '.
3554: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3555: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3556: ': '.$domform.'</span></td></tr>'.
3557: '<tr class="LC_odd_row">'.
3558: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3559: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3560: '<input type="radio" name="autoassign_coowners"'.
3561: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3562: '<label><input type="radio" name="autoassign_coowners"'.
3563: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3564: '</tr><tr>'.
3565: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3566: '<td class="LC_left_item"><span class="LC_nobreak">'.
3567: '<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> '.
3568: '<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 />'.
3569: '<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>'.
3570: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3571: '<span class="LC_nobreak">'.
3572: &mt('Threshold for number of students in section to drop: [_1]',
3573: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3574: '</span></div></td></tr>';
1.160.6.68 raeburn 3575: $$rowtotal += 4;
1.3 raeburn 3576: return $datatable;
3577: }
3578:
3579: sub print_autoupdate {
1.30 raeburn 3580: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3581: my ($enable,$datatable);
1.3 raeburn 3582: if ($position eq 'top') {
1.160.6.113 raeburn 3583: my %choices = &Apache::lonlocal::texthash (
3584: run => 'Auto-update active?',
3585: classlists => 'Update information in classlists?',
3586: unexpired => 'Skip updates for users without active or future roles?',
3587: lastactive => 'Skip updates for inactive users?',
3588: );
3589: my $itemcount = 0;
1.3 raeburn 3590: my $updateon = ' ';
3591: my $updateoff = ' checked="checked" ';
3592: if (ref($settings) eq 'HASH') {
3593: if ($settings->{'run'} eq '1') {
3594: $updateon = $updateoff;
3595: $updateoff = ' ';
3596: }
3597: }
1.160.6.113 raeburn 3598: $enable = '<tr class="LC_odd_row">'.
3599: '<td>'.&mt($choices{'run'}).'</td>'.
3600: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3601: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3602: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3603: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3604: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3605: '</tr>';
1.160.6.113 raeburn 3606: my @toggles = ('classlists','unexpired');
3607: my %defaultchecked = ('classlists' => 'off',
3608: 'unexpired' => 'off'
3609: );
3610: $$rowtotal ++;
3611: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3612: \%choices,$itemcount,'','','left','no');
3613: $datatable = $enable.$datatable;
3614: $$rowtotal += $itemcount;
3615: my $lastactiveon = ' ';
3616: my $lastactiveoff = ' checked="checked" ';
3617: my $lastactivestyle = 'none';
3618: my $lastactivedays;
3619: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3620: if (ref($settings) eq 'HASH') {
3621: if ($settings->{'lastactive'} =~ /^\d+$/) {
3622: $lastactiveon = $lastactiveoff;
3623: $lastactiveoff = ' ';
3624: $lastactivestyle = 'inline-block';
3625: $lastactivedays = $settings->{'lastactive'};
3626: }
3627: }
3628: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3629: $datatable .= '<tr'.$css_class.'>'.
3630: '<td>'.$choices{'lastactive'}.'</td>'.
3631: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3632: '<input type="radio" name="lastactive"'.
3633: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3634: ' <label>'.
3635: '<input type="radio" name="lastactive"'.
3636: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3637: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3638: ': '.&mt('inactive = no activity in last [_1] days',
3639: '<input type="text" size="5" name="lastactivedays" value="'.
3640: $lastactivedays.'" />').
3641: '</span></td>'.
3642: '</tr>';
3643: $$rowtotal ++;
1.131 raeburn 3644: } elsif ($position eq 'middle') {
3645: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3646: my $numinrow = 3;
3647: my $locknamesettings;
3648: $datatable .= &insttypes_row($settings,$types,$usertypes,
3649: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3650: 'lockablenames',$rowtotal);
1.131 raeburn 3651: $$rowtotal ++;
1.3 raeburn 3652: } else {
1.44 raeburn 3653: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3654: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3655: 'permanentemail','id');
1.33 raeburn 3656: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3657: my $numrows = 0;
1.26 raeburn 3658: if (ref($types) eq 'ARRAY') {
3659: if (@{$types} > 0) {
3660: $datatable =
3661: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3662: \@fields,$types,\$numrows);
1.30 raeburn 3663: $$rowtotal += @{$types};
1.26 raeburn 3664: }
1.3 raeburn 3665: }
3666: $datatable .=
3667: &usertype_update_row($settings,{'default' => $othertitle},
3668: \%fieldtitles,\@fields,['default'],
3669: \$numrows);
1.30 raeburn 3670: $$rowtotal ++;
1.3 raeburn 3671: }
3672: return $datatable;
3673: }
3674:
1.125 raeburn 3675: sub print_autocreate {
3676: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3677: my (%createon,%createoff,%currhash);
1.125 raeburn 3678: my @types = ('xml','req');
3679: if (ref($settings) eq 'HASH') {
3680: foreach my $item (@types) {
3681: $createoff{$item} = ' checked="checked" ';
3682: $createon{$item} = ' ';
3683: if (exists($settings->{$item})) {
3684: if ($settings->{$item}) {
3685: $createon{$item} = ' checked="checked" ';
3686: $createoff{$item} = ' ';
3687: }
3688: }
3689: }
1.160.6.16 raeburn 3690: if ($settings->{'xmldc'} ne '') {
3691: $currhash{$settings->{'xmldc'}} = 1;
3692: }
1.125 raeburn 3693: } else {
3694: foreach my $item (@types) {
3695: $createoff{$item} = ' checked="checked" ';
3696: $createon{$item} = ' ';
3697: }
3698: }
3699: $$rowtotal += 2;
1.160.6.16 raeburn 3700: my $numinrow = 2;
1.125 raeburn 3701: my $datatable='<tr class="LC_odd_row">'.
3702: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3703: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3704: '<input type="radio" name="autocreate_xml"'.
3705: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3706: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3707: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3708: '</td></tr><tr>'.
3709: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3710: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3711: '<input type="radio" name="autocreate_req"'.
3712: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3713: '<label><input type="radio" name="autocreate_req"'.
3714: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3715: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3716: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3717: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3718: if ($numdc > 1) {
1.160.6.50 raeburn 3719: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3720: '</td><td class="LC_left_item">';
1.125 raeburn 3721: } else {
1.160.6.50 raeburn 3722: $datatable .= &mt('Course creation processed as:').
3723: '</td><td class="LC_right_item">';
1.125 raeburn 3724: }
1.160.6.50 raeburn 3725: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3726: $$rowtotal += $rows;
1.125 raeburn 3727: return $datatable;
3728: }
3729:
1.23 raeburn 3730: sub print_directorysrch {
1.160.6.72 raeburn 3731: my ($position,$dom,$settings,$rowtotal) = @_;
3732: my $datatable;
3733: if ($position eq 'top') {
3734: my $instsrchon = ' ';
3735: my $instsrchoff = ' checked="checked" ';
3736: my ($exacton,$containson,$beginson);
3737: my $instlocalon = ' ';
3738: my $instlocaloff = ' checked="checked" ';
3739: if (ref($settings) eq 'HASH') {
3740: if ($settings->{'available'} eq '1') {
3741: $instsrchon = $instsrchoff;
3742: $instsrchoff = ' ';
3743: }
3744: if ($settings->{'localonly'} eq '1') {
3745: $instlocalon = $instlocaloff;
3746: $instlocaloff = ' ';
3747: }
3748: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3749: foreach my $type (@{$settings->{'searchtypes'}}) {
3750: if ($type eq 'exact') {
3751: $exacton = ' checked="checked" ';
3752: } elsif ($type eq 'contains') {
3753: $containson = ' checked="checked" ';
3754: } elsif ($type eq 'begins') {
3755: $beginson = ' checked="checked" ';
3756: }
3757: }
3758: } else {
3759: if ($settings->{'searchtypes'} eq 'exact') {
3760: $exacton = ' checked="checked" ';
3761: } elsif ($settings->{'searchtypes'} eq 'contains') {
3762: $containson = ' checked="checked" ';
3763: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3764: $exacton = ' checked="checked" ';
3765: $containson = ' checked="checked" ';
3766: }
3767: }
1.23 raeburn 3768: }
1.160.6.72 raeburn 3769: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3770: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3771:
1.160.6.72 raeburn 3772: my $numinrow = 4;
3773: my $cansrchrow = 0;
3774: $datatable='<tr class="LC_odd_row">'.
3775: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3776: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3777: '<input type="radio" name="dirsrch_available"'.
3778: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3779: '<label><input type="radio" name="dirsrch_available"'.
3780: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3781: '</tr><tr>'.
3782: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3783: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3784: '<input type="radio" name="dirsrch_instlocalonly"'.
3785: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3786: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3787: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3788: '</tr>';
3789: $$rowtotal += 2;
3790: if (ref($usertypes) eq 'HASH') {
3791: if (keys(%{$usertypes}) > 0) {
3792: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3793: $numinrow,$othertitle,'cansearch',
3794: $rowtotal);
1.160.6.72 raeburn 3795: $cansrchrow = 1;
3796: }
1.26 raeburn 3797: }
1.160.6.72 raeburn 3798: if ($cansrchrow) {
3799: $$rowtotal ++;
3800: $datatable .= '<tr>';
3801: } else {
3802: $datatable .= '<tr class="LC_odd_row">';
3803: }
3804: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3805: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3806: foreach my $title (@{$titleorder}) {
3807: if (defined($searchtitles->{$title})) {
3808: my $check = ' ';
3809: if (ref($settings) eq 'HASH') {
3810: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3811: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3812: $check = ' checked="checked" ';
3813: }
1.39 raeburn 3814: }
1.25 raeburn 3815: }
1.160.6.72 raeburn 3816: $datatable .= '<td class="LC_left_item">'.
3817: '<span class="LC_nobreak"><label>'.
3818: '<input type="checkbox" name="searchby" '.
3819: 'value="'.$title.'"'.$check.'/>'.
3820: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3821: }
3822: }
1.160.6.72 raeburn 3823: $datatable .= '</tr></table></td></tr>';
3824: $$rowtotal ++;
3825: if ($cansrchrow) {
3826: $datatable .= '<tr class="LC_odd_row">';
3827: } else {
3828: $datatable .= '<tr>';
3829: }
3830: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3831: '<td class="LC_left_item" colspan="2">'.
3832: '<span class="LC_nobreak"><label>'.
3833: '<input type="checkbox" name="searchtypes" '.
3834: $exacton.' value="exact" />'.&mt('Exact match').
3835: '</label> '.
3836: '<label><input type="checkbox" name="searchtypes" '.
3837: $beginson.' value="begins" />'.&mt('Begins with').
3838: '</label> '.
3839: '<label><input type="checkbox" name="searchtypes" '.
3840: $containson.' value="contains" />'.&mt('Contains').
3841: '</label></span></td></tr>';
3842: $$rowtotal ++;
1.26 raeburn 3843: } else {
1.160.6.72 raeburn 3844: my $domsrchon = ' checked="checked" ';
3845: my $domsrchoff = ' ';
3846: my $domlocalon = ' ';
3847: my $domlocaloff = ' checked="checked" ';
3848: if (ref($settings) eq 'HASH') {
3849: if ($settings->{'lclocalonly'} eq '1') {
3850: $domlocalon = $domlocaloff;
3851: $domlocaloff = ' ';
3852: }
3853: if ($settings->{'lcavailable'} eq '0') {
3854: $domsrchoff = $domsrchon;
3855: $domsrchon = ' ';
3856: }
3857: }
3858: $datatable='<tr class="LC_odd_row">'.
3859: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3860: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3861: '<input type="radio" name="dirsrch_domavailable"'.
3862: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3863: '<label><input type="radio" name="dirsrch_domavailable"'.
3864: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3865: '</tr><tr>'.
3866: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3867: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3868: '<input type="radio" name="dirsrch_domlocalonly"'.
3869: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3870: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3871: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3872: '</tr>';
3873: $$rowtotal += 2;
1.26 raeburn 3874: }
1.25 raeburn 3875: return $datatable;
3876: }
3877:
1.28 raeburn 3878: sub print_contacts {
1.160.6.78 raeburn 3879: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3880: my $datatable;
3881: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3882: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3883: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3884: if ($position eq 'top') {
3885: if (ref($settings) eq 'HASH') {
3886: foreach my $item (@contacts) {
3887: if (exists($settings->{$item})) {
3888: $to{$item} = $settings->{$item};
3889: }
1.28 raeburn 3890: }
3891: }
1.160.6.78 raeburn 3892: } elsif ($position eq 'middle') {
3893: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3894: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3895: foreach my $type (@mailings) {
1.160.6.78 raeburn 3896: $otheremails{$type} = '';
3897: }
1.160.6.107 raeburn 3898: } elsif ($position eq 'lower') {
3899: if (ref($settings) eq 'HASH') {
3900: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3901: %lonstatus = %{$settings->{'lonstatus'}};
3902: }
3903: }
1.160.6.78 raeburn 3904: } else {
3905: @mailings = ('helpdeskmail','otherdomsmail');
3906: foreach my $type (@mailings) {
3907: $otheremails{$type} = '';
3908: }
3909: $bccemails{'helpdeskmail'} = '';
3910: $bccemails{'otherdomsmail'} = '';
3911: $includestr{'helpdeskmail'} = '';
3912: $includestr{'otherdomsmail'} = '';
3913: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3914: }
3915: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3916: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3917: foreach my $type (@mailings) {
3918: if (exists($settings->{$type})) {
3919: if (ref($settings->{$type}) eq 'HASH') {
3920: foreach my $item (@contacts) {
3921: if ($settings->{$type}{$item}) {
3922: $checked{$type}{$item} = ' checked="checked" ';
3923: }
1.28 raeburn 3924: }
1.160.6.78 raeburn 3925: $otheremails{$type} = $settings->{$type}{'others'};
3926: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3927: $bccemails{$type} = $settings->{$type}{'bcc'};
3928: if ($settings->{$type}{'include'} ne '') {
3929: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3930: $includestr{$type} = &unescape($includestr{$type});
3931: }
3932: }
3933: }
3934: } elsif ($type eq 'lonstatusmail') {
3935: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3936: }
3937: }
3938: }
3939: if ($position eq 'bottom') {
3940: foreach my $type (@mailings) {
3941: $bccemails{$type} = $settings->{$type}{'bcc'};
3942: if ($settings->{$type}{'include'} ne '') {
3943: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3944: $includestr{$type} = &unescape($includestr{$type});
3945: }
3946: }
3947: if (ref($settings->{'helpform'}) eq 'HASH') {
3948: if (ref($fields) eq 'ARRAY') {
3949: foreach my $field (@{$fields}) {
3950: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3951: }
1.160.6.78 raeburn 3952: }
3953: if (exists($settings->{'helpform'}{'maxsize'})) {
3954: $maxsize = $settings->{'helpform'}{'maxsize'};
3955: } else {
3956: $maxsize = '1.0';
3957: }
3958: } else {
3959: if (ref($fields) eq 'ARRAY') {
3960: foreach my $field (@{$fields}) {
3961: $currfield{$field} = 'yes';
1.134 raeburn 3962: }
1.28 raeburn 3963: }
1.160.6.78 raeburn 3964: $maxsize = '1.0';
1.28 raeburn 3965: }
3966: }
3967: } else {
1.160.6.78 raeburn 3968: if ($position eq 'top') {
3969: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3970: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3971: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3972: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3973: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3974: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3975: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3976: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3977: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3978: } elsif ($position eq 'bottom') {
3979: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3980: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3981: if (ref($fields) eq 'ARRAY') {
3982: foreach my $field (@{$fields}) {
3983: $currfield{$field} = 'yes';
3984: }
3985: }
3986: $maxsize = '1.0';
3987: }
1.28 raeburn 3988: }
3989: my ($titles,$short_titles) = &contact_titles();
3990: my $rownum = 0;
3991: my $css_class;
1.160.6.78 raeburn 3992: if ($position eq 'top') {
3993: foreach my $item (@contacts) {
3994: $css_class = $rownum%2?' class="LC_odd_row"':'';
3995: $datatable .= '<tr'.$css_class.'>'.
3996: '<td><span class="LC_nobreak">'.$titles->{$item}.
3997: '</span></td><td class="LC_right_item">'.
3998: '<input type="text" name="'.$item.'" value="'.
3999: $to{$item}.'" /></td></tr>';
4000: $rownum ++;
4001: }
1.160.6.101 raeburn 4002: } elsif ($position eq 'bottom') {
4003: $css_class = $rownum%2?' class="LC_odd_row"':'';
4004: $datatable .= '<tr'.$css_class.'>'.
4005: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4006: &mt('(e-mail, subject, and description always shown)').
4007: '</td><td class="LC_left_item">';
4008: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4009: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4010: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4011: foreach my $field (@{$fields}) {
4012: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4013: if (($field eq 'screenshot') || ($field eq 'cc')) {
4014: $datatable .= ' '.&mt('(logged-in users)');
4015: }
4016: $datatable .='</td><td>';
4017: my $clickaction;
4018: if ($field eq 'screenshot') {
4019: $clickaction = ' onclick="screenshotSize(this);"';
4020: }
4021: if (ref($possoptions->{$field}) eq 'ARRAY') {
4022: foreach my $option (@{$possoptions->{$field}}) {
4023: my $checked;
4024: if ($currfield{$field} eq $option) {
4025: $checked = ' checked="checked"';
4026: }
4027: $datatable .= '<span class="LC_nobreak"><label>'.
4028: '<input type="radio" name="helpform_'.$field.'" '.
4029: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4030: '</label></span>'.(' 'x2);
4031: }
4032: }
4033: if ($field eq 'screenshot') {
4034: my $display;
4035: if ($currfield{$field} eq 'no') {
4036: $display = ' style="display:none"';
4037: }
4038: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4039: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4040: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4041: }
4042: $datatable .= '</td></tr>';
4043: }
4044: $datatable .= '</table>';
4045: }
4046: $datatable .= '</td></tr>'."\n";
4047: $rownum ++;
4048: }
1.160.6.107 raeburn 4049: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4050: foreach my $type (@mailings) {
4051: $css_class = $rownum%2?' class="LC_odd_row"':'';
4052: $datatable .= '<tr'.$css_class.'>'.
4053: '<td><span class="LC_nobreak">'.
4054: $titles->{$type}.': </span></td>'.
4055: '<td class="LC_left_item">';
4056: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4057: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4058: }
4059: $datatable .= '<span class="LC_nobreak">';
4060: foreach my $item (@contacts) {
4061: $datatable .= '<label>'.
4062: '<input type="checkbox" name="'.$type.'"'.
4063: $checked{$type}{$item}.
4064: ' value="'.$item.'" />'.$short_titles->{$item}.
4065: '</label> ';
4066: }
4067: $datatable .= '</span><br />'.&mt('Others').': '.
4068: '<input type="text" name="'.$type.'_others" '.
4069: 'value="'.$otheremails{$type}.'" />';
4070: my %locchecked;
4071: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4072: foreach my $loc ('s','b') {
4073: if ($includeloc{$type} eq $loc) {
4074: $locchecked{$loc} = ' checked="checked"';
4075: last;
4076: }
4077: }
4078: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4079: '<input type="text" name="'.$type.'_bcc" '.
4080: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4081: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4082: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4083: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4084: '<span class="LC_nobreak">'.&mt('Location:').' '.
4085: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4086: (' 'x2).
4087: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4088: '</span></fieldset>';
4089: }
4090: $datatable .= '</td></tr>'."\n";
4091: $rownum ++;
4092: }
1.28 raeburn 4093: }
1.160.6.78 raeburn 4094: if ($position eq 'middle') {
4095: my %choices;
1.160.6.107 raeburn 4096: my $corelink = &core_link_msu();
4097: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4098: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4099: $corelink);
4100: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4101: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4102: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4103: 'reportupdates' => 'on',
4104: 'reportstatus' => 'on');
1.160.6.78 raeburn 4105: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4106: \%choices,$rownum);
4107: $datatable .= $reports;
1.160.6.107 raeburn 4108: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4109: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4110: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4111: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4112: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4113: } else {
1.160.6.109 raeburn 4114: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4115: }
4116: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4117: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4118: } else {
1.160.6.109 raeburn 4119: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4120: }
4121: if (ref($lonstatus{'weights'}) eq 'HASH') {
4122: foreach my $type ('E','W','N','U') {
4123: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4124: $weights{$type} = $lonstatus{'weights'}{$type};
4125: } else {
4126: $weights{$type} = $defaults->{$type};
4127: }
4128: }
4129: } else {
4130: foreach my $type ('E','W','N','U') {
4131: $weights{$type} = $defaults->{$type};
4132: }
4133: }
4134: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4135: if (@{$lonstatus{'excluded'}} > 0) {
4136: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4137: }
4138: }
1.160.6.109 raeburn 4139: foreach my $item ('errorthreshold','errorsysmail') {
4140: $css_class = $rownum%2?' class="LC_odd_row"':'';
4141: $datatable .= '<tr'.$css_class.'>'.
4142: '<td class="LC_left_item"><span class="LC_nobreak">'.
4143: $titles->{$item}.
4144: '</span></td><td class="LC_left_item">'.
4145: '<input type="text" name="'.$item.'" value="'.
4146: $current{$item}.'" size="5" /></td></tr>';
4147: $rownum ++;
4148: }
1.160.6.107 raeburn 4149: $css_class = $rownum%2?' class="LC_odd_row"':'';
4150: $datatable .= '<tr'.$css_class.'>'.
4151: '<td class="LC_left_item">'.
4152: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4153: '</span></td><td class="LC_left_item"><table><tr>';
4154: foreach my $type ('E','W','N','U') {
4155: $datatable .= '<td>'.$names->{$type}.'<br />'.
4156: '<input type="text" name="errorweights_'.$type.'" value="'.
4157: $weights{$type}.'" size="5" /></td>';
4158: }
4159: $datatable .= '</tr></table></tr>';
4160: $rownum ++;
4161: $css_class = $rownum%2?' class="LC_odd_row"':'';
4162: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4163: $titles->{'errorexcluded'}.'</td>'.
4164: '<td class="LC_left_item"><table>';
4165: my $numinrow = 4;
4166: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4167: for (my $i=0; $i<@ids; $i++) {
4168: my $rem = $i%($numinrow);
4169: if ($rem == 0) {
4170: if ($i > 0) {
4171: $datatable .= '</tr>';
4172: }
4173: $datatable .= '<tr>';
4174: }
4175: my $check;
4176: if ($excluded{$ids[$i]}) {
4177: $check = ' checked="checked" ';
4178: }
4179: $datatable .= '<td class="LC_left_item">'.
4180: '<span class="LC_nobreak"><label>'.
4181: '<input type="checkbox" name="errorexcluded" '.
4182: 'value="'.$ids[$i].'"'.$check.' />'.
4183: $ids[$i].'</label></span></td>';
4184: }
4185: my $colsleft = $numinrow - @ids%($numinrow);
4186: if ($colsleft > 1 ) {
4187: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4188: ' </td>';
4189: } elsif ($colsleft == 1) {
4190: $datatable .= '<td class="LC_left_item"> </td>';
4191: }
4192: $datatable .= '</tr></table></td></tr>';
4193: $rownum ++;
1.160.6.78 raeburn 4194: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4195: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4196: my (@posstypes,%usertypeshash);
4197: if (ref($types) eq 'ARRAY') {
4198: @posstypes = @{$types};
4199: }
4200: if (@posstypes) {
4201: if (ref($usertypes) eq 'HASH') {
4202: %usertypeshash = %{$usertypes};
4203: }
4204: my @overridden;
4205: my $numinrow = 4;
4206: if (ref($settings) eq 'HASH') {
4207: if (ref($settings->{'overrides'}) eq 'HASH') {
4208: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4209: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4210: push(@overridden,$key);
4211: foreach my $item (@contacts) {
4212: if ($settings->{'overrides'}{$key}{$item}) {
4213: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4214: }
4215: }
4216: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4217: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4218: $includeloc{'override_'.$key} = '';
4219: $includestr{'override_'.$key} = '';
4220: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4221: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4222: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4223: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4224: }
1.160.6.78 raeburn 4225: }
4226: }
4227: }
1.160.6.101 raeburn 4228: }
4229: my $customclass = 'LC_helpdesk_override';
4230: my $optionsprefix = 'LC_options_helpdesk_';
4231:
4232: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4233:
4234: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4235: $numinrow,$othertitle,'overrides',
4236: \$rownum,$onclicktypes,$customclass);
4237: $rownum ++;
4238: $usertypeshash{'default'} = $othertitle;
4239: foreach my $status (@posstypes) {
4240: my $css_class;
4241: if ($rownum%2) {
4242: $css_class = 'LC_odd_row ';
4243: }
4244: $css_class .= $customclass;
4245: my $rowid = $optionsprefix.$status;
4246: my $hidden = 1;
4247: my $currstyle = 'display:none';
4248: if (grep(/^\Q$status\E$/,@overridden)) {
4249: $currstyle = 'display:table-row';
4250: $hidden = 0;
4251: }
4252: my $key = 'override_'.$status;
4253: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4254: $includeloc{$key},$includestr{$key},$status,$rowid,
4255: $usertypeshash{$status},$css_class,$currstyle,
4256: \@contacts,$short_titles);
4257: unless ($hidden) {
4258: $rownum ++;
1.160.6.78 raeburn 4259: }
4260: }
1.134 raeburn 4261: }
1.28 raeburn 4262: }
1.30 raeburn 4263: $$rowtotal += $rownum;
1.28 raeburn 4264: return $datatable;
4265: }
4266:
1.160.6.107 raeburn 4267: sub core_link_msu {
4268: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4269: &mt('LON-CAPA core group - MSU'),600,500);
4270: }
4271:
1.160.6.101 raeburn 4272: sub overridden_helpdesk {
4273: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4274: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4275: my $class = 'LC_left_item';
4276: if ($css_class) {
4277: $css_class = ' class="'.$css_class.'"';
4278: }
4279: if ($rowid) {
4280: $rowid = ' id="'.$rowid.'"';
4281: }
4282: if ($rowstyle) {
4283: $rowstyle = ' style="'.$rowstyle.'"';
4284: }
4285: my ($output,$description);
4286: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4287: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4288: "<td>$description</td>\n".
4289: '<td class="'.$class.'" colspan="2">'.
4290: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4291: '<span class="LC_nobreak">';
4292: if (ref($contacts) eq 'ARRAY') {
4293: foreach my $item (@{$contacts}) {
4294: my $check;
4295: if (ref($checked) eq 'HASH') {
4296: $check = $checked->{$item};
4297: }
4298: my $title;
4299: if (ref($short_titles) eq 'HASH') {
4300: $title = $short_titles->{$item};
4301: }
4302: $output .= '<label>'.
4303: '<input type="checkbox" name="override_'.$type.'"'.$check.
4304: ' value="'.$item.'" />'.$title.'</label> ';
4305: }
4306: }
4307: $output .= '</span><br />'.&mt('Others').': '.
4308: '<input type="text" name="override_'.$type.'_others" '.
4309: 'value="'.$otheremails.'" />';
4310: my %locchecked;
4311: foreach my $loc ('s','b') {
4312: if ($includeloc eq $loc) {
4313: $locchecked{$loc} = ' checked="checked"';
4314: last;
4315: }
4316: }
4317: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4318: '<input type="text" name="override_'.$type.'_bcc" '.
4319: 'value="'.$bccemails.'" /></fieldset>'.
4320: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4321: &mt('Text automatically added to e-mail:').' '.
4322: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4323: '<span class="LC_nobreak">'.&mt('Location:').' '.
4324: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4325: (' 'x2).
4326: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4327: '</span></fieldset>'.
4328: '</td></tr>'."\n";
4329: return $output;
4330: }
4331:
1.160.6.78 raeburn 4332: sub contacts_javascript {
4333: return <<"ENDSCRIPT";
4334:
4335: <script type="text/javascript">
4336: // <![CDATA[
4337:
4338: function screenshotSize(field) {
4339: if (document.getElementById('help_screenshotsize')) {
4340: if (field.value == 'no') {
4341: document.getElementById('help_screenshotsize').style.display="none";
4342: } else {
4343: document.getElementById('help_screenshotsize').style.display="";
4344: }
4345: }
4346: return;
4347: }
4348:
1.160.6.101 raeburn 4349: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4350: if (form.elements[checkbox].length != undefined) {
4351: var count = 0;
4352: if (docount) {
4353: for (var i=0; i<form.elements[checkbox].length; i++) {
4354: if (form.elements[checkbox][i].checked) {
4355: count ++;
4356: }
4357: }
4358: }
4359: for (var i=0; i<form.elements[checkbox].length; i++) {
4360: var type = form.elements[checkbox][i].value;
4361: if (document.getElementById(prefix+type)) {
4362: if (form.elements[checkbox][i].checked) {
4363: document.getElementById(prefix+type).style.display = 'table-row';
4364: if (count % 2 == 1) {
4365: document.getElementById(prefix+type).className = target+' LC_odd_row';
4366: } else {
4367: document.getElementById(prefix+type).className = target;
4368: }
4369: count ++;
4370: } else {
4371: document.getElementById(prefix+type).style.display = 'none';
4372: }
4373: }
4374: }
4375: }
4376: return;
4377: }
4378:
1.160.6.78 raeburn 4379: // ]]>
4380: </script>
4381:
4382: ENDSCRIPT
4383: }
4384:
1.118 jms 4385: sub print_helpsettings {
1.160.6.73 raeburn 4386: my ($position,$dom,$settings,$rowtotal) = @_;
4387: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4388: my $formname = 'display';
1.160.6.5 raeburn 4389: my ($datatable,$itemcount);
1.160.6.73 raeburn 4390: if ($position eq 'top') {
4391: $itemcount = 1;
4392: my (%choices,%defaultchecked,@toggles);
4393: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4394: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4395: &mt('LON-CAPA bug tracker'),600,500));
4396: %defaultchecked = ('submitbugs' => 'on');
4397: @toggles = ('submitbugs');
4398: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4399: \%choices,$itemcount);
4400: $$rowtotal ++;
4401: } else {
4402: my $css_class;
4403: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4404: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4405: if (ref($settings) eq 'HASH') {
4406: if (ref($settings->{'adhoc'}) eq 'HASH') {
4407: %current = %{$settings->{'adhoc'}};
4408: }
1.160.6.77 raeburn 4409: }
4410: my $count = 0;
4411: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4412: if ($key=~/^rolesdef\_(\w+)$/) {
4413: my $rolename = $1;
1.160.6.77 raeburn 4414: my (%privs,$order);
1.160.6.73 raeburn 4415: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4416: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4417: if (ref($current{$rolename}) eq 'HASH') {
4418: $order = $current{$rolename}{'order'};
4419: }
4420: if ($order eq '') {
4421: $order = $count;
4422: }
4423: $ordered{$order} = $rolename;
4424: $count++;
1.160.6.73 raeburn 4425: }
4426: }
1.160.6.77 raeburn 4427: my $maxnum = scalar(keys(%ordered));
4428: my @roles_by_num = ();
4429: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4430: push(@roles_by_num,$item);
4431: }
4432: my $context = 'domprefs';
4433: my $crstype = 'Course';
4434: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4435: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4436: my ($numstatustypes,@jsarray);
4437: if (ref($types) eq 'ARRAY') {
4438: if (@{$types} > 0) {
4439: $numstatustypes = scalar(@{$types});
4440: push(@accesstypes,'status');
4441: @jsarray = ('bystatus');
4442: }
4443: }
1.160.6.86 raeburn 4444: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4445: if (keys(%domhelpdesk)) {
4446: push(@accesstypes,('inc','exc'));
4447: push(@jsarray,('notinc','notexc'));
4448: }
4449: my $hiddenstr = join("','",@jsarray);
4450: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4451: my $context = 'domprefs';
4452: my $crstype = 'Course';
1.160.6.77 raeburn 4453: my $prefix = 'helproles_';
4454: my $add_class = 'LC_hidden';
4455: foreach my $num (@roles_by_num) {
4456: my $role = $ordered{$num};
4457: my ($desc,$access,@statuses);
4458: if (ref($current{$role}) eq 'HASH') {
4459: $desc = $current{$role}{'desc'};
4460: $access = $current{$role}{'access'};
4461: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4462: @statuses = @{$current{$role}{'insttypes'}};
4463: }
4464: }
4465: if ($desc eq '') {
4466: $desc = $role;
4467: }
4468: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4469: my %full=();
4470: my %levels= (
4471: course => {},
4472: domain => {},
4473: system => {},
4474: );
4475: my %levelscurrent=(
4476: course => {},
4477: domain => {},
4478: system => {},
4479: );
4480: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4481: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4482: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4483: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4484: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4485: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4486: for (my $k=0; $k<=$maxnum; $k++) {
4487: my $vpos = $k+1;
4488: my $selstr;
4489: if ($k == $num) {
4490: $selstr = ' selected="selected" ';
4491: }
4492: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4493: }
4494: $datatable .= '</select>'.(' 'x2).
4495: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4496: '</td>'.
4497: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4498: &mt('Name shown to users:').
4499: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4500: '</fieldset>'.
4501: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4502: $othertitle,$usertypes,$types,\%domhelpdesk).
4503: '<fieldset>'.
4504: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4505: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4506: \%levelscurrent,$identifier,
4507: 'LC_hidden',$prefix.$num.'_privs').
4508: '</fieldset></td>';
1.160.6.73 raeburn 4509: $itemcount ++;
4510: }
4511: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4512: my $newcust = 'custhelp'.$count;
4513: my (%privs,%levelscurrent);
4514: my %full=();
4515: my %levels= (
4516: course => {},
4517: domain => {},
4518: system => {},
4519: );
4520: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4521: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4522: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4523: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4524: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4525: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4526: for (my $k=0; $k<$maxnum+1; $k++) {
4527: my $vpos = $k+1;
4528: my $selstr;
4529: if ($k == $maxnum) {
4530: $selstr = ' selected="selected" ';
4531: }
4532: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4533: }
4534: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4535: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4536: '</label></span></td>'.
1.160.6.77 raeburn 4537: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4538: '<span class="LC_nobreak">'.
4539: &mt('Internal name:').
4540: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4541: '</span>'.(' 'x4).
4542: '<span class="LC_nobreak">'.
4543: &mt('Name shown to users:').
4544: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4545: '</span></fieldset>'.
4546: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4547: $usertypes,$types,\%domhelpdesk).
4548: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4549: &Apache::lonuserutils::custom_role_header($context,$crstype,
4550: \@templateroles,$newcust).
4551: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4552: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4553: '</fieldset>'.
4554: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4555: '</td></tr>';
1.160.6.73 raeburn 4556: $count ++;
4557: $$rowtotal += $count;
4558: }
1.160.6.5 raeburn 4559: return $datatable;
1.121 raeburn 4560: }
4561:
1.160.6.77 raeburn 4562: sub adhocbutton {
4563: my ($prefix,$num,$field,$visibility) = @_;
4564: my %lt = &Apache::lonlocal::texthash(
4565: show => 'Show details',
4566: hide => 'Hide details',
4567: );
4568: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4569: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4570: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4571: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4572: }
4573:
4574: sub helpsettings_javascript {
4575: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4576: return unless(ref($roles_by_num) eq 'ARRAY');
4577: my %html_js_lt = &Apache::lonlocal::texthash(
4578: show => 'Show details',
4579: hide => 'Hide details',
4580: );
4581: &html_escape(\%html_js_lt);
4582: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4583: return <<"ENDSCRIPT";
4584: <script type="text/javascript">
4585: // <![CDATA[
4586:
4587: function reorderHelpRoles(form,item) {
4588: var changedVal;
4589: $jstext
4590: var newpos = 'helproles_${total}_pos';
4591: var maxh = 1 + $total;
4592: var current = new Array();
4593: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4594: if (item == newpos) {
4595: changedVal = newitemVal;
4596: } else {
4597: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4598: current[newitemVal] = newpos;
4599: }
4600: for (var i=0; i<helproles.length; i++) {
4601: var elementName = 'helproles_'+helproles[i]+'_pos';
4602: if (elementName != item) {
4603: if (form.elements[elementName]) {
4604: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4605: current[currVal] = elementName;
4606: }
4607: }
4608: }
4609: var oldVal;
4610: for (var j=0; j<maxh; j++) {
4611: if (current[j] == undefined) {
4612: oldVal = j;
4613: }
4614: }
4615: if (oldVal < changedVal) {
4616: for (var k=oldVal+1; k<=changedVal ; k++) {
4617: var elementName = current[k];
4618: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4619: }
4620: } else {
4621: for (var k=changedVal; k<oldVal; k++) {
4622: var elementName = current[k];
4623: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4624: }
4625: }
4626: return;
4627: }
4628:
4629: function helpdeskAccess(num) {
4630: var curraccess = null;
4631: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4632: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4633: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4634: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4635: }
4636: }
4637: }
4638: var shown = Array();
4639: var hidden = Array();
4640: if (curraccess == 'none') {
4641: hidden = Array('$hiddenstr');
4642: } else {
4643: if (curraccess == 'status') {
4644: shown = Array('bystatus');
4645: hidden = Array('notinc','notexc');
4646: } else {
4647: if (curraccess == 'exc') {
4648: shown = Array('notexc');
4649: hidden = Array('notinc','bystatus');
4650: }
4651: if (curraccess == 'inc') {
4652: shown = Array('notinc');
4653: hidden = Array('notexc','bystatus');
4654: }
1.160.6.79 raeburn 4655: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4656: hidden = Array('notinc','notexc','bystatus');
4657: }
4658: }
4659: }
4660: if (hidden.length > 0) {
4661: for (var i=0; i<hidden.length; i++) {
4662: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4663: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4664: }
4665: }
4666: }
4667: if (shown.length > 0) {
4668: for (var i=0; i<shown.length; i++) {
4669: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4670: if (shown[i] == 'privs') {
4671: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4672: } else {
4673: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4674: }
4675: }
4676: }
4677: }
4678: return;
4679: }
4680:
4681: function toggleHelpdeskItem(num,field) {
4682: if (document.getElementById('helproles_'+num+'_'+field)) {
4683: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4684: document.getElementById('helproles_'+num+'_'+field).className =
4685: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4686: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4687: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4688: }
4689: } else {
4690: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4691: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4692: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4693: }
4694: }
4695: }
4696: return;
4697: }
4698:
4699: // ]]>
4700: </script>
4701:
4702: ENDSCRIPT
4703: }
4704:
4705: sub helpdeskroles_access {
4706: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4707: $usertypes,$types,$domhelpdesk) = @_;
4708: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4709: my %lt = &Apache::lonlocal::texthash(
4710: 'rou' => 'Role usage',
4711: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4712: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4713: 'dh' => 'All with domain helpdesk role',
4714: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4715: 'none' => 'None',
4716: 'status' => 'Determined based on institutional status',
4717: 'inc' => 'Include all, but exclude specific personnel',
4718: 'exc' => 'Exclude all, but include specific personnel',
4719: );
4720: my %usecheck = (
4721: all => ' checked="checked"',
4722: );
4723: my %displaydiv = (
4724: status => 'none',
4725: inc => 'none',
4726: exc => 'none',
4727: priv => 'block',
4728: );
4729: my $output;
4730: if (ref($current) eq 'HASH') {
4731: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4732: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4733: $usecheck{$current->{access}} = $usecheck{'all'};
4734: delete($usecheck{'all'});
4735: if ($current->{access} =~ /^(status|inc|exc)$/) {
4736: my $access = $1;
4737: $displaydiv{$access} = 'inline';
4738: } elsif ($current->{access} eq 'none') {
4739: $displaydiv{'priv'} = 'none';
4740: }
4741: }
4742: }
4743: }
4744: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4745: '<p>'.$lt{'whi'}.'</p>';
4746: foreach my $access (@{$accesstypes}) {
4747: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4748: ' onclick="helpdeskAccess('."'$num'".');" />'.
4749: $lt{$access}.'</label>';
4750: if ($access eq 'status') {
4751: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4752: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4753: $othertitle,$usertypes,$types).
4754: '</div>';
4755: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4756: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4757: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4758: '</div>';
4759: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4760: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4761: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4762: '</div>';
4763: }
4764: $output .= '</p>';
4765: }
4766: $output .= '</fieldset>';
4767: return $output;
4768: }
4769:
1.121 raeburn 4770: sub radiobutton_prefs {
1.160.6.16 raeburn 4771: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4772: $additional,$align,$firstval) = @_;
1.121 raeburn 4773: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4774: (ref($choices) eq 'HASH'));
4775:
4776: my (%checkedon,%checkedoff,$datatable,$css_class);
4777:
4778: foreach my $item (@{$toggles}) {
4779: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4780: $checkedon{$item} = ' checked="checked" ';
4781: $checkedoff{$item} = ' ';
1.121 raeburn 4782: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4783: $checkedoff{$item} = ' checked="checked" ';
4784: $checkedon{$item} = ' ';
4785: }
4786: }
4787: if (ref($settings) eq 'HASH') {
1.121 raeburn 4788: foreach my $item (@{$toggles}) {
1.118 jms 4789: if ($settings->{$item} eq '1') {
4790: $checkedon{$item} = ' checked="checked" ';
4791: $checkedoff{$item} = ' ';
4792: } elsif ($settings->{$item} eq '0') {
4793: $checkedoff{$item} = ' checked="checked" ';
4794: $checkedon{$item} = ' ';
4795: }
4796: }
1.121 raeburn 4797: }
1.160.6.16 raeburn 4798: if ($onclick) {
4799: $onclick = ' onclick="'.$onclick.'"';
4800: }
1.121 raeburn 4801: foreach my $item (@{$toggles}) {
1.118 jms 4802: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4803: $datatable .=
1.160.6.16 raeburn 4804: '<tr'.$css_class.'><td valign="top">'.
4805: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4806: '</span></td>';
4807: if ($align eq 'left') {
4808: $datatable .= '<td class="LC_left_item">';
4809: } else {
4810: $datatable .= '<td class="LC_right_item">';
4811: }
1.160.6.113 raeburn 4812: $datatable .= '<span class="LC_nobreak">';
4813: if ($firstval eq 'no') {
4814: $datatable .=
4815: '<label><input type="radio" name="'.
4816: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4817: '</label> <label><input type="radio" name="'.$item.'" '.
4818: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4819: } else {
4820: $datatable .=
1.118 jms 4821: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4822: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4823: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4824: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4825: }
4826: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4827: $itemcount ++;
1.121 raeburn 4828: }
4829: return ($datatable,$itemcount);
4830: }
4831:
1.160.6.118.2 1(raebur 4832:1): sub print_ltitools {
4833:1): my ($dom,$settings,$rowtotal) = @_;
4834:1): my $rownum = 0;
4835:1): my $css_class;
4836:1): my $itemcount = 1;
4837:1): my $maxnum = 0;
4838:1): my %ordered;
4839:1): if (ref($settings) eq 'HASH') {
4840:1): foreach my $item (keys(%{$settings})) {
4841:1): if (ref($settings->{$item}) eq 'HASH') {
4842:1): my $num = $settings->{$item}{'order'};
4843:1): $ordered{$num} = $item;
4844:1): }
4845:1): }
4846:1): }
4847:1): my $confname = $dom.'-domainconfig';
4848:1): my $switchserver = &check_switchserver($dom,$confname);
4849:1): my $maxnum = scalar(keys(%ordered));
4850:1): my $datatable;
4851:1): my %lt = <itools_names();
4852:1): my @courseroles = ('cc','in','ta','ep','st');
4853:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4854:1): my @fields = ('fullname','firstname','lastname','email','roles','user');
4855:1): if (keys(%ordered)) {
4856:1): my @items = sort { $a <=> $b } keys(%ordered);
4857:1): for (my $i=0; $i<@items; $i++) {
4858:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
4859:1): my $item = $ordered{$items[$i]};
4860:1): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
4861:1): if (ref($settings->{$item}) eq 'HASH') {
4862:1): $title = $settings->{$item}->{'title'};
4863:1): $url = $settings->{$item}->{'url'};
4864:1): $key = $settings->{$item}->{'key'};
4865:1): $secret = $settings->{$item}->{'secret'};
4866:1): $lifetime = $settings->{$item}->{'lifetime'};
4867:1): my $image = $settings->{$item}->{'image'};
4868:1): if ($image ne '') {
4869:1): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4870:1): }
4871:1): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4872:1): $sigsel{'HMAC-256'} = ' selected="selected"';
4873:1): } else {
4874:1): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4875:1): }
4876:1): }
4877:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
4878:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4879:1): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4880:1): for (my $k=0; $k<=$maxnum; $k++) {
4881:1): my $vpos = $k+1;
4882:1): my $selstr;
4883:1): if ($k == $i) {
4884:1): $selstr = ' selected="selected" ';
4885:1): }
4886:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4887:1): }
4888:1): $datatable .= '</select>'.(' 'x2).
4889:1): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4890:1): &mt('Delete?').'</label></span></td>'.
4891:1): '<td colspan="2">'.
4892:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4893:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4894:1): (' 'x2).
4895:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4896:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4897:1): (' 'x2).
4898:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4899:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4900:1): (' 'x2).
4901:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4902:1): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4903:1): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
4904:1): '<br /><br />'.
4905:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
4906:1): ' value="'.$url.'" /></span>'.
4907:1): (' 'x2).
4908:1): '<span class="LC_nobreak">'.$lt{'key'}.':'.
4909:1): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4910:1): (' 'x2).
4911:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4912:1): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4913:1): (' 'x2).
4914:1): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4915:1): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4916:1): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_secret_'.$i.'.type='."'text'".' } else { this.form.ltitools_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
4917:1): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4918:1): '</fieldset>'.
4919:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4920:1): '<span class="LC_nobreak">'.&mt('Display target:');
4921:1): my %currdisp;
4922:1): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4923:1): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4924:1): $currdisp{'window'} = ' checked="checked"';
4925:1): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4926:1): $currdisp{'tab'} = ' checked="checked"';
4927:1): } else {
4928:1): $currdisp{'iframe'} = ' checked="checked"';
4929:1): }
4930:1): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4931:1): $currdisp{'width'} = $1;
4932:1): }
4933:1): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4934:1): $currdisp{'height'} = $1;
4935:1): }
4936:1): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4937:1): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4938:1): } else {
4939:1): $currdisp{'iframe'} = ' checked="checked"';
4940:1): }
4941:1): foreach my $disp ('iframe','tab','window') {
4942:1): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4943:1): $lt{$disp}.'</label>'.(' 'x2);
4944:1): }
4945:1): $datatable .= (' 'x4);
4946:1): foreach my $dimen ('width','height') {
4947:1): $datatable .= '<label>'.$lt{$dimen}.' '.
4948:1): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4949:1): (' 'x2);
4950:1): }
4951:1): $datatable .= '</span><br />'.
4952:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4953:1): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
4954:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4955:1): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4956:1): '</textarea></div><div style=""></div>'.
4957:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4958:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
4959:1): if ($imgsrc) {
4960:1): $datatable .= $imgsrc.
4961:1): '<label><input type="checkbox" name="ltitools_image_del"'.
4962:1): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4963:1): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4964:1): } else {
4965:1): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4966:1): }
4967:1): if ($switchserver) {
4968:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4969:1): } else {
4970:1): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4971:1): }
4972:1): $datatable .= '</span></fieldset>';
4973:1): my (%checkedfields,%rolemaps,$userincdom);
4974:1): if (ref($settings->{$item}) eq 'HASH') {
4975:1): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4976:1): %checkedfields = %{$settings->{$item}->{'fields'}};
4977:1): }
4978:1): $userincdom = $settings->{$item}->{'incdom'};
4979:1): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4980:1): %rolemaps = %{$settings->{$item}->{'roles'}};
4981:1): $checkedfields{'roles'} = 1;
4982:1): }
4983:1): }
4984:1): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4985:1): '<span class="LC_nobreak">';
4986:1): my $userfieldstyle = 'display:none;';
4987:1): my $seluserdom = '';
4988:1): my $unseluserdom = ' selected="selected"';
4989:1): foreach my $field (@fields) {
4990:1): my ($checked,$onclick,$id,$spacer);
4991:1): if ($checkedfields{$field}) {
4992:1): $checked = ' checked="checked"';
4993:1): }
4994:1): if ($field eq 'user') {
4995:1): $id = ' id="ltitools_user_field_'.$i.'"';
4996:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4997:1): if ($checked) {
4998:1): $userfieldstyle = 'display:inline-block';
4999:1): if ($userincdom) {
5000:1): $seluserdom = $unseluserdom;
5001:1): $unseluserdom = '';
5002:1): }
5003:1): }
5004:1): } else {
5005:1): $spacer = (' ' x2);
5006:1): }
5007:1): $datatable .= '<label>'.
5008:1): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
5009:1): $lt{$field}.'</label>'.$spacer;
5010:1): }
5011:1): $datatable .= '</span>';
5012:1): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
5013:1): '<span class="LC_nobreak"> : '.
5014:1): '<select name="ltitools_userincdom_'.$i.'">'.
5015:1): '<option value="">'.&mt('Select').'</option>'.
5016:1): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5017:1): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5018:1): '</select></span></div>';
5019:1): $datatable .= '</fieldset>'.
5020:1): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5021:1): foreach my $role (@courseroles) {
5022:1): my ($selected,$selectnone);
5023:1): if (!$rolemaps{$role}) {
5024:1): $selectnone = ' selected="selected"';
5025:1): }
5026:1): $datatable .= '<td align="center">'.
5027:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
5028:1): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5029:1): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5030:1): foreach my $ltirole (@ltiroles) {
5031:1): unless ($selectnone) {
5032:1): if ($rolemaps{$role} eq $ltirole) {
5033:1): $selected = ' selected="selected"';
5034:1): } else {
5035:1): $selected = '';
5036:1): }
5037:1): }
5038:1): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5039:1): }
5040:1): $datatable .= '</select></td>';
5041:1): }
5042:1): $datatable .= '</tr></table></fieldset>';
5043:1): my %courseconfig;
5044:1): if (ref($settings->{$item}) eq 'HASH') {
5045:1): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5046:1): %courseconfig = %{$settings->{$item}->{'crsconf'}};
5047:1): }
5048:1): }
5049:1): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5050:1): foreach my $item ('label','title','target','linktext','explanation','append') {
5051:1): my $checked;
5052:1): if ($courseconfig{$item}) {
5053:1): $checked = ' checked="checked"';
5054:1): }
5055:1): $datatable .= '<label>'.
5056:1): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
5057:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5058:1): }
5059:1): $datatable .= '</span></fieldset>'.
5060:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5061:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5062:1): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5063:1): my %custom = %{$settings->{$item}->{'custom'}};
5064:1): if (keys(%custom) > 0) {
5065:1): foreach my $key (sort(keys(%custom))) {
5066:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
5067:1): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5068:1): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5069:1): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5070:1): ' value="'.$custom{$key}.'" /></td></tr>';
5071:1): }
5072:1): }
5073:1): }
5074:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
5075:1): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5076:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5077:1): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5078:1): $datatable .= '</table></fieldset></td></tr>'."\n";
5079:1): $itemcount ++;
5080:1): }
5081:1): }
5082:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5083:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
5084:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5085:1): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5086:1): '<select name="ltitools_add_pos"'.$chgstr.'>';
5087:1): for (my $k=0; $k<$maxnum+1; $k++) {
5088:1): my $vpos = $k+1;
5089:1): my $selstr;
5090:1): if ($k == $maxnum) {
5091:1): $selstr = ' selected="selected" ';
5092:1): }
5093:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5094:1): }
5095:1): $datatable .= '</select> '."\n".
5096:1): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5097:1): '<td colspan="2">'.
5098:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5099:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
5100:1): (' 'x2).
5101:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5102:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5103:1): (' 'x2).
5104:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5105:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5106:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5107:1): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5108:1): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5109:1): '<br />'.
5110:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
5111:1): (' 'x2).
5112:1): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5113:1): (' 'x2).
5114:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5115:1): (' 'x2).
5116:1): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5117:1): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltitools_add_secret.type='."'text'".' } else { this.form.ltitools_add_secret.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n".
5118:1): '</fieldset>'.
5119:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5120:1): '<span class="LC_nobreak">'.&mt('Display target:');
5121:1): my %defaultdisp;
5122:1): $defaultdisp{'iframe'} = ' checked="checked"';
5123:1): foreach my $disp ('iframe','tab','window') {
5124:1): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5125:1): $lt{$disp}.'</label>'.(' 'x2);
5126:1): }
5127:1): $datatable .= (' 'x4);
5128:1): foreach my $dimen ('width','height') {
5129:1): $datatable .= '<label>'.$lt{$dimen}.' '.
5130:1): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5131:1): (' 'x2);
5132:1): }
5133:1): $datatable .= '</span><br />'.
5134:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5135:1): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
5136:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5137:1): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
5138:1): '</div><div style=""></div>'.
5139:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
5140:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
5141:1): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5142:1): if ($switchserver) {
5143:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5144:1): } else {
5145:1): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5146:1): }
5147:1): $datatable .= '</span></fieldset>'.
5148:1): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5149:1): '<span class="LC_nobreak">';
5150:1): foreach my $field (@fields) {
5151:1): my ($id,$onclick,$spacer);
5152:1): if ($field eq 'user') {
5153:1): $id = ' id="ltitools_user_field_add"';
5154:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5155:1): } else {
5156:1): $spacer = (' ' x2);
5157:1): }
5158:1): $datatable .= '<label>'.
5159:1): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5160:1): $lt{$field}.'</label>'.$spacer;
5161:1): }
5162:1): $datatable .= '</span>'.
5163:1): '<div style="display:none;" id="ltitools_user_div_add">'.
5164:1): '<span class="LC_nobreak"> : '.
5165:1): '<select name="ltitools_userincdom_add">'.
5166:1): '<option value="" selected="selected">'.&mt('Select').'</option>'.
5167:1): '<option value="0">'.&mt('username').'</option>'.
5168:1): '<option value="1">'.&mt('username:domain').'</option>'.
5169:1): '</select></span></div></fieldset>';
5170:1): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5171:1): foreach my $role (@courseroles) {
5172:1): my ($checked,$checkednone);
5173:1): $datatable .= '<td align="center">'.
5174:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
5175:1): '<select name="ltitools_add_roles_'.$role.'">'.
5176:1): '<option value="" selected="selected">'.&mt('Select').'</option>';
5177:1): foreach my $ltirole (@ltiroles) {
5178:1): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5179:1): }
5180:1): $datatable .= '</select></td>';
5181:1): }
5182:1): $datatable .= '</tr></table></fieldset>'.
5183:1): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5184:1): foreach my $item ('label','title','target','linktext','explanation','append') {
5185:1): $datatable .= '<label>'.
5186:1): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5187:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5188:1): }
5189:1): $datatable .= '</span></fieldset>'.
5190:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5191:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5192:1): '<tr><td><span class="LC_nobreak">'.
5193:1): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5194:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5195:1): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5196:1): '</table></fieldset>'."\n".
5197:1): '</td>'."\n".
5198:1): '</tr>'."\n";
5199:1): $itemcount ++;
5200:1): return $datatable;
5201:1): }
5202:1):
5203:1): sub ltitools_names {
5204:1): my %lt = &Apache::lonlocal::texthash(
5205:1): 'title' => 'Title',
5206:1): 'version' => 'Version',
5207:1): 'msgtype' => 'Message Type',
5208:1): 'sigmethod' => 'Signature Method',
5209:1): 'url' => 'URL',
5210:1): 'key' => 'Key',
5211:1): 'lifetime' => 'Nonce lifetime (s)',
5212:1): 'secret' => 'Secret',
5213:1): 'icon' => 'Icon',
5214:1): 'user' => 'User',
5215:1): 'fullname' => 'Full Name',
5216:1): 'firstname' => 'First Name',
5217:1): 'lastname' => 'Last Name',
5218:1): 'email' => 'E-mail',
5219:1): 'roles' => 'Role',
5220:1): 'window' => 'Window',
5221:1): 'tab' => 'Tab',
5222:1): 'iframe' => 'iFrame',
5223:1): 'height' => 'Height',
5224:1): 'width' => 'Width',
5225:1): 'linktext' => 'Default Link Text',
5226:1): 'explanation' => 'Default Explanation',
5227:1): 'crstarget' => 'Display target',
5228:1): 'crslabel' => 'Course label',
5229:1): 'crstitle' => 'Course title',
5230:1): 'crslinktext' => 'Link Text',
5231:1): 'crsexplanation' => 'Explanation',
5232:1): 'crsappend' => 'Provider URL',
5233:1): );
5234:1):
5235:1): return %lt;
5236:1): }
5237:1):
5(raebur 5238:2): sub print_lti {
5239:2): my ($position,$dom,$settings,$rowtotal) = @_;
5240:2): my $itemcount = 1;
5241:2): my ($datatable,$css_class);
5242:2): my (%rules,%encrypt,%privkeys,%linkprot);
5243:2): if (ref($settings) eq 'HASH') {
5244:2): if ($position eq 'top') {
5245:2): if (exists($settings->{'encrypt'})) {
5246:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5247:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5248:2): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5249:2): }
5250:2): }
5251:2): }
5252:2): if (exists($settings->{'private'})) {
5253:2): if (ref($settings->{'private'}) eq 'HASH') {
5254:2): if (ref($settings->{'private'}) eq 'HASH') {
5255:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5256:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5257:2): }
5258:2): }
5259:2): }
5260:2): }
5261:2): } elsif ($position eq 'middle') {
5262:2): if (exists($settings->{'rules'})) {
5263:2): if (ref($settings->{'rules'}) eq 'HASH') {
5264:2): %rules = %{$settings->{'rules'}};
5265:2): }
5266:2): }
5267:2): } elsif ($position eq 'bottom') {
5268:2): if (exists($settings->{'linkprot'})) {
5269:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5270:2): %linkprot = %{$settings->{'linkprot'}};
5271:2): if ($linkprot{'lock'}) {
5272:2): delete($linkprot{'lock'});
5273:2): }
5274:2): }
5275:2): }
5276:2): }
5277:2): }
5278:2): if ($position eq 'top') {
5279:2): my @ids=&Apache::lonnet::current_machine_ids();
5280:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
5281:2): my $primary = &Apache::lonnet::domain($dom,'primary');
5282:2): my ($extra,$numshown);
5283:2): foreach my $hostid (sort(keys(%servers))) {
5284:2): my ($showextra,$divsty,$switch);
5285:2): if ($hostid eq $primary) {
5286:2): if ($encrypt{'ltisec_domlinkprot'}) {
5287:2): $showextra = 1;
5288:2): }
5289:2): }
5290:2): if ($encrypt{'ltisec_crslinkprot'}) {
5291:2): $showextra = 1;
5292:2): }
5293:2): unless (grep(/^\Q$hostid\E$/,@ids)) {
5294:2): $switch = 1;
5295:2): }
5296:2): if ($showextra) {
5297:2): $numshown ++;
5298:2): $divsty = 'display:inline-block';
5299:2): } else {
5300:2): $divsty = 'display:none';
5301:2): }
5302:2): $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
5303:2): '<legend>'.$hostid.'</legend>';
5304:2): if ($switch) {
5305:2): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5306:2): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5307:2): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5308:2): if (exists($privkeys{$hostid})) {
5309:2): $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5310:2): '<span class="LC_nobreak">'.
5311:2): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5312:2): '<span class="LC_nobreak">'.&mt('Change?').
5313:2): '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5314:2): (' 'x2).
5315:2): '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5316:2): '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5317:2): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5318:2): '</span></div>';
5319:2): } else {
5320:2): $extra .= '<span class="LC_nobreak">'.
5321:2): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5322:2): '</span>'."\n";
5323:2): }
5324:2): } elsif (exists($privkeys{$hostid})) {
5325:2): $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5326:2): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5327:2): '<span class="LC_nobreak">'.&mt('Change?').
5328:2): '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5329:2): (' 'x2).
5330:2): '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5331:2): '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5332:2): '<span class="LC_nobreak">'.&mt('New Key').':'.
5333:2): '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5334:2): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5335:2): '</span></div>';
5336:2): } else {
5337:2): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5338:2): '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5339:2): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.ltisec_privkey_'.$hostid.'.type='."'text'".' } else { this.form.ltisec_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5340:2): }
5341:2): $extra .= '</fieldset>';
5342:2): }
5343:2): my %choices = &Apache::lonlocal::texthash (
5344:2): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5345:2): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5346:2): );
5347:2): my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot);
5348:2): my %defaultchecked = (
5349:2): 'ltisec_crslinkprot' => 'off',
5350:2): 'ltisec_domlinkprot' => 'off',
5351:2): );
5352:2): my ($onclick,$itemcount);
5353:2): $onclick = 'javascript:toggleLTIEncKey(this.form);';
5354:2): ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
5355:2): \%choices,$itemcount,$onclick,'','left','no');
5356:2):
5357:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5358:2): my $noprivkeysty = 'display:inline-block';
5359:2): if ($numshown) {
5360:2): $noprivkeysty = 'display:none';
5361:2): }
5362:2): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5363:2): '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
5364:2): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5365:2): $extra.
5366:2): '</td></tr>';
5367:2): $itemcount ++;
5368:2): $$rowtotal += $itemcount;
5369:2): } elsif ($position eq 'middle') {
5370:2): $datatable = &password_rules('secrets',\$itemcount,\%rules);
5371:2): $$rowtotal += $itemcount;
5372:2): } elsif ($position eq 'bottom') {
5373:2): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
5374:2): }
5375:2): return $datatable;
5376:2): }
5377:2):
1.121 raeburn 5378: sub print_coursedefaults {
1.139 raeburn 5379: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5380: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5381: my $itemcount = 1;
1.160.6.16 raeburn 5382: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 5383: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 5384: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5385: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 5386: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5387: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 5388: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 5389: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 5390: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 5391: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 5392: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 5393:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
7(raebur 5394:2): );
1.160.6.21 raeburn 5395: my %staticdefaults = (
5396: anonsurvey_threshold => 10,
5397: uploadquota => 500,
1.160.6.57 raeburn 5398: postsubmit => 60,
1.160.6.70 raeburn 5399: mysqltables => 172800,
1.160.6.21 raeburn 5400: );
1.139 raeburn 5401: if ($position eq 'top') {
1.160.6.57 raeburn 5402: %defaultchecked = (
5403: 'uselcmath' => 'on',
5404: 'usejsme' => 'on',
1.160.6.115 raeburn 5405: 'inline_chem' => 'on',
1.160.6.64 raeburn 5406: 'canclone' => 'none',
1.160.6.57 raeburn 5407: );
1.160.6.115 raeburn 5408: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 5409: my $deftex = $Apache::lonnet::deftex;
5410: if (ref($settings) eq 'HASH') {
5411: if ($settings->{'texengine'}) {
5412: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5413: $deftex = $settings->{'texengine'};
5414: }
5415: }
5416: }
5417: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5418: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5419: '<span class="LC_nobreak">'.$choices{'texengine'}.
5420: '</span></td><td class="LC_right_item">'.
5421: '<select name="texengine">'."\n";
5422: my %texoptions = (
5423: MathJax => 'MathJax',
5424: mimetex => &mt('Convert to Images'),
5425: tth => &mt('TeX to HTML'),
5426: );
5427: foreach my $renderer ('MathJax','mimetex','tth') {
5428: my $selected = '';
5429: if ($renderer eq $deftex) {
5430: $selected = ' selected="selected"';
5431: }
5432: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5433: }
5434: $mathdisp .= '</select></td></tr>'."\n";
5435: $itemcount ++;
1.139 raeburn 5436: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5437: \%choices,$itemcount);
1.160.6.90 raeburn 5438: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 5439: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5440: $datatable .=
5441: '<tr'.$css_class.'><td valign="top">'.
5442: '<span class="LC_nobreak">'.$choices{'canclone'}.
5443: '</span></td><td class="LC_left_item">';
5444: my $currcanclone = 'none';
5445: my $onclick;
5446: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 5447: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 5448: none => 'No additional course requesters',
5449: domain => "Any course requester in course's domain",
5450: instcode => 'Course requests for official courses ...',
5451: );
5452: my (%codedefaults,@code_order,@posscodes);
5453: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5454: \@code_order) eq 'ok') {
5455: if (@code_order > 0) {
5456: push(@cloneoptions,'instcode');
5457: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5458: }
5459: }
5460: if (ref($settings) eq 'HASH') {
5461: if ($settings->{'canclone'}) {
5462: if (ref($settings->{'canclone'}) eq 'HASH') {
5463: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5464: if (@code_order > 0) {
5465: $currcanclone = 'instcode';
5466: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5467: }
5468: }
5469: } elsif ($settings->{'canclone'} eq 'domain') {
5470: $currcanclone = $settings->{'canclone'};
5471: }
5472: }
5473: }
5474: foreach my $option (@cloneoptions) {
5475: my ($checked,$additional);
5476: if ($currcanclone eq $option) {
5477: $checked = ' checked="checked"';
5478: }
5479: if ($option eq 'instcode') {
5480: if (@code_order) {
5481: my $show = 'none';
5482: if ($checked) {
5483: $show = 'block';
5484: }
5485: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
5486: &mt('Institutional codes for new and cloned course have identical:').
5487: '<br />';
5488: foreach my $item (@code_order) {
5489: my $codechk;
5490: if ($checked) {
5491: if (grep(/^\Q$item\E$/,@posscodes)) {
5492: $codechk = ' checked="checked"';
5493: }
5494: }
5495: $additional .= '<label>'.
5496: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5497: $item.'</label>';
5498: }
5499: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5500: }
5501: }
5502: $datatable .=
5503: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5504: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5505: '</label> '.$additional.'</span><br />';
5506: }
5507: $datatable .= '</td>'.
5508: '</tr>';
5509: $itemcount ++;
1.139 raeburn 5510: } else {
5511: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 5512: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 5513: my $currusecredits = 0;
1.160.6.57 raeburn 5514: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 5515:2): my $ltiauth = 0;
1.160.6.30 raeburn 5516: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 5517: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 5518:2): if ($settings->{'ltiauth'}) {
5519:2): $ltiauth = 1;
5520:2): }
1.139 raeburn 5521: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 5522: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5523: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5524: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5525: }
5526: }
1.160.6.16 raeburn 5527: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 5528: foreach my $type (@types) {
5529: next if ($type eq 'community');
5530: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5531: if ($defcredits{$type} ne '') {
5532: $currusecredits = 1;
5533: }
5534: }
5535: }
5536: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5537: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5538: $postsubmitclient = 0;
5539: foreach my $type (@types) {
5540: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5541: }
5542: } else {
5543: foreach my $type (@types) {
5544: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5545: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
5546: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
5547: } else {
5548: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5549: }
5550: } else {
5551: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5552: }
5553: }
5554: }
5555: } else {
5556: foreach my $type (@types) {
5557: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 5558: }
5559: }
1.160.6.70 raeburn 5560: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5561: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5562: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5563: }
5564: } else {
5565: foreach my $type (@types) {
5566: $currmysql{$type} = $staticdefaults{'mysqltables'};
5567: }
5568: }
1.160.6.58 raeburn 5569: } else {
5570: foreach my $type (@types) {
5571: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5572: }
1.139 raeburn 5573: }
5574: if (!$currdefresponder) {
1.160.6.21 raeburn 5575: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5576: } elsif ($currdefresponder < 1) {
5577: $currdefresponder = 1;
5578: }
1.160.6.21 raeburn 5579: foreach my $type (@types) {
5580: if ($curruploadquota{$type} eq '') {
5581: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5582: }
5583: }
1.139 raeburn 5584: $datatable .=
1.160.6.16 raeburn 5585: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5586: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5587: '</span></td>'.
5588: '<td class="LC_right_item"><span class="LC_nobreak">'.
5589: '<input type="text" name="anonsurvey_threshold"'.
5590: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 5591: '</td></tr>'."\n";
5592: $itemcount ++;
5593: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5594: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5595: $choices{'uploadquota'}.
5596: '</span></td>'.
5597: '<td align="right" class="LC_right_item">'.
5598: '<table><tr>';
1.160.6.21 raeburn 5599: foreach my $type (@types) {
5600: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5601: '<input type="text" name="uploadquota_'.$type.'"'.
5602: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5603: }
5604: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 5605: $itemcount ++;
1.160.6.40 raeburn 5606: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 5607: my $display = 'none';
5608: if ($currusecredits) {
5609: $display = 'block';
5610: }
5611: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 5612: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5613: foreach my $type (@types) {
5614: next if ($type eq 'community');
5615: $additional .= '<td align="center">'.&mt($type).'<br />'.
5616: '<input type="text" name="'.$type.'_credits"'.
5617: ' value="'.$defcredits{$type}.'" size="3" /></td>';
5618: }
5619: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 5620: %defaultchecked = ('coursecredits' => 'off');
5621: @toggles = ('coursecredits');
5622: my $current = {
5623: 'coursecredits' => $currusecredits,
5624: };
5625: (my $table,$itemcount) =
5626: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5627: \%choices,$itemcount,$onclick,$additional,'left');
5628: $datatable .= $table;
5629: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5630: my $display = 'none';
5631: if ($postsubmitclient) {
5632: $display = 'block';
5633: }
5634: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 5635: &mt('Number of seconds submit is disabled').'<br />'.
5636: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5637: '<table><tr>';
1.160.6.57 raeburn 5638: foreach my $type (@types) {
5639: $additional .= '<td align="center">'.&mt($type).'<br />'.
5640: '<input type="text" name="'.$type.'_timeout" value="'.
5641: $deftimeout{$type}.'" size="5" /></td>';
5642: }
5643: $additional .= '</tr></table></div>'."\n";
5644: %defaultchecked = ('postsubmit' => 'on');
5645: @toggles = ('postsubmit');
1.160.6.70 raeburn 5646: $current = {
5647: 'postsubmit' => $postsubmitclient,
5648: };
1.160.6.57 raeburn 5649: ($table,$itemcount) =
5650: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5651: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 5652: $datatable .= $table;
1.160.6.70 raeburn 5653: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5654: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5655: $choices{'mysqltables'}.
5656: '</span></td>'.
5657: '<td align="right" class="LC_right_item">'.
5658: '<table><tr>';
5659: foreach my $type (@types) {
5660: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5661: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 5662: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 5663: }
5664: $datatable .= '</tr></table></td></tr>'."\n";
5665: $itemcount ++;
1.160.6.118.2 4(raebur 5666:2): %defaultchecked = ('ltiauth' => 'off');
5667:2): @toggles = ('ltiauth');
5668:2): $current = {
5669:2): 'ltiauth' => $ltiauth,
5670:2): };
5671:2): ($table,$itemcount) =
5672:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5673:2): \%choices,$itemcount,undef,undef,'left');
5674:2): $datatable .= $table;
5675:2): $itemcount ++;
1.160.6.37 raeburn 5676: }
5677: $$rowtotal += $itemcount;
5678: return $datatable;
5679: }
5680:
5681: sub print_selfenrollment {
5682: my ($position,$dom,$settings,$rowtotal) = @_;
5683: my ($css_class,$datatable);
5684: my $itemcount = 1;
5685: my @types = ('official','unofficial','community','textbook');
5686: if (($position eq 'top') || ($position eq 'middle')) {
5687: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5688: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
5689: my @rows;
5690: my $key;
5691: if ($position eq 'top') {
5692: $key = 'admin';
5693: if (ref($rowsref) eq 'ARRAY') {
5694: @rows = @{$rowsref};
5695: }
5696: } elsif ($position eq 'middle') {
5697: $key = 'default';
5698: @rows = ('types','registered','approval','limit');
5699: }
5700: foreach my $row (@rows) {
5701: if (defined($titlesref->{$row})) {
5702: $itemcount ++;
5703: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5704: $datatable .= '<tr'.$css_class.'>'.
5705: '<td>'.$titlesref->{$row}.'</td>'.
5706: '<td class="LC_left_item">'.
5707: '<table><tr>';
5708: my (%current,%currentcap);
5709: if (ref($settings) eq 'HASH') {
5710: if (ref($settings->{$key}) eq 'HASH') {
5711: foreach my $type (@types) {
5712: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5713: $current{$type} = $settings->{$key}->{$type}->{$row};
5714: }
5715: if (($row eq 'limit') && ($key eq 'default')) {
5716: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5717: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5718: }
5719: }
5720: }
5721: }
5722: }
5723: my %roles = (
5724: '0' => &Apache::lonnet::plaintext('dc'),
5725: );
5726:
5727: foreach my $type (@types) {
5728: unless (($row eq 'registered') && ($key eq 'default')) {
5729: $datatable .= '<th>'.&mt($type).'</th>';
5730: }
5731: }
5732: unless (($row eq 'registered') && ($key eq 'default')) {
5733: $datatable .= '</tr><tr>';
5734: }
5735: foreach my $type (@types) {
5736: if ($type eq 'community') {
5737: $roles{'1'} = &mt('Community personnel');
5738: } else {
5739: $roles{'1'} = &mt('Course personnel');
5740: }
5741: $datatable .= '<td style="vertical-align: top">';
5742: if ($position eq 'top') {
5743: my %checked;
5744: if ($current{$type} eq '0') {
5745: $checked{'0'} = ' checked="checked"';
5746: } else {
5747: $checked{'1'} = ' checked="checked"';
5748: }
5749: foreach my $role ('1','0') {
5750: $datatable .= '<span class="LC_nobreak"><label>'.
5751: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5752: 'value="'.$role.'"'.$checked{$role}.' />'.
5753: $roles{$role}.'</label></span> ';
5754: }
5755: } else {
5756: if ($row eq 'types') {
5757: my %checked;
5758: if ($current{$type} =~ /^(all|dom)$/) {
5759: $checked{$1} = ' checked="checked"';
5760: } else {
5761: $checked{''} = ' checked="checked"';
5762: }
5763: foreach my $val ('','dom','all') {
5764: $datatable .= '<span class="LC_nobreak"><label>'.
5765: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5766: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5767: }
5768: } elsif ($row eq 'registered') {
5769: my %checked;
5770: if ($current{$type} eq '1') {
5771: $checked{'1'} = ' checked="checked"';
5772: } else {
5773: $checked{'0'} = ' checked="checked"';
5774: }
5775: foreach my $val ('0','1') {
5776: $datatable .= '<span class="LC_nobreak"><label>'.
5777: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5778: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5779: }
5780: } elsif ($row eq 'approval') {
5781: my %checked;
5782: if ($current{$type} =~ /^([12])$/) {
5783: $checked{$1} = ' checked="checked"';
5784: } else {
5785: $checked{'0'} = ' checked="checked"';
5786: }
5787: for my $val (0..2) {
5788: $datatable .= '<span class="LC_nobreak"><label>'.
5789: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5790: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5791: }
5792: } elsif ($row eq 'limit') {
5793: my %checked;
5794: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5795: $checked{$1} = ' checked="checked"';
5796: } else {
5797: $checked{'none'} = ' checked="checked"';
5798: }
5799: my $cap;
5800: if ($currentcap{$type} =~ /^\d+$/) {
5801: $cap = $currentcap{$type};
5802: }
5803: foreach my $val ('none','allstudents','selfenrolled') {
5804: $datatable .= '<span class="LC_nobreak"><label>'.
5805: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5806: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5807: }
5808: $datatable .= '<br />'.
5809: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5810: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5811: '</span>';
5812: }
5813: }
5814: $datatable .= '</td>';
5815: }
5816: $datatable .= '</tr>';
5817: }
5818: $datatable .= '</table></td></tr>';
5819: }
5820: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 5821: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5822: }
5823: $$rowtotal += $itemcount;
5824: return $datatable;
5825: }
5826:
5827: sub print_validation_rows {
5828: my ($caller,$dom,$settings,$rowtotal) = @_;
5829: my ($itemsref,$namesref,$fieldsref);
5830: if ($caller eq 'selfenroll') {
5831: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5832: } elsif ($caller eq 'requestcourses') {
5833: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5834: }
5835: my %currvalidation;
5836: if (ref($settings) eq 'HASH') {
5837: if (ref($settings->{'validation'}) eq 'HASH') {
5838: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 5839: }
1.160.6.39 raeburn 5840: }
5841: my $datatable;
5842: my $itemcount = 0;
5843: foreach my $item (@{$itemsref}) {
5844: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5845: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5846: $namesref->{$item}.
5847: '</span></td>'.
5848: '<td class="LC_left_item">';
5849: if (($item eq 'url') || ($item eq 'button')) {
5850: $datatable .= '<span class="LC_nobreak">'.
5851: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5852: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5853: } elsif ($item eq 'fields') {
5854: my @currfields;
5855: if (ref($currvalidation{$item}) eq 'ARRAY') {
5856: @currfields = @{$currvalidation{$item}};
5857: }
5858: foreach my $field (@{$fieldsref}) {
5859: my $check = '';
5860: if (grep(/^\Q$field\E$/,@currfields)) {
5861: $check = ' checked="checked"';
5862: }
5863: $datatable .= '<span class="LC_nobreak"><label>'.
5864: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5865: ' value="'.$field.'"'.$check.' />'.$field.
5866: '</label></span> ';
5867: }
5868: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 5869: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 5870: $currvalidation{$item}.
1.160.6.37 raeburn 5871: '</textarea>';
1.160.6.39 raeburn 5872: }
5873: $datatable .= '</td></tr>'."\n";
5874: if (ref($rowtotal)) {
1.160.6.37 raeburn 5875: $itemcount ++;
5876: }
1.139 raeburn 5877: }
1.160.6.39 raeburn 5878: if ($caller eq 'requestcourses') {
5879: my %currhash;
1.160.6.51 raeburn 5880: if (ref($settings) eq 'HASH') {
5881: if (ref($settings->{'validation'}) eq 'HASH') {
5882: if ($settings->{'validation'}{'dc'} ne '') {
5883: $currhash{$settings->{'validation'}{'dc'}} = 1;
5884: }
1.160.6.39 raeburn 5885: }
5886: }
5887: my $numinrow = 2;
5888: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5889: 'validationdc',%currhash);
1.160.6.50 raeburn 5890: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5891: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5892: if ($numdc > 1) {
1.160.6.50 raeburn 5893: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5894: } else {
1.160.6.50 raeburn 5895: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5896: }
1.160.6.50 raeburn 5897: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5898: $itemcount ++;
5899: }
5900: if (ref($rowtotal)) {
5901: $$rowtotal += $itemcount;
5902: }
1.121 raeburn 5903: return $datatable;
1.118 jms 5904: }
5905:
1.160.6.98 raeburn 5906: sub print_passwords {
5907: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5908: my ($datatable,$css_class);
5909: my $itemcount = 0;
5910: my %titles = &Apache::lonlocal::texthash (
5911: captcha => '"Forgot Password" CAPTCHA validation',
5912: link => 'Reset link expiration (hours)',
5913: case => 'Case-sensitive usernames/e-mail',
5914: prelink => 'Information required (form 1)',
5915: postlink => 'Information required (form 2)',
5916: emailsrc => 'LON-CAPA e-mail address type(s)',
5917: customtext => 'Domain specific text (HTML)',
5918: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5919: intauth_check => 'Check bcrypt cost if authenticated',
5920: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5921: permanent => 'Permanent e-mail address',
5922: critical => 'Critical notification address',
5923: notify => 'Notification address',
5924: min => 'Minimum password length',
5925: max => 'Maximum password length',
5926: chars => 'Required characters',
5927: numsaved => 'Number of previous passwords to save and disallow reuse',
5928: );
5929: if ($position eq 'top') {
5930: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5931: my $shownlinklife = 2;
5932: my $prelink = 'both';
5933: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5934: if (ref($settings) eq 'HASH') {
5935: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5936: $shownlinklife = $settings->{resetlink};
5937: }
5938: if (ref($settings->{resetcase}) eq 'ARRAY') {
5939: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5940: }
5941: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5942: $prelink = $settings->{resetprelink};
5943: }
5944: if (ref($settings->{resetpostlink}) eq 'HASH') {
5945: %postlink = %{$settings->{resetpostlink}};
5946: }
5947: if (ref($settings->{resetemail}) eq 'ARRAY') {
5948: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5949: }
5950: if ($settings->{resetremove}) {
5951: $nostdtext = 1;
5952: }
5953: if ($settings->{resetcustom}) {
5954: $customurl = $settings->{resetcustom};
5955: }
5956: } else {
5957: if (ref($types) eq 'ARRAY') {
5958: foreach my $item (@{$types}) {
5959: $casesens{$item} = 1;
5960: $postlink{$item} = ['username','email'];
5961: }
5962: }
5963: $casesens{'default'} = 1;
5964: $postlink{'default'} = ['username','email'];
5965: $prelink = 'both';
5966: %emailsrc = (
5967: permanent => 1,
5968: critical => 1,
5969: notify => 1,
5970: );
5971: }
5972: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5973: $itemcount ++;
5974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5975: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5976: '<td class="LC_left_item">'.
5977: '<input type="textbox" value="'.$shownlinklife.'" '.
5978: 'name="passwords_link" size="3" /></td></tr>';
5979: $itemcount ++;
5980: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5981: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5982: '<td class="LC_left_item">';
5983: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5984: foreach my $item (@{$types}) {
5985: my $checkedcase;
5986: if ($casesens{$item}) {
5987: $checkedcase = ' checked="checked"';
5988: }
5989: $datatable .= '<span class="LC_nobreak"><label>'.
5990: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5991: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5992: '</span> ';
1.160.6.98 raeburn 5993: }
5994: }
5995: my $checkedcase;
5996: if ($casesens{'default'}) {
5997: $checkedcase = ' checked="checked"';
5998: }
5999: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6000: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6001: $othertitle.'</label></span></td>';
6002: $itemcount ++;
6003: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6004: my %checkedpre = (
6005: both => ' checked="checked"',
6006: either => '',
6007: );
6008: if ($prelink eq 'either') {
6009: $checkedpre{either} = ' checked="checked"';
6010: $checkedpre{both} = '';
6011: }
6012: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6013: '<td class="LC_left_item"><span class="LC_nobreak">'.
6014: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6015: &mt('Both username and e-mail address').'</label></span> '.
6016: '<span class="LC_nobreak"><label>'.
6017: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6018: &mt('Either username or e-mail address').'</label></span></td></tr>';
6019: $itemcount ++;
6020: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6021: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6022: '<td class="LC_left_item">';
6023: my %postlinked;
6024: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6025: foreach my $item (@{$types}) {
6026: undef(%postlinked);
6027: $datatable .= '<fieldset style="display: inline-block;">'.
6028: '<legend>'.$usertypes->{$item}.'</legend>';
6029: if (ref($postlink{$item}) eq 'ARRAY') {
6030: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6031: }
6032: foreach my $field ('email','username') {
6033: my $checked;
6034: if ($postlinked{$field}) {
6035: $checked = ' checked="checked"';
6036: }
6037: $datatable .= '<span class="LC_nobreak"><label>'.
6038: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6039: $field.'"'.$checked.' />'.$field.'</label>'.
6040: '<span> ';
6041: }
6042: $datatable .= '</fieldset>';
6043: }
6044: }
6045: if (ref($postlink{'default'}) eq 'ARRAY') {
6046: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6047: }
6048: $datatable .= '<fieldset style="display: inline-block;">'.
6049: '<legend>'.$othertitle.'</legend>';
6050: foreach my $field ('email','username') {
6051: my $checked;
6052: if ($postlinked{$field}) {
6053: $checked = ' checked="checked"';
6054: }
6055: $datatable .= '<span class="LC_nobreak"><label>'.
6056: '<input type="checkbox" name="passwords_postlink_default" value="'.
6057: $field.'"'.$checked.' />'.$field.'</label>'.
6058: '<span> ';
6059: }
6060: $datatable .= '</fieldset></td></tr>';
6061: $itemcount ++;
6062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6063: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6064: '<td class="LC_left_item">';
6065: foreach my $type ('permanent','critical','notify') {
6066: my $checkedemail;
6067: if ($emailsrc{$type}) {
6068: $checkedemail = ' checked="checked"';
6069: }
6070: $datatable .= '<span class="LC_nobreak"><label>'.
6071: '<input type="checkbox" name="passwords_emailsrc" value="'.
6072: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6073: '<span> ';
6074: }
6075: $datatable .= '</td></tr>';
6076: $itemcount ++;
6077: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6078: my $switchserver = &check_switchserver($dom,$confname);
6079: my ($showstd,$noshowstd);
6080: if ($nostdtext) {
6081: $noshowstd = ' checked="checked"';
6082: } else {
6083: $showstd = ' checked="checked"';
6084: }
6085: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6086: '<td class="LC_left_item"><span class="LC_nobreak">'.
6087: &mt('Retain standard text:').
6088: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6089: &mt('Yes').'</label>'.' '.
6090: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6091: &mt('No').'</label></span><br />'.
6092: '<span class="LC_fontsize_small">'.
6093: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6094: &mt('Include custom text:');
6095: if ($customurl) {
1.160.6.104 raeburn 6096: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 6097: undef,undef,undef,undef,'background-color:#ffffff');
6098: $datatable .= '<span class="LC_nobreak"> '.$link.
6099: '<label><input type="checkbox" name="passwords_custom_del"'.
6100: ' value="1" />'.&mt('Delete?').'</label></span>'.
6101: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6102: }
6103: if ($switchserver) {
6104: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6105: } else {
6106: $datatable .='<span class="LC_nobreak"> '.
6107: '<input type="file" name="passwords_customfile" /></span>';
6108: }
6109: $datatable .= '</td></tr>';
6110: } elsif ($position eq 'middle') {
6111: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6112: my @items = ('intauth_cost','intauth_check','intauth_switch');
6113: my %defaults;
6114: if (ref($domconf{'defaults'}) eq 'HASH') {
6115: %defaults = %{$domconf{'defaults'}};
6116: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6117: $defaults{'intauth_cost'} = 10;
6118: }
6119: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6120: $defaults{'intauth_check'} = 0;
6121: }
6122: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6123: $defaults{'intauth_switch'} = 0;
6124: }
6125: } else {
6126: %defaults = (
6127: 'intauth_cost' => 10,
6128: 'intauth_check' => 0,
6129: 'intauth_switch' => 0,
6130: );
6131: }
6132: foreach my $item (@items) {
6133: if ($itemcount%2) {
6134: $css_class = '';
6135: } else {
6136: $css_class = ' class="LC_odd_row" ';
6137: }
6138: $datatable .= '<tr'.$css_class.'>'.
6139: '<td><span class="LC_nobreak">'.$titles{$item}.
6140: '</span></td><td class="LC_left_item" colspan="3">';
6141: if ($item eq 'intauth_switch') {
6142: my @options = (0,1,2);
6143: my %optiondesc = &Apache::lonlocal::texthash (
6144: 0 => 'No',
6145: 1 => 'Yes',
6146: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6147: );
6148: $datatable .= '<table width="100%">';
6149: foreach my $option (@options) {
6150: my $checked = ' ';
6151: if ($defaults{$item} eq $option) {
6152: $checked = ' checked="checked"';
6153: }
6154: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6155: '<label><input type="radio" name="'.$item.
6156: '" value="'.$option.'"'.$checked.' />'.
6157: $optiondesc{$option}.'</label></span></td></tr>';
6158: }
6159: $datatable .= '</table>';
6160: } elsif ($item eq 'intauth_check') {
6161: my @options = (0,1,2);
6162: my %optiondesc = &Apache::lonlocal::texthash (
6163: 0 => 'No',
6164: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6165: 2 => 'Yes, disallow login if stored cost is less than domain default',
6166: );
6167: $datatable .= '<table width="100%">';
6168: foreach my $option (@options) {
6169: my $checked = ' ';
6170: my $onclick;
6171: if ($defaults{$item} eq $option) {
6172: $checked = ' checked="checked"';
6173: }
6174: if ($option == 2) {
6175: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6176: }
6177: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6178: '<label><input type="radio" name="'.$item.
6179: '" value="'.$option.'"'.$checked.$onclick.' />'.
6180: $optiondesc{$option}.'</label></span></td></tr>';
6181: }
6182: $datatable .= '</table>';
6183: } else {
6184: $datatable .= '<input type="text" name="'.$item.'" value="'.
6185: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6186: }
6187: $datatable .= '</td></tr>';
6188: $itemcount ++;
6189: }
6190: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 6191:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 6192: } else {
6193: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6194: my %ownerchg = (
6195: by => {},
6196: for => {},
6197: );
6198: my %ownertitles = &Apache::lonlocal::texthash (
6199: by => 'Course owner status(es) allowed',
6200: for => 'Student status(es) allowed',
6201: );
6202: if (ref($settings) eq 'HASH') {
6203: if (ref($settings->{crsownerchg}) eq 'HASH') {
6204: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6205: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6206: }
6207: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6208: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6209: }
6210: }
6211: }
6212: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6213: $datatable .= '<tr '.$css_class.'>'.
6214: '<td>'.
6215: &mt('Requirements').'<ul>'.
6216: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6217: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6218: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6219: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6220: '</ul>'.
6221: '</td>'.
6222: '<td class="LC_left_item">';
6223: foreach my $item ('by','for') {
6224: $datatable .= '<fieldset style="display: inline-block;">'.
6225: '<legend>'.$ownertitles{$item}.'</legend>';
6226: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6227: foreach my $type (@{$types}) {
6228: my $checked;
6229: if ($ownerchg{$item}{$type}) {
6230: $checked = ' checked="checked"';
6231: }
6232: $datatable .= '<span class="LC_nobreak"><label>'.
6233: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6234: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 6235: '</span> ';
1.160.6.98 raeburn 6236: }
6237: }
6238: my $checked;
6239: if ($ownerchg{$item}{'default'}) {
6240: $checked = ' checked="checked"';
6241: }
6242: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6243: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6244: $othertitle.'</label></span></fieldset>';
6245: }
6246: $datatable .= '</td></tr>';
6247: }
6248: return $datatable;
6249: }
6250:
1.160.6.118.2 5(raebur 6251:2): sub password_rules {
6252:2): my ($prefix,$itemcountref,$settings) = @_;
6253:2): my ($min,$max,%chars,$numsaved,$numinrow);
6254:2): my %titles;
6255:2): if ($prefix eq 'passwords') {
6256:2): %titles = &Apache::lonlocal::texthash (
6257:2): min => 'Minimum password length',
6258:2): max => 'Maximum password length',
6259:2): chars => 'Required characters',
6260:2): );
6261:2): } elsif ($prefix eq 'secrets') {
6262:2): %titles = &Apache::lonlocal::texthash (
6263:2): min => 'Minimum secret length',
6264:2): max => 'Maximum secret length',
6265:2): chars => 'Required characters',
6266:2): );
6267:2): }
6268:2): $min = $Apache::lonnet::passwdmin;
6269:2): my $datatable;
6270:2): my $itemcount;
6271:2): if (ref($itemcountref)) {
6272:2): $itemcount = $$itemcountref;
6273:2): }
6274:2): if (ref($settings) eq 'HASH') {
6275:2): if ($settings->{min}) {
6276:2): $min = $settings->{min};
6277:2): }
6278:2): if ($settings->{max}) {
6279:2): $max = $settings->{max};
6280:2): }
6281:2): if (ref($settings->{chars}) eq 'ARRAY') {
6282:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
6283:2): }
6284:2): if ($prefix eq 'passwords') {
6285:2): if ($settings->{numsaved}) {
6286:2): $numsaved = $settings->{numsaved};
6287:2): }
6288:2): }
6289:2): }
6290:2): my %rulenames = &Apache::lonlocal::texthash(
6291:2): uc => 'At least one upper case letter',
6292:2): lc => 'At least one lower case letter',
6293:2): num => 'At least one number',
6294:2): spec => 'At least one non-alphanumeric',
6295:2): );
6296:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6297:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6298:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6299:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6300:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6301:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
6302:2): '</span></td></tr>';
6303:2): $itemcount ++;
6304:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6305:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6306:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6307:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
6308:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6309:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6310:2): '</span></td></tr>';
6311:2): $itemcount ++;
6312:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6313:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6314:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6315:2): '</span></td>';
6316:2): my $numinrow = 2;
6317:2): my @possrules = ('uc','lc','num','spec');
6318:2): $datatable .= '<td class="LC_left_item"><table>';
6319:2): for (my $i=0; $i<@possrules; $i++) {
6320:2): my ($rem,$checked);
6321:2): if ($chars{$possrules[$i]}) {
6322:2): $checked = ' checked="checked"';
6323:2): }
6324:2): $rem = $i%($numinrow);
6325:2): if ($rem == 0) {
6326:2): if ($i > 0) {
6327:2): $datatable .= '</tr>';
6328:2): }
6329:2): $datatable .= '<tr>';
6330:2): }
6331:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
6332:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6333:2): $rulenames{$possrules[$i]}.'</label></span></td>';
6334:2): }
6335:2): my $rem = @possrules%($numinrow);
6336:2): my $colsleft = $numinrow - $rem;
6337:2): if ($colsleft > 1 ) {
6338:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6339:2): ' </td>';
6340:2): } elsif ($colsleft == 1) {
6341:2): $datatable .= '<td class="LC_left_item"> </td>';
6342:2): }
6343:2): $datatable .='</table></td></tr>';
6344:2): $itemcount ++;
6345:2): if ($prefix eq 'passwords') {
6346:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
6347:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6348:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6349:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6350:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
6351:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6352:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6353:2): '</span></td></tr>';
6354:2): $itemcount ++;
6355:2): }
6356:2): if (ref($itemcountref)) {
6357:2): $$itemcountref += $itemcount;
6358:2): }
6359:2): return $datatable;
6360:2): }
6361:2):
1.160.6.113 raeburn 6362: sub print_wafproxy {
6363: my ($position,$dom,$settings,$rowtotal) = @_;
6364: my $css_class;
6365: my $itemcount = 0;
6366: my $datatable;
6367: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6368: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6369: my %lt = &wafproxy_titles();
6370: foreach my $server (sort(keys(%servers))) {
6371: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6372: next if ($serverhome eq '');
6373: my $serverdom;
6374: if ($serverhome ne $server) {
6375: $serverdom = &Apache::lonnet::host_domain($serverhome);
6376: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6377: $othercontrol{$server} = $serverdom;
6378: }
6379: } else {
6380: $serverdom = &Apache::lonnet::host_domain($server);
6381: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
6382: if ($serverdom ne $dom) {
6383: $othercontrol{$server} = $serverdom;
6384: } else {
6385: $setdom = 1;
6386: if (ref($settings) eq 'HASH') {
6387: if (ref($settings->{'alias'}) eq 'HASH') {
6388: $aliases{$dom} = $settings->{'alias'};
6389: if ($aliases{$dom} ne '') {
6390: $showdom = 1;
6391: }
6392: }
6393: if (ref($settings->{'saml'}) eq 'HASH') {
6394: $saml{$dom} = $settings->{'saml'};
6395: }
6396: }
6397: }
6398: }
6399: }
6400: if ($setdom) {
6401: %{$values{$dom}} = ();
6402: if (ref($settings) eq 'HASH') {
6403: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6404: $values{$dom}{$item} = $settings->{$item};
6405: }
6406: }
6407: }
6408: if (keys(%othercontrol)) {
6409: %otherdoms = reverse(%othercontrol);
6410: foreach my $domain (keys(%otherdoms)) {
6411: %{$values{$domain}} = ();
6412: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
6413: if (ref($config{'wafproxy'}) eq 'HASH') {
6414: $aliases{$domain} = $config{'wafproxy'}{'alias'};
6415: if (exists($config{'wafproxy'}{'saml'})) {
6416: $saml{$domain} = $config{'wafproxy'}{'saml'};
6417: }
6418: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6419: $values{$domain}{$item} = $config{'wafproxy'}{$item};
6420: }
6421: }
6422: }
6423: }
6424: if ($position eq 'top') {
6425: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6426: my %aliasinfo;
6427: foreach my $server (sort(keys(%servers))) {
6428: $itemcount ++;
6429: my $dom_in_effect;
6430: my $aliasrows = '<tr>'.
6431: '<td class="LC_left_item" style="vertical-align: baseline;">'.
6432: &mt('Hostname').': '.
6433: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
6434: if ($othercontrol{$server}) {
6435: $dom_in_effect = $othercontrol{$server};
6436: my ($current,$forsaml);
6437: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
6438: $current = $aliases{$dom_in_effect}{$server};
6439: }
6440: if (ref($saml{$dom_in_effect}) eq 'HASH') {
6441: if ($saml{$dom_in_effect}{$server}) {
6442: $forsaml = 1;
6443: }
6444: }
6445: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6446: &mt('Alias').': ';
6447: if ($current) {
6448: $aliasrows .= $current;
6449: if ($forsaml) {
6450: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
6451: }
6452: } else {
6453: $aliasrows .= &mt('None');
6454: }
6455: $aliasrows .= ' <span class="LC_small">('.
6456: &mt('controlled by domain: [_1]',
6457: '<b>'.$dom_in_effect.'</b>').')</span></td>';
6458: } else {
6459: $dom_in_effect = $dom;
6460: my ($current,$samlon,$samloff);
6461: $samloff = ' checked="checked"';
6462: if (ref($aliases{$dom}) eq 'HASH') {
6463: if ($aliases{$dom}{$server}) {
6464: $current = $aliases{$dom}{$server};
6465: }
6466: }
6467: if (ref($saml{$dom}) eq 'HASH') {
6468: if ($saml{$dom}{$server}) {
6469: $samlon = $samloff;
6470: undef($samloff);
6471: }
6472: }
6473: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6474: &mt('Alias').': '.
6475: '<input type="text" name="wafproxy_alias_'.$server.'" '.
6476: 'value="'.$current.'" size="30" />'.
6477: (' 'x2).'<span class="LC_nobreak">'.
6478: &mt('Alias used for SSO Auth').': <label>'.
6479: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
6480: &mt('No').'</label> <label>'.
6481: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
6482: &mt('Yes').'</label></span>'.
6483: '</td>';
6484: }
6485: $aliasrows .= '</tr>';
6486: $aliasinfo{$dom_in_effect} .= $aliasrows;
6487: }
6488: if ($aliasinfo{$dom}) {
6489: my ($onclick,$wafon,$wafoff,$showtable);
6490: $onclick = ' onclick="javascript:toggleWAF();"';
6491: $wafoff = ' checked="checked"';
6492: $showtable = ' style="display:none";';
6493: if ($showdom) {
6494: $wafon = $wafoff;
6495: $wafoff = '';
6496: $showtable = ' style="display:inline;"';
6497: }
6498: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6499: $datatable = '<tr'.$css_class.'>'.
6500: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
6501: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
6502: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
6503: &mt('Yes').'</label>'.(' 'x2).'<label>'.
6504: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
6505: &mt('No').'</label></span></td>'.
6506: '<td class="LC_left_item">'.
6507: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
6508: '</table></td></tr>';
6509: $itemcount++;
6510: }
6511: if (keys(%otherdoms)) {
6512: foreach my $key (sort(keys(%otherdoms))) {
6513: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6514: $datatable .= '<tr'.$css_class.'>'.
6515: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
6516: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
6517: '</table></td></tr>';
6518: $itemcount++;
6519: }
6520: }
6521: } else {
6522: my %ip_methods = &remoteip_methods();
6523: if ($setdom) {
6524: $itemcount ++;
6525: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6526: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
6527: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
6528: $wafstyle = ' style="display:none;"';
6529: $nowafstyle = ' style="display:table-row;"';
6530: $currwafdisplay = ' style="display: none"';
6531: $wafrangestyle = ' style="display: none"';
6532: $curr_remotip = 'n';
6533: $ssltossl = ' checked="checked"';
6534: if ($showdom) {
6535: $wafstyle = ' style="display:table-row;"';
6536: $nowafstyle = ' style="display:none;"';
6537: if (keys(%{$values{$dom}})) {
6538: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
6539: $curr_remotip = $values{$dom}{remoteip};
6540: }
6541: if ($curr_remotip eq 'h') {
6542: $currwafdisplay = ' style="display:table-row"';
6543: $wafrangestyle = ' style="display:inline-block;"';
6544: }
6545: if ($values{$dom}{'sslopt'}) {
6546: $alltossl = ' checked="checked"';
6547: $ssltossl = '';
6548: }
6549: }
6550: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
6551: $vpndircheck = ' checked="checked"';
6552: $currwafvpn = ' style="display:table-row;"';
6553: $wafrangestyle = ' style="display:inline-block;"';
6554: } else {
6555: $vpnaliascheck = ' checked="checked"';
6556: $currwafvpn = ' style="display:none;"';
6557: }
6558: }
6559: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6560: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
6561: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
6562: '</tr>'.
6563: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6564: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
6565: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
6566: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
6567: &mt('Range(s) stored in CIDR notation').'</div></td>'.
6568: '<td class="LC_left_item"><table>'.
6569: '<tr>'.
6570: '<td valign="top">'.$lt{'remoteip'}.': '.
6571: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
6572: foreach my $option ('m','h','n') {
6573: my $sel;
1.160.6.114 raeburn 6574: if ($option eq $curr_remotip) {
6575: $sel = ' selected="selected"';
6576: }
6577: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
6578: $ip_methods{$option}.'</option>';
6579: }
6580: $datatable .= '</select></td></tr>'."\n".
6581: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
6582: $lt{'ipheader'}.': '.
6583: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
6584: 'name="wafproxy_ipheader" />'.
6585: '</td></tr>'."\n".
6586: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
6587: $lt{'trusted'}.':<br />'.
6588: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
6589: $values{$dom}{'trusted'}.'</textarea>'.
6590: '</td></tr>'."\n".
6591: '<tr><td><hr /></td></tr>'."\n".
6592: '<tr>'.
1.160.6.113 raeburn 6593: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
6594: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
6595: $lt{'vpndirect'}.'</label>'.(' 'x2).
6596: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
6597: $lt{'vpnaliased'}.'</label></span></td></tr>';
6598: foreach my $item ('vpnint','vpnext') {
6599: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
6600: '<td valign="top">'.$lt{$item}.':<br />'.
6601: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
6602: $values{$dom}{$item}.'</textarea>'.
6603: '</td></tr>'."\n";
6604: }
6605: $datatable .= '<tr><td><hr /></td></tr>'."\n".
6606: '<tr>'.
6607: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
6608: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
6609: $lt{'alltossl'}.'</label>'.(' 'x2).
6610: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
6611: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
6612: '</table></td></tr>';
6613: }
6614: if (keys(%otherdoms)) {
6615: foreach my $domain (sort(keys(%otherdoms))) {
6616: $itemcount ++;
6617: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6618: $datatable .= '<tr'.$css_class.'>'.
6619: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
6620: '<td class="LC_left_item"><table>';
6621: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
6622: my $showval = &mt('None');
6623: if ($item eq 'ssl') {
6624: $showval = $lt{'ssltossl'};
6625: }
6626: if ($values{$domain}{$item}) {
6627: $showval = $values{$domain}{$item};
6628: if ($item eq 'ssl') {
6629: $showval = $lt{'alltossl'};
6630: } elsif ($item eq 'remoteip') {
6631: $showval = $ip_methods{$values{$domain}{$item}};
6632: }
6633: }
6634: $datatable .= '<tr>'.
6635: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
6636: }
6637: $datatable .= '</table></td></tr>';
6638: }
6639: }
6640: }
6641: $$rowtotal += $itemcount;
6642: return $datatable;
6643: }
6644:
6645: sub wafproxy_titles {
6646: return &Apache::lonlocal::texthash(
6647: remoteip => "Method for determining user's IP",
6648: ipheader => 'Request header containing remote IP',
6649: trusted => 'Trusted IP range(s)',
6650: vpnaccess => 'Access from institutional VPN',
6651: vpndirect => 'via regular hostname (no WAF)',
6652: vpnaliased => 'via aliased hostname (WAF)',
6653: vpnint => 'Internal IP Range(s) for VPN sessions',
6654: vpnext => 'IP Range(s) for backend WAF connections',
6655: sslopt => 'Forwarding http/https',
6656: alltossl => 'WAF forwards both http and https requests to https',
6657: ssltossl => 'WAF forwards http requests to http and https to https',
6658: );
6659: }
6660:
6661: sub remoteip_methods {
6662: return &Apache::lonlocal::texthash(
6663: m => 'Use Apache mod_remoteip',
6664: h => 'Use headers parsed by LON-CAPA',
6665: n => 'Not in use',
6666: );
6667: }
6668:
1.137 raeburn 6669: sub print_usersessions {
6670: my ($position,$dom,$settings,$rowtotal) = @_;
6671: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 6672: my (%by_ip,%by_location,@intdoms);
6673: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 6674:
6675: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6676: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6677: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6678: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6679: my $itemcount = 1;
6680: if ($position eq 'top') {
1.152 raeburn 6681: if (keys(%serverhomes) > 1) {
1.145 raeburn 6682: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 6683: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 6684: if (ref($settings) eq 'HASH') {
6685: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6686: $curroffloadnow = $settings->{'offloadnow'};
6687: }
1.160.6.105 raeburn 6688: if (ref($settings->{'offloadoth'}) eq 'HASH') {
6689: $curroffloadoth = $settings->{'offloadoth'};
6690: }
1.160.6.61 raeburn 6691: }
1.160.6.105 raeburn 6692: my $other_insts = scalar(keys(%by_location));
6693: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
6694: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 6695: } else {
1.140 raeburn 6696: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6697: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 6698: }
1.137 raeburn 6699: } else {
1.145 raeburn 6700: if (keys(%by_location) == 0) {
6701: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6702: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 6703: } else {
6704: my %lt = &usersession_titles();
6705: my $numinrow = 5;
6706: my $prefix;
6707: my @types;
6708: if ($position eq 'bottom') {
6709: $prefix = 'remote';
6710: @types = ('version','excludedomain','includedomain');
6711: } else {
6712: $prefix = 'hosted';
6713: @types = ('excludedomain','includedomain');
6714: }
6715: my (%current,%checkedon,%checkedoff);
6716: my @lcversions = &Apache::lonnet::all_loncaparevs();
6717: my @locations = sort(keys(%by_location));
6718: foreach my $type (@types) {
6719: $checkedon{$type} = '';
6720: $checkedoff{$type} = ' checked="checked"';
6721: }
6722: if (ref($settings) eq 'HASH') {
6723: if (ref($settings->{$prefix}) eq 'HASH') {
6724: foreach my $key (keys(%{$settings->{$prefix}})) {
6725: $current{$key} = $settings->{$prefix}{$key};
6726: if ($key eq 'version') {
6727: if ($current{$key} ne '') {
6728: $checkedon{$key} = ' checked="checked"';
6729: $checkedoff{$key} = '';
6730: }
6731: } elsif (ref($current{$key}) eq 'ARRAY') {
6732: $checkedon{$key} = ' checked="checked"';
6733: $checkedoff{$key} = '';
6734: }
1.137 raeburn 6735: }
6736: }
6737: }
1.145 raeburn 6738: foreach my $type (@types) {
6739: next if ($type ne 'version' && !@locations);
6740: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6741: $datatable .= '<tr'.$css_class.'>
6742: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
6743: <span class="LC_nobreak">
6744: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6745: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6746: if ($type eq 'version') {
6747: my $selector = '<select name="'.$prefix.'_version">';
6748: foreach my $version (@lcversions) {
6749: my $selected = '';
6750: if ($current{'version'} eq $version) {
6751: $selected = ' selected="selected"';
6752: }
6753: $selector .= ' <option value="'.$version.'"'.
6754: $selected.'>'.$version.'</option>';
6755: }
6756: $selector .= '</select> ';
6757: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6758: } else {
6759: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6760: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6761: ' />'.(' 'x2).
6762: '<input type="button" value="'.&mt('uncheck all').'" '.
6763: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6764: "\n".
6765: '</div><div><table>';
6766: my $rem;
6767: for (my $i=0; $i<@locations; $i++) {
6768: my ($showloc,$value,$checkedtype);
6769: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
6770: my $ip = $by_location{$locations[$i]}->[0];
6771: if (ref($by_ip{$ip}) eq 'ARRAY') {
6772: $value = join(':',@{$by_ip{$ip}});
6773: $showloc = join(', ',@{$by_ip{$ip}});
6774: if (ref($current{$type}) eq 'ARRAY') {
6775: foreach my $loc (@{$by_ip{$ip}}) {
6776: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6777: $checkedtype = ' checked="checked"';
6778: last;
6779: }
6780: }
1.138 raeburn 6781: }
6782: }
6783: }
1.145 raeburn 6784: $rem = $i%($numinrow);
6785: if ($rem == 0) {
6786: if ($i > 0) {
6787: $datatable .= '</tr>';
6788: }
6789: $datatable .= '<tr>';
6790: }
6791: $datatable .= '<td class="LC_left_item">'.
6792: '<span class="LC_nobreak"><label>'.
6793: '<input type="checkbox" name="'.$prefix.'_'.$type.
6794: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6795: '</label></span></td>';
1.137 raeburn 6796: }
1.145 raeburn 6797: $rem = @locations%($numinrow);
6798: my $colsleft = $numinrow - $rem;
6799: if ($colsleft > 1 ) {
6800: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6801: ' </td>';
6802: } elsif ($colsleft == 1) {
6803: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6804: }
1.145 raeburn 6805: $datatable .= '</tr></table>';
1.137 raeburn 6806: }
1.145 raeburn 6807: $datatable .= '</td></tr>';
6808: $itemcount ++;
1.137 raeburn 6809: }
6810: }
6811: }
6812: $$rowtotal += $itemcount;
6813: return $datatable;
6814: }
6815:
1.138 raeburn 6816: sub build_location_hashes {
6817: my ($intdoms,$by_ip,$by_location) = @_;
6818: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
6819: (ref($by_location) eq 'HASH'));
6820: my %iphost = &Apache::lonnet::get_iphost();
6821: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6822: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6823: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6824: foreach my $id (@{$iphost{$primary_ip}}) {
6825: my $intdom = &Apache::lonnet::internet_dom($id);
6826: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6827: push(@{$intdoms},$intdom);
6828: }
6829: }
6830: }
6831: foreach my $ip (keys(%iphost)) {
6832: if (ref($iphost{$ip}) eq 'ARRAY') {
6833: foreach my $id (@{$iphost{$ip}}) {
6834: my $location = &Apache::lonnet::internet_dom($id);
6835: if ($location) {
6836: next if (grep(/^\Q$location\E$/,@{$intdoms}));
6837: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6838: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6839: push(@{$by_ip->{$ip}},$location);
6840: }
6841: } else {
6842: $by_ip->{$ip} = [$location];
6843: }
6844: }
6845: }
6846: }
6847: }
6848: foreach my $ip (sort(keys(%{$by_ip}))) {
6849: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6850: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6851: my $first = $by_ip->{$ip}->[0];
6852: if (ref($by_location->{$first}) eq 'ARRAY') {
6853: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6854: push(@{$by_location->{$first}},$ip);
6855: }
6856: } else {
6857: $by_location->{$first} = [$ip];
6858: }
6859: }
6860: }
6861: return;
6862: }
6863:
1.145 raeburn 6864: sub current_offloads_to {
6865: my ($dom,$settings,$servers) = @_;
6866: my (%spareid,%otherdomconfigs);
1.152 raeburn 6867: if (ref($servers) eq 'HASH') {
1.145 raeburn 6868: foreach my $lonhost (sort(keys(%{$servers}))) {
6869: my $gotspares;
1.152 raeburn 6870: if (ref($settings) eq 'HASH') {
6871: if (ref($settings->{'spares'}) eq 'HASH') {
6872: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6873: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6874: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6875: $gotspares = 1;
6876: }
1.145 raeburn 6877: }
6878: }
6879: unless ($gotspares) {
6880: my $gotspares;
6881: my $serverhomeID =
6882: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6883: my $serverhomedom =
6884: &Apache::lonnet::host_domain($serverhomeID);
6885: if ($serverhomedom ne $dom) {
6886: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6887: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6888: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6889: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6890: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6891: $gotspares = 1;
6892: }
6893: }
6894: } else {
6895: $otherdomconfigs{$serverhomedom} =
6896: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6897: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6898: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6899: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6900: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6901: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6902: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6903: $gotspares = 1;
6904: }
6905: }
6906: }
6907: }
6908: }
6909: }
6910: }
6911: unless ($gotspares) {
6912: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6913: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6914: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6915: } else {
6916: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6917: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6918: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6919: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6920: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6921: } else {
1.150 raeburn 6922: my %what = (
6923: spareid => 1,
6924: );
6925: my ($result,$returnhash) =
6926: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6927: if ($result eq 'ok') {
6928: if (ref($returnhash) eq 'HASH') {
6929: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6930: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6931: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6932: }
6933: }
1.145 raeburn 6934: }
6935: }
6936: }
6937: }
6938: }
6939: }
6940: return %spareid;
6941: }
6942:
6943: sub spares_row {
1.160.6.105 raeburn 6944: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6945: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6946: my $css_class;
6947: my $numinrow = 4;
6948: my $itemcount = 1;
6949: my $datatable;
1.152 raeburn 6950: my %typetitles = &sparestype_titles();
6951: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6952: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6953: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6954: my ($othercontrol,$serverdom);
6955: if ($serverhome ne $server) {
6956: $serverdom = &Apache::lonnet::host_domain($serverhome);
6957: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6958: } else {
6959: $serverdom = &Apache::lonnet::host_domain($server);
6960: if ($serverdom ne $dom) {
6961: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6962: }
6963: }
6964: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6965: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6966: if (ref($curroffloadnow) eq 'HASH') {
6967: if ($curroffloadnow->{$server}) {
6968: $checkednow = ' checked="checked"';
6969: }
6970: }
1.160.6.105 raeburn 6971: if (ref($curroffloadoth) eq 'HASH') {
6972: if ($curroffloadoth->{$server}) {
6973: $checkedoth = ' checked="checked"';
6974: }
6975: }
1.145 raeburn 6976: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6977: $datatable .= '<tr'.$css_class.'>
6978: <td rowspan="2">
1.160.6.13 raeburn 6979: <span class="LC_nobreak">'.
6980: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6981: ,'<b>'.$server.'</b>').'</span><br />'.
6982: '<span class="LC_nobreak">'."\n".
6983: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6984: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6985: "\n";
1.160.6.105 raeburn 6986: if ($other_insts) {
6987: $datatable .= '<br />'.
6988: '<span class="LC_nobreak">'."\n".
6989: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6990: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6991: "\n";
6992: }
1.145 raeburn 6993: my (%current,%canselect);
1.152 raeburn 6994: my @choices =
6995: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6996: foreach my $type ('primary','default') {
6997: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6998: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6999: my @spares = @{$spareid->{$server}{$type}};
7000: if (@spares > 0) {
1.152 raeburn 7001: if ($othercontrol) {
7002: $current{$type} = join(', ',@spares);
7003: } else {
7004: $current{$type} .= '<table>';
7005: my $numspares = scalar(@spares);
7006: for (my $i=0; $i<@spares; $i++) {
7007: my $rem = $i%($numinrow);
7008: if ($rem == 0) {
7009: if ($i > 0) {
7010: $current{$type} .= '</tr>';
7011: }
7012: $current{$type} .= '<tr>';
1.145 raeburn 7013: }
1.152 raeburn 7014: $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'".');" /> '.
7015: $spareid->{$server}{$type}[$i].
7016: '</label></td>'."\n";
7017: }
7018: my $rem = @spares%($numinrow);
7019: my $colsleft = $numinrow - $rem;
7020: if ($colsleft > 1 ) {
7021: $current{$type} .= '<td colspan="'.$colsleft.
7022: '" class="LC_left_item">'.
7023: ' </td>';
7024: } elsif ($colsleft == 1) {
7025: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7026: }
1.152 raeburn 7027: $current{$type} .= '</tr></table>';
1.150 raeburn 7028: }
1.145 raeburn 7029: }
7030: }
7031: if ($current{$type} eq '') {
7032: $current{$type} = &mt('None specified');
7033: }
1.152 raeburn 7034: if ($othercontrol) {
7035: if ($type eq 'primary') {
7036: $canselect{$type} = $othercontrol;
7037: }
7038: } else {
7039: $canselect{$type} =
7040: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7041: '<select name="newspare_'.$type.'_'.$server.'" '.
7042: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7043: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7044: if (@choices > 0) {
7045: foreach my $lonhost (@choices) {
7046: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7047: }
7048: }
7049: $canselect{$type} .= '</select>'."\n";
7050: }
7051: } else {
7052: $current{$type} = &mt('Could not be determined');
7053: if ($type eq 'primary') {
7054: $canselect{$type} = $othercontrol;
7055: }
1.145 raeburn 7056: }
1.152 raeburn 7057: if ($type eq 'default') {
7058: $datatable .= '<tr'.$css_class.'>';
7059: }
7060: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7061: '<td>'.$current{$type}.'</td>'."\n".
7062: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7063: }
7064: $itemcount ++;
7065: }
7066: }
7067: $$rowtotal += $itemcount;
7068: return $datatable;
7069: }
7070:
1.152 raeburn 7071: sub possible_newspares {
7072: my ($server,$currspares,$serverhomes,$altids) = @_;
7073: my $serverhostname = &Apache::lonnet::hostname($server);
7074: my %excluded;
7075: if ($serverhostname ne '') {
7076: %excluded = (
7077: $serverhostname => 1,
7078: );
7079: }
7080: if (ref($currspares) eq 'HASH') {
7081: foreach my $type (keys(%{$currspares})) {
7082: if (ref($currspares->{$type}) eq 'ARRAY') {
7083: if (@{$currspares->{$type}} > 0) {
7084: foreach my $curr (@{$currspares->{$type}}) {
7085: my $hostname = &Apache::lonnet::hostname($curr);
7086: $excluded{$hostname} = 1;
7087: }
7088: }
7089: }
7090: }
7091: }
7092: my @choices;
7093: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7094: if (keys(%{$serverhomes}) > 1) {
7095: foreach my $name (sort(keys(%{$serverhomes}))) {
7096: unless ($excluded{$name}) {
7097: if (exists($altids->{$serverhomes->{$name}})) {
7098: push(@choices,$altids->{$serverhomes->{$name}});
7099: } else {
7100: push(@choices,$serverhomes->{$name});
1.145 raeburn 7101: }
7102: }
7103: }
7104: }
7105: }
1.152 raeburn 7106: return sort(@choices);
1.145 raeburn 7107: }
7108:
1.150 raeburn 7109: sub print_loadbalancing {
7110: my ($dom,$settings,$rowtotal) = @_;
7111: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7112: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7113: my $numinrow = 1;
7114: my $datatable;
7115: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 7116: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 7117: if (ref($settings) eq 'HASH') {
7118: %existing = %{$settings};
7119: }
7120: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7121: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 7122: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7123: } else {
7124: return;
7125: }
7126: my ($othertitle,$usertypes,$types) =
7127: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 7128: my $rownum = 8;
1.150 raeburn 7129: if (ref($types) eq 'ARRAY') {
7130: $rownum += scalar(@{$types});
7131: }
1.160.6.7 raeburn 7132: my @css_class = ('LC_odd_row','LC_even_row');
7133: my $balnum = 0;
7134: my $islast;
7135: my (@toshow,$disabledtext);
7136: if (keys(%currbalancer) > 0) {
7137: @toshow = sort(keys(%currbalancer));
7138: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7139: push(@toshow,'');
7140: }
7141: } else {
7142: @toshow = ('');
7143: $disabledtext = &mt('No existing load balancer');
7144: }
7145: foreach my $lonhost (@toshow) {
7146: if ($balnum == scalar(@toshow)-1) {
7147: $islast = 1;
7148: } else {
7149: $islast = 0;
7150: }
7151: my $cssidx = $balnum%2;
7152: my $targets_div_style = 'display: none';
7153: my $disabled_div_style = 'display: block';
7154: my $homedom_div_style = 'display: none';
7155: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7156: '<td rowspan="'.$rownum.'" valign="top">'.
7157: '<p>';
7158: if ($lonhost eq '') {
7159: $datatable .= '<span class="LC_nobreak">';
7160: if (keys(%currbalancer) > 0) {
7161: $datatable .= &mt('Add balancer:');
7162: } else {
7163: $datatable .= &mt('Enable balancer:');
7164: }
7165: $datatable .= ' '.
7166: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7167: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7168: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7169: '<option value="" selected="selected">'.&mt('None').
7170: '</option>'."\n";
7171: foreach my $server (sort(keys(%servers))) {
7172: next if ($currbalancer{$server});
7173: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7174: }
7175: $datatable .=
7176: '</select>'."\n".
7177: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7178: } else {
7179: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7180: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7181: &mt('Stop balancing').'</label>'.
7182: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7183: $targets_div_style = 'display: block';
7184: $disabled_div_style = 'display: none';
7185: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7186: $homedom_div_style = 'display: block';
7187: }
7188: }
7189: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7190: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7191: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7192: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7193: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7194: my @sparestypes = ('primary','default');
7195: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 7196: my %hostherechecked = (
7197: no => ' checked="checked"',
7198: );
1.160.6.94 raeburn 7199: my %balcookiechecked = (
7200: no => ' checked="checked"',
7201: );
1.160.6.7 raeburn 7202: foreach my $sparetype (@sparestypes) {
7203: my $targettable;
7204: for (my $i=0; $i<$numspares; $i++) {
7205: my $checked;
7206: if (ref($currtargets{$lonhost}) eq 'HASH') {
7207: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7208: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7209: $checked = ' checked="checked"';
7210: }
7211: }
7212: }
7213: my ($chkboxval,$disabled);
7214: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7215: $chkboxval = $spares[$i];
7216: }
7217: if (exists($currbalancer{$spares[$i]})) {
7218: $disabled = ' disabled="disabled"';
7219: }
7220: $targettable .=
1.160.6.55 raeburn 7221: '<td><span class="LC_nobreak"><label>'.
7222: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 7223: $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 7224: '</span></label></span></td>';
1.160.6.7 raeburn 7225: my $rem = $i%($numinrow);
7226: if ($rem == 0) {
7227: if (($i > 0) && ($i < $numspares-1)) {
7228: $targettable .= '</tr>';
7229: }
7230: if ($i < $numspares-1) {
7231: $targettable .= '<tr>';
1.150 raeburn 7232: }
7233: }
7234: }
1.160.6.7 raeburn 7235: if ($targettable ne '') {
7236: my $rem = $numspares%($numinrow);
7237: my $colsleft = $numinrow - $rem;
7238: if ($colsleft > 1 ) {
7239: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7240: ' </td>';
7241: } elsif ($colsleft == 1) {
7242: $targettable .= '<td class="LC_left_item"> </td>';
7243: }
7244: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7245: '<table><tr>'.$targettable.'</tr></table><br />';
7246: }
1.160.6.76 raeburn 7247: $hostherechecked{$sparetype} = '';
7248: if (ref($currtargets{$lonhost}) eq 'HASH') {
7249: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7250: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7251: $hostherechecked{$sparetype} = ' checked="checked"';
7252: $hostherechecked{'no'} = '';
7253: }
7254: }
7255: }
7256: }
1.160.6.94 raeburn 7257: if ($currcookies{$lonhost}) {
7258: %balcookiechecked = (
7259: yes => ' checked="checked"',
7260: );
7261: }
1.160.6.76 raeburn 7262: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7263: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7264: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7265: foreach my $sparetype (@sparestypes) {
7266: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7267: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7268: '</i></label><br />';
1.160.6.7 raeburn 7269: }
1.160.6.94 raeburn 7270: $datatable .= &mt('Use balancer cookie').'<br />'.
7271: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7272: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7273: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7274: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7275: '</div></td></tr>'.
1.160.6.7 raeburn 7276: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7277: $othertitle,$usertypes,$types,\%servers,
7278: \%currbalancer,$lonhost,
7279: $targets_div_style,$homedom_div_style,
7280: $css_class[$cssidx],$balnum,$islast);
7281: $$rowtotal += $rownum;
7282: $balnum ++;
7283: }
7284: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7285: return $datatable;
7286: }
7287:
7288: sub get_loadbalancers_config {
1.160.6.94 raeburn 7289: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 7290: return unless ((ref($servers) eq 'HASH') &&
7291: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 7292: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7293: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 7294: if (keys(%{$existing}) > 0) {
7295: my $oldlonhost;
7296: foreach my $key (sort(keys(%{$existing}))) {
7297: if ($key eq 'lonhost') {
7298: $oldlonhost = $existing->{'lonhost'};
7299: $currbalancer->{$oldlonhost} = 1;
7300: } elsif ($key eq 'targets') {
7301: if ($oldlonhost) {
7302: $currtargets->{$oldlonhost} = $existing->{'targets'};
7303: }
7304: } elsif ($key eq 'rules') {
7305: if ($oldlonhost) {
7306: $currrules->{$oldlonhost} = $existing->{'rules'};
7307: }
7308: } elsif (ref($existing->{$key}) eq 'HASH') {
7309: $currbalancer->{$key} = 1;
7310: $currtargets->{$key} = $existing->{$key}{'targets'};
7311: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 7312: if ($existing->{$key}{'cookie'}) {
7313: $currcookies->{$key} = 1;
7314: }
1.150 raeburn 7315: }
7316: }
1.160.6.7 raeburn 7317: } else {
7318: my ($balancerref,$targetsref) =
7319: &Apache::lonnet::get_lonbalancer_config($servers);
7320: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7321: foreach my $server (sort(keys(%{$balancerref}))) {
7322: $currbalancer->{$server} = 1;
7323: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7324: }
7325: }
7326: }
1.160.6.7 raeburn 7327: return;
1.150 raeburn 7328: }
7329:
7330: sub loadbalancing_rules {
7331: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 7332: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7333: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7334: my $output;
1.160.6.7 raeburn 7335: my $num = 0;
7336: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7337: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7338: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7339: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 7340: $num ++;
1.150 raeburn 7341: my $current;
7342: if (ref($currrules) eq 'HASH') {
7343: $current = $currrules->{$type};
7344: }
1.160.6.55 raeburn 7345: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 7346: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7347: $current = '';
7348: }
7349: }
7350: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 7351: $servers,$currbalancer,$lonhost,$dom,
7352: $targets_div_style,$homedom_div_style,
7353: $css_class,$balnum,$num,$islast);
1.150 raeburn 7354: }
7355: }
7356: return $output;
7357: }
7358:
7359: sub loadbalancing_titles {
7360: my ($dom,$intdom,$usertypes,$types) = @_;
7361: my %othertypes = (
7362: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7363: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7364: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7365: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 7366: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7367: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7368: );
1.160.6.26 raeburn 7369: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 7370: my @available;
1.150 raeburn 7371: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7372: @available = @{$types};
1.150 raeburn 7373: }
1.160.6.89 raeburn 7374: unless (grep(/^default$/,@available)) {
7375: push(@available,'default');
7376: }
7377: unshift(@alltypes,@available);
1.150 raeburn 7378: my %titles;
7379: foreach my $type (@alltypes) {
7380: if ($type =~ /^_LC_/) {
7381: $titles{$type} = $othertypes{$type};
7382: } elsif ($type eq 'default') {
7383: $titles{$type} = &mt('All users from [_1]',$dom);
7384: if (ref($types) eq 'ARRAY') {
7385: if (@{$types} > 0) {
7386: $titles{$type} = &mt('Other users from [_1]',$dom);
7387: }
7388: }
7389: } elsif (ref($usertypes) eq 'HASH') {
7390: $titles{$type} = $usertypes->{$type};
7391: }
7392: }
7393: return (\@alltypes,\%othertypes,\%titles);
7394: }
7395:
7396: sub loadbalance_rule_row {
1.160.6.7 raeburn 7397: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7398: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 7399: my @rulenames;
1.150 raeburn 7400: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 7401: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 7402: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7403: } else {
1.160.6.26 raeburn 7404: @rulenames = ('default','homeserver');
7405: if ($type eq '_LC_external') {
7406: push(@rulenames,'externalbalancer');
7407: } else {
7408: push(@rulenames,'specific');
7409: }
7410: push(@rulenames,'none');
1.150 raeburn 7411: }
7412: my $style = $targets_div_style;
1.160.6.55 raeburn 7413: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7414: $style = $homedom_div_style;
7415: }
1.160.6.7 raeburn 7416: my $space;
7417: if ($islast && $num == 1) {
7418: $space = '<div display="inline-block"> </div>';
7419: }
7420: my $output =
7421: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
7422: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7423: '<td valaign="top">'.$space.
7424: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7425: for (my $i=0; $i<@rulenames; $i++) {
7426: my $rule = $rulenames[$i];
7427: my ($checked,$extra);
7428: if ($rulenames[$i] eq 'default') {
7429: $rule = '';
7430: }
7431: if ($rulenames[$i] eq 'specific') {
7432: if (ref($servers) eq 'HASH') {
7433: my $default;
7434: if (($current ne '') && (exists($servers->{$current}))) {
7435: $checked = ' checked="checked"';
7436: }
7437: unless ($checked) {
7438: $default = ' selected="selected"';
7439: }
1.160.6.7 raeburn 7440: $extra =
7441: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7442: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7443: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7444: '<option value=""'.$default.'></option>'."\n";
7445: foreach my $server (sort(keys(%{$servers}))) {
7446: if (ref($currbalancer) eq 'HASH') {
7447: next if (exists($currbalancer->{$server}));
7448: }
1.150 raeburn 7449: my $selected;
1.160.6.7 raeburn 7450: if ($server eq $current) {
1.150 raeburn 7451: $selected = ' selected="selected"';
7452: }
1.160.6.7 raeburn 7453: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7454: }
7455: $extra .= '</select>';
7456: }
7457: } elsif ($rule eq $current) {
7458: $checked = ' checked="checked"';
7459: }
7460: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 7461: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7462: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7463: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 7464: ')"'.$checked.' /> ';
1.160.6.56 raeburn 7465: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 7466: $output .= $ruletitles{'particular'};
7467: } else {
7468: $output .= $ruletitles{$rulenames[$i]};
7469: }
7470: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7471: }
7472: $output .= '</div></td></tr>'."\n";
7473: return $output;
7474: }
7475:
7476: sub offloadtype_text {
7477: my %ruletitles = &Apache::lonlocal::texthash (
7478: 'default' => 'Offloads to default destinations',
7479: 'homeserver' => "Offloads to user's home server",
7480: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7481: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 7482: 'none' => 'No offload',
1.160.6.26 raeburn 7483: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7484: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 7485: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7486: );
7487: return %ruletitles;
7488: }
7489:
7490: sub sparestype_titles {
7491: my %typestitles = &Apache::lonlocal::texthash (
7492: 'primary' => 'primary',
7493: 'default' => 'default',
7494: );
7495: return %typestitles;
7496: }
7497:
1.28 raeburn 7498: sub contact_titles {
7499: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 7500: 'supportemail' => 'Support E-mail address',
7501: 'adminemail' => 'Default Server Admin E-mail address',
7502: 'errormail' => 'Error reports to be e-mailed to',
7503: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 7504: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7505: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 7506: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7507: 'requestsmail' => 'E-mail from course requests requiring approval',
7508: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 7509: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 7510: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 7511: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
7512: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 7513: 'errorweights' => 'Weights used to compute error count',
7514: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7515: );
7516: my %short_titles = &Apache::lonlocal::texthash (
7517: adminemail => 'Admin E-mail address',
7518: supportemail => 'Support E-mail',
7519: );
7520: return (\%titles,\%short_titles);
7521: }
7522:
1.160.6.78 raeburn 7523: sub helpform_fields {
7524: my %titles = &Apache::lonlocal::texthash (
7525: 'username' => 'Name',
7526: 'user' => 'Username/domain',
7527: 'phone' => 'Phone',
7528: 'cc' => 'Cc e-mail',
7529: 'course' => 'Course Details',
7530: 'section' => 'Sections',
7531: 'screenshot' => 'File upload',
7532: );
7533: my @fields = ('username','phone','user','course','section','cc','screenshot');
7534: my %possoptions = (
7535: username => ['yes','no','req'],
7536: phone => ['yes','no','req'],
7537: user => ['yes','no'],
7538: cc => ['yes','no'],
7539: course => ['yes','no'],
7540: section => ['yes','no'],
7541: screenshot => ['yes','no'],
7542: );
7543: my %fieldoptions = &Apache::lonlocal::texthash (
7544: 'yes' => 'Optional',
7545: 'req' => 'Required',
7546: 'no' => "Not shown",
7547: );
7548: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7549: }
7550:
1.72 raeburn 7551: sub tool_titles {
7552: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 7553: aboutme => 'Personal web page',
1.86 raeburn 7554: blog => 'Blog',
1.160.6.4 raeburn 7555: webdav => 'WebDAV',
1.86 raeburn 7556: portfolio => 'Portfolio',
1.160.6.118.2 10(raebu 7557:22): timezone => 'Can set time zone',
1.88 bisitz 7558: official => 'Official courses (with institutional codes)',
7559: unofficial => 'Unofficial courses',
1.98 raeburn 7560: community => 'Communities',
1.160.6.30 raeburn 7561: textbook => 'Textbook courses',
1.86 raeburn 7562: );
1.72 raeburn 7563: return %titles;
7564: }
7565:
1.101 raeburn 7566: sub courserequest_titles {
7567: my %titles = &Apache::lonlocal::texthash (
7568: official => 'Official',
7569: unofficial => 'Unofficial',
7570: community => 'Communities',
1.160.6.30 raeburn 7571: textbook => 'Textbook',
1.101 raeburn 7572: norequest => 'Not allowed',
1.104 raeburn 7573: approval => 'Approval by Dom. Coord.',
1.101 raeburn 7574: validate => 'With validation',
7575: autolimit => 'Numerical limit',
1.103 raeburn 7576: unlimited => '(blank for unlimited)',
1.101 raeburn 7577: );
7578: return %titles;
7579: }
7580:
1.160.6.5 raeburn 7581: sub authorrequest_titles {
7582: my %titles = &Apache::lonlocal::texthash (
7583: norequest => 'Not allowed',
7584: approval => 'Approval by Dom. Coord.',
7585: automatic => 'Automatic approval',
7586: );
7587: return %titles;
7588: }
7589:
1.101 raeburn 7590: sub courserequest_conditions {
7591: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7592: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 7593: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7594: );
7595: return %conditions;
7596: }
7597:
7598:
1.27 raeburn 7599: sub print_usercreation {
1.30 raeburn 7600: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7601: my $numinrow = 4;
1.28 raeburn 7602: my $datatable;
7603: if ($position eq 'top') {
1.30 raeburn 7604: $$rowtotal ++;
1.34 raeburn 7605: my $rowcount = 0;
1.32 raeburn 7606: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7607: if (ref($rules) eq 'HASH') {
7608: if (keys(%{$rules}) > 0) {
1.32 raeburn 7609: $datatable .= &user_formats_row('username',$settings,$rules,
7610: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7611: $$rowtotal ++;
1.32 raeburn 7612: $rowcount ++;
7613: }
7614: }
7615: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7616: if (ref($idrules) eq 'HASH') {
7617: if (keys(%{$idrules}) > 0) {
7618: $datatable .= &user_formats_row('id',$settings,$idrules,
7619: $idruleorder,$numinrow,$rowcount);
7620: $$rowtotal ++;
7621: $rowcount ++;
1.28 raeburn 7622: }
7623: }
1.39 raeburn 7624: if ($rowcount == 0) {
7625: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7626: $$rowtotal ++;
7627: $rowcount ++;
7628: }
1.34 raeburn 7629: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 7630: my @creators = ('author','course','requestcrs');
1.37 raeburn 7631: my ($rules,$ruleorder) =
7632: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7633: my %lt = &usercreation_types();
7634: my %checked;
7635: if (ref($settings) eq 'HASH') {
7636: if (ref($settings->{'cancreate'}) eq 'HASH') {
7637: foreach my $item (@creators) {
7638: $checked{$item} = $settings->{'cancreate'}{$item};
7639: }
7640: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7641: foreach my $item (@creators) {
7642: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7643: $checked{$item} = 'none';
7644: }
7645: }
7646: }
7647: }
7648: my $rownum = 0;
7649: foreach my $item (@creators) {
7650: $rownum ++;
1.160.6.34 raeburn 7651: if ($checked{$item} eq '') {
7652: $checked{$item} = 'any';
1.34 raeburn 7653: }
7654: my $css_class;
7655: if ($rownum%2) {
7656: $css_class = '';
7657: } else {
7658: $css_class = ' class="LC_odd_row" ';
7659: }
7660: $datatable .= '<tr'.$css_class.'>'.
7661: '<td><span class="LC_nobreak">'.$lt{$item}.
7662: '</span></td><td align="right">';
1.160.6.34 raeburn 7663: my @options = ('any');
7664: if (ref($rules) eq 'HASH') {
7665: if (keys(%{$rules}) > 0) {
7666: push(@options,('official','unofficial'));
1.37 raeburn 7667: }
7668: }
1.160.6.34 raeburn 7669: push(@options,'none');
1.37 raeburn 7670: foreach my $option (@options) {
1.50 raeburn 7671: my $type = 'radio';
1.34 raeburn 7672: my $check = ' ';
1.160.6.34 raeburn 7673: if ($checked{$item} eq $option) {
7674: $check = ' checked="checked" ';
1.34 raeburn 7675: }
7676: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7677: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7678: $item.'" value="'.$option.'"'.$check.'/> '.
7679: $lt{$option}.'</label> </span>';
7680: }
7681: $datatable .= '</td></tr>';
7682: }
1.28 raeburn 7683: } else {
7684: my @contexts = ('author','course','domain');
7685: my @authtypes = ('int','krb4','krb5','loc');
7686: my %checked;
7687: if (ref($settings) eq 'HASH') {
7688: if (ref($settings->{'authtypes'}) eq 'HASH') {
7689: foreach my $item (@contexts) {
7690: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7691: foreach my $auth (@authtypes) {
7692: if ($settings->{'authtypes'}{$item}{$auth}) {
7693: $checked{$item}{$auth} = ' checked="checked" ';
7694: }
7695: }
7696: }
7697: }
1.27 raeburn 7698: }
1.35 raeburn 7699: } else {
7700: foreach my $item (@contexts) {
1.36 raeburn 7701: foreach my $auth (@authtypes) {
1.35 raeburn 7702: $checked{$item}{$auth} = ' checked="checked" ';
7703: }
7704: }
1.27 raeburn 7705: }
1.28 raeburn 7706: my %title = &context_names();
7707: my %authname = &authtype_names();
7708: my $rownum = 0;
7709: my $css_class;
7710: foreach my $item (@contexts) {
7711: if ($rownum%2) {
7712: $css_class = '';
7713: } else {
7714: $css_class = ' class="LC_odd_row" ';
7715: }
1.30 raeburn 7716: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7717: '<td>'.$title{$item}.
7718: '</td><td class="LC_left_item">'.
7719: '<span class="LC_nobreak">';
7720: foreach my $auth (@authtypes) {
7721: $datatable .= '<label>'.
7722: '<input type="checkbox" name="'.$item.'_auth" '.
7723: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7724: $authname{$auth}.'</label> ';
7725: }
7726: $datatable .= '</span></td></tr>';
7727: $rownum ++;
1.27 raeburn 7728: }
1.30 raeburn 7729: $$rowtotal += $rownum;
1.27 raeburn 7730: }
7731: return $datatable;
7732: }
7733:
1.160.6.34 raeburn 7734: sub print_selfcreation {
7735: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 7736: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7737: $emaildomain,$datatable);
1.160.6.34 raeburn 7738: if (ref($settings) eq 'HASH') {
7739: if (ref($settings->{'cancreate'}) eq 'HASH') {
7740: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 7741: if (ref($createsettings) eq 'HASH') {
7742: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7743: @selfcreate = @{$createsettings->{'selfcreate'}};
7744: } elsif ($createsettings->{'selfcreate'} ne '') {
7745: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7746: @selfcreate = ('email','login','sso');
7747: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7748: @selfcreate = ($createsettings->{'selfcreate'});
7749: }
7750: }
7751: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7752: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 7753: }
1.160.6.93 raeburn 7754: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7755: $emailoptions = $createsettings->{'emailoptions'};
7756: }
7757: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7758: $emailverified = $createsettings->{'emailverified'};
7759: }
7760: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7761: $emaildomain = $createsettings->{'emaildomain'};
7762: }
1.160.6.34 raeburn 7763: }
7764: }
7765: }
7766: my %radiohash;
7767: my $numinrow = 4;
7768: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 7769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 7770: if ($position eq 'top') {
7771: my %choices = &Apache::lonlocal::texthash (
7772: cancreate_login => 'Institutional Login',
7773: cancreate_sso => 'Institutional Single Sign On',
7774: );
7775: my @toggles = sort(keys(%choices));
7776: my %defaultchecked = (
7777: 'cancreate_login' => 'off',
7778: 'cancreate_sso' => 'off',
7779: );
1.160.6.35 raeburn 7780: my ($onclick,$itemcount);
1.160.6.34 raeburn 7781: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7782: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 7783: $$rowtotal += $itemcount;
1.160.6.34 raeburn 7784:
7785: if (ref($usertypes) eq 'HASH') {
7786: if (keys(%{$usertypes}) > 0) {
7787: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7788: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 7789: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 7790: $$rowtotal ++;
7791: }
7792: }
1.160.6.44 raeburn 7793: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7794: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7795: $fieldtitles{'inststatus'} = &mt('Institutional status');
7796: my $rem;
7797: my $numperrow = 2;
7798: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7799: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 7800: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 7801: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 7802: '<table>'."\n";
1.160.6.44 raeburn 7803: for (my $i=0; $i<@fields; $i++) {
7804: $rem = $i%($numperrow);
7805: if ($rem == 0) {
7806: if ($i > 0) {
7807: $datatable .= '</tr>';
7808: }
7809: $datatable .= '<tr>';
7810: }
7811: my $currval;
1.160.6.51 raeburn 7812: if (ref($createsettings) eq 'HASH') {
7813: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7814: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7815: }
1.160.6.44 raeburn 7816: }
7817: $datatable .= '<td class="LC_left_item">'.
7818: '<span class="LC_nobreak">'.
7819: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7820: 'value="'.$currval.'" size="10" /> '.
7821: $fieldtitles{$fields[$i]}.'</span></td>';
7822: }
7823: my $colsleft = $numperrow - $rem;
7824: if ($colsleft > 1 ) {
7825: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7826: ' </td>';
7827: } elsif ($colsleft == 1) {
7828: $datatable .= '<td class="LC_left_item"> </td>';
7829: }
7830: $datatable .= '</tr></table></td></tr>';
7831: $$rowtotal ++;
1.160.6.34 raeburn 7832: } elsif ($position eq 'middle') {
7833: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 7834: my @posstypes;
1.160.6.34 raeburn 7835: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7836: @posstypes = @{$types};
7837: }
7838: unless (grep(/^default$/,@posstypes)) {
7839: push(@posstypes,'default');
7840: }
7841: my %usertypeshash;
7842: if (ref($usertypes) eq 'HASH') {
7843: %usertypeshash = %{$usertypes};
7844: }
7845: $usertypeshash{'default'} = $othertitle;
7846: foreach my $status (@posstypes) {
7847: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7848: $numinrow,$$rowtotal,\%usertypeshash);
7849: $$rowtotal ++;
1.160.6.34 raeburn 7850: }
7851: } else {
1.160.6.40 raeburn 7852: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 7853: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 7854: );
7855: my @toggles = sort(keys(%choices));
7856: my %defaultchecked = (
7857: 'cancreate_email' => 'off',
7858: );
1.160.6.93 raeburn 7859: my $customclass = 'LC_selfcreate_email';
7860: my $classprefix = 'LC_canmodify_emailusername_';
7861: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 7862: my $display = 'none';
1.160.6.93 raeburn 7863: my $rowstyle = 'display:none';
1.160.6.40 raeburn 7864: if (grep(/^\Qemail\E$/,@selfcreate)) {
7865: $display = 'block';
1.160.6.93 raeburn 7866: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 7867: }
1.160.6.93 raeburn 7868: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7869: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7870: \%choices,$$rowtotal,$onclick);
7871: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7872: $rowstyle);
7873: $$rowtotal ++;
7874: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7875: $rowstyle);
7876: $$rowtotal ++;
7877: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 7878: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 7879: my ($emailrules,$emailruleorder) =
7880: &Apache::lonnet::inst_userrules($dom,'email');
7881: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7882: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7883: if (ref($types) eq 'ARRAY') {
7884: @posstypes = @{$types};
7885: }
7886: if (@posstypes) {
7887: unless (grep(/^default$/,@posstypes)) {
7888: push(@posstypes,'default');
1.160.6.89 raeburn 7889: }
7890: if (ref($usertypes) eq 'HASH') {
7891: %usertypeshash = %{$usertypes};
7892: }
1.160.6.93 raeburn 7893: my $currassign;
7894: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7895: $currassign = {
7896: selfassign => $domdefaults{'inststatusguest'},
7897: };
7898: @ordered = @{$domdefaults{'inststatusguest'}};
7899: } else {
7900: $currassign = { selfassign => [] };
7901: }
7902: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7903: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7904: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7905: $numinrow,$othertitle,'selfassign',
7906: $rowtotal,$onclicktypes,$customclass,
7907: $rowstyle);
7908: $$rowtotal ++;
1.160.6.89 raeburn 7909: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7910: foreach my $status (@posstypes) {
7911: my $css_class;
7912: if ($$rowtotal%2) {
7913: $css_class = 'LC_odd_row ';
7914: }
7915: $css_class .= $customclass;
7916: my $rowid = $optionsprefix.$status;
7917: my $hidden = 1;
7918: my $currstyle = 'display:none';
7919: if (grep(/^\Q$status\E$/,@ordered)) {
7920: $currstyle = $rowstyle;
7921: $hidden = 0;
7922: }
7923: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7924: $emailrules,$emailruleorder,$settings,$status,$rowid,
7925: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7926: unless ($hidden) {
7927: $$rowtotal ++;
7928: }
1.160.6.89 raeburn 7929: }
7930: } else {
1.160.6.93 raeburn 7931: my $css_class;
7932: if ($$rowtotal%2) {
7933: $css_class = 'LC_odd_row ';
7934: }
7935: $css_class .= $customclass;
1.160.6.89 raeburn 7936: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7937: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7938: $emailrules,$emailruleorder,$settings,'default','',
7939: $othertitle,$css_class,$rowstyle,$intdom);
7940: $$rowtotal ++;
1.160.6.34 raeburn 7941: }
1.160.6.35 raeburn 7942: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7943: $numinrow = 1;
1.160.6.93 raeburn 7944: if (@posstypes) {
7945: foreach my $status (@posstypes) {
7946: my $rowid = $classprefix.$status;
7947: my $datarowstyle = 'display:none';
7948: if (grep(/^\Q$status\E$/,@ordered)) {
7949: $datarowstyle = $rowstyle;
7950: }
7951: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7952: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7953: $infotitles,$rowid,$customclass,$datarowstyle);
7954: unless ($datarowstyle eq 'display:none') {
7955: $$rowtotal ++;
7956: }
1.160.6.34 raeburn 7957: }
1.160.6.93 raeburn 7958: } else {
7959: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7960: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7961: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7962: }
7963: }
7964: return $datatable;
7965: }
7966:
1.160.6.93 raeburn 7967: sub selfcreate_javascript {
7968: return <<"ENDSCRIPT";
7969:
7970: <script type="text/javascript">
7971: // <![CDATA[
7972:
7973: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7974: var x = document.getElementsByClassName(target);
7975: var insttypes = 0;
7976: var insttypeRegExp = new RegExp(prefix);
7977: if ((x.length != undefined) && (x.length > 0)) {
7978: if (form.elements[radio].length != undefined) {
7979: for (var i=0; i<form.elements[radio].length; i++) {
7980: if (form.elements[radio][i].checked) {
7981: if (form.elements[radio][i].value == 1) {
7982: for (var j=0; j<x.length; j++) {
7983: if (x[j].id == 'undefined') {
7984: x[j].style.display = 'table-row';
7985: } else if (insttypeRegExp.test(x[j].id)) {
7986: insttypes ++;
7987: } else {
7988: x[j].style.display = 'table-row';
7989: }
7990: }
7991: } else {
7992: for (var j=0; j<x.length; j++) {
7993: x[j].style.display = 'none';
7994: }
1.160.6.40 raeburn 7995: }
1.160.6.93 raeburn 7996: break;
7997: }
7998: }
7999: if (insttypes > 0) {
8000: toggleDataRow(form,checkbox,target,altprefix);
8001: toggleDataRow(form,checkbox,target,prefix,1);
8002: }
8003: }
8004: }
8005: return;
8006: }
8007:
8008: function toggleDataRow(form,checkbox,target,prefix,docount) {
8009: if (form.elements[checkbox].length != undefined) {
8010: var count = 0;
8011: if (docount) {
8012: for (var i=0; i<form.elements[checkbox].length; i++) {
8013: if (form.elements[checkbox][i].checked) {
8014: count ++;
8015: }
8016: }
8017: }
8018: for (var i=0; i<form.elements[checkbox].length; i++) {
8019: var type = form.elements[checkbox][i].value;
8020: if (document.getElementById(prefix+type)) {
8021: if (form.elements[checkbox][i].checked) {
8022: document.getElementById(prefix+type).style.display = 'table-row';
8023: if (count % 2 == 1) {
8024: document.getElementById(prefix+type).className = target+' LC_odd_row';
8025: } else {
8026: document.getElementById(prefix+type).className = target;
8027: }
8028: count ++;
1.160.6.40 raeburn 8029: } else {
1.160.6.93 raeburn 8030: document.getElementById(prefix+type).style.display = 'none';
8031: }
8032: }
8033: }
8034: }
8035: return;
8036: }
8037:
8038: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8039: var caller = radio+'_'+status;
8040: if (form.elements[caller].length != undefined) {
8041: for (var i=0; i<form.elements[caller].length; i++) {
8042: if (form.elements[caller][i].checked) {
8043: if (document.getElementById(altprefix+'_inst_'+status)) {
8044: var curr = form.elements[caller][i].value;
8045: if (prefix) {
8046: document.getElementById(prefix+'_'+status).style.display = 'none';
8047: }
8048: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8049: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8050: if (curr == 'custom') {
8051: if (prefix) {
8052: document.getElementById(prefix+'_'+status).style.display = 'inline';
8053: }
8054: } else if (curr == 'inst') {
8055: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8056: } else if (curr == 'noninst') {
8057: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 8058: }
1.160.6.93 raeburn 8059: break;
1.160.6.40 raeburn 8060: }
1.160.6.93 raeburn 8061: }
8062: }
8063: }
8064: }
8065:
8066: // ]]>
8067: </script>
8068:
8069: ENDSCRIPT
8070: }
8071:
8072: sub noninst_users {
8073: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8074: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8075: my $class = 'LC_left_item';
8076: if ($css_class) {
8077: $css_class = ' class="'.$css_class.'"';
8078: }
8079: if ($rowid) {
8080: $rowid = ' id="'.$rowid.'"';
8081: }
8082: if ($rowstyle) {
8083: $rowstyle = ' style="'.$rowstyle.'"';
8084: }
8085: my ($output,$description);
8086: if ($type eq 'default') {
8087: $description = &mt('Requests for: [_1]',$typetitle);
8088: } else {
8089: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8090: }
8091: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8092: "<td>$description</td>\n".
8093: '<td class="'.$class.'" colspan="2">'.
8094: '<table><tr>';
8095: my %headers = &Apache::lonlocal::texthash(
8096: approve => 'Processing',
8097: email => 'E-mail',
8098: username => 'Username',
8099: );
8100: foreach my $item ('approve','email','username') {
8101: $output .= '<th>'.$headers{$item}.'</th>';
8102: }
8103: $output .= '</tr><tr>';
8104: foreach my $item ('approve','email','username') {
8105: $output .= '<td valign="top">';
8106: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8107: if ($item eq 'approve') {
8108: %choices = &Apache::lonlocal::texthash (
8109: automatic => 'Automatically approved',
8110: approval => 'Queued for approval',
8111: );
8112: @options = ('automatic','approval');
8113: $hashref = $processing;
8114: $defoption = 'automatic';
8115: $name = 'cancreate_emailprocess_'.$type;
8116: } elsif ($item eq 'email') {
8117: %choices = &Apache::lonlocal::texthash (
8118: any => 'Any e-mail',
8119: inst => 'Institutional only',
8120: noninst => 'Non-institutional only',
8121: custom => 'Custom restrictions',
8122: );
8123: @options = ('any','inst','noninst');
8124: my $showcustom;
8125: if (ref($emailrules) eq 'HASH') {
8126: if (keys(%{$emailrules}) > 0) {
8127: push(@options,'custom');
8128: $showcustom = 'cancreate_emailrule';
8129: if (ref($settings) eq 'HASH') {
8130: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8131: foreach my $rule (@{$settings->{'email_rule'}}) {
8132: if (exists($emailrules->{$rule})) {
8133: $hascustom ++;
8134: }
8135: }
8136: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8137: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8138: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8139: if (exists($emailrules->{$rule})) {
8140: $hascustom ++;
8141: }
8142: }
8143: }
8144: }
8145: }
8146: }
8147: }
8148: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8149: "'cancreate_emaildomain','$type'".');"';
8150: $hashref = $emailoptions;
8151: $defoption = 'any';
8152: $name = 'cancreate_emailoptions_'.$type;
8153: } elsif ($item eq 'username') {
8154: %choices = &Apache::lonlocal::texthash (
8155: all => 'Same as e-mail',
8156: first => 'Omit @domain',
8157: free => 'Free to choose',
8158: );
8159: @options = ('all','first','free');
8160: $hashref = $emailverified;
8161: $defoption = 'all';
8162: $name = 'cancreate_usernameoptions_'.$type;
8163: }
8164: foreach my $option (@options) {
8165: my $checked;
8166: if (ref($hashref) eq 'HASH') {
8167: if ($type eq '') {
8168: if (!exists($hashref->{'default'})) {
8169: if ($option eq $defoption) {
8170: $checked = ' checked="checked"';
8171: }
8172: } else {
8173: if ($hashref->{'default'} eq $option) {
8174: $checked = ' checked="checked"';
8175: }
1.160.6.40 raeburn 8176: }
8177: } else {
1.160.6.93 raeburn 8178: if (!exists($hashref->{$type})) {
8179: if ($option eq $defoption) {
8180: $checked = ' checked="checked"';
8181: }
8182: } else {
8183: if ($hashref->{$type} eq $option) {
8184: $checked = ' checked="checked"';
8185: }
1.160.6.40 raeburn 8186: }
8187: }
1.160.6.93 raeburn 8188: } elsif (($item eq 'email') && ($hascustom)) {
8189: if ($option eq 'custom') {
8190: $checked = ' checked="checked"';
8191: }
8192: } elsif ($option eq $defoption) {
8193: $checked = ' checked="checked"';
8194: }
8195: $output .= '<span class="LC_nobreak"><label>'.
8196: '<input type="radio" name="'.$name.'"'.
8197: $checked.' value="'.$option.'"'.$onclick.' />'.
8198: $choices{$option}.'</label></span><br />';
8199: if ($item eq 'email') {
8200: if ($option eq 'custom') {
8201: my $id = 'cancreate_emailrule_'.$type;
8202: my $display = 'none';
8203: if ($checked) {
8204: $display = 'inline';
8205: }
8206: my $numinrow = 2;
8207: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8208: '<legend>'.&mt('Disallow').'</legend><table>'.
8209: &user_formats_row('email',$settings,$emailrules,
8210: $emailruleorder,$numinrow,'',$type);
8211: '</table></fieldset>';
8212: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8213: my %text = &Apache::lonlocal::texthash (
8214: inst => 'must end:',
8215: noninst => 'cannot end:',
8216: );
8217: my $value;
8218: if (ref($emaildomain) eq 'HASH') {
8219: if (ref($emaildomain->{$type}) eq 'HASH') {
8220: $value = $emaildomain->{$type}->{$option};
8221: }
8222: }
8223: if ($value eq '') {
8224: $value = '@'.$intdom;
8225: }
8226: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8227: my $display = 'none';
8228: if ($checked) {
8229: $display = 'inline';
8230: }
8231: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8232: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8233: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8234: '</div>';
8235: }
1.160.6.40 raeburn 8236: }
8237: }
1.160.6.93 raeburn 8238: $output .= '</td>'."\n";
1.160.6.40 raeburn 8239: }
1.160.6.93 raeburn 8240: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 8241: return $output;
8242: }
8243:
1.160.6.5 raeburn 8244: sub captcha_choice {
1.160.6.93 raeburn 8245: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 8246: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8247: $vertext,$currver);
1.160.6.5 raeburn 8248: my %lt = &captcha_phrases();
8249: $keyentry = 'hidden';
1.160.6.98 raeburn 8250: my $colspan=2;
1.160.6.5 raeburn 8251: if ($context eq 'cancreate') {
1.160.6.34 raeburn 8252: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 8253: } elsif ($context eq 'login') {
8254: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 8255: } elsif ($context eq 'passwords') {
8256: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8257: $colspan=1;
1.160.6.5 raeburn 8258: }
8259: if (ref($settings) eq 'HASH') {
8260: if ($settings->{'captcha'}) {
8261: $checked{$settings->{'captcha'}} = ' checked="checked"';
8262: } else {
8263: $checked{'original'} = ' checked="checked"';
8264: }
8265: if ($settings->{'captcha'} eq 'recaptcha') {
8266: $pubtext = $lt{'pub'};
8267: $privtext = $lt{'priv'};
8268: $keyentry = 'text';
1.160.6.69 raeburn 8269: $vertext = $lt{'ver'};
8270: $currver = $settings->{'recaptchaversion'};
8271: if ($currver ne '2') {
8272: $currver = 1;
8273: }
1.160.6.5 raeburn 8274: }
8275: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8276: $currpub = $settings->{'recaptchakeys'}{'public'};
8277: $currpriv = $settings->{'recaptchakeys'}{'private'};
8278: }
8279: } else {
8280: $checked{'original'} = ' checked="checked"';
8281: }
1.160.6.93 raeburn 8282: my $css_class;
8283: if ($itemcount%2) {
8284: $css_class = 'LC_odd_row';
8285: }
8286: if ($customcss) {
8287: $css_class .= " $customcss";
8288: }
8289: $css_class =~ s/^\s+//;
8290: if ($css_class) {
8291: $css_class = ' class="'.$css_class.'"';
8292: }
8293: if ($rowstyle) {
8294: $css_class .= ' style="'.$rowstyle.'"';
8295: }
1.160.6.5 raeburn 8296: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 8297: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 8298: '<table><tr><td>'."\n";
8299: foreach my $option ('original','recaptcha','notused') {
8300: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8301: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8302: $lt{$option}.'</label></span>';
8303: unless ($option eq 'notused') {
8304: $output .= (' 'x2)."\n";
8305: }
8306: }
8307: #
8308: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8309: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
8310: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
8311: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
8312: #
8313: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 8314: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 8315: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8316: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8317: $currpub.'" size="40" /></span><br />'."\n".
8318: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8319: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 8320: $currpriv.'" size="40" /></span><br />'.
8321: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8322: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8323: $currver.'" size="3" /></span><br />'.
8324: '</td></tr></table>'."\n".
1.160.6.5 raeburn 8325: '</td></tr>';
8326: return $output;
8327: }
8328:
1.32 raeburn 8329: sub user_formats_row {
1.160.6.93 raeburn 8330: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8331: my $output;
8332: my %text = (
8333: 'username' => 'new usernames',
8334: 'id' => 'IDs',
8335: );
1.160.6.118.2 8(raebur 8336:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 8337: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8338: $output = '<tr '.$css_class.'>'.
8339: '<td><span class="LC_nobreak">'.
8340: &mt("Format rules to check for $text{$type}: ").
8341: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8342: }
1.27 raeburn 8343: my $rem;
8344: if (ref($ruleorder) eq 'ARRAY') {
8345: for (my $i=0; $i<@{$ruleorder}; $i++) {
8346: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8347: my $rem = $i%($numinrow);
8348: if ($rem == 0) {
8349: if ($i > 0) {
8350: $output .= '</tr>';
8351: }
8352: $output .= '<tr>';
8353: }
8354: my $check = ' ';
1.39 raeburn 8355: if (ref($settings) eq 'HASH') {
8356: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8357: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8358: $check = ' checked="checked" ';
8359: }
1.160.6.93 raeburn 8360: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8361: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8362: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8363: $check = ' checked="checked" ';
8364: }
8365: }
1.27 raeburn 8366: }
8367: }
1.160.6.93 raeburn 8368: my $name = $type.'_rule';
8369: if ($type eq 'email') {
8370: $name .= '_'.$status;
8371: }
1.27 raeburn 8372: $output .= '<td class="LC_left_item">'.
8373: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 8374: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8375: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8376: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8377: }
8378: }
8379: $rem = @{$ruleorder}%($numinrow);
8380: }
1.160.6.93 raeburn 8381: my $colsleft;
8382: if ($rem) {
8383: $colsleft = $numinrow - $rem;
8384: }
1.27 raeburn 8385: if ($colsleft > 1 ) {
8386: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8387: ' </td>';
8388: } elsif ($colsleft == 1) {
8389: $output .= '<td class="LC_left_item"> </td>';
8390: }
1.160.6.118.2 8(raebur 8391:2): $output .= '</tr>';
8392:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
8393:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 8394: }
1.27 raeburn 8395: return $output;
8396: }
8397:
1.34 raeburn 8398: sub usercreation_types {
8399: my %lt = &Apache::lonlocal::texthash (
8400: author => 'When adding a co-author',
8401: course => 'When adding a user to a course',
1.100 raeburn 8402: requestcrs => 'When requesting a course',
1.34 raeburn 8403: any => 'Any',
8404: official => 'Institutional only ',
8405: unofficial => 'Non-institutional only',
8406: none => 'None',
8407: );
8408: return %lt;
1.48 raeburn 8409: }
1.34 raeburn 8410:
1.160.6.34 raeburn 8411: sub selfcreation_types {
8412: my %lt = &Apache::lonlocal::texthash (
8413: selfcreate => 'User creates own account',
8414: any => 'Any',
8415: official => 'Institutional only ',
8416: unofficial => 'Non-institutional only',
8417: email => 'E-mail address',
8418: login => 'Institutional Login',
8419: sso => 'SSO',
8420: );
8421: }
8422:
1.28 raeburn 8423: sub authtype_names {
8424: my %lt = &Apache::lonlocal::texthash(
8425: int => 'Internal',
8426: krb4 => 'Kerberos 4',
8427: krb5 => 'Kerberos 5',
8428: loc => 'Local',
8429: );
8430: return %lt;
8431: }
8432:
8433: sub context_names {
8434: my %context_title = &Apache::lonlocal::texthash(
8435: author => 'Creating users when an Author',
8436: course => 'Creating users when in a course',
8437: domain => 'Creating users when a Domain Coordinator',
8438: );
8439: return %context_title;
8440: }
8441:
1.33 raeburn 8442: sub print_usermodification {
8443: my ($position,$dom,$settings,$rowtotal) = @_;
8444: my $numinrow = 4;
8445: my ($context,$datatable,$rowcount);
8446: if ($position eq 'top') {
8447: $rowcount = 0;
8448: $context = 'author';
8449: foreach my $role ('ca','aa') {
8450: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8451: $numinrow,$rowcount);
8452: $$rowtotal ++;
8453: $rowcount ++;
8454: }
1.160.6.37 raeburn 8455: } elsif ($position eq 'bottom') {
1.33 raeburn 8456: $context = 'course';
8457: $rowcount = 0;
8458: foreach my $role ('st','ep','ta','in','cr') {
8459: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8460: $numinrow,$rowcount);
8461: $$rowtotal ++;
8462: $rowcount ++;
8463: }
8464: }
8465: return $datatable;
8466: }
8467:
1.43 raeburn 8468: sub print_defaults {
1.160.6.40 raeburn 8469: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8470: my $rownum = 0;
1.160.6.80 raeburn 8471: my ($datatable,$css_class,$titles);
8472: unless ($position eq 'bottom') {
8473: $titles = &defaults_titles($dom);
8474: }
1.160.6.40 raeburn 8475: if ($position eq 'top') {
8476: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8477: 'datelocale_def','portal_def');
8478: my %defaults;
8479: if (ref($settings) eq 'HASH') {
8480: %defaults = %{$settings};
1.43 raeburn 8481: } else {
1.160.6.40 raeburn 8482: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8483: foreach my $item (@items) {
8484: $defaults{$item} = $domdefaults{$item};
8485: }
1.43 raeburn 8486: }
1.160.6.40 raeburn 8487: foreach my $item (@items) {
8488: if ($rownum%2) {
8489: $css_class = '';
8490: } else {
8491: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 8492: }
1.160.6.40 raeburn 8493: $datatable .= '<tr'.$css_class.'>'.
8494: '<td><span class="LC_nobreak">'.$titles->{$item}.
8495: '</span></td><td class="LC_right_item" colspan="3">';
8496: if ($item eq 'auth_def') {
8497: my @authtypes = ('internal','krb4','krb5','localauth');
8498: my %shortauth = (
8499: internal => 'int',
8500: krb4 => 'krb4',
8501: krb5 => 'krb5',
8502: localauth => 'loc'
8503: );
8504: my %authnames = &authtype_names();
8505: foreach my $auth (@authtypes) {
8506: my $checked = ' ';
8507: if ($defaults{$item} eq $auth) {
8508: $checked = ' checked="checked" ';
8509: }
8510: $datatable .= '<label><input type="radio" name="'.$item.
8511: '" value="'.$auth.'"'.$checked.'/>'.
8512: $authnames{$shortauth{$auth}}.'</label> ';
8513: }
8514: } elsif ($item eq 'timezone_def') {
8515: my $includeempty = 1;
8516: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8517: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 8518: my $includeempty = 1;
8519: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8520: } elsif ($item eq 'lang_def') {
8521: my $includeempty = 1;
8522: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 8523:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 8524: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 8525:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
8526:23): my $portalsty = 'none';
8527:23): if ($defaults{$item}) {
8528:23): $portalsty = 'block';
8529:23): }
8530:23): foreach my $field ('email','web') {
8531:23): my $checkedoff = ' checked="checked"';
8532:23): my $checkedon;
8533:23): if ($defaults{$item.'_'.$field}) {
8534:23): $checkedon = $checkedoff;
8535:23): $checkedoff = '';
8536:23): }
8537:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
8538:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
8539:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
8540:23): (' 'x2).
8541:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
8542:23): '</div>';
8543:23): }
8544:23): } else {
8545:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 8546: }
8547: $datatable .= '</td></tr>';
8548: $rownum ++;
8549: }
1.160.6.118.2 8(raebur 8550:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 8551: my %defaults;
1.160.6.40 raeburn 8552: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 8553: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 8554: my $maxnum = @{$settings->{'inststatusorder'}};
8555: for (my $i=0; $i<$maxnum; $i++) {
8556: $css_class = $rownum%2?' class="LC_odd_row"':'';
8557: my $item = $settings->{'inststatusorder'}->[$i];
8558: my $title = $settings->{'inststatustypes'}->{$item};
8559: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8560: $datatable .= '<tr'.$css_class.'>'.
8561: '<td><span class="LC_nobreak">'.
8562: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8563: for (my $k=0; $k<=$maxnum; $k++) {
8564: my $vpos = $k+1;
8565: my $selstr;
8566: if ($k == $i) {
8567: $selstr = ' selected="selected" ';
8568: }
8569: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8570: }
8571: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8572: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8573: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 8574: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 8575: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 8576: '</span></td></tr>';
1.160.6.40 raeburn 8577: }
8578: $css_class = $rownum%2?' class="LC_odd_row"':'';
8579: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8580: $datatable .= '<tr '.$css_class.'>'.
8581: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8582: for (my $k=0; $k<=$maxnum; $k++) {
8583: my $vpos = $k+1;
8584: my $selstr;
8585: if ($k == $maxnum) {
8586: $selstr = ' selected="selected" ';
8587: }
8588: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8589: }
8590: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 8591: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 8592: ' '.&mt('(new)').
8593: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 8594: &mt('Name displayed').':'.
1.160.6.40 raeburn 8595: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8596: '</tr>'."\n";
8597: $rownum ++;
1.141 raeburn 8598: }
1.43 raeburn 8599: }
1.160.6.118.2 8(raebur 8600:2): } else {
8601:2): my ($unamemaprules,$ruleorder) =
8602:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
8603:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
8604:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8605:2): my $numinrow = 2;
8606:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
8607:2): &user_formats_row('unamemap',$settings,$unamemaprules,
8608:2): $ruleorder,$numinrow).
8609:2): '</table></td></tr>';
8610:2): }
8611:2): if ($datatable eq '') {
8612:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
8613:2): &mt('No rules set for domain in customized localenroll.pm').
8614:2): '</td></tr>';
8615:2): }
1.43 raeburn 8616: }
8617: $$rowtotal += $rownum;
8618: return $datatable;
8619: }
8620:
1.160.6.5 raeburn 8621: sub get_languages_hash {
8622: my %langchoices;
8623: foreach my $id (&Apache::loncommon::languageids()) {
8624: my $code = &Apache::loncommon::supportedlanguagecode($id);
8625: if ($code ne '') {
8626: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8627: }
8628: }
8629: return %langchoices;
8630: }
8631:
1.43 raeburn 8632: sub defaults_titles {
1.141 raeburn 8633: my ($dom) = @_;
1.43 raeburn 8634: my %titles = &Apache::lonlocal::texthash (
8635: 'auth_def' => 'Default authentication type',
8636: 'auth_arg_def' => 'Default authentication argument',
8637: 'lang_def' => 'Default language',
1.54 raeburn 8638: 'timezone_def' => 'Default timezone',
1.68 raeburn 8639: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8640: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 8641:23): 'email' => 'Email links use portal URL',
8642:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 8643: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8644: 'intauth_check' => 'Check bcrypt cost if authenticated',
8645: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8646: );
1.141 raeburn 8647: if ($dom) {
8648: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8649: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8650: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8651: $protocol = 'http' if ($protocol ne 'https');
8652: if ($uint_dom) {
8653: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8654: $uint_dom);
8655: }
8656: }
1.43 raeburn 8657: return (\%titles);
8658: }
8659:
1.160.6.97 raeburn 8660: sub print_scantron {
8661: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8662: if ($position eq 'top') {
8663: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8664: } else {
8665: return &print_scantronconfig($dom,$settings,\$rowtotal);
8666: }
8667: }
8668:
8669: sub scantron_javascript {
8670: return <<"ENDSCRIPT";
8671:
8672: <script type="text/javascript">
8673: // <![CDATA[
8674:
8675: function toggleScantron(form) {
8676: var csvfieldset = new Array();
8677: if (document.getElementById('scantroncsv_cols')) {
8678: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8679: }
8680: if (document.getElementById('scantroncsv_options')) {
8681: csvfieldset.push(document.getElementById('scantroncsv_options'));
8682: }
8683: if (csvfieldset.length) {
8684: if (document.getElementById('scantronconfcsv')) {
8685: var scantroncsv = document.getElementById('scantronconfcsv');
8686: if (scantroncsv.checked) {
8687: for (var i=0; i<csvfieldset.length; i++) {
8688: csvfieldset[i].style.display = 'block';
8689: }
8690: } else {
8691: for (var i=0; i<csvfieldset.length; i++) {
8692: csvfieldset[i].style.display = 'none';
8693: }
8694: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8695: if (csvselects.length) {
8696: for (var j=0; j<csvselects.length; j++) {
8697: csvselects[j].selectedIndex = 0;
8698: }
8699: }
8700: }
8701: }
8702: }
8703: return;
8704: }
8705: // ]]>
8706: </script>
8707:
8708: ENDSCRIPT
8709:
8710: }
8711:
1.46 raeburn 8712: sub print_scantronformat {
8713: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8714: my $itemcount = 1;
1.60 raeburn 8715: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8716: %confhash);
1.46 raeburn 8717: my $switchserver = &check_switchserver($dom,$confname);
8718: my %lt = &Apache::lonlocal::texthash (
1.95 www 8719: default => 'Default bubblesheet format file error',
8720: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8721: );
8722: my %scantronfiles = (
8723: default => 'default.tab',
8724: custom => 'custom.tab',
8725: );
8726: foreach my $key (keys(%scantronfiles)) {
8727: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8728: .$scantronfiles{$key};
8729: }
8730: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8731: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8732: if (!$switchserver) {
8733: my $servadm = $r->dir_config('lonAdmEMail');
8734: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8735: if ($configuserok eq 'ok') {
8736: if ($author_ok eq 'ok') {
8737: my %legacyfile = (
1.160.6.97 raeburn 8738: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8739: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8740: );
8741: my %md5chk;
8742: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8743: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8744: chomp($md5chk{$type});
1.46 raeburn 8745: }
8746: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8747: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 8748: ($scantronurls{$type},my $error) =
1.46 raeburn 8749: &legacy_scantronformat($r,$dom,$confname,
8750: $type,$legacyfile{$type},
8751: $scantronurls{$type},
8752: $scantronfiles{$type});
1.60 raeburn 8753: if ($error ne '') {
8754: $error{$type} = $error;
8755: }
8756: }
8757: if (keys(%error) == 0) {
8758: $is_custom = 1;
1.160.6.97 raeburn 8759: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8760: $scantronurls{'custom'};
1.160.6.97 raeburn 8761: my $putresult =
1.60 raeburn 8762: &Apache::lonnet::put_dom('configuration',
8763: \%confhash,$dom);
8764: if ($putresult ne 'ok') {
1.160.6.97 raeburn 8765: $error{'custom'} =
1.60 raeburn 8766: '<span class="LC_error">'.
8767: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8768: }
1.46 raeburn 8769: }
8770: } else {
1.60 raeburn 8771: ($scantronurls{'default'},my $error) =
1.46 raeburn 8772: &legacy_scantronformat($r,$dom,$confname,
8773: 'default',$legacyfile{'default'},
8774: $scantronurls{'default'},
8775: $scantronfiles{'default'});
1.60 raeburn 8776: if ($error eq '') {
8777: $confhash{'scantron'}{'scantronformat'} = '';
8778: my $putresult =
8779: &Apache::lonnet::put_dom('configuration',
8780: \%confhash,$dom);
8781: if ($putresult ne 'ok') {
8782: $error{'default'} =
8783: '<span class="LC_error">'.
8784: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8785: }
8786: } else {
8787: $error{'default'} = $error;
8788: }
1.46 raeburn 8789: }
8790: }
8791: }
8792: } else {
1.95 www 8793: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8794: }
8795: }
8796: if (ref($settings) eq 'HASH') {
8797: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8798: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8799: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8800: $scantronurl = '';
8801: } else {
8802: $scantronurl = $settings->{'scantronformat'};
8803: }
8804: $is_custom = 1;
8805: } else {
8806: $scantronurl = $scantronurls{'default'};
8807: }
8808: } else {
1.60 raeburn 8809: if ($is_custom) {
8810: $scantronurl = $scantronurls{'custom'};
8811: } else {
8812: $scantronurl = $scantronurls{'default'};
8813: }
1.46 raeburn 8814: }
8815: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8816: $datatable .= '<tr'.$css_class.'>';
8817: if (!$is_custom) {
1.65 raeburn 8818: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8819: '<span class="LC_nobreak">';
1.46 raeburn 8820: if ($scantronurl) {
1.160.6.21 raeburn 8821: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8822: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8823: } else {
8824: $datatable = &mt('File unavailable for display');
8825: }
1.65 raeburn 8826: $datatable .= '</span></td>';
1.60 raeburn 8827: if (keys(%error) == 0) {
8828: $datatable .= '<td valign="bottom">';
8829: if (!$switchserver) {
8830: $datatable .= &mt('Upload:').'<br />';
8831: }
8832: } else {
8833: my $errorstr;
8834: foreach my $key (sort(keys(%error))) {
8835: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8836: }
8837: $datatable .= '<td>'.$errorstr;
8838: }
1.46 raeburn 8839: } else {
8840: if (keys(%error) > 0) {
8841: my $errorstr;
8842: foreach my $key (sort(keys(%error))) {
8843: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8844: }
1.60 raeburn 8845: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8846: } elsif ($scantronurl) {
1.160.6.26 raeburn 8847: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 8848: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8849: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 8850: $link.
8851: '<label><input type="checkbox" name="scantronformat_del"'.
8852: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8853: '<td><span class="LC_nobreak"> '.
8854: &mt('Replace:').'</span><br />';
1.46 raeburn 8855: }
8856: }
8857: if (keys(%error) == 0) {
8858: if ($switchserver) {
8859: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8860: } else {
1.65 raeburn 8861: $datatable .='<span class="LC_nobreak"> '.
8862: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8863: }
8864: }
8865: $datatable .= '</td></tr>';
8866: $$rowtotal ++;
8867: return $datatable;
8868: }
8869:
8870: sub legacy_scantronformat {
8871: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8872: my ($url,$error);
8873: my @statinfo = &Apache::lonnet::stat_file($newurl);
8874: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8875: (my $result,$url) =
8876: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8877: '','',$newfile);
8878: if ($result ne 'ok') {
1.130 raeburn 8879: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8880: }
8881: }
8882: return ($url,$error);
8883: }
1.43 raeburn 8884:
1.160.6.97 raeburn 8885: sub print_scantronconfig {
8886: my ($dom,$settings,$rowtotal) = @_;
8887: my $itemcount = 2;
8888: my $is_checked = ' checked="checked"';
8889: my %optionson = (
8890: hdr => ' checked="checked"',
8891: pad => ' checked="checked"',
8892: rem => ' checked="checked"',
8893: );
8894: my %optionsoff = (
8895: hdr => '',
8896: pad => '',
8897: rem => '',
8898: );
8899: my $currcsvsty = 'none';
8900: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
8901: my @fields = &scantroncsv_fields();
8902: my %titles = &scantronconfig_titles();
8903: if (ref($settings) eq 'HASH') {
8904: if (ref($settings->{config}) eq 'HASH') {
8905: if ($settings->{config}->{dat}) {
8906: $checked{'dat'} = $is_checked;
8907: }
8908: if (ref($settings->{config}->{csv}) eq 'HASH') {
8909: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8910: %csvfields = %{$settings->{config}->{csv}->{fields}};
8911: if (keys(%csvfields) > 0) {
8912: $checked{'csv'} = $is_checked;
8913: $currcsvsty = 'block';
8914: }
8915: }
8916: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8917: %csvoptions = %{$settings->{config}->{csv}->{options}};
8918: foreach my $option (keys(%optionson)) {
8919: unless ($csvoptions{$option}) {
8920: $optionsoff{$option} = $optionson{$option};
8921: $optionson{$option} = '';
8922: }
8923: }
8924: }
8925: }
8926: } else {
8927: $checked{'dat'} = $is_checked;
8928: }
8929: } else {
8930: $checked{'dat'} = $is_checked;
8931: }
8932: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8933: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8934: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8935: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8936: foreach my $item ('dat','csv') {
8937: my $id;
8938: if ($item eq 'csv') {
8939: $id = 'id="scantronconfcsv" ';
8940: }
8941: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8942: $titles{$item}.'</label>'.(' 'x3);
8943: if ($item eq 'csv') {
8944: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8945: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8946: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8947: foreach my $col (@fields) {
8948: my $selnone;
8949: if ($csvfields{$col} eq '') {
8950: $selnone = ' selected="selected"';
8951: }
8952: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8953: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8954: '<option value=""'.$selnone.'></option>';
8955: for (my $i=0; $i<20; $i++) {
8956: my $shown = $i+1;
8957: my $sel;
8958: unless ($selnone) {
8959: if (exists($csvfields{$col})) {
8960: if ($csvfields{$col} == $i) {
8961: $sel = ' selected="selected"';
8962: }
8963: }
8964: }
8965: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8966: }
8967: $datatable .= '</select></td></tr>';
8968: }
8969: $datatable .= '</table></fieldset>'.
8970: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8971: '<legend>'.&mt('CSV Options').'</legend>';
8972: foreach my $option ('hdr','pad','rem') {
8973: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8974: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8975: &mt('Yes').'</label>'.(' 'x2)."\n".
8976: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8977: }
8978: $datatable .= '</fieldset>';
8979: $itemcount ++;
8980: }
8981: }
8982: $datatable .= '</td></tr>';
8983: $$rowtotal ++;
8984: return $datatable;
8985: }
8986:
8987: sub scantronconfig_titles {
8988: return &Apache::lonlocal::texthash(
8989: dat => 'Standard format (.dat)',
8990: csv => 'Comma separated values (.csv)',
8991: hdr => 'Remove first line in file (contains column titles)',
8992: pad => 'Prepend 0s to PaperID',
8993: rem => 'Remove leading spaces (except Question Response columns)',
8994: CODE => 'CODE',
8995: ID => 'Student ID',
8996: PaperID => 'Paper ID',
8997: FirstName => 'First Name',
8998: LastName => 'Last Name',
8999: FirstQuestion => 'First Question Response',
9000: Section => 'Section',
9001: );
9002: }
9003:
9004: sub scantroncsv_fields {
9005: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9006: }
9007:
1.49 raeburn 9008: sub print_coursecategories {
1.57 raeburn 9009: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9010: my $datatable;
9011: if ($position eq 'top') {
1.160.6.42 raeburn 9012: my (%checked);
9013: my @catitems = ('unauth','auth');
9014: my @cattypes = ('std','domonly','codesrch','none');
9015: $checked{'unauth'} = 'std';
9016: $checked{'auth'} = 'std';
9017: if (ref($settings) eq 'HASH') {
9018: foreach my $type (@cattypes) {
9019: if ($type eq $settings->{'unauth'}) {
9020: $checked{'unauth'} = $type;
9021: }
9022: if ($type eq $settings->{'auth'}) {
9023: $checked{'auth'} = $type;
9024: }
9025: }
9026: }
9027: my %lt = &Apache::lonlocal::texthash (
9028: unauth => 'Catalog type for unauthenticated users',
9029: auth => 'Catalog type for authenticated users',
9030: none => 'No catalog',
9031: std => 'Standard catalog',
9032: domonly => 'Domain-only catalog',
9033: codesrch => "Code search form",
9034: );
9035: my $itemcount = 0;
9036: foreach my $item (@catitems) {
9037: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9038: $datatable .= '<tr '.$css_class.'>'.
9039: '<td>'.$lt{$item}.'</td>'.
9040: '<td class="LC_right_item"><span class="LC_nobreak">';
9041: foreach my $type (@cattypes) {
9042: my $ischecked;
9043: if ($checked{$item} eq $type) {
9044: $ischecked=' checked="checked"';
9045: }
9046: $datatable .= '<label>'.
9047: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9048: ' />'.$lt{$type}.'</label> ';
9049: }
1.160.6.87 raeburn 9050: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 9051: $itemcount ++;
9052: }
9053: $$rowtotal += $itemcount;
9054: } elsif ($position eq 'middle') {
1.57 raeburn 9055: my $toggle_cats_crs = ' ';
9056: my $toggle_cats_dom = ' checked="checked" ';
9057: my $can_cat_crs = ' ';
9058: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9059: my $toggle_catscomm_comm = ' ';
9060: my $toggle_catscomm_dom = ' checked="checked" ';
9061: my $can_catcomm_comm = ' ';
9062: my $can_catcomm_dom = ' checked="checked" ';
9063:
1.57 raeburn 9064: if (ref($settings) eq 'HASH') {
9065: if ($settings->{'togglecats'} eq 'crs') {
9066: $toggle_cats_crs = $toggle_cats_dom;
9067: $toggle_cats_dom = ' ';
9068: }
9069: if ($settings->{'categorize'} eq 'crs') {
9070: $can_cat_crs = $can_cat_dom;
9071: $can_cat_dom = ' ';
9072: }
1.120 raeburn 9073: if ($settings->{'togglecatscomm'} eq 'comm') {
9074: $toggle_catscomm_comm = $toggle_catscomm_dom;
9075: $toggle_catscomm_dom = ' ';
9076: }
9077: if ($settings->{'categorizecomm'} eq 'comm') {
9078: $can_catcomm_comm = $can_catcomm_dom;
9079: $can_catcomm_dom = ' ';
9080: }
1.57 raeburn 9081: }
9082: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 9083: togglecats => 'Show/Hide a course in catalog',
9084: togglecatscomm => 'Show/Hide a community in catalog',
9085: categorize => 'Assign a category to a course',
9086: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9087: );
9088: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 9089: dom => 'Set in Domain',
9090: crs => 'Set in Course',
9091: comm => 'Set in Community',
1.57 raeburn 9092: );
9093: $datatable = '<tr class="LC_odd_row">'.
9094: '<td>'.$title{'togglecats'}.'</td>'.
9095: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9096: '<input type="radio" name="togglecats"'.
9097: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9098: '<label><input type="radio" name="togglecats"'.
9099: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9100: '</tr><tr>'.
9101: '<td>'.$title{'categorize'}.'</td>'.
9102: '<td class="LC_right_item"><span class="LC_nobreak">'.
9103: '<label><input type="radio" name="categorize"'.
9104: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9105: '<label><input type="radio" name="categorize"'.
9106: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9107: '</tr><tr class="LC_odd_row">'.
9108: '<td>'.$title{'togglecatscomm'}.'</td>'.
9109: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9110: '<input type="radio" name="togglecatscomm"'.
9111: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9112: '<label><input type="radio" name="togglecatscomm"'.
9113: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9114: '</tr><tr>'.
9115: '<td>'.$title{'categorizecomm'}.'</td>'.
9116: '<td class="LC_right_item"><span class="LC_nobreak">'.
9117: '<label><input type="radio" name="categorizecomm"'.
9118: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9119: '<label><input type="radio" name="categorizecomm"'.
9120: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 9121: '</tr>';
1.120 raeburn 9122: $$rowtotal += 4;
1.57 raeburn 9123: } else {
9124: my $css_class;
9125: my $itemcount = 1;
9126: my $cathash;
9127: if (ref($settings) eq 'HASH') {
9128: $cathash = $settings->{'cats'};
9129: }
9130: if (ref($cathash) eq 'HASH') {
9131: my (@cats,@trails,%allitems,%idx,@jsarray);
9132: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9133: \%allitems,\%idx,\@jsarray);
9134: my $maxdepth = scalar(@cats);
9135: my $colattrib = '';
9136: if ($maxdepth > 2) {
9137: $colattrib = ' colspan="2" ';
9138: }
9139: my @path;
9140: if (@cats > 0) {
9141: if (ref($cats[0]) eq 'ARRAY') {
9142: my $numtop = @{$cats[0]};
9143: my $maxnum = $numtop;
1.120 raeburn 9144: my %default_names = (
9145: instcode => &mt('Official courses'),
9146: communities => &mt('Communities'),
9147: );
9148:
9149: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9150: ($cathash->{'instcode::0'} eq '') ||
9151: (!grep(/^communities$/,@{$cats[0]})) ||
9152: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 9153: $maxnum ++;
9154: }
9155: my $lastidx;
9156: for (my $i=0; $i<$numtop; $i++) {
9157: my $parent = $cats[0][$i];
9158: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9159: my $item = &escape($parent).'::0';
9160: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9161: $lastidx = $idx{$item};
9162: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9163: .'<select name="'.$item.'"'.$chgstr.'>';
9164: for (my $k=0; $k<=$maxnum; $k++) {
9165: my $vpos = $k+1;
9166: my $selstr;
9167: if ($k == $i) {
9168: $selstr = ' selected="selected" ';
9169: }
9170: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9171: }
1.160.6.29 raeburn 9172: $datatable .= '</select></span></td><td>';
1.120 raeburn 9173: if ($parent eq 'instcode' || $parent eq 'communities') {
9174: $datatable .= '<span class="LC_nobreak">'
9175: .$default_names{$parent}.'</span>';
9176: if ($parent eq 'instcode') {
9177: $datatable .= '<br /><span class="LC_nobreak">('
9178: .&mt('with institutional codes')
9179: .')</span></td><td'.$colattrib.'>';
9180: } else {
9181: $datatable .= '<table><tr><td>';
9182: }
9183: $datatable .= '<span class="LC_nobreak">'
9184: .'<label><input type="radio" name="'
9185: .$parent.'" value="1" checked="checked" />'
9186: .&mt('Display').'</label>';
9187: if ($parent eq 'instcode') {
9188: $datatable .= ' ';
9189: } else {
9190: $datatable .= '</span></td></tr><tr><td>'
9191: .'<span class="LC_nobreak">';
9192: }
9193: $datatable .= '<label><input type="radio" name="'
9194: .$parent.'" value="0" />'
9195: .&mt('Do not display').'</label></span>';
9196: if ($parent eq 'communities') {
9197: $datatable .= '</td></tr></table>';
9198: }
9199: $datatable .= '</td>';
1.57 raeburn 9200: } else {
9201: $datatable .= $parent
1.160.6.29 raeburn 9202: .' <span class="LC_nobreak"><label>'
9203: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9204: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9205: }
9206: my $depth = 1;
9207: push(@path,$parent);
9208: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9209: pop(@path);
9210: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9211: $itemcount ++;
9212: }
1.48 raeburn 9213: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9214: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9215: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9216: for (my $k=0; $k<=$maxnum; $k++) {
9217: my $vpos = $k+1;
9218: my $selstr;
1.57 raeburn 9219: if ($k == $numtop) {
1.48 raeburn 9220: $selstr = ' selected="selected" ';
9221: }
9222: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9223: }
1.59 bisitz 9224: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9225: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9226: .'</tr>'."\n";
1.48 raeburn 9227: $itemcount ++;
1.120 raeburn 9228: foreach my $default ('instcode','communities') {
9229: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9230: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9231: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9232: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9233: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9234: for (my $k=0; $k<=$maxnum; $k++) {
9235: my $vpos = $k+1;
9236: my $selstr;
9237: if ($k == $maxnum) {
9238: $selstr = ' selected="selected" ';
9239: }
9240: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9241: }
1.120 raeburn 9242: $datatable .= '</select></span></td>'.
9243: '<td><span class="LC_nobreak">'.
9244: $default_names{$default}.'</span>';
9245: if ($default eq 'instcode') {
9246: $datatable .= '<br /><span class="LC_nobreak">('
9247: .&mt('with institutional codes').')</span>';
9248: }
9249: $datatable .= '</td>'
9250: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9251: .&mt('Display').'</label> '
9252: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9253: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9254: }
9255: }
9256: }
1.57 raeburn 9257: } else {
9258: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9259: }
9260: } else {
1.160.6.87 raeburn 9261: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9262: .&initialize_categories($itemcount);
1.48 raeburn 9263: }
1.57 raeburn 9264: $$rowtotal += $itemcount;
1.48 raeburn 9265: }
9266: return $datatable;
9267: }
9268:
1.69 raeburn 9269: sub print_serverstatuses {
9270: my ($dom,$settings,$rowtotal) = @_;
9271: my $datatable;
9272: my @pages = &serverstatus_pages();
9273: my (%namedaccess,%machineaccess);
9274: foreach my $type (@pages) {
9275: $namedaccess{$type} = '';
9276: $machineaccess{$type}= '';
9277: }
9278: if (ref($settings) eq 'HASH') {
9279: foreach my $type (@pages) {
9280: if (exists($settings->{$type})) {
9281: if (ref($settings->{$type}) eq 'HASH') {
9282: foreach my $key (keys(%{$settings->{$type}})) {
9283: if ($key eq 'namedusers') {
9284: $namedaccess{$type} = $settings->{$type}->{$key};
9285: } elsif ($key eq 'machines') {
9286: $machineaccess{$type} = $settings->{$type}->{$key};
9287: }
9288: }
9289: }
9290: }
9291: }
9292: }
1.81 raeburn 9293: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9294: my $rownum = 0;
9295: my $css_class;
9296: foreach my $type (@pages) {
9297: $rownum ++;
9298: $css_class = $rownum%2?' class="LC_odd_row"':'';
9299: $datatable .= '<tr'.$css_class.'>'.
9300: '<td><span class="LC_nobreak">'.
9301: $titles->{$type}.'</span></td>'.
9302: '<td class="LC_left_item">'.
9303: '<input type="text" name="'.$type.'_namedusers" '.
9304: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9305: '<td class="LC_right_item">'.
9306: '<span class="LC_nobreak">'.
9307: '<input type="text" name="'.$type.'_machines" '.
9308: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 9309: '</span></td></tr>'."\n";
1.69 raeburn 9310: }
9311: $$rowtotal += $rownum;
9312: return $datatable;
9313: }
9314:
9315: sub serverstatus_pages {
9316: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 9317: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 9318: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 9319: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9320: }
9321:
1.160.6.40 raeburn 9322: sub defaults_javascript {
9323: my ($settings) = @_;
1.160.6.98 raeburn 9324: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 9325:23): my $portal_js = <<"ENDPORTAL";
9326:23):
9327:23): function portalExtras(caller) {
9328:23): var x = caller.value;
9329:23): var y = new Array('email','web');
9330:23): for (var i=0; i<y.length; i++) {
9331:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
9332:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
9333:23): if (x.length > 0) {
9334:23): z.style.display = 'block';
9335:23): } else {
9336:23): z.style.display = 'none';
9337:23): }
9338:23): }
9339:23): }
9340:23): }
9341:23): ENDPORTAL
1.160.6.40 raeburn 9342: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9343: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9344: if ($maxnum eq '') {
9345: $maxnum = 0;
9346: }
9347: $maxnum ++;
1.160.6.51 raeburn 9348: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 9349: return <<"ENDSCRIPT";
9350: <script type="text/javascript">
9351: // <![CDATA[
9352: function reorderTypes(form,caller) {
9353: var changedVal;
9354: $jstext
9355: var newpos = 'addinststatus_pos';
9356: var current = new Array;
9357: var maxh = $maxnum;
9358: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9359: var oldVal;
9360: if (caller == newpos) {
9361: changedVal = newitemVal;
9362: } else {
9363: var curritem = 'inststatus_pos_'+caller;
9364: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9365: current[newitemVal] = newpos;
9366: }
9367: for (var i=0; i<inststatuses.length; i++) {
9368: if (inststatuses[i] != caller) {
9369: var elementName = 'inststatus_pos_'+inststatuses[i];
9370: if (form.elements[elementName]) {
9371: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9372: current[currVal] = elementName;
9373: }
9374: }
9375: }
9376: for (var j=0; j<maxh; j++) {
9377: if (current[j] == undefined) {
9378: oldVal = j;
9379: }
9380: }
9381: if (oldVal < changedVal) {
9382: for (var k=oldVal+1; k<=changedVal ; k++) {
9383: var elementName = current[k];
9384: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9385: }
9386: } else {
9387: for (var k=changedVal; k<oldVal; k++) {
9388: var elementName = current[k];
9389: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9390: }
9391: }
9392: return;
9393: }
9394:
1.160.6.118.2 12(raebu 9395:23): $portal_js
9396:23):
9397:23): // ]]>
9398:23): </script>
9399:23):
9400:23): ENDSCRIPT
9401:23): } else {
9402:23): return <<"ENDSCRIPT";
9403:23): <script type="text/javascript">
9404:23): // <![CDATA[
9405:23): $portal_js
1.160.6.40 raeburn 9406: // ]]>
9407: </script>
9408:
9409: ENDSCRIPT
9410: }
9411: }
9412:
1.160.6.98 raeburn 9413: sub passwords_javascript {
1.160.6.118.2 5(raebur 9414:2): my ($prefix) = @_;
9415:2): my %intalert;
9416:2): if ($prefix eq 'passwords') {
9417:2): %intalert = &Apache::lonlocal::texthash (
9418: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.',
9419:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
9420:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
9421:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
9422:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
9423:2): );
9424:2): } elsif ($prefix eq 'secrets') {
9425:2): %intalert = &Apache::lonlocal::texthash (
9426:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
9427:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
9428:2): );
9429:2): }
1.160.6.99 raeburn 9430: &js_escape(\%intalert);
9431: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 9432:2): my $intauthjs;
9433:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 9434:
9435: function warnIntAuth(field) {
9436: if (field.name == 'intauth_check') {
9437: if (field.value == '2') {
1.160.6.99 raeburn 9438: alert('$intalert{authcheck}');
1.160.6.98 raeburn 9439: }
9440: }
9441: if (field.name == 'intauth_cost') {
9442: field.value.replace(/\s/g,'');
9443: if (field.value != '') {
9444: var regexdigit=/^\\d+\$/;
9445: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 9446: alert('$intalert{authcost}');
9447: }
9448: }
9449: }
9450: return;
9451: }
9452:
1.160.6.118.2 5(raebur 9453:2): ENDSCRIPT
9454:2):
9455:2): }
9456:2):
9457:2): $intauthjs .= <<"ENDSCRIPT";
9458:2):
9459:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 9460: field.value.replace(/^\s+/,'');
9461: field.value.replace(/\s+\$/,'');
9462: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 9463:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 9464: if (field.value == '') {
9465: alert('$intalert{passmin}');
9466: field.value = '$defmin';
9467: } else {
9468: if (!regexdigit.test(field.value)) {
9469: alert('$intalert{passmin}');
9470: field.value = '$defmin';
9471: }
9472: var minval = parseInt(field.value,10);
9473: if (minval < $defmin) {
9474: alert('$intalert{passmin}');
9475: field.value = '$defmin';
9476: }
9477: }
9478: } else {
9479: if (field.value == '0') {
9480: field.value = '';
9481: }
9482: if (field.value != '') {
1.160.6.118.2 5(raebur 9483:2): if (!regexdigit.test(field.value)) {
9484:2): if (field.name == '${prefix}_max') {
9485:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 9486: } else {
1.160.6.118.2 5(raebur 9487:2): if (field.name == '${prefix}_numsaved') {
9488:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 9489: }
9490: }
1.160.6.118.2 5(raebur 9491:2): field.value = '';
1.160.6.98 raeburn 9492: }
9493: }
9494: }
9495: return;
9496: }
9497:
9498: ENDSCRIPT
9499: return &Apache::lonhtmlcommon::scripttag($intauthjs);
9500: }
9501:
1.49 raeburn 9502: sub coursecategories_javascript {
9503: my ($settings) = @_;
1.57 raeburn 9504: my ($output,$jstext,$cathash);
1.49 raeburn 9505: if (ref($settings) eq 'HASH') {
1.57 raeburn 9506: $cathash = $settings->{'cats'};
9507: }
9508: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9509: my (@cats,@jsarray,%idx);
1.57 raeburn 9510: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9511: if (@jsarray > 0) {
9512: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9513: for (my $i=0; $i<@jsarray; $i++) {
9514: if (ref($jsarray[$i]) eq 'ARRAY') {
9515: my $catstr = join('","',@{$jsarray[$i]});
9516: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9517: }
9518: }
9519: }
9520: } else {
9521: $jstext = ' var categories = Array(1);'."\n".
9522: ' categories[0] = Array("instcode_pos");'."\n";
9523: }
1.160.6.42 raeburn 9524: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9525: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 9526: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9527: &js_escape(\$instcode_reserved);
9528: &js_escape(\$communities_reserved);
9529: &js_escape(\$choose_again);
1.49 raeburn 9530: $output = <<"ENDSCRIPT";
9531: <script type="text/javascript">
1.109 raeburn 9532: // <![CDATA[
1.49 raeburn 9533: function reorderCats(form,parent,item,idx) {
9534: var changedVal;
9535: $jstext
9536: var newpos = 'addcategory_pos';
9537: if (parent == '') {
9538: var has_instcode = 0;
9539: var maxtop = categories[idx].length;
9540: for (var j=0; j<maxtop; j++) {
9541: if (categories[idx][j] == 'instcode::0') {
9542: has_instcode == 1;
9543: }
9544: }
9545: if (has_instcode == 0) {
9546: categories[idx][maxtop] = 'instcode_pos';
9547: }
9548: } else {
9549: newpos += '_'+parent;
9550: }
9551: var maxh = 1 + categories[idx].length;
9552: var current = new Array;
9553: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9554: if (item == newpos) {
9555: changedVal = newitemVal;
9556: } else {
9557: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9558: current[newitemVal] = newpos;
9559: }
9560: for (var i=0; i<categories[idx].length; i++) {
9561: var elementName = categories[idx][i];
9562: if (elementName != item) {
9563: if (form.elements[elementName]) {
9564: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9565: current[currVal] = elementName;
9566: }
9567: }
9568: }
9569: var oldVal;
9570: for (var j=0; j<maxh; j++) {
9571: if (current[j] == undefined) {
9572: oldVal = j;
9573: }
9574: }
9575: if (oldVal < changedVal) {
9576: for (var k=oldVal+1; k<=changedVal ; k++) {
9577: var elementName = current[k];
9578: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9579: }
9580: } else {
9581: for (var k=changedVal; k<oldVal; k++) {
9582: var elementName = current[k];
9583: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9584: }
9585: }
9586: return;
9587: }
1.120 raeburn 9588:
9589: function categoryCheck(form) {
9590: if (form.elements['addcategory_name'].value == 'instcode') {
9591: alert('$instcode_reserved\\n$choose_again');
9592: return false;
9593: }
9594: if (form.elements['addcategory_name'].value == 'communities') {
9595: alert('$communities_reserved\\n$choose_again');
9596: return false;
9597: }
9598: return true;
9599: }
9600:
1.109 raeburn 9601: // ]]>
1.49 raeburn 9602: </script>
9603:
9604: ENDSCRIPT
9605: return $output;
9606: }
9607:
1.48 raeburn 9608: sub initialize_categories {
9609: my ($itemcount) = @_;
1.120 raeburn 9610: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 9611: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 9612: instcode => 'Official courses (with institutional codes)',
9613: communities => 'Communities',
9614: );
9615: my $select0 = ' selected="selected"';
9616: my $select1 = '';
9617: foreach my $default ('instcode','communities') {
9618: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 9619: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 9620: if ($default eq 'communities') {
9621: $select1 = $select0;
9622: $select0 = '';
9623: }
9624: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9625: .'<select name="'.$default.'_pos">'
9626: .'<option value="0"'.$select0.'>1</option>'
9627: .'<option value="1"'.$select1.'>2</option>'
9628: .'<option value="2">3</option></select> '
9629: .$default_names{$default}
9630: .'</span></td><td><span class="LC_nobreak">'
9631: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9632: .&mt('Display').'</label> <label>'
9633: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9634: .'</label></span></td></tr>';
1.120 raeburn 9635: $itemcount ++;
9636: }
1.48 raeburn 9637: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9638: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9639: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9640: .'<select name="addcategory_pos"'.$chgstr.'>'
9641: .'<option value="0">1</option>'
9642: .'<option value="1">2</option>'
9643: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 9644: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 9645: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9646: .'</td></tr>';
1.48 raeburn 9647: return $datatable;
9648: }
9649:
9650: sub build_category_rows {
1.49 raeburn 9651: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9652: my ($text,$name,$item,$chgstr);
1.48 raeburn 9653: if (ref($cats) eq 'ARRAY') {
9654: my $maxdepth = scalar(@{$cats});
9655: if (ref($cats->[$depth]) eq 'HASH') {
9656: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9657: my $numchildren = @{$cats->[$depth]{$parent}};
9658: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 9659: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9660: my ($idxnum,$parent_name,$parent_item);
9661: my $higher = $depth - 1;
9662: if ($higher == 0) {
9663: $parent_name = &escape($parent).'::'.$higher;
9664: } else {
9665: if (ref($path) eq 'ARRAY') {
9666: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9667: }
9668: }
9669: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9670: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9671: if ($j < $numchildren) {
1.48 raeburn 9672: $name = $cats->[$depth]{$parent}[$j];
9673: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9674: $idxnum = $idx->{$item};
9675: } else {
9676: $name = $parent_name;
9677: $item = $parent_item;
1.48 raeburn 9678: }
1.49 raeburn 9679: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9680: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9681: for (my $i=0; $i<=$numchildren; $i++) {
9682: my $vpos = $i+1;
9683: my $selstr;
9684: if ($j == $i) {
9685: $selstr = ' selected="selected" ';
9686: }
9687: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9688: }
9689: $text .= '</select> ';
9690: if ($j < $numchildren) {
9691: my $deeper = $depth+1;
9692: $text .= $name.' '
9693: .'<label><input type="checkbox" name="deletecategory" value="'
9694: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9695: if(ref($path) eq 'ARRAY') {
9696: push(@{$path},$name);
1.49 raeburn 9697: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9698: pop(@{$path});
9699: }
9700: } else {
1.160.6.87 raeburn 9701: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9702: if ($j == $numchildren) {
9703: $text .= $name;
9704: } else {
9705: $text .= $item;
9706: }
9707: $text .= '" value="" />';
9708: }
9709: $text .= '</td></tr>';
9710: }
9711: $text .= '</table></td>';
9712: } else {
9713: my $higher = $depth-1;
9714: if ($higher == 0) {
9715: $name = &escape($parent).'::'.$higher;
9716: } else {
9717: if (ref($path) eq 'ARRAY') {
9718: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9719: }
9720: }
9721: my $colspan;
9722: if ($parent ne 'instcode') {
9723: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 9724: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9725: }
9726: }
9727: }
9728: }
9729: return $text;
9730: }
9731:
1.33 raeburn 9732: sub modifiable_userdata_row {
1.160.6.93 raeburn 9733: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9734: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 9735: my ($role,$rolename,$statustype);
9736: $role = $item;
1.160.6.34 raeburn 9737: if ($context eq 'cancreate') {
1.160.6.93 raeburn 9738: if ($item =~ /^(emailusername)_(.+)$/) {
9739: $role = $1;
9740: $statustype = $2;
1.160.6.35 raeburn 9741: if (ref($usertypes) eq 'HASH') {
9742: if ($usertypes->{$statustype}) {
9743: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9744: } else {
9745: $rolename = &mt('Data provided by user');
9746: }
9747: }
1.160.6.34 raeburn 9748: }
9749: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9750: if (ref($usertypes) eq 'HASH') {
9751: $rolename = $usertypes->{$role};
9752: } else {
9753: $rolename = $role;
9754: }
1.33 raeburn 9755: } else {
1.63 raeburn 9756: if ($role eq 'cr') {
9757: $rolename = &mt('Custom role');
9758: } else {
9759: $rolename = &Apache::lonnet::plaintext($role);
9760: }
1.33 raeburn 9761: }
1.160.6.34 raeburn 9762: my (@fields,%fieldtitles);
9763: if (ref($fieldsref) eq 'ARRAY') {
9764: @fields = @{$fieldsref};
9765: } else {
9766: @fields = ('lastname','firstname','middlename','generation',
9767: 'permanentemail','id');
9768: }
9769: if ((ref($titlesref) eq 'HASH')) {
9770: %fieldtitles = %{$titlesref};
9771: } else {
9772: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9773: }
1.33 raeburn 9774: my $output;
1.160.6.93 raeburn 9775: my $css_class;
9776: if ($rowcount%2) {
9777: $css_class = 'LC_odd_row';
9778: }
9779: if ($customcss) {
9780: $css_class .= " $customcss";
9781: }
9782: $css_class =~ s/^\s+//;
9783: if ($css_class) {
9784: $css_class = ' class="'.$css_class.'"';
9785: }
9786: if ($rowstyle) {
9787: $css_class .= ' style="'.$rowstyle.'"';
9788: }
9789: if ($rowid) {
9790: $rowid = ' id="'.$rowid.'"';
9791: }
9792:
9793: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9794: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9795: '<td class="LC_left_item" colspan="2"><table>';
9796: my $rem;
9797: my %checks;
9798: if (ref($settings) eq 'HASH') {
9799: if (ref($settings->{$context}) eq 'HASH') {
9800: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 9801: my $hashref = $settings->{$context}->{$role};
9802: if ($role eq 'emailusername') {
9803: if ($statustype) {
9804: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9805: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 9806: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 9807: foreach my $field (@fields) {
9808: if ($hashref->{$field}) {
9809: $checks{$field} = $hashref->{$field};
9810: }
9811: }
9812: }
9813: }
9814: }
9815: } else {
9816: if (ref($hashref) eq 'HASH') {
9817: foreach my $field (@fields) {
9818: if ($hashref->{$field}) {
9819: $checks{$field} = ' checked="checked" ';
9820: }
9821: }
1.33 raeburn 9822: }
9823: }
9824: }
9825: }
9826: }
1.160.6.93 raeburn 9827:
9828: my $total = scalar(@fields);
9829: for (my $i=0; $i<$total; $i++) {
9830: $rem = $i%($numinrow);
1.33 raeburn 9831: if ($rem == 0) {
9832: if ($i > 0) {
9833: $output .= '</tr>';
9834: }
9835: $output .= '<tr>';
9836: }
9837: my $check = ' ';
1.160.6.35 raeburn 9838: unless ($role eq 'emailusername') {
9839: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 9840: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 9841: } else {
9842: if ($role eq 'st') {
9843: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 9844: $check = ' checked="checked" ';
1.160.6.35 raeburn 9845: }
1.33 raeburn 9846: }
9847: }
9848: }
9849: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 9850: '<span class="LC_nobreak">';
9851: if ($role eq 'emailusername') {
9852: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9853: $checks{$fields[$i]} = 'omit';
9854: }
9855: foreach my $option ('required','optional','omit') {
9856: my $checked='';
9857: if ($checks{$fields[$i]} eq $option) {
9858: $checked='checked="checked" ';
9859: }
9860: $output .= '<label>'.
9861: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
9862: &mt($option).'</label>'.(' ' x2);
9863: }
9864: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9865: } else {
9866: $output .= '<label>'.
9867: '<input type="checkbox" name="canmodify_'.$role.'" '.
9868: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9869: '</label>';
9870: }
9871: $output .= '</span></td>';
1.33 raeburn 9872: }
1.160.6.93 raeburn 9873: $rem = $total%$numinrow;
9874: my $colsleft;
9875: if ($rem) {
9876: $colsleft = $numinrow - $rem;
9877: }
9878: if ($colsleft > 1) {
1.33 raeburn 9879: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9880: ' </td>';
9881: } elsif ($colsleft == 1) {
9882: $output .= '<td class="LC_left_item"> </td>';
9883: }
9884: $output .= '</tr></table></td></tr>';
9885: return $output;
9886: }
1.28 raeburn 9887:
1.93 raeburn 9888: sub insttypes_row {
1.160.6.93 raeburn 9889: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9890: $customcss,$rowstyle) = @_;
1.93 raeburn 9891: my %lt = &Apache::lonlocal::texthash (
9892: cansearch => 'Users allowed to search',
9893: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9894: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 9895: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 9896: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9897: );
9898: my $showdom;
9899: if ($context eq 'cansearch') {
9900: $showdom = ' ('.$dom.')';
9901: }
1.160.6.5 raeburn 9902: my $class = 'LC_left_item';
9903: if ($context eq 'statustocreate') {
9904: $class = 'LC_right_item';
9905: }
1.160.6.93 raeburn 9906: my $css_class;
9907: if ($$rowtotal%2) {
9908: $css_class = 'LC_odd_row';
9909: }
9910: if ($customcss) {
9911: $css_class .= ' '.$customcss;
9912: }
9913: $css_class =~ s/^\s+//;
9914: if ($css_class) {
9915: $css_class = ' class="'.$css_class.'"';
9916: }
9917: if ($rowstyle) {
9918: $css_class .= ' style="'.$rowstyle.'"';
9919: }
9920: if ($onclick) {
9921: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 9922: }
9923: my $output = '<tr'.$css_class.'>'.
9924: '<td>'.$lt{$context}.$showdom.
9925: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9926: my $rem;
9927: if (ref($types) eq 'ARRAY') {
9928: for (my $i=0; $i<@{$types}; $i++) {
9929: if (defined($usertypes->{$types->[$i]})) {
9930: my $rem = $i%($numinrow);
9931: if ($rem == 0) {
9932: if ($i > 0) {
9933: $output .= '</tr>';
9934: }
9935: $output .= '<tr>';
1.23 raeburn 9936: }
1.26 raeburn 9937: my $check = ' ';
1.99 raeburn 9938: if (ref($settings) eq 'HASH') {
9939: if (ref($settings->{$context}) eq 'ARRAY') {
9940: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9941: $check = ' checked="checked" ';
9942: }
1.160.6.101 raeburn 9943: } elsif (ref($settings->{$context}) eq 'HASH') {
9944: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9945: $check = ' checked="checked" ';
9946: }
1.99 raeburn 9947: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9948: $check = ' checked="checked" ';
9949: }
1.23 raeburn 9950: }
1.26 raeburn 9951: $output .= '<td class="LC_left_item">'.
9952: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9953: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 9954: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 9955: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9956: }
9957: }
1.26 raeburn 9958: $rem = @{$types}%($numinrow);
1.23 raeburn 9959: }
9960: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9961: if ($context eq 'overrides') {
9962: if ($colsleft > 1) {
9963: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9964: } else {
9965: $output .= '<td class="LC_left_item">';
9966: }
9967: $output .= ' ';
1.23 raeburn 9968: } else {
1.160.6.101 raeburn 9969: if ($rem == 0) {
9970: $output .= '<tr>';
9971: }
9972: if ($colsleft > 1) {
9973: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9974: } else {
9975: $output .= '<td class="LC_left_item">';
9976: }
9977: my $defcheck = ' ';
9978: if (ref($settings) eq 'HASH') {
9979: if (ref($settings->{$context}) eq 'ARRAY') {
9980: if (grep(/^default$/,@{$settings->{$context}})) {
9981: $defcheck = ' checked="checked" ';
9982: }
9983: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9984: $defcheck = ' checked="checked" ';
9985: }
1.26 raeburn 9986: }
1.160.6.101 raeburn 9987: $output .= '<span class="LC_nobreak"><label>'.
9988: '<input type="checkbox" name="'.$context.'" '.
9989: 'value="default"'.$defcheck.$onclick.' />'.
9990: $othertitle.'</label></span>';
1.23 raeburn 9991: }
1.160.6.101 raeburn 9992: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9993: return $output;
1.23 raeburn 9994: }
9995:
9996: sub sorted_searchtitles {
9997: my %searchtitles = &Apache::lonlocal::texthash(
9998: 'uname' => 'username',
9999: 'lastname' => 'last name',
10000: 'lastfirst' => 'last name, first name',
10001: );
10002: my @titleorder = ('uname','lastname','lastfirst');
10003: return (\%searchtitles,\@titleorder);
10004: }
10005:
1.25 raeburn 10006: sub sorted_searchtypes {
10007: my %srchtypes_desc = (
10008: exact => 'is exact match',
10009: contains => 'contains ..',
10010: begins => 'begins with ..',
10011: );
10012: my @srchtypeorder = ('exact','begins','contains');
10013: return (\%srchtypes_desc,\@srchtypeorder);
10014: }
10015:
1.3 raeburn 10016: sub usertype_update_row {
10017: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10018: my $datatable;
10019: my $numinrow = 4;
10020: foreach my $type (@{$types}) {
10021: if (defined($usertypes->{$type})) {
10022: $$rownums ++;
10023: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10024: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10025: '</td><td class="LC_left_item"><table>';
10026: for (my $i=0; $i<@{$fields}; $i++) {
10027: my $rem = $i%($numinrow);
10028: if ($rem == 0) {
10029: if ($i > 0) {
10030: $datatable .= '</tr>';
10031: }
10032: $datatable .= '<tr>';
10033: }
10034: my $check = ' ';
1.39 raeburn 10035: if (ref($settings) eq 'HASH') {
10036: if (ref($settings->{'fields'}) eq 'HASH') {
10037: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10038: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10039: $check = ' checked="checked" ';
10040: }
1.3 raeburn 10041: }
10042: }
10043: }
10044:
10045: if ($i == @{$fields}-1) {
10046: my $colsleft = $numinrow - $rem;
10047: if ($colsleft > 1) {
10048: $datatable .= '<td colspan="'.$colsleft.'">';
10049: } else {
10050: $datatable .= '<td>';
10051: }
10052: } else {
10053: $datatable .= '<td>';
10054: }
1.8 raeburn 10055: $datatable .= '<span class="LC_nobreak"><label>'.
10056: '<input type="checkbox" name="updateable_'.$type.
10057: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10058: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 10059: }
10060: $datatable .= '</tr></table></td></tr>';
10061: }
10062: }
10063: return $datatable;
1.1 raeburn 10064: }
10065:
10066: sub modify_login {
1.160.6.24 raeburn 10067: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 10068: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 10069: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 10070:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 10071: %title = ( coursecatalog => 'Display course catalog',
10072: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 10073: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 10074: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 10075: loginheader => 'Log-in box header',
10076: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 10077: @offon = ('off','on');
1.112 raeburn 10078: if (ref($domconfig{login}) eq 'HASH') {
10079: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10080: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10081: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10082: }
10083: }
1.160.6.113 raeburn 10084: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10085: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10086: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10087: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10088: $saml{$lonhost} = 1;
10089: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10090: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10091: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10092: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10093: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 10094:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 10095: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10096: }
10097: }
10098: }
1.112 raeburn 10099: }
1.9 raeburn 10100: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10101: \%domconfig,\%loginhash);
1.160.6.14 raeburn 10102: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10103: foreach my $item (@toggles) {
10104: $loginhash{login}{$item} = $env{'form.'.$item};
10105: }
1.41 raeburn 10106: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10107: if (ref($colchanges{'login'}) eq 'HASH') {
10108: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10109: \%loginhash);
10110: }
1.110 raeburn 10111:
1.149 raeburn 10112: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 10113: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10114: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10115: if (keys(%servers) > 1) {
10116: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10117: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10118: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10119: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10120: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10121: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10122: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10123: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10124: $changes{'loginvia'}{$lonhost} = 1;
10125: } else {
10126: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10127: $changes{'loginvia'}{$lonhost} = 1;
10128: }
10129: } else {
10130: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10131: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10132: $changes{'loginvia'}{$lonhost} = 1;
10133: }
10134: }
10135: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10136: foreach my $item (@loginvia_attribs) {
10137: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10138: }
10139: } else {
10140: foreach my $item (@loginvia_attribs) {
10141: my $new = $env{'form.'.$lonhost.'_'.$item};
10142: if (($item eq 'serverpath') && ($new eq 'custom')) {
10143: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10144: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10145: $new = '/';
10146: }
10147: }
10148: if (($item eq 'custompath') &&
10149: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10150: $new = '';
10151: }
10152: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10153: $changes{'loginvia'}{$lonhost} = 1;
10154: }
10155: if ($item eq 'exempt') {
1.160.6.56 raeburn 10156: $new = &check_exempt_addresses($new);
1.128 raeburn 10157: }
10158: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10159: }
10160: }
1.112 raeburn 10161: } else {
1.128 raeburn 10162: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10163: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 10164: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 10165: foreach my $item (@loginvia_attribs) {
10166: my $new = $env{'form.'.$lonhost.'_'.$item};
10167: if (($item eq 'serverpath') && ($new eq 'custom')) {
10168: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10169: $new = '/';
10170: }
10171: }
10172: if (($item eq 'custompath') &&
10173: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10174: $new = '';
10175: }
10176: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10177: }
1.110 raeburn 10178: }
10179: }
10180: }
10181: }
1.119 raeburn 10182:
1.160.6.5 raeburn 10183: my $servadm = $r->dir_config('lonAdmEMail');
10184: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10185: if (ref($domconfig{'login'}) eq 'HASH') {
10186: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10187: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10188: if ($lang eq 'nolang') {
10189: push(@currlangs,$lang);
10190: } elsif (defined($langchoices{$lang})) {
10191: push(@currlangs,$lang);
10192: } else {
10193: next;
10194: }
10195: }
10196: }
10197: }
10198: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10199: if (@currlangs > 0) {
10200: foreach my $lang (@currlangs) {
10201: if (grep(/^\Q$lang\E$/,@delurls)) {
10202: $changes{'helpurl'}{$lang} = 1;
10203: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10204: $changes{'helpurl'}{$lang} = 1;
10205: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10206: push(@newlangs,$lang);
10207: } else {
10208: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10209: }
10210: }
10211: }
10212: unless (grep(/^nolang$/,@currlangs)) {
10213: if ($env{'form.loginhelpurl_nolang.filename'}) {
10214: $changes{'helpurl'}{'nolang'} = 1;
10215: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10216: push(@newlangs,'nolang');
10217: }
10218: }
10219: if ($env{'form.loginhelpurl_add_lang'}) {
10220: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10221: ($env{'form.loginhelpurl_add_file.filename'})) {
10222: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10223: $addedfile = $env{'form.loginhelpurl_add_lang'};
10224: }
10225: }
10226: if ((@newlangs > 0) || ($addedfile)) {
10227: my $error;
10228: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10229: if ($configuserok eq 'ok') {
10230: if ($switchserver) {
10231: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10232: } elsif ($author_ok eq 'ok') {
10233: my @allnew = @newlangs;
10234: if ($addedfile ne '') {
10235: push(@allnew,$addedfile);
10236: }
10237: foreach my $lang (@allnew) {
10238: my $formelem = 'loginhelpurl_'.$lang;
10239: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10240: $formelem = 'loginhelpurl_add_file';
10241: }
10242: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10243: "help/$lang",'','',$newfile{$lang});
10244: if ($result eq 'ok') {
10245: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10246: $changes{'helpurl'}{$lang} = 1;
10247: } else {
10248: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10249: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10250: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10251: (!grep(/^\Q$lang\E$/,@delurls))) {
10252: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10253: }
10254: }
10255: }
10256: } else {
10257: $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);
10258: }
10259: } else {
10260: $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);
10261: }
10262: if ($error) {
10263: &Apache::lonnet::logthis($error);
10264: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10265: }
10266: }
1.160.6.56 raeburn 10267:
10268: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10269: if (ref($domconfig{'login'}) eq 'HASH') {
10270: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10271: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10272: if ($domservers{$lonhost}) {
10273: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10274: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 10275: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 10276: }
10277: }
10278: }
10279: }
10280: }
10281: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10282: foreach my $lonhost (sort(keys(%domservers))) {
10283: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10284: $changes{'headtag'}{$lonhost} = 1;
10285: } else {
10286: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10287: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10288: }
10289: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10290: push(@newhosts,$lonhost);
10291: } elsif ($currheadtagurls{$lonhost}) {
10292: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10293: if ($currexempt{$lonhost}) {
10294: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
10295: $changes{'headtag'}{$lonhost} = 1;
10296: }
10297: } elsif ($possexempt{$lonhost}) {
10298: $changes{'headtag'}{$lonhost} = 1;
10299: }
10300: if ($possexempt{$lonhost}) {
10301: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10302: }
10303: }
10304: }
10305: }
10306: if (@newhosts) {
10307: my $error;
10308: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10309: if ($configuserok eq 'ok') {
10310: if ($switchserver) {
10311: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10312: } elsif ($author_ok eq 'ok') {
10313: foreach my $lonhost (@newhosts) {
10314: my $formelem = 'loginheadtag_'.$lonhost;
10315: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10316: "login/headtag/$lonhost",'','',
10317: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10318: if ($result eq 'ok') {
1.160.6.113 raeburn 10319: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10320: $changes{'headtag'}{$lonhost} = 1;
10321: if ($possexempt{$lonhost}) {
10322: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10323: }
10324: } else {
10325: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10326: $newheadtagurls{$lonhost},$result);
10327: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10328: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10329: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10330: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10331: }
10332: }
10333: }
10334: } else {
10335: $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);
10336: }
10337: } else {
10338: $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);
10339: }
10340: if ($error) {
10341: &Apache::lonnet::logthis($error);
10342: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10343: }
10344: }
10345: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
10346: my @newsamlimgs;
10347: foreach my $lonhost (keys(%domservers)) {
10348: if ($env{'form.saml_'.$lonhost}) {
10349: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
10350: push(@newsamlimgs,$lonhost);
10351: }
1.160.6.118.2 9(raebur 10352:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 10353: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
10354: }
10355: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 10356:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
10357:2): $env{'form.saml_window_'.$lonhost} = '';
10358:2): }
1.160.6.113 raeburn 10359: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
10360: #FIXME Need to obsolete published image
10361: delete($currsaml{$lonhost}{'img'});
10362: $changes{'saml'}{$lonhost} = 1;
10363: }
10364: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
10365: $changes{'saml'}{$lonhost} = 1;
10366: }
10367: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
10368: $changes{'saml'}{$lonhost} = 1;
10369: }
10370: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
10371: $changes{'saml'}{$lonhost} = 1;
10372: }
10373: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
10374: $changes{'saml'}{$lonhost} = 1;
10375: }
1.160.6.118.2 9(raebur 10376:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
10377:2): $changes{'saml'}{$lonhost} = 1;
10378:2): }
1.160.6.113 raeburn 10379: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
10380: $changes{'saml'}{$lonhost} = 1;
10381: }
10382: } else {
10383: $changes{'saml'}{$lonhost} = 1;
10384: }
1.160.6.118.2 9(raebur 10385:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 10386: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
10387: }
10388: } else {
10389: if ($saml{$lonhost}) {
10390: $changes{'saml'}{$lonhost} = 1;
10391: delete($currsaml{$lonhost});
10392: }
10393: }
10394: }
10395: foreach my $posshost (keys(%currsaml)) {
10396: unless (exists($domservers{$posshost})) {
10397: delete($currsaml{$posshost});
10398: }
10399: }
10400: %{$loginhash{'login'}{'saml'}} = %currsaml;
10401: if (@newsamlimgs) {
10402: my $error;
10403: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10404: if ($configuserok eq 'ok') {
10405: if ($switchserver) {
10406: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
10407: } elsif ($author_ok eq 'ok') {
10408: foreach my $lonhost (@newsamlimgs) {
10409: my $formelem = 'saml_img_'.$lonhost;
10410: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10411: "login/saml/$lonhost",'','',
10412: $env{'form.saml_img_'.$lonhost.'.filename'});
10413: if ($result eq 'ok') {
10414: $currsaml{$lonhost}{'img'} = $imgurl;
10415: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
10416: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 10417: } else {
1.160.6.113 raeburn 10418: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
10419: $lonhost,$result);
1.160.6.56 raeburn 10420: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10421: }
10422: }
10423: } else {
1.160.6.113 raeburn 10424: $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 10425: }
10426: } else {
1.160.6.113 raeburn 10427: $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 10428: }
10429: if ($error) {
10430: &Apache::lonnet::logthis($error);
10431: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10432: }
10433: }
1.160.6.5 raeburn 10434: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
10435:
10436: my $defaulthelpfile = '/adm/loginproblems.html';
10437: my $defaulttext = &mt('Default in use');
10438:
1.1 raeburn 10439: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10440: $dom);
10441: if ($putresult eq 'ok') {
1.160.6.14 raeburn 10442: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10443: my %defaultchecked = (
10444: 'coursecatalog' => 'on',
1.160.6.14 raeburn 10445: 'helpdesk' => 'on',
1.42 raeburn 10446: 'adminmail' => 'off',
1.43 raeburn 10447: 'newuser' => 'off',
1.42 raeburn 10448: );
1.55 raeburn 10449: if (ref($domconfig{'login'}) eq 'HASH') {
10450: foreach my $item (@toggles) {
10451: if ($defaultchecked{$item} eq 'on') {
10452: if (($domconfig{'login'}{$item} eq '0') &&
10453: ($env{'form.'.$item} eq '1')) {
10454: $changes{$item} = 1;
10455: } elsif (($domconfig{'login'}{$item} eq '' ||
10456: $domconfig{'login'}{$item} eq '1') &&
10457: ($env{'form.'.$item} eq '0')) {
10458: $changes{$item} = 1;
10459: }
10460: } elsif ($defaultchecked{$item} eq 'off') {
10461: if (($domconfig{'login'}{$item} eq '1') &&
10462: ($env{'form.'.$item} eq '0')) {
10463: $changes{$item} = 1;
10464: } elsif (($domconfig{'login'}{$item} eq '' ||
10465: $domconfig{'login'}{$item} eq '0') &&
10466: ($env{'form.'.$item} eq '1')) {
10467: $changes{$item} = 1;
10468: }
1.42 raeburn 10469: }
10470: }
1.41 raeburn 10471: }
1.6 raeburn 10472: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10473: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 10474: if (exists($changes{'saml'})) {
10475: my $hostid_in_use;
10476: my @hosts = &Apache::lonnet::current_machine_ids();
10477: if (@hosts > 1) {
10478: foreach my $hostid (@hosts) {
10479: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
10480: $hostid_in_use = $hostid;
10481: last;
10482: }
10483: }
10484: } else {
10485: $hostid_in_use = $r->dir_config('lonHostID');
10486: }
10487: if (($hostid_in_use) &&
10488: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
10489: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
10490: }
10491: if (ref($lastactref) eq 'HASH') {
10492: if (ref($changes{'saml'}) eq 'HASH') {
10493: my %updates;
10494: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
10495: $lastactref->{'samllanding'} = \%updates;
10496: }
10497: }
10498: }
1.160.6.27 raeburn 10499: if (ref($lastactref) eq 'HASH') {
10500: $lastactref->{'domainconfig'} = 1;
10501: }
1.1 raeburn 10502: $resulttext = &mt('Changes made:').'<ul>';
10503: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10504: if ($item eq 'loginvia') {
1.112 raeburn 10505: if (ref($changes{$item}) eq 'HASH') {
10506: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10507: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10508: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10509: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10510: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10511: $protocol = 'http' if ($protocol ne 'https');
10512: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10513:
10514: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10515: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10516: } else {
10517: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10518: }
10519: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10520: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10521: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10522: }
10523: $resulttext .= '</li>';
10524: } else {
10525: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10526: }
1.112 raeburn 10527: } else {
1.128 raeburn 10528: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10529: }
10530: }
1.128 raeburn 10531: $resulttext .= '</ul></li>';
1.112 raeburn 10532: }
1.160.6.5 raeburn 10533: } elsif ($item eq 'helpurl') {
10534: if (ref($changes{$item}) eq 'HASH') {
10535: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10536: if (grep(/^\Q$lang\E$/,@delurls)) {
10537: my ($chg,$link);
10538: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10539: if ($lang eq 'nolang') {
10540: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10541: } else {
10542: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10543: }
10544: $resulttext .= '<li>'.$chg.'</li>';
10545: } else {
10546: my $chg;
10547: if ($lang eq 'nolang') {
10548: $chg = &mt('custom log-in help file for no preferred language');
10549: } else {
10550: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10551: }
10552: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10553: $loginhash{'login'}{'helpurl'}{$lang}.
10554: '?inhibitmenu=yes',$chg,600,500).
10555: '</li>';
10556: }
10557: }
10558: }
1.160.6.56 raeburn 10559: } elsif ($item eq 'headtag') {
10560: if (ref($changes{$item}) eq 'HASH') {
10561: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10562: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10563: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10564: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10565: $resulttext .= '<li><a href="'.
10566: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10567: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10568: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10569: if ($possexempt{$lonhost}) {
10570: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10571: } else {
10572: $resulttext .= &mt('included for any client IP');
10573: }
10574: $resulttext .= '</li>';
10575: }
10576: }
10577: }
1.160.6.113 raeburn 10578: } elsif ($item eq 'saml') {
10579: if (ref($changes{$item}) eq 'HASH') {
10580: my %notlt = (
10581: text => 'Text for log-in by SSO',
10582: img => 'SSO button image',
10583: alt => 'Alt text for button image',
10584: url => 'SSO URL',
10585: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 10586:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 10587: notsso => 'Text for non-SSO log-in',
10588: );
10589: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10590: if (ref($currsaml{$lonhost}) eq 'HASH') {
10591: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
10592: '<ul>';
1.160.6.118.2 9(raebur 10593:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 10594: if ($currsaml{$lonhost}{$key} eq '') {
10595: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
10596: } else {
10597: my $value = "'$currsaml{$lonhost}{$key}'";
10598: if ($key eq 'img') {
10599: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 10600:2): } elsif ($key eq 'window') {
10601:2): $value = 'On';
1.160.6.113 raeburn 10602: }
10603: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
10604: $value).'</li>';
10605: }
10606: }
10607: $resulttext .= '</ul></li>';
10608: } else {
10609: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
10610: }
10611: }
10612: }
1.160.6.5 raeburn 10613: } elsif ($item eq 'captcha') {
10614: if (ref($loginhash{'login'}) eq 'HASH') {
10615: my $chgtxt;
10616: if ($loginhash{'login'}{$item} eq 'notused') {
10617: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10618: } else {
10619: my %captchas = &captcha_phrases();
10620: if ($captchas{$loginhash{'login'}{$item}}) {
10621: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10622: } else {
10623: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10624: }
10625: }
10626: $resulttext .= '<li>'.$chgtxt.'</li>';
10627: }
10628: } elsif ($item eq 'recaptchakeys') {
10629: if (ref($loginhash{'login'}) eq 'HASH') {
10630: my ($privkey,$pubkey);
10631: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10632: $pubkey = $loginhash{'login'}{$item}{'public'};
10633: $privkey = $loginhash{'login'}{$item}{'private'};
10634: }
10635: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10636: if (!$pubkey) {
10637: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10638: } else {
10639: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10640: }
10641: if (!$privkey) {
10642: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10643: } else {
1.160.6.53 raeburn 10644: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 10645: }
10646: $chgtxt .= '</ul>';
10647: $resulttext .= '<li>'.$chgtxt.'</li>';
10648: }
1.160.6.69 raeburn 10649: } elsif ($item eq 'recaptchaversion') {
10650: if (ref($loginhash{'login'}) eq 'HASH') {
10651: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
10652: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
10653: '</li>';
10654: }
10655: }
1.41 raeburn 10656: } else {
10657: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10658: }
1.1 raeburn 10659: }
1.6 raeburn 10660: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10661: } else {
10662: $resulttext = &mt('No changes made to log-in page settings');
10663: }
10664: } else {
1.11 albertel 10665: $resulttext = '<span class="LC_error">'.
10666: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10667: }
1.6 raeburn 10668: if ($errors) {
1.9 raeburn 10669: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10670: $errors.'</ul>';
10671: }
10672: return $resulttext;
10673: }
10674:
1.160.6.56 raeburn 10675: sub check_exempt_addresses {
10676: my ($iplist) = @_;
10677: $iplist =~ s/^\s+//;
10678: $iplist =~ s/\s+$//;
10679: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10680: my (@okips,$new);
10681: foreach my $ip (@poss_ips) {
10682: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10683: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10684: push(@okips,$ip);
10685: }
10686: }
10687: }
10688: if (@okips > 0) {
10689: $new = join(',',@okips);
10690: } else {
10691: $new = '';
10692: }
10693: return $new;
10694: }
10695:
1.6 raeburn 10696: sub color_font_choices {
10697: my %choices =
10698: &Apache::lonlocal::texthash (
10699: img => "Header",
10700: bgs => "Background colors",
10701: links => "Link colors",
1.55 raeburn 10702: images => "Images",
1.6 raeburn 10703: font => "Font color",
1.160.6.22 raeburn 10704: fontmenu => "Font menu",
1.76 raeburn 10705: pgbg => "Page",
1.6 raeburn 10706: tabbg => "Header",
10707: sidebg => "Border",
10708: link => "Link",
10709: alink => "Active link",
10710: vlink => "Visited link",
10711: );
10712: return %choices;
10713: }
10714:
1.160.6.113 raeburn 10715: sub modify_ipaccess {
10716: my ($dom,$lastactref,%domconfig) = @_;
10717: my (@allpos,%changes,%confhash,$errors,$resulttext);
10718: my (@items,%deletions,%itemids,@warnings);
10719: my ($typeorder,$types) = &commblocktype_text();
10720: if ($env{'form.ipaccess_add'}) {
10721: my $name = $env{'form.ipaccess_name_add'};
10722: my ($newid,$error) = &get_ipaccess_id($dom,$name);
10723: if ($newid) {
10724: $itemids{'add'} = $newid;
10725: push(@items,'add');
10726: $changes{$newid} = 1;
10727: } else {
10728: $error = &mt('Failed to acquire unique ID for new IP access control item');
10729: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10730: }
10731: }
10732: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10733: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
10734: if (@todelete) {
10735: map { $deletions{$_} = 1; } @todelete;
10736: }
10737: my $maxnum = $env{'form.ipaccess_maxnum'};
10738: for (my $i=0; $i<$maxnum; $i++) {
10739: my $itemid = $env{'form.ipaccess_id_'.$i};
10740: $itemid =~ s/\D+//g;
10741: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10742: if ($deletions{$itemid}) {
10743: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
10744: } else {
10745: push(@items,$i);
10746: $itemids{$i} = $itemid;
10747: }
10748: }
10749: }
10750: }
10751: foreach my $idx (@items) {
10752: my $itemid = $itemids{$idx};
10753: next unless ($itemid);
10754: my %current;
10755: unless ($idx eq 'add') {
10756: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10757: %current = %{$domconfig{'ipaccess'}{$itemid}};
10758: }
10759: }
10760: my $position = $env{'form.ipaccess_pos_'.$itemid};
10761: $position =~ s/\D+//g;
10762: if ($position ne '') {
10763: $allpos[$position] = $itemid;
10764: }
10765: my $name = $env{'form.ipaccess_name_'.$idx};
10766: $name =~ s/^\s+|\s+$//g;
10767: $confhash{$itemid}{'name'} = $name;
10768: my $possrange = $env{'form.ipaccess_range_'.$idx};
10769: $possrange =~ s/^\s+|\s+$//g;
10770: unless ($possrange eq '') {
10771: $possrange =~ s/[\r\n]+/\s/g;
10772: $possrange =~ s/\s*-\s*/-/g;
10773: $possrange =~ s/\s+/,/g;
10774: $possrange =~ s/,+/,/g;
10775: if ($possrange ne '') {
10776: my (@ok,$count);
10777: $count = 0;
10778: foreach my $poss (split(/\,/,$possrange)) {
10779: $count ++;
10780: $poss = &validate_ip_pattern($poss);
10781: if ($poss ne '') {
10782: push(@ok,$poss);
10783: }
10784: }
10785: my $diff = $count - scalar(@ok);
10786: if ($diff) {
10787: $errors .= '<li><span class="LC_error">'.
10788: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
10789: $diff,$name).
10790: '</span></li>';
10791: }
10792: if (@ok) {
10793: my @cidr_list;
10794: foreach my $item (@ok) {
10795: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
10796: }
10797: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
10798: }
10799: }
10800: }
10801: foreach my $field ('name','ip') {
10802: unless (($idx eq 'add') || ($changes{$itemid})) {
10803: if ($current{$field} ne $confhash{$itemid}{$field}) {
10804: $changes{$itemid} = 1;
10805: last;
10806: }
10807: }
10808: }
10809: $confhash{$itemid}{'commblocks'} = {};
10810:
10811: my %commblocks;
10812: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
10813: foreach my $type (@{$typeorder}) {
10814: if ($commblocks{$type}) {
10815: $confhash{$itemid}{'commblocks'}{$type} = 'on';
10816: }
10817: unless (($idx eq 'add') || ($changes{$itemid})) {
10818: if (ref($current{'commblocks'}) eq 'HASH') {
10819: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
10820: $changes{$itemid} = 1;
10821: }
10822: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
10823: $changes{$itemid} = 1;
10824: }
10825: }
10826: }
10827: $confhash{$itemid}{'courses'} = {};
10828: my %crsdeletions;
10829: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
10830: if (@delcrs) {
10831: map { $crsdeletions{$_} = 1; } @delcrs;
10832: }
10833: if (ref($current{'courses'}) eq 'HASH') {
10834: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
10835: if ($crsdeletions{$cid}) {
10836: $changes{$itemid} = 1;
10837: } else {
10838: $confhash{$itemid}{'courses'}{$cid} = 1;
10839: }
10840: }
10841: }
10842: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
10843: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
10844: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
10845: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
10846: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
10847: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
10848: $errors .= '<li><span class="LC_error">'.
10849: &mt('Invalid courseID [_1] omitted from list of allowed courses',
10850: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
10851: '</span></li>';
10852: } else {
10853: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
10854: $changes{$itemid} = 1;
10855: }
10856: }
10857: }
10858: if (@allpos > 0) {
10859: my $idx = 0;
10860: foreach my $itemid (@allpos) {
10861: if ($itemid ne '') {
10862: $confhash{$itemid}{'order'} = $idx;
10863: unless ($changes{$itemid}) {
10864: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10865: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10866: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
10867: $changes{$itemid} = 1;
10868: }
10869: }
10870: }
10871: }
10872: $idx ++;
10873: }
10874: }
10875: }
10876: if (keys(%changes)) {
10877: my %defaultshash = (
10878: ipaccess => \%confhash,
10879: );
10880: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10881: $dom);
10882: if ($putresult eq 'ok') {
10883: my $cachetime = 1800;
10884: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
10885: if (ref($lastactref) eq 'HASH') {
10886: $lastactref->{'ipaccess'} = 1;
10887: }
10888: $resulttext = &mt('Changes made:').'<ul>';
10889: my %bynum;
10890: foreach my $itemid (sort(keys(%changes))) {
10891: if (ref($confhash{$itemid}) eq 'HASH') {
10892: my $position = $confhash{$itemid}{'order'};
10893: if ($position =~ /^\d+$/) {
10894: $bynum{$position} = $itemid;
10895: }
10896: }
10897: }
10898: if (keys(%deletions)) {
10899: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
10900: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10901: }
10902: }
10903: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10904: my $itemid = $bynum{$pos};
10905: if (ref($confhash{$itemid}) eq 'HASH') {
10906: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
10907: my $position = $pos + 1;
10908: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10909: if ($confhash{$itemid}{'ip'} eq '') {
10910: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
10911: } else {
10912: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
10913: }
10914: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
10915: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
10916: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
10917: '</li>';
10918: } else {
10919: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
10920: }
10921: if (keys(%{$confhash{$itemid}{'courses'}})) {
10922: my @courses;
10923: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
10924: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
10925: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
10926: }
10927: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
10928: join('</li><li>',@courses).'</li></ul>';
10929: } else {
10930: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
10931: }
10932: $resulttext .= '</ul></li>';
10933: }
10934: }
10935: $resulttext .= '</ul>';
10936: } else {
10937: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10938: }
10939: } else {
10940: $resulttext = &mt('No changes made');
10941: }
10942: if ($errors) {
10943: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
10944: $errors.'</ul></p>';
10945: }
10946: return $resulttext;
10947: }
10948:
10949: sub get_ipaccess_id {
10950: my ($domain,$location) = @_;
10951: # get lock on ipaccess db
10952: my $lockhash = {
10953: lock => $env{'user.name'}.
10954: ':'.$env{'user.domain'},
10955: };
10956: my $tries = 0;
10957: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10958: my ($id,$error);
10959:
10960: while (($gotlock ne 'ok') && ($tries<10)) {
10961: $tries ++;
10962: sleep (0.1);
10963: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10964: }
10965: if ($gotlock eq 'ok') {
10966: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10967: if ($currids{'lock'}) {
10968: delete($currids{'lock'});
10969: if (keys(%currids)) {
10970: my @curr = sort { $a <=> $b } keys(%currids);
10971: if ($curr[-1] =~ /^\d+$/) {
10972: $id = 1 + $curr[-1];
10973: }
10974: } else {
10975: $id = 1;
10976: }
10977: if ($id) {
10978: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10979: $error = 'nostore';
10980: }
10981: } else {
10982: $error = 'nonumber';
10983: }
10984: }
10985: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10986: } else {
10987: $error = 'nolock';
10988: }
10989: return ($id,$error);
10990: }
10991:
1.6 raeburn 10992: sub modify_rolecolors {
1.160.6.24 raeburn 10993: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10994: my ($resulttext,%rolehash);
10995: $rolehash{'rolecolors'} = {};
1.55 raeburn 10996: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10997: if ($domconfig{'rolecolors'} eq '') {
10998: $domconfig{'rolecolors'} = {};
10999: }
11000: }
1.9 raeburn 11001: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11002: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11003: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11004: $dom);
11005: if ($putresult eq 'ok') {
11006: if (keys(%changes) > 0) {
1.41 raeburn 11007: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11008: if (ref($lastactref) eq 'HASH') {
11009: $lastactref->{'domainconfig'} = 1;
11010: }
1.6 raeburn 11011: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11012: $rolehash{'rolecolors'});
11013: } else {
11014: $resulttext = &mt('No changes made to default color schemes');
11015: }
11016: } else {
1.11 albertel 11017: $resulttext = '<span class="LC_error">'.
11018: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11019: }
11020: if ($errors) {
11021: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11022: $errors.'</ul>';
11023: }
11024: return $resulttext;
11025: }
11026:
11027: sub modify_colors {
1.9 raeburn 11028: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11029: my (%changes,%choices);
1.51 raeburn 11030: my @bgs;
1.6 raeburn 11031: my @links = ('link','alink','vlink');
1.41 raeburn 11032: my @logintext;
1.6 raeburn 11033: my @images;
11034: my $servadm = $r->dir_config('lonAdmEMail');
11035: my $errors;
1.160.6.22 raeburn 11036: my %defaults;
1.6 raeburn 11037: foreach my $role (@{$roles}) {
11038: if ($role eq 'login') {
1.12 raeburn 11039: %choices = &login_choices();
1.41 raeburn 11040: @logintext = ('textcol','bgcol');
1.12 raeburn 11041: } else {
11042: %choices = &color_font_choices();
11043: }
11044: if ($role eq 'login') {
1.41 raeburn 11045: @images = ('img','logo','domlogo','login');
1.51 raeburn 11046: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11047: } else {
11048: @images = ('img');
1.160.6.22 raeburn 11049: @bgs = ('pgbg','tabbg','sidebg');
11050: }
11051: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11052: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11053: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11054: }
11055: if ($role eq 'login') {
11056: foreach my $item (@logintext) {
1.160.6.39 raeburn 11057: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11058: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11059: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11060: }
11061: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 11062: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11063: }
11064: }
11065: } else {
1.160.6.39 raeburn 11066: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11067: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11068: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11069: }
11070: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 11071: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11072: }
1.6 raeburn 11073: }
1.160.6.22 raeburn 11074: foreach my $item (@bgs) {
1.160.6.39 raeburn 11075: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11076: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11077: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11078: }
11079: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 11080: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11081: }
11082: }
11083: foreach my $item (@links) {
1.160.6.39 raeburn 11084: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11085: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11086: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11087: }
11088: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 11089: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11090: }
1.6 raeburn 11091: }
1.46 raeburn 11092: my ($configuserok,$author_ok,$switchserver) =
11093: &config_check($dom,$confname,$servadm);
1.9 raeburn 11094: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11095: if (ref($domconfig->{$role}) ne 'HASH') {
11096: $domconfig->{$role} = {};
11097: }
1.8 raeburn 11098: foreach my $img (@images) {
1.160.6.118.2 2(raebur 11099:2): if ($role eq 'login') {
11100:2): if (($img eq 'img') || ($img eq 'logo')) {
11101:2): if (defined($env{'form.login_showlogo_'.$img})) {
11102:2): $confhash->{$role}{'showlogo'}{$img} = 1;
11103:2): } else {
11104:2): $confhash->{$role}{'showlogo'}{$img} = 0;
11105:2): }
1.70 raeburn 11106: }
1.160.6.118.2 2(raebur 11107:2): if ($env{'form.login_alt_'.$img} ne '') {
11108:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11109:2): }
11110:2): }
1.18 albertel 11111: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11112: && !defined($domconfig->{$role}{$img})
11113: && !$env{'form.'.$role.'_del_'.$img}
11114: && $env{'form.'.$role.'_import_'.$img}) {
11115: # import the old configured image from the .tab setting
11116: # if they haven't provided a new one
11117: $domconfig->{$role}{$img} =
11118: $env{'form.'.$role.'_import_'.$img};
11119: }
1.6 raeburn 11120: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11121: my $error;
1.6 raeburn 11122: if ($configuserok eq 'ok') {
1.9 raeburn 11123: if ($switchserver) {
1.12 raeburn 11124: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11125: } else {
11126: if ($author_ok eq 'ok') {
11127: my ($result,$logourl) =
11128: &publishlogo($r,'upload',$role.'_'.$img,
11129: $dom,$confname,$img,$width,$height);
11130: if ($result eq 'ok') {
11131: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11132: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11133: } else {
1.12 raeburn 11134: $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 11135: }
11136: } else {
1.46 raeburn 11137: $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 11138: }
11139: }
11140: } else {
1.46 raeburn 11141: $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 11142: }
11143: if ($error) {
1.8 raeburn 11144: &Apache::lonnet::logthis($error);
1.11 albertel 11145: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11146: }
11147: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11148: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11149: my $error;
11150: if ($configuserok eq 'ok') {
11151: # is confname an author?
11152: if ($switchserver eq '') {
11153: if ($author_ok eq 'ok') {
11154: my ($result,$logourl) =
11155: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11156: $dom,$confname,$img,$width,$height);
11157: if ($result eq 'ok') {
11158: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11159: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11160: }
11161: }
11162: }
11163: }
1.6 raeburn 11164: }
11165: }
11166: }
11167: if (ref($domconfig) eq 'HASH') {
11168: if (ref($domconfig->{$role}) eq 'HASH') {
11169: foreach my $img (@images) {
11170: if ($domconfig->{$role}{$img} ne '') {
11171: if ($env{'form.'.$role.'_del_'.$img}) {
11172: $confhash->{$role}{$img} = '';
1.12 raeburn 11173: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11174: } else {
1.9 raeburn 11175: if ($confhash->{$role}{$img} eq '') {
11176: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11177: }
1.6 raeburn 11178: }
11179: } else {
11180: if ($env{'form.'.$role.'_del_'.$img}) {
11181: $confhash->{$role}{$img} = '';
1.12 raeburn 11182: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11183: }
11184: }
1.160.6.118.2 2(raebur 11185:2): if ($role eq 'login') {
11186:2): if (($img eq 'logo') || ($img eq 'img')) {
11187:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11188:2): if ($confhash->{$role}{'showlogo'}{$img} ne
11189:2): $domconfig->{$role}{'showlogo'}{$img}) {
11190:2): $changes{$role}{'showlogo'}{$img} = 1;
11191:2): }
11192:2): } else {
11193:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11194:2): $changes{$role}{'showlogo'}{$img} = 1;
11195:2): }
1.70 raeburn 11196: }
1.160.6.118.2 2(raebur 11197:2): }
11198:2): if ($img ne 'login') {
11199:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11200:2): if ($confhash->{$role}{'alttext'}{$img} ne
11201:2): $domconfig->{$role}{'alttext'}{$img}) {
11202:2): $changes{$role}{'alttext'}{$img} = 1;
11203:2): }
11204:2): } else {
11205:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11206:2): $changes{$role}{'alttext'}{$img} = 1;
11207:2): }
1.70 raeburn 11208: }
11209: }
11210: }
11211: }
1.6 raeburn 11212: if ($domconfig->{$role}{'font'} ne '') {
11213: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11214: $changes{$role}{'font'} = 1;
11215: }
11216: } else {
11217: if ($confhash->{$role}{'font'}) {
11218: $changes{$role}{'font'} = 1;
11219: }
11220: }
1.107 raeburn 11221: if ($role ne 'login') {
11222: if ($domconfig->{$role}{'fontmenu'} ne '') {
11223: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11224: $changes{$role}{'fontmenu'} = 1;
11225: }
11226: } else {
11227: if ($confhash->{$role}{'fontmenu'}) {
11228: $changes{$role}{'fontmenu'} = 1;
11229: }
1.97 tempelho 11230: }
11231: }
1.6 raeburn 11232: foreach my $item (@bgs) {
11233: if ($domconfig->{$role}{$item} ne '') {
11234: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11235: $changes{$role}{'bgs'}{$item} = 1;
11236: }
11237: } else {
11238: if ($confhash->{$role}{$item}) {
11239: $changes{$role}{'bgs'}{$item} = 1;
11240: }
11241: }
11242: }
11243: foreach my $item (@links) {
11244: if ($domconfig->{$role}{$item} ne '') {
11245: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11246: $changes{$role}{'links'}{$item} = 1;
11247: }
11248: } else {
11249: if ($confhash->{$role}{$item}) {
11250: $changes{$role}{'links'}{$item} = 1;
11251: }
11252: }
11253: }
1.41 raeburn 11254: foreach my $item (@logintext) {
11255: if ($domconfig->{$role}{$item} ne '') {
11256: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11257: $changes{$role}{'logintext'}{$item} = 1;
11258: }
11259: } else {
11260: if ($confhash->{$role}{$item}) {
11261: $changes{$role}{'logintext'}{$item} = 1;
11262: }
11263: }
11264: }
1.6 raeburn 11265: } else {
11266: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11267: \@logintext,$confhash,\%changes);
1.6 raeburn 11268: }
11269: } else {
11270: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11271: \@logintext,$confhash,\%changes);
1.6 raeburn 11272: }
11273: }
11274: return ($errors,%changes);
11275: }
11276:
1.46 raeburn 11277: sub config_check {
11278: my ($dom,$confname,$servadm) = @_;
11279: my ($configuserok,$author_ok,$switchserver,%currroles);
11280: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11281: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11282: $confname,$servadm);
11283: if ($configuserok eq 'ok') {
11284: $switchserver = &check_switchserver($dom,$confname);
11285: if ($switchserver eq '') {
11286: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11287: }
11288: }
11289: return ($configuserok,$author_ok,$switchserver);
11290: }
11291:
1.6 raeburn 11292: sub default_change_checker {
1.41 raeburn 11293: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11294: foreach my $item (@{$links}) {
11295: if ($confhash->{$role}{$item}) {
11296: $changes->{$role}{'links'}{$item} = 1;
11297: }
11298: }
11299: foreach my $item (@{$bgs}) {
11300: if ($confhash->{$role}{$item}) {
11301: $changes->{$role}{'bgs'}{$item} = 1;
11302: }
11303: }
1.41 raeburn 11304: foreach my $item (@{$logintext}) {
11305: if ($confhash->{$role}{$item}) {
11306: $changes->{$role}{'logintext'}{$item} = 1;
11307: }
11308: }
1.6 raeburn 11309: foreach my $img (@{$images}) {
11310: if ($env{'form.'.$role.'_del_'.$img}) {
11311: $confhash->{$role}{$img} = '';
1.12 raeburn 11312: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11313: }
1.70 raeburn 11314: if ($role eq 'login') {
11315: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11316: $changes->{$role}{'showlogo'}{$img} = 1;
11317: }
1.160.6.118.2 2(raebur 11318:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
11319:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11320:2): $changes->{$role}{'alttext'}{$img} = 1;
11321:2): }
11322:2): }
1.70 raeburn 11323: }
1.6 raeburn 11324: }
11325: if ($confhash->{$role}{'font'}) {
11326: $changes->{$role}{'font'} = 1;
11327: }
1.48 raeburn 11328: }
1.6 raeburn 11329:
11330: sub display_colorchgs {
11331: my ($dom,$changes,$roles,$confhash) = @_;
11332: my (%choices,$resulttext);
11333: if (!grep(/^login$/,@{$roles})) {
11334: $resulttext = &mt('Changes made:').'<br />';
11335: }
11336: foreach my $role (@{$roles}) {
11337: if ($role eq 'login') {
11338: %choices = &login_choices();
11339: } else {
11340: %choices = &color_font_choices();
11341: }
11342: if (ref($changes->{$role}) eq 'HASH') {
11343: if ($role ne 'login') {
11344: $resulttext .= '<h4>'.&mt($role).'</h4>';
11345: }
11346: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11347: if ($role ne 'login') {
11348: $resulttext .= '<ul>';
11349: }
11350: if (ref($changes->{$role}{$key}) eq 'HASH') {
11351: if ($role ne 'login') {
11352: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11353: }
11354: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11355: if (($role eq 'login') && ($key eq 'showlogo')) {
11356: if ($confhash->{$role}{$key}{$item}) {
11357: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11358: } else {
11359: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11360: }
1.160.6.118.2 2(raebur 11361:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
11362:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 11363:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 11364:2): $confhash->{$role}{$key}{$item}).'</li>';
11365:2): } else {
11366:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
11367:2): }
1.70 raeburn 11368: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 11369: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11370: } else {
1.12 raeburn 11371: my $newitem = $confhash->{$role}{$item};
11372: if ($key eq 'images') {
11373: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
11374: }
11375: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 11376: }
11377: }
11378: if ($role ne 'login') {
11379: $resulttext .= '</ul></li>';
11380: }
11381: } else {
11382: if ($confhash->{$role}{$key} eq '') {
11383: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11384: } else {
11385: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11386: }
11387: }
11388: if ($role ne 'login') {
11389: $resulttext .= '</ul>';
11390: }
11391: }
11392: }
11393: }
1.3 raeburn 11394: return $resulttext;
1.1 raeburn 11395: }
11396:
1.9 raeburn 11397: sub thumb_dimensions {
11398: return ('200','50');
11399: }
11400:
1.16 raeburn 11401: sub check_dimensions {
11402: my ($inputfile) = @_;
11403: my ($fullwidth,$fullheight);
11404: if ($inputfile =~ m|^[/\w.\-]+$|) {
11405: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11406: my $imageinfo = <PIPE>;
11407: if (!close(PIPE)) {
11408: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11409: }
11410: chomp($imageinfo);
11411: my ($fullsize) =
1.21 raeburn 11412: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 11413: if ($fullsize) {
11414: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11415: }
11416: }
11417: }
11418: return ($fullwidth,$fullheight);
11419: }
11420:
1.9 raeburn 11421: sub check_configuser {
11422: my ($uhome,$dom,$confname,$servadm) = @_;
11423: my ($configuserok,%currroles);
11424: if ($uhome eq 'no_host') {
11425: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 11426: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 11427: $configuserok =
11428: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11429: $configpass,'','','','','',undef,$servadm);
11430: } else {
11431: $configuserok = 'ok';
11432: %currroles =
11433: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11434: }
11435: return ($configuserok,%currroles);
11436: }
11437:
11438: sub check_authorstatus {
11439: my ($dom,$confname,%currroles) = @_;
11440: my $author_ok;
1.40 raeburn 11441: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11442: my $start = time;
11443: my $end = 0;
11444: $author_ok =
11445: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11446: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11447: } else {
11448: $author_ok = 'ok';
11449: }
11450: return $author_ok;
11451: }
11452:
11453: sub publishlogo {
1.46 raeburn 11454: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 11455: my ($output,$fname,$logourl);
11456: if ($action eq 'upload') {
11457: $fname=$env{'form.'.$formname.'.filename'};
11458: chop($env{'form.'.$formname});
11459: } else {
11460: ($fname) = ($formname =~ /([^\/]+)$/);
11461: }
1.46 raeburn 11462: if ($savefileas ne '') {
11463: $fname = $savefileas;
11464: }
1.9 raeburn 11465: $fname=&Apache::lonnet::clean_filename($fname);
11466: # See if there is anything left
11467: unless ($fname) { return ('error: no uploaded file'); }
11468: $fname="$subdir/$fname";
1.160.6.5 raeburn 11469: my $docroot=$r->dir_config('lonDocRoot');
11470: my $filepath="$docroot/priv";
11471: my $relpath = "$dom/$confname";
1.9 raeburn 11472: my ($fnamepath,$file,$fetchthumb);
11473: $file=$fname;
11474: if ($fname=~m|/|) {
11475: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11476: }
1.160.6.26 raeburn 11477: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11478: my $count;
1.160.6.5 raeburn 11479: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11480: $filepath.="/$parts[$count]";
11481: if ((-e $filepath)!=1) {
11482: mkdir($filepath,02770);
11483: }
11484: }
11485: # Check for bad extension and disallow upload
11486: if ($file=~/\.(\w+)$/ &&
11487: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11488: $output =
1.160.6.25 raeburn 11489: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11490: } elsif ($file=~/\.(\w+)$/ &&
11491: !defined(&Apache::loncommon::fileembstyle($1))) {
11492: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11493: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 11494: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 11495: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 11496: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11497: } else {
11498: my $source = $filepath.'/'.$file;
11499: my $logfile;
1.160.6.88 raeburn 11500: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 11501: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11502: }
11503: print $logfile
11504: "\n================= Publish ".localtime()." ================\n".
11505: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11506: # Save the file
1.160.6.88 raeburn 11507: if (!open(FH,">",$source)) {
1.9 raeburn 11508: &Apache::lonnet::logthis('Failed to create '.$source);
11509: return (&mt('Failed to create file'));
11510: }
11511: if ($action eq 'upload') {
11512: if (!print FH ($env{'form.'.$formname})) {
11513: &Apache::lonnet::logthis('Failed to write to '.$source);
11514: return (&mt('Failed to write file'));
11515: }
11516: } else {
11517: my $original = &Apache::lonnet::filelocation('',$formname);
11518: if(!copy($original,$source)) {
11519: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11520: return (&mt('Failed to write file'));
11521: }
11522: }
11523: close(FH);
11524: chmod(0660, $source); # Permissions to rw-rw---.
11525:
11526: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11527: my $copyfile=$targetdir.'/'.$file;
11528:
11529: my @parts=split(/\//,$targetdir);
11530: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11531: for (my $count=5;$count<=$#parts;$count++) {
11532: $path.="/$parts[$count]";
11533: if (!-e $path) {
11534: print $logfile "\nCreating directory ".$path;
11535: mkdir($path,02770);
11536: }
11537: }
11538: my $versionresult;
11539: if (-e $copyfile) {
11540: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11541: } else {
11542: $versionresult = 'ok';
11543: }
11544: if ($versionresult eq 'ok') {
11545: if (copy($source,$copyfile)) {
11546: print $logfile "\nCopied original source to ".$copyfile."\n";
11547: $output = 'ok';
11548: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11549: push(@{$modified_urls},[$copyfile,$source]);
11550: my $metaoutput =
11551: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11552: unless ($registered_cleanup) {
11553: my $handlers = $r->get_handlers('PerlCleanupHandler');
11554: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11555: $registered_cleanup=1;
11556: }
1.9 raeburn 11557: } else {
11558: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11559: $output = &mt('Failed to copy file to RES space').", $!";
11560: }
11561: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11562: my $inputfile = $filepath.'/'.$file;
11563: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11564: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11565: if ($fullwidth ne '' && $fullheight ne '') {
11566: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11567: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 11568: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11569: system({$args[0]} @args);
1.16 raeburn 11570: chmod(0660, $filepath.'/tn-'.$file);
11571: if (-e $outfile) {
11572: my $copyfile=$targetdir.'/tn-'.$file;
11573: if (copy($outfile,$copyfile)) {
11574: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11575: my $thumb_metaoutput =
11576: &write_metadata($dom,$confname,$formname,
11577: $targetdir,'tn-'.$file,$logfile);
11578: push(@{$modified_urls},[$copyfile,$outfile]);
11579: unless ($registered_cleanup) {
11580: my $handlers = $r->get_handlers('PerlCleanupHandler');
11581: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11582: $registered_cleanup=1;
11583: }
1.16 raeburn 11584: } else {
11585: print $logfile "\nUnable to write ".$copyfile.
11586: ':'.$!."\n";
11587: }
11588: }
1.9 raeburn 11589: }
11590: }
11591: }
11592: } else {
11593: $output = $versionresult;
11594: }
11595: }
11596: return ($output,$logourl);
11597: }
11598:
11599: sub logo_versioning {
11600: my ($targetdir,$file,$logfile) = @_;
11601: my $target = $targetdir.'/'.$file;
11602: my ($maxversion,$fn,$extn,$output);
11603: $maxversion = 0;
11604: if ($file =~ /^(.+)\.(\w+)$/) {
11605: $fn=$1;
11606: $extn=$2;
11607: }
11608: opendir(DIR,$targetdir);
11609: while (my $filename=readdir(DIR)) {
11610: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11611: $maxversion=($1>$maxversion)?$1:$maxversion;
11612: }
11613: }
11614: $maxversion++;
11615: print $logfile "\nCreating old version ".$maxversion."\n";
11616: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11617: if (copy($target,$copyfile)) {
11618: print $logfile "Copied old target to ".$copyfile."\n";
11619: $copyfile=$copyfile.'.meta';
11620: if (copy($target.'.meta',$copyfile)) {
11621: print $logfile "Copied old target metadata to ".$copyfile."\n";
11622: $output = 'ok';
11623: } else {
11624: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11625: $output = &mt('Failed to copy old meta').", $!, ";
11626: }
11627: } else {
11628: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11629: $output = &mt('Failed to copy old target').", $!, ";
11630: }
11631: return $output;
11632: }
11633:
11634: sub write_metadata {
11635: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11636: my (%metadatafields,%metadatakeys,$output);
11637: $metadatafields{'title'}=$formname;
11638: $metadatafields{'creationdate'}=time;
11639: $metadatafields{'lastrevisiondate'}=time;
11640: $metadatafields{'copyright'}='public';
11641: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11642: $env{'user.domain'};
11643: $metadatafields{'authorspace'}=$confname.':'.$dom;
11644: $metadatafields{'domain'}=$dom;
11645: {
11646: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11647: my $mfh;
1.160.6.88 raeburn 11648: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 11649: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11650: unless ($_=~/\./) {
11651: my $unikey=$_;
11652: $unikey=~/^([A-Za-z]+)/;
11653: my $tag=$1;
11654: $tag=~tr/A-Z/a-z/;
11655: print $mfh "\n\<$tag";
11656: foreach (split(/\,/,$metadatakeys{$unikey})) {
11657: my $value=$metadatafields{$unikey.'.'.$_};
11658: $value=~s/\"/\'\'/g;
11659: print $mfh ' '.$_.'="'.$value.'"';
11660: }
11661: print $mfh '>'.
11662: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11663: .'</'.$tag.'>';
11664: }
11665: }
11666: $output = 'ok';
11667: print $logfile "\nWrote metadata";
11668: close($mfh);
11669: } else {
11670: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11671: $output = &mt('Could not write metadata');
11672: }
11673: }
1.155 raeburn 11674: return $output;
11675: }
11676:
11677: sub notifysubscribed {
11678: foreach my $targetsource (@{$modified_urls}){
11679: next unless (ref($targetsource) eq 'ARRAY');
11680: my ($target,$source)=@{$targetsource};
11681: if ($source ne '') {
1.160.6.88 raeburn 11682: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11683: print $logfh "\nCleanup phase: Notifications\n";
11684: my @subscribed=&subscribed_hosts($target);
11685: foreach my $subhost (@subscribed) {
11686: print $logfh "\nNotifying host ".$subhost.':';
11687: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11688: print $logfh $reply;
11689: }
11690: my @subscribedmeta=&subscribed_hosts("$target.meta");
11691: foreach my $subhost (@subscribedmeta) {
11692: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11693: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11694: $subhost);
11695: print $logfh $reply;
11696: }
11697: print $logfh "\n============ Done ============\n";
1.160 raeburn 11698: close($logfh);
1.155 raeburn 11699: }
11700: }
11701: }
11702: return OK;
11703: }
11704:
11705: sub subscribed_hosts {
11706: my ($target) = @_;
11707: my @subscribed;
1.160.6.88 raeburn 11708: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11709: while (my $subline=<$fh>) {
11710: if ($subline =~ /^($match_lonid):/) {
11711: my $host = $1;
11712: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11713: unless (grep(/^\Q$host\E$/,@subscribed)) {
11714: push(@subscribed,$host);
11715: }
11716: }
11717: }
11718: }
11719: }
11720: return @subscribed;
1.9 raeburn 11721: }
11722:
11723: sub check_switchserver {
11724: my ($dom,$confname) = @_;
11725: my ($allowed,$switchserver);
11726: my $home = &Apache::lonnet::homeserver($confname,$dom);
11727: if ($home eq 'no_host') {
11728: $home = &Apache::lonnet::domain($dom,'primary');
11729: }
11730: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11731: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11732: if (!$allowed) {
1.160.6.11 raeburn 11733: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11734: }
11735: return $switchserver;
11736: }
11737:
1.1 raeburn 11738: sub modify_quotas {
1.160.6.30 raeburn 11739: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11740: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 11741: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 11742: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11743: $validationfieldsref);
1.86 raeburn 11744: if ($action eq 'quotas') {
11745: $context = 'tools';
1.160.6.26 raeburn 11746: } else {
1.86 raeburn 11747: $context = $action;
11748: }
11749: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 11750: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 11751: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11752: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11753: %titles = &courserequest_titles();
11754: $toolregexp = join('|',@usertools);
11755: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 11756: $confname = $dom.'-domainconfig';
11757: my $servadm = $r->dir_config('lonAdmEMail');
11758: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 11759: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11760: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 11761: } elsif ($context eq 'requestauthor') {
11762: @usertools = ('author');
11763: %titles = &authorrequest_titles();
1.86 raeburn 11764: } else {
1.160.6.118.2 10(raebu 11765:22): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 11766: %titles = &tool_titles();
1.86 raeburn 11767: }
1.160.6.27 raeburn 11768: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11769: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11770: foreach my $key (keys(%env)) {
1.101 raeburn 11771: if ($context eq 'requestcourses') {
11772: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11773: my $item = $1;
11774: my $type = $2;
11775: if ($type =~ /^limit_(.+)/) {
11776: $limithash{$item}{$1} = $env{$key};
11777: } else {
11778: $confhash{$item}{$type} = $env{$key};
11779: }
11780: }
1.160.6.5 raeburn 11781: } elsif ($context eq 'requestauthor') {
11782: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11783: $confhash{$1} = $env{$key};
11784: }
1.101 raeburn 11785: } else {
1.86 raeburn 11786: if ($key =~ /^form\.quota_(.+)$/) {
11787: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 11788: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11789: $confhash{'authorquota'}{$1} = $env{$key};
11790: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11791: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11792: }
1.72 raeburn 11793: }
11794: }
1.160.6.5 raeburn 11795: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 11796: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11797: @approvalnotify = sort(@approvalnotify);
11798: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 11799: my @crstypes = ('official','unofficial','community','textbook');
11800: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11801: foreach my $type (@hasuniquecode) {
11802: if (grep(/^\Q$type\E$/,@crstypes)) {
11803: $confhash{'uniquecode'}{$type} = 1;
11804: }
11805: }
1.160.6.46 raeburn 11806: my (%newbook,%allpos);
1.160.6.30 raeburn 11807: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11808: foreach my $type ('textbooks','templates') {
11809: @{$allpos{$type}} = ();
11810: my $invalid;
11811: if ($type eq 'textbooks') {
11812: $invalid = &mt('Invalid LON-CAPA course for textbook');
11813: } else {
11814: $invalid = &mt('Invalid LON-CAPA course for template');
11815: }
11816: if ($env{'form.'.$type.'_addbook'}) {
11817: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11818: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11819: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11820: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11821: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11822: } else {
11823: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11824: my $position = $env{'form.'.$type.'_addbook_pos'};
11825: $position =~ s/\D+//g;
11826: if ($position ne '') {
11827: $allpos{$type}[$position] = $newbook{$type};
11828: }
1.160.6.30 raeburn 11829: }
1.160.6.46 raeburn 11830: } else {
11831: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 11832: }
11833: }
1.160.6.46 raeburn 11834: }
1.160.6.30 raeburn 11835: }
1.102 raeburn 11836: if (ref($domconfig{$action}) eq 'HASH') {
11837: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11838: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11839: $changes{'notify'}{'approval'} = 1;
11840: }
11841: } else {
1.144 raeburn 11842: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11843: $changes{'notify'}{'approval'} = 1;
11844: }
11845: }
1.160.6.30 raeburn 11846: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11847: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11848: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11849: unless ($confhash{'uniquecode'}{$crstype}) {
11850: $changes{'uniquecode'} = 1;
11851: }
11852: }
11853: unless ($changes{'uniquecode'}) {
11854: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11855: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11856: $changes{'uniquecode'} = 1;
11857: }
11858: }
11859: }
11860: } else {
11861: $changes{'uniquecode'} = 1;
11862: }
11863: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11864: $changes{'uniquecode'} = 1;
11865: }
11866: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11867: foreach my $type ('textbooks','templates') {
11868: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11869: my %deletions;
11870: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11871: if (@todelete) {
11872: map { $deletions{$_} = 1; } @todelete;
11873: }
11874: my %imgdeletions;
11875: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11876: if (@todeleteimages) {
11877: map { $imgdeletions{$_} = 1; } @todeleteimages;
11878: }
11879: my $maxnum = $env{'form.'.$type.'_maxnum'};
11880: for (my $i=0; $i<=$maxnum; $i++) {
11881: my $itemid = $env{'form.'.$type.'_id_'.$i};
11882: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11883: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11884: if ($deletions{$key}) {
11885: if ($domconfig{$action}{$type}{$key}{'image'}) {
11886: #FIXME need to obsolete item in RES space
11887: }
11888: next;
11889: } else {
11890: my $newpos = $env{'form.'.$itemid};
11891: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 11892: foreach my $item ('subject','title','publisher','author') {
11893: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11894: ($type eq 'templates'));
1.160.6.46 raeburn 11895: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11896: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11897: $changes{$type}{$key} = 1;
11898: }
11899: }
11900: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 11901: }
1.160.6.46 raeburn 11902: if ($imgdeletions{$key}) {
11903: $changes{$type}{$key} = 1;
11904: #FIXME need to obsolete item in RES space
11905: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11906: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 11907: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11908: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11909: } else {
11910: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11911: $cdom,$cnum,$type,$configuserok,
11912: $switchserver,$author_ok);
11913: if ($imgurl) {
11914: $confhash{$type}{$key}{'image'} = $imgurl;
11915: $changes{$type}{$key} = 1;
11916: }
11917: if ($error) {
11918: &Apache::lonnet::logthis($error);
11919: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11920: }
1.160.6.46 raeburn 11921: }
11922: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11923: $confhash{$type}{$key}{'image'} =
11924: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 11925: }
11926: }
11927: }
11928: }
11929: }
11930: }
1.102 raeburn 11931: } else {
1.144 raeburn 11932: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11933: $changes{'notify'}{'approval'} = 1;
11934: }
1.160.6.30 raeburn 11935: if (ref($confhash{'uniquecode'} eq 'HASH')) {
11936: $changes{'uniquecode'} = 1;
11937: }
11938: }
11939: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11940: foreach my $type ('textbooks','templates') {
11941: if ($newbook{$type}) {
11942: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 11943: foreach my $item ('subject','title','publisher','author') {
11944: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11945: ($type eq 'template'));
1.160.6.46 raeburn 11946: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11947: if ($env{'form.'.$type.'_addbook_'.$item}) {
11948: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11949: }
11950: }
11951: if ($type eq 'textbooks') {
11952: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11953: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 11954: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11955: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11956: } else {
11957: my ($imageurl,$error) =
11958: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11959: $configuserok,$switchserver,$author_ok);
11960: if ($imageurl) {
11961: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11962: }
11963: if ($error) {
11964: &Apache::lonnet::logthis($error);
11965: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11966: }
1.160.6.46 raeburn 11967: }
11968: }
1.160.6.30 raeburn 11969: }
11970: }
1.160.6.46 raeburn 11971: if (@{$allpos{$type}} > 0) {
11972: my $idx = 0;
11973: foreach my $item (@{$allpos{$type}}) {
11974: if ($item ne '') {
11975: $confhash{$type}{$item}{'order'} = $idx;
11976: if (ref($domconfig{$action}) eq 'HASH') {
11977: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11978: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11979: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11980: $changes{$type}{$item} = 1;
11981: }
1.160.6.30 raeburn 11982: }
11983: }
11984: }
1.160.6.46 raeburn 11985: $idx ++;
1.160.6.30 raeburn 11986: }
11987: }
11988: }
11989: }
1.160.6.39 raeburn 11990: if (ref($validationitemsref) eq 'ARRAY') {
11991: foreach my $item (@{$validationitemsref}) {
11992: if ($item eq 'fields') {
11993: my @changed;
11994: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11995: if (@{$confhash{'validation'}{$item}} > 0) {
11996: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11997: }
1.160.6.65 raeburn 11998: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11999: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12000: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12001: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12002: $domconfig{'requestcourses'}{'validation'}{$item});
12003: } else {
12004: @changed = @{$confhash{'validation'}{$item}};
12005: }
1.160.6.39 raeburn 12006: } else {
12007: @changed = @{$confhash{'validation'}{$item}};
12008: }
12009: } else {
12010: @changed = @{$confhash{'validation'}{$item}};
12011: }
12012: if (@changed) {
12013: if ($confhash{'validation'}{$item}) {
12014: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12015: } else {
12016: $changes{'validation'}{$item} = &mt('None');
12017: }
12018: }
12019: } else {
12020: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12021: if ($item eq 'markup') {
12022: if ($env{'form.requestcourses_validation_'.$item}) {
12023: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12024: }
12025: }
1.160.6.65 raeburn 12026: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12027: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12028: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12029: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12030: }
12031: } else {
12032: if ($confhash{'validation'}{$item} ne '') {
12033: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12034: }
1.160.6.39 raeburn 12035: }
12036: } else {
12037: if ($confhash{'validation'}{$item} ne '') {
12038: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12039: }
12040: }
12041: }
12042: }
12043: }
12044: if ($env{'form.validationdc'}) {
12045: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 12046: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 12047: if (exists($domcoords{$newval})) {
12048: $confhash{'validation'}{'dc'} = $newval;
12049: }
12050: }
12051: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 12052: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12053: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12054: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12055: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12056: if ($confhash{'validation'}{'dc'} eq '') {
12057: $changes{'validation'}{'dc'} = &mt('None');
12058: } else {
12059: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12060: }
1.160.6.39 raeburn 12061: }
1.160.6.65 raeburn 12062: } elsif ($confhash{'validation'}{'dc'} ne '') {
12063: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 12064: }
12065: } elsif ($confhash{'validation'}{'dc'} ne '') {
12066: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12067: }
12068: } elsif ($confhash{'validation'}{'dc'} ne '') {
12069: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12070: }
1.160.6.65 raeburn 12071: } else {
12072: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12073: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12074: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12075: $changes{'validation'}{'dc'} = &mt('None');
12076: }
12077: }
1.160.6.39 raeburn 12078: }
12079: }
1.102 raeburn 12080: }
12081: } else {
1.86 raeburn 12082: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 12083: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12084: }
1.72 raeburn 12085: foreach my $item (@usertools) {
12086: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12087: my $unset;
1.101 raeburn 12088: if ($context eq 'requestcourses') {
1.104 raeburn 12089: $unset = '0';
12090: if ($type eq '_LC_adv') {
12091: $unset = '';
12092: }
1.101 raeburn 12093: if ($confhash{$item}{$type} eq 'autolimit') {
12094: $confhash{$item}{$type} .= '=';
12095: unless ($limithash{$item}{$type} =~ /\D/) {
12096: $confhash{$item}{$type} .= $limithash{$item}{$type};
12097: }
12098: }
1.160.6.5 raeburn 12099: } elsif ($context eq 'requestauthor') {
12100: $unset = '0';
12101: if ($type eq '_LC_adv') {
12102: $unset = '';
12103: }
1.72 raeburn 12104: } else {
1.101 raeburn 12105: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12106: $confhash{$item}{$type} = 1;
12107: } else {
12108: $confhash{$item}{$type} = 0;
12109: }
1.72 raeburn 12110: }
1.86 raeburn 12111: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 12112: if ($action eq 'requestauthor') {
12113: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12114: $changes{$type} = 1;
12115: }
12116: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12117: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12118: $changes{$item}{$type} = 1;
12119: }
12120: } else {
12121: if ($context eq 'requestcourses') {
1.104 raeburn 12122: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12123: $changes{$item}{$type} = 1;
12124: }
12125: } else {
12126: if (!$confhash{$item}{$type}) {
12127: $changes{$item}{$type} = 1;
12128: }
12129: }
12130: }
12131: } else {
12132: if ($context eq 'requestcourses') {
1.104 raeburn 12133: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12134: $changes{$item}{$type} = 1;
12135: }
1.160.6.5 raeburn 12136: } elsif ($context eq 'requestauthor') {
12137: if ($confhash{$type} ne $unset) {
12138: $changes{$type} = 1;
12139: }
1.72 raeburn 12140: } else {
12141: if (!$confhash{$item}{$type}) {
12142: $changes{$item}{$type} = 1;
12143: }
12144: }
12145: }
1.1 raeburn 12146: }
12147: }
1.160.6.5 raeburn 12148: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12149: if (ref($domconfig{'quotas'}) eq 'HASH') {
12150: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12151: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12152: if (exists($confhash{'defaultquota'}{$key})) {
12153: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12154: $changes{'defaultquota'}{$key} = 1;
12155: }
12156: } else {
12157: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12158: }
12159: }
1.86 raeburn 12160: } else {
12161: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12162: if (exists($confhash{'defaultquota'}{$key})) {
12163: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12164: $changes{'defaultquota'}{$key} = 1;
12165: }
12166: } else {
12167: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12168: }
1.1 raeburn 12169: }
12170: }
1.160.6.20 raeburn 12171: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12172: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12173: if (exists($confhash{'authorquota'}{$key})) {
12174: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12175: $changes{'authorquota'}{$key} = 1;
12176: }
12177: } else {
12178: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12179: }
12180: }
12181: }
1.1 raeburn 12182: }
1.86 raeburn 12183: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12184: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12185: if (ref($domconfig{'quotas'}) eq 'HASH') {
12186: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12187: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12188: $changes{'defaultquota'}{$key} = 1;
12189: }
12190: } else {
12191: if (!exists($domconfig{'quotas'}{$key})) {
12192: $changes{'defaultquota'}{$key} = 1;
12193: }
1.72 raeburn 12194: }
12195: } else {
1.86 raeburn 12196: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12197: }
1.1 raeburn 12198: }
12199: }
1.160.6.20 raeburn 12200: if (ref($confhash{'authorquota'}) eq 'HASH') {
12201: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12202: if (ref($domconfig{'quotas'}) eq 'HASH') {
12203: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12204: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12205: $changes{'authorquota'}{$key} = 1;
12206: }
12207: } else {
12208: $changes{'authorquota'}{$key} = 1;
12209: }
12210: } else {
12211: $changes{'authorquota'}{$key} = 1;
12212: }
12213: }
12214: }
1.1 raeburn 12215: }
1.72 raeburn 12216:
1.160.6.5 raeburn 12217: if ($context eq 'requestauthor') {
12218: $domdefaults{'requestauthor'} = \%confhash;
12219: } else {
12220: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 12221: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 12222: $domdefaults{$key} = $confhash{$key};
12223: }
1.160.6.5 raeburn 12224: }
1.72 raeburn 12225: }
1.160.6.5 raeburn 12226:
1.1 raeburn 12227: my %quotahash = (
1.86 raeburn 12228: $action => { %confhash }
1.1 raeburn 12229: );
12230: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12231: $dom);
12232: if ($putresult eq 'ok') {
12233: if (keys(%changes) > 0) {
1.72 raeburn 12234: my $cachetime = 24*60*60;
12235: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12236: if (ref($lastactref) eq 'HASH') {
12237: $lastactref->{'domdefaults'} = 1;
12238: }
1.1 raeburn 12239: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 12240: unless (($context eq 'requestcourses') ||
12241: ($context eq 'requestauthor')) {
1.86 raeburn 12242: if (ref($changes{'defaultquota'}) eq 'HASH') {
12243: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12244: foreach my $type (@{$types},'default') {
12245: if (defined($changes{'defaultquota'}{$type})) {
12246: my $typetitle = $usertypes->{$type};
12247: if ($type eq 'default') {
12248: $typetitle = $othertitle;
12249: }
1.160.6.28 raeburn 12250: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12251: }
12252: }
1.86 raeburn 12253: $resulttext .= '</ul></li>';
1.72 raeburn 12254: }
1.160.6.20 raeburn 12255: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 12256: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 12257: foreach my $type (@{$types},'default') {
12258: if (defined($changes{'authorquota'}{$type})) {
12259: my $typetitle = $usertypes->{$type};
12260: if ($type eq 'default') {
12261: $typetitle = $othertitle;
12262: }
1.160.6.28 raeburn 12263: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 12264: }
12265: }
12266: $resulttext .= '</ul></li>';
12267: }
1.72 raeburn 12268: }
1.80 raeburn 12269: my %newenv;
1.72 raeburn 12270: foreach my $item (@usertools) {
1.160.6.5 raeburn 12271: my (%haschgs,%inconf);
12272: if ($context eq 'requestauthor') {
12273: %haschgs = %changes;
12274: %inconf = %confhash;
12275: } else {
12276: if (ref($changes{$item}) eq 'HASH') {
12277: %haschgs = %{$changes{$item}};
12278: }
12279: if (ref($confhash{$item}) eq 'HASH') {
12280: %inconf = %{$confhash{$item}};
12281: }
12282: }
12283: if (keys(%haschgs) > 0) {
1.80 raeburn 12284: my $newacc =
12285: &Apache::lonnet::usertools_access($env{'user.name'},
12286: $env{'user.domain'},
1.86 raeburn 12287: $item,'reload',$context);
1.160.6.5 raeburn 12288: if (($context eq 'requestcourses') ||
12289: ($context eq 'requestauthor')) {
1.108 raeburn 12290: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12291: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12292: }
12293: } else {
12294: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12295: $newenv{'environment.availabletools.'.$item} = $newacc;
12296: }
1.80 raeburn 12297: }
1.160.6.5 raeburn 12298: unless ($context eq 'requestauthor') {
12299: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12300: }
1.72 raeburn 12301: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 12302: if ($haschgs{$type}) {
1.72 raeburn 12303: my $typetitle = $usertypes->{$type};
12304: if ($type eq 'default') {
12305: $typetitle = $othertitle;
12306: } elsif ($type eq '_LC_adv') {
12307: $typetitle = 'LON-CAPA Advanced Users';
12308: }
1.160.6.5 raeburn 12309: if ($inconf{$type}) {
1.101 raeburn 12310: if ($context eq 'requestcourses') {
12311: my $cond;
1.160.6.5 raeburn 12312: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12313: if ($1 eq '') {
12314: $cond = &mt('(Automatic processing of any request).');
12315: } else {
12316: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12317: }
12318: } else {
1.160.6.5 raeburn 12319: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12320: }
12321: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 12322: } elsif ($context eq 'requestauthor') {
12323: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12324: $titles{$inconf{$type}},$typetitle);
12325:
1.101 raeburn 12326: } else {
12327: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12328: }
1.72 raeburn 12329: } else {
1.104 raeburn 12330: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 12331: if ($inconf{$type} eq '0') {
1.104 raeburn 12332: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12333: } else {
12334: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12335: }
12336: } else {
12337: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12338: }
1.72 raeburn 12339: }
12340: }
1.26 raeburn 12341: }
1.160.6.5 raeburn 12342: unless ($context eq 'requestauthor') {
12343: $resulttext .= '</ul></li>';
12344: }
1.26 raeburn 12345: }
1.1 raeburn 12346: }
1.160.6.5 raeburn 12347: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12348: if (ref($changes{'notify'}) eq 'HASH') {
12349: if ($changes{'notify'}{'approval'}) {
12350: if (ref($confhash{'notify'}) eq 'HASH') {
12351: if ($confhash{'notify'}{'approval'}) {
12352: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12353: } else {
1.160.6.5 raeburn 12354: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12355: }
12356: }
12357: }
12358: }
12359: }
1.160.6.30 raeburn 12360: if ($action eq 'requestcourses') {
12361: my @offon = ('off','on');
12362: if ($changes{'uniquecode'}) {
12363: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12364: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12365: $resulttext .= '<li>'.
12366: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12367: '</li>';
12368: } else {
12369: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12370: '</li>';
12371: }
12372: }
1.160.6.46 raeburn 12373: foreach my $type ('textbooks','templates') {
12374: if (ref($changes{$type}) eq 'HASH') {
12375: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12376: foreach my $key (sort(keys(%{$changes{$type}}))) {
12377: my %coursehash = &Apache::lonnet::coursedescription($key);
12378: my $coursetitle = $coursehash{'description'};
12379: my $position = $confhash{$type}{$key}{'order'} + 1;
12380: $resulttext .= '<li>';
1.160.6.47 raeburn 12381: foreach my $item ('subject','title','publisher','author') {
12382: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12383: ($type eq 'templates'));
1.160.6.46 raeburn 12384: my $name = $item.':';
12385: $name =~ s/^(\w)/\U$1/;
12386: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12387: }
12388: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12389: if ($type eq 'textbooks') {
12390: if ($confhash{$type}{$key}{'image'}) {
12391: $resulttext .= ' '.&mt('Image: [_1]',
12392: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12393: ' alt="Textbook cover" />').'<br />';
12394: }
12395: }
12396: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 12397: }
1.160.6.46 raeburn 12398: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 12399: }
12400: }
1.160.6.39 raeburn 12401: if (ref($changes{'validation'}) eq 'HASH') {
12402: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12403: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12404: foreach my $item (@{$validationitemsref}) {
12405: if (exists($changes{'validation'}{$item})) {
12406: if ($item eq 'markup') {
12407: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12408: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12409: } else {
12410: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12411: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12412: }
12413: }
12414: }
12415: if (exists($changes{'validation'}{'dc'})) {
12416: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12417: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12418: }
12419: }
12420: }
1.160.6.30 raeburn 12421: }
1.1 raeburn 12422: $resulttext .= '</ul>';
1.80 raeburn 12423: if (keys(%newenv)) {
12424: &Apache::lonnet::appenv(\%newenv);
12425: }
1.1 raeburn 12426: } else {
1.86 raeburn 12427: if ($context eq 'requestcourses') {
12428: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 12429: } elsif ($context eq 'requestauthor') {
12430: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12431: } else {
1.90 weissno 12432: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12433: }
1.1 raeburn 12434: }
12435: } else {
1.11 albertel 12436: $resulttext = '<span class="LC_error">'.
12437: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12438: }
1.160.6.30 raeburn 12439: if ($errors) {
12440: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12441: '<ul>'.$errors.'</ul></p>';
12442: }
1.3 raeburn 12443: return $resulttext;
1.1 raeburn 12444: }
12445:
1.160.6.30 raeburn 12446: sub process_textbook_image {
1.160.6.46 raeburn 12447: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 12448: my $filename = $env{'form.'.$caller.'.filename'};
12449: my ($error,$url);
12450: my ($width,$height) = (50,50);
12451: if ($configuserok eq 'ok') {
12452: if ($switchserver) {
12453: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12454: $switchserver);
12455: } elsif ($author_ok eq 'ok') {
12456: my ($result,$imageurl) =
12457: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 12458: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 12459: if ($result eq 'ok') {
12460: $url = $imageurl;
12461: } else {
12462: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12463: }
12464: } else {
12465: $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);
12466: }
12467: } else {
12468: $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);
12469: }
12470: return ($url,$error);
12471: }
12472:
1.160.6.118.2 1(raebur 12473:1): sub modify_ltitools {
12474:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12475:1): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12476:1): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12477:1): my $confname = $dom.'-domainconfig';
12478:1): my $servadm = $r->dir_config('lonAdmEMail');
12479:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12480:1): my (%posslti,%possfield);
12481:1): my @courseroles = ('cc','in','ta','ep','st');
12482:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12483:1): map { $posslti{$_} = 1; } @ltiroles;
12484:1): my @allfields = ('fullname','firstname','lastname','email','user','roles');
12485:1): map { $possfield{$_} = 1; } @allfields;
12486:1): my %lt = <itools_names();
12487:1): if ($env{'form.ltitools_add'}) {
12488:1): my $title = $env{'form.ltitools_add_title'};
12489:1): $title =~ s/(`)/'/g;
12490:1): ($newid,my $error) = &get_ltitools_id($dom,$title);
12491:1): if ($newid) {
12492:1): my $position = $env{'form.ltitools_add_pos'};
12493:1): $position =~ s/\D+//g;
12494:1): if ($position ne '') {
12495:1): $allpos[$position] = $newid;
12496:1): }
12497:1): $changes{$newid} = 1;
12498:1): foreach my $item ('title','url','key','secret','lifetime') {
12499:1): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
12500:1): if ($item eq 'lifetime') {
12501:1): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12502:1): }
12503:1): if ($env{'form.ltitools_add_'.$item}) {
12504:1): if (($item eq 'key') || ($item eq 'secret')) {
12505:1): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12506:1): } else {
12507:1): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12508:1): }
12509:1): }
12510:1): }
12511:1): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12512:1): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12513:1): }
12514:1): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12515:1): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12516:1): }
12517:1): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12518:1): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12519:1): } else {
12520:1): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12521:1): }
12522:1): foreach my $item ('width','height','linktext','explanation') {
12523:1): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12524:1): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
12525:1): if (($item eq 'width') || ($item eq 'height')) {
12526:1): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12527:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12528:1): }
12529:1): } else {
12530:1): if ($env{'form.ltitools_add_'.$item} ne '') {
12531:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12532:1): }
12533:1): }
12534:1): }
12535:1): if ($env{'form.ltitools_add_target'} eq 'window') {
12536:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12537:1): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12538:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12539:1): } else {
12540:1): $confhash{$newid}{'display'}{'target'} = 'iframe';
12541:1): }
12542:1): if ($env{'form.ltitools_add_image.filename'} ne '') {
12543:1): my ($imageurl,$error) =
12544:1): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
12545:1): $configuserok,$switchserver,$author_ok);
12546:1): if ($imageurl) {
12547:1): $confhash{$newid}{'image'} = $imageurl;
12548:1): }
12549:1): if ($error) {
12550:1): &Apache::lonnet::logthis($error);
12551:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12552:1): }
12553:1): }
12554:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12555:1): foreach my $field (@fields) {
12556:1): if ($possfield{$field}) {
12557:1): if ($field eq 'roles') {
12558:1): foreach my $role (@courseroles) {
12559:1): my $choice = $env{'form.ltitools_add_roles_'.$role};
12560:1): if (($choice ne '') && ($posslti{$choice})) {
12561:1): $confhash{$newid}{'roles'}{$role} = $choice;
12562:1): if ($role eq 'cc') {
12563:1): $confhash{$newid}{'roles'}{'co'} = $choice;
12564:1): }
12565:1): }
12566:1): }
12567:1): } else {
12568:1): $confhash{$newid}{'fields'}{$field} = 1;
12569:1): }
12570:1): }
12571:1): }
12572:1): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12573:1): if ($confhash{$newid}{'fields'}{'user'}) {
12574:1): if ($env{'form.ltitools_userincdom_add'}) {
12575:1): $confhash{$newid}{'incdom'} = 1;
12576:1): }
12577:1): }
12578:1): }
12579:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12580:1): foreach my $item (@courseconfig) {
12581:1): $confhash{$newid}{'crsconf'}{$item} = 1;
12582:1): }
12583:1): if ($env{'form.ltitools_add_custom'}) {
12584:1): my $name = $env{'form.ltitools_add_custom_name'};
12585:1): my $value = $env{'form.ltitools_add_custom_value'};
12586:1): $value =~ s/(`)/'/g;
12587:1): $name =~ s/(`)/'/g;
12588:1): $confhash{$newid}{'custom'}{$name} = $value;
12589:1): }
12590:1): } else {
12591:1): my $error = &mt('Failed to acquire unique ID for new external tool');
12592:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12593:1): }
12594:1): }
12595:1): if (ref($domconfig{$action}) eq 'HASH') {
12596:1): my %deletions;
12597:1): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12598:1): if (@todelete) {
12599:1): map { $deletions{$_} = 1; } @todelete;
12600:1): }
12601:1): my %customadds;
12602:1): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12603:1): if (@newcustom) {
12604:1): map { $customadds{$_} = 1; } @newcustom;
12605:1): }
12606:1): my %imgdeletions;
12607:1): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12608:1): if (@todeleteimages) {
12609:1): map { $imgdeletions{$_} = 1; } @todeleteimages;
12610:1): }
12611:1): my $maxnum = $env{'form.ltitools_maxnum'};
12612:1): for (my $i=0; $i<=$maxnum; $i++) {
12613:1): my $itemid = $env{'form.ltitools_id_'.$i};
12614:1): $itemid =~ s/\D+//g;
12615:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12616:1): if ($deletions{$itemid}) {
12617:1): if ($domconfig{$action}{$itemid}{'image'}) {
12618:1): #FIXME need to obsolete item in RES space
12619:1): }
12620:1): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12621:1): next;
12622:1): } else {
12623:1): my $newpos = $env{'form.ltitools_'.$itemid};
12624:1): $newpos =~ s/\D+//g;
12625:1): foreach my $item ('title','url','lifetime') {
12626:1): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12627:1): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12628:1): $changes{$itemid} = 1;
12629:1): }
12630:1): }
12631:1): foreach my $item ('key','secret') {
12632:1): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12633:1): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12634:1): $changes{$itemid} = 1;
12635:1): }
12636:1): }
12637:1): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12638:1): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12639:1): }
12640:1): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12641:1): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12642:1): }
12643:1): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12644:1): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12645:1): } else {
12646:1): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12647:1): }
12648:1): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12649:1): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12650:1): $changes{$itemid} = 1;
12651:1): }
12652:1): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12653:1): $changes{$itemid} = 1;
12654:1): }
12655:1): foreach my $size ('width','height') {
12656:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12657:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12658:1): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12659:1): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12660:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12661:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12662:1): $changes{$itemid} = 1;
12663:1): }
12664:1): } else {
12665:1): $changes{$itemid} = 1;
12666:1): }
12667:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12668:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12669:1): $changes{$itemid} = 1;
12670:1): }
12671:1): }
12672:1): }
12673:1): foreach my $item ('linktext','explanation') {
12674:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12675:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12676:1): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12677:1): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12678:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12679:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12680:1): $changes{$itemid} = 1;
12681:1): }
12682:1): } else {
12683:1): $changes{$itemid} = 1;
12684:1): }
12685:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12686:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12687:1): $changes{$itemid} = 1;
12688:1): }
12689:1): }
12690:1): }
12691:1): if ($env{'form.ltitools_target_'.$i} eq 'window') {
12692:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12693:1): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12694:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12695:1): } else {
12696:1): $confhash{$itemid}{'display'}{'target'} = 'iframe';
12697:1): }
12698:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12699:1): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12700:1): $changes{$itemid} = 1;
12701:1): }
12702:1): } else {
12703:1): $changes{$itemid} = 1;
12704:1): }
12705:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
12706:1): foreach my $item ('label','title','target','linktext','explanation','append') {
12707:1): if (grep(/^\Q$item\E$/,@courseconfig)) {
12708:1): $confhash{$itemid}{'crsconf'}{$item} = 1;
12709:1): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12710:1): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12711:1): $changes{$itemid} = 1;
12712:1): }
12713:1): } else {
12714:1): $changes{$itemid} = 1;
12715:1): }
12716:1): }
12717:1): }
12718:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12719:1): foreach my $field (@fields) {
12720:1): if ($possfield{$field}) {
12721:1): if ($field eq 'roles') {
12722:1): foreach my $role (@courseroles) {
12723:1): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12724:1): if (($choice ne '') && ($posslti{$choice})) {
12725:1): $confhash{$itemid}{'roles'}{$role} = $choice;
12726:1): if ($role eq 'cc') {
12727:1): $confhash{$itemid}{'roles'}{'co'} = $choice;
12728:1): }
12729:1): }
12730:1): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12731:1): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12732:1): $changes{$itemid} = 1;
12733:1): }
12734:1): } elsif ($confhash{$itemid}{'roles'}{$role}) {
12735:1): $changes{$itemid} = 1;
12736:1): }
12737:1): }
12738:1): } else {
12739:1): $confhash{$itemid}{'fields'}{$field} = 1;
12740:1): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12741:1): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12742:1): $changes{$itemid} = 1;
12743:1): }
12744:1): } else {
12745:1): $changes{$itemid} = 1;
12746:1): }
12747:1): }
12748:1): }
12749:1): }
12750:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12751:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12752:1): if ($env{'form.ltitools_userincdom_'.$i}) {
12753:1): $confhash{$itemid}{'incdom'} = 1;
12754:1): }
12755:1): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12756:1): $changes{$itemid} = 1;
12757:1): }
12758:1): }
12759:1): }
12760:1): $allpos[$newpos] = $itemid;
12761:1): }
12762:1): if ($imgdeletions{$itemid}) {
12763:1): $changes{$itemid} = 1;
12764:1): #FIXME need to obsolete item in RES space
12765:1): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12766:1): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12767:1): $itemid,$configuserok,$switchserver,
12768:1): $author_ok);
12769:1): if ($imgurl) {
12770:1): $confhash{$itemid}{'image'} = $imgurl;
12771:1): $changes{$itemid} = 1;
12772:1): }
12773:1): if ($error) {
12774:1): &Apache::lonnet::logthis($error);
12775:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12776:1): }
12777:1): } elsif ($domconfig{$action}{$itemid}{'image'}) {
12778:1): $confhash{$itemid}{'image'} =
12779:1): $domconfig{$action}{$itemid}{'image'};
12780:1): }
12781:1): if ($customadds{$i}) {
12782:1): my $name = $env{'form.ltitools_custom_name_'.$i};
12783:1): $name =~ s/(`)/'/g;
12784:1): $name =~ s/^\s+//;
12785:1): $name =~ s/\s+$//;
12786:1): my $value = $env{'form.ltitools_custom_value_'.$i};
12787:1): $value =~ s/(`)/'/g;
12788:1): $value =~ s/^\s+//;
12789:1): $value =~ s/\s+$//;
12790:1): if ($name ne '') {
12791:1): $confhash{$itemid}{'custom'}{$name} = $value;
12792:1): $changes{$itemid} = 1;
12793:1): }
12794:1): }
12795:1): my %customdels;
12796:1): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12797:1): if (@customdeletions) {
12798:1): $changes{$itemid} = 1;
12799:1): }
12800:1): map { $customdels{$_} = 1; } @customdeletions;
12801:1): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12802:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12803:1): unless ($customdels{$key}) {
12804:1): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12805:1): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12806:1): }
12807:1): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12808:1): $changes{$itemid} = 1;
12809:1): }
12810:1): }
12811:1): }
12812:1): }
12813:1): unless ($changes{$itemid}) {
12814:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12815:1): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12816:1): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12817:1): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12818:1): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12819:1): $changes{$itemid} = 1;
12820:1): last;
12821:1): }
12822:1): }
12823:1): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12824:1): $changes{$itemid} = 1;
12825:1): }
12826:1): }
12827:1): last if ($changes{$itemid});
12828:1): }
12829:1): }
12830:1): }
12831:1): }
12832:1): }
12833:1): if (@allpos > 0) {
12834:1): my $idx = 0;
12835:1): foreach my $itemid (@allpos) {
12836:1): if ($itemid ne '') {
12837:1): $confhash{$itemid}{'order'} = $idx;
12838:1): if (ref($domconfig{$action}) eq 'HASH') {
12839:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12840:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12841:1): $changes{$itemid} = 1;
12842:1): }
12843:1): }
12844:1): }
12845:1): $idx ++;
12846:1): }
12847:1): }
12848:1): }
12849:1): my %ltitoolshash = (
12850:1): $action => { %confhash }
12851:1): );
12852:1): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12853:1): $dom);
12854:1): if ($putresult eq 'ok') {
12855:1): my %ltienchash = (
12856:1): $action => { %encconfig }
12857:1): );
12858:1): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
12859:1): if (keys(%changes) > 0) {
12860:1): my $cachetime = 24*60*60;
12861:1): my %ltiall = %confhash;
12862:1): foreach my $id (keys(%ltiall)) {
12863:1): if (ref($encconfig{$id}) eq 'HASH') {
12864:1): foreach my $item ('key','secret') {
12865:1): $ltiall{$id}{$item} = $encconfig{$id}{$item};
12866:1): }
12867:1): }
12868:1): }
12869:1): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
12870:1): if (ref($lastactref) eq 'HASH') {
12871:1): $lastactref->{'ltitools'} = 1;
12872:1): }
12873:1): $resulttext = &mt('Changes made:').'<ul>';
12874:1): my %bynum;
12875:1): foreach my $itemid (sort(keys(%changes))) {
12876:1): my $position = $confhash{$itemid}{'order'};
12877:1): $bynum{$position} = $itemid;
12878:1): }
12879:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12880:1): my $itemid = $bynum{$pos};
12881:1): if (ref($confhash{$itemid}) ne 'HASH') {
12882:1): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12883:1): } else {
12884:1): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12885:1): if ($confhash{$itemid}{'image'}) {
12886:1): $resulttext .= ' '.
12887:1): '<img src="'.$confhash{$itemid}{'image'}.'"'.
12888:1): ' alt="'.&mt('Tool Provider icon').'" />';
12889:1): }
12890:1): $resulttext .= '</li><ul>';
12891:1): my $position = $pos + 1;
12892:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12893:1): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
12894:1): if ($confhash{$itemid}{$item} ne '') {
12895:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12896:1): }
12897:1): }
12898:1): if ($encconfig{$itemid}{'key'} ne '') {
12899:1): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12900:1): }
12901:1): if ($encconfig{$itemid}{'secret'} ne '') {
12902:1): $resulttext .= '<li>'.$lt{'secret'}.': ';
12903:1): my $num = length($encconfig{$itemid}{'secret'});
12904:1): $resulttext .= ('*'x$num).'</li>';
12905:1): }
12906:1): $resulttext .= '<li>'.&mt('Configurable in course:');
12907:1): my @possconfig = ('label','title','target','linktext','explanation','append');
12908:1): my $numconfig = 0;
12909:1): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12910:1): foreach my $item (@possconfig) {
12911:1): if ($confhash{$itemid}{'crsconf'}{$item}) {
12912:1): $numconfig ++;
12913:1): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
12914:1): }
12915:1): }
12916:1): }
12917:1): if (!$numconfig) {
12918:1): $resulttext .= &mt('None');
12919:1): }
12920:1): $resulttext .= '</li>';
12921:1): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12922:1): my $displaylist;
12923:1): if ($confhash{$itemid}{'display'}{'target'}) {
12924:1): $displaylist = &mt('Display target').': '.
12925:1): $confhash{$itemid}{'display'}{'target'}.',';
12926:1): }
12927:1): foreach my $size ('width','height') {
12928:1): if ($confhash{$itemid}{'display'}{$size}) {
12929:1): $displaylist .= (' 'x2).$lt{$size}.': '.
12930:1): $confhash{$itemid}{'display'}{$size}.',';
12931:1): }
12932:1): }
12933:1): if ($displaylist) {
12934:1): $displaylist =~ s/,$//;
12935:1): $resulttext .= '<li>'.$displaylist.'</li>';
12936:1): }
12937:1): foreach my $item ('linktext','explanation') {
12938:1): if ($confhash{$itemid}{'display'}{$item}) {
12939:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12940:1): }
12941:1): }
12942:1): }
12943:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12944:1): my $fieldlist;
12945:1): foreach my $field (@allfields) {
12946:1): if ($confhash{$itemid}{'fields'}{$field}) {
12947:1): $fieldlist .= (' 'x2).$lt{$field}.',';
12948:1): }
12949:1): }
12950:1): if ($fieldlist) {
12951:1): $fieldlist =~ s/,$//;
12952:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12953:1): if ($confhash{$itemid}{'incdom'}) {
12954:1): $fieldlist .= ' ('.&mt('username:domain').')';
12955:1): } else {
12956:1): $fieldlist .= ' ('.&mt('username').')';
12957:1): }
12958:1): }
12959:1): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12960:1): }
12961:1): }
12962:1): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12963:1): my $rolemaps;
12964:1): foreach my $role (@courseroles) {
12965:1): if ($confhash{$itemid}{'roles'}{$role}) {
12966:1): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12967:1): $confhash{$itemid}{'roles'}{$role}.',';
12968:1): }
12969:1): }
12970:1): if ($rolemaps) {
12971:1): $rolemaps =~ s/,$//;
12972:1): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12973:1): }
12974:1): }
12975:1): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12976:1): my $customlist;
12977:1): if (keys(%{$confhash{$itemid}{'custom'}})) {
12978:1): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12979:1): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12980:1): }
12981:1): }
12982:1): if ($customlist) {
12983:1): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
12984:1): }
12985:1): }
12986:1): $resulttext .= '</ul></li>';
12987:1): }
12988:1): }
12989:1): $resulttext .= '</ul>';
12990:1): } else {
12991:1): $resulttext = &mt('No changes made.');
12992:1): }
12993:1): } else {
12994:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12995:1): }
12996:1): if ($errors) {
12997:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12998:1): $errors.'</ul>';
12999:1): }
13000:1): return $resulttext;
13001:1): }
13002:1):
13003:1): sub process_ltitools_image {
13004:1): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
13005:1): my $filename = $env{'form.'.$caller.'.filename'};
13006:1): my ($error,$url);
13007:1): my ($width,$height) = (21,21);
13008:1): if ($configuserok eq 'ok') {
13009:1): if ($switchserver) {
13010:1): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
13011:1): $switchserver);
13012:1): } elsif ($author_ok eq 'ok') {
13013:1): my ($result,$imageurl,$madethumb) =
13014:1): &publishlogo($r,'upload',$caller,$dom,$confname,
13015:1): "ltitools/$itemid/icon",$width,$height);
13016:1): if ($result eq 'ok') {
13017:1): if ($madethumb) {
13018:1): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
13019:1): my $imagethumb = "$path/tn-".$imagefile;
13020:1): $url = $imagethumb;
13021:1): } else {
13022:1): $url = $imageurl;
13023:1): }
13024:1): } else {
13025:1): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13026:1): }
13027:1): } else {
13028:1): $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);
13029:1): }
13030:1): } else {
13031:1): $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);
13032:1): }
13033:1): return ($url,$error);
13034:1): }
13035:1):
13036:1): sub get_ltitools_id {
13037:1): my ($cdom,$title) = @_;
13038:1): # get lock on ltitools db
13039:1): my $lockhash = {
13040:1): lock => $env{'user.name'}.
13041:1): ':'.$env{'user.domain'},
13042:1): };
13043:1): my $tries = 0;
13044:1): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13045:1): my ($id,$error);
13046:1):
13047:1): while (($gotlock ne 'ok') && ($tries<10)) {
13048:1): $tries ++;
13049:1): sleep (0.1);
13050:1): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
13051:1): }
13052:1): if ($gotlock eq 'ok') {
13053:1): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
13054:1): if ($currids{'lock'}) {
13055:1): delete($currids{'lock'});
13056:1): if (keys(%currids)) {
13057:1): my @curr = sort { $a <=> $b } keys(%currids);
13058:1): if ($curr[-1] =~ /^\d+$/) {
13059:1): $id = 1 + $curr[-1];
13060:1): }
13061:1): } else {
13062:1): $id = 1;
13063:1): }
13064:1): if ($id) {
13065:1): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
13066:1): $error = 'nostore';
13067:1): }
13068:1): } else {
13069:1): $error = 'nonumber';
13070:1): }
13071:1): }
13072:1): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13073:1): } else {
13074:1): $error = 'nolock';
13075:1): }
13076:1): return ($id,$error);
13077:1): }
13078:1):
5(raebur 13079:2): sub modify_lti {
13080:2): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13081:2): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13082:2): my (%encconfig,$errors,$resulttext);
13083:2):
13084:2): my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
13085:2): $newltisec{'private'}{'keys'} = [];
13086:2): $newltisec{'encrypt'} = {};
13087:2): $newltisec{'rules'} = {};
13088:2): $newltisec{'linkprot'} = {};
13089:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
13090:2): %currltisec = %{$domconfig{'ltisec'}};
13091:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13092:2): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
13093:2): unless ($id =~ /^\d+$/) {
13094:2): delete($currltisec{'linkprot'}{$id});
13095:2): }
13096:2): }
13097:2): }
13098:2): if (ref($currltisec{'private'}) eq 'HASH') {
13099:2): if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
13100:2): $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
13101:2): map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
13102:2): }
13103:2): }
13104:2): }
13105:2): foreach my $item ('crs','dom') {
13106:2): my $formelement = 'form.ltisec_'.$item.'linkprot';
13107:2): if ($env{$formelement}) {
13108:2): $newltisec{'encrypt'}{$item} = 1;
13109:2): if (ref($currltisec{'encrypt'}) eq 'HASH') {
13110:2): unless ($currltisec{'encrypt'}{$item}) {
13111:2): $secchanges{'encrypt'} = 1;
13112:2): }
13113:2): } else {
13114:2): $secchanges{'encrypt'} = 1;
13115:2): }
13116:2): } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
13117:2): if ($currltisec{'encrypt'}{$item}) {
13118:2): $secchanges{'encrypt'} = 1;
13119:2): }
13120:2): }
13121:2): }
13122:2): unless (exists($currltisec{'rules'})) {
13123:2): $currltisec{'rules'} = {};
13124:2): }
13125:2): &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
13126:2):
13127:2): my @ids=&Apache::lonnet::current_machine_ids();
13128:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
13129:2):
13130:2): foreach my $hostid (keys(%servers)) {
13131:2): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13132:2): my $newkey;
13133:2): my $keyitem = 'form.ltisec_privkey_'.$hostid;
13134:2): if (exists($env{$keyitem})) {
13135:2): $env{$keyitem} =~ s/(`)/'/g;
13136:2): if ($keyset{$hostid}) {
13137:2): if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
13138:2): if ($env{$keyitem} ne '') {
13139:2): $secchanges{'private'} = 1;
13140:2): $newkeyset{$hostid} = $env{$keyitem};
13141:2): }
13142:2): }
13143:2): } elsif ($env{$keyitem} ne '') {
13144:2): unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
13145:2): push(@{$newltisec{'private'}{'keys'}},$hostid);
13146:2): }
13147:2): $secchanges{'private'} = 1;
13148:2): $newkeyset{$hostid} = $env{$keyitem};
13149:2): }
13150:2): }
13151:2): }
13152:2): }
13153:2):
13154:2): my (%linkprotchg,$linkprotoutput,$is_home);
13155:2): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13156:2): \%linkprotchg,'domain');
13157:2): my $home = &Apache::lonnet::domain($dom,'primary');
13158:2): unless (($home eq 'no_host') || ($home eq '')) {
13159:2): my @ids=&Apache::lonnet::current_machine_ids();
13160:2): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13161:2): }
13162:2):
13163:2): if (keys(%linkprotchg)) {
13164:2): $secchanges{'linkprot'} = 1;
13165:2): my %oldlinkprot;
13166:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13167:2): %oldlinkprot = %{$currltisec{'linkprot'}};
13168:2): }
13169:2): foreach my $id (keys(%linkprotchg)) {
13170:2): if (ref($linkprotchg{$id}) eq 'HASH') {
13171:2): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13172:2): if (($inner eq 'secret') || ($inner eq 'key')) {
13173:2): if ($is_home) {
13174:2): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13175:2): }
13176:2): }
13177:2): }
13178:2): } else {
13179:2): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
13180:2): }
13181:2): }
13182:2): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13183:2): if (keys(%linkprotchg)) {
13184:2): %{$newltisec{'linkprot'}} = %linkprotchg;
13185:2): }
13186:2): }
13187:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13188:2): foreach my $id (%{$currltisec{'linkprot'}}) {
13189:2): next if ($id !~ /^\d+$/);
13190:2): unless (exists($linkprotchg{$id})) {
13191:2): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13192:2): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13193:2): if (($inner eq 'secret') || ($inner eq 'key')) {
13194:2): if ($is_home) {
13195:2): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13196:2): }
13197:2): } else {
13198:2): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13199:2): }
13200:2): }
13201:2): } else {
13202:2): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13203:2): }
13204:2): }
13205:2): }
13206:2): }
13207:2): if ($proterror) {
13208:2): $errors .= '<li>'.$proterror.'</li>';
13209:2): }
13210:2):
6(raebur 13211:2): my ($putresult,%keystore);
5(raebur 13212:2): if (keys(%secchanges)) {
13213:2): my %ltienchash;
13214:2): my %ltihash = (
13215:2): 'ltisec' => { %newltisec }
13216:2): );
13217:2): $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
13218:2): if ($putresult eq 'ok') {
13219:2): if ($secchanges{'private'}) {
13220:2): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13221:2): foreach my $hostid (keys(%newkeyset)) {
13222:2): my $storehash = {
13223:2): key => $newkeyset{$hostid},
13224:2): who => $env{'user.name'}.':'.$env{'user.domain'},
13225:2): };
13226:2): $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
13227:2): $dom,$hostid);
13228:2): }
13229:2): }
13230:2): if (ref($lastactref) eq 'HASH') {
13231:2): if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
13232:2): $lastactref->{'domdefaults'} = 1;
13233:2): }
13234:2): }
13235:2): if (($secchanges{'linkprot'}) && ($is_home)) {
13236:2): my %ltienchash = (
13237:2): 'linkprot' => { %newltienc }
13238:2): );
13239:2): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13240:2): }
13241:2): }
13242:2): } else {
13243:2): return &mt('No changes made.');
13244:2): }
13245:2): if ($putresult eq 'ok') {
13246:2): $resulttext = &mt('Changes made:').'<ul>';
13247:2): foreach my $item (keys(%secchanges)) {
13248:2): if ($item eq 'encrypt') {
13249:2): my %encrypted = (
13250:2): crs => {
13251:2): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13252:2): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13253:2): },
13254:2): dom => {
13255:2): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13256:2): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13257:2): },
13258:2): );
13259:2): foreach my $type ('crs','dom') {
13260:2): my $shown = $encrypted{$type}{'off'};
13261:2): if (ref($newltisec{$item}) eq 'HASH') {
13262:2): if ($newltisec{$item}{$type}) {
13263:2): $shown = $encrypted{$type}{'on'};
13264:2): }
13265:2): }
13266:2): $resulttext .= '<li>'.$shown.'</li>';
13267:2): }
13268:2): } elsif ($item eq 'rules') {
13269:2): my %titles = &Apache::lonlocal::texthash(
13270:2): min => 'Minimum password length',
13271:2): max => 'Maximum password length',
13272:2): chars => 'Required characters',
13273:2): );
13274:2): foreach my $rule ('min','max') {
13275:2): if ($newltisec{rules}{$rule} eq '') {
13276:2): if ($rule eq 'min') {
13277:2): $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13278:2): ' '.&mt('Default of [_1] will be used',
13279:2): $Apache::lonnet::passwdmin).'</li>';
13280:2): } else {
13281:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13282:2): }
13283:2): } else {
13284:2): $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
13285:2): }
13286:2): }
13287:2): if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
13288:2): if (@{$newltisec{'rules'}{'chars'}} > 0) {
13289:2): my %rulenames = &Apache::lonlocal::texthash(
13290:2): uc => 'At least one upper case letter',
13291:2): lc => 'At least one lower case letter',
13292:2): num => 'At least one number',
13293:2): spec => 'At least one non-alphanumeric',
13294:2): );
13295:2): my $needed = '<ul><li>'.
13296:2): join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
13297:2): '</li></ul>';
13298:2): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13299:2): } else {
13300:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13301:2): }
13302:2): } else {
13303:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13304:2): }
13305:2): } elsif ($item eq 'private') {
13306:2): if (keys(%newkeyset)) {
13307:2): foreach my $hostid (sort(keys(%newkeyset))) {
13308:2): if ($keystore{$hostid} eq 'ok') {
13309:2): $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13310:2): }
13311:2): }
13312:2): }
13313:2): } elsif ($item eq 'linkprot') {
13314:2): $resulttext .= $linkprotoutput;
13315:2): }
13316:2): }
13317:2): $resulttext .= '</ul>';
13318:2): } else {
13319:2): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13320:2): }
13321:2): if ($errors) {
13322:2): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13323:2): $errors.'</ul>';
13324:2): }
13325:2): return $resulttext;
13326:2): }
13327:2):
1.3 raeburn 13328: sub modify_autoenroll {
1.160.6.24 raeburn 13329: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 13330: my ($resulttext,%changes);
13331: my %currautoenroll;
13332: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13333: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13334: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13335: }
13336: }
13337: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13338: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 13339: sender => 'Sender for notification messages',
1.160.6.68 raeburn 13340: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 13341: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 13342: my @offon = ('off','on');
1.17 raeburn 13343: my $sender_uname = $env{'form.sender_uname'};
13344: my $sender_domain = $env{'form.sender_domain'};
13345: if ($sender_domain eq '') {
13346: $sender_uname = '';
13347: } elsif ($sender_uname eq '') {
13348: $sender_domain = '';
13349: }
1.129 raeburn 13350: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 13351: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
13352: $autofailsafe =~ s{^\s+|\s+$}{}g;
13353: if ($autofailsafe =~ /\D/) {
13354: undef($autofailsafe);
13355: }
1.160.6.68 raeburn 13356: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 13357: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
13358: $failsafe = 'off';
13359: undef($autofailsafe);
1.160.6.68 raeburn 13360: }
1.1 raeburn 13361: my %autoenrollhash = (
1.129 raeburn 13362: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13363: 'sender_uname' => $sender_uname,
13364: 'sender_domain' => $sender_domain,
13365: 'co-owners' => $coowners,
1.160.6.116 raeburn 13366: 'autofailsafe' => $autofailsafe,
13367: 'failsafe' => $failsafe,
1.1 raeburn 13368: }
13369: );
1.4 raeburn 13370: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13371: $dom);
1.1 raeburn 13372: if ($putresult eq 'ok') {
13373: if (exists($currautoenroll{'run'})) {
13374: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13375: $changes{'run'} = 1;
13376: }
13377: } elsif ($autorun) {
13378: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 13379: $changes{'run'} = 1;
1.1 raeburn 13380: }
13381: }
1.17 raeburn 13382: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 13383: $changes{'sender'} = 1;
13384: }
1.17 raeburn 13385: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 13386: $changes{'sender'} = 1;
13387: }
1.129 raeburn 13388: if ($currautoenroll{'co-owners'} ne '') {
13389: if ($currautoenroll{'co-owners'} ne $coowners) {
13390: $changes{'coowners'} = 1;
13391: }
13392: } elsif ($coowners) {
13393: $changes{'coowners'} = 1;
1.160.6.68 raeburn 13394: }
1.160.6.116 raeburn 13395: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 13396: $changes{'autofailsafe'} = 1;
13397: }
1.160.6.116 raeburn 13398: if ($currautoenroll{'failsafe'} ne $failsafe) {
13399: $changes{'failsafe'} = 1;
13400: }
1.1 raeburn 13401: if (keys(%changes) > 0) {
13402: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 13403: if ($changes{'run'}) {
1.1 raeburn 13404: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13405: }
13406: if ($changes{'sender'}) {
1.17 raeburn 13407: if ($sender_uname eq '' || $sender_domain eq '') {
13408: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13409: } else {
13410: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13411: }
1.1 raeburn 13412: }
1.129 raeburn 13413: if ($changes{'coowners'}) {
13414: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13415: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13416: if (ref($lastactref) eq 'HASH') {
13417: $lastactref->{'domainconfig'} = 1;
13418: }
1.129 raeburn 13419: }
1.160.6.68 raeburn 13420: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 13421: if ($autofailsafe ne '') {
13422: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 13423: } else {
1.160.6.116 raeburn 13424: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 13425: }
1.160.6.116 raeburn 13426: }
13427: if ($changes{'failsafe'}) {
13428: if ($failsafe eq 'off') {
13429: unless ($changes{'autofailsafe'}) {
13430: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
13431: }
13432: } elsif ($failsafe eq 'zero') {
13433: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
13434: } else {
13435: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
13436: }
13437: }
13438: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 13439: &Apache::lonnet::get_domain_defaults($dom,1);
13440: if (ref($lastactref) eq 'HASH') {
13441: $lastactref->{'domdefaults'} = 1;
13442: }
13443: }
1.1 raeburn 13444: $resulttext .= '</ul>';
13445: } else {
13446: $resulttext = &mt('No changes made to auto-enrollment settings');
13447: }
13448: } else {
1.11 albertel 13449: $resulttext = '<span class="LC_error">'.
13450: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13451: }
1.3 raeburn 13452: return $resulttext;
1.1 raeburn 13453: }
13454:
13455: sub modify_autoupdate {
1.3 raeburn 13456: my ($dom,%domconfig) = @_;
1.1 raeburn 13457: my ($resulttext,%currautoupdate,%fields,%changes);
13458: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13459: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13460: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13461: }
13462: }
13463: my @offon = ('off','on');
13464: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 13465: run => 'Auto-update:',
13466: classlists => 'Updates to user information in classlists?',
13467: unexpired => 'Skip updates for users without active or future roles?',
13468: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 13469: );
1.44 raeburn 13470: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13471: my %fieldtitles = &Apache::lonlocal::texthash (
13472: id => 'Student/Employee ID',
1.20 raeburn 13473: permanentemail => 'E-mail address',
1.1 raeburn 13474: lastname => 'Last Name',
13475: firstname => 'First Name',
13476: middlename => 'Middle Name',
1.132 raeburn 13477: generation => 'Generation',
1.1 raeburn 13478: );
1.142 raeburn 13479: $othertitle = &mt('All users');
1.1 raeburn 13480: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 13481: $othertitle = &mt('Other users');
1.1 raeburn 13482: }
13483: foreach my $key (keys(%env)) {
13484: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 13485: my ($usertype,$item) = ($1,$2);
13486: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13487: if ($usertype eq 'default') {
13488: push(@{$fields{$1}},$2);
13489: } elsif (ref($types) eq 'ARRAY') {
13490: if (grep(/^\Q$usertype\E$/,@{$types})) {
13491: push(@{$fields{$1}},$2);
13492: }
13493: }
13494: }
1.1 raeburn 13495: }
13496: }
1.131 raeburn 13497: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13498: @lockablenames = sort(@lockablenames);
13499: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13500: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13501: if (@changed) {
13502: $changes{'lockablenames'} = 1;
13503: }
13504: } else {
13505: if (@lockablenames) {
13506: $changes{'lockablenames'} = 1;
13507: }
13508: }
1.1 raeburn 13509: my %updatehash = (
13510: autoupdate => { run => $env{'form.autoupdate_run'},
13511: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 13512: unexpired => $env{'form.unexpired'},
1.1 raeburn 13513: fields => {%fields},
1.131 raeburn 13514: lockablenames => \@lockablenames,
1.1 raeburn 13515: }
13516: );
1.160.6.113 raeburn 13517: my $lastactivedays;
13518: if ($env{'form.lastactive'}) {
13519: $lastactivedays = $env{'form.lastactivedays'};
13520: $lastactivedays =~ s/^\s+|\s+$//g;
13521: unless ($lastactivedays =~ /^\d+$/) {
13522: undef($lastactivedays);
13523: $env{'form.lastactive'} = 0;
13524: }
13525: }
13526: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 13527: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 13528: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 13529: if (exists($updatehash{autoupdate}{$key})) {
13530: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13531: $changes{$key} = 1;
13532: }
13533: }
13534: } elsif ($key eq 'fields') {
13535: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 13536: foreach my $item (@{$types},'default') {
1.1 raeburn 13537: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13538: my $change = 0;
13539: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13540: if (!exists($fields{$item})) {
13541: $change = 1;
1.132 raeburn 13542: last;
1.1 raeburn 13543: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 13544: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 13545: $change = 1;
1.132 raeburn 13546: last;
1.1 raeburn 13547: }
13548: }
13549: }
13550: if ($change) {
13551: push(@{$changes{$key}},$item);
13552: }
1.26 raeburn 13553: }
1.1 raeburn 13554: }
13555: }
1.131 raeburn 13556: } elsif ($key eq 'lockablenames') {
13557: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13558: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13559: if (@changed) {
13560: $changes{'lockablenames'} = 1;
13561: }
13562: } else {
13563: if (@lockablenames) {
13564: $changes{'lockablenames'} = 1;
13565: }
13566: }
13567: }
13568: }
13569: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13570: if (@lockablenames) {
13571: $changes{'lockablenames'} = 1;
1.1 raeburn 13572: }
13573: }
1.160.6.113 raeburn 13574: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
13575: if ($updatehash{'autoupdate'}{'unexpired'}) {
13576: $changes{'unexpired'} = 1;
13577: }
13578: }
13579: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
13580: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
13581: $changes{'lastactive'} = 1;
13582: }
13583: }
1.26 raeburn 13584: foreach my $item (@{$types},'default') {
13585: if (defined($fields{$item})) {
13586: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13587: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13588: my $change = 0;
13589: if (ref($fields{$item}) eq 'ARRAY') {
13590: foreach my $type (@{$fields{$item}}) {
13591: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13592: $change = 1;
13593: last;
13594: }
13595: }
13596: }
13597: if ($change) {
13598: push(@{$changes{'fields'}},$item);
13599: }
13600: } else {
1.26 raeburn 13601: push(@{$changes{'fields'}},$item);
13602: }
13603: } else {
13604: push(@{$changes{'fields'}},$item);
1.1 raeburn 13605: }
13606: }
13607: }
13608: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13609: $dom);
13610: if ($putresult eq 'ok') {
13611: if (keys(%changes) > 0) {
13612: $resulttext = &mt('Changes made:').'<ul>';
13613: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13614: if ($key eq 'lockablenames') {
13615: $resulttext .= '<li>';
13616: if (@lockablenames) {
13617: $usertypes->{'default'} = $othertitle;
13618: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13619: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13620: } else {
13621: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13622: }
13623: $resulttext .= '</li>';
13624: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13625: foreach my $item (@{$changes{$key}}) {
13626: my @newvalues;
13627: foreach my $type (@{$fields{$item}}) {
13628: push(@newvalues,$fieldtitles{$type});
13629: }
1.3 raeburn 13630: my $newvaluestr;
13631: if (@newvalues > 0) {
13632: $newvaluestr = join(', ',@newvalues);
13633: } else {
13634: $newvaluestr = &mt('none');
1.6 raeburn 13635: }
1.1 raeburn 13636: if ($item eq 'default') {
1.26 raeburn 13637: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13638: } else {
1.26 raeburn 13639: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13640: }
13641: }
13642: } else {
13643: my $newvalue;
13644: if ($key eq 'run') {
13645: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 13646: } elsif ($key eq 'lastactive') {
13647: $newvalue = $offon[$env{'form.lastactive'}];
13648: unless ($lastactivedays eq '') {
13649: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
13650: }
1.1 raeburn 13651: } else {
13652: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13653: }
1.1 raeburn 13654: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13655: }
13656: }
13657: $resulttext .= '</ul>';
13658: } else {
1.3 raeburn 13659: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13660: }
13661: } else {
1.11 albertel 13662: $resulttext = '<span class="LC_error">'.
13663: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13664: }
1.3 raeburn 13665: return $resulttext;
1.1 raeburn 13666: }
13667:
1.125 raeburn 13668: sub modify_autocreate {
13669: my ($dom,%domconfig) = @_;
13670: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13671: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13672: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13673: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13674: }
13675: }
13676: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13677: req => 'Auto-creation of validated requests for official courses',
13678: xmldc => 'Identity of course creator of courses from XML files',
13679: );
13680: my @types = ('xml','req');
13681: foreach my $item (@types) {
13682: $newvals{$item} = $env{'form.autocreate_'.$item};
13683: $newvals{$item} =~ s/\D//g;
13684: $newvals{$item} = 0 if ($newvals{$item} eq '');
13685: }
13686: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 13687: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13688: unless (exists($domcoords{$newvals{'xmldc'}})) {
13689: $newvals{'xmldc'} = '';
13690: }
13691: %autocreatehash = (
13692: autocreate => { xml => $newvals{'xml'},
13693: req => $newvals{'req'},
13694: }
13695: );
13696: if ($newvals{'xmldc'} ne '') {
13697: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13698: }
13699: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13700: $dom);
13701: if ($putresult eq 'ok') {
13702: my @items = @types;
13703: if ($newvals{'xml'}) {
13704: push(@items,'xmldc');
13705: }
13706: foreach my $item (@items) {
13707: if (exists($currautocreate{$item})) {
13708: if ($currautocreate{$item} ne $newvals{$item}) {
13709: $changes{$item} = 1;
13710: }
13711: } elsif ($newvals{$item}) {
13712: $changes{$item} = 1;
13713: }
13714: }
13715: if (keys(%changes) > 0) {
13716: my @offon = ('off','on');
13717: $resulttext = &mt('Changes made:').'<ul>';
13718: foreach my $item (@types) {
13719: if ($changes{$item}) {
13720: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 13721: $resulttext .= '<li>'.
13722: &mt("$title{$item} set to [_1]$newtxt [_2]",
13723: '<b>','</b>').
13724: '</li>';
1.125 raeburn 13725: }
13726: }
13727: if ($changes{'xmldc'}) {
13728: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13729: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 13730: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13731: }
13732: $resulttext .= '</ul>';
13733: } else {
13734: $resulttext = &mt('No changes made to auto-creation settings');
13735: }
13736: } else {
13737: $resulttext = '<span class="LC_error">'.
13738: &mt('An error occurred: [_1]',$putresult).'</span>';
13739: }
13740: return $resulttext;
13741: }
13742:
1.23 raeburn 13743: sub modify_directorysrch {
1.160.6.81 raeburn 13744: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13745: my ($resulttext,%changes);
13746: my %currdirsrch;
13747: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13748: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13749: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13750: }
13751: }
1.160.6.72 raeburn 13752: my %title = ( available => 'Institutional directory search available',
13753: localonly => 'Other domains can search institution',
13754: lcavailable => 'LON-CAPA directory search available',
13755: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13756: searchby => 'Search types',
13757: searchtypes => 'Search latitude');
13758: my @offon = ('off','on');
1.24 raeburn 13759: my @otherdoms = ('Yes','No');
1.23 raeburn 13760:
1.25 raeburn 13761: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13762: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13763: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13764:
1.44 raeburn 13765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13766: if (keys(%{$usertypes}) == 0) {
13767: @cansearch = ('default');
13768: } else {
13769: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13770: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13771: if (!grep(/^\Q$type\E$/,@cansearch)) {
13772: push(@{$changes{'cansearch'}},$type);
13773: }
1.23 raeburn 13774: }
1.26 raeburn 13775: foreach my $type (@cansearch) {
13776: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13777: push(@{$changes{'cansearch'}},$type);
13778: }
1.23 raeburn 13779: }
1.26 raeburn 13780: } else {
13781: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13782: }
13783: }
13784:
13785: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13786: foreach my $by (@{$currdirsrch{'searchby'}}) {
13787: if (!grep(/^\Q$by\E$/,@searchby)) {
13788: push(@{$changes{'searchby'}},$by);
13789: }
13790: }
13791: foreach my $by (@searchby) {
13792: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13793: push(@{$changes{'searchby'}},$by);
13794: }
13795: }
13796: } else {
13797: push(@{$changes{'searchby'}},@searchby);
13798: }
1.25 raeburn 13799:
13800: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13801: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13802: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13803: push(@{$changes{'searchtypes'}},$type);
13804: }
13805: }
13806: foreach my $type (@searchtypes) {
13807: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13808: push(@{$changes{'searchtypes'}},$type);
13809: }
13810: }
13811: } else {
13812: if (exists($currdirsrch{'searchtypes'})) {
13813: foreach my $type (@searchtypes) {
13814: if ($type ne $currdirsrch{'searchtypes'}) {
13815: push(@{$changes{'searchtypes'}},$type);
13816: }
13817: }
13818: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13819: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13820: }
13821: } else {
13822: push(@{$changes{'searchtypes'}},@searchtypes);
13823: }
13824: }
13825:
1.23 raeburn 13826: my %dirsrch_hash = (
13827: directorysrch => { available => $env{'form.dirsrch_available'},
13828: cansearch => \@cansearch,
1.160.6.72 raeburn 13829: localonly => $env{'form.dirsrch_instlocalonly'},
13830: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13831: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13832: searchby => \@searchby,
1.25 raeburn 13833: searchtypes => \@searchtypes,
1.23 raeburn 13834: }
13835: );
13836: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13837: $dom);
13838: if ($putresult eq 'ok') {
13839: if (exists($currdirsrch{'available'})) {
13840: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13841: $changes{'available'} = 1;
13842: }
13843: } else {
13844: if ($env{'form.dirsrch_available'} eq '1') {
13845: $changes{'available'} = 1;
13846: }
13847: }
1.160.6.72 raeburn 13848: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 13849: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13850: $changes{'lcavailable'} = 1;
13851: }
1.24 raeburn 13852: } else {
1.160.6.72 raeburn 13853: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13854: $changes{'lcavailable'} = 1;
13855: }
13856: }
13857: if (exists($currdirsrch{'localonly'})) {
13858: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 13859: $changes{'localonly'} = 1;
13860: }
1.160.6.72 raeburn 13861: } else {
13862: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
13863: $changes{'localonly'} = 1;
13864: }
13865: }
13866: if (exists($currdirsrch{'lclocalonly'})) {
13867: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13868: $changes{'lclocalonly'} = 1;
13869: }
13870: } else {
13871: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13872: $changes{'lclocalonly'} = 1;
13873: }
1.24 raeburn 13874: }
1.23 raeburn 13875: if (keys(%changes) > 0) {
13876: $resulttext = &mt('Changes made:').'<ul>';
13877: if ($changes{'available'}) {
13878: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13879: }
1.160.6.72 raeburn 13880: if ($changes{'lcavailable'}) {
13881: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13882: }
1.24 raeburn 13883: if ($changes{'localonly'}) {
1.160.6.72 raeburn 13884: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
13885: }
13886: if ($changes{'lclocalonly'}) {
13887: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 13888: }
1.23 raeburn 13889: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13890: my $chgtext;
1.26 raeburn 13891: if (ref($usertypes) eq 'HASH') {
13892: if (keys(%{$usertypes}) > 0) {
13893: foreach my $type (@{$types}) {
13894: if (grep(/^\Q$type\E$/,@cansearch)) {
13895: $chgtext .= $usertypes->{$type}.'; ';
13896: }
13897: }
13898: if (grep(/^default$/,@cansearch)) {
13899: $chgtext .= $othertitle;
13900: } else {
13901: $chgtext =~ s/\; $//;
13902: }
1.160.6.13 raeburn 13903: $resulttext .=
13904: '<li>'.
13905: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13906: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13907: '</li>';
1.23 raeburn 13908: }
13909: }
13910: }
13911: if (ref($changes{'searchby'}) eq 'ARRAY') {
13912: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13913: my $chgtext;
13914: foreach my $type (@{$titleorder}) {
13915: if (grep(/^\Q$type\E$/,@searchby)) {
13916: if (defined($searchtitles->{$type})) {
13917: $chgtext .= $searchtitles->{$type}.'; ';
13918: }
13919: }
13920: }
13921: $chgtext =~ s/\; $//;
13922: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13923: }
1.25 raeburn 13924: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13925: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13926: my $chgtext;
13927: foreach my $type (@{$srchtypeorder}) {
13928: if (grep(/^\Q$type\E$/,@searchtypes)) {
13929: if (defined($srchtypes_desc->{$type})) {
13930: $chgtext .= $srchtypes_desc->{$type}.'; ';
13931: }
13932: }
13933: }
13934: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 13935: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13936: }
13937: $resulttext .= '</ul>';
1.160.6.81 raeburn 13938: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13939: if (ref($lastactref) eq 'HASH') {
13940: $lastactref->{'directorysrch'} = 1;
13941: }
1.23 raeburn 13942: } else {
1.160.6.72 raeburn 13943: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13944: }
13945: } else {
13946: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13947: &mt('An error occurred: [_1]',$putresult).'</span>';
13948: }
13949: return $resulttext;
13950: }
13951:
1.28 raeburn 13952: sub modify_contacts {
1.160.6.24 raeburn 13953: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13954: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13955: if (ref($domconfig{'contacts'}) eq 'HASH') {
13956: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13957: $currsetting{$key} = $domconfig{'contacts'}{$key};
13958: }
13959: }
1.160.6.78 raeburn 13960: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13961: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 13962: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 13963: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 13964: my @toggles = ('reporterrors','reportupdates','reportstatus');
13965: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 13966: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13967: foreach my $type (@mailings) {
13968: @{$newsetting{$type}} =
13969: &Apache::loncommon::get_env_multiple('form.'.$type);
13970: foreach my $item (@contacts) {
13971: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13972: $contacts_hash{contacts}{$type}{$item} = 1;
13973: } else {
13974: $contacts_hash{contacts}{$type}{$item} = 0;
13975: }
1.160.6.78 raeburn 13976: }
1.28 raeburn 13977: $others{$type} = $env{'form.'.$type.'_others'};
13978: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 13979: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13980: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13981: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 13982: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13983: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13984: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13985: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13986: }
1.134 raeburn 13987: }
1.28 raeburn 13988: }
13989: foreach my $item (@contacts) {
13990: $to{$item} = $env{'form.'.$item};
13991: $contacts_hash{'contacts'}{$item} = $to{$item};
13992: }
1.160.6.23 raeburn 13993: foreach my $item (@toggles) {
13994: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13995: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13996: }
13997: }
1.160.6.107 raeburn 13998: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13999: foreach my $item (@lonstatus) {
14000: if ($item eq 'excluded') {
14001: my (%serverhomes,@excluded);
14002: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
14003: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
14004: if (@possexcluded) {
14005: foreach my $id (sort(@possexcluded)) {
14006: if ($serverhomes{$id}) {
14007: push(@excluded,$id);
14008: }
14009: }
14010: }
14011: if (@excluded) {
14012: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
14013: }
14014: } elsif ($item eq 'weights') {
14015: foreach my $type ('E','W','N','U') {
14016: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
14017: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
14018: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
14019: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
14020: $env{'form.error'.$item.'_'.$type};
14021: }
14022: }
14023: }
14024: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
14025: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
14026: if ($env{'form.error'.$item} =~ /^\d+$/) {
14027: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
14028: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
14029: }
14030: }
14031: }
14032: }
1.160.6.78 raeburn 14033: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
14034: foreach my $field (@{$fields}) {
14035: if (ref($possoptions->{$field}) eq 'ARRAY') {
14036: my $value = $env{'form.helpform_'.$field};
14037: $value =~ s/^\s+|\s+$//g;
14038: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 14039: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 14040: if ($field eq 'screenshot') {
14041: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
14042: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 14043: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 14044: }
14045: }
14046: }
14047: }
14048: }
14049: }
1.160.6.101 raeburn 14050: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14051: my (@statuses,%usertypeshash,@overrides);
14052: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
14053: @statuses = @{$types};
14054: if (ref($usertypes) eq 'HASH') {
14055: %usertypeshash = %{$usertypes};
14056: }
14057: }
14058: if (@statuses) {
14059: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
14060: foreach my $type (@possoverrides) {
14061: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
14062: push(@overrides,$type);
14063: }
14064: }
14065: if (@overrides) {
14066: foreach my $type (@overrides) {
14067: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
14068: foreach my $item (@contacts) {
14069: if (grep(/^\Q$item\E$/,@standard)) {
14070: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
14071: $newsetting{'override_'.$type}{$item} = 1;
14072: } else {
14073: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
14074: $newsetting{'override_'.$type}{$item} = 0;
14075: }
14076: }
14077: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
14078: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14079: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
14080: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14081: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
14082: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
14083: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
14084: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14085: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
14086: }
14087: }
14088: }
14089: }
1.28 raeburn 14090: if (keys(%currsetting) > 0) {
14091: foreach my $item (@contacts) {
14092: if ($to{$item} ne $currsetting{$item}) {
14093: $changes{$item} = 1;
14094: }
14095: }
14096: foreach my $type (@mailings) {
14097: foreach my $item (@contacts) {
14098: if (ref($currsetting{$type}) eq 'HASH') {
14099: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14100: push(@{$changes{$type}},$item);
14101: }
14102: } else {
14103: push(@{$changes{$type}},@{$newsetting{$type}});
14104: }
14105: }
14106: if ($others{$type} ne $currsetting{$type}{'others'}) {
14107: push(@{$changes{$type}},'others');
14108: }
1.160.6.78 raeburn 14109: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14110: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14111: push(@{$changes{$type}},'bcc');
14112: }
1.160.6.78 raeburn 14113: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14114: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14115: push(@{$changes{$type}},'include');
14116: }
14117: }
14118: }
14119: if (ref($fields) eq 'ARRAY') {
14120: if (ref($currsetting{'helpform'}) eq 'HASH') {
14121: foreach my $field (@{$fields}) {
14122: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
14123: push(@{$changes{'helpform'}},$field);
14124: }
14125: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14126: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
14127: push(@{$changes{'helpform'}},'maxsize');
14128: }
14129: }
14130: }
14131: } else {
14132: foreach my $field (@{$fields}) {
14133: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14134: push(@{$changes{'helpform'}},$field);
14135: }
14136: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14137: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14138: push(@{$changes{'helpform'}},'maxsize');
14139: }
14140: }
14141: }
1.134 raeburn 14142: }
1.28 raeburn 14143: }
1.160.6.101 raeburn 14144: if (@statuses) {
14145: if (ref($currsetting{'overrides'}) eq 'HASH') {
14146: foreach my $key (keys(%{$currsetting{'overrides'}})) {
14147: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
14148: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
14149: foreach my $item (@contacts,'bcc','others','include') {
14150: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
14151: push(@{$changes{'overrides'}},$key);
14152: last;
14153: }
14154: }
14155: } else {
14156: push(@{$changes{'overrides'}},$key);
14157: }
14158: }
14159: }
14160: foreach my $key (@overrides) {
14161: unless (exists($currsetting{'overrides'}{$key})) {
14162: push(@{$changes{'overrides'}},$key);
14163: }
14164: }
14165: } else {
14166: foreach my $key (@overrides) {
14167: push(@{$changes{'overrides'}},$key);
14168: }
14169: }
14170: }
1.160.6.107 raeburn 14171: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
14172: foreach my $key ('excluded','weights','threshold','sysmail') {
14173: if ($key eq 'excluded') {
14174: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14175: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
14176: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14177: (@{$currsetting{'lonstatus'}{$key}})) {
14178: my @diffs =
14179: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
14180: $currsetting{'lonstatus'}{$key});
14181: if (@diffs) {
14182: push(@{$changes{'lonstatus'}},$key);
14183: }
14184: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
14185: push(@{$changes{'lonstatus'}},$key);
14186: }
14187: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14188: (@{$currsetting{'lonstatus'}{$key}})) {
14189: push(@{$changes{'lonstatus'}},$key);
14190: }
14191: } elsif ($key eq 'weights') {
14192: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14193: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
14194: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14195: foreach my $type ('E','W','N','U') {
14196: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
14197: $currsetting{'lonstatus'}{$key}{$type}) {
14198: push(@{$changes{'lonstatus'}},$key);
14199: last;
14200: }
14201: }
14202: } else {
14203: foreach my $type ('E','W','N','U') {
14204: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
14205: push(@{$changes{'lonstatus'}},$key);
14206: last;
14207: }
14208: }
14209: }
14210: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14211: foreach my $type ('E','W','N','U') {
14212: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
14213: push(@{$changes{'lonstatus'}},$key);
14214: last;
14215: }
14216: }
14217: }
14218: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
14219: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14220: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14221: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
14222: push(@{$changes{'lonstatus'}},$key);
14223: }
14224: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
14225: push(@{$changes{'lonstatus'}},$key);
14226: }
14227: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14228: push(@{$changes{'lonstatus'}},$key);
14229: }
14230: }
14231: }
14232: } else {
14233: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14234: foreach my $key ('excluded','weights','threshold','sysmail') {
14235: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14236: push(@{$changes{'lonstatus'}},$key);
14237: }
14238: }
14239: }
14240: }
1.28 raeburn 14241: } else {
14242: my %default;
14243: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
14244: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
14245: $default{'errormail'} = 'adminemail';
14246: $default{'packagesmail'} = 'adminemail';
14247: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 14248: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 14249: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 14250: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 14251: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 14252: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 14253: foreach my $item (@contacts) {
14254: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 14255: $changes{$item} = 1;
1.160.6.23 raeburn 14256: }
1.28 raeburn 14257: }
14258: foreach my $type (@mailings) {
14259: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
14260: push(@{$changes{$type}},@{$newsetting{$type}});
14261: }
14262: if ($others{$type} ne '') {
14263: push(@{$changes{$type}},'others');
1.134 raeburn 14264: }
1.160.6.78 raeburn 14265: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14266: if ($bcc{$type} ne '') {
14267: push(@{$changes{$type}},'bcc');
14268: }
1.160.6.78 raeburn 14269: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14270: push(@{$changes{$type}},'include');
14271: }
14272: }
14273: }
14274: if (ref($fields) eq 'ARRAY') {
14275: foreach my $field (@{$fields}) {
14276: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14277: push(@{$changes{'helpform'}},$field);
14278: }
14279: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14280: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14281: push(@{$changes{'helpform'}},'maxsize');
14282: }
14283: }
1.134 raeburn 14284: }
1.28 raeburn 14285: }
1.160.6.107 raeburn 14286: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14287: foreach my $key ('excluded','weights','threshold','sysmail') {
14288: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14289: push(@{$changes{'lonstatus'}},$key);
14290: }
14291: }
14292: }
1.28 raeburn 14293: }
1.160.6.23 raeburn 14294: foreach my $item (@toggles) {
14295: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
14296: $changes{$item} = 1;
14297: } elsif ((!$env{'form.'.$item}) &&
14298: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
14299: $changes{$item} = 1;
14300: }
14301: }
1.28 raeburn 14302: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
14303: $dom);
14304: if ($putresult eq 'ok') {
14305: if (keys(%changes) > 0) {
1.160.6.24 raeburn 14306: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14307: if (ref($lastactref) eq 'HASH') {
14308: $lastactref->{'domainconfig'} = 1;
14309: }
1.28 raeburn 14310: my ($titles,$short_titles) = &contact_titles();
14311: $resulttext = &mt('Changes made:').'<ul>';
14312: foreach my $item (@contacts) {
14313: if ($changes{$item}) {
14314: $resulttext .= '<li>'.$titles->{$item}.
14315: &mt(' set to: ').
14316: '<span class="LC_cusr_emph">'.
14317: $to{$item}.'</span></li>';
14318: }
14319: }
14320: foreach my $type (@mailings) {
14321: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 14322: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14323: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
14324: } else {
14325: $resulttext .= '<li>'.$titles->{$type}.': ';
14326: }
1.28 raeburn 14327: my @text;
14328: foreach my $item (@{$newsetting{$type}}) {
14329: push(@text,$short_titles->{$item});
14330: }
14331: if ($others{$type} ne '') {
14332: push(@text,$others{$type});
14333: }
1.160.6.78 raeburn 14334: if (@text) {
14335: $resulttext .= '<span class="LC_cusr_emph">'.
14336: join(', ',@text).'</span>';
14337: }
14338: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14339: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 14340: my $bcctext;
14341: if (@text) {
14342: $bcctext = ' '.&mt('with Bcc to');
14343: } else {
14344: $bcctext = '(Bcc)';
14345: }
14346: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
14347: } elsif (!@text) {
14348: $resulttext .= &mt('No one');
1.134 raeburn 14349: }
1.160.6.78 raeburn 14350: if ($includestr{$type} ne '') {
14351: if ($includeloc{$type} eq 'b') {
14352: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
14353: } elsif ($includeloc{$type} eq 's') {
14354: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
14355: }
14356: }
14357: } elsif (!@text) {
14358: $resulttext .= &mt('No recipients');
1.134 raeburn 14359: }
14360: $resulttext .= '</li>';
1.28 raeburn 14361: }
14362: }
1.160.6.101 raeburn 14363: if (ref($changes{'overrides'}) eq 'ARRAY') {
14364: my @deletions;
14365: foreach my $type (@{$changes{'overrides'}}) {
14366: if ($usertypeshash{$type}) {
14367: if (grep(/^\Q$type\E/,@overrides)) {
14368: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
14369: $usertypeshash{$type}).'<ul><li>';
14370: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
14371: my @text;
14372: foreach my $item (@contacts) {
14373: if ($newsetting{'override_'.$type}{$item}) {
14374: push(@text,$short_titles->{$item});
14375: }
14376: }
14377: if ($newsetting{'override_'.$type}{'others'} ne '') {
14378: push(@text,$newsetting{'override_'.$type}{'others'});
14379: }
14380:
14381: if (@text) {
14382: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14383: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14384: }
14385: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14386: my $bcctext;
14387: if (@text) {
14388: $bcctext = ' '.&mt('with Bcc to');
14389: } else {
14390: $bcctext = '(Bcc)';
14391: }
14392: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14393: } elsif (!@text) {
14394: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14395: }
14396: $resulttext .= '</li>';
14397: if ($newsetting{'override_'.$type}{'include'} ne '') {
14398: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14399: if ($loc eq 'b') {
14400: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14401: } elsif ($loc eq 's') {
14402: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14403: }
14404: }
14405: }
14406: $resulttext .= '</li></ul></li>';
14407: } else {
14408: push(@deletions,$usertypeshash{$type});
14409: }
14410: }
14411: }
14412: if (@deletions) {
14413: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14414: join(', ',@deletions)).'</li>';
14415: }
14416: }
1.160.6.23 raeburn 14417: my @offon = ('off','on');
1.160.6.107 raeburn 14418: my $corelink = &core_link_msu();
1.160.6.23 raeburn 14419: if ($changes{'reporterrors'}) {
14420: $resulttext .= '<li>'.
14421: &mt('E-mail error reports to [_1] set to "'.
14422: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 14423: $corelink).
1.160.6.23 raeburn 14424: '</li>';
14425: }
14426: if ($changes{'reportupdates'}) {
14427: $resulttext .= '<li>'.
14428: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14429: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 14430: $corelink).
1.160.6.23 raeburn 14431: '</li>';
14432: }
1.160.6.107 raeburn 14433: if ($changes{'reportstatus'}) {
14434: $resulttext .= '<li>'.
14435: &mt('E-mail status if errors above threshold to [_1] set to "'.
14436: $offon[$env{'form.reportstatus'}].'".',
14437: $corelink).
14438: '</li>';
14439: }
14440: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14441: $resulttext .= '<li>'.
14442: &mt('Nightly status check e-mail settings').':<ul>';
14443: my (%defval,%use_def,%shown);
14444: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14445: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14446: $defval{'weights'} =
14447: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
14448: $defval{'excluded'} = &mt('None');
14449: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14450: foreach my $item ('threshold','sysmail','weights','excluded') {
14451: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14452: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14453: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14454: } elsif ($item eq 'weights') {
14455: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
14456: foreach my $type ('E','W','N','U') {
14457: $shown{$item} .= $lonstatus_names->{$type}.'=';
14458: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14459: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14460: } else {
14461: $shown{$item} .= $lonstatus_defs->{$type};
14462: }
14463: $shown{$item} .= ', ';
14464: }
14465: $shown{$item} =~ s/, $//;
14466: } else {
14467: $shown{$item} = $defval{$item};
14468: }
14469: } elsif ($item eq 'excluded') {
14470: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14471: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14472: } else {
14473: $shown{$item} = $defval{$item};
14474: }
14475: }
14476: } else {
14477: $shown{$item} = $defval{$item};
14478: }
14479: }
14480: } else {
14481: foreach my $item ('threshold','weights','excluded','sysmail') {
14482: $shown{$item} = $defval{$item};
14483: }
14484: }
14485: foreach my $item ('threshold','weights','excluded','sysmail') {
14486: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14487: $shown{$item}).'</li>';
14488: }
14489: $resulttext .= '</ul></li>';
14490: }
1.160.6.78 raeburn 14491: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14492: my (@optional,@required,@unused,$maxsizechg);
14493: foreach my $field (@{$changes{'helpform'}}) {
14494: if ($field eq 'maxsize') {
14495: $maxsizechg = 1;
14496: next;
14497: }
14498: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
14499: push(@optional,$field);
14500: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14501: push(@unused,$field);
14502: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
14503: push(@required,$field);
14504: }
14505: }
14506: if (@optional) {
14507: $resulttext .= '<li>'.
14508: &mt('Help form fields changed to "Optional": [_1].',
14509: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14510: '</li>';
14511: }
14512: if (@required) {
14513: $resulttext .= '<li>'.
14514: &mt('Help form fields changed to "Required": [_1].',
14515: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14516: '</li>';
14517: }
14518: if (@unused) {
14519: $resulttext .= '<li>'.
14520: &mt('Help form fields changed to "Not shown": [_1].',
14521: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14522: '</li>';
14523: }
14524: if ($maxsizechg) {
14525: $resulttext .= '<li>'.
14526: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14527: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14528: '</li>';
14529: }
14530: }
1.28 raeburn 14531: $resulttext .= '</ul>';
14532: } else {
1.160.6.78 raeburn 14533: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 14534: }
14535: } else {
14536: $resulttext = '<span class="LC_error">'.
14537: &mt('An error occurred: [_1].',$putresult).'</span>';
14538: }
14539: return $resulttext;
14540: }
14541:
1.160.6.98 raeburn 14542: sub modify_passwords {
14543: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14544: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14545: $updatedefaults,$updateconf);
14546: my $customfn = 'resetpw.html';
14547: if (ref($domconfig{'passwords'}) eq 'HASH') {
14548: %current = %{$domconfig{'passwords'}};
14549: }
14550: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14551: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14552: if (ref($types) eq 'ARRAY') {
14553: @oktypes = @{$types};
14554: }
14555: push(@oktypes,'default');
14556:
14557: my %titles = &Apache::lonlocal::texthash (
14558: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14559: intauth_check => 'Check bcrypt cost if authenticated',
14560: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14561: permanent => 'Permanent e-mail address',
14562: critical => 'Critical notification address',
14563: notify => 'Notification address',
14564: min => 'Minimum password length',
14565: max => 'Maximum password length',
14566: chars => 'Required characters',
14567: numsaved => 'Number of previous passwords to save',
14568: reset => 'Resetting Forgotten Password',
14569: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14570: rules => 'Rules for LON-CAPA Passwords',
14571: crsownerchg => 'Course Owner Changing Student Passwords',
14572: username => 'Username',
14573: email => 'E-mail address',
14574: );
14575:
14576: #
14577: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14578: #
14579: my (%curr_defaults,%save_defaults);
14580: if (ref($domconfig{'defaults'}) eq 'HASH') {
14581: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14582: if ($key =~ /^intauth_(cost|check|switch)$/) {
14583: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14584: } else {
14585: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14586: }
14587: }
14588: }
14589: my %staticdefaults = (
14590: 'resetlink' => 2,
14591: 'resetcase' => \@oktypes,
14592: 'resetprelink' => 'both',
14593: 'resetemail' => ['critical','notify','permanent'],
14594: 'intauth_cost' => 10,
14595: 'intauth_check' => 0,
14596: 'intauth_switch' => 0,
14597: );
1.160.6.99 raeburn 14598: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 14599: foreach my $type (@oktypes) {
14600: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14601: }
14602: my $linklife = $env{'form.passwords_link'};
14603: $linklife =~ s/^\s+|\s+$//g;
14604: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14605: $newvalues{'resetlink'} = $linklife;
14606: if ($current{'resetlink'}) {
14607: if ($current{'resetlink'} ne $linklife) {
14608: $changes{'reset'} = 1;
14609: }
1.160.6.102 raeburn 14610: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14611: if ($staticdefaults{'resetlink'} ne $linklife) {
14612: $changes{'reset'} = 1;
14613: }
14614: }
14615: } elsif ($current{'resetlink'}) {
14616: $changes{'reset'} = 1;
14617: }
14618: my @casesens;
14619: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14620: foreach my $case (sort(@posscase)) {
14621: if (grep(/^\Q$case\E$/,@oktypes)) {
14622: push(@casesens,$case);
14623: }
14624: }
14625: $newvalues{'resetcase'} = \@casesens;
14626: if (ref($current{'resetcase'}) eq 'ARRAY') {
14627: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14628: if (@diffs > 0) {
14629: $changes{'reset'} = 1;
14630: }
1.160.6.102 raeburn 14631: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14632: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14633: if (@diffs > 0) {
14634: $changes{'reset'} = 1;
14635: }
14636: }
14637: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14638: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14639: if (exists($current{'resetprelink'})) {
14640: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14641: $changes{'reset'} = 1;
14642: }
1.160.6.102 raeburn 14643: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14644: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14645: $changes{'reset'} = 1;
14646: }
14647: }
14648: } elsif ($current{'resetprelink'}) {
14649: $changes{'reset'} = 1;
14650: }
14651: foreach my $type (@oktypes) {
14652: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14653: my @postlink;
14654: foreach my $item (sort(@possplink)) {
14655: if ($item =~ /^(email|username)$/) {
14656: push(@postlink,$item);
14657: }
14658: }
14659: $newvalues{'resetpostlink'}{$type} = \@postlink;
14660: unless ($changes{'reset'}) {
14661: if (ref($current{'resetpostlink'}) eq 'HASH') {
14662: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14663: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14664: if (@diffs > 0) {
14665: $changes{'reset'} = 1;
14666: }
14667: } else {
14668: $changes{'reset'} = 1;
14669: }
1.160.6.102 raeburn 14670: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14671: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14672: if (@diffs > 0) {
14673: $changes{'reset'} = 1;
14674: }
14675: }
14676: }
14677: }
14678: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14679: my @resetemail;
14680: foreach my $item (sort(@possemailsrc)) {
14681: if ($item =~ /^(permanent|critical|notify)$/) {
14682: push(@resetemail,$item);
14683: }
14684: }
14685: $newvalues{'resetemail'} = \@resetemail;
14686: unless ($changes{'reset'}) {
14687: if (ref($current{'resetemail'}) eq 'ARRAY') {
14688: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14689: if (@diffs > 0) {
14690: $changes{'reset'} = 1;
14691: }
1.160.6.102 raeburn 14692: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14693: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14694: if (@diffs > 0) {
14695: $changes{'reset'} = 1;
14696: }
14697: }
14698: }
14699: if ($env{'form.passwords_stdtext'} == 0) {
14700: $newvalues{'resetremove'} = 1;
14701: unless ($current{'resetremove'}) {
14702: $changes{'reset'} = 1;
14703: }
14704: } elsif ($current{'resetremove'}) {
14705: $changes{'reset'} = 1;
14706: }
14707: if ($env{'form.passwords_customfile.filename'} ne '') {
14708: my $servadm = $r->dir_config('lonAdmEMail');
14709: my $servadm = $r->dir_config('lonAdmEMail');
14710: my ($configuserok,$author_ok,$switchserver) =
14711: &config_check($dom,$confname,$servadm);
14712: my $error;
14713: if ($configuserok eq 'ok') {
14714: if ($switchserver) {
14715: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14716: } else {
14717: if ($author_ok eq 'ok') {
14718: my ($result,$customurl) =
14719: &publishlogo($r,'upload','passwords_customfile',$dom,
14720: $confname,'customtext/resetpw','','',$customfn);
14721: if ($result eq 'ok') {
14722: $newvalues{'resetcustom'} = $customurl;
14723: $changes{'reset'} = 1;
14724: } else {
14725: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14726: }
14727: } else {
14728: $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);
14729: }
14730: }
14731: } else {
14732: $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);
14733: }
14734: if ($error) {
14735: &Apache::lonnet::logthis($error);
14736: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14737: }
14738: } elsif ($current{'resetcustom'}) {
14739: if ($env{'form.passwords_custom_del'}) {
14740: $changes{'reset'} = 1;
14741: } else {
14742: $newvalues{'resetcustom'} = $current{'resetcustom'};
14743: }
14744: }
14745: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14746: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14747: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14748: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14749: $changes{'intauth'} = 1;
14750: }
14751: } else {
14752: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14753: }
14754: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14755: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14756: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14757: $changes{'intauth'} = 1;
14758: }
14759: } else {
14760: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14761: }
14762: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14763: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14764: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14765: $changes{'intauth'} = 1;
14766: }
14767: } else {
14768: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14769: }
14770: foreach my $item ('cost','check','switch') {
14771: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14772: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14773: $updatedefaults = 1;
14774: }
14775: }
1.160.6.118.2 5(raebur 14776:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 14777: my %crsownerchg = (
14778: by => [],
14779: for => [],
14780: );
14781: foreach my $item ('by','for') {
14782: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14783: foreach my $type (sort(@posstypes)) {
14784: if (grep(/^\Q$type\E$/,@oktypes)) {
14785: push(@{$crsownerchg{$item}},$type);
14786: }
14787: }
14788: }
14789: $newvalues{'crsownerchg'} = \%crsownerchg;
14790: if (ref($current{'crsownerchg'}) eq 'HASH') {
14791: foreach my $item ('by','for') {
14792: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14793: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14794: if (@diffs > 0) {
14795: $changes{'crsownerchg'} = 1;
14796: last;
14797: }
14798: }
14799: }
1.160.6.102 raeburn 14800: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 14801: foreach my $item ('by','for') {
14802: if (@{$crsownerchg{$item}} > 0) {
14803: $changes{'crsownerchg'} = 1;
14804: last;
14805: }
14806: }
14807: }
14808:
14809: my %confighash = (
14810: defaults => \%save_defaults,
14811: passwords => \%newvalues,
14812: );
14813: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14814:
14815: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14816: if ($putresult eq 'ok') {
14817: if (keys(%changes) > 0) {
14818: $resulttext = &mt('Changes made: ').'<ul>';
14819: foreach my $key ('reset','intauth','rules','crsownerchg') {
14820: if ($changes{$key}) {
14821: unless ($key eq 'intauth') {
14822: $updateconf = 1;
14823: }
14824: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14825: if ($key eq 'reset') {
14826: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14827: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14828: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14829: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 14830: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
14831: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
14832: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
14833: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
14834: }
1.160.6.98 raeburn 14835: } else {
14836: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14837: }
14838: if ($confighash{'passwords'}{'resetlink'}) {
14839: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14840: } else {
14841: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14842: &mt('Will default to 2 hours').'</li>';
14843: }
14844: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14845: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14846: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14847: } else {
14848: my $casesens;
14849: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14850: if ($type eq 'default') {
14851: $casesens .= $othertitle.', ';
14852: } elsif ($usertypes->{$type} ne '') {
14853: $casesens .= $usertypes->{$type}.', ';
14854: }
14855: }
14856: $casesens =~ s/\Q, \E$//;
14857: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14858: }
14859: } else {
14860: $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>';
14861: }
14862: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14863: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14864: } else {
14865: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14866: }
14867: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14868: my $output;
14869: if (ref($types) eq 'ARRAY') {
14870: foreach my $type (@{$types}) {
14871: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14872: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14873: $output .= $usertypes->{$type}.' -- '.&mt('none');
14874: } else {
14875: $output .= $usertypes->{$type}.' -- '.
14876: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14877: }
14878: }
14879: }
14880: }
14881: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14882: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14883: $output .= $othertitle.' -- '.&mt('none');
14884: } else {
14885: $output .= $othertitle.' -- '.
14886: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14887: }
14888: }
14889: if ($output) {
14890: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14891: } else {
14892: $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>';
14893: }
14894: } else {
14895: $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>';
14896: }
14897: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14898: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14899: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14900: } else {
14901: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14902: }
14903: } else {
1.160.6.110 raeburn 14904: $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 14905: }
14906: if ($confighash{'passwords'}{'resetremove'}) {
14907: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14908: } else {
14909: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14910: }
14911: if ($confighash{'passwords'}{'resetcustom'}) {
14912: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 14913: &mt('custom text'),600,500,undef,undef,
14914: undef,undef,'background-color:#ffffff');
14915: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 14916: } else {
14917: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14918: }
14919: } elsif ($key eq 'intauth') {
14920: foreach my $item ('cost','switch','check') {
14921: my $value = $save_defaults{$key.'_'.$item};
14922: if ($item eq 'switch') {
14923: my %optiondesc = &Apache::lonlocal::texthash (
14924: 0 => 'No',
14925: 1 => 'Yes',
14926: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14927: );
14928: if ($value =~ /^(0|1|2)$/) {
14929: $value = $optiondesc{$value};
14930: } else {
14931: $value = &mt('none -- defaults to No');
14932: }
14933: } elsif ($item eq 'check') {
14934: my %optiondesc = &Apache::lonlocal::texthash (
14935: 0 => 'No',
14936: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14937: 2 => 'Yes, disallow login if stored cost is less than domain default',
14938: );
14939: if ($value =~ /^(0|1|2)$/) {
14940: $value = $optiondesc{$value};
14941: } else {
14942: $value = &mt('none -- defaults to No');
14943: }
14944: }
14945: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14946: }
14947: } elsif ($key eq 'rules') {
14948: foreach my $rule ('min','max','numsaved') {
14949: if ($confighash{'passwords'}{$rule} eq '') {
14950: if ($rule eq 'min') {
14951: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 14952: ' '.&mt('Default of [_1] will be used',
14953: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 14954: } else {
14955: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14956: }
14957: } else {
14958: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14959: }
14960: }
1.160.6.104 raeburn 14961: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
14962: if (@{$confighash{'passwords'}{'chars'}} > 0) {
14963: my %rulenames = &Apache::lonlocal::texthash(
14964: uc => 'At least one upper case letter',
14965: lc => 'At least one lower case letter',
14966: num => 'At least one number',
14967: spec => 'At least one non-alphanumeric',
14968: );
14969: my $needed = '<ul><li>'.
14970: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
14971: '</li></ul>';
14972: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14973: } else {
14974: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14975: }
14976: } else {
14977: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14978: }
1.160.6.98 raeburn 14979: } elsif ($key eq 'crsownerchg') {
14980: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14981: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14982: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14983: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14984: } else {
14985: my %crsownerstr;
14986: foreach my $item ('by','for') {
14987: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14988: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14989: if ($type eq 'default') {
14990: $crsownerstr{$item} .= $othertitle.', ';
14991: } elsif ($usertypes->{$type} ne '') {
14992: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14993: }
14994: }
14995: $crsownerstr{$item} =~ s/\Q, \E$//;
14996: }
14997: }
14998: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14999: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
15000: }
15001: } else {
15002: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15003: }
15004: }
15005: $resulttext .= '</ul></li>';
15006: }
15007: }
15008: $resulttext .= '</ul>';
15009: } else {
15010: $resulttext = &mt('No changes made to password settings');
15011: }
15012: my $cachetime = 24*60*60;
15013: if ($updatedefaults) {
15014: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15015: if (ref($lastactref) eq 'HASH') {
15016: $lastactref->{'domdefaults'} = 1;
15017: }
15018: }
15019: if ($updateconf) {
15020: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
15021: if (ref($lastactref) eq 'HASH') {
15022: $lastactref->{'passwdconf'} = 1;
15023: }
15024: }
15025: } else {
15026: $resulttext = '<span class="LC_error">'.
15027: &mt('An error occurred: [_1]',$putresult).'</span>';
15028: }
15029: if ($errors) {
15030: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15031: $errors.'</ul></p>';
15032: }
15033: return $resulttext;
15034: }
15035:
1.160.6.118.2 5(raebur 15036:2): sub password_rule_changes {
15037:2): my ($prefix,$newvalues,$current,$changes) = @_;
15038:2): return unless ((ref($newvalues) eq 'HASH') &&
15039:2): (ref($current) eq 'HASH') &&
15040:2): (ref($changes) eq 'HASH'));
15041:2): my (@rules,%staticdefaults);
15042:2): if ($prefix eq 'passwords') {
15043:2): @rules = ('min','max','numsaved');
15044:2): } elsif ($prefix eq 'secrets') {
15045:2): @rules = ('min','max');
15046:2): }
15047:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
15048:2): foreach my $rule (@rules) {
15049:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
15050:2): my $ruleok;
15051:2): if ($rule eq 'min') {
15052:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
15053:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
15054:2): $ruleok = 1;
15055:2): }
15056:2): }
15057:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
15058:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
15059:2): $ruleok = 1;
15060:2): }
15061:2): if ($ruleok) {
15062:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
15063:2): if (exists($current->{$rule})) {
15064:2): if ($newvalues->{$rule} ne $current->{$rule}) {
15065:2): $changes->{'rules'} = 1;
15066:2): }
15067:2): } elsif ($rule eq 'min') {
15068:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
15069:2): $changes->{'rules'} = 1;
15070:2): }
15071:2): } else {
15072:2): $changes->{'rules'} = 1;
15073:2): }
15074:2): } elsif (exists($current->{$rule})) {
15075:2): $changes->{'rules'} = 1;
15076:2): }
15077:2): }
15078:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
15079:2): my @chars;
15080:2): foreach my $item (sort(@posschars)) {
15081:2): if ($item =~ /^(uc|lc|num|spec)$/) {
15082:2): push(@chars,$item);
15083:2): }
15084:2): }
15085:2): $newvalues->{'chars'} = \@chars;
15086:2): unless ($changes->{'rules'}) {
15087:2): if (ref($current->{'chars'}) eq 'ARRAY') {
15088:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
15089:2): if (@diffs > 0) {
15090:2): $changes->{'rules'} = 1;
15091:2): }
15092:2): } else {
15093:2): if (@chars > 0) {
15094:2): $changes->{'rules'} = 1;
15095:2): }
15096:2): }
15097:2): }
15098:2): return;
15099:2): }
15100:2):
1.28 raeburn 15101: sub modify_usercreation {
1.27 raeburn 15102: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15103: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 15104: my $warningmsg;
1.27 raeburn 15105: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15106: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 15107: if ($key eq 'cancreate') {
15108: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15109: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 15110: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 15111: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 15112: } else {
15113: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 15114: }
1.50 raeburn 15115: }
1.43 raeburn 15116: }
1.160.6.34 raeburn 15117: } elsif ($key eq 'email_rule') {
15118: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15119: } else {
15120: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 15121: }
15122: }
1.34 raeburn 15123: }
1.160.6.34 raeburn 15124: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
15125: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
15126: my @contexts = ('author','course','requestcrs');
15127: foreach my $item(@contexts) {
15128: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 15129: }
1.34 raeburn 15130: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15131: foreach my $item (@contexts) {
1.160.6.34 raeburn 15132: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15133: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 15134: }
1.27 raeburn 15135: }
1.34 raeburn 15136: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15137: foreach my $item (@contexts) {
1.43 raeburn 15138: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 15139: if ($cancreate{$item} ne 'any') {
15140: push(@{$changes{'cancreate'}},$item);
15141: }
15142: } else {
15143: if ($cancreate{$item} ne 'none') {
15144: push(@{$changes{'cancreate'}},$item);
15145: }
1.27 raeburn 15146: }
15147: }
15148: } else {
1.43 raeburn 15149: foreach my $item (@contexts) {
1.34 raeburn 15150: push(@{$changes{'cancreate'}},$item);
15151: }
1.27 raeburn 15152: }
1.34 raeburn 15153:
1.27 raeburn 15154: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15155: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15156: if (!grep(/^\Q$type\E$/,@username_rule)) {
15157: push(@{$changes{'username_rule'}},$type);
15158: }
15159: }
15160: foreach my $type (@username_rule) {
15161: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15162: push(@{$changes{'username_rule'}},$type);
15163: }
15164: }
15165: } else {
15166: push(@{$changes{'username_rule'}},@username_rule);
15167: }
15168:
1.32 raeburn 15169: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15170: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15171: if (!grep(/^\Q$type\E$/,@id_rule)) {
15172: push(@{$changes{'id_rule'}},$type);
15173: }
15174: }
15175: foreach my $type (@id_rule) {
15176: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15177: push(@{$changes{'id_rule'}},$type);
15178: }
15179: }
15180: } else {
15181: push(@{$changes{'id_rule'}},@id_rule);
15182: }
15183:
1.43 raeburn 15184: my @authen_contexts = ('author','course','domain');
1.28 raeburn 15185: my @authtypes = ('int','krb4','krb5','loc');
15186: my %authhash;
1.43 raeburn 15187: foreach my $item (@authen_contexts) {
1.28 raeburn 15188: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15189: foreach my $auth (@authtypes) {
15190: if (grep(/^\Q$auth\E$/,@authallowed)) {
15191: $authhash{$item}{$auth} = 1;
15192: } else {
15193: $authhash{$item}{$auth} = 0;
15194: }
15195: }
15196: }
15197: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 15198: foreach my $item (@authen_contexts) {
1.28 raeburn 15199: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15200: foreach my $auth (@authtypes) {
15201: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15202: push(@{$changes{'authtypes'}},$item);
15203: last;
15204: }
15205: }
15206: }
15207: }
15208: } else {
1.43 raeburn 15209: foreach my $item (@authen_contexts) {
1.28 raeburn 15210: push(@{$changes{'authtypes'}},$item);
15211: }
15212: }
15213:
1.160.6.34 raeburn 15214: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15215: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15216: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15217: $save_usercreate{'id_rule'} = \@id_rule;
15218: $save_usercreate{'username_rule'} = \@username_rule,
15219: $save_usercreate{'authtypes'} = \%authhash;
15220:
1.27 raeburn 15221: my %usercreation_hash = (
1.160.6.34 raeburn 15222: usercreation => \%save_usercreate,
15223: );
1.27 raeburn 15224:
15225: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15226: $dom);
1.50 raeburn 15227:
1.160.6.34 raeburn 15228: if ($putresult eq 'ok') {
15229: if (keys(%changes) > 0) {
15230: $resulttext = &mt('Changes made:').'<ul>';
15231: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15232: my %lt = &usercreation_types();
15233: foreach my $type (@{$changes{'cancreate'}}) {
15234: my $chgtext = $lt{$type}.', ';
15235: if ($cancreate{$type} eq 'none') {
15236: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15237: } elsif ($cancreate{$type} eq 'any') {
15238: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15239: } elsif ($cancreate{$type} eq 'official') {
15240: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15241: } elsif ($cancreate{$type} eq 'unofficial') {
15242: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15243: }
15244: $resulttext .= '<li>'.$chgtext.'</li>';
15245: }
15246: }
15247: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15248: my ($rules,$ruleorder) =
15249: &Apache::lonnet::inst_userrules($dom,'username');
15250: my $chgtext = '<ul>';
15251: foreach my $type (@username_rule) {
15252: if (ref($rules->{$type}) eq 'HASH') {
15253: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15254: }
15255: }
15256: $chgtext .= '</ul>';
15257: if (@username_rule > 0) {
15258: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15259: } else {
15260: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15261: }
15262: }
15263: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15264: my ($idrules,$idruleorder) =
15265: &Apache::lonnet::inst_userrules($dom,'id');
15266: my $chgtext = '<ul>';
15267: foreach my $type (@id_rule) {
15268: if (ref($idrules->{$type}) eq 'HASH') {
15269: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15270: }
15271: }
15272: $chgtext .= '</ul>';
15273: if (@id_rule > 0) {
15274: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15275: } else {
15276: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15277: }
15278: }
15279: my %authname = &authtype_names();
15280: my %context_title = &context_names();
15281: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15282: my $chgtext = '<ul>';
15283: foreach my $type (@{$changes{'authtypes'}}) {
15284: my @allowed;
15285: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15286: foreach my $auth (@authtypes) {
15287: if ($authhash{$type}{$auth}) {
15288: push(@allowed,$authname{$auth});
15289: }
15290: }
15291: if (@allowed > 0) {
15292: $chgtext .= join(', ',@allowed).'</li>';
15293: } else {
15294: $chgtext .= &mt('none').'</li>';
15295: }
15296: }
15297: $chgtext .= '</ul>';
15298: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15299: $resulttext .= '</li>';
15300: }
15301: $resulttext .= '</ul>';
15302: } else {
15303: $resulttext = &mt('No changes made to user creation settings');
15304: }
15305: } else {
15306: $resulttext = '<span class="LC_error">'.
15307: &mt('An error occurred: [_1]',$putresult).'</span>';
15308: }
15309: if ($warningmsg ne '') {
15310: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15311: }
15312: return $resulttext;
15313: }
15314:
15315: sub modify_selfcreation {
1.160.6.93 raeburn 15316: my ($dom,$lastactref,%domconfig) = @_;
15317: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15318: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15319: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15320: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15321: if (ref($typesref) eq 'ARRAY') {
15322: @types = @{$typesref};
15323: }
15324: if (ref($usertypesref) eq 'HASH') {
15325: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 15326: }
1.160.6.93 raeburn 15327: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 15328: #
15329: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15330: #
15331: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15332: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15333: if ($key eq 'cancreate') {
15334: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15335: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15336: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 15337: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15338: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15339: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15340: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
15341: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 15342: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15343: } else {
15344: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15345: }
15346: }
15347: }
15348: } elsif ($key eq 'email_rule') {
15349: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15350: } else {
15351: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15352: }
15353: }
15354: }
15355: #
15356: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15357: #
15358: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15359: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15360: if ($key eq 'selfcreate') {
15361: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15362: } else {
15363: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15364: }
15365: }
15366: }
1.160.6.93 raeburn 15367: #
15368: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15369: #
15370: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15371: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15372: if ($key eq 'inststatusguest') {
15373: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15374: } else {
15375: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15376: }
15377: }
15378: }
1.160.6.34 raeburn 15379:
15380: my @contexts = ('selfcreate');
15381: @{$cancreate{'selfcreate'}} = ();
15382: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 15383: if (@types) {
15384: @{$cancreate{'statustocreate'}} = ();
15385: }
1.160.6.40 raeburn 15386: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 15387: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 15388: %{$cancreate{'emailverified'}} = ();
15389: %{$cancreate{'emailoptions'}} = ();
15390: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 15391: my %selfcreatetypes = (
15392: sso => 'users authenticated by institutional single sign on',
15393: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 15394: email => 'users verified by e-mail',
1.50 raeburn 15395: );
1.160.6.34 raeburn 15396: #
15397: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15398: # is permitted.
15399: #
1.160.6.40 raeburn 15400:
1.160.6.93 raeburn 15401: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 15402:
1.160.6.93 raeburn 15403: my (@statuses,%email_rule);
1.160.6.35 raeburn 15404: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 15405: if ($item eq 'email') {
1.160.6.40 raeburn 15406: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 15407: if (@types) {
15408: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15409: foreach my $status (@poss_statuses) {
15410: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15411: push(@statuses,$status);
15412: }
15413: }
15414: $save_inststatus{'inststatusguest'} = \@statuses;
15415: } else {
15416: push(@statuses,'default');
15417: }
15418: if (@statuses) {
15419: my %curr_rule;
15420: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15421: foreach my $type (@statuses) {
15422: $curr_rule{$type} = $curr_usercreation{'email_rule'};
15423: }
15424: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15425: foreach my $type (@statuses) {
15426: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15427: }
15428: }
15429: push(@{$cancreate{'selfcreate'}},'email');
15430: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15431: my %curremaildom;
15432: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15433: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15434: }
15435: foreach my $type (@statuses) {
15436: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15437: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15438: }
15439: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15440: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15441: }
15442: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15443: #
15444: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15445: #
15446: my $chosen = $1;
15447: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15448: my $emaildom;
15449: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15450: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15451: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15452: if (ref($curremaildom{$type}) eq 'HASH') {
15453: if (exists($curremaildom{$type}{$chosen})) {
15454: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15455: push(@{$changes{'cancreate'}},'emaildomain');
15456: }
15457: } elsif ($emaildom ne '') {
15458: push(@{$changes{'cancreate'}},'emaildomain');
15459: }
15460: } elsif ($emaildom ne '') {
15461: push(@{$changes{'cancreate'}},'emaildomain');
15462: }
15463: }
15464: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15465: } elsif ($chosen eq 'custom') {
15466: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15467: $email_rule{$type} = [];
15468: if (ref($emailrules) eq 'HASH') {
15469: foreach my $rule (@possemail_rules) {
15470: if (exists($emailrules->{$rule})) {
15471: push(@{$email_rule{$type}},$rule);
15472: }
15473: }
15474: }
15475: if (@{$email_rule{$type}}) {
15476: $cancreate{'emailoptions'}{$type} = 'custom';
15477: if (ref($curr_rule{$type}) eq 'ARRAY') {
15478: if (@{$curr_rule{$type}} > 0) {
15479: foreach my $rule (@{$curr_rule{$type}}) {
15480: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15481: push(@{$changes{'email_rule'}},$type);
15482: }
15483: }
15484: }
15485: foreach my $type (@{$email_rule{$type}}) {
15486: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15487: push(@{$changes{'email_rule'}},$type);
15488: }
15489: }
15490: } else {
15491: push(@{$changes{'email_rule'}},$type);
15492: }
15493: }
15494: } else {
15495: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15496: }
15497: }
15498: }
15499: if (@types) {
15500: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15501: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15502: if (@changed) {
15503: push(@{$changes{'inststatus'}},'inststatusguest');
15504: }
15505: } else {
15506: push(@{$changes{'inststatus'}},'inststatusguest');
15507: }
15508: }
15509: } else {
15510: delete($env{'form.cancreate_email'});
15511: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15512: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15513: push(@{$changes{'inststatus'}},'inststatusguest');
15514: }
15515: }
15516: }
15517: } else {
15518: $save_inststatus{'inststatusguest'} = [];
15519: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15520: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15521: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 15522: }
15523: }
1.160.6.34 raeburn 15524: }
15525: } else {
15526: if ($env{'form.cancreate_'.$item}) {
15527: push(@{$cancreate{'selfcreate'}},$item);
15528: }
15529: }
15530: }
1.160.6.93 raeburn 15531: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 15532: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15533: #
1.160.6.35 raeburn 15534: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15535: # 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 15536: #
1.160.6.40 raeburn 15537:
1.160.6.48 raeburn 15538: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 15539: push(@contexts,'emailusername');
1.160.6.93 raeburn 15540: if (@statuses) {
15541: foreach my $type (@statuses) {
1.160.6.35 raeburn 15542: if (ref($infofields) eq 'ARRAY') {
15543: foreach my $field (@{$infofields}) {
15544: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15545: $cancreate{'emailusername'}{$type}{$field} = $1;
15546: }
15547: }
1.160.6.34 raeburn 15548: }
15549: }
15550: }
15551: #
15552: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 15553: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 15554: #
15555:
15556: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15557: @approvalnotify = sort(@approvalnotify);
15558: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15559: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15560: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15561: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15562: push(@{$changes{'cancreate'}},'notify');
15563: }
15564: } else {
15565: if ($cancreate{'notify'}{'approval'}) {
15566: push(@{$changes{'cancreate'}},'notify');
15567: }
15568: }
15569: } elsif ($cancreate{'notify'}{'approval'}) {
15570: push(@{$changes{'cancreate'}},'notify');
15571: }
15572:
15573: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15574: }
15575: #
1.160.6.40 raeburn 15576: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 15577: # institutional log-in.
15578: #
15579: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15580: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15581: ($domdefaults{'auth_def'} eq 'localauth'))) {
15582: $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.').' '.
15583: &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.');
15584: }
15585: }
15586: my @fields = ('lastname','firstname','middlename','generation',
15587: 'permanentemail','id');
1.160.6.44 raeburn 15588: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 15589: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15590: #
15591: # Where usernames may created for institutional log-in and/or institutional single sign on:
15592: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15593: # may self-create accounts
15594: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15595: # which the user may supply, if institutional data is unavailable.
15596: #
15597: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 15598: if (@types) {
15599: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15600: push(@contexts,'statustocreate');
15601: foreach my $type (@types) {
1.160.6.34 raeburn 15602: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15603: foreach my $field (@fields) {
15604: if (grep(/^\Q$field\E$/,@modifiable)) {
15605: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15606: } else {
15607: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15608: }
15609: }
15610: }
15611: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 15612: foreach my $type (@types) {
1.160.6.34 raeburn 15613: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15614: foreach my $field (@fields) {
15615: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15616: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15617: push(@{$changes{'selfcreate'}},$type);
15618: last;
15619: }
15620: }
15621: }
15622: }
15623: } else {
1.160.6.93 raeburn 15624: foreach my $type (@types) {
1.160.6.34 raeburn 15625: push(@{$changes{'selfcreate'}},$type);
15626: }
15627: }
15628: }
1.160.6.44 raeburn 15629: foreach my $field (@shibfields) {
15630: if ($env{'form.shibenv_'.$field} ne '') {
15631: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15632: }
15633: }
15634: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15635: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15636: foreach my $field (@shibfields) {
15637: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15638: push(@{$changes{'cancreate'}},'shibenv');
15639: }
15640: }
15641: } else {
15642: foreach my $field (@shibfields) {
15643: if ($env{'form.shibenv_'.$field}) {
15644: push(@{$changes{'cancreate'}},'shibenv');
15645: last;
15646: }
15647: }
15648: }
15649: }
1.160.6.34 raeburn 15650: }
15651: foreach my $item (@contexts) {
15652: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15653: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15654: if (ref($cancreate{$item}) eq 'ARRAY') {
15655: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15656: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15657: push(@{$changes{'cancreate'}},$item);
15658: }
15659: }
15660: }
15661: }
15662: if (ref($cancreate{$item}) eq 'ARRAY') {
15663: foreach my $type (@{$cancreate{$item}}) {
15664: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15665: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15666: push(@{$changes{'cancreate'}},$item);
15667: }
15668: }
15669: }
15670: }
15671: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15672: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 15673: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15674: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15675: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15676: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 15677: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15678: push(@{$changes{'cancreate'}},$item);
15679: }
15680: }
15681: }
1.160.6.93 raeburn 15682: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15683: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15684: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15685: push(@{$changes{'cancreate'}},$item);
15686: }
1.160.6.34 raeburn 15687: }
15688: }
15689: }
1.160.6.93 raeburn 15690: foreach my $type (keys(%{$cancreate{$item}})) {
15691: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15692: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15693: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15694: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 15695: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15696: push(@{$changes{'cancreate'}},$item);
15697: }
15698: }
15699: } else {
15700: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15701: push(@{$changes{'cancreate'}},$item);
15702: }
15703: }
15704: }
1.160.6.93 raeburn 15705: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15706: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15707: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15708: push(@{$changes{'cancreate'}},$item);
15709: }
1.160.6.34 raeburn 15710: }
15711: }
15712: }
15713: }
15714: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15715: if (ref($cancreate{$item}) eq 'ARRAY') {
15716: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15717: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15718: push(@{$changes{'cancreate'}},$item);
15719: }
15720: }
1.160.6.93 raeburn 15721: }
15722: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15723: if (ref($cancreate{$item}) eq 'HASH') {
15724: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15725: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 15726: }
15727: }
15728: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 15729: if (ref($cancreate{$item}) eq 'HASH') {
15730: foreach my $type (keys(%{$cancreate{$item}})) {
15731: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15732: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15733: if ($cancreate{$item}{$type}{$field}) {
15734: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15735: push(@{$changes{'cancreate'}},$item);
15736: }
15737: last;
15738: }
15739: }
15740: }
15741: }
1.160.6.34 raeburn 15742: }
15743: }
15744: }
15745: #
15746: # Populate %save_usercreate hash with updates to self-creation configuration.
15747: #
15748: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15749: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 15750: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 15751: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15752: if (ref($cancreate{'notify'}) eq 'HASH') {
15753: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15754: }
1.160.6.40 raeburn 15755: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15756: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15757: }
1.160.6.93 raeburn 15758: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15759: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15760: }
15761: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15762: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15763: }
15764: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15765: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15766: }
1.160.6.34 raeburn 15767: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15768: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15769: }
1.160.6.44 raeburn 15770: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15771: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15772: }
1.160.6.34 raeburn 15773: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 15774: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 15775:
15776: my %userconfig_hash = (
15777: usercreation => \%save_usercreate,
15778: usermodification => \%save_usermodify,
1.160.6.93 raeburn 15779: inststatus => \%save_inststatus,
1.160.6.34 raeburn 15780: );
1.160.6.93 raeburn 15781:
1.160.6.34 raeburn 15782: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15783: $dom);
15784: #
1.160.6.93 raeburn 15785: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 15786: #
1.27 raeburn 15787: if ($putresult eq 'ok') {
15788: if (keys(%changes) > 0) {
15789: $resulttext = &mt('Changes made:').'<ul>';
15790: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 15791: my %lt = &selfcreation_types();
1.34 raeburn 15792: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 15793: my $chgtext = '';
1.45 raeburn 15794: if ($type eq 'selfcreate') {
1.50 raeburn 15795: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 15796: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15797: } else {
1.160.6.34 raeburn 15798: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15799: '<ul>';
1.50 raeburn 15800: foreach my $case (@{$cancreate{$type}}) {
15801: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15802: }
15803: $chgtext .= '</ul>';
1.100 raeburn 15804: if (ref($cancreate{$type}) eq 'ARRAY') {
15805: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15806: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15807: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 15808: $chgtext .= '<span class="LC_warning">'.
15809: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15810: '</span><br />';
1.100 raeburn 15811: }
15812: }
15813: }
1.160.6.93 raeburn 15814: if (grep(/^email$/,@{$cancreate{$type}})) {
15815: if (!@statuses) {
15816: $chgtext .= '<span class="LC_warning">'.
15817: &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.").
15818: '</span><br />';
15819:
15820: }
15821: }
1.100 raeburn 15822: }
1.43 raeburn 15823: }
1.160.6.44 raeburn 15824: } elsif ($type eq 'shibenv') {
15825: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 15826: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 15827: } else {
15828: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15829: '<ul>';
15830: foreach my $field (@shibfields) {
15831: next if ($cancreate{$type}{$field} eq '');
15832: if ($field eq 'inststatus') {
15833: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15834: } else {
15835: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15836: }
15837: }
15838: $chgtext .= '</ul>';
1.160.6.93 raeburn 15839: }
1.93 raeburn 15840: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15841: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15842: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15843: if (@{$cancreate{'selfcreate'}} > 0) {
15844: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15845: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15846: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 15847: $chgtext .= '<br />'.
15848: '<span class="LC_warning">'.
15849: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15850: '</span>';
15851: }
1.160.6.93 raeburn 15852: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15853: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15854: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15855: } else {
15856: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15857: }
15858: $chgtext .= '<ul>';
15859: foreach my $case (@{$cancreate{$type}}) {
15860: if ($case eq 'default') {
15861: $chgtext .= '<li>'.$othertitle.'</li>';
15862: } else {
1.160.6.93 raeburn 15863: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15864: }
15865: }
1.100 raeburn 15866: $chgtext .= '</ul>';
15867: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 15868: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 15869: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15870: '</span>';
1.100 raeburn 15871: }
15872: }
15873: } else {
15874: if (@{$cancreate{$type}} == 0) {
15875: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15876: } else {
15877: $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 15878: }
15879: }
1.160.6.93 raeburn 15880: $chgtext .= '<br />';
1.93 raeburn 15881: }
1.160.6.40 raeburn 15882: } elsif ($type eq 'selfcreateprocessing') {
15883: my %choices = &Apache::lonlocal::texthash (
15884: automatic => 'Automatic approval',
15885: approval => 'Queued for approval',
15886: );
1.160.6.93 raeburn 15887: if (@types) {
15888: if (@statuses) {
15889: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
15890: '<ul>';
15891: foreach my $status (@statuses) {
15892: if ($status eq 'default') {
15893: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15894: } else {
15895: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15896: }
15897: }
15898: $chgtext .= '</ul>';
15899: }
15900: } else {
15901: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15902: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15903: }
15904: } elsif ($type eq 'emailverified') {
15905: my %options = &Apache::lonlocal::texthash (
15906: all => 'Same as e-mail',
15907: first => 'Omit @domain',
15908: free => 'Free to choose',
15909: );
15910: if (@types) {
15911: if (@statuses) {
15912: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15913: '<ul>';
15914: foreach my $status (@statuses) {
15915: if ($status eq 'default') {
15916: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15917: } else {
15918: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15919: }
15920: }
15921: $chgtext .= '</ul>';
15922: }
1.160.6.40 raeburn 15923: } else {
1.160.6.93 raeburn 15924: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
15925: $options{$cancreate{'emailverified'}{'default'}});
15926: }
15927: } elsif ($type eq 'emailoptions') {
15928: my %options = &Apache::lonlocal::texthash (
15929: any => 'Any e-mail',
15930: inst => 'Institutional only',
15931: noninst => 'Non-institutional only',
15932: custom => 'Custom restrictions',
15933: );
15934: if (@types) {
15935: if (@statuses) {
15936: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15937: '<ul>';
15938: foreach my $status (@statuses) {
15939: if ($type eq 'default') {
15940: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15941: } else {
15942: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15943: }
15944: }
15945: $chgtext .= '</ul>';
15946: }
15947: } else {
15948: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15949: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15950: } else {
15951: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15952: $options{$cancreate{'emailoptions'}{'default'}});
15953: }
15954: }
15955: } elsif ($type eq 'emaildomain') {
15956: my $output;
15957: if (@statuses) {
15958: foreach my $type (@statuses) {
15959: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15960: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15961: if ($type eq 'default') {
15962: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15963: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15964: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15965: } else {
15966: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15967: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15968: }
15969: } else {
15970: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15971: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15972: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15973: } else {
15974: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15975: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15976: }
15977: }
15978: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15979: if ($type eq 'default') {
15980: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15981: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15982: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15983: } else {
15984: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15985: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15986: }
15987: } else {
15988: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15989: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15990: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15991: } else {
15992: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15993: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15994: }
15995: }
15996: }
15997: }
15998: }
15999: }
16000: if ($output ne '') {
16001: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
16002: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 16003: }
1.160.6.5 raeburn 16004: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 16005: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 16006: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
16007: } else {
16008: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 16009: if ($captchas{$savecaptcha{$type}}) {
16010: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 16011: } else {
16012: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
16013: }
16014: }
16015: } elsif ($type eq 'recaptchakeys') {
16016: my ($privkey,$pubkey);
1.160.6.34 raeburn 16017: if (ref($savecaptcha{$type}) eq 'HASH') {
16018: $pubkey = $savecaptcha{$type}{'public'};
16019: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 16020: }
16021: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
16022: if (!$pubkey) {
16023: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
16024: } else {
16025: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
16026: }
16027: if (!$privkey) {
16028: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
16029: } else {
16030: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
16031: }
16032: $chgtext .= '</ul>';
1.160.6.69 raeburn 16033: } elsif ($type eq 'recaptchaversion') {
16034: if ($savecaptcha{'captcha'} eq 'recaptcha') {
16035: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
16036: }
1.160.6.34 raeburn 16037: } elsif ($type eq 'emailusername') {
16038: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 16039: if (@statuses) {
16040: foreach my $type (@statuses) {
1.160.6.35 raeburn 16041: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
16042: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 16043: $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 16044: '<ul>';
16045: foreach my $field (@{$infofields}) {
16046: if ($cancreate{'emailusername'}{$type}{$field}) {
16047: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
16048: }
16049: }
1.160.6.50 raeburn 16050: $chgtext .= '</ul>';
16051: } else {
1.160.6.93 raeburn 16052: $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 16053: }
16054: } else {
1.160.6.93 raeburn 16055: $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 16056: }
16057: }
16058: }
16059: }
16060: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 16061: my $numapprove = 0;
1.160.6.34 raeburn 16062: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16063: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
16064: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 16065: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
16066: $numapprove ++;
1.160.6.34 raeburn 16067: }
16068: }
1.43 raeburn 16069: }
1.160.6.93 raeburn 16070: unless ($numapprove) {
16071: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
16072: }
1.34 raeburn 16073: }
1.160.6.34 raeburn 16074: if ($chgtext) {
16075: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 16076: }
16077: }
16078: }
1.160.6.93 raeburn 16079: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 16080: my ($emailrules,$emailruleorder) =
16081: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 16082: foreach my $type (@{$changes{'email_rule'}}) {
16083: if (ref($email_rule{$type}) eq 'ARRAY') {
16084: my $chgtext = '<ul>';
16085: foreach my $rule (@{$email_rule{$type}}) {
16086: if (ref($emailrules->{$rule}) eq 'HASH') {
16087: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16088: }
16089: }
16090: $chgtext .= '</ul>';
16091: my $typename;
16092: if (@types) {
16093: if ($type eq 'default') {
16094: $typename = $othertitle;
16095: } else {
16096: $typename = $usertypes{$type};
16097: }
16098: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16099: }
16100: if (@{$email_rule{$type}} > 0) {
16101: $resulttext .= '<li>'.
16102: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16103: $usertypes{$type}).
16104: $chgtext.
16105: '</li>';
16106: } else {
16107: $resulttext .= '<li>'.
16108: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16109: '</li>'.
16110: &mt('(Affiliation: [_1])',$typename);
16111: }
1.43 raeburn 16112: }
16113: }
1.160.6.93 raeburn 16114: }
16115: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16116: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16117: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16118: my $chgtext = '<ul>';
16119: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16120: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16121: }
16122: $chgtext .= '</ul>';
16123: $resulttext .= '<li>'.
16124: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16125: $chgtext.
16126: '</li>';
16127: } else {
16128: $resulttext .= '<li>'.
16129: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16130: '</li>';
16131: }
1.43 raeburn 16132: }
16133: }
1.160.6.34 raeburn 16134: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16135: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16136: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16137: foreach my $type (@{$changes{'selfcreate'}}) {
16138: my $typename = $type;
1.160.6.93 raeburn 16139: if (keys(%usertypes) > 0) {
16140: if ($usertypes{$type} ne '') {
16141: $typename = $usertypes{$type};
1.28 raeburn 16142: }
16143: }
1.160.6.34 raeburn 16144: my @modifiable;
16145: $resulttext .= '<li>'.
16146: &mt('Self-creation of account by users with status: [_1]',
16147: '<span class="LC_cusr_emph">'.$typename.'</span>').
16148: ' - '.&mt('modifiable fields (if institutional data blank): ');
16149: foreach my $field (@fields) {
16150: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16151: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
16152: }
16153: }
16154: if (@modifiable > 0) {
16155: $resulttext .= join(', ',@modifiable);
1.43 raeburn 16156: } else {
1.160.6.34 raeburn 16157: $resulttext .= &mt('none');
1.43 raeburn 16158: }
1.160.6.34 raeburn 16159: $resulttext .= '</li>';
1.28 raeburn 16160: }
1.160.6.34 raeburn 16161: $resulttext .= '</ul></li>';
1.28 raeburn 16162: }
1.27 raeburn 16163: $resulttext .= '</ul>';
1.160.6.93 raeburn 16164: my $cachetime = 24*60*60;
16165: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16166: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16167: if (ref($lastactref) eq 'HASH') {
16168: $lastactref->{'domdefaults'} = 1;
16169: }
1.27 raeburn 16170: } else {
1.160.6.34 raeburn 16171: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 16172: }
16173: } else {
16174: $resulttext = '<span class="LC_error">'.
1.23 raeburn 16175: &mt('An error occurred: [_1]',$putresult).'</span>';
16176: }
1.43 raeburn 16177: if ($warningmsg ne '') {
16178: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16179: }
1.23 raeburn 16180: return $resulttext;
16181: }
16182:
1.160.6.5 raeburn 16183: sub process_captcha {
1.160.6.104 raeburn 16184: my ($container,$changes,$newsettings,$currsettings) = @_;
16185: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 16186: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16187: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16188: $newsettings->{'captcha'} = 'original';
16189: }
1.160.6.104 raeburn 16190: my %current;
16191: if (ref($currsettings) eq 'HASH') {
16192: %current = %{$currsettings};
16193: }
16194: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 16195: if ($container eq 'cancreate') {
16196: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16197: push(@{$changes->{'cancreate'}},'captcha');
16198: } elsif (!defined($changes->{'cancreate'})) {
16199: $changes->{'cancreate'} = ['captcha'];
16200: }
1.160.6.102 raeburn 16201: } elsif ($container eq 'passwords') {
16202: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16203: } else {
16204: $changes->{'captcha'} = 1;
16205: }
16206: }
1.160.6.69 raeburn 16207: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 16208: if ($newsettings->{'captcha'} eq 'recaptcha') {
16209: $newpub = $env{'form.'.$container.'_recaptchapub'};
16210: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 16211: $newpub =~ s/[^\w\-]//g;
16212: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 16213: $newsettings->{'recaptchakeys'} = {
16214: public => $newpub,
16215: private => $newpriv,
16216: };
1.160.6.69 raeburn 16217: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16218: $newversion =~ s/\D//g;
16219: if ($newversion ne '2') {
16220: $newversion = 1;
16221: }
16222: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 16223: }
1.160.6.104 raeburn 16224: if (ref($current{'recaptchakeys'}) eq 'HASH') {
16225: $currpub = $current{'recaptchakeys'}{'public'};
16226: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 16227: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16228: $newsettings->{'recaptchakeys'} = {
16229: public => '',
16230: private => '',
16231: }
16232: }
1.160.6.5 raeburn 16233: }
1.160.6.104 raeburn 16234: if ($current{'captcha'} eq 'recaptcha') {
16235: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 16236: if ($currversion ne '2') {
16237: $currversion = 1;
16238: }
16239: }
16240: if ($currversion ne $newversion) {
16241: if ($container eq 'cancreate') {
16242: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16243: push(@{$changes->{'cancreate'}},'recaptchaversion');
16244: } elsif (!defined($changes->{'cancreate'})) {
16245: $changes->{'cancreate'} = ['recaptchaversion'];
16246: }
1.160.6.102 raeburn 16247: } elsif ($container eq 'passwords') {
16248: $changes->{'reset'} = 1;
1.160.6.69 raeburn 16249: } else {
16250: $changes->{'recaptchaversion'} = 1;
16251: }
16252: }
1.160.6.5 raeburn 16253: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
16254: if ($container eq 'cancreate') {
16255: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16256: push(@{$changes->{'cancreate'}},'recaptchakeys');
16257: } elsif (!defined($changes->{'cancreate'})) {
16258: $changes->{'cancreate'} = ['recaptchakeys'];
16259: }
1.160.6.102 raeburn 16260: } elsif ($container eq 'passwords') {
16261: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16262: } else {
16263: $changes->{'recaptchakeys'} = 1;
16264: }
16265: }
16266: return;
16267: }
16268:
1.33 raeburn 16269: sub modify_usermodification {
16270: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16271: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16272: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16273: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 16274: if ($key eq 'selfcreate') {
16275: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16276: } else {
16277: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16278: }
1.33 raeburn 16279: }
16280: }
1.160.6.34 raeburn 16281: my @contexts = ('author','course');
1.33 raeburn 16282: my %context_title = (
16283: author => 'In author context',
16284: course => 'In course context',
16285: );
16286: my @fields = ('lastname','firstname','middlename','generation',
16287: 'permanentemail','id');
16288: my %roles = (
16289: author => ['ca','aa'],
16290: course => ['st','ep','ta','in','cr'],
16291: );
16292: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16293: foreach my $context (@contexts) {
16294: foreach my $role (@{$roles{$context}}) {
16295: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16296: foreach my $item (@fields) {
16297: if (grep(/^\Q$item\E$/,@modifiable)) {
16298: $modifyhash{$context}{$role}{$item} = 1;
16299: } else {
16300: $modifyhash{$context}{$role}{$item} = 0;
16301: }
16302: }
16303: }
16304: if (ref($curr_usermodification{$context}) eq 'HASH') {
16305: foreach my $role (@{$roles{$context}}) {
16306: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16307: foreach my $field (@fields) {
16308: if ($modifyhash{$context}{$role}{$field} ne
16309: $curr_usermodification{$context}{$role}{$field}) {
16310: push(@{$changes{$context}},$role);
16311: last;
16312: }
16313: }
16314: }
16315: }
16316: } else {
16317: foreach my $context (@contexts) {
16318: foreach my $role (@{$roles{$context}}) {
16319: push(@{$changes{$context}},$role);
16320: }
16321: }
16322: }
16323: }
16324: my %usermodification_hash = (
16325: usermodification => \%modifyhash,
16326: );
16327: my $putresult = &Apache::lonnet::put_dom('configuration',
16328: \%usermodification_hash,$dom);
16329: if ($putresult eq 'ok') {
16330: if (keys(%changes) > 0) {
16331: $resulttext = &mt('Changes made: ').'<ul>';
16332: foreach my $context (@contexts) {
16333: if (ref($changes{$context}) eq 'ARRAY') {
16334: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16335: if (ref($changes{$context}) eq 'ARRAY') {
16336: foreach my $role (@{$changes{$context}}) {
16337: my $rolename;
1.160.6.34 raeburn 16338: if ($role eq 'cr') {
16339: $rolename = &mt('Custom');
1.33 raeburn 16340: } else {
1.160.6.34 raeburn 16341: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 16342: }
16343: my @modifiable;
1.160.6.34 raeburn 16344: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 16345: foreach my $field (@fields) {
16346: if ($modifyhash{$context}{$role}{$field}) {
16347: push(@modifiable,$fieldtitles{$field});
16348: }
16349: }
16350: if (@modifiable > 0) {
16351: $resulttext .= join(', ',@modifiable);
16352: } else {
16353: $resulttext .= &mt('none');
16354: }
16355: $resulttext .= '</li>';
16356: }
16357: $resulttext .= '</ul></li>';
16358: }
16359: }
16360: }
16361: $resulttext .= '</ul>';
16362: } else {
16363: $resulttext = &mt('No changes made to user modification settings');
16364: }
16365: } else {
16366: $resulttext = '<span class="LC_error">'.
16367: &mt('An error occurred: [_1]',$putresult).'</span>';
16368: }
16369: return $resulttext;
16370: }
16371:
1.43 raeburn 16372: sub modify_defaults {
1.160.6.27 raeburn 16373: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 16374: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 16375: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 16376: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 16377: 'portal_def');
1.43 raeburn 16378: my @authtypes = ('internal','krb4','krb5','localauth');
16379: foreach my $item (@items) {
16380: $newvalues{$item} = $env{'form.'.$item};
16381: if ($item eq 'auth_def') {
16382: if ($newvalues{$item} ne '') {
16383: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16384: push(@errors,$item);
16385: }
16386: }
16387: } elsif ($item eq 'lang_def') {
16388: if ($newvalues{$item} ne '') {
16389: if ($newvalues{$item} =~ /^(\w+)/) {
16390: my $langcode = $1;
1.103 raeburn 16391: if ($langcode ne 'x_chef') {
16392: if (code2language($langcode) eq '') {
16393: push(@errors,$item);
16394: }
1.43 raeburn 16395: }
16396: } else {
16397: push(@errors,$item);
16398: }
16399: }
1.54 raeburn 16400: } elsif ($item eq 'timezone_def') {
16401: if ($newvalues{$item} ne '') {
1.62 raeburn 16402: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 16403: push(@errors,$item);
16404: }
16405: }
1.68 raeburn 16406: } elsif ($item eq 'datelocale_def') {
16407: if ($newvalues{$item} ne '') {
16408: my @datelocale_ids = DateTime::Locale->ids();
16409: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16410: push(@errors,$item);
16411: }
16412: }
1.141 raeburn 16413: } elsif ($item eq 'portal_def') {
16414: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 16415: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])\/?$/) {
16416:23): foreach my $field ('email','web') {
16417:23): if ($env{'form.'.$item.'_'.$field}) {
16418:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
16419:23): }
16420:23): }
16421:23): } else {
1.141 raeburn 16422: push(@errors,$item);
16423: }
16424: }
1.43 raeburn 16425: }
16426: if (grep(/^\Q$item\E$/,@errors)) {
16427: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 16428:23): if ($item eq 'portal_def') {
16429:23): if ($domdefaults{$item}) {
16430:23): foreach my $field ('email','web') {
16431:23): if (exists($domdefaults{$item.'_'.$field})) {
16432:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
16433:23): }
16434:23): }
16435:23): }
16436:23): }
1.43 raeburn 16437: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16438: $changes{$item} = 1;
16439: }
1.160.6.118.2 12(raebu 16440:23): if ($item eq 'portal_def') {
16441:23): unless (grep(/^\Q$item\E$/,@errors)) {
16442:23): if ($newvalues{$item} eq '') {
16443:23): foreach my $field ('email','web') {
16444:23): if (exists($domdefaults{$item.'_'.$field})) {
16445:23): delete($domdefaults{$item.'_'.$field});
16446:23): }
16447:23): }
16448:23): } else {
16449:23): unless ($changes{$item}) {
16450:23): foreach my $field ('email','web') {
16451:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
16452:23): $changes{$item} = 1;
16453:23): last;
16454:23): }
16455:23): }
16456:23): }
16457:23): foreach my $field ('email','web') {
16458:23): if ($newvalues{$item.'_'.$field}) {
16459:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
16460:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
16461:23): delete($domdefaults{$item.'_'.$field});
16462:23): }
16463:23): }
16464:23): }
16465:23): }
16466:23): }
1.72 raeburn 16467: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 16468: }
1.160.6.98 raeburn 16469: my %staticdefaults = (
16470: 'intauth_cost' => 10,
16471: 'intauth_check' => 0,
16472: 'intauth_switch' => 0,
16473: );
16474: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16475: if (exists($domdefaults{$item})) {
16476: $newvalues{$item} = $domdefaults{$item};
16477: } else {
16478: $newvalues{$item} = $staticdefaults{$item};
16479: }
16480: }
1.160.6.118.2 8(raebur 16481:2): my ($unamemaprules,$ruleorder);
16482:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
16483:2): if (@possunamemaprules) {
16484:2): ($unamemaprules,$ruleorder) =
16485:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
16486:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
16487:2): if (@{$ruleorder} > 0) {
16488:2): my %possrules;
16489:2): map { $possrules{$_} = 1; } @possunamemaprules;
16490:2): foreach my $rule (@{$ruleorder}) {
16491:2): if ($possrules{$rule}) {
16492:2): push(@{$newvalues{'unamemap_rule'}},$rule);
16493:2): }
16494:2): }
16495:2): }
16496:2): }
16497:2): }
16498:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
16499:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16500:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
16501:2): $newvalues{'unamemap_rule'});
16502:2): if (@rulediffs) {
16503:2): $changes{'unamemap_rule'} = 1;
16504:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
16505:2): }
16506:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
16507:2): $changes{'unamemap_rule'} = 1;
16508:2): delete($domdefaults{'unamemap_rule'});
16509:2): }
16510:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16511:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
16512:2): $changes{'unamemap_rule'} = 1;
16513:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
16514:2): }
16515:2): }
1.43 raeburn 16516: my %defaults_hash = (
1.72 raeburn 16517: defaults => \%newvalues,
16518: );
1.43 raeburn 16519: my $title = &defaults_titles();
1.160.6.40 raeburn 16520:
16521: my $currinststatus;
16522: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16523: $currinststatus = $domconfig{'inststatus'};
16524: } else {
16525: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16526: $currinststatus = {
16527: inststatustypes => $usertypes,
16528: inststatusorder => $types,
16529: inststatusguest => [],
16530: };
16531: }
16532: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16533: my @allpos;
16534: my %alltypes;
1.160.6.93 raeburn 16535: my @inststatusguest;
16536: if (ref($currinststatus) eq 'HASH') {
16537: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16538: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16539: unless (grep(/^\Q$type\E$/,@todelete)) {
16540: push(@inststatusguest,$type);
16541: }
16542: }
16543: }
16544: }
16545: my ($currtitles,$currorder);
1.160.6.40 raeburn 16546: if (ref($currinststatus) eq 'HASH') {
16547: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16548: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16549: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16550: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16551: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16552: }
16553: }
16554: unless (grep(/^\Q$type\E$/,@todelete)) {
16555: my $position = $env{'form.inststatus_pos_'.$type};
16556: $position =~ s/\D+//g;
16557: $allpos[$position] = $type;
16558: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16559: $alltypes{$type} =~ s/`//g;
16560: }
16561: }
16562: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16563: $currtitles =~ s/,$//;
16564: }
16565: }
16566: if ($env{'form.addinststatus'}) {
16567: my $newtype = $env{'form.addinststatus'};
16568: $newtype =~ s/\W//g;
16569: unless (exists($alltypes{$newtype})) {
16570: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16571: $alltypes{$newtype} =~ s/`//g;
16572: my $position = $env{'form.addinststatus_pos'};
16573: $position =~ s/\D+//g;
16574: if ($position ne '') {
16575: $allpos[$position] = $newtype;
16576: }
16577: }
16578: }
1.160.6.93 raeburn 16579: my @orderedstatus;
1.160.6.40 raeburn 16580: foreach my $type (@allpos) {
16581: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16582: push(@orderedstatus,$type);
16583: }
16584: }
16585: foreach my $type (keys(%alltypes)) {
16586: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16587: delete($alltypes{$type});
16588: }
16589: }
16590: $defaults_hash{'inststatus'} = {
16591: inststatustypes => \%alltypes,
16592: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 16593: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 16594: };
16595: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16596: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16597: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16598: }
16599: }
16600: if ($currorder ne join(',',@orderedstatus)) {
16601: $changes{'inststatus'}{'inststatusorder'} = 1;
16602: }
16603: my $newtitles;
16604: foreach my $item (@orderedstatus) {
16605: $newtitles .= $alltypes{$item}.',';
16606: }
16607: $newtitles =~ s/,$//;
16608: if ($currtitles ne $newtitles) {
16609: $changes{'inststatus'}{'inststatustypes'} = 1;
16610: }
1.43 raeburn 16611: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16612: $dom);
16613: if ($putresult eq 'ok') {
16614: if (keys(%changes) > 0) {
16615: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 16616: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 16617: 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";
16618: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 16619: if ($item eq 'inststatus') {
16620: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 16621: if (@orderedstatus) {
1.160.6.40 raeburn 16622: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16623: foreach my $type (@orderedstatus) {
16624: $resulttext .= $alltypes{$type}.', ';
16625: }
16626: $resulttext =~ s/, $//;
16627: $resulttext .= '</li>';
1.160.6.93 raeburn 16628: } else {
16629: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 16630: }
16631: }
1.160.6.118.2 8(raebur 16632:2): } elsif ($item eq 'unamemap_rule') {
16633:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16634:2): my @rulenames;
16635:2): if (ref($unamemaprules) eq 'HASH') {
16636:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
16637:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
16638:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
16639:2): }
16640:2): }
16641:2): }
16642:2): if (@rulenames) {
16643:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
16644:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
16645:2): '</li>';
16646:2): } else {
16647:2): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
16648:2): }
16649:2): } else {
16650:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
16651:2): }
1.160.6.40 raeburn 16652: } else {
16653: my $value = $env{'form.'.$item};
16654: if ($value eq '') {
16655: $value = &mt('none');
16656: } elsif ($item eq 'auth_def') {
16657: my %authnames = &authtype_names();
16658: my %shortauth = (
16659: internal => 'int',
16660: krb4 => 'krb4',
16661: krb5 => 'krb5',
16662: localauth => 'loc',
16663: );
16664: $value = $authnames{$shortauth{$value}};
16665: }
16666: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 16667:23): $mailmsgtext .= "$title->{$item} set to $value\n";
16668:23): if ($item eq 'portal_def') {
16669:23): if ($env{'form.'.$item} ne '') {
16670:23): foreach my $field ('email','web') {
16671:23): $value = $env{'form.'.$item.'_'.$field};
16672:23): if ($value) {
16673:23): $value = &mt('Yes');
16674:23): } else {
16675:23): $value = &mt('No');
16676:23): }
16677:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
16678:23): }
16679:23): }
16680:23): }
1.43 raeburn 16681: }
16682: }
16683: $resulttext .= '</ul>';
16684: $mailmsgtext .= "\n";
16685: my $cachetime = 24*60*60;
1.72 raeburn 16686: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 16687: if (ref($lastactref) eq 'HASH') {
16688: $lastactref->{'domdefaults'} = 1;
16689: }
1.68 raeburn 16690: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 16691: my $notify = 1;
16692: if (ref($domconfig{'contacts'}) eq 'HASH') {
16693: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16694: $notify = 0;
16695: }
16696: }
16697: if ($notify) {
16698: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16699: "LON-CAPA Domain Settings Change - $dom",
16700: $mailmsgtext);
16701: }
1.54 raeburn 16702: }
1.43 raeburn 16703: } else {
1.54 raeburn 16704: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 16705: }
16706: } else {
16707: $resulttext = '<span class="LC_error">'.
16708: &mt('An error occurred: [_1]',$putresult).'</span>';
16709: }
16710: if (@errors > 0) {
16711: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16712: foreach my $item (@errors) {
16713: $resulttext .= ' "'.$title->{$item}.'",';
16714: }
16715: $resulttext =~ s/,$//;
16716: }
16717: return $resulttext;
16718: }
16719:
1.46 raeburn 16720: sub modify_scantron {
1.160.6.24 raeburn 16721: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 16722: my ($resulttext,%confhash,%changes,$errors);
16723: my $custom = 'custom.tab';
16724: my $default = 'default.tab';
16725: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 16726: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 16727: &config_check($dom,$confname,$servadm);
16728: if ($env{'form.scantronformat.filename'} ne '') {
16729: my $error;
16730: if ($configuserok eq 'ok') {
16731: if ($switchserver) {
1.130 raeburn 16732: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 16733: } else {
16734: if ($author_ok eq 'ok') {
16735: my ($result,$scantronurl) =
16736: &publishlogo($r,'upload','scantronformat',$dom,
16737: $confname,'scantron','','',$custom);
16738: if ($result eq 'ok') {
16739: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 16740: $changes{'scantronformat'} = 1;
1.46 raeburn 16741: } else {
16742: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16743: }
16744: } else {
16745: $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);
16746: }
16747: }
16748: } else {
16749: $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);
16750: }
16751: if ($error) {
16752: &Apache::lonnet::logthis($error);
16753: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16754: }
16755: }
1.48 raeburn 16756: if (ref($domconfig{'scantron'}) eq 'HASH') {
16757: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16758: if ($env{'form.scantronformat_del'}) {
16759: $confhash{'scantron'}{'scantronformat'} = '';
16760: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 16761: } else {
16762: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
16763: }
16764: }
16765: }
16766: my @options = ('hdr','pad','rem');
16767: my @fields = &scantroncsv_fields();
16768: my %titles = &scantronconfig_titles();
16769: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
16770: my ($newdat,$currdat,%newcol,%currcol);
16771: if (grep(/^dat$/,@formats)) {
16772: $confhash{'scantron'}{config}{dat} = 1;
16773: $newdat = 1;
16774: } else {
16775: $newdat = 0;
16776: }
16777: if (grep(/^csv$/,@formats)) {
16778: my %bynum;
16779: foreach my $field (@fields) {
16780: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16781: my $posscol = $1;
16782: if (($posscol < 20) && (!$bynum{$posscol})) {
16783: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
16784: $bynum{$posscol} = $field;
16785: $newcol{$field} = $posscol;
16786: }
16787: }
16788: }
16789: if (keys(%newcol)) {
16790: foreach my $option (@options) {
16791: if ($env{'form.scantroncsv_'.$option}) {
16792: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16793: }
16794: }
16795: }
16796: }
16797: $currdat = 1;
16798: if (ref($domconfig{'scantron'}) eq 'HASH') {
16799: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
16800: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
16801: $currdat = 0;
16802: }
16803: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16804: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16805: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16806: }
16807: }
16808: }
16809: }
16810: if ($currdat != $newdat) {
16811: $changes{'config'} = 1;
16812: } else {
16813: foreach my $field (@fields) {
16814: if ($currcol{$field} ne '') {
16815: if ($currcol{$field} ne $newcol{$field}) {
16816: $changes{'config'} = 1;
16817: last;
16818: }
16819: } elsif ($newcol{$field} ne '') {
16820: $changes{'config'} = 1;
16821: last;
1.46 raeburn 16822: }
16823: }
16824: }
16825: if (keys(%confhash) > 0) {
16826: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16827: $dom);
16828: if ($putresult eq 'ok') {
16829: if (keys(%changes) > 0) {
1.48 raeburn 16830: if (ref($confhash{'scantron'}) eq 'HASH') {
16831: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 16832: if ($changes{'scantronformat'}) {
16833: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16834: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16835: } else {
16836: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16837: }
16838: }
16839: if ($changes{'config'}) {
16840: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16841: if ($confhash{'scantron'}{'config'}{'dat'}) {
16842: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16843: }
16844: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16845: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16846: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16847: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16848: foreach my $field (@fields) {
16849: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16850: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16851: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16852: }
16853: }
16854: $resulttext .= '</ul></li>';
16855: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16856: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16857: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16858: foreach my $option (@options) {
16859: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16860: $resulttext .= '<li>'.$titles{$option}.'</li>';
16861: }
16862: }
16863: $resulttext .= '</ul></li>';
16864: }
16865: }
16866: }
16867: }
16868: }
16869: } else {
16870: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16871: }
1.46 raeburn 16872: }
1.48 raeburn 16873: $resulttext .= '</ul>';
16874: } else {
1.130 raeburn 16875: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16876: }
16877: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 16878: if (ref($lastactref) eq 'HASH') {
16879: $lastactref->{'domainconfig'} = 1;
16880: }
1.46 raeburn 16881: } else {
1.160.6.97 raeburn 16882: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16883: }
16884: } else {
16885: $resulttext = '<span class="LC_error">'.
16886: &mt('An error occurred: [_1]',$putresult).'</span>';
16887: }
16888: } else {
1.160.6.97 raeburn 16889: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16890: }
16891: if ($errors) {
16892: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16893: $errors.'</ul>';
16894: }
16895: return $resulttext;
16896: }
16897:
1.48 raeburn 16898: sub modify_coursecategories {
1.160.6.43 raeburn 16899: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16900: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16901: $cathash);
1.48 raeburn 16902: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 16903: my @catitems = ('unauth','auth');
16904: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16905: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16906: $cathash = $domconfig{'coursecategories'}{'cats'};
16907: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16908: $changes{'togglecats'} = 1;
16909: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16910: }
16911: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16912: $changes{'categorize'} = 1;
16913: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16914: }
1.120 raeburn 16915: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16916: $changes{'togglecatscomm'} = 1;
16917: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16918: }
16919: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16920: $changes{'categorizecomm'} = 1;
16921: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
16922: }
1.160.6.42 raeburn 16923: foreach my $item (@catitems) {
16924: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16925: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16926: $changes{$item} = 1;
16927: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16928: }
16929: }
16930: }
1.57 raeburn 16931: } else {
16932: $changes{'togglecats'} = 1;
16933: $changes{'categorize'} = 1;
1.124 raeburn 16934: $changes{'togglecatscomm'} = 1;
16935: $changes{'categorizecomm'} = 1;
1.87 raeburn 16936: $domconfig{'coursecategories'} = {
16937: togglecats => $env{'form.togglecats'},
16938: categorize => $env{'form.categorize'},
1.124 raeburn 16939: togglecatscomm => $env{'form.togglecatscomm'},
16940: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 16941: };
1.160.6.42 raeburn 16942: foreach my $item (@catitems) {
16943: if ($env{'form.coursecat_'.$item} ne 'std') {
16944: $changes{$item} = 1;
16945: }
16946: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16947: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16948: }
16949: }
1.57 raeburn 16950: }
16951: if (ref($cathash) eq 'HASH') {
16952: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16953: push (@deletecategory,'instcode::0');
16954: }
1.120 raeburn 16955: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16956: push(@deletecategory,'communities::0');
16957: }
1.48 raeburn 16958: }
1.57 raeburn 16959: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16960: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16961: if (@deletecategory > 0) {
16962: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16963: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16964: foreach my $item (@deletecategory) {
1.57 raeburn 16965: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16966: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16967: $deletions{$item} = 1;
1.57 raeburn 16968: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16969: }
16970: }
16971: }
1.57 raeburn 16972: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16973: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16974: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16975: $reorderings{$item} = 1;
1.57 raeburn 16976: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16977: }
16978: if ($env{'form.addcategory_name_'.$item} ne '') {
16979: my $newcat = $env{'form.addcategory_name_'.$item};
16980: my $newdepth = $depth+1;
16981: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16982: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16983: $adds{$newitem} = 1;
16984: }
16985: if ($env{'form.subcat_'.$item} ne '') {
16986: my $newcat = $env{'form.subcat_'.$item};
16987: my $newdepth = $depth+1;
16988: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16989: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16990: $adds{$newitem} = 1;
16991: }
16992: }
16993: }
16994: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16995: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16996: my $newitem = 'instcode::0';
1.57 raeburn 16997: if ($cathash->{$newitem} eq '') {
16998: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16999: $adds{$newitem} = 1;
17000: }
17001: } else {
17002: my $newitem = 'instcode::0';
1.57 raeburn 17003: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 17004: $adds{$newitem} = 1;
17005: }
17006: }
1.120 raeburn 17007: if ($env{'form.communities'} eq '1') {
17008: if (ref($cathash) eq 'HASH') {
17009: my $newitem = 'communities::0';
17010: if ($cathash->{$newitem} eq '') {
17011: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17012: $adds{$newitem} = 1;
17013: }
17014: } else {
17015: my $newitem = 'communities::0';
17016: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17017: $adds{$newitem} = 1;
17018: }
17019: }
1.48 raeburn 17020: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 17021: if (($env{'form.addcategory_name'} ne 'instcode') &&
17022: ($env{'form.addcategory_name'} ne 'communities')) {
17023: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
17024: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
17025: $adds{$newitem} = 1;
17026: }
1.48 raeburn 17027: }
1.57 raeburn 17028: my $putresult;
1.48 raeburn 17029: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17030: if (keys(%deletions) > 0) {
17031: foreach my $key (keys(%deletions)) {
17032: if ($predelallitems{$key} ne '') {
17033: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
17034: }
17035: }
17036: }
17037: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 17038: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 17039: if (ref($chkcats[0]) eq 'ARRAY') {
17040: my $depth = 0;
17041: my $chg = 0;
17042: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
17043: my $name = $chkcats[0][$i];
17044: my $item;
17045: if ($name eq '') {
17046: $chg ++;
17047: } else {
17048: $item = &escape($name).'::0';
17049: if ($chg) {
1.57 raeburn 17050: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 17051: }
17052: $depth ++;
1.57 raeburn 17053: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 17054: $depth --;
17055: }
17056: }
17057: }
1.57 raeburn 17058: }
17059: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17060: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 17061: if ($putresult eq 'ok') {
1.57 raeburn 17062: my %title = (
1.120 raeburn 17063: togglecats => 'Show/Hide a course in catalog',
17064: categorize => 'Assign a category to a course',
17065: togglecatscomm => 'Show/Hide a community in catalog',
17066: categorizecomm => 'Assign a category to a community',
1.57 raeburn 17067: );
17068: my %level = (
1.120 raeburn 17069: dom => 'set in Domain ("Modify Course/Community")',
17070: crs => 'set in Course ("Course Configuration")',
17071: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 17072: none => 'No catalog',
17073: std => 'Standard catalog',
17074: domonly => 'Domain-only catalog',
17075: codesrch => 'Code search form',
1.57 raeburn 17076: );
1.48 raeburn 17077: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 17078: if ($changes{'togglecats'}) {
17079: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
17080: }
17081: if ($changes{'categorize'}) {
17082: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 17083: }
1.120 raeburn 17084: if ($changes{'togglecatscomm'}) {
17085: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
17086: }
17087: if ($changes{'categorizecomm'}) {
17088: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
17089: }
1.160.6.42 raeburn 17090: if ($changes{'unauth'}) {
17091: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
17092: }
17093: if ($changes{'auth'}) {
17094: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
17095: }
1.57 raeburn 17096: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17097: my $cathash;
17098: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
17099: $cathash = $domconfig{'coursecategories'}{'cats'};
17100: } else {
17101: $cathash = {};
17102: }
17103: my (@cats,@trails,%allitems);
17104: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
17105: if (keys(%deletions) > 0) {
17106: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
17107: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
17108: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
17109: }
17110: $resulttext .= '</ul></li>';
17111: }
17112: if (keys(%reorderings) > 0) {
17113: my %sort_by_trail;
17114: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
17115: foreach my $key (keys(%reorderings)) {
17116: if ($allitems{$key} ne '') {
17117: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17118: }
1.48 raeburn 17119: }
1.57 raeburn 17120: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17121: $resulttext .= '<li>'.$trails[$trail].'</li>';
17122: }
17123: $resulttext .= '</ul></li>';
1.48 raeburn 17124: }
1.57 raeburn 17125: if (keys(%adds) > 0) {
17126: my %sort_by_trail;
17127: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
17128: foreach my $key (keys(%adds)) {
17129: if ($allitems{$key} ne '') {
17130: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17131: }
17132: }
17133: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17134: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 17135: }
1.57 raeburn 17136: $resulttext .= '</ul></li>';
1.48 raeburn 17137: }
1.160.6.92 raeburn 17138: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
17139: if (ref($lastactref) eq 'HASH') {
17140: $lastactref->{'cats'} = 1;
17141: }
1.48 raeburn 17142: }
17143: $resulttext .= '</ul>';
1.160.6.43 raeburn 17144: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 17145: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17146: if ($changes{'auth'}) {
17147: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
17148: }
17149: if ($changes{'unauth'}) {
17150: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
17151: }
17152: my $cachetime = 24*60*60;
17153: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 17154: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 17155: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 17156: }
17157: }
1.48 raeburn 17158: } else {
17159: $resulttext = '<span class="LC_error">'.
1.57 raeburn 17160: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 17161: }
17162: } else {
1.120 raeburn 17163: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 17164: }
17165: return $resulttext;
17166: }
17167:
1.69 raeburn 17168: sub modify_serverstatuses {
17169: my ($dom,%domconfig) = @_;
17170: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
17171: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
17172: %currserverstatus = %{$domconfig{'serverstatuses'}};
17173: }
17174: my @pages = &serverstatus_pages();
17175: foreach my $type (@pages) {
17176: $newserverstatus{$type}{'namedusers'} = '';
17177: $newserverstatus{$type}{'machines'} = '';
17178: if (defined($env{'form.'.$type.'_namedusers'})) {
17179: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
17180: my @okusers;
17181: foreach my $user (@users) {
17182: my ($uname,$udom) = split(/:/,$user);
17183: if (($udom =~ /^$match_domain$/) &&
17184: (&Apache::lonnet::domain($udom)) &&
17185: ($uname =~ /^$match_username$/)) {
17186: if (!grep(/^\Q$user\E/,@okusers)) {
17187: push(@okusers,$user);
17188: }
17189: }
17190: }
17191: if (@okusers > 0) {
17192: @okusers = sort(@okusers);
17193: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
17194: }
17195: }
17196: if (defined($env{'form.'.$type.'_machines'})) {
17197: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
17198: my @okmachines;
17199: foreach my $ip (@machines) {
17200: my @parts = split(/\./,$ip);
17201: next if (@parts < 4);
17202: my $badip = 0;
17203: for (my $i=0; $i<4; $i++) {
17204: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17205: $badip = 1;
17206: last;
17207: }
17208: }
17209: if (!$badip) {
17210: push(@okmachines,$ip);
17211: }
17212: }
17213: @okmachines = sort(@okmachines);
17214: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17215: }
17216: }
17217: my %serverstatushash = (
17218: serverstatuses => \%newserverstatus,
17219: );
17220: foreach my $type (@pages) {
1.83 raeburn 17221: foreach my $setting ('namedusers','machines') {
1.84 raeburn 17222: my (@current,@new);
1.83 raeburn 17223: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 17224: if ($currserverstatus{$type}{$setting} ne '') {
17225: @current = split(/,/,$currserverstatus{$type}{$setting});
17226: }
17227: }
17228: if ($newserverstatus{$type}{$setting} ne '') {
17229: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 17230: }
17231: if (@current > 0) {
17232: if (@new > 0) {
17233: foreach my $item (@current) {
17234: if (!grep(/^\Q$item\E$/,@new)) {
17235: $changes{$type}{$setting} = 1;
1.82 raeburn 17236: last;
17237: }
17238: }
1.84 raeburn 17239: foreach my $item (@new) {
17240: if (!grep(/^\Q$item\E$/,@current)) {
17241: $changes{$type}{$setting} = 1;
17242: last;
1.82 raeburn 17243: }
17244: }
17245: } else {
1.83 raeburn 17246: $changes{$type}{$setting} = 1;
1.69 raeburn 17247: }
1.83 raeburn 17248: } elsif (@new > 0) {
17249: $changes{$type}{$setting} = 1;
1.69 raeburn 17250: }
17251: }
17252: }
17253: if (keys(%changes) > 0) {
1.81 raeburn 17254: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 17255: my $putresult = &Apache::lonnet::put_dom('configuration',
17256: \%serverstatushash,$dom);
17257: if ($putresult eq 'ok') {
17258: $resulttext .= &mt('Changes made:').'<ul>';
17259: foreach my $type (@pages) {
1.84 raeburn 17260: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 17261: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 17262: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 17263: if ($newserverstatus{$type}{'namedusers'} eq '') {
17264: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17265: } else {
17266: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17267: }
1.84 raeburn 17268: }
17269: if ($changes{$type}{'machines'}) {
1.69 raeburn 17270: if ($newserverstatus{$type}{'machines'} eq '') {
17271: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17272: } else {
17273: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
17274: }
17275:
17276: }
17277: $resulttext .= '</ul></li>';
17278: }
17279: }
17280: $resulttext .= '</ul>';
17281: } else {
17282: $resulttext = '<span class="LC_error">'.
17283: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
17284:
17285: }
17286: } else {
17287: $resulttext = &mt('No changes made to access to server status pages');
17288: }
17289: return $resulttext;
17290: }
17291:
1.118 jms 17292: sub modify_helpsettings {
1.160.6.77 raeburn 17293: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 17294: my ($resulttext,$errors,%changes,%helphash);
17295: my %defaultchecked = ('submitbugs' => 'on');
17296: my @offon = ('off','on');
1.118 jms 17297: my @toggles = ('submitbugs');
1.160.6.77 raeburn 17298: my %current = ('submitbugs' => '',
17299: 'adhoc' => {},
17300: );
1.118 jms 17301: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 17302: %current = %{$domconfig{'helpsettings'}};
17303: }
1.160.6.77 raeburn 17304: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 17305: foreach my $item (@toggles) {
17306: if ($defaultchecked{$item} eq 'on') {
17307: if ($current{$item} eq '') {
17308: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 17309: $changes{$item} = 1;
17310: }
1.160.6.73 raeburn 17311: } elsif ($current{$item} ne $env{'form.'.$item}) {
17312: $changes{$item} = 1;
17313: }
17314: } elsif ($defaultchecked{$item} eq 'off') {
17315: if ($current{$item} eq '') {
17316: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 17317: $changes{$item} = 1;
17318: }
1.160.6.73 raeburn 17319: } elsif ($current{$item} ne $env{'form.'.$item}) {
17320: $changes{$item} = 1;
17321: }
17322: }
17323: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17324: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17325: }
17326: }
1.160.6.77 raeburn 17327: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 17328: my $confname = $dom.'-domainconfig';
17329: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 17330: my (@allpos,%newsettings,%changedprivs,$newrole);
17331: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 17332: my @accesstypes = ('all','dh','da','none','status','inc','exc');
17333: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 17334: my %lt = &Apache::lonlocal::texthash(
17335: s => 'system',
17336: d => 'domain',
17337: order => 'Display order',
17338: access => 'Role usage',
1.160.6.79 raeburn 17339: all => 'All with domain helpdesk or helpdesk assistant role',
17340: dh => 'All with domain helpdesk role',
17341: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 17342: none => 'None',
17343: status => 'Determined based on institutional status',
17344: inc => 'Include all, but exclude specific personnel',
17345: exc => 'Exclude all, but include specific personnel',
17346: );
17347: for (my $num=0; $num<=$maxnum; $num++) {
17348: my ($prefix,$identifier,$rolename,%curr);
17349: if ($num == $maxnum) {
17350: next unless ($env{'form.newcusthelp'} == $maxnum);
17351: $identifier = 'custhelp'.$num;
17352: $prefix = 'helproles_'.$num;
17353: $rolename = $env{'form.custhelpname'.$num};
17354: $rolename=~s/[^A-Za-z0-9]//gs;
17355: next if ($rolename eq '');
17356: next if (exists($existing{'rolesdef_'.$rolename}));
17357: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17358: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17359: $newprivs{'c'},$confname,$dom);
17360: if ($result ne 'ok') {
17361: $errors .= '<li><span class="LC_error">'.
17362: &mt('An error occurred storing the new custom role: [_1]',
17363: $result).'</span></li>';
17364: next;
17365: } else {
17366: $changedprivs{$rolename} = \%newprivs;
17367: $newrole = $rolename;
17368: }
17369: } else {
17370: $prefix = 'helproles_'.$num;
17371: $rolename = $env{'form.'.$prefix};
17372: next if ($rolename eq '');
17373: next unless (exists($existing{'rolesdef_'.$rolename}));
17374: $identifier = 'custhelp'.$num;
17375: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17376: my %currprivs;
17377: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
17378: split(/\_/,$existing{'rolesdef_'.$rolename});
17379: foreach my $level ('c','d','s') {
17380: if ($newprivs{$level} ne $currprivs{$level}) {
17381: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17382: $newprivs{'c'},$confname,$dom);
17383: if ($result ne 'ok') {
17384: $errors .= '<li><span class="LC_error">'.
17385: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17386: $rolename,$result).'</span></li>';
17387: } else {
17388: $changedprivs{$rolename} = \%newprivs;
17389: }
17390: last;
17391: }
17392: }
17393: if (ref($current{'adhoc'}) eq 'HASH') {
17394: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17395: %curr = %{$current{'adhoc'}{$rolename}};
17396: }
17397: }
17398: }
17399: my $newpos = $env{'form.'.$prefix.'_pos'};
17400: $newpos =~ s/\D+//g;
17401: $allpos[$newpos] = $rolename;
17402: my $newdesc = $env{'form.'.$prefix.'_desc'};
17403: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17404: if ($curr{'desc'}) {
17405: if ($curr{'desc'} ne $newdesc) {
17406: $changes{'customrole'}{$rolename}{'desc'} = 1;
17407: $newsettings{$rolename}{'desc'} = $newdesc;
17408: }
17409: } elsif ($newdesc ne '') {
17410: $changes{'customrole'}{$rolename}{'desc'} = 1;
17411: $newsettings{$rolename}{'desc'} = $newdesc;
17412: }
17413: my $access = $env{'form.'.$prefix.'_access'};
17414: if (grep(/^\Q$access\E$/,@accesstypes)) {
17415: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17416: if ($access eq 'status') {
17417: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17418: if (scalar(@statuses) == 0) {
17419: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
17420: } else {
17421: my (@shownstatus,$numtypes);
17422: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17423: if (ref($types) eq 'ARRAY') {
17424: $numtypes = scalar(@{$types});
17425: foreach my $type (sort(@statuses)) {
17426: if ($type eq 'default') {
17427: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17428: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17429: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17430: push(@shownstatus,$usertypes->{$type});
17431: }
1.160.6.73 raeburn 17432: }
17433: }
1.160.6.77 raeburn 17434: if (grep(/^default$/,@statuses)) {
17435: push(@shownstatus,$othertitle);
17436: }
17437: if (scalar(@shownstatus) == 1+$numtypes) {
17438: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17439: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17440: } else {
17441: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17442: if (ref($curr{'status'}) eq 'ARRAY') {
17443: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17444: if (@diffs) {
17445: $changes{'customrole'}{$rolename}{$access} = 1;
17446: }
17447: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17448: $changes{'customrole'}{$rolename}{$access} = 1;
17449: }
17450: }
17451: }
17452: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17453: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17454: my @newspecstaff;
17455: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17456: foreach my $person (sort(@personnel)) {
17457: if ($domhelpdesk{$person}) {
17458: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17459: }
17460: }
17461: if (ref($curr{$access}) eq 'ARRAY') {
17462: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17463: if (@diffs) {
17464: $changes{'customrole'}{$rolename}{$access} = 1;
17465: }
17466: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17467: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 17468: }
1.160.6.77 raeburn 17469: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17470: my ($uname,$udom) = split(/:/,$person);
17471: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17472: }
17473: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 17474: }
1.160.6.77 raeburn 17475: } else {
17476: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17477: }
17478: unless ($curr{'access'} eq $access) {
17479: $changes{'customrole'}{$rolename}{'access'} = 1;
17480: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 17481: }
17482: }
1.160.6.77 raeburn 17483: if (@allpos > 0) {
17484: my $idx = 0;
17485: foreach my $rolename (@allpos) {
17486: if ($rolename ne '') {
17487: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17488: if (ref($current{'adhoc'}) eq 'HASH') {
17489: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17490: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17491: $changes{'customrole'}{$rolename}{'order'} = 1;
17492: $newsettings{$rolename}{'order'} = $idx+1;
17493: }
17494: }
1.160.6.73 raeburn 17495: }
1.160.6.77 raeburn 17496: $idx ++;
1.122 jms 17497: }
17498: }
1.118 jms 17499: }
1.123 jms 17500: my $putresult;
17501: if (keys(%changes) > 0) {
1.160.6.5 raeburn 17502: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
17503: if ($putresult eq 'ok') {
1.160.6.77 raeburn 17504: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17505: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17506: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17507: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17508: }
17509: }
17510: my $cachetime = 24*60*60;
17511: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17512: if (ref($lastactref) eq 'HASH') {
17513: $lastactref->{'domdefaults'} = 1;
17514: }
17515: } else {
17516: $errors .= '<li><span class="LC_error">'.
17517: &mt('An error occurred storing the settings: [_1]',
17518: $putresult).'</span></li>';
17519: }
17520: }
17521: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17522: $resulttext = &mt('Changes made:').'<ul>';
17523: my (%shownprivs,@levelorder);
17524: @levelorder = ('c','d','s');
17525: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 17526: foreach my $item (sort(keys(%changes))) {
17527: if ($item eq 'submitbugs') {
17528: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17529: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17530: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 17531: } elsif ($item eq 'customrole') {
17532: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 17533: my @keyorder = ('order','desc','access','status','exc','inc');
17534: my %keytext = &Apache::lonlocal::texthash(
17535: order => 'Order',
17536: desc => 'Role description',
17537: access => 'Role usage',
1.160.6.83 raeburn 17538: status => 'Allowed institutional types',
1.160.6.77 raeburn 17539: exc => 'Allowed personnel',
17540: inc => 'Disallowed personnel',
17541: );
1.160.6.73 raeburn 17542: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 17543: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17544: if ($role eq $newrole) {
17545: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17546: $role).'<ul>';
17547: } else {
17548: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17549: $role).'<ul>';
17550: }
17551: foreach my $key (@keyorder) {
17552: if ($changes{'customrole'}{$role}{$key}) {
17553: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17554: $keytext{$key},$newsettings{$role}{$key}).
17555: '</li>';
17556: }
17557: }
17558: if (ref($changedprivs{$role}) eq 'HASH') {
17559: $shownprivs{$role} = 1;
17560: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17561: foreach my $level (@levelorder) {
17562: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17563: next if ($item eq '');
17564: my ($priv) = split(/\&/,$item,2);
17565: if (&Apache::lonnet::plaintext($priv)) {
17566: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17567: unless ($level eq 'c') {
17568: $resulttext .= ' ('.$lt{$level}.')';
17569: }
17570: $resulttext .= '</li>';
17571: }
17572: }
17573: }
17574: $resulttext .= '</ul>';
17575: }
17576: $resulttext .= '</ul></li>';
17577: }
1.160.6.73 raeburn 17578: }
17579: }
1.160.6.5 raeburn 17580: }
17581: }
17582: }
1.160.6.77 raeburn 17583: if (keys(%changedprivs)) {
17584: foreach my $role (sort(keys(%changedprivs))) {
17585: unless ($shownprivs{$role}) {
17586: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17587: $role).'<ul>'.
17588: '<li>'.&mt('Privileges set to :').'<ul>';
17589: foreach my $level (@levelorder) {
17590: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17591: next if ($item eq '');
17592: my ($priv) = split(/\&/,$item,2);
17593: if (&Apache::lonnet::plaintext($priv)) {
17594: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17595: unless ($level eq 'c') {
17596: $resulttext .= ' ('.$lt{$level}.')';
17597: }
17598: $resulttext .= '</li>';
17599: }
17600: }
17601: }
17602: $resulttext .= '</ul></li></ul></li>';
17603: }
17604: }
17605: }
17606: $resulttext .= '</ul>';
17607: } else {
17608: $resulttext = &mt('No changes made to help settings');
1.118 jms 17609: }
17610: if ($errors) {
1.160.6.5 raeburn 17611: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 17612: $errors.'</ul>';
1.118 jms 17613: }
17614: return $resulttext;
17615: }
17616:
1.121 raeburn 17617: sub modify_coursedefaults {
1.160.6.27 raeburn 17618: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 17619: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 17620: my %defaultchecked = (
17621: 'uselcmath' => 'on',
1.160.6.115 raeburn 17622: 'usejsme' => 'on',
17623: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 17624:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 17625: );
1.160.6.118.2 4(raebur 17626:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 17627: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 17628: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
17629: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 17630: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 17631: my %staticdefaults = (
17632: anonsurvey_threshold => 10,
17633: uploadquota => 500,
1.160.6.57 raeburn 17634: postsubmit => 60,
1.160.6.70 raeburn 17635: mysqltables => 172800,
1.160.6.21 raeburn 17636: );
1.160.6.90 raeburn 17637: my %texoptions = (
17638: MathJax => 'MathJax',
17639: mimetex => &mt('Convert to Images'),
17640: tth => &mt('TeX to HTML'),
17641: );
1.121 raeburn 17642: $defaultshash{'coursedefaults'} = {};
17643:
17644: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17645: if ($domconfig{'coursedefaults'} eq '') {
17646: $domconfig{'coursedefaults'} = {};
17647: }
17648: }
17649:
17650: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17651: foreach my $item (@toggles) {
17652: if ($defaultchecked{$item} eq 'on') {
17653: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17654: ($env{'form.'.$item} eq '0')) {
17655: $changes{$item} = 1;
1.160.6.16 raeburn 17656: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 17657: $changes{$item} = 1;
17658: }
17659: } elsif ($defaultchecked{$item} eq 'off') {
17660: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17661: ($env{'form.'.$item} eq '1')) {
17662: $changes{$item} = 1;
17663: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17664: $changes{$item} = 1;
17665: }
17666: }
17667: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17668: }
1.160.6.21 raeburn 17669: foreach my $item (@numbers) {
17670: my ($currdef,$newdef);
1.160.6.26 raeburn 17671: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 17672: if ($item eq 'anonsurvey_threshold') {
17673: $currdef = $domconfig{'coursedefaults'}{$item};
17674: $newdef =~ s/\D//g;
17675: if ($newdef eq '' || $newdef < 1) {
17676: $newdef = 1;
17677: }
17678: $defaultshash{'coursedefaults'}{$item} = $newdef;
17679: } else {
1.160.6.70 raeburn 17680: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17681: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17682: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 17683: }
17684: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 17685: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 17686: }
17687: if ($currdef ne $newdef) {
17688: if ($item eq 'anonsurvey_threshold') {
17689: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17690: $changes{$item} = 1;
17691: }
1.160.6.70 raeburn 17692: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
17693: my $setting = $1;
17694: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17695: $changes{$setting} = 1;
1.160.6.21 raeburn 17696: }
17697: }
1.139 raeburn 17698: }
17699: }
1.160.6.90 raeburn 17700: my $texengine;
17701: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17702: $texengine = $env{'form.texengine'};
17703: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17704: if ($currdef eq '') {
17705: unless ($texengine eq $Apache::lonnet::deftex) {
17706: $changes{'texengine'} = 1;
17707: }
17708: } elsif ($currdef ne $texengine) {
17709: $changes{'texengine'} = 1;
17710: }
17711: }
17712: if ($texengine ne '') {
17713: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17714: }
1.160.6.64 raeburn 17715: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17716: my @currclonecode;
17717: if (ref($currclone) eq 'HASH') {
17718: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17719: @currclonecode = @{$currclone->{'instcode'}};
17720: }
17721: }
17722: my $newclone;
17723: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
17724: $newclone = $env{'form.canclone'};
17725: }
17726: if ($newclone eq 'instcode') {
17727: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17728: my (%codedefaults,@code_order,@clonecode);
17729: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17730: \@code_order);
17731: foreach my $item (@code_order) {
17732: if (grep(/^\Q$item\E$/,@newcodes)) {
17733: push(@clonecode,$item);
17734: }
17735: }
17736: if (@clonecode) {
17737: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17738: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17739: if (@diffs) {
17740: $changes{'canclone'} = 1;
17741: }
17742: } else {
17743: $newclone eq '';
17744: }
17745: } elsif ($newclone ne '') {
17746: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17747: }
17748: if ($newclone ne $currclone) {
17749: $changes{'canclone'} = 1;
17750: }
1.160.6.57 raeburn 17751: my %credits;
17752: foreach my $type (@types) {
17753: unless ($type eq 'community') {
17754: $credits{$type} = $env{'form.'.$type.'_credits'};
17755: $credits{$type} =~ s/[^\d.]+//g;
17756: }
17757: }
17758: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17759: ($env{'form.coursecredits'} eq '1')) {
17760: $changes{'coursecredits'} = 1;
17761: foreach my $type (keys(%credits)) {
17762: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17763: }
17764: } else {
17765: if ($env{'form.coursecredits'} eq '1') {
17766: foreach my $type (@types) {
17767: unless ($type eq 'community') {
17768: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
17769: $changes{'coursecredits'} = 1;
17770: }
17771: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17772: }
17773: }
17774: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17775: foreach my $type (@types) {
17776: unless ($type eq 'community') {
17777: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17778: $changes{'coursecredits'} = 1;
17779: last;
17780: }
17781: }
17782: }
17783: }
17784: }
17785: if ($env{'form.postsubmit'} eq '1') {
17786: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17787: my %currtimeout;
17788: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17789: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17790: $changes{'postsubmit'} = 1;
17791: }
17792: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17793: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17794: }
17795: } else {
17796: $changes{'postsubmit'} = 1;
17797: }
17798: foreach my $type (@types) {
17799: my $timeout = $env{'form.'.$type.'_timeout'};
17800: $timeout =~ s/\D//g;
17801: if ($timeout == $staticdefaults{'postsubmit'}) {
17802: $timeout = '';
17803: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17804: $timeout = '0';
17805: }
17806: unless ($timeout eq '') {
17807: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17808: }
17809: if (exists($currtimeout{$type})) {
17810: if ($timeout ne $currtimeout{$type}) {
17811: $changes{'postsubmit'} = 1;
17812: }
17813: } elsif ($timeout ne '') {
17814: $changes{'postsubmit'} = 1;
17815: }
17816: }
17817: } else {
17818: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17819: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17820: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17821: $changes{'postsubmit'} = 1;
17822: }
17823: } else {
17824: $changes{'postsubmit'} = 1;
17825: }
1.160.6.16 raeburn 17826: }
1.121 raeburn 17827: }
17828: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17829: $dom);
17830: if ($putresult eq 'ok') {
17831: if (keys(%changes) > 0) {
1.160.6.27 raeburn 17832: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 17833: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 17834: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 17835: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 4(raebur 17836:2): ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
17837:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 17838: if ($changes{$item}) {
17839: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17840: }
1.160.6.16 raeburn 17841: }
17842: if ($changes{'coursecredits'}) {
17843: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 17844: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17845: $domdefaults{$type.'credits'} =
17846: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17847: }
17848: }
17849: }
17850: if ($changes{'postsubmit'}) {
17851: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17852: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17853: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17854: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17855: $domdefaults{$type.'postsubtimeout'} =
17856: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17857: }
17858: }
1.160.6.16 raeburn 17859: }
17860: }
1.160.6.21 raeburn 17861: if ($changes{'uploadquota'}) {
17862: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17863: foreach my $type (@types) {
17864: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17865: }
17866: }
17867: }
1.160.6.64 raeburn 17868: if ($changes{'canclone'}) {
17869: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17870: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17871: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17872: if (@clonecodes) {
17873: $domdefaults{'canclone'} = join('+',@clonecodes);
17874: }
17875: }
17876: } else {
17877: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17878: }
17879: }
1.121 raeburn 17880: my $cachetime = 24*60*60;
17881: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17882: if (ref($lastactref) eq 'HASH') {
17883: $lastactref->{'domdefaults'} = 1;
17884: }
1.121 raeburn 17885: }
17886: $resulttext = &mt('Changes made:').'<ul>';
17887: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 17888: if ($item eq 'uselcmath') {
1.121 raeburn 17889: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 17890: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 17891: } else {
1.160.6.57 raeburn 17892: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17893: }
17894: } elsif ($item eq 'usejsme') {
17895: if ($env{'form.'.$item} eq '1') {
17896: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17897: } else {
17898: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 17899: }
1.160.6.115 raeburn 17900: } elsif ($item eq 'inline_chem') {
17901: if ($env{'form.'.$item} eq '1') {
17902: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
17903: } else {
17904: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
17905: }
1.160.6.90 raeburn 17906: } elsif ($item eq 'texengine') {
17907: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17908: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17909: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17910: }
1.139 raeburn 17911: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 17912: $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 17913: } elsif ($item eq 'uploadquota') {
17914: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17915: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17916: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17917: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 17918: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
17919:
1.160.6.21 raeburn 17920: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17921: '</ul>'.
17922: '</li>';
17923: } else {
17924: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17925: }
1.160.6.70 raeburn 17926: } elsif ($item eq 'mysqltables') {
17927: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17928: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17929: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17930: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17931: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17932: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17933: '</ul>'.
17934: '</li>';
17935: } else {
17936: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17937: }
1.160.6.57 raeburn 17938: } elsif ($item eq 'postsubmit') {
17939: if ($domdefaults{'postsubmit'} eq 'off') {
17940: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17941: } else {
17942: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
17943: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17944: $resulttext .= &mt('durations:').'<ul>';
17945: foreach my $type (@types) {
17946: $resulttext .= '<li>';
17947: my $timeout;
17948: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17949: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17950: }
17951: my $display;
17952: if ($timeout eq '0') {
17953: $display = &mt('unlimited');
17954: } elsif ($timeout eq '') {
17955: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17956: } else {
17957: $display = &mt('[quant,_1,second]',$timeout);
17958: }
17959: if ($type eq 'community') {
17960: $resulttext .= &mt('Communities');
17961: } elsif ($type eq 'official') {
17962: $resulttext .= &mt('Official courses');
17963: } elsif ($type eq 'unofficial') {
17964: $resulttext .= &mt('Unofficial courses');
17965: } elsif ($type eq 'textbook') {
17966: $resulttext .= &mt('Textbook courses');
17967: }
17968: $resulttext .= ' -- '.$display.'</li>';
17969: }
17970: $resulttext .= '</ul>';
17971: }
17972: $resulttext .= '</li>';
17973: }
1.160.6.16 raeburn 17974: } elsif ($item eq 'coursecredits') {
17975: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17976: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 17977: ($domdefaults{'unofficialcredits'} eq '') &&
17978: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 17979: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17980: } else {
17981: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17982: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17983: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 17984: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 17985: '</ul>'.
17986: '</li>';
17987: }
17988: } else {
17989: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17990: }
1.160.6.64 raeburn 17991: } elsif ($item eq 'canclone') {
17992: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17993: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17994: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17995: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17996: }
17997: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17998: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17999: } else {
18000: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
18001: }
1.160.6.118.2 4(raebur 18002:2): } elsif ($item eq 'ltiauth') {
18003:2): if ($env{'form.'.$item} eq '1') {
18004:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
18005:2): } else {
18006:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
18007:2): }
1.140 raeburn 18008: }
1.121 raeburn 18009: }
18010: $resulttext .= '</ul>';
18011: } else {
18012: $resulttext = &mt('No changes made to course defaults');
18013: }
18014: } else {
18015: $resulttext = '<span class="LC_error">'.
18016: &mt('An error occurred: [_1]',$putresult).'</span>';
18017: }
18018: return $resulttext;
18019: }
18020:
1.160.6.37 raeburn 18021: sub modify_selfenrollment {
18022: my ($dom,$lastactref,%domconfig) = @_;
18023: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
18024: my @types = ('official','unofficial','community','textbook');
18025: my %titles = &tool_titles();
18026: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
18027: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
18028: $ordered{'default'} = ['types','registered','approval','limit'];
18029:
18030: my (%roles,%shown,%toplevel);
18031: $roles{'0'} = &Apache::lonnet::plaintext('dc');
18032:
18033: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
18034: if ($domconfig{'selfenrollment'} eq '') {
18035: $domconfig{'selfenrollment'} = {};
18036: }
18037: }
18038: %toplevel = (
18039: admin => 'Configuration Rights',
18040: default => 'Default settings',
18041: validation => 'Validation of self-enrollment requests',
18042: );
18043: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
18044:
18045: if (ref($ordered{'admin'}) eq 'ARRAY') {
18046: foreach my $item (@{$ordered{'admin'}}) {
18047: foreach my $type (@types) {
18048: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
18049: $selfenrollhash{'admin'}{$type}{$item} = 1;
18050: } else {
18051: $selfenrollhash{'admin'}{$type}{$item} = 0;
18052: }
18053: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
18054: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
18055: if ($selfenrollhash{'admin'}{$type}{$item} ne
18056: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
18057: push(@{$changes{'admin'}{$type}},$item);
18058: }
18059: } else {
18060: if (!$selfenrollhash{'admin'}{$type}{$item}) {
18061: push(@{$changes{'admin'}{$type}},$item);
18062: }
18063: }
18064: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
18065: push(@{$changes{'admin'}{$type}},$item);
18066: }
18067: }
18068: }
18069: }
18070:
18071: foreach my $item (@{$ordered{'default'}}) {
18072: foreach my $type (@types) {
18073: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
18074: if ($item eq 'types') {
18075: unless (($value eq 'all') || ($value eq 'dom')) {
18076: $value = '';
18077: }
18078: } elsif ($item eq 'registered') {
18079: unless ($value eq '1') {
18080: $value = 0;
18081: }
18082: } elsif ($item eq 'approval') {
18083: unless ($value =~ /^[012]$/) {
18084: $value = 0;
18085: }
18086: } else {
18087: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18088: $value = 'none';
18089: }
18090: }
18091: $selfenrollhash{'default'}{$type}{$item} = $value;
18092: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
18093: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18094: if ($selfenrollhash{'default'}{$type}{$item} ne
18095: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
18096: push(@{$changes{'default'}{$type}},$item);
18097: }
18098: } else {
18099: push(@{$changes{'default'}{$type}},$item);
18100: }
18101: } else {
18102: push(@{$changes{'default'}{$type}},$item);
18103: }
18104: if ($item eq 'limit') {
18105: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18106: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
18107: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
18108: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
18109: }
18110: } else {
18111: $selfenrollhash{'default'}{$type}{'cap'} = '';
18112: }
18113: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18114: if ($selfenrollhash{'default'}{$type}{'cap'} ne
18115: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
18116: push(@{$changes{'default'}{$type}},'cap');
18117: }
18118: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
18119: push(@{$changes{'default'}{$type}},'cap');
18120: }
18121: }
18122: }
18123: }
18124:
18125: foreach my $item (@{$itemsref}) {
18126: if ($item eq 'fields') {
18127: my @changed;
18128: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
18129: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
18130: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
18131: }
18132: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18133: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
18134: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
18135: $domconfig{'selfenrollment'}{'validation'}{$item});
18136: } else {
18137: @changed = @{$selfenrollhash{'validation'}{$item}};
18138: }
18139: } else {
18140: @changed = @{$selfenrollhash{'validation'}{$item}};
18141: }
18142: if (@changed) {
18143: if ($selfenrollhash{'validation'}{$item}) {
18144: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
18145: } else {
18146: $changes{'validation'}{$item} = &mt('None');
18147: }
18148: }
18149: } else {
18150: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
18151: if ($item eq 'markup') {
18152: if ($env{'form.selfenroll_validation_'.$item}) {
18153: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
18154: }
18155: }
18156: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18157: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
18158: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
18159: }
18160: }
18161: }
18162: }
18163:
18164: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
18165: $dom);
18166: if ($putresult eq 'ok') {
18167: if (keys(%changes) > 0) {
18168: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18169: $resulttext = &mt('Changes made:').'<ul>';
18170: foreach my $key ('admin','default','validation') {
18171: if (ref($changes{$key}) eq 'HASH') {
18172: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
18173: if ($key eq 'validation') {
18174: foreach my $item (@{$itemsref}) {
18175: if (exists($changes{$key}{$item})) {
18176: if ($item eq 'markup') {
18177: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18178: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
18179: } else {
18180: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18181: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
18182: }
18183: }
18184: }
18185: } else {
18186: foreach my $type (@types) {
18187: if ($type eq 'community') {
18188: $roles{'1'} = &mt('Community personnel');
18189: } else {
18190: $roles{'1'} = &mt('Course personnel');
18191: }
18192: if (ref($changes{$key}{$type}) eq 'ARRAY') {
18193: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18194: if ($key eq 'admin') {
18195: my @mgrdc = ();
18196: if (ref($ordered{$key}) eq 'ARRAY') {
18197: foreach my $item (@{$ordered{'admin'}}) {
18198: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18199: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
18200: push(@mgrdc,$item);
18201: }
18202: }
18203: }
18204: if (@mgrdc) {
18205: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
18206: } else {
18207: delete($domdefaults{$type.'selfenrolladmdc'});
18208: }
18209: }
18210: } else {
18211: if (ref($ordered{$key}) eq 'ARRAY') {
18212: foreach my $item (@{$ordered{$key}}) {
18213: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18214: $domdefaults{$type.'selfenroll'.$item} =
18215: $selfenrollhash{$key}{$type}{$item};
18216: }
18217: }
18218: }
18219: }
18220: }
18221: $resulttext .= '<li>'.$titles{$type}.'<ul>';
18222: foreach my $item (@{$ordered{$key}}) {
18223: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18224: $resulttext .= '<li>';
18225: if ($key eq 'admin') {
18226: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
18227: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
18228: } else {
18229: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
18230: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
18231: }
18232: $resulttext .= '</li>';
18233: }
18234: }
18235: $resulttext .= '</ul></li>';
18236: }
18237: }
18238: $resulttext .= '</ul></li>';
18239: }
18240: }
1.160.6.93 raeburn 18241: }
18242: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
18243: my $cachetime = 24*60*60;
18244: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18245: if (ref($lastactref) eq 'HASH') {
18246: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 18247: }
18248: }
18249: $resulttext .= '</ul>';
18250: } else {
18251: $resulttext = &mt('No changes made to self-enrollment settings');
18252: }
18253: } else {
18254: $resulttext = '<span class="LC_error">'.
18255: &mt('An error occurred: [_1]',$putresult).'</span>';
18256: }
18257: return $resulttext;
18258: }
18259:
1.160.6.113 raeburn 18260: sub modify_wafproxy {
18261: my ($dom,$action,$lastactref,%domconfig) = @_;
18262: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18263: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
18264: %wafproxy,%changes,%expirecache,%expiresaml);
18265: foreach my $server (sort(keys(%servers))) {
18266: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18267: if ($serverhome eq $server) {
18268: my $serverdom = &Apache::lonnet::host_domain($server);
18269: if ($serverdom eq $dom) {
18270: $canset{$server} = 1;
18271: }
18272: }
18273: }
18274: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
18275: %{$values{$dom}} = ();
18276: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
18277: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
18278: }
18279: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
18280: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
18281: }
18282: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18283: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
18284: }
18285: }
18286: my $output;
18287: if (keys(%canset)) {
18288: %{$wafproxy{'alias'}} = ();
18289: %{$wafproxy{'saml'}} = ();
18290: foreach my $key (sort(keys(%canset))) {
18291: if ($env{'form.wafproxy_'.$dom}) {
18292: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
18293: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
18294: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
18295: $changes{'alias'} = 1;
18296: }
18297: if ($env{'form.wafproxy_alias_saml_'.$key}) {
18298: $wafproxy{'saml'}{$key} = 1;
18299: }
18300: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
18301: $changes{'saml'} = 1;
18302: }
18303: } else {
18304: $wafproxy{'alias'}{$key} = '';
18305: $wafproxy{'saml'}{$key} = '';
18306: if ($curralias{$key}) {
18307: $changes{'alias'} = 1;
18308: }
18309: if ($currsaml{$key}) {
18310: $changes{'saml'} = 1;
18311: }
18312: }
18313: if ($wafproxy{'alias'}{$key} eq '') {
18314: if ($curralias{$key}) {
18315: $expirecache{$key} = 1;
18316: }
18317: delete($wafproxy{'alias'}{$key});
18318: }
18319: if ($wafproxy{'saml'}{$key} eq '') {
18320: if ($currsaml{$key}) {
18321: $expiresaml{$key} = 1;
18322: }
18323: delete($wafproxy{'saml'}{$key});
18324: }
18325: }
18326: unless (keys(%{$wafproxy{'alias'}})) {
18327: delete($wafproxy{'alias'});
18328: }
18329: unless (keys(%{$wafproxy{'saml'}})) {
18330: delete($wafproxy{'saml'});
18331: }
18332: # Localization for values in %warn occurs in &mt() calls separately.
18333: my %warn = (
18334: trusted => 'trusted IP range(s)',
18335: vpnint => 'internal IP range(s) for VPN sessions(s)',
18336: vpnext => 'IP range(s) for backend WAF connections',
18337: );
18338: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18339: my $possible = $env{'form.wafproxy_'.$item};
18340: $possible =~ s/^\s+|\s+$//g;
18341: if ($possible ne '') {
18342: if ($item eq 'remoteip') {
18343: if ($possible =~ /^[mhn]$/) {
18344: $wafproxy{$item} = $possible;
18345: }
18346: } elsif ($item eq 'ipheader') {
18347: if ($wafproxy{'remoteip'} eq 'h') {
18348: $wafproxy{$item} = $possible;
18349: }
18350: } elsif ($item eq 'sslopt') {
18351: if ($possible =~ /^0|1$/) {
18352: $wafproxy{$item} = $possible;
18353: }
18354: } else {
18355: my (@ok,$count);
18356: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
18357: unless ($env{'form.wafproxy_vpnaccess'}) {
18358: $possible = '';
18359: }
18360: } elsif ($item eq 'trusted') {
18361: unless ($wafproxy{'remoteip'} eq 'h') {
18362: $possible = '';
18363: }
18364: }
18365: unless ($possible eq '') {
18366: $possible =~ s/[\r\n]+/\s/g;
18367: $possible =~ s/\s*-\s*/-/g;
18368: $possible =~ s/\s+/,/g;
18369: $possible =~ s/,+/,/g;
18370: }
18371: $count = 0;
18372: if ($possible ne '') {
18373: foreach my $poss (split(/\,/,$possible)) {
18374: $count ++;
18375: $poss = &validate_ip_pattern($poss);
18376: if ($poss ne '') {
18377: push(@ok,$poss);
18378: }
18379: }
18380: my $diff = $count - scalar(@ok);
18381: if ($diff) {
18382: push(@warnings,'<li>'.
18383: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
18384: $diff,$warn{$item}).
18385: '</li>');
18386: }
18387: if (@ok) {
18388: my @cidr_list;
18389: foreach my $item (@ok) {
18390: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
18391: }
18392: $wafproxy{$item} = join(',',@cidr_list);
18393: }
18394: }
18395: }
18396: if ($wafproxy{$item} ne $currvalue{$item}) {
18397: $changes{$item} = 1;
18398: }
18399: } elsif ($currvalue{$item}) {
18400: $changes{$item} = 1;
18401: }
18402: }
18403: } else {
18404: if (keys(%curralias)) {
18405: $changes{'alias'} = 1;
18406: }
18407: if (keys(%currsaml)) {
18408: $changes{'saml'} = 1;
18409: }
18410: if (keys(%currvalue)) {
18411: foreach my $key (keys(%currvalue)) {
18412: $changes{$key} = 1;
18413: }
18414: }
18415: }
18416: if (keys(%changes)) {
18417: my %defaultshash = (
18418: wafproxy => \%wafproxy,
18419: );
18420: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18421: $dom);
18422: if ($putresult eq 'ok') {
18423: my $cachetime = 24*60*60;
18424: my (%domdefaults,$updatedomdefs);
18425: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
18426: if ($changes{$item}) {
18427: unless ($updatedomdefs) {
18428: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18429: $updatedomdefs = 1;
18430: }
18431: if ($wafproxy{$item}) {
18432: $domdefaults{'waf_'.$item} = $wafproxy{$item};
18433: } elsif (exists($domdefaults{'waf_'.$item})) {
18434: delete($domdefaults{'waf_'.$item});
18435: }
18436: }
18437: }
18438: if ($updatedomdefs) {
18439: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18440: if (ref($lastactref) eq 'HASH') {
18441: $lastactref->{'domdefaults'} = 1;
18442: }
18443: }
18444: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
18445: my %updates = %expirecache;
18446: foreach my $key (keys(%expirecache)) {
18447: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
18448: }
18449: if (ref($wafproxy{'alias'}) eq 'HASH') {
18450: my $cachetime = 24*60*60;
18451: foreach my $key (keys(%{$wafproxy{'alias'}})) {
18452: $updates{$key} = 1;
18453: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
18454: $cachetime);
18455: }
18456: }
18457: if (ref($lastactref) eq 'HASH') {
18458: $lastactref->{'proxyalias'} = \%updates;
18459: }
18460: }
18461: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
18462: my %samlupdates = %expiresaml;
18463: foreach my $key (keys(%expiresaml)) {
18464: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
18465: }
18466: if (ref($wafproxy{'saml'}) eq 'HASH') {
18467: my $cachetime = 24*60*60;
18468: foreach my $key (keys(%{$wafproxy{'saml'}})) {
18469: $samlupdates{$key} = 1;
18470: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
18471: $cachetime);
18472: }
18473: }
18474: if (ref($lastactref) eq 'HASH') {
18475: $lastactref->{'proxysaml'} = \%samlupdates;
18476: }
18477: }
18478: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 18479: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 18480: if ($changes{$item}) {
18481: if ($item eq 'alias') {
18482: my $numaliased = 0;
18483: if (ref($wafproxy{'alias'}) eq 'HASH') {
18484: my $shown;
18485: if (keys(%{$wafproxy{'alias'}})) {
18486: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
18487: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
18488: &Apache::lonnet::hostname($server),
18489: $wafproxy{'alias'}{$server}).'</li>';
18490: $numaliased ++;
18491: }
18492: if ($numaliased) {
18493: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
18494: '<ul>'.$shown.'</ul>').'</li>';
18495: }
18496: }
18497: }
18498: unless ($numaliased) {
18499: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
18500: }
18501: } elsif ($item eq 'saml') {
18502: my $shown;
18503: if (ref($wafproxy{'saml'}) eq 'HASH') {
18504: if (keys(%{$wafproxy{'saml'}})) {
18505: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
18506: }
18507: }
18508: if ($shown) {
18509: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
18510: $shown).'</li>';
18511: } else {
18512: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
18513: }
18514: } else {
18515: if ($item eq 'remoteip') {
18516: my %ip_methods = &remoteip_methods();
18517: if ($wafproxy{$item} =~ /^[mh]$/) {
18518: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
18519: $ip_methods{$wafproxy{$item}}).'</li>';
18520: } else {
18521: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
18522: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
18523: '</li>';
18524: } else {
18525: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
18526: }
18527: }
18528: } elsif ($item eq 'ipheader') {
18529: if ($wafproxy{$item}) {
18530: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
18531: $wafproxy{$item}).'</li>';
18532: } else {
18533: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
18534: }
18535: } elsif ($item eq 'trusted') {
18536: if ($wafproxy{$item}) {
18537: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
18538: $wafproxy{$item}).'</li>';
18539: } else {
18540: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
18541: }
18542: } elsif ($item eq 'vpnint') {
18543: if ($wafproxy{$item}) {
18544: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
18545: $wafproxy{$item}).'</li>';
18546: } else {
18547: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
18548: }
18549: } elsif ($item eq 'vpnext') {
18550: if ($wafproxy{$item}) {
18551: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
18552: $wafproxy{$item}).'</li>';
18553: } else {
18554: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
18555: }
18556: } elsif ($item eq 'sslopt') {
18557: if ($wafproxy{$item}) {
18558: $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>';
18559: } else {
18560: $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>';
18561: }
18562: }
18563: }
18564: }
18565: }
18566: } else {
18567: $output = '<span class="LC_error">'.
18568: &mt('An error occurred: [_1]',$putresult).'</span>';
18569: }
18570: } elsif (keys(%canset)) {
18571: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
18572: }
18573: if (@warnings) {
18574: $output .= '<br />'.&mt('Warnings:').'<ul>'.
18575: join("\n",@warnings).'</ul>';
18576: }
18577: return $output;
18578: }
18579:
18580: sub validate_ip_pattern {
18581: my ($pattern) = @_;
18582: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
18583: my ($start,$end) = ($1,$2);
18584: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
18585: if (($start !~ m{/}) && ($end !~ m{/})) {
18586: return $start.'-'.$end;
18587: }
18588: }
18589: } elsif ($pattern ne '') {
18590: $pattern = &Net::CIDR::cidrvalidate($pattern);
18591: if ($pattern ne '') {
18592: return $pattern;
18593: }
18594: }
18595: return;
18596: }
18597:
1.137 raeburn 18598: sub modify_usersessions {
1.160.6.27 raeburn 18599: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 18600: my @hostingtypes = ('version','excludedomain','includedomain');
18601: my @offloadtypes = ('primary','default');
18602: my %types = (
18603: remote => \@hostingtypes,
18604: hosted => \@hostingtypes,
18605: spares => \@offloadtypes,
18606: );
18607: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 18608: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 18609: my (%by_ip,%by_location,@intdoms);
18610: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
18611: my @locations = sort(keys(%by_location));
1.137 raeburn 18612: my (%defaultshash,%changes);
18613: foreach my $prefix (@prefixes) {
18614: $defaultshash{'usersessions'}{$prefix} = {};
18615: }
1.160.6.27 raeburn 18616: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 18617: my $resulttext;
1.138 raeburn 18618: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 18619: foreach my $prefix (@prefixes) {
1.145 raeburn 18620: next if ($prefix eq 'spares');
18621: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 18622: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18623: if ($type eq 'version') {
18624: my $value = $env{'form.'.$prefix.'_'.$type};
18625: my $okvalue;
18626: if ($value ne '') {
18627: if (grep(/^\Q$value\E$/,@lcversions)) {
18628: $okvalue = $value;
18629: }
18630: }
18631: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18632: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18633: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
18634: if ($inuse == 0) {
18635: $changes{$prefix}{$type} = 1;
18636: } else {
18637: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
18638: $changes{$prefix}{$type} = 1;
18639: }
18640: if ($okvalue ne '') {
18641: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18642: }
18643: }
18644: } else {
18645: if (($inuse == 1) && ($okvalue ne '')) {
18646: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18647: $changes{$prefix}{$type} = 1;
18648: }
18649: }
18650: } else {
18651: if (($inuse == 1) && ($okvalue ne '')) {
18652: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18653: $changes{$prefix}{$type} = 1;
18654: }
18655: }
18656: } else {
18657: if (($inuse == 1) && ($okvalue ne '')) {
18658: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18659: $changes{$prefix}{$type} = 1;
18660: }
18661: }
18662: } else {
18663: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18664: my @okvals;
18665: foreach my $val (@vals) {
1.138 raeburn 18666: if ($val =~ /:/) {
18667: my @items = split(/:/,$val);
18668: foreach my $item (@items) {
18669: if (ref($by_location{$item}) eq 'ARRAY') {
18670: push(@okvals,$item);
18671: }
18672: }
18673: } else {
18674: if (ref($by_location{$val}) eq 'ARRAY') {
18675: push(@okvals,$val);
18676: }
1.137 raeburn 18677: }
18678: }
18679: @okvals = sort(@okvals);
18680: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18681: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18682: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18683: if ($inuse == 0) {
18684: $changes{$prefix}{$type} = 1;
18685: } else {
18686: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18687: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18688: if (@changed > 0) {
18689: $changes{$prefix}{$type} = 1;
18690: }
18691: }
18692: } else {
18693: if ($inuse == 1) {
18694: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18695: $changes{$prefix}{$type} = 1;
18696: }
18697: }
18698: } else {
18699: if ($inuse == 1) {
18700: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18701: $changes{$prefix}{$type} = 1;
18702: }
18703: }
18704: } else {
18705: if ($inuse == 1) {
18706: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18707: $changes{$prefix}{$type} = 1;
18708: }
18709: }
18710: }
18711: }
18712: }
1.145 raeburn 18713:
18714: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 18715: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 18716: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18717: my $savespares;
18718:
18719: foreach my $lonhost (sort(keys(%servers))) {
18720: my $serverhomeID =
18721: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 18722: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 18723: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18724: my %spareschg;
18725: foreach my $type (@{$types{'spares'}}) {
18726: my @okspares;
18727: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18728: foreach my $server (@checked) {
1.152 raeburn 18729: if (&Apache::lonnet::hostname($server) ne '') {
18730: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18731: unless (grep(/^\Q$server\E$/,@okspares)) {
18732: push(@okspares,$server);
18733: }
1.145 raeburn 18734: }
18735: }
18736: }
18737: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18738: my $newspare;
1.152 raeburn 18739: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18740: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 18741: $newspare = $new;
18742: }
18743: }
1.152 raeburn 18744: my @spares;
18745: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18746: @spares = sort(@okspares,$newspare);
18747: } else {
18748: @spares = sort(@okspares);
18749: }
18750: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 18751: if (ref($spareid{$lonhost}) eq 'HASH') {
18752: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 18753: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 18754: if (@diffs > 0) {
18755: $spareschg{$type} = 1;
18756: }
18757: }
18758: }
18759: }
18760: if (keys(%spareschg) > 0) {
18761: $changes{'spares'}{$lonhost} = \%spareschg;
18762: }
18763: }
1.160.6.61 raeburn 18764: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 18765: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 18766: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18767: my @okoffload;
18768: if (@offloadnow) {
18769: foreach my $server (@offloadnow) {
18770: if (&Apache::lonnet::hostname($server) ne '') {
18771: unless (grep(/^\Q$server\E$/,@okoffload)) {
18772: push(@okoffload,$server);
18773: }
18774: }
18775: }
18776: if (@okoffload) {
18777: foreach my $lonhost (@okoffload) {
18778: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18779: }
18780: }
18781: }
1.160.6.105 raeburn 18782: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
18783: my @okoffloadoth;
18784: if (@offloadoth) {
18785: foreach my $server (@offloadoth) {
18786: if (&Apache::lonnet::hostname($server) ne '') {
18787: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
18788: push(@okoffloadoth,$server);
18789: }
18790: }
18791: }
18792: if (@okoffloadoth) {
18793: foreach my $lonhost (@okoffloadoth) {
18794: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
18795: }
18796: }
18797: }
1.145 raeburn 18798: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18799: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18800: if (ref($changes{'spares'}) eq 'HASH') {
18801: if (keys(%{$changes{'spares'}}) > 0) {
18802: $savespares = 1;
18803: }
18804: }
18805: } else {
18806: $savespares = 1;
18807: }
1.160.6.105 raeburn 18808: foreach my $offload ('offloadnow','offloadoth') {
18809: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
18810: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
18811: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
18812: $changes{$offload} = 1;
1.160.6.61 raeburn 18813: last;
18814: }
18815: }
1.160.6.105 raeburn 18816: unless ($changes{$offload}) {
18817: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
18818: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
18819: $changes{$offload} = 1;
18820: last;
18821: }
18822: }
18823: }
18824: } else {
18825: if (($offload eq 'offloadnow') && (@okoffload)) {
18826: $changes{'offloadnow'} = 1;
18827: }
18828: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
18829: $changes{'offloadoth'} = 1;
18830: }
1.160.6.61 raeburn 18831: }
1.160.6.105 raeburn 18832: }
18833: } else {
18834: if (@okoffload) {
1.160.6.61 raeburn 18835: $changes{'offloadnow'} = 1;
18836: }
1.160.6.105 raeburn 18837: if (@okoffloadoth) {
18838: $changes{'offloadoth'} = 1;
18839: }
1.145 raeburn 18840: }
1.147 raeburn 18841: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18842: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18843: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18844: $dom);
18845: if ($putresult eq 'ok') {
18846: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18847: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18848: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18849: }
18850: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18851: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18852: }
1.160.6.61 raeburn 18853: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18854: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18855: }
1.160.6.105 raeburn 18856: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18857: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
18858: }
1.137 raeburn 18859: }
18860: my $cachetime = 24*60*60;
18861: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 18862: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 18863: if (ref($lastactref) eq 'HASH') {
18864: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 18865: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 18866: }
1.147 raeburn 18867: if (keys(%changes) > 0) {
18868: my %lt = &usersession_titles();
18869: $resulttext = &mt('Changes made:').'<ul>';
18870: foreach my $prefix (@prefixes) {
18871: if (ref($changes{$prefix}) eq 'HASH') {
18872: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18873: if ($prefix eq 'spares') {
18874: if (ref($changes{$prefix}) eq 'HASH') {
18875: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18876: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18877: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 18878: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18879: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18880: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18881: foreach my $type (@{$types{$prefix}}) {
18882: if ($changes{$prefix}{$lonhost}{$type}) {
18883: my $offloadto = &mt('None');
18884: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18885: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18886: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18887: }
1.145 raeburn 18888: }
1.147 raeburn 18889: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18890: }
1.137 raeburn 18891: }
18892: }
1.147 raeburn 18893: $resulttext .= '</li>';
1.137 raeburn 18894: }
18895: }
1.147 raeburn 18896: } else {
18897: foreach my $type (@{$types{$prefix}}) {
18898: if (defined($changes{$prefix}{$type})) {
18899: my $newvalue;
18900: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18901: if (ref($defaultshash{'usersessions'}{$prefix})) {
18902: if ($type eq 'version') {
18903: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
18904: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18905: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18906: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18907: }
1.145 raeburn 18908: }
18909: }
18910: }
1.147 raeburn 18911: if ($newvalue eq '') {
18912: if ($type eq 'version') {
18913: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
18914: } else {
18915: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18916: }
1.145 raeburn 18917: } else {
1.147 raeburn 18918: if ($type eq 'version') {
18919: $newvalue .= ' '.&mt('(or later)');
18920: }
18921: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18922: }
1.137 raeburn 18923: }
18924: }
18925: }
1.147 raeburn 18926: $resulttext .= '</ul>';
1.137 raeburn 18927: }
18928: }
1.160.6.61 raeburn 18929: if ($changes{'offloadnow'}) {
18930: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18931: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 18932: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 18933: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18934: $resulttext .= '<li>'.$lonhost.'</li>';
18935: }
18936: $resulttext .= '</ul>';
18937: } else {
1.160.6.105 raeburn 18938: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
18939: }
18940: } else {
18941: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
18942: }
18943: }
18944: if ($changes{'offloadoth'}) {
18945: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18946: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
18947: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
18948: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
18949: $resulttext .= '<li>'.$lonhost.'</li>';
18950: }
18951: $resulttext .= '</ul>';
18952: } else {
18953: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 18954: }
18955: } else {
1.160.6.105 raeburn 18956: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 18957: }
18958: }
1.147 raeburn 18959: $resulttext .= '</ul>';
18960: } else {
18961: $resulttext = $nochgmsg;
1.137 raeburn 18962: }
18963: } else {
18964: $resulttext = '<span class="LC_error">'.
18965: &mt('An error occurred: [_1]',$putresult).'</span>';
18966: }
18967: } else {
1.147 raeburn 18968: $resulttext = $nochgmsg;
1.137 raeburn 18969: }
18970: return $resulttext;
18971: }
18972:
1.150 raeburn 18973: sub modify_loadbalancing {
18974: my ($dom,%domconfig) = @_;
18975: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18976: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18977: my ($othertitle,$usertypes,$types) =
18978: &Apache::loncommon::sorted_inst_types($dom);
18979: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 18980: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18981: my @sparestypes = ('primary','default');
18982: my %typetitles = &sparestype_titles();
18983: my $resulttext;
1.160.6.94 raeburn 18984: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18985: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18986: %existing = %{$domconfig{'loadbalancing'}};
18987: }
18988: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18989: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18990: my ($saveloadbalancing,%defaultshash,%changes);
18991: my ($alltypes,$othertypes,$titles) =
18992: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18993: my %ruletitles = &offloadtype_text();
18994: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18995: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18996: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18997: if ($balancer eq '') {
18998: next;
18999: }
19000: if (!exists($servers{$balancer})) {
19001: if (exists($currbalancer{$balancer})) {
19002: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 19003: }
1.160.6.7 raeburn 19004: next;
19005: }
19006: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
19007: push(@{$changes{'delete'}},$balancer);
19008: next;
19009: }
19010: if (!exists($currbalancer{$balancer})) {
19011: push(@{$changes{'add'}},$balancer);
19012: }
19013: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
19014: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
19015: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
19016: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
19017: $saveloadbalancing = 1;
19018: }
19019: foreach my $sparetype (@sparestypes) {
19020: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
19021: my @offloadto;
19022: foreach my $target (@targets) {
19023: if (($servers{$target}) && ($target ne $balancer)) {
19024: if ($sparetype eq 'default') {
19025: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
19026: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 19027: }
19028: }
1.160.6.7 raeburn 19029: unless(grep(/^\Q$target\E$/,@offloadto)) {
19030: push(@offloadto,$target);
19031: }
1.150 raeburn 19032: }
19033: }
1.160.6.76 raeburn 19034: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
19035: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
19036: push(@offloadto,$balancer);
19037: }
19038: }
19039: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 19040: }
1.160.6.94 raeburn 19041: if ($env{'form.loadbalancing_cookie_'.$i}) {
19042: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
19043: if (exists($currbalancer{$balancer})) {
19044: unless ($currcookies{$balancer}) {
19045: $changes{'curr'}{$balancer}{'cookie'} = 1;
19046: }
19047: }
19048: } elsif (exists($currbalancer{$balancer})) {
19049: if ($currcookies{$balancer}) {
19050: $changes{'curr'}{$balancer}{'cookie'} = 1;
19051: }
19052: }
1.160.6.7 raeburn 19053: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 19054: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 19055: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
19056: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 19057: if (@targetdiffs > 0) {
1.160.6.7 raeburn 19058: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 19059: }
1.160.6.7 raeburn 19060: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19061: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19062: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 19063: }
19064: }
19065: }
19066: } else {
1.160.6.7 raeburn 19067: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
19068: foreach my $sparetype (@sparestypes) {
19069: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19070: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19071: $changes{'curr'}{$balancer}{'targets'} = 1;
19072: }
1.150 raeburn 19073: }
19074: }
1.160.6.7 raeburn 19075: }
1.150 raeburn 19076: }
19077: my $ishomedom;
1.160.6.7 raeburn 19078: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
19079: $ishomedom = 1;
1.150 raeburn 19080: }
19081: if (ref($alltypes) eq 'ARRAY') {
19082: foreach my $type (@{$alltypes}) {
19083: my $rule;
1.160.6.7 raeburn 19084: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 19085: (!$ishomedom)) {
1.160.6.7 raeburn 19086: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
19087: }
19088: if ($rule eq 'specific') {
1.160.6.55 raeburn 19089: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
19090: if (exists($servers{$specifiedhost})) {
19091: $rule = $specifiedhost;
19092: }
1.150 raeburn 19093: }
1.160.6.7 raeburn 19094: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
19095: if (ref($currrules{$balancer}) eq 'HASH') {
19096: if ($rule ne $currrules{$balancer}{$type}) {
19097: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 19098: }
19099: } elsif ($rule ne '') {
1.160.6.7 raeburn 19100: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 19101: }
19102: }
19103: }
1.160.6.7 raeburn 19104: }
19105: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
19106: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
19107: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
19108: $defaultshash{'loadbalancing'} = {};
19109: }
19110: my $putresult = &Apache::lonnet::put_dom('configuration',
19111: \%defaultshash,$dom);
19112: if ($putresult eq 'ok') {
19113: if (keys(%changes) > 0) {
1.160.6.54 raeburn 19114: my %toupdate;
1.160.6.7 raeburn 19115: if (ref($changes{'delete'}) eq 'ARRAY') {
19116: foreach my $balancer (sort(@{$changes{'delete'}})) {
19117: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 19118: $toupdate{$balancer} = 1;
1.150 raeburn 19119: }
1.160.6.7 raeburn 19120: }
19121: if (ref($changes{'add'}) eq 'ARRAY') {
19122: foreach my $balancer (sort(@{$changes{'add'}})) {
19123: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 19124: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 19125: }
19126: }
19127: if (ref($changes{'curr'}) eq 'HASH') {
19128: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 19129: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 19130: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
19131: if ($changes{'curr'}{$balancer}{'targets'}) {
19132: my %offloadstr;
19133: foreach my $sparetype (@sparestypes) {
19134: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19135: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19136: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19137: }
19138: }
1.150 raeburn 19139: }
1.160.6.7 raeburn 19140: if (keys(%offloadstr) == 0) {
19141: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 19142: } else {
1.160.6.7 raeburn 19143: my $showoffload;
19144: foreach my $sparetype (@sparestypes) {
19145: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
19146: if (defined($offloadstr{$sparetype})) {
19147: $showoffload .= $offloadstr{$sparetype};
19148: } else {
19149: $showoffload .= &mt('None');
19150: }
19151: $showoffload .= (' 'x3);
19152: }
19153: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 19154: }
19155: }
19156: }
1.160.6.7 raeburn 19157: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
19158: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
19159: foreach my $type (@{$alltypes}) {
19160: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
19161: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19162: my $balancetext;
19163: if ($rule eq '') {
19164: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 19165: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 19166: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
19167: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 19168: foreach my $sparetype (@sparestypes) {
19169: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19170: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19171: }
19172: }
1.160.6.55 raeburn 19173: foreach my $item (@{$alltypes}) {
19174: next if ($item =~ /^_LC_ipchange/);
19175: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
19176: if ($hasrule eq 'homeserver') {
19177: map { $toupdate{$_} = 1; } (keys(%libraryservers));
19178: } else {
19179: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
19180: if ($servers{$hasrule}) {
19181: $toupdate{$hasrule} = 1;
19182: }
19183: }
19184: }
19185: }
19186: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
19187: $balancetext = $ruletitles{$rule};
19188: } else {
19189: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19190: $balancetext = $ruletitles{'particular'}.' '.$receiver;
19191: if ($receiver) {
19192: $toupdate{$receiver};
19193: }
19194: }
19195: } else {
19196: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 19197: }
1.160.6.7 raeburn 19198: } else {
19199: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
19200: }
1.160.6.26 raeburn 19201: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 19202: }
19203: }
19204: }
19205: }
1.160.6.94 raeburn 19206: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 19207: if ($currcookies{$balancer}) {
19208: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
19209: $balancer).'</li>';
19210: } else {
19211: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
19212: $balancer).'</li>';
19213: }
1.160.6.94 raeburn 19214: }
1.160.6.106 raeburn 19215: }
19216: }
19217: if (keys(%toupdate)) {
19218: my %thismachine;
19219: my $updatedhere;
19220: my $cachetime = 60*60*24;
19221: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
19222: foreach my $lonhost (keys(%toupdate)) {
19223: if ($thismachine{$lonhost}) {
19224: unless ($updatedhere) {
19225: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
19226: $defaultshash{'loadbalancing'},
19227: $cachetime);
19228: $updatedhere = 1;
1.160.6.54 raeburn 19229: }
1.160.6.106 raeburn 19230: } else {
19231: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
19232: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 19233: }
1.150 raeburn 19234: }
1.160.6.7 raeburn 19235: }
19236: if ($resulttext ne '') {
19237: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 19238: } else {
19239: $resulttext = $nochgmsg;
19240: }
19241: } else {
1.160.6.7 raeburn 19242: $resulttext = $nochgmsg;
1.150 raeburn 19243: }
19244: } else {
1.160.6.7 raeburn 19245: $resulttext = '<span class="LC_error">'.
19246: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 19247: }
19248: } else {
1.160.6.7 raeburn 19249: $resulttext = $nochgmsg;
1.150 raeburn 19250: }
19251: return $resulttext;
19252: }
19253:
1.48 raeburn 19254: sub recurse_check {
19255: my ($chkcats,$categories,$depth,$name) = @_;
19256: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
19257: my $chg = 0;
19258: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
19259: my $category = $chkcats->[$depth]{$name}[$j];
19260: my $item;
19261: if ($category eq '') {
19262: $chg ++;
19263: } else {
19264: my $deeper = $depth + 1;
19265: $item = &escape($category).':'.&escape($name).':'.$depth;
19266: if ($chg) {
19267: $categories->{$item} -= $chg;
19268: }
19269: &recurse_check($chkcats,$categories,$deeper,$category);
19270: $deeper --;
19271: }
19272: }
19273: }
19274: return;
19275: }
19276:
19277: sub recurse_cat_deletes {
19278: my ($item,$coursecategories,$deletions) = @_;
19279: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
19280: my $subdepth = $depth + 1;
19281: if (ref($coursecategories) eq 'HASH') {
19282: foreach my $subitem (keys(%{$coursecategories})) {
19283: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
19284: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
19285: delete($coursecategories->{$subitem});
19286: $deletions->{$subitem} = 1;
19287: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 19288: }
1.48 raeburn 19289: }
19290: }
19291: return;
19292: }
19293:
1.125 raeburn 19294: sub active_dc_picker {
1.160.6.16 raeburn 19295: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 19296: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 19297: my @domcoord = keys(%domcoords);
19298: if (keys(%currhash)) {
19299: foreach my $dc (keys(%currhash)) {
19300: unless (exists($domcoords{$dc})) {
19301: push(@domcoord,$dc);
19302: }
19303: }
19304: }
19305: @domcoord = sort(@domcoord);
19306: my $numdcs = scalar(@domcoord);
19307: my $rows = 0;
19308: my $table;
1.125 raeburn 19309: if ($numdcs > 1) {
1.160.6.16 raeburn 19310: $table = '<table>';
19311: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 19312: my $rem = $i%($numinrow);
19313: if ($rem == 0) {
19314: if ($i > 0) {
1.160.6.16 raeburn 19315: $table .= '</tr>';
1.125 raeburn 19316: }
1.160.6.16 raeburn 19317: $table .= '<tr>';
19318: $rows ++;
1.125 raeburn 19319: }
1.160.6.16 raeburn 19320: my $check = '';
19321: if ($inputtype eq 'radio') {
19322: if (keys(%currhash) == 0) {
19323: if (!$i) {
19324: $check = ' checked="checked"';
19325: }
19326: } elsif (exists($currhash{$domcoord[$i]})) {
19327: $check = ' checked="checked"';
19328: }
19329: } else {
19330: if (exists($currhash{$domcoord[$i]})) {
19331: $check = ' checked="checked"';
1.125 raeburn 19332: }
19333: }
1.160.6.16 raeburn 19334: if ($i == @domcoord - 1) {
1.125 raeburn 19335: my $colsleft = $numinrow - $rem;
19336: if ($colsleft > 1) {
1.160.6.16 raeburn 19337: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 19338: } else {
1.160.6.16 raeburn 19339: $table .= '<td class="LC_left_item">';
1.125 raeburn 19340: }
19341: } else {
1.160.6.16 raeburn 19342: $table .= '<td class="LC_left_item">';
19343: }
19344: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
19345: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
19346: $table .= '<span class="LC_nobreak"><label>'.
19347: '<input type="'.$inputtype.'" name="'.$name.'"'.
19348: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
19349: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 19350: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 19351: }
1.160.6.33 raeburn 19352: $table .= '</label></span></td>';
1.125 raeburn 19353: }
1.160.6.16 raeburn 19354: $table .= '</tr></table>';
19355: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 19356: my ($dcname,$dcdom) = split(':',$domcoord[0]);
19357: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 19358: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 19359: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 19360: if ($user ne $dcname.':'.$dcdom) {
19361: $table .= ' ('.$dcname.':'.$dcdom.')';
19362: }
1.160.6.16 raeburn 19363: } else {
19364: my $check;
19365: if (exists($currhash{$domcoord[0]})) {
19366: $check = ' checked="checked"';
19367: }
1.160.6.50 raeburn 19368: $table = '<span class="LC_nobreak"><label>'.
19369: '<input type="checkbox" name="'.$name.'" '.
19370: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 19371: if ($user ne $dcname.':'.$dcdom) {
19372: $table .= ' ('.$dcname.':'.$dcdom.')';
19373: }
19374: $table .= '</label></span>';
1.160.6.16 raeburn 19375: $rows ++;
19376: }
1.125 raeburn 19377: }
1.160.6.16 raeburn 19378: return ($numdcs,$table,$rows);
1.125 raeburn 19379: }
19380:
1.137 raeburn 19381: sub usersession_titles {
19382: return &Apache::lonlocal::texthash(
19383: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19384: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 19385: spares => 'Servers offloaded to, when busy',
1.137 raeburn 19386: version => 'LON-CAPA version requirement',
1.138 raeburn 19387: excludedomain => 'Allow all, but exclude specific domains',
19388: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 19389: primary => 'Primary (checked first)',
1.154 raeburn 19390: default => 'Default',
1.137 raeburn 19391: );
19392: }
19393:
1.152 raeburn 19394: sub id_for_thisdom {
19395: my (%servers) = @_;
19396: my %altids;
19397: foreach my $server (keys(%servers)) {
19398: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19399: if ($serverhome ne $server) {
19400: $altids{$serverhome} = $server;
19401: }
19402: }
19403: return %altids;
19404: }
19405:
1.150 raeburn 19406: sub count_servers {
19407: my ($currbalancer,%servers) = @_;
19408: my (@spares,$numspares);
19409: foreach my $lonhost (sort(keys(%servers))) {
19410: next if ($currbalancer eq $lonhost);
19411: push(@spares,$lonhost);
19412: }
19413: if ($currbalancer) {
19414: $numspares = scalar(@spares);
19415: } else {
19416: $numspares = scalar(@spares) - 1;
19417: }
19418: return ($numspares,@spares);
19419: }
19420:
19421: sub lonbalance_targets_js {
1.160.6.7 raeburn 19422: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 19423: my $select = &mt('Select');
19424: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19425: if (ref($servers) eq 'HASH') {
19426: $alltargets = join("','",sort(keys(%{$servers})));
19427: my @homedoms;
19428: foreach my $server (sort(keys(%{$servers}))) {
19429: if (&Apache::lonnet::host_domain($server) eq $dom) {
19430: push(@homedoms,'1');
19431: } else {
19432: push(@homedoms,'0');
19433: }
19434: }
19435: $allishome = join("','",@homedoms);
19436: }
19437: if (ref($types) eq 'ARRAY') {
19438: if (@{$types} > 0) {
19439: @alltypes = @{$types};
19440: }
19441: }
19442: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19443: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 19444: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 19445: if (ref($settings) eq 'HASH') {
19446: %existing = %{$settings};
19447: }
19448: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 19449: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 19450: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 19451: return <<"END";
19452:
19453: <script type="text/javascript">
19454: // <![CDATA[
19455:
1.160.6.7 raeburn 19456: currBalancers = new Array('$balancers');
19457:
19458: function toggleTargets(balnum) {
19459: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19460: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19461: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19462: var prevbalancer = prevhostitem.value;
19463: var baltotal = document.getElementById('loadbalancing_total').value;
19464: prevhostitem.value = balancer;
19465: if (prevbalancer != '') {
19466: var prevIdx = currBalancers.indexOf(prevbalancer);
19467: if (prevIdx != -1) {
19468: currBalancers.splice(prevIdx,1);
19469: }
19470: }
1.150 raeburn 19471: if (balancer == '') {
1.160.6.7 raeburn 19472: hideSpares(balnum);
1.150 raeburn 19473: } else {
1.160.6.7 raeburn 19474: var currIdx = currBalancers.indexOf(balancer);
19475: if (currIdx == -1) {
19476: currBalancers.push(balancer);
19477: }
1.150 raeburn 19478: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 19479: var ishomedom = homedoms[lonhostitem.selectedIndex];
19480: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 19481: }
1.160.6.7 raeburn 19482: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 19483: return;
19484: }
19485:
1.160.6.7 raeburn 19486: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 19487: var alltargets = new Array('$alltargets');
19488: var insttypes = new Array('$allinsttypes');
1.151 raeburn 19489: var offloadtypes = new Array('primary','default');
19490:
1.160.6.7 raeburn 19491: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19492: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 19493:
1.151 raeburn 19494: for (var i=0; i<offloadtypes.length; i++) {
19495: var count = 0;
19496: for (var j=0; j<alltargets.length; j++) {
19497: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 19498: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19499: item.value = alltargets[j];
19500: item.style.textAlign='left';
19501: item.style.textFace='normal';
19502: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19503: if (currBalancers.indexOf(alltargets[j]) == -1) {
19504: item.disabled = '';
19505: } else {
19506: item.disabled = 'disabled';
19507: item.checked = false;
19508: }
1.151 raeburn 19509: count ++;
19510: }
1.150 raeburn 19511: }
19512: }
1.151 raeburn 19513: for (var k=0; k<insttypes.length; k++) {
19514: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 19515: if (ishomedom == 1) {
1.160.6.7 raeburn 19516: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19517: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19518: } else {
1.160.6.7 raeburn 19519: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19520: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 19521: }
19522: } else {
1.160.6.7 raeburn 19523: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19524: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19525: }
1.151 raeburn 19526: if ((insttypes[k] != '_LC_external') &&
19527: ((insttypes[k] != '_LC_internetdom') ||
19528: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 19529: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19530: item.options.length = 0;
19531: item.options[0] = new Option("","",true,true);
19532: var idx = 0;
1.151 raeburn 19533: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 19534: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19535: idx ++;
19536: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 19537: }
19538: }
19539: }
19540: }
19541: return;
19542: }
19543:
1.160.6.7 raeburn 19544: function hideSpares(balnum) {
1.150 raeburn 19545: var alltargets = new Array('$alltargets');
19546: var insttypes = new Array('$allinsttypes');
19547: var offloadtypes = new Array('primary','default');
19548:
1.160.6.7 raeburn 19549: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19550: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 19551:
19552: var total = alltargets.length - 1;
19553: for (var i=0; i<offloadtypes; i++) {
19554: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 19555: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19556: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19557: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 19558: }
1.150 raeburn 19559: }
19560: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 19561: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19562: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 19563: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 19564: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19565: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 19566: }
19567: }
19568: return;
19569: }
19570:
1.160.6.7 raeburn 19571: function checkOffloads(item,balnum,type) {
1.150 raeburn 19572: var alltargets = new Array('$alltargets');
19573: var offloadtypes = new Array('primary','default');
19574: if (item.checked) {
19575: var total = alltargets.length - 1;
19576: var other;
19577: if (type == offloadtypes[0]) {
1.151 raeburn 19578: other = offloadtypes[1];
1.150 raeburn 19579: } else {
1.151 raeburn 19580: other = offloadtypes[0];
1.150 raeburn 19581: }
19582: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 19583: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 19584: if (server == item.value) {
1.160.6.7 raeburn 19585: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19586: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 19587: }
19588: }
19589: }
19590: }
19591: return;
19592: }
19593:
1.160.6.7 raeburn 19594: function singleServerToggle(balnum,type) {
19595: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 19596: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 19597: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19598: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19599:
19600: } else {
1.160.6.7 raeburn 19601: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19602: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 19603: }
19604: return;
19605: }
19606:
1.160.6.7 raeburn 19607: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 19608: if (type == '_LC_external') {
1.160.6.26 raeburn 19609: return;
1.150 raeburn 19610: }
1.160.6.7 raeburn 19611: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 19612: for (var i=0; i<typesRules.length; i++) {
19613: if (formname.elements[typesRules[i]].checked) {
19614: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 19615: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19616: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19617: } else {
1.160.6.7 raeburn 19618: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19619: }
19620: }
19621: }
19622: return;
19623: }
19624:
19625: function balancerDeleteChange(balnum) {
19626: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19627: var baltotal = document.getElementById('loadbalancing_total').value;
19628: var addtarget;
19629: var removetarget;
19630: var action = 'delete';
19631: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19632: var lonhost = hostitem.value;
19633: var currIdx = currBalancers.indexOf(lonhost);
19634: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19635: if (currIdx != -1) {
19636: currBalancers.splice(currIdx,1);
19637: }
19638: addtarget = lonhost;
19639: } else {
19640: if (currIdx == -1) {
19641: currBalancers.push(lonhost);
19642: }
19643: removetarget = lonhost;
19644: action = 'undelete';
19645: }
19646: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19647: }
19648: return;
19649: }
19650:
19651: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19652: if (baltotal > 1) {
19653: var offloadtypes = new Array('primary','default');
19654: var alltargets = new Array('$alltargets');
19655: var insttypes = new Array('$allinsttypes');
19656: for (var i=0; i<baltotal; i++) {
19657: if (i != balnum) {
19658: for (var j=0; j<offloadtypes.length; j++) {
19659: var total = alltargets.length - 1;
19660: for (var k=0; k<total; k++) {
19661: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19662: var server = serveritem.value;
19663: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19664: if (server == addtarget) {
19665: serveritem.disabled = '';
19666: }
19667: }
19668: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19669: if (server == removetarget) {
19670: serveritem.disabled = 'disabled';
19671: serveritem.checked = false;
19672: }
19673: }
19674: }
19675: }
19676: for (var j=0; j<insttypes.length; j++) {
19677: if (insttypes[j] != '_LC_external') {
19678: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19679: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19680: var currSel = singleserver.selectedIndex;
19681: var currVal = singleserver.options[currSel].value;
19682: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19683: var numoptions = singleserver.options.length;
19684: var needsnew = 1;
19685: for (var k=0; k<numoptions; k++) {
19686: if (singleserver.options[k] == addtarget) {
19687: needsnew = 0;
19688: break;
19689: }
19690: }
19691: if (needsnew == 1) {
19692: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19693: }
19694: }
19695: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19696: singleserver.options.length = 0;
19697: if ((currVal) && (currVal != removetarget)) {
19698: singleserver.options[0] = new Option("","",false,false);
19699: } else {
19700: singleserver.options[0] = new Option("","",true,true);
19701: }
19702: var idx = 0;
19703: for (var m=0; m<alltargets.length; m++) {
19704: if (currBalancers.indexOf(alltargets[m]) == -1) {
19705: idx ++;
19706: if (currVal == alltargets[m]) {
19707: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19708: } else {
19709: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19710: }
19711: }
19712: }
19713: }
19714: }
19715: }
19716: }
1.150 raeburn 19717: }
19718: }
19719: }
19720: return;
19721: }
19722:
1.152 raeburn 19723: // ]]>
19724: </script>
19725:
19726: END
19727: }
19728:
19729: sub new_spares_js {
19730: my @sparestypes = ('primary','default');
19731: my $types = join("','",@sparestypes);
19732: my $select = &mt('Select');
19733: return <<"END";
19734:
19735: <script type="text/javascript">
19736: // <![CDATA[
19737:
19738: function updateNewSpares(formname,lonhost) {
19739: var types = new Array('$types');
19740: var include = new Array();
19741: var exclude = new Array();
19742: for (var i=0; i<types.length; i++) {
19743: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19744: for (var j=0; j<spareboxes.length; j++) {
19745: if (formname.elements[spareboxes[j]].checked) {
19746: exclude.push(formname.elements[spareboxes[j]].value);
19747: } else {
19748: include.push(formname.elements[spareboxes[j]].value);
19749: }
19750: }
19751: }
19752: for (var i=0; i<types.length; i++) {
19753: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19754: var selIdx = newSpare.selectedIndex;
19755: var currnew = newSpare.options[selIdx].value;
19756: var okSpares = new Array();
19757: for (var j=0; j<newSpare.options.length; j++) {
19758: var possible = newSpare.options[j].value;
19759: if (possible != '') {
19760: if (exclude.indexOf(possible) == -1) {
19761: okSpares.push(possible);
19762: } else {
19763: if (currnew == possible) {
19764: selIdx = 0;
19765: }
19766: }
19767: }
19768: }
19769: for (var k=0; k<include.length; k++) {
19770: if (okSpares.indexOf(include[k]) == -1) {
19771: okSpares.push(include[k]);
19772: }
19773: }
19774: okSpares.sort();
19775: newSpare.options.length = 0;
19776: if (selIdx == 0) {
19777: newSpare.options[0] = new Option("$select","",true,true);
19778: } else {
19779: newSpare.options[0] = new Option("$select","",false,false);
19780: }
19781: for (var m=0; m<okSpares.length; m++) {
19782: var idx = m+1;
19783: var selThis = 0;
19784: if (selIdx != 0) {
19785: if (okSpares[m] == currnew) {
19786: selThis = 1;
19787: }
19788: }
19789: if (selThis == 1) {
19790: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19791: } else {
19792: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19793: }
19794: }
19795: }
19796: return;
19797: }
19798:
19799: function checkNewSpares(lonhost,type) {
19800: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19801: var chosen = newSpare.options[newSpare.selectedIndex].value;
19802: if (chosen != '') {
19803: var othertype;
19804: var othernewSpare;
19805: if (type == 'primary') {
19806: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19807: }
19808: if (type == 'default') {
19809: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19810: }
19811: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19812: othernewSpare.selectedIndex = 0;
19813: }
19814: }
19815: return;
19816: }
19817:
19818: // ]]>
19819: </script>
19820:
19821: END
19822:
19823: }
19824:
19825: sub common_domprefs_js {
19826: return <<"END";
19827:
19828: <script type="text/javascript">
19829: // <![CDATA[
19830:
1.150 raeburn 19831: function getIndicesByName(formname,item) {
1.152 raeburn 19832: var group = new Array();
1.150 raeburn 19833: for (var i=0;i<formname.elements.length;i++) {
19834: if (formname.elements[i].name == item) {
1.152 raeburn 19835: group.push(formname.elements[i].id);
1.150 raeburn 19836: }
19837: }
1.152 raeburn 19838: return group;
1.150 raeburn 19839: }
19840:
19841: // ]]>
19842: </script>
19843:
19844: END
1.152 raeburn 19845:
1.150 raeburn 19846: }
19847:
1.160.6.5 raeburn 19848: sub recaptcha_js {
19849: my %lt = &captcha_phrases();
19850: return <<"END";
19851:
19852: <script type="text/javascript">
19853: // <![CDATA[
19854:
19855: function updateCaptcha(caller,context) {
19856: var privitem;
19857: var pubitem;
19858: var privtext;
19859: var pubtext;
1.160.6.69 raeburn 19860: var versionitem;
19861: var versiontext;
1.160.6.5 raeburn 19862: if (document.getElementById(context+'_recaptchapub')) {
19863: pubitem = document.getElementById(context+'_recaptchapub');
19864: } else {
19865: return;
19866: }
19867: if (document.getElementById(context+'_recaptchapriv')) {
19868: privitem = document.getElementById(context+'_recaptchapriv');
19869: } else {
19870: return;
19871: }
19872: if (document.getElementById(context+'_recaptchapubtxt')) {
19873: pubtext = document.getElementById(context+'_recaptchapubtxt');
19874: } else {
19875: return;
19876: }
19877: if (document.getElementById(context+'_recaptchaprivtxt')) {
19878: privtext = document.getElementById(context+'_recaptchaprivtxt');
19879: } else {
19880: return;
19881: }
1.160.6.69 raeburn 19882: if (document.getElementById(context+'_recaptchaversion')) {
19883: versionitem = document.getElementById(context+'_recaptchaversion');
19884: } else {
19885: return;
19886: }
19887: if (document.getElementById(context+'_recaptchavertxt')) {
19888: versiontext = document.getElementById(context+'_recaptchavertxt');
19889: } else {
19890: return;
19891: }
1.160.6.5 raeburn 19892: if (caller.checked) {
19893: if (caller.value == 'recaptcha') {
19894: pubitem.type = 'text';
19895: privitem.type = 'text';
19896: pubitem.size = '40';
19897: privitem.size = '40';
19898: pubtext.innerHTML = "$lt{'pub'}";
19899: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 19900: versionitem.type = 'text';
19901: versionitem.size = '3';
19902: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 19903: } else {
19904: pubitem.type = 'hidden';
19905: privitem.type = 'hidden';
1.160.6.69 raeburn 19906: versionitem.type = 'hidden';
1.160.6.5 raeburn 19907: pubtext.innerHTML = '';
19908: privtext.innerHTML = '';
1.160.6.69 raeburn 19909: versiontext.innerHTML = '';
1.160.6.5 raeburn 19910: }
19911: }
19912: return;
19913: }
19914:
19915: // ]]>
19916: </script>
19917:
19918: END
19919:
19920: }
19921:
1.160.6.40 raeburn 19922: sub toggle_display_js {
1.160.6.16 raeburn 19923: return <<"END";
19924:
19925: <script type="text/javascript">
19926: // <![CDATA[
19927:
1.160.6.40 raeburn 19928: function toggleDisplay(domForm,caller) {
19929: if (document.getElementById(caller)) {
19930: var divitem = document.getElementById(caller);
19931: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 19932: var checkval = 1;
19933: var dispval = 'block';
1.160.6.93 raeburn 19934: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 19935: if (caller == 'emailoptions') {
19936: optionsElement = domForm.cancreate_email;
19937: }
1.160.6.57 raeburn 19938: if (caller == 'studentsubmission') {
19939: optionsElement = domForm.postsubmit;
19940: }
1.160.6.64 raeburn 19941: if (caller == 'cloneinstcode') {
19942: optionsElement = domForm.canclone;
19943: checkval = 'instcode';
19944: }
1.160.6.93 raeburn 19945: if (selfcreateRegExp.test(caller)) {
19946: optionsElement = domForm.elements[caller];
19947: checkval = 'other';
19948: dispval = 'inline'
19949: }
1.160.6.40 raeburn 19950: if (optionsElement.length) {
1.160.6.16 raeburn 19951: var currval;
1.160.6.40 raeburn 19952: for (var i=0; i<optionsElement.length; i++) {
19953: if (optionsElement[i].checked) {
19954: currval = optionsElement[i].value;
1.160.6.16 raeburn 19955: }
19956: }
1.160.6.64 raeburn 19957: if (currval == checkval) {
19958: divitem.style.display = dispval;
1.160.6.16 raeburn 19959: } else {
1.160.6.40 raeburn 19960: divitem.style.display = 'none';
1.160.6.16 raeburn 19961: }
19962: }
19963: }
19964: return;
19965: }
19966:
19967: // ]]>
19968: </script>
19969:
19970: END
19971:
19972: }
19973:
1.160.6.5 raeburn 19974: sub captcha_phrases {
19975: return &Apache::lonlocal::texthash (
19976: priv => 'Private key',
19977: pub => 'Public key',
19978: original => 'original (CAPTCHA)',
19979: recaptcha => 'successor (ReCAPTCHA)',
19980: notused => 'unused',
1.160.6.69 raeburn 19981: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 19982: );
19983: }
19984:
1.160.6.24 raeburn 19985: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 19986: my ($dom,$cachekeys) = @_;
19987: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 19988: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19989: my %thismachine;
19990: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 19991:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 19992: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
19993: 'ipaccess');
19994: my %cache_by_lonhost;
19995: if (exists($cachekeys->{'samllanding'})) {
19996: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
19997: my %landing = %{$cachekeys->{'samllanding'}};
19998: my %domservers = &Apache::lonnet::get_servers($dom);
19999: if (keys(%domservers)) {
20000: foreach my $server (keys(%domservers)) {
20001: my @cached;
20002: next if ($thismachine{$server});
20003: if ($landing{$server}) {
20004: push(@cached,&escape('samllanding').':'.&escape($server));
20005: }
20006: if (@cached) {
20007: $cache_by_lonhost{$server} = \@cached;
20008: }
20009: }
20010: }
20011: }
20012: }
1.160.6.61 raeburn 20013: if (keys(%servers)) {
1.160.6.24 raeburn 20014: foreach my $server (keys(%servers)) {
20015: next if ($thismachine{$server});
1.160.6.27 raeburn 20016: my @cached;
20017: foreach my $name (@posscached) {
20018: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 20019: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
20020: if (ref($cachekeys->{$name}) eq 'HASH') {
20021: foreach my $key (keys(%{$cachekeys->{$name}})) {
20022: push(@cached,&escape($name).':'.&escape($key));
20023: }
20024: }
20025: } else {
20026: push(@cached,&escape($name).':'.&escape($dom));
20027: }
1.160.6.27 raeburn 20028: }
20029: }
1.160.6.113 raeburn 20030: if ((exists($cache_by_lonhost{$server})) &&
20031: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
20032: push(@cached,@{$cache_by_lonhost{$server}});
20033: }
1.160.6.27 raeburn 20034: if (@cached) {
20035: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
20036: }
1.160.6.24 raeburn 20037: }
20038: }
20039: return;
20040: }
20041:
1.3 raeburn 20042: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>