Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.8
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 8(raebur 4:2): # $Id: domainprefs.pm,v 1.160.6.118.2.7 2022/02/22 19:18:45 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.20 raeburn 333: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
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";
1474: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso,%styleon,%styleoff);
1475: foreach my $lonhost (keys(%domservers)) {
1476: $samlurl{$lonhost} = '/adm/sso';
1477: $styleon{$lonhost} = 'display:none';
1478: $styleoff{$lonhost} = '';
1479: }
1480: if (ref($settings->{'saml'}) eq 'HASH') {
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'};
1489: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1490: $styleon{$lonhost} = '';
1491: $styleoff{$lonhost} = 'display:none';
1492: } else {
1493: $styleon{$lonhost} = 'display:none';
1494: $styleoff{$lonhost} = '';
1495: }
1496: }
1497: }
1498: my $itemcount = 1;
1499: foreach my $lonhost (sort(keys(%domservers))) {
1500: my $samlon = ' ';
1501: my $samloff = ' checked="checked" ';
1502: if ($saml{$lonhost}) {
1503: $samlon = $samloff;
1504: $samloff = ' ';
1505: }
1506: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1507: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1508: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1509: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1510: &mt('No').'</label>'.(' 'x2).
1511: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1512: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1513: &mt('Yes').'</label></span></td>'.
1514: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1515: '<table><tr><th colspan="5" align="center">'.&mt('SSO').'</th><th align="center">'.
1516: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1517: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1518: '<th>'.&mt('Alt Text').'</th><th>'.&mt('URL').'</th>'.
1519: '<th>'.&mt('Tool Tip').'</th><th>'.&mt('Text').'</th></tr>'.
1520: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="8" value="'.
1521: $samltext{$lonhost}.'" /></td><td>';
1522: if ($samlimg{$lonhost}) {
1523: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1524: '<span class="LC_nobreak"><label>'.
1525: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1526: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1527: } else {
1528: $datatable .= $lt{'upl'};
1529: }
1530: $datatable .='<br />';
1531: if ($switchserver) {
1532: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1533: } else {
1534: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1535: }
1536: $datatable .= '</td>'.
1537: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="20" '.
1538: 'value="'.$samlalt{$lonhost}.'" /></td>'.
1539: '<td><input type="text" name="saml_url_'.$lonhost.'" size="8" '.
1540: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1541: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="15">'.
1542: $samltitle{$lonhost}.'</textarea></td>'.
1543: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="8" '.
1544: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1545: '</table></td>'.
1546: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1547: $itemcount ++;
1548: }
1549: $datatable .= '</table></td></tr>';
1.1 raeburn 1550: }
1.6 raeburn 1551: return $datatable;
1552: }
1553:
1554: sub login_choices {
1555: my %choices =
1556: &Apache::lonlocal::texthash (
1.116 bisitz 1557: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1558: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1559: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1560: disallowlogin => "Login page requests redirected",
1561: hostid => "Server",
1.128 raeburn 1562: server => "Redirect to:",
1563: serverpath => "Path",
1564: custompath => "Custom",
1565: exempt => "Exempt IP(s)",
1.110 raeburn 1566: directlogin => "No redirect",
1567: newuser => "Link to create a user account",
1568: img => "Header",
1569: logo => "Main Logo",
1570: domlogo => "Domain Logo",
1571: login => "Log-in Header",
1572: textcol => "Text color",
1573: bgcol => "Box color",
1574: bgs => "Background colors",
1575: links => "Link colors",
1576: font => "Font color",
1577: pgbg => "Header",
1578: mainbg => "Page",
1579: sidebg => "Login box",
1580: link => "Link",
1581: alink => "Active link",
1582: vlink => "Visited link",
1.160.6.56 raeburn 1583: headtag => "Custom markup",
1584: action => "Action",
1585: current => "Current",
1.160.6.113 raeburn 1586: samllanding => "Dual login?",
1587: samloptions => "Options",
1.160.6.118.2 2(raebur 1588:2): alttext => "Alt text",
1.6 raeburn 1589: );
1590: return %choices;
1591: }
1592:
1.160.6.113 raeburn 1593: sub login_file_options {
1594: return &Apache::lonlocal::texthash(
1595: del => 'Delete?',
1596: rep => 'Replace:',
1597: upl => 'Upload:',
1598: curr => 'View contents',
1599: default => 'Default',
1600: custom => 'Custom',
1601: none => 'None',
1602: );
1603: }
1604:
1605: sub print_ipaccess {
1606: my ($dom,$settings,$rowtotal) = @_;
1607: my $css_class;
1608: my $itemcount = 0;
1609: my $datatable;
1610: my %ordered;
1611: if (ref($settings) eq 'HASH') {
1612: foreach my $item (keys(%{$settings})) {
1613: if (ref($settings->{$item}) eq 'HASH') {
1614: my $num = $settings->{$item}{'order'};
1615: if ($num eq '') {
1616: $num = scalar(keys(%{$settings}));
1617: }
1618: $ordered{$num} = $item;
1619: }
1620: }
1621: }
1622: my $maxnum = scalar(keys(%ordered));
1623: if (keys(%ordered)) {
1624: my @items = sort { $a <=> $b } keys(%ordered);
1625: for (my $i=0; $i<@items; $i++) {
1626: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1627: my $item = $ordered{$items[$i]};
1628: my ($name,$ipranges,%commblocks,%courses);
1629: if (ref($settings->{$item}) eq 'HASH') {
1630: $name = $settings->{$item}->{'name'};
1631: $ipranges = $settings->{$item}->{'ip'};
1632: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1633: %commblocks = %{$settings->{$item}->{'commblocks'}};
1634: }
1635: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1636: %courses = %{$settings->{$item}->{'courses'}};
1637: }
1638: }
1639: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1640: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1641: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1642: for (my $k=0; $k<=$maxnum; $k++) {
1643: my $vpos = $k+1;
1644: my $selstr;
1645: if ($k == $i) {
1646: $selstr = ' selected="selected" ';
1647: }
1648: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1649: }
1650: $datatable .= '</select>'.(' 'x2).
1651: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1652: &mt('Delete?').'</label></span></td>'.
1653: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1654: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1655: '</td></tr>';
1656: $itemcount ++;
1657: }
1658: }
1659: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1660: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1661: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1662: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1663: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1664: for (my $k=0; $k<$maxnum+1; $k++) {
1665: my $vpos = $k+1;
1666: my $selstr;
1667: if ($k == $maxnum) {
1668: $selstr = ' selected="selected" ';
1669: }
1670: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1671: }
1672: $datatable .= '</select> '."\n".
1673: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1674: '<td colspan="2">'.
1675: &ipaccess_options('add',$itemcount,$dom).
1676: '</td>'."\n".
1677: '</tr>'."\n";
1678: $$rowtotal ++;
1679: return $datatable;
1680: }
1681:
1682: sub ipaccess_options {
1683: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1684: my (%currblocks,%currcourses,$output);
1685: if (ref($blocksref) eq 'HASH') {
1686: %currblocks = %{$blocksref};
1687: }
1688: if (ref($coursesref) eq 'HASH') {
1689: %currcourses = %{$coursesref};
1690: }
1691: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1692: '<span class="LC_nobreak">'.&mt('Name').': '.
1693: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1694: '</span></fieldset>'.
1695: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1696: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1697: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1698: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1699: $ipranges.'</textarea></fieldset>'.
1700: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1701: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1702: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1703: '<table>';
1704: foreach my $cid (sort(keys(%currcourses))) {
1705: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1706: $output .= '<tr><td><span class="LC_nobreak">'.
1707: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1708: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1709: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1710: }
1711: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1712: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1713: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1714: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1715: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1716: '</span></td></tr></table>'."\n".
1717: '</fieldset>';
1718: return $output;
1719: }
1720:
1721: sub blocker_checkboxes {
1722: my ($num,$blocks) = @_;
1723: my ($typeorder,$types) = &commblocktype_text();
1724: my $numinrow = 6;
1725: my $output = '<table>';
1726: for (my $i=0; $i<@{$typeorder}; $i++) {
1727: my $block = $typeorder->[$i];
1728: my $blockstatus;
1729: if (ref($blocks) eq 'HASH') {
1730: if ($blocks->{$block} eq 'on') {
1731: $blockstatus = 'checked="checked"';
1732: }
1733: }
1734: my $rem = $i%($numinrow);
1735: if ($rem == 0) {
1736: if ($i > 0) {
1737: $output .= '</tr>';
1738: }
1739: $output .= '<tr>';
1740: }
1741: if ($i == scalar(@{$typeorder})-1) {
1742: my $colsleft = $numinrow-$rem;
1743: if ($colsleft > 1) {
1744: $output .= '<td colspan="'.$colsleft.'">';
1745: } else {
1746: $output .= '<td>';
1747: }
1748: } else {
1749: $output .= '<td>';
1750: }
1751: my $item = 'ipaccess_block_'.$num;
1752: if ($blockstatus) {
1753: $blockstatus = ' '.$blockstatus;
1754: }
1755: $output .= '<span class="LC_nobreak"><label>'."\n".
1756: '<input type="checkbox" name="'.$item.'"'.
1757: $blockstatus.' value="'.$block.'"'.' />'.
1758: $types->{$block}.'</label></span>'."\n".
1759: '<br /></td>';
1760: }
1761: $output .= '</tr></table>';
1762: return $output;
1763: }
1764:
1765: sub commblocktype_text {
1766: my %types = &Apache::lonlocal::texthash(
1767: 'com' => 'Messaging',
1768: 'chat' => 'Chat Room',
1769: 'boards' => 'Discussion',
1770: 'port' => 'Portfolio',
1771: 'groups' => 'Groups',
1772: 'blogs' => 'Blogs',
1773: 'about' => 'User Information',
1774: 'printout' => 'Printouts',
1775: 'passwd' => 'Change Password',
1776: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1777: 'search' => 'Course search',
1778: 'wishlist' => 'Stored links',
1779: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1780: );
1.160.6.115 raeburn 1781: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1782: return ($typeorder,\%types);
1783: }
1784:
1.6 raeburn 1785: sub print_rolecolors {
1.30 raeburn 1786: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1787: my %choices = &color_font_choices();
1788: my @bgs = ('pgbg','tabbg','sidebg');
1789: my @links = ('link','alink','vlink');
1790: my @images = ('img');
1791: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1792: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1793: my %defaultdesign = %Apache::loncommon::defaultdesign;
1794: my (%is_custom,%designs);
1.160.6.22 raeburn 1795: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1796: if (ref($settings) eq 'HASH') {
1797: if (ref($settings->{$role}) eq 'HASH') {
1798: if ($settings->{$role}->{'img'} ne '') {
1799: $designs{'img'} = $settings->{$role}->{'img'};
1800: $is_custom{'img'} = 1;
1801: }
1802: if ($settings->{$role}->{'font'} ne '') {
1803: $designs{'font'} = $settings->{$role}->{'font'};
1804: $is_custom{'font'} = 1;
1805: }
1.97 tempelho 1806: if ($settings->{$role}->{'fontmenu'} ne '') {
1807: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1808: $is_custom{'fontmenu'} = 1;
1809: }
1.6 raeburn 1810: foreach my $item (@bgs) {
1811: if ($settings->{$role}->{$item} ne '') {
1812: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1813: $is_custom{$item} = 1;
1814: }
1815: }
1816: foreach my $item (@links) {
1817: if ($settings->{$role}->{$item} ne '') {
1818: $designs{'links'}{$item} = $settings->{$role}->{$item};
1819: $is_custom{$item} = 1;
1820: }
1821: }
1822: }
1823: } else {
1824: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1825: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1826: $is_custom{'img'} = 1;
1827: }
1.97 tempelho 1828: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1829: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1830: $is_custom{'fontmenu'} = 1;
1831: }
1.6 raeburn 1832: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1833: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1834: $is_custom{'font'} = 1;
1835: }
1836: foreach my $item (@bgs) {
1837: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1838: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1839: $is_custom{$item} = 1;
1840:
1841: }
1842: }
1843: foreach my $item (@links) {
1844: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1845: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1846: $is_custom{$item} = 1;
1847: }
1848: }
1849: }
1850: my $itemcount = 1;
1.30 raeburn 1851: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1852: $datatable .= '</tr></table></td></tr>';
1853: return $datatable;
1854: }
1855:
1.160.6.22 raeburn 1856: sub role_defaults {
1857: my ($role,$bgs,$links,$images,$logintext) = @_;
1858: my %defaults;
1859: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1860: return %defaults;
1861: }
1862: my %defaultdesign = %Apache::loncommon::defaultdesign;
1863: if ($role eq 'login') {
1864: %defaults = (
1865: font => $defaultdesign{$role.'.font'},
1866: );
1867: if (ref($logintext) eq 'ARRAY') {
1868: foreach my $item (@{$logintext}) {
1869: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1870: }
1871: }
1872: foreach my $item (@{$images}) {
1873: $defaults{'showlogo'}{$item} = 1;
1874: }
1875: } else {
1876: %defaults = (
1877: img => $defaultdesign{$role.'.img'},
1878: font => $defaultdesign{$role.'.font'},
1879: fontmenu => $defaultdesign{$role.'.fontmenu'},
1880: );
1881: }
1882: foreach my $item (@{$bgs}) {
1883: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1884: }
1885: foreach my $item (@{$links}) {
1886: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1887: }
1888: foreach my $item (@{$images}) {
1889: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1890: }
1891: return %defaults;
1892: }
1893:
1.6 raeburn 1894: sub display_color_options {
1.9 raeburn 1895: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1896: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1897: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1898: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1899: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1900: '<td>'.$choices->{'font'}.'</td>';
1901: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1902: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1903: } else {
1904: $datatable .= '<td> </td>';
1905: }
1.160.6.9 raeburn 1906: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1907:
1.8 raeburn 1908: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1909: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1910: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1911: ' </span></td></tr>';
1.107 raeburn 1912: unless ($role eq 'login') {
1913: $datatable .= '<tr'.$css_class.'>'.
1914: '<td>'.$choices->{'fontmenu'}.'</td>';
1915: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1916: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1917: } else {
1918: $datatable .= '<td> </td>';
1919: }
1.160.6.22 raeburn 1920: $current_color = $designs->{'fontmenu'} ?
1921: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1922: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1923: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1924: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1925: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1926: ' </span></td></tr>';
1.97 tempelho 1927: }
1.9 raeburn 1928: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1929: foreach my $img (@{$images}) {
1.18 albertel 1930: $itemcount ++;
1.6 raeburn 1931: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1932: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1933: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 1934:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1935: if ($role eq 'login') {
1936: if ($img eq 'login') {
1937: $login_hdr_pick =
1.135 bisitz 1938: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1939: $logincolors =
1940: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1941: $designs,$defaults);
1.160.6.118.2 2(raebur 1942:2): } else {
1943:2): if ($img ne 'domlogo') {
1944:2): $datatable.= &logo_display_options($img,$defaults,$designs);
1945:2): }
1946:2): if (ref($designs->{'alttext'}) eq 'HASH') {
1947:2): $alttext = $designs->{'alttext'}{$img};
1948:2): }
1.70 raeburn 1949: }
1950: }
1951: $datatable .= '</td>';
1.6 raeburn 1952: if ($designs->{$img} ne '') {
1953: $imgfile = $designs->{$img};
1.18 albertel 1954: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1955: } else {
1956: $imgfile = $defaults->{$img};
1957: }
1958: if ($imgfile) {
1.9 raeburn 1959: my ($showfile,$fullsize);
1960: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1961: my $urldir = $1;
1962: my $filename = $2;
1963: my @info = &Apache::lonnet::stat_file($designs->{$img});
1964: if (@info) {
1965: my $thumbfile = 'tn-'.$filename;
1966: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1967: if (@thumb) {
1968: $showfile = $urldir.'/'.$thumbfile;
1969: } else {
1970: $showfile = $imgfile;
1971: }
1972: } else {
1973: $showfile = '';
1974: }
1975: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1976: $showfile = $imgfile;
1.6 raeburn 1977: my $imgdir = $1;
1978: my $filename = $2;
1.159 raeburn 1979: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1980: $showfile = "/$imgdir/tn-".$filename;
1981: } else {
1.159 raeburn 1982: my $input = $londocroot.$imgfile;
1983: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1984: if (!-e $output) {
1.9 raeburn 1985: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1986: my ($fullwidth,$fullheight) = &check_dimensions($input);
1987: if ($fullwidth ne '' && $fullheight ne '') {
1988: if ($fullwidth > $width && $fullheight > $height) {
1989: my $size = $width.'x'.$height;
1.160.6.88 raeburn 1990: my @args = ('convert','-sample',$size,$input,$output);
1991: system({$args[0]} @args);
1.159 raeburn 1992: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1993: }
1994: }
1.6 raeburn 1995: }
1996: }
1.16 raeburn 1997: }
1.6 raeburn 1998: if ($showfile) {
1.40 raeburn 1999: if ($showfile =~ m{^/(adm|res)/}) {
2000: if ($showfile =~ m{^/res/}) {
2001: my $local_showfile =
2002: &Apache::lonnet::filelocation('',$showfile);
2003: &Apache::lonnet::repcopy($local_showfile);
2004: }
2005: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2006: }
2007: if ($imgfile) {
2008: if ($imgfile =~ m{^/(adm|res)/}) {
2009: if ($imgfile =~ m{^/res/}) {
2010: my $local_imgfile =
2011: &Apache::lonnet::filelocation('',$imgfile);
2012: &Apache::lonnet::repcopy($local_imgfile);
2013: }
2014: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2015: } else {
2016: $fullsize = $imgfile;
2017: }
2018: }
1.41 raeburn 2019: $datatable .= '<td>';
2020: if ($img eq 'login') {
1.135 bisitz 2021: $datatable .= $login_hdr_pick;
2022: }
1.41 raeburn 2023: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2024: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2025: } else {
1.160.6.22 raeburn 2026: $datatable .= '<td> </td><td class="LC_left_item">'.
2027: &mt('Upload:').'<br />';
1.6 raeburn 2028: }
2029: } else {
1.160.6.22 raeburn 2030: $datatable .= '<td> </td><td class="LC_left_item">'.
2031: &mt('Upload:').'<br />';
1.6 raeburn 2032: }
1.9 raeburn 2033: if ($switchserver) {
2034: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2035: } else {
1.135 bisitz 2036: if ($img ne 'login') { # suppress file selection for Log-in header
2037: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2038: }
1.9 raeburn 2039: }
1.160.6.118.2 2(raebur 2040:2): if (($role eq 'login') && ($img ne 'login')) {
2041:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2042:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2043:2): '</label></span>';
2044:2): }
1.9 raeburn 2045: $datatable .= '</td></tr>';
1.6 raeburn 2046: }
2047: $itemcount ++;
2048: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2049: $datatable .= '<tr'.$css_class.'>'.
2050: '<td>'.$choices->{'bgs'}.'</td>';
2051: my $bgs_def;
2052: foreach my $item (@{$bgs}) {
2053: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2054: $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 2055: }
2056: }
2057: if ($bgs_def) {
1.8 raeburn 2058: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2059: } else {
2060: $datatable .= '<td> </td>';
2061: }
2062: $datatable .= '<td class="LC_right_item">'.
2063: '<table border="0"><tr>';
1.160.6.13 raeburn 2064:
1.6 raeburn 2065: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2066: $datatable .= '<td align="center">'.$choices->{$item};
2067: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2068: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2069: $datatable .= ' ';
1.6 raeburn 2070: }
1.160.6.9 raeburn 2071: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2072: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2073: }
2074: $datatable .= '</tr></table></td></tr>';
2075: $itemcount ++;
2076: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2077: $datatable .= '<tr'.$css_class.'>'.
2078: '<td>'.$choices->{'links'}.'</td>';
2079: my $links_def;
2080: foreach my $item (@{$links}) {
2081: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2082: $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 2083: }
2084: }
2085: if ($links_def) {
1.8 raeburn 2086: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2087: } else {
2088: $datatable .= '<td> </td>';
2089: }
2090: $datatable .= '<td class="LC_right_item">'.
2091: '<table border="0"><tr>';
2092: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2093: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2094: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2095: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2096: $datatable.=' ';
1.6 raeburn 2097: }
1.160.6.9 raeburn 2098: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2099: '" /></td>';
2100: }
1.30 raeburn 2101: $$rowtotal += $itemcount;
1.3 raeburn 2102: return $datatable;
2103: }
2104:
1.70 raeburn 2105: sub logo_display_options {
2106: my ($img,$defaults,$designs) = @_;
2107: my $checkedon;
2108: if (ref($defaults) eq 'HASH') {
2109: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2110: if ($defaults->{'showlogo'}{$img}) {
2111: $checkedon = 'checked="checked" ';
2112: }
2113: }
2114: }
2115: if (ref($designs) eq 'HASH') {
2116: if (ref($designs->{'showlogo'}) eq 'HASH') {
2117: if (defined($designs->{'showlogo'}{$img})) {
2118: if ($designs->{'showlogo'}{$img} == 0) {
2119: $checkedon = '';
2120: } elsif ($designs->{'showlogo'}{$img} == 1) {
2121: $checkedon = 'checked="checked" ';
2122: }
2123: }
2124: }
2125: }
2126: return '<br /><label> <input type="checkbox" name="'.
2127: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2128: &mt('show').'</label>'."\n";
2129: }
2130:
1.41 raeburn 2131: sub login_header_options {
1.135 bisitz 2132: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2133: my $output = '';
1.41 raeburn 2134: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2135: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2136: if (!$is_custom->{'textcol'}) {
2137: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2138: ' ';
2139: }
2140: if (!$is_custom->{'bgcol'}) {
2141: $output .= $choices->{'bgcol'}.': '.
2142: '<span id="css_'.$role.'_font" style="background-color: '.
2143: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2144: }
2145: $output .= '<br />';
2146: }
2147: $output .='<br />';
2148: return $output;
2149: }
2150:
2151: sub login_text_colors {
1.160.6.22 raeburn 2152: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2153: my $color_menu = '<table border="0"><tr>';
2154: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2155: $color_menu .= '<td align="center">'.$choices->{$item};
2156: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2157: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2158: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2159: }
2160: $color_menu .= '</tr></table><br />';
2161: return $color_menu;
2162: }
2163:
2164: sub image_changes {
2165: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2166: my $output;
1.135 bisitz 2167: if ($img eq 'login') {
1.160.6.87 raeburn 2168: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2169: } elsif (!$is_custom) {
1.70 raeburn 2170: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2171: $output = &mt('Default image:').'<br />';
1.41 raeburn 2172: } else {
1.160.6.87 raeburn 2173: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2174: }
2175: }
1.160.6.87 raeburn 2176: if ($img ne 'login') {
1.135 bisitz 2177: if ($img_import) {
2178: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2179: }
2180: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2181: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2182: if ($is_custom) {
2183: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2184: '<input type="checkbox" name="'.
2185: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2186: '</label> '.&mt('Replace:').'</span><br />';
2187: } else {
1.160.6.22 raeburn 2188: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2189: }
1.41 raeburn 2190: }
2191: return $output;
2192: }
2193:
1.3 raeburn 2194: sub print_quotas {
1.86 raeburn 2195: my ($dom,$settings,$rowtotal,$action) = @_;
2196: my $context;
2197: if ($action eq 'quotas') {
2198: $context = 'tools';
2199: } else {
2200: $context = $action;
2201: }
1.160.6.20 raeburn 2202: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2203: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2204: my $typecount = 0;
1.101 raeburn 2205: my ($css_class,%titles);
1.86 raeburn 2206: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 2207: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 2208: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2209: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2210: %titles = &courserequest_titles();
1.160.6.5 raeburn 2211: } elsif ($context eq 'requestauthor') {
2212: @usertools = ('author');
2213: @options = ('norequest','approval','automatic');
2214: %titles = &authorrequest_titles();
1.86 raeburn 2215: } else {
1.160.6.4 raeburn 2216: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 2217: %titles = &tool_titles();
1.86 raeburn 2218: }
1.26 raeburn 2219: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2220: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2221: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2222: unless (($context eq 'requestcourses') ||
2223: ($context eq 'requestauthor')) {
1.86 raeburn 2224: if (ref($settings) eq 'HASH') {
2225: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2226: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2227: } else {
2228: $currdefquota = $settings->{$type};
2229: }
1.160.6.20 raeburn 2230: if (ref($settings->{authorquota}) eq 'HASH') {
2231: $currauthorquota = $settings->{authorquota}->{$type};
2232: }
1.78 raeburn 2233: }
1.72 raeburn 2234: }
1.3 raeburn 2235: if (defined($usertypes->{$type})) {
2236: $typecount ++;
2237: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2238: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2239: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2240: '<td class="LC_left_item">';
1.101 raeburn 2241: if ($context eq 'requestcourses') {
2242: $datatable .= '<table><tr>';
2243: }
2244: my %cell;
1.72 raeburn 2245: foreach my $item (@usertools) {
1.101 raeburn 2246: if ($context eq 'requestcourses') {
2247: my ($curroption,$currlimit);
2248: if (ref($settings) eq 'HASH') {
2249: if (ref($settings->{$item}) eq 'HASH') {
2250: $curroption = $settings->{$item}->{$type};
2251: if ($curroption =~ /^autolimit=(\d*)$/) {
2252: $currlimit = $1;
2253: }
2254: }
2255: }
2256: if (!$curroption) {
2257: $curroption = 'norequest';
2258: }
2259: $datatable .= '<th>'.$titles{$item}.'</th>';
2260: foreach my $option (@options) {
2261: my $val = $option;
2262: if ($option eq 'norequest') {
2263: $val = 0;
2264: }
2265: if ($option eq 'validate') {
2266: my $canvalidate = 0;
2267: if (ref($validations{$item}) eq 'HASH') {
2268: if ($validations{$item}{$type}) {
2269: $canvalidate = 1;
2270: }
2271: }
2272: next if (!$canvalidate);
2273: }
2274: my $checked = '';
2275: if ($option eq $curroption) {
2276: $checked = ' checked="checked"';
2277: } elsif ($option eq 'autolimit') {
2278: if ($curroption =~ /^autolimit/) {
2279: $checked = ' checked="checked"';
2280: }
2281: }
2282: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2283: '<input type="radio" name="crsreq_'.$item.
2284: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2285: $titles{$option}.'</label>';
1.101 raeburn 2286: if ($option eq 'autolimit') {
1.127 raeburn 2287: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2288: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2289: 'value="'.$currlimit.'" />';
1.101 raeburn 2290: }
1.127 raeburn 2291: $cell{$item} .= '</span> ';
1.103 raeburn 2292: if ($option eq 'autolimit') {
1.127 raeburn 2293: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2294: }
1.101 raeburn 2295: }
1.160.6.5 raeburn 2296: } elsif ($context eq 'requestauthor') {
2297: my $curroption;
2298: if (ref($settings) eq 'HASH') {
2299: $curroption = $settings->{$type};
2300: }
2301: if (!$curroption) {
2302: $curroption = 'norequest';
2303: }
2304: foreach my $option (@options) {
2305: my $val = $option;
2306: if ($option eq 'norequest') {
2307: $val = 0;
2308: }
2309: my $checked = '';
2310: if ($option eq $curroption) {
2311: $checked = ' checked="checked"';
2312: }
2313: $datatable .= '<span class="LC_nobreak"><label>'.
2314: '<input type="radio" name="authorreq_'.$type.
2315: '" value="'.$val.'"'.$checked.' />'.
2316: $titles{$option}.'</label></span> ';
2317: }
1.101 raeburn 2318: } else {
2319: my $checked = 'checked="checked" ';
2320: if (ref($settings) eq 'HASH') {
2321: if (ref($settings->{$item}) eq 'HASH') {
2322: if ($settings->{$item}->{$type} == 0) {
2323: $checked = '';
2324: } elsif ($settings->{$item}->{$type} == 1) {
2325: $checked = 'checked="checked" ';
2326: }
1.78 raeburn 2327: }
1.72 raeburn 2328: }
1.101 raeburn 2329: $datatable .= '<span class="LC_nobreak"><label>'.
2330: '<input type="checkbox" name="'.$context.'_'.$item.
2331: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2332: '</label></span> ';
1.72 raeburn 2333: }
1.101 raeburn 2334: }
2335: if ($context eq 'requestcourses') {
2336: $datatable .= '</tr><tr>';
2337: foreach my $item (@usertools) {
1.106 raeburn 2338: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2339: }
2340: $datatable .= '</tr></table>';
1.72 raeburn 2341: }
1.86 raeburn 2342: $datatable .= '</td>';
1.160.6.5 raeburn 2343: unless (($context eq 'requestcourses') ||
2344: ($context eq 'requestauthor')) {
1.86 raeburn 2345: $datatable .=
1.160.6.20 raeburn 2346: '<td class="LC_right_item">'.
2347: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2348: '<input type="text" name="quota_'.$type.
1.72 raeburn 2349: '" value="'.$currdefquota.
1.160.6.20 raeburn 2350: '" size="5" /></span>'.(' ' x 2).
2351: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2352: '<input type="text" name="authorquota_'.$type.
2353: '" value="'.$currauthorquota.
2354: '" size="5" /></span></td>';
1.86 raeburn 2355: }
2356: $datatable .= '</tr>';
1.3 raeburn 2357: }
2358: }
2359: }
1.160.6.5 raeburn 2360: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2361: $defaultquota = '20';
1.160.6.20 raeburn 2362: $authorquota = '500';
1.86 raeburn 2363: if (ref($settings) eq 'HASH') {
2364: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2365: $defaultquota = $settings->{'defaultquota'}->{'default'};
2366: } elsif (defined($settings->{'default'})) {
2367: $defaultquota = $settings->{'default'};
2368: }
1.160.6.20 raeburn 2369: if (ref($settings->{'authorquota'}) eq 'HASH') {
2370: $authorquota = $settings->{'authorquota'}->{'default'};
2371: }
1.3 raeburn 2372: }
2373: }
2374: $typecount ++;
2375: $css_class = $typecount%2?' class="LC_odd_row"':'';
2376: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2377: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2378: '<td class="LC_left_item">';
1.101 raeburn 2379: if ($context eq 'requestcourses') {
2380: $datatable .= '<table><tr>';
2381: }
2382: my %defcell;
1.72 raeburn 2383: foreach my $item (@usertools) {
1.101 raeburn 2384: if ($context eq 'requestcourses') {
2385: my ($curroption,$currlimit);
2386: if (ref($settings) eq 'HASH') {
2387: if (ref($settings->{$item}) eq 'HASH') {
2388: $curroption = $settings->{$item}->{'default'};
2389: if ($curroption =~ /^autolimit=(\d*)$/) {
2390: $currlimit = $1;
2391: }
2392: }
2393: }
2394: if (!$curroption) {
2395: $curroption = 'norequest';
2396: }
2397: $datatable .= '<th>'.$titles{$item}.'</th>';
2398: foreach my $option (@options) {
2399: my $val = $option;
2400: if ($option eq 'norequest') {
2401: $val = 0;
2402: }
2403: if ($option eq 'validate') {
2404: my $canvalidate = 0;
2405: if (ref($validations{$item}) eq 'HASH') {
2406: if ($validations{$item}{'default'}) {
2407: $canvalidate = 1;
2408: }
2409: }
2410: next if (!$canvalidate);
2411: }
2412: my $checked = '';
2413: if ($option eq $curroption) {
2414: $checked = ' checked="checked"';
2415: } elsif ($option eq 'autolimit') {
2416: if ($curroption =~ /^autolimit/) {
2417: $checked = ' checked="checked"';
2418: }
2419: }
2420: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2421: '<input type="radio" name="crsreq_'.$item.
2422: '_default" value="'.$val.'"'.$checked.' />'.
2423: $titles{$option}.'</label>';
2424: if ($option eq 'autolimit') {
1.127 raeburn 2425: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2426: $item.'_limit_default" size="1" '.
2427: 'value="'.$currlimit.'" />';
2428: }
1.127 raeburn 2429: $defcell{$item} .= '</span> ';
1.104 raeburn 2430: if ($option eq 'autolimit') {
1.127 raeburn 2431: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2432: }
1.101 raeburn 2433: }
1.160.6.5 raeburn 2434: } elsif ($context eq 'requestauthor') {
2435: my $curroption;
2436: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2437: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2438: }
2439: if (!$curroption) {
2440: $curroption = 'norequest';
2441: }
2442: foreach my $option (@options) {
2443: my $val = $option;
2444: if ($option eq 'norequest') {
2445: $val = 0;
2446: }
2447: my $checked = '';
2448: if ($option eq $curroption) {
2449: $checked = ' checked="checked"';
2450: }
2451: $datatable .= '<span class="LC_nobreak"><label>'.
2452: '<input type="radio" name="authorreq_default"'.
2453: ' value="'.$val.'"'.$checked.' />'.
2454: $titles{$option}.'</label></span> ';
2455: }
1.101 raeburn 2456: } else {
2457: my $checked = 'checked="checked" ';
2458: if (ref($settings) eq 'HASH') {
2459: if (ref($settings->{$item}) eq 'HASH') {
2460: if ($settings->{$item}->{'default'} == 0) {
2461: $checked = '';
2462: } elsif ($settings->{$item}->{'default'} == 1) {
2463: $checked = 'checked="checked" ';
2464: }
1.78 raeburn 2465: }
1.72 raeburn 2466: }
1.101 raeburn 2467: $datatable .= '<span class="LC_nobreak"><label>'.
2468: '<input type="checkbox" name="'.$context.'_'.$item.
2469: '" value="default" '.$checked.'/>'.$titles{$item}.
2470: '</label></span> ';
2471: }
2472: }
2473: if ($context eq 'requestcourses') {
2474: $datatable .= '</tr><tr>';
2475: foreach my $item (@usertools) {
1.106 raeburn 2476: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2477: }
1.101 raeburn 2478: $datatable .= '</tr></table>';
1.72 raeburn 2479: }
1.86 raeburn 2480: $datatable .= '</td>';
1.160.6.5 raeburn 2481: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2482: $datatable .= '<td class="LC_right_item">'.
2483: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2484: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2485: $defaultquota.'" size="5" /></span>'.(' ' x2).
2486: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2487: '<input type="text" name="authorquota" value="'.
2488: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2489: }
2490: $datatable .= '</tr>';
1.72 raeburn 2491: $typecount ++;
2492: $css_class = $typecount%2?' class="LC_odd_row"':'';
2493: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2494: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2495: if ($context eq 'requestcourses') {
1.109 raeburn 2496: $datatable .= &mt('(overrides affiliation, if set)').
2497: '</td>'.
2498: '<td class="LC_left_item">'.
2499: '<table><tr>';
1.101 raeburn 2500: } else {
1.109 raeburn 2501: $datatable .= &mt('(overrides affiliation, if checked)').
2502: '</td>'.
2503: '<td class="LC_left_item" colspan="2">'.
2504: '<br />';
1.101 raeburn 2505: }
2506: my %advcell;
1.72 raeburn 2507: foreach my $item (@usertools) {
1.101 raeburn 2508: if ($context eq 'requestcourses') {
2509: my ($curroption,$currlimit);
2510: if (ref($settings) eq 'HASH') {
2511: if (ref($settings->{$item}) eq 'HASH') {
2512: $curroption = $settings->{$item}->{'_LC_adv'};
2513: if ($curroption =~ /^autolimit=(\d*)$/) {
2514: $currlimit = $1;
2515: }
2516: }
2517: }
2518: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2519: my $checked = '';
2520: if ($curroption eq '') {
2521: $checked = ' checked="checked"';
2522: }
2523: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2524: '<input type="radio" name="crsreq_'.$item.
2525: '__LC_adv" value=""'.$checked.' />'.
2526: &mt('No override set').'</label></span> ';
1.101 raeburn 2527: foreach my $option (@options) {
2528: my $val = $option;
2529: if ($option eq 'norequest') {
2530: $val = 0;
2531: }
2532: if ($option eq 'validate') {
2533: my $canvalidate = 0;
2534: if (ref($validations{$item}) eq 'HASH') {
2535: if ($validations{$item}{'_LC_adv'}) {
2536: $canvalidate = 1;
2537: }
2538: }
2539: next if (!$canvalidate);
2540: }
2541: my $checked = '';
1.104 raeburn 2542: if ($val eq $curroption) {
1.101 raeburn 2543: $checked = ' checked="checked"';
2544: } elsif ($option eq 'autolimit') {
2545: if ($curroption =~ /^autolimit/) {
2546: $checked = ' checked="checked"';
2547: }
2548: }
2549: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2550: '<input type="radio" name="crsreq_'.$item.
2551: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2552: $titles{$option}.'</label>';
2553: if ($option eq 'autolimit') {
1.127 raeburn 2554: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2555: $item.'_limit__LC_adv" size="1" '.
2556: 'value="'.$currlimit.'" />';
2557: }
1.127 raeburn 2558: $advcell{$item} .= '</span> ';
1.104 raeburn 2559: if ($option eq 'autolimit') {
1.127 raeburn 2560: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2561: }
1.101 raeburn 2562: }
1.160.6.5 raeburn 2563: } elsif ($context eq 'requestauthor') {
2564: my $curroption;
2565: if (ref($settings) eq 'HASH') {
2566: $curroption = $settings->{'_LC_adv'};
2567: }
2568: my $checked = '';
2569: if ($curroption eq '') {
2570: $checked = ' checked="checked"';
2571: }
2572: $datatable .= '<span class="LC_nobreak"><label>'.
2573: '<input type="radio" name="authorreq__LC_adv"'.
2574: ' value=""'.$checked.' />'.
2575: &mt('No override set').'</label></span> ';
2576: foreach my $option (@options) {
2577: my $val = $option;
2578: if ($option eq 'norequest') {
2579: $val = 0;
2580: }
2581: my $checked = '';
2582: if ($val eq $curroption) {
2583: $checked = ' checked="checked"';
2584: }
2585: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2586: '<input type="radio" name="authorreq__LC_adv"'.
2587: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2588: $titles{$option}.'</label></span> ';
2589: }
1.101 raeburn 2590: } else {
2591: my $checked = 'checked="checked" ';
2592: if (ref($settings) eq 'HASH') {
2593: if (ref($settings->{$item}) eq 'HASH') {
2594: if ($settings->{$item}->{'_LC_adv'} == 0) {
2595: $checked = '';
2596: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2597: $checked = 'checked="checked" ';
2598: }
1.79 raeburn 2599: }
1.72 raeburn 2600: }
1.101 raeburn 2601: $datatable .= '<span class="LC_nobreak"><label>'.
2602: '<input type="checkbox" name="'.$context.'_'.$item.
2603: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2604: '</label></span> ';
2605: }
2606: }
2607: if ($context eq 'requestcourses') {
2608: $datatable .= '</tr><tr>';
2609: foreach my $item (@usertools) {
1.106 raeburn 2610: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2611: }
1.101 raeburn 2612: $datatable .= '</tr></table>';
1.72 raeburn 2613: }
1.98 raeburn 2614: $datatable .= '</td></tr>';
1.30 raeburn 2615: $$rowtotal += $typecount;
1.3 raeburn 2616: return $datatable;
2617: }
2618:
1.160.6.5 raeburn 2619: sub print_requestmail {
1.160.6.93 raeburn 2620: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2621: my ($now,$datatable,%currapp);
1.102 raeburn 2622: $now = time;
2623: if (ref($settings) eq 'HASH') {
2624: if (ref($settings->{'notify'}) eq 'HASH') {
2625: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2626: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2627: }
2628: }
2629: }
1.160.6.16 raeburn 2630: my $numinrow = 2;
1.160.6.34 raeburn 2631: my $css_class;
1.160.6.93 raeburn 2632: if ($$rowtotal%2) {
2633: $css_class = 'LC_odd_row';
2634: }
2635: if ($customcss) {
2636: $css_class .= " $customcss";
2637: }
2638: $css_class =~ s/^\s+//;
2639: if ($css_class) {
2640: $css_class = ' class="'.$css_class.'"';
2641: }
2642: if ($rowstyle) {
2643: $css_class .= ' style="'.$rowstyle.'"';
2644: }
1.160.6.5 raeburn 2645: my $text;
2646: if ($action eq 'requestcourses') {
2647: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2648: } elsif ($action eq 'requestauthor') {
2649: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2650: } else {
1.160.6.34 raeburn 2651: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2652: }
1.160.6.34 raeburn 2653: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2654: ' <td>'.$text.'</td>'.
1.102 raeburn 2655: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2656: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2657: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2658: if ($numdc > 0) {
2659: $datatable .= $table;
1.102 raeburn 2660: } else {
2661: $datatable .= &mt('There are no active Domain Coordinators');
2662: }
2663: $datatable .='</td></tr>';
2664: return $datatable;
2665: }
2666:
1.160.6.30 raeburn 2667: sub print_studentcode {
2668: my ($settings,$rowtotal) = @_;
2669: my $rownum = 0;
2670: my ($output,%current);
2671: my @crstypes = ('official','unofficial','community','textbook');
1.160.6.51 raeburn 2672: if (ref($settings) eq 'HASH') {
2673: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2674: foreach my $type (@crstypes) {
2675: $current{$type} = $settings->{'uniquecode'}{$type};
2676: }
1.160.6.30 raeburn 2677: }
2678: }
2679: $output .= '<tr>'.
2680: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2681: '<td class="LC_left_item">';
2682: foreach my $type (@crstypes) {
2683: my $check = ' ';
2684: if ($current{$type}) {
2685: $check = ' checked="checked" ';
2686: }
2687: $output .= '<span class="LC_nobreak"><label>'.
2688: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2689: &mt($type).'</label></span>'.(' 'x2).' ';
2690: }
2691: $output .= '</td></tr>';
2692: $$rowtotal ++;
2693: return $output;
2694: }
2695:
2696: sub print_textbookcourses {
1.160.6.46 raeburn 2697: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2698: my $rownum = 0;
2699: my $css_class;
2700: my $itemcount = 1;
2701: my $maxnum = 0;
2702: my $bookshash;
2703: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2704: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2705: }
2706: my %ordered;
2707: if (ref($bookshash) eq 'HASH') {
2708: foreach my $item (keys(%{$bookshash})) {
2709: if (ref($bookshash->{$item}) eq 'HASH') {
2710: my $num = $bookshash->{$item}{'order'};
2711: $ordered{$num} = $item;
2712: }
2713: }
2714: }
2715: my $confname = $dom.'-domainconfig';
2716: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2717: my $maxnum = scalar(keys(%ordered));
2718: my $datatable;
1.160.6.30 raeburn 2719: if (keys(%ordered)) {
2720: my @items = sort { $a <=> $b } keys(%ordered);
2721: for (my $i=0; $i<@items; $i++) {
2722: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2723: my $key = $ordered{$items[$i]};
2724: my %coursehash=&Apache::lonnet::coursedescription($key);
2725: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2726: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2727: if (ref($bookshash->{$key}) eq 'HASH') {
2728: $subject = $bookshash->{$key}->{'subject'};
2729: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2730: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2731: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2732: $author = $bookshash->{$key}->{'author'};
2733: $image = $bookshash->{$key}->{'image'};
2734: if ($image ne '') {
2735: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2736: my $imagethumb = "$path/tn-".$imagefile;
2737: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2738: }
1.160.6.30 raeburn 2739: }
2740: }
1.160.6.46 raeburn 2741: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2742: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2743: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2744: for (my $k=0; $k<=$maxnum; $k++) {
2745: my $vpos = $k+1;
2746: my $selstr;
2747: if ($k == $i) {
2748: $selstr = ' selected="selected" ';
2749: }
2750: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2751: }
2752: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2753: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2754: &mt('Delete?').'</label></span></td>'.
2755: '<td colspan="2">'.
1.160.6.46 raeburn 2756: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2757: (' 'x2).
1.160.6.46 raeburn 2758: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2759: if ($type eq 'textbooks') {
2760: $datatable .= (' 'x2).
1.160.6.47 raeburn 2761: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2762: (' 'x2).
1.160.6.46 raeburn 2763: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2764: (' 'x2).
2765: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2766: if ($image) {
1.160.6.114 raeburn 2767: $datatable .= $imgsrc.
1.160.6.46 raeburn 2768: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2769: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2770: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2771: }
2772: if ($switchserver) {
2773: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2774: } else {
2775: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2776: }
1.160.6.30 raeburn 2777: }
1.160.6.46 raeburn 2778: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2779: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2780: $coursetitle.'</span></td></tr>'."\n";
2781: $itemcount ++;
2782: }
2783: }
2784: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2785: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2786: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2787: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2788: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2789: for (my $k=0; $k<$maxnum+1; $k++) {
2790: my $vpos = $k+1;
2791: my $selstr;
2792: if ($k == $maxnum) {
2793: $selstr = ' selected="selected" ';
2794: }
2795: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2796: }
2797: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2798: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2799: '<td colspan="2">'.
1.160.6.46 raeburn 2800: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2801: (' 'x2).
1.160.6.46 raeburn 2802: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2803: (' 'x2);
2804: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2805: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2806: (' 'x2).
2807: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2808: (' 'x2).
2809: '<span class="LC_nobreak">'.&mt('Image:').' ';
2810: if ($switchserver) {
2811: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2812: } else {
2813: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2814: }
1.160.6.87 raeburn 2815: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2816: }
1.160.6.87 raeburn 2817: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2818: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2819: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2820: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2821: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2822: '</span></td>'."\n".
2823: '</tr>'."\n";
2824: $itemcount ++;
2825: return $datatable;
2826: }
2827:
2828: sub textbookcourses_javascript {
1.160.6.46 raeburn 2829: my ($settings) = @_;
2830: return unless(ref($settings) eq 'HASH');
2831: my (%ordered,%total,%jstext);
2832: foreach my $type ('textbooks','templates') {
2833: $total{$type} = 0;
2834: if (ref($settings->{$type}) eq 'HASH') {
2835: foreach my $item (keys(%{$settings->{$type}})) {
2836: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2837: my $num = $settings->{$type}->{$item}{'order'};
2838: $ordered{$type}{$num} = $item;
2839: }
2840: }
2841: $total{$type} = scalar(keys(%{$settings->{$type}}));
2842: }
2843: my @jsarray = ();
2844: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2845: push(@jsarray,$ordered{$type}{$item});
2846: }
2847: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2848: }
2849: return <<"ENDSCRIPT";
2850: <script type="text/javascript">
2851: // <![CDATA[
1.160.6.46 raeburn 2852: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2853: var changedVal;
1.160.6.46 raeburn 2854: $jstext{'textbooks'};
2855: $jstext{'templates'};
2856: var newpos;
2857: var maxh;
2858: if (caller == 'textbooks') {
2859: newpos = 'textbooks_addbook_pos';
2860: maxh = 1 + $total{'textbooks'};
2861: } else {
2862: newpos = 'templates_addbook_pos';
2863: maxh = 1 + $total{'templates'};
2864: }
1.160.6.30 raeburn 2865: var current = new Array;
2866: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2867: if (item == newpos) {
2868: changedVal = newitemVal;
2869: } else {
2870: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2871: current[newitemVal] = newpos;
2872: }
1.160.6.46 raeburn 2873: if (caller == 'textbooks') {
2874: for (var i=0; i<textbooks.length; i++) {
2875: var elementName = 'textbooks_'+textbooks[i];
2876: if (elementName != item) {
2877: if (form.elements[elementName]) {
2878: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2879: current[currVal] = elementName;
2880: }
2881: }
2882: }
2883: }
2884: if (caller == 'templates') {
2885: for (var i=0; i<templates.length; i++) {
2886: var elementName = 'templates_'+templates[i];
2887: if (elementName != item) {
2888: if (form.elements[elementName]) {
2889: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2890: current[currVal] = elementName;
2891: }
1.160.6.30 raeburn 2892: }
2893: }
2894: }
2895: var oldVal;
2896: for (var j=0; j<maxh; j++) {
2897: if (current[j] == undefined) {
2898: oldVal = j;
2899: }
2900: }
2901: if (oldVal < changedVal) {
2902: for (var k=oldVal+1; k<=changedVal ; k++) {
2903: var elementName = current[k];
2904: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2905: }
2906: } else {
2907: for (var k=changedVal; k<oldVal; k++) {
2908: var elementName = current[k];
2909: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2910: }
2911: }
2912: return;
2913: }
2914:
2915: // ]]>
2916: </script>
2917:
2918: ENDSCRIPT
2919: }
2920:
1.160.6.118.2 1(raebur 2921:1): sub ltitools_javascript {
2922:1): my ($settings) = @_;
2923:1): my $togglejs = <itools_toggle_js();
2924:1): unless (ref($settings) eq 'HASH') {
2925:1): return $togglejs;
2926:1): }
2927:1): my (%ordered,$total,%jstext);
2928:1): $total = 0;
2929:1): foreach my $item (keys(%{$settings})) {
2930:1): if (ref($settings->{$item}) eq 'HASH') {
2931:1): my $num = $settings->{$item}{'order'};
2932:1): $ordered{$num} = $item;
2933:1): }
2934:1): }
2935:1): $total = scalar(keys(%{$settings}));
2936:1): my @jsarray = ();
2937:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2938:1): push(@jsarray,$ordered{$item});
2939:1): }
2940:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
2941:1): return <<"ENDSCRIPT";
2942:1): <script type="text/javascript">
2943:1): // <![CDATA[
2944:1): function reorderLTITools(form,item) {
2945:1): var changedVal;
2946:1): $jstext
2947:1): var newpos = 'ltitools_add_pos';
2948:1): var maxh = 1 + $total;
2949:1): var current = new Array;
2950:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2951:1): if (item == newpos) {
2952:1): changedVal = newitemVal;
2953:1): } else {
2954:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2955:1): current[newitemVal] = newpos;
2956:1): }
2957:1): for (var i=0; i<ltitools.length; i++) {
2958:1): var elementName = 'ltitools_'+ltitools[i];
2959:1): if (elementName != item) {
2960:1): if (form.elements[elementName]) {
2961:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2962:1): current[currVal] = elementName;
2963:1): }
2964:1): }
2965:1): }
2966:1): var oldVal;
2967:1): for (var j=0; j<maxh; j++) {
2968:1): if (current[j] == undefined) {
2969:1): oldVal = j;
2970:1): }
2971:1): }
2972:1): if (oldVal < changedVal) {
2973:1): for (var k=oldVal+1; k<=changedVal ; k++) {
2974:1): var elementName = current[k];
2975:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2976:1): }
2977:1): } else {
2978:1): for (var k=changedVal; k<oldVal; k++) {
2979:1): var elementName = current[k];
2980:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2981:1): }
2982:1): }
2983:1): return;
2984:1): }
2985:1):
2986:1): // ]]>
2987:1): </script>
2988:1):
2989:1): $togglejs
2990:1):
2991:1): ENDSCRIPT
2992:1): }
2993:1):
2994:1): sub ltitools_toggle_js {
2995:1): return <<"ENDSCRIPT";
2996:1): <script type="text/javascript">
2997:1): // <![CDATA[
2998:1):
2999:1): function toggleLTITools(form,setting,item) {
3000:1): var radioname = '';
3001:1): var divid = '';
3002:1): if (setting == 'user') {
3003:1): divid = 'ltitools_'+setting+'_div_'+item;
3004:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3005:1): if (document.getElementById(divid)) {
3006:1): if (document.getElementById(checkid)) {
3007:1): if (document.getElementById(checkid).checked) {
3008:1): document.getElementById(divid).style.display = 'inline-block';
3009:1): } else {
3010:1): document.getElementById(divid).style.display = 'none';
3011:1): }
3012:1): }
3013:1): }
3014:1): }
3015:1): return;
3016:1): }
3017:1): // ]]>
3018:1): </script>
3019:1):
3020:1): ENDSCRIPT
3021:1): }
3022:1):
1.160.6.113 raeburn 3023: sub wafproxy_javascript {
3024: my ($dom) = @_;
3025: return <<"ENDSCRIPT";
3026: <script type="text/javascript">
3027: // <![CDATA[
3028: function updateWAF() {
3029: if (document.getElementById('wafproxy_remoteip')) {
3030: var wafremote = 0;
3031: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3032: wafremote = 1;
3033: }
3034: var fields = new Array('header','trust');
3035: for (var i=0; i<fields.length; i++) {
3036: if (document.getElementById('wafproxy_'+fields[i])) {
3037: if (wafremote == 1) {
3038: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3039: }
3040: else {
3041: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3042: }
3043: }
3044: }
3045: if (document.getElementById('wafproxyranges_$dom')) {
3046: if (wafremote == 1) {
3047: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3048: } else {
3049: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3050: if (document.display.wafproxy_vpnaccess[i].checked) {
3051: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3052: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3053: }
3054: }
3055: }
3056: }
3057: }
3058: }
3059: return;
3060: }
3061:
3062: function checkWAF() {
3063: if (document.getElementById('wafproxy_remoteip')) {
3064: var wafvpn = 0;
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 == 1) {
3068: wafvpn = 1;
3069: }
3070: break;
3071: }
3072: }
3073: var vpn = new Array('vpnint','vpnext');
3074: for (var i=0; i<vpn.length; i++) {
3075: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3076: if (wafvpn == 1) {
3077: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3078: }
3079: else {
3080: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3081: }
3082: }
3083: }
3084: if (document.getElementById('wafproxyranges_$dom')) {
3085: if (wafvpn == 1) {
3086: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3087: }
3088: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3089: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3090: }
3091: }
3092: }
3093: return;
3094: }
3095:
3096: function toggleWAF() {
3097: if (document.getElementById('wafproxy_table')) {
3098: var wafproxy = 0;
3099: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3100: if (document.display.wafproxy_${dom}[i].checked) {
3101: if (document.display.wafproxy_${dom}[i].value == 1) {
3102: wafproxy = 1;
3103: break;
3104: }
3105: }
3106: }
3107: if (wafproxy == 1) {
3108: document.getElementById('wafproxy_table').style.display='inline';
3109: }
3110: else {
3111: document.getElementById('wafproxy_table').style.display='none';
3112: }
3113: if (document.getElementById('wafproxyrow_${dom}')) {
3114: if (wafproxy == 1) {
3115: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3116: }
3117: else {
3118: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3119: }
3120: }
3121: if (document.getElementById('nowafproxyrow_$dom')) {
3122: if (wafproxy == 1) {
3123: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3124: }
3125: else {
3126: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3127: }
3128: }
3129: }
3130: return;
3131: }
3132: // ]]>
3133: </script>
3134:
3135: ENDSCRIPT
3136: }
3137:
1.160.6.118.2 5(raebur 3138:2): sub lti_javascript {
3139:2): my ($dom,$settings) = @_;
3140:2): my $togglejs = <i_toggle_js($dom);
3141:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
3142:2): return <<"ENDSCRIPT";
3143:2): <script type="text/javascript">
3144:2): // <![CDATA[
3145:2):
3146:2): $linkprot_js
3147:2):
3148:2): // ]]>
3149:2): </script>
3150:2):
3151:2): $togglejs
3152:2):
3153:2): ENDSCRIPT
3154:2): }
3155:2):
3156:2): sub lti_toggle_js {
3157:2): my ($dom) = @_;
3158:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3159:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3160:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3161:2): return <<"ENDSCRIPT";
3162:2): <script type="text/javascript">
3163:2): // <![CDATA[
5(raebur 3164:2): function toggleLTIEncKey(form) {
3165:2): var shownhosts = new Array();
3166:2): var hiddenhosts = new Array();
3167:2): var forcourse = new Array($course_servers);
3168:2): var fromdomain = '$primary';
3169:2): var crsradio = form.elements['ltisec_crslinkprot'];
3170:2): if (crsradio.length) {
3171:2): for (var i=0; i<crsradio.length; i++) {
3172:2): if (crsradio[i].checked) {
3173:2): if (crsradio[i].value == 1) {
3174:2): if (forcourse.length > 0) {
3175:2): for (var j=0; j<forcourse.length; j++) {
3176:2): if (!shownhosts.includes(forcourse[j])) {
3177:2): shownhosts.push(forcourse[j]);
3178:2): }
3179:2): }
3180:2): }
3181:2): } else {
3182:2): if (forcourse.length > 0) {
3183:2): for (var j=0; j<forcourse.length; j++) {
3184:2): if (!hiddenhosts.includes(forcourse[j])) {
3185:2): hiddenhosts.push(forcourse[j]);
3186:2): }
3187:2): }
3188:2): }
3189:2): }
3190:2): }
3191:2): }
3192:2): }
3193:2): var domradio = form.elements['ltisec_domlinkprot'];
3194:2): if (domradio.length) {
3195:2): for (var i=0; i<domradio.length; i++) {
3196:2): if (domradio[i].checked) {
3197:2): if (domradio[i].value == 1) {
3198:2): if (!shownhosts.includes(fromdomain)) {
3199:2): shownhosts.push(fromdomain);
3200:2): }
3201:2): } else {
3202:2): if (!hiddenhosts.includes(fromdomain)) {
3203:2): hiddenhosts.push(fromdomain);
3204:2): }
3205:2): }
3206:2): }
3207:2): }
3208:2): }
3209:2): if (shownhosts.length > 0) {
3210:2): for (var i=0; i<shownhosts.length; i++) {
3211:2): if (document.getElementById('ltisec_info_'+shownhosts[i])) {
3212:2): document.getElementById('ltisec_info_'+shownhosts[i]).style.display = 'block';
3213:2): }
3214:2): }
3215:2): if (document.getElementById('ltisec_noprivkey')) {
3216:2): document.getElementById('ltisec_noprivkey').style.display = 'none';
3217:2): }
3218:2): } else {
3219:2): if (document.getElementById('ltisec_noprivkey')) {
3220:2): document.getElementById('ltisec_noprivkey').style.display = 'inline-block';
3221:2): }
3222:2): }
3223:2): if (hiddenhosts.length > 0) {
3224:2): for (var i=0; i<hiddenhosts.length; i++) {
3225:2): if (!shownhosts.includes(hiddenhosts[i])) {
3226:2): if (document.getElementById('ltisec_info_'+hiddenhosts[i])) {
3227:2): document.getElementById('ltisec_info_'+hiddenhosts[i]).style.display = 'none';
3228:2): }
3229:2): }
3230:2): }
3231:2): }
3232:2): return;
3233:2): }
3234:2):
3235:2): function togglePrivKey(form,hostid) {
3236:2): var radioname = '';
3237:2): var currdivid = '';
3238:2): var newdivid = '';
3239:2): if ((document.getElementById('ltisec_divcurrprivkey_'+hostid)) &&
3240:2): (document.getElementById('ltisec_divchgprivkey_'+hostid))) {
3241:2): currdivid = document.getElementById('ltisec_divcurrprivkey_'+hostid);
3242:2): newdivid = document.getElementById('ltisec_divchgprivkey_'+hostid);
3243:2): radioname = form.elements['ltisec_changeprivkey_'+hostid];
3244:2): if (radioname) {
3245:2): if (radioname.length > 0) {
3246:2): var setvis;
3247:2): for (var i=0; i<radioname.length; i++) {
3248:2): if (radioname[i].checked == true) {
3249:2): if (radioname[i].value == 1) {
3250:2): newdivid.style.display = 'inline-block';
3251:2): currdivid.style.display = 'none';
3252:2): setvis = 1;
3253:2): }
3254:2): break;
3255:2): }
3256:2): }
3257:2): if (!setvis) {
3258:2): newdivid.style.display = 'none';
3259:2): currdivid.style.display = 'inline-block';
3260:2): }
3261:2): }
3262:2): }
3263:2): }
3264:2): }
3265:2):
3266:2): // ]]>
3267:2): </script>
3268:2):
3269:2): ENDSCRIPT
3270:2): }
3271:2):
1.160.6.113 raeburn 3272: sub autoupdate_javascript {
3273: return <<"ENDSCRIPT";
3274: <script type="text/javascript">
3275: // <![CDATA[
3276: function toggleLastActiveDays(form) {
3277: var radioname = 'lastactive';
3278: var divid = 'lastactive_div';
3279: var num = form.elements[radioname].length;
3280: if (num) {
3281: var setvis = '';
3282: for (var i=0; i<num; i++) {
3283: if (form.elements[radioname][i].checked) {
3284: if (form.elements[radioname][i].value == '1') {
3285: if (document.getElementById(divid)) {
3286: document.getElementById(divid).style.display = 'inline-block';
3287: }
3288: setvis = 1;
3289: }
3290: break;
3291: }
3292: }
3293: if (!setvis) {
3294: if (document.getElementById(divid)) {
3295: document.getElementById(divid).style.display = 'none';
3296: }
3297: }
3298: }
3299: return;
3300: }
3301: // ]]>
3302: </script>
3303:
3304: ENDSCRIPT
3305: }
3306:
1.160.6.116 raeburn 3307: sub autoenroll_javascript {
3308: return <<"ENDSCRIPT";
3309: <script type="text/javascript">
3310: // <![CDATA[
3311: function toggleFailsafe(form) {
3312: var radioname = 'autoenroll_failsafe';
3313: var divid = 'autoenroll_failsafe_div';
3314: var num = form.elements[radioname].length;
3315: if (num) {
3316: var setvis = '';
3317: for (var i=0; i<num; i++) {
3318: if (form.elements[radioname][i].checked) {
3319: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3320: if (document.getElementById(divid)) {
3321: document.getElementById(divid).style.display = 'inline-block';
3322: }
3323: setvis = 1;
3324: }
3325: break;
3326: }
3327: }
3328: if (!setvis) {
3329: if (document.getElementById(divid)) {
3330: document.getElementById(divid).style.display = 'none';
3331: }
3332: }
3333: }
3334: return;
3335: }
3336: // ]]>
3337: </script>
3338:
3339: ENDSCRIPT
3340: }
3341:
1.160.6.113 raeburn 3342: sub saml_javascript {
3343: return <<"ENDSCRIPT";
3344: <script type="text/javascript">
3345: // <![CDATA[
3346: function toggleSamlOptions(form,hostid) {
3347: var radioname = 'saml_'+hostid;
3348: var tablecellon = 'samloptionson_'+hostid;
3349: var tablecelloff = 'samloptionsoff_'+hostid;
3350: var num = form.elements[radioname].length;
3351: if (num) {
3352: var setvis = '';
3353: for (var i=0; i<num; i++) {
3354: if (form.elements[radioname][i].checked) {
3355: if (form.elements[radioname][i].value == '1') {
3356: if (document.getElementById(tablecellon)) {
3357: document.getElementById(tablecellon).style.display='';
3358: }
3359: if (document.getElementById(tablecelloff)) {
3360: document.getElementById(tablecelloff).style.display='none';
3361: }
3362: setvis = 1;
3363: }
3364: break;
3365: }
3366: }
3367: if (!setvis) {
3368: if (document.getElementById(tablecellon)) {
3369: document.getElementById(tablecellon).style.display='none';
3370: }
3371: if (document.getElementById(tablecelloff)) {
3372: document.getElementById(tablecelloff).style.display='';
3373: }
3374: }
3375: }
3376: return;
3377: }
3378: // ]]>
3379: </script>
3380:
3381: ENDSCRIPT
3382: }
3383:
3384: sub ipaccess_javascript {
3385: my ($settings) = @_;
3386: my (%ordered,$total,%jstext);
3387: $total = 0;
3388: if (ref($settings) eq 'HASH') {
3389: foreach my $item (keys(%{$settings})) {
3390: if (ref($settings->{$item}) eq 'HASH') {
3391: my $num = $settings->{$item}{'order'};
3392: $ordered{$num} = $item;
3393: }
3394: }
3395: $total = scalar(keys(%{$settings}));
3396: }
3397: my @jsarray = ();
3398: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3399: push(@jsarray,$ordered{$item});
3400: }
3401: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3402: return <<"ENDSCRIPT";
3403: <script type="text/javascript">
3404: // <![CDATA[
3405: function reorderIPaccess(form,item) {
3406: var changedVal;
3407: $jstext
3408: var newpos = 'ipaccess_pos_add';
3409: var maxh = 1 + $total;
3410: var current = new Array;
3411: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3412: if (item == newpos) {
3413: changedVal = newitemVal;
3414: } else {
3415: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3416: current[newitemVal] = newpos;
3417: }
3418: for (var i=0; i<ipaccess.length; i++) {
3419: var elementName = 'ipaccess_pos_'+ipaccess[i];
3420: if (elementName != item) {
3421: if (form.elements[elementName]) {
3422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3423: current[currVal] = elementName;
3424: }
3425: }
3426: }
3427: var oldVal;
3428: for (var j=0; j<maxh; j++) {
3429: if (current[j] == undefined) {
3430: oldVal = j;
3431: }
3432: }
3433: if (oldVal < changedVal) {
3434: for (var k=oldVal+1; k<=changedVal ; k++) {
3435: var elementName = current[k];
3436: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3437: }
3438: } else {
3439: for (var k=changedVal; k<oldVal; k++) {
3440: var elementName = current[k];
3441: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3442: }
3443: }
3444: return;
3445: }
3446: // ]]>
3447: </script>
3448:
3449: ENDSCRIPT
3450: }
3451:
1.3 raeburn 3452: sub print_autoenroll {
1.30 raeburn 3453: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3454: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3455: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3456: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3457: $failsafesty = 'none';
3458: %failsafechecked = (
3459: off => ' checked="checked"',
3460: );
1.3 raeburn 3461: if (ref($settings) eq 'HASH') {
3462: if (exists($settings->{'run'})) {
3463: if ($settings->{'run'} eq '0') {
3464: $runoff = ' checked="checked" ';
3465: $runon = ' ';
3466: } else {
3467: $runon = ' checked="checked" ';
3468: $runoff = ' ';
3469: }
3470: } else {
3471: if ($autorun) {
3472: $runon = ' checked="checked" ';
3473: $runoff = ' ';
3474: } else {
3475: $runoff = ' checked="checked" ';
3476: $runon = ' ';
3477: }
3478: }
1.129 raeburn 3479: if (exists($settings->{'co-owners'})) {
3480: if ($settings->{'co-owners'} eq '0') {
3481: $coownersoff = ' checked="checked" ';
3482: $coownerson = ' ';
3483: } else {
3484: $coownerson = ' checked="checked" ';
3485: $coownersoff = ' ';
3486: }
3487: } else {
3488: $coownersoff = ' checked="checked" ';
3489: $coownerson = ' ';
3490: }
1.3 raeburn 3491: if (exists($settings->{'sender_domain'})) {
3492: $defdom = $settings->{'sender_domain'};
3493: }
1.160.6.116 raeburn 3494: if (exists($settings->{'failsafe'})) {
3495: $failsafe = $settings->{'failsafe'};
3496: if ($failsafe eq 'zero') {
3497: $failsafechecked{'zero'} = ' checked="checked"';
3498: $failsafechecked{'off'} = '';
3499: $failsafesty = 'inline-block';
3500: } elsif ($failsafe eq 'any') {
3501: $failsafechecked{'any'} = ' checked="checked"';
3502: $failsafechecked{'off'} = '';
3503: }
3504: $autofailsafe = $settings->{'autofailsafe'};
3505: } elsif (exists($settings->{'autofailsafe'})) {
3506: $autofailsafe = $settings->{'autofailsafe'};
3507: if ($autofailsafe ne '') {
3508: $failsafechecked{'zero'} = ' checked="checked"';
3509: $failsafe = 'zero';
3510: $failsafechecked{'off'} = '';
3511: }
1.160.6.68 raeburn 3512: }
1.14 raeburn 3513: } else {
3514: if ($autorun) {
3515: $runon = ' checked="checked" ';
3516: $runoff = ' ';
3517: } else {
3518: $runoff = ' checked="checked" ';
3519: $runon = ' ';
3520: }
1.3 raeburn 3521: }
3522: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3523: my $notif_sender;
3524: if (ref($settings) eq 'HASH') {
3525: $notif_sender = $settings->{'sender_uname'};
3526: }
1.3 raeburn 3527: my $datatable='<tr class="LC_odd_row">'.
3528: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3529: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3530: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3531: $runon.' value="1" />'.&mt('Yes').'</label> '.
3532: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3533: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3534: '</tr><tr>'.
3535: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3536: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3537: &mt('username').': '.
3538: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3539: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3540: ': '.$domform.'</span></td></tr>'.
3541: '<tr class="LC_odd_row">'.
3542: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3543: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3544: '<input type="radio" name="autoassign_coowners"'.
3545: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3546: '<label><input type="radio" name="autoassign_coowners"'.
3547: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3548: '</tr><tr>'.
3549: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3550: '<td class="LC_left_item"><span class="LC_nobreak">'.
3551: '<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> '.
3552: '<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 />'.
3553: '<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>'.
3554: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3555: '<span class="LC_nobreak">'.
3556: &mt('Threshold for number of students in section to drop: [_1]',
3557: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3558: '</span></div></td></tr>';
1.160.6.68 raeburn 3559: $$rowtotal += 4;
1.3 raeburn 3560: return $datatable;
3561: }
3562:
3563: sub print_autoupdate {
1.30 raeburn 3564: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3565: my ($enable,$datatable);
1.3 raeburn 3566: if ($position eq 'top') {
1.160.6.113 raeburn 3567: my %choices = &Apache::lonlocal::texthash (
3568: run => 'Auto-update active?',
3569: classlists => 'Update information in classlists?',
3570: unexpired => 'Skip updates for users without active or future roles?',
3571: lastactive => 'Skip updates for inactive users?',
3572: );
3573: my $itemcount = 0;
1.3 raeburn 3574: my $updateon = ' ';
3575: my $updateoff = ' checked="checked" ';
3576: if (ref($settings) eq 'HASH') {
3577: if ($settings->{'run'} eq '1') {
3578: $updateon = $updateoff;
3579: $updateoff = ' ';
3580: }
3581: }
1.160.6.113 raeburn 3582: $enable = '<tr class="LC_odd_row">'.
3583: '<td>'.&mt($choices{'run'}).'</td>'.
3584: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3585: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3586: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3587: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3588: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3589: '</tr>';
1.160.6.113 raeburn 3590: my @toggles = ('classlists','unexpired');
3591: my %defaultchecked = ('classlists' => 'off',
3592: 'unexpired' => 'off'
3593: );
3594: $$rowtotal ++;
3595: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3596: \%choices,$itemcount,'','','left','no');
3597: $datatable = $enable.$datatable;
3598: $$rowtotal += $itemcount;
3599: my $lastactiveon = ' ';
3600: my $lastactiveoff = ' checked="checked" ';
3601: my $lastactivestyle = 'none';
3602: my $lastactivedays;
3603: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3604: if (ref($settings) eq 'HASH') {
3605: if ($settings->{'lastactive'} =~ /^\d+$/) {
3606: $lastactiveon = $lastactiveoff;
3607: $lastactiveoff = ' ';
3608: $lastactivestyle = 'inline-block';
3609: $lastactivedays = $settings->{'lastactive'};
3610: }
3611: }
3612: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3613: $datatable .= '<tr'.$css_class.'>'.
3614: '<td>'.$choices{'lastactive'}.'</td>'.
3615: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3616: '<input type="radio" name="lastactive"'.
3617: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3618: ' <label>'.
3619: '<input type="radio" name="lastactive"'.
3620: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3621: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3622: ': '.&mt('inactive = no activity in last [_1] days',
3623: '<input type="text" size="5" name="lastactivedays" value="'.
3624: $lastactivedays.'" />').
3625: '</span></td>'.
3626: '</tr>';
3627: $$rowtotal ++;
1.131 raeburn 3628: } elsif ($position eq 'middle') {
3629: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3630: my $numinrow = 3;
3631: my $locknamesettings;
3632: $datatable .= &insttypes_row($settings,$types,$usertypes,
3633: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3634: 'lockablenames',$rowtotal);
1.131 raeburn 3635: $$rowtotal ++;
1.3 raeburn 3636: } else {
1.44 raeburn 3637: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3638: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3639: 'permanentemail','id');
1.33 raeburn 3640: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3641: my $numrows = 0;
1.26 raeburn 3642: if (ref($types) eq 'ARRAY') {
3643: if (@{$types} > 0) {
3644: $datatable =
3645: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3646: \@fields,$types,\$numrows);
1.30 raeburn 3647: $$rowtotal += @{$types};
1.26 raeburn 3648: }
1.3 raeburn 3649: }
3650: $datatable .=
3651: &usertype_update_row($settings,{'default' => $othertitle},
3652: \%fieldtitles,\@fields,['default'],
3653: \$numrows);
1.30 raeburn 3654: $$rowtotal ++;
1.3 raeburn 3655: }
3656: return $datatable;
3657: }
3658:
1.125 raeburn 3659: sub print_autocreate {
3660: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3661: my (%createon,%createoff,%currhash);
1.125 raeburn 3662: my @types = ('xml','req');
3663: if (ref($settings) eq 'HASH') {
3664: foreach my $item (@types) {
3665: $createoff{$item} = ' checked="checked" ';
3666: $createon{$item} = ' ';
3667: if (exists($settings->{$item})) {
3668: if ($settings->{$item}) {
3669: $createon{$item} = ' checked="checked" ';
3670: $createoff{$item} = ' ';
3671: }
3672: }
3673: }
1.160.6.16 raeburn 3674: if ($settings->{'xmldc'} ne '') {
3675: $currhash{$settings->{'xmldc'}} = 1;
3676: }
1.125 raeburn 3677: } else {
3678: foreach my $item (@types) {
3679: $createoff{$item} = ' checked="checked" ';
3680: $createon{$item} = ' ';
3681: }
3682: }
3683: $$rowtotal += 2;
1.160.6.16 raeburn 3684: my $numinrow = 2;
1.125 raeburn 3685: my $datatable='<tr class="LC_odd_row">'.
3686: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3687: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3688: '<input type="radio" name="autocreate_xml"'.
3689: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3690: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3691: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3692: '</td></tr><tr>'.
3693: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3694: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3695: '<input type="radio" name="autocreate_req"'.
3696: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3697: '<label><input type="radio" name="autocreate_req"'.
3698: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3699: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3700: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3701: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3702: if ($numdc > 1) {
1.160.6.50 raeburn 3703: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3704: '</td><td class="LC_left_item">';
1.125 raeburn 3705: } else {
1.160.6.50 raeburn 3706: $datatable .= &mt('Course creation processed as:').
3707: '</td><td class="LC_right_item">';
1.125 raeburn 3708: }
1.160.6.50 raeburn 3709: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3710: $$rowtotal += $rows;
1.125 raeburn 3711: return $datatable;
3712: }
3713:
1.23 raeburn 3714: sub print_directorysrch {
1.160.6.72 raeburn 3715: my ($position,$dom,$settings,$rowtotal) = @_;
3716: my $datatable;
3717: if ($position eq 'top') {
3718: my $instsrchon = ' ';
3719: my $instsrchoff = ' checked="checked" ';
3720: my ($exacton,$containson,$beginson);
3721: my $instlocalon = ' ';
3722: my $instlocaloff = ' checked="checked" ';
3723: if (ref($settings) eq 'HASH') {
3724: if ($settings->{'available'} eq '1') {
3725: $instsrchon = $instsrchoff;
3726: $instsrchoff = ' ';
3727: }
3728: if ($settings->{'localonly'} eq '1') {
3729: $instlocalon = $instlocaloff;
3730: $instlocaloff = ' ';
3731: }
3732: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3733: foreach my $type (@{$settings->{'searchtypes'}}) {
3734: if ($type eq 'exact') {
3735: $exacton = ' checked="checked" ';
3736: } elsif ($type eq 'contains') {
3737: $containson = ' checked="checked" ';
3738: } elsif ($type eq 'begins') {
3739: $beginson = ' checked="checked" ';
3740: }
3741: }
3742: } else {
3743: if ($settings->{'searchtypes'} eq 'exact') {
3744: $exacton = ' checked="checked" ';
3745: } elsif ($settings->{'searchtypes'} eq 'contains') {
3746: $containson = ' checked="checked" ';
3747: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 3748: $exacton = ' checked="checked" ';
3749: $containson = ' checked="checked" ';
3750: }
3751: }
1.23 raeburn 3752: }
1.160.6.72 raeburn 3753: my ($searchtitles,$titleorder) = &sorted_searchtitles();
3754: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 3755:
1.160.6.72 raeburn 3756: my $numinrow = 4;
3757: my $cansrchrow = 0;
3758: $datatable='<tr class="LC_odd_row">'.
3759: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
3760: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3761: '<input type="radio" name="dirsrch_available"'.
3762: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
3763: '<label><input type="radio" name="dirsrch_available"'.
3764: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3765: '</tr><tr>'.
3766: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
3767: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3768: '<input type="radio" name="dirsrch_instlocalonly"'.
3769: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3770: '<label><input type="radio" name="dirsrch_instlocalonly"'.
3771: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3772: '</tr>';
3773: $$rowtotal += 2;
3774: if (ref($usertypes) eq 'HASH') {
3775: if (keys(%{$usertypes}) > 0) {
3776: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 3777: $numinrow,$othertitle,'cansearch',
3778: $rowtotal);
1.160.6.72 raeburn 3779: $cansrchrow = 1;
3780: }
1.26 raeburn 3781: }
1.160.6.72 raeburn 3782: if ($cansrchrow) {
3783: $$rowtotal ++;
3784: $datatable .= '<tr>';
3785: } else {
3786: $datatable .= '<tr class="LC_odd_row">';
3787: }
3788: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
3789: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
3790: foreach my $title (@{$titleorder}) {
3791: if (defined($searchtitles->{$title})) {
3792: my $check = ' ';
3793: if (ref($settings) eq 'HASH') {
3794: if (ref($settings->{'searchby'}) eq 'ARRAY') {
3795: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
3796: $check = ' checked="checked" ';
3797: }
1.39 raeburn 3798: }
1.25 raeburn 3799: }
1.160.6.72 raeburn 3800: $datatable .= '<td class="LC_left_item">'.
3801: '<span class="LC_nobreak"><label>'.
3802: '<input type="checkbox" name="searchby" '.
3803: 'value="'.$title.'"'.$check.'/>'.
3804: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 3805: }
3806: }
1.160.6.72 raeburn 3807: $datatable .= '</tr></table></td></tr>';
3808: $$rowtotal ++;
3809: if ($cansrchrow) {
3810: $datatable .= '<tr class="LC_odd_row">';
3811: } else {
3812: $datatable .= '<tr>';
3813: }
3814: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
3815: '<td class="LC_left_item" colspan="2">'.
3816: '<span class="LC_nobreak"><label>'.
3817: '<input type="checkbox" name="searchtypes" '.
3818: $exacton.' value="exact" />'.&mt('Exact match').
3819: '</label> '.
3820: '<label><input type="checkbox" name="searchtypes" '.
3821: $beginson.' value="begins" />'.&mt('Begins with').
3822: '</label> '.
3823: '<label><input type="checkbox" name="searchtypes" '.
3824: $containson.' value="contains" />'.&mt('Contains').
3825: '</label></span></td></tr>';
3826: $$rowtotal ++;
1.26 raeburn 3827: } else {
1.160.6.72 raeburn 3828: my $domsrchon = ' checked="checked" ';
3829: my $domsrchoff = ' ';
3830: my $domlocalon = ' ';
3831: my $domlocaloff = ' checked="checked" ';
3832: if (ref($settings) eq 'HASH') {
3833: if ($settings->{'lclocalonly'} eq '1') {
3834: $domlocalon = $domlocaloff;
3835: $domlocaloff = ' ';
3836: }
3837: if ($settings->{'lcavailable'} eq '0') {
3838: $domsrchoff = $domsrchon;
3839: $domsrchon = ' ';
3840: }
3841: }
3842: $datatable='<tr class="LC_odd_row">'.
3843: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
3844: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3845: '<input type="radio" name="dirsrch_domavailable"'.
3846: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
3847: '<label><input type="radio" name="dirsrch_domavailable"'.
3848: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
3849: '</tr><tr>'.
3850: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
3851: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3852: '<input type="radio" name="dirsrch_domlocalonly"'.
3853: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
3854: '<label><input type="radio" name="dirsrch_domlocalonly"'.
3855: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
3856: '</tr>';
3857: $$rowtotal += 2;
1.26 raeburn 3858: }
1.25 raeburn 3859: return $datatable;
3860: }
3861:
1.28 raeburn 3862: sub print_contacts {
1.160.6.78 raeburn 3863: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 3864: my $datatable;
3865: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 3866: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 3867: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 3868: if ($position eq 'top') {
3869: if (ref($settings) eq 'HASH') {
3870: foreach my $item (@contacts) {
3871: if (exists($settings->{$item})) {
3872: $to{$item} = $settings->{$item};
3873: }
1.28 raeburn 3874: }
3875: }
1.160.6.78 raeburn 3876: } elsif ($position eq 'middle') {
3877: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 3878: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 3879: foreach my $type (@mailings) {
1.160.6.78 raeburn 3880: $otheremails{$type} = '';
3881: }
1.160.6.107 raeburn 3882: } elsif ($position eq 'lower') {
3883: if (ref($settings) eq 'HASH') {
3884: if (ref($settings->{'lonstatus'}) eq 'HASH') {
3885: %lonstatus = %{$settings->{'lonstatus'}};
3886: }
3887: }
1.160.6.78 raeburn 3888: } else {
3889: @mailings = ('helpdeskmail','otherdomsmail');
3890: foreach my $type (@mailings) {
3891: $otheremails{$type} = '';
3892: }
3893: $bccemails{'helpdeskmail'} = '';
3894: $bccemails{'otherdomsmail'} = '';
3895: $includestr{'helpdeskmail'} = '';
3896: $includestr{'otherdomsmail'} = '';
3897: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
3898: }
3899: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 3900: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 3901: foreach my $type (@mailings) {
3902: if (exists($settings->{$type})) {
3903: if (ref($settings->{$type}) eq 'HASH') {
3904: foreach my $item (@contacts) {
3905: if ($settings->{$type}{$item}) {
3906: $checked{$type}{$item} = ' checked="checked" ';
3907: }
1.28 raeburn 3908: }
1.160.6.78 raeburn 3909: $otheremails{$type} = $settings->{$type}{'others'};
3910: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
3911: $bccemails{$type} = $settings->{$type}{'bcc'};
3912: if ($settings->{$type}{'include'} ne '') {
3913: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3914: $includestr{$type} = &unescape($includestr{$type});
3915: }
3916: }
3917: }
3918: } elsif ($type eq 'lonstatusmail') {
3919: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3920: }
3921: }
3922: }
3923: if ($position eq 'bottom') {
3924: foreach my $type (@mailings) {
3925: $bccemails{$type} = $settings->{$type}{'bcc'};
3926: if ($settings->{$type}{'include'} ne '') {
3927: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
3928: $includestr{$type} = &unescape($includestr{$type});
3929: }
3930: }
3931: if (ref($settings->{'helpform'}) eq 'HASH') {
3932: if (ref($fields) eq 'ARRAY') {
3933: foreach my $field (@{$fields}) {
3934: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 3935: }
1.160.6.78 raeburn 3936: }
3937: if (exists($settings->{'helpform'}{'maxsize'})) {
3938: $maxsize = $settings->{'helpform'}{'maxsize'};
3939: } else {
3940: $maxsize = '1.0';
3941: }
3942: } else {
3943: if (ref($fields) eq 'ARRAY') {
3944: foreach my $field (@{$fields}) {
3945: $currfield{$field} = 'yes';
1.134 raeburn 3946: }
1.28 raeburn 3947: }
1.160.6.78 raeburn 3948: $maxsize = '1.0';
1.28 raeburn 3949: }
3950: }
3951: } else {
1.160.6.78 raeburn 3952: if ($position eq 'top') {
3953: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
3954: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
3955: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
3956: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
3957: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
3958: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
3959: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
3960: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 3961: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 3962: } elsif ($position eq 'bottom') {
3963: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
3964: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
3965: if (ref($fields) eq 'ARRAY') {
3966: foreach my $field (@{$fields}) {
3967: $currfield{$field} = 'yes';
3968: }
3969: }
3970: $maxsize = '1.0';
3971: }
1.28 raeburn 3972: }
3973: my ($titles,$short_titles) = &contact_titles();
3974: my $rownum = 0;
3975: my $css_class;
1.160.6.78 raeburn 3976: if ($position eq 'top') {
3977: foreach my $item (@contacts) {
3978: $css_class = $rownum%2?' class="LC_odd_row"':'';
3979: $datatable .= '<tr'.$css_class.'>'.
3980: '<td><span class="LC_nobreak">'.$titles->{$item}.
3981: '</span></td><td class="LC_right_item">'.
3982: '<input type="text" name="'.$item.'" value="'.
3983: $to{$item}.'" /></td></tr>';
3984: $rownum ++;
3985: }
1.160.6.101 raeburn 3986: } elsif ($position eq 'bottom') {
3987: $css_class = $rownum%2?' class="LC_odd_row"':'';
3988: $datatable .= '<tr'.$css_class.'>'.
3989: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
3990: &mt('(e-mail, subject, and description always shown)').
3991: '</td><td class="LC_left_item">';
3992: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
3993: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
3994: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
3995: foreach my $field (@{$fields}) {
3996: $datatable .= '<tr><td>'.$fieldtitles->{$field};
3997: if (($field eq 'screenshot') || ($field eq 'cc')) {
3998: $datatable .= ' '.&mt('(logged-in users)');
3999: }
4000: $datatable .='</td><td>';
4001: my $clickaction;
4002: if ($field eq 'screenshot') {
4003: $clickaction = ' onclick="screenshotSize(this);"';
4004: }
4005: if (ref($possoptions->{$field}) eq 'ARRAY') {
4006: foreach my $option (@{$possoptions->{$field}}) {
4007: my $checked;
4008: if ($currfield{$field} eq $option) {
4009: $checked = ' checked="checked"';
4010: }
4011: $datatable .= '<span class="LC_nobreak"><label>'.
4012: '<input type="radio" name="helpform_'.$field.'" '.
4013: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4014: '</label></span>'.(' 'x2);
4015: }
4016: }
4017: if ($field eq 'screenshot') {
4018: my $display;
4019: if ($currfield{$field} eq 'no') {
4020: $display = ' style="display:none"';
4021: }
4022: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4023: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4024: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4025: }
4026: $datatable .= '</td></tr>';
4027: }
4028: $datatable .= '</table>';
4029: }
4030: $datatable .= '</td></tr>'."\n";
4031: $rownum ++;
4032: }
1.160.6.107 raeburn 4033: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4034: foreach my $type (@mailings) {
4035: $css_class = $rownum%2?' class="LC_odd_row"':'';
4036: $datatable .= '<tr'.$css_class.'>'.
4037: '<td><span class="LC_nobreak">'.
4038: $titles->{$type}.': </span></td>'.
4039: '<td class="LC_left_item">';
4040: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4041: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4042: }
4043: $datatable .= '<span class="LC_nobreak">';
4044: foreach my $item (@contacts) {
4045: $datatable .= '<label>'.
4046: '<input type="checkbox" name="'.$type.'"'.
4047: $checked{$type}{$item}.
4048: ' value="'.$item.'" />'.$short_titles->{$item}.
4049: '</label> ';
4050: }
4051: $datatable .= '</span><br />'.&mt('Others').': '.
4052: '<input type="text" name="'.$type.'_others" '.
4053: 'value="'.$otheremails{$type}.'" />';
4054: my %locchecked;
4055: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4056: foreach my $loc ('s','b') {
4057: if ($includeloc{$type} eq $loc) {
4058: $locchecked{$loc} = ' checked="checked"';
4059: last;
4060: }
4061: }
4062: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4063: '<input type="text" name="'.$type.'_bcc" '.
4064: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4065: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4066: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4067: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4068: '<span class="LC_nobreak">'.&mt('Location:').' '.
4069: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4070: (' 'x2).
4071: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4072: '</span></fieldset>';
4073: }
4074: $datatable .= '</td></tr>'."\n";
4075: $rownum ++;
4076: }
1.28 raeburn 4077: }
1.160.6.78 raeburn 4078: if ($position eq 'middle') {
4079: my %choices;
1.160.6.107 raeburn 4080: my $corelink = &core_link_msu();
4081: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4082: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4083: $corelink);
4084: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4085: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4086: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4087: 'reportupdates' => 'on',
4088: 'reportstatus' => 'on');
1.160.6.78 raeburn 4089: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4090: \%choices,$rownum);
4091: $datatable .= $reports;
1.160.6.107 raeburn 4092: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4093: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4094: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4095: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4096: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4097: } else {
1.160.6.109 raeburn 4098: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4099: }
4100: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4101: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4102: } else {
1.160.6.109 raeburn 4103: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4104: }
4105: if (ref($lonstatus{'weights'}) eq 'HASH') {
4106: foreach my $type ('E','W','N','U') {
4107: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4108: $weights{$type} = $lonstatus{'weights'}{$type};
4109: } else {
4110: $weights{$type} = $defaults->{$type};
4111: }
4112: }
4113: } else {
4114: foreach my $type ('E','W','N','U') {
4115: $weights{$type} = $defaults->{$type};
4116: }
4117: }
4118: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4119: if (@{$lonstatus{'excluded'}} > 0) {
4120: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4121: }
4122: }
1.160.6.109 raeburn 4123: foreach my $item ('errorthreshold','errorsysmail') {
4124: $css_class = $rownum%2?' class="LC_odd_row"':'';
4125: $datatable .= '<tr'.$css_class.'>'.
4126: '<td class="LC_left_item"><span class="LC_nobreak">'.
4127: $titles->{$item}.
4128: '</span></td><td class="LC_left_item">'.
4129: '<input type="text" name="'.$item.'" value="'.
4130: $current{$item}.'" size="5" /></td></tr>';
4131: $rownum ++;
4132: }
1.160.6.107 raeburn 4133: $css_class = $rownum%2?' class="LC_odd_row"':'';
4134: $datatable .= '<tr'.$css_class.'>'.
4135: '<td class="LC_left_item">'.
4136: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4137: '</span></td><td class="LC_left_item"><table><tr>';
4138: foreach my $type ('E','W','N','U') {
4139: $datatable .= '<td>'.$names->{$type}.'<br />'.
4140: '<input type="text" name="errorweights_'.$type.'" value="'.
4141: $weights{$type}.'" size="5" /></td>';
4142: }
4143: $datatable .= '</tr></table></tr>';
4144: $rownum ++;
4145: $css_class = $rownum%2?' class="LC_odd_row"':'';
4146: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4147: $titles->{'errorexcluded'}.'</td>'.
4148: '<td class="LC_left_item"><table>';
4149: my $numinrow = 4;
4150: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4151: for (my $i=0; $i<@ids; $i++) {
4152: my $rem = $i%($numinrow);
4153: if ($rem == 0) {
4154: if ($i > 0) {
4155: $datatable .= '</tr>';
4156: }
4157: $datatable .= '<tr>';
4158: }
4159: my $check;
4160: if ($excluded{$ids[$i]}) {
4161: $check = ' checked="checked" ';
4162: }
4163: $datatable .= '<td class="LC_left_item">'.
4164: '<span class="LC_nobreak"><label>'.
4165: '<input type="checkbox" name="errorexcluded" '.
4166: 'value="'.$ids[$i].'"'.$check.' />'.
4167: $ids[$i].'</label></span></td>';
4168: }
4169: my $colsleft = $numinrow - @ids%($numinrow);
4170: if ($colsleft > 1 ) {
4171: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4172: ' </td>';
4173: } elsif ($colsleft == 1) {
4174: $datatable .= '<td class="LC_left_item"> </td>';
4175: }
4176: $datatable .= '</tr></table></td></tr>';
4177: $rownum ++;
1.160.6.78 raeburn 4178: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4179: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4180: my (@posstypes,%usertypeshash);
4181: if (ref($types) eq 'ARRAY') {
4182: @posstypes = @{$types};
4183: }
4184: if (@posstypes) {
4185: if (ref($usertypes) eq 'HASH') {
4186: %usertypeshash = %{$usertypes};
4187: }
4188: my @overridden;
4189: my $numinrow = 4;
4190: if (ref($settings) eq 'HASH') {
4191: if (ref($settings->{'overrides'}) eq 'HASH') {
4192: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4193: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4194: push(@overridden,$key);
4195: foreach my $item (@contacts) {
4196: if ($settings->{'overrides'}{$key}{$item}) {
4197: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4198: }
4199: }
4200: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4201: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4202: $includeloc{'override_'.$key} = '';
4203: $includestr{'override_'.$key} = '';
4204: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4205: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4206: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4207: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4208: }
1.160.6.78 raeburn 4209: }
4210: }
4211: }
1.160.6.101 raeburn 4212: }
4213: my $customclass = 'LC_helpdesk_override';
4214: my $optionsprefix = 'LC_options_helpdesk_';
4215:
4216: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4217:
4218: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4219: $numinrow,$othertitle,'overrides',
4220: \$rownum,$onclicktypes,$customclass);
4221: $rownum ++;
4222: $usertypeshash{'default'} = $othertitle;
4223: foreach my $status (@posstypes) {
4224: my $css_class;
4225: if ($rownum%2) {
4226: $css_class = 'LC_odd_row ';
4227: }
4228: $css_class .= $customclass;
4229: my $rowid = $optionsprefix.$status;
4230: my $hidden = 1;
4231: my $currstyle = 'display:none';
4232: if (grep(/^\Q$status\E$/,@overridden)) {
4233: $currstyle = 'display:table-row';
4234: $hidden = 0;
4235: }
4236: my $key = 'override_'.$status;
4237: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4238: $includeloc{$key},$includestr{$key},$status,$rowid,
4239: $usertypeshash{$status},$css_class,$currstyle,
4240: \@contacts,$short_titles);
4241: unless ($hidden) {
4242: $rownum ++;
1.160.6.78 raeburn 4243: }
4244: }
1.134 raeburn 4245: }
1.28 raeburn 4246: }
1.30 raeburn 4247: $$rowtotal += $rownum;
1.28 raeburn 4248: return $datatable;
4249: }
4250:
1.160.6.107 raeburn 4251: sub core_link_msu {
4252: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4253: &mt('LON-CAPA core group - MSU'),600,500);
4254: }
4255:
1.160.6.101 raeburn 4256: sub overridden_helpdesk {
4257: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4258: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4259: my $class = 'LC_left_item';
4260: if ($css_class) {
4261: $css_class = ' class="'.$css_class.'"';
4262: }
4263: if ($rowid) {
4264: $rowid = ' id="'.$rowid.'"';
4265: }
4266: if ($rowstyle) {
4267: $rowstyle = ' style="'.$rowstyle.'"';
4268: }
4269: my ($output,$description);
4270: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4271: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4272: "<td>$description</td>\n".
4273: '<td class="'.$class.'" colspan="2">'.
4274: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4275: '<span class="LC_nobreak">';
4276: if (ref($contacts) eq 'ARRAY') {
4277: foreach my $item (@{$contacts}) {
4278: my $check;
4279: if (ref($checked) eq 'HASH') {
4280: $check = $checked->{$item};
4281: }
4282: my $title;
4283: if (ref($short_titles) eq 'HASH') {
4284: $title = $short_titles->{$item};
4285: }
4286: $output .= '<label>'.
4287: '<input type="checkbox" name="override_'.$type.'"'.$check.
4288: ' value="'.$item.'" />'.$title.'</label> ';
4289: }
4290: }
4291: $output .= '</span><br />'.&mt('Others').': '.
4292: '<input type="text" name="override_'.$type.'_others" '.
4293: 'value="'.$otheremails.'" />';
4294: my %locchecked;
4295: foreach my $loc ('s','b') {
4296: if ($includeloc eq $loc) {
4297: $locchecked{$loc} = ' checked="checked"';
4298: last;
4299: }
4300: }
4301: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4302: '<input type="text" name="override_'.$type.'_bcc" '.
4303: 'value="'.$bccemails.'" /></fieldset>'.
4304: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4305: &mt('Text automatically added to e-mail:').' '.
4306: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4307: '<span class="LC_nobreak">'.&mt('Location:').' '.
4308: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4309: (' 'x2).
4310: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4311: '</span></fieldset>'.
4312: '</td></tr>'."\n";
4313: return $output;
4314: }
4315:
1.160.6.78 raeburn 4316: sub contacts_javascript {
4317: return <<"ENDSCRIPT";
4318:
4319: <script type="text/javascript">
4320: // <![CDATA[
4321:
4322: function screenshotSize(field) {
4323: if (document.getElementById('help_screenshotsize')) {
4324: if (field.value == 'no') {
4325: document.getElementById('help_screenshotsize').style.display="none";
4326: } else {
4327: document.getElementById('help_screenshotsize').style.display="";
4328: }
4329: }
4330: return;
4331: }
4332:
1.160.6.101 raeburn 4333: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4334: if (form.elements[checkbox].length != undefined) {
4335: var count = 0;
4336: if (docount) {
4337: for (var i=0; i<form.elements[checkbox].length; i++) {
4338: if (form.elements[checkbox][i].checked) {
4339: count ++;
4340: }
4341: }
4342: }
4343: for (var i=0; i<form.elements[checkbox].length; i++) {
4344: var type = form.elements[checkbox][i].value;
4345: if (document.getElementById(prefix+type)) {
4346: if (form.elements[checkbox][i].checked) {
4347: document.getElementById(prefix+type).style.display = 'table-row';
4348: if (count % 2 == 1) {
4349: document.getElementById(prefix+type).className = target+' LC_odd_row';
4350: } else {
4351: document.getElementById(prefix+type).className = target;
4352: }
4353: count ++;
4354: } else {
4355: document.getElementById(prefix+type).style.display = 'none';
4356: }
4357: }
4358: }
4359: }
4360: return;
4361: }
4362:
1.160.6.78 raeburn 4363: // ]]>
4364: </script>
4365:
4366: ENDSCRIPT
4367: }
4368:
1.118 jms 4369: sub print_helpsettings {
1.160.6.73 raeburn 4370: my ($position,$dom,$settings,$rowtotal) = @_;
4371: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4372: my $formname = 'display';
1.160.6.5 raeburn 4373: my ($datatable,$itemcount);
1.160.6.73 raeburn 4374: if ($position eq 'top') {
4375: $itemcount = 1;
4376: my (%choices,%defaultchecked,@toggles);
4377: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4378: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4379: &mt('LON-CAPA bug tracker'),600,500));
4380: %defaultchecked = ('submitbugs' => 'on');
4381: @toggles = ('submitbugs');
4382: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4383: \%choices,$itemcount);
4384: $$rowtotal ++;
4385: } else {
4386: my $css_class;
4387: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4388: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4389: if (ref($settings) eq 'HASH') {
4390: if (ref($settings->{'adhoc'}) eq 'HASH') {
4391: %current = %{$settings->{'adhoc'}};
4392: }
1.160.6.77 raeburn 4393: }
4394: my $count = 0;
4395: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4396: if ($key=~/^rolesdef\_(\w+)$/) {
4397: my $rolename = $1;
1.160.6.77 raeburn 4398: my (%privs,$order);
1.160.6.73 raeburn 4399: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4400: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4401: if (ref($current{$rolename}) eq 'HASH') {
4402: $order = $current{$rolename}{'order'};
4403: }
4404: if ($order eq '') {
4405: $order = $count;
4406: }
4407: $ordered{$order} = $rolename;
4408: $count++;
1.160.6.73 raeburn 4409: }
4410: }
1.160.6.77 raeburn 4411: my $maxnum = scalar(keys(%ordered));
4412: my @roles_by_num = ();
4413: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4414: push(@roles_by_num,$item);
4415: }
4416: my $context = 'domprefs';
4417: my $crstype = 'Course';
4418: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4419: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4420: my ($numstatustypes,@jsarray);
4421: if (ref($types) eq 'ARRAY') {
4422: if (@{$types} > 0) {
4423: $numstatustypes = scalar(@{$types});
4424: push(@accesstypes,'status');
4425: @jsarray = ('bystatus');
4426: }
4427: }
1.160.6.86 raeburn 4428: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4429: if (keys(%domhelpdesk)) {
4430: push(@accesstypes,('inc','exc'));
4431: push(@jsarray,('notinc','notexc'));
4432: }
4433: my $hiddenstr = join("','",@jsarray);
4434: $datatable .= &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname);
1.160.6.73 raeburn 4435: my $context = 'domprefs';
4436: my $crstype = 'Course';
1.160.6.77 raeburn 4437: my $prefix = 'helproles_';
4438: my $add_class = 'LC_hidden';
4439: foreach my $num (@roles_by_num) {
4440: my $role = $ordered{$num};
4441: my ($desc,$access,@statuses);
4442: if (ref($current{$role}) eq 'HASH') {
4443: $desc = $current{$role}{'desc'};
4444: $access = $current{$role}{'access'};
4445: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4446: @statuses = @{$current{$role}{'insttypes'}};
4447: }
4448: }
4449: if ($desc eq '') {
4450: $desc = $role;
4451: }
4452: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4453: my %full=();
4454: my %levels= (
4455: course => {},
4456: domain => {},
4457: system => {},
4458: );
4459: my %levelscurrent=(
4460: course => {},
4461: domain => {},
4462: system => {},
4463: );
4464: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4465: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4466: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4467: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4468: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4469: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4470: for (my $k=0; $k<=$maxnum; $k++) {
4471: my $vpos = $k+1;
4472: my $selstr;
4473: if ($k == $num) {
4474: $selstr = ' selected="selected" ';
4475: }
4476: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4477: }
4478: $datatable .= '</select>'.(' 'x2).
4479: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4480: '</td>'.
4481: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4482: &mt('Name shown to users:').
4483: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4484: '</fieldset>'.
4485: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4486: $othertitle,$usertypes,$types,\%domhelpdesk).
4487: '<fieldset>'.
4488: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4489: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4490: \%levelscurrent,$identifier,
4491: 'LC_hidden',$prefix.$num.'_privs').
4492: '</fieldset></td>';
1.160.6.73 raeburn 4493: $itemcount ++;
4494: }
4495: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4496: my $newcust = 'custhelp'.$count;
4497: my (%privs,%levelscurrent);
4498: my %full=();
4499: my %levels= (
4500: course => {},
4501: domain => {},
4502: system => {},
4503: );
4504: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4505: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4506: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4507: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4508: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4509: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4510: for (my $k=0; $k<$maxnum+1; $k++) {
4511: my $vpos = $k+1;
4512: my $selstr;
4513: if ($k == $maxnum) {
4514: $selstr = ' selected="selected" ';
4515: }
4516: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4517: }
4518: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4519: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4520: '</label></span></td>'.
1.160.6.77 raeburn 4521: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4522: '<span class="LC_nobreak">'.
4523: &mt('Internal name:').
4524: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4525: '</span>'.(' 'x4).
4526: '<span class="LC_nobreak">'.
4527: &mt('Name shown to users:').
4528: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4529: '</span></fieldset>'.
4530: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4531: $usertypes,$types,\%domhelpdesk).
4532: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4533: &Apache::lonuserutils::custom_role_header($context,$crstype,
4534: \@templateroles,$newcust).
4535: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4536: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4537: '</fieldset>'.
4538: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4539: '</td></tr>';
1.160.6.73 raeburn 4540: $count ++;
4541: $$rowtotal += $count;
4542: }
1.160.6.5 raeburn 4543: return $datatable;
1.121 raeburn 4544: }
4545:
1.160.6.77 raeburn 4546: sub adhocbutton {
4547: my ($prefix,$num,$field,$visibility) = @_;
4548: my %lt = &Apache::lonlocal::texthash(
4549: show => 'Show details',
4550: hide => 'Hide details',
4551: );
4552: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4553: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4554: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4555: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4556: }
4557:
4558: sub helpsettings_javascript {
4559: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4560: return unless(ref($roles_by_num) eq 'ARRAY');
4561: my %html_js_lt = &Apache::lonlocal::texthash(
4562: show => 'Show details',
4563: hide => 'Hide details',
4564: );
4565: &html_escape(\%html_js_lt);
4566: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4567: return <<"ENDSCRIPT";
4568: <script type="text/javascript">
4569: // <![CDATA[
4570:
4571: function reorderHelpRoles(form,item) {
4572: var changedVal;
4573: $jstext
4574: var newpos = 'helproles_${total}_pos';
4575: var maxh = 1 + $total;
4576: var current = new Array();
4577: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4578: if (item == newpos) {
4579: changedVal = newitemVal;
4580: } else {
4581: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4582: current[newitemVal] = newpos;
4583: }
4584: for (var i=0; i<helproles.length; i++) {
4585: var elementName = 'helproles_'+helproles[i]+'_pos';
4586: if (elementName != item) {
4587: if (form.elements[elementName]) {
4588: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4589: current[currVal] = elementName;
4590: }
4591: }
4592: }
4593: var oldVal;
4594: for (var j=0; j<maxh; j++) {
4595: if (current[j] == undefined) {
4596: oldVal = j;
4597: }
4598: }
4599: if (oldVal < changedVal) {
4600: for (var k=oldVal+1; k<=changedVal ; k++) {
4601: var elementName = current[k];
4602: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4603: }
4604: } else {
4605: for (var k=changedVal; k<oldVal; k++) {
4606: var elementName = current[k];
4607: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4608: }
4609: }
4610: return;
4611: }
4612:
4613: function helpdeskAccess(num) {
4614: var curraccess = null;
4615: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4616: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4617: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4618: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4619: }
4620: }
4621: }
4622: var shown = Array();
4623: var hidden = Array();
4624: if (curraccess == 'none') {
4625: hidden = Array('$hiddenstr');
4626: } else {
4627: if (curraccess == 'status') {
4628: shown = Array('bystatus');
4629: hidden = Array('notinc','notexc');
4630: } else {
4631: if (curraccess == 'exc') {
4632: shown = Array('notexc');
4633: hidden = Array('notinc','bystatus');
4634: }
4635: if (curraccess == 'inc') {
4636: shown = Array('notinc');
4637: hidden = Array('notexc','bystatus');
4638: }
1.160.6.79 raeburn 4639: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4640: hidden = Array('notinc','notexc','bystatus');
4641: }
4642: }
4643: }
4644: if (hidden.length > 0) {
4645: for (var i=0; i<hidden.length; i++) {
4646: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4647: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4648: }
4649: }
4650: }
4651: if (shown.length > 0) {
4652: for (var i=0; i<shown.length; i++) {
4653: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4654: if (shown[i] == 'privs') {
4655: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4656: } else {
4657: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4658: }
4659: }
4660: }
4661: }
4662: return;
4663: }
4664:
4665: function toggleHelpdeskItem(num,field) {
4666: if (document.getElementById('helproles_'+num+'_'+field)) {
4667: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4668: document.getElementById('helproles_'+num+'_'+field).className =
4669: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4670: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4671: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4672: }
4673: } else {
4674: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4675: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4676: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4677: }
4678: }
4679: }
4680: return;
4681: }
4682:
4683: // ]]>
4684: </script>
4685:
4686: ENDSCRIPT
4687: }
4688:
4689: sub helpdeskroles_access {
4690: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4691: $usertypes,$types,$domhelpdesk) = @_;
4692: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4693: my %lt = &Apache::lonlocal::texthash(
4694: 'rou' => 'Role usage',
4695: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4696: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4697: 'dh' => 'All with domain helpdesk role',
4698: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4699: 'none' => 'None',
4700: 'status' => 'Determined based on institutional status',
4701: 'inc' => 'Include all, but exclude specific personnel',
4702: 'exc' => 'Exclude all, but include specific personnel',
4703: );
4704: my %usecheck = (
4705: all => ' checked="checked"',
4706: );
4707: my %displaydiv = (
4708: status => 'none',
4709: inc => 'none',
4710: exc => 'none',
4711: priv => 'block',
4712: );
4713: my $output;
4714: if (ref($current) eq 'HASH') {
4715: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4716: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4717: $usecheck{$current->{access}} = $usecheck{'all'};
4718: delete($usecheck{'all'});
4719: if ($current->{access} =~ /^(status|inc|exc)$/) {
4720: my $access = $1;
4721: $displaydiv{$access} = 'inline';
4722: } elsif ($current->{access} eq 'none') {
4723: $displaydiv{'priv'} = 'none';
4724: }
4725: }
4726: }
4727: }
4728: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4729: '<p>'.$lt{'whi'}.'</p>';
4730: foreach my $access (@{$accesstypes}) {
4731: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4732: ' onclick="helpdeskAccess('."'$num'".');" />'.
4733: $lt{$access}.'</label>';
4734: if ($access eq 'status') {
4735: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4736: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4737: $othertitle,$usertypes,$types).
4738: '</div>';
4739: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4740: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4741: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4742: '</div>';
4743: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4744: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
4745: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4746: '</div>';
4747: }
4748: $output .= '</p>';
4749: }
4750: $output .= '</fieldset>';
4751: return $output;
4752: }
4753:
1.121 raeburn 4754: sub radiobutton_prefs {
1.160.6.16 raeburn 4755: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 4756: $additional,$align,$firstval) = @_;
1.121 raeburn 4757: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
4758: (ref($choices) eq 'HASH'));
4759:
4760: my (%checkedon,%checkedoff,$datatable,$css_class);
4761:
4762: foreach my $item (@{$toggles}) {
4763: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 4764: $checkedon{$item} = ' checked="checked" ';
4765: $checkedoff{$item} = ' ';
1.121 raeburn 4766: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 4767: $checkedoff{$item} = ' checked="checked" ';
4768: $checkedon{$item} = ' ';
4769: }
4770: }
4771: if (ref($settings) eq 'HASH') {
1.121 raeburn 4772: foreach my $item (@{$toggles}) {
1.118 jms 4773: if ($settings->{$item} eq '1') {
4774: $checkedon{$item} = ' checked="checked" ';
4775: $checkedoff{$item} = ' ';
4776: } elsif ($settings->{$item} eq '0') {
4777: $checkedoff{$item} = ' checked="checked" ';
4778: $checkedon{$item} = ' ';
4779: }
4780: }
1.121 raeburn 4781: }
1.160.6.16 raeburn 4782: if ($onclick) {
4783: $onclick = ' onclick="'.$onclick.'"';
4784: }
1.121 raeburn 4785: foreach my $item (@{$toggles}) {
1.118 jms 4786: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 4787: $datatable .=
1.160.6.16 raeburn 4788: '<tr'.$css_class.'><td valign="top">'.
4789: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 4790: '</span></td>';
4791: if ($align eq 'left') {
4792: $datatable .= '<td class="LC_left_item">';
4793: } else {
4794: $datatable .= '<td class="LC_right_item">';
4795: }
1.160.6.113 raeburn 4796: $datatable .= '<span class="LC_nobreak">';
4797: if ($firstval eq 'no') {
4798: $datatable .=
4799: '<label><input type="radio" name="'.
4800: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
4801: '</label> <label><input type="radio" name="'.$item.'" '.
4802: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
4803: } else {
4804: $datatable .=
1.118 jms 4805: '<label><input type="radio" name="'.
1.160.6.16 raeburn 4806: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 4807: '</label> <label><input type="radio" name="'.$item.'" '.
1.160.6.113 raeburn 4808: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
4809: }
4810: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 4811: $itemcount ++;
1.121 raeburn 4812: }
4813: return ($datatable,$itemcount);
4814: }
4815:
1.160.6.118.2 1(raebur 4816:1): sub print_ltitools {
4817:1): my ($dom,$settings,$rowtotal) = @_;
4818:1): my $rownum = 0;
4819:1): my $css_class;
4820:1): my $itemcount = 1;
4821:1): my $maxnum = 0;
4822:1): my %ordered;
4823:1): if (ref($settings) eq 'HASH') {
4824:1): foreach my $item (keys(%{$settings})) {
4825:1): if (ref($settings->{$item}) eq 'HASH') {
4826:1): my $num = $settings->{$item}{'order'};
4827:1): $ordered{$num} = $item;
4828:1): }
4829:1): }
4830:1): }
4831:1): my $confname = $dom.'-domainconfig';
4832:1): my $switchserver = &check_switchserver($dom,$confname);
4833:1): my $maxnum = scalar(keys(%ordered));
4834:1): my $datatable;
4835:1): my %lt = <itools_names();
4836:1): my @courseroles = ('cc','in','ta','ep','st');
4837:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
4838:1): my @fields = ('fullname','firstname','lastname','email','roles','user');
4839:1): if (keys(%ordered)) {
4840:1): my @items = sort { $a <=> $b } keys(%ordered);
4841:1): for (my $i=0; $i<@items; $i++) {
4842:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
4843:1): my $item = $ordered{$items[$i]};
4844:1): my ($title,$key,$secret,$url,$lifetime,$imgsrc,%sigsel);
4845:1): if (ref($settings->{$item}) eq 'HASH') {
4846:1): $title = $settings->{$item}->{'title'};
4847:1): $url = $settings->{$item}->{'url'};
4848:1): $key = $settings->{$item}->{'key'};
4849:1): $secret = $settings->{$item}->{'secret'};
4850:1): $lifetime = $settings->{$item}->{'lifetime'};
4851:1): my $image = $settings->{$item}->{'image'};
4852:1): if ($image ne '') {
4853:1): $imgsrc = '<img src="'.$image.'" alt="'.&mt('Tool Provider icon').'" />';
4854:1): }
4855:1): if ($settings->{$item}->{'sigmethod'} eq 'HMAC-256') {
4856:1): $sigsel{'HMAC-256'} = ' selected="selected"';
4857:1): } else {
4858:1): $sigsel{'HMAC-SHA1'} = ' selected="selected"';
4859:1): }
4860:1): }
4861:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_".$item."'".');"';
4862:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4863:1): .'<select name="ltitools_'.$item.'"'.$chgstr.'>';
4864:1): for (my $k=0; $k<=$maxnum; $k++) {
4865:1): my $vpos = $k+1;
4866:1): my $selstr;
4867:1): if ($k == $i) {
4868:1): $selstr = ' selected="selected" ';
4869:1): }
4870:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4871:1): }
4872:1): $datatable .= '</select>'.(' 'x2).
4873:1): '<label><input type="checkbox" name="ltitools_del" value="'.$item.'" />'.
4874:1): &mt('Delete?').'</label></span></td>'.
4875:1): '<td colspan="2">'.
4876:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
4877:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_title_'.$i.'" value="'.$title.'" /></span> '.
4878:1): (' 'x2).
4879:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_version_'.$i.'">'.
4880:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
4881:1): (' 'x2).
4882:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_msgtype_'.$i.'">'.
4883:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
4884:1): (' 'x2).
4885:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_sigmethod_'.$i.'">'.
4886:1): '<option value="HMAC-SHA1"'.$sigsel{'HMAC-SHA1'}.'>HMAC-SHA1</option>'.
4887:1): '<option value="HMAC-SHA256"'.$sigsel{'HMAC-SHA256'}.'>HMAC-SHA256</option></select></span>'.
4888:1): '<br /><br />'.
4889:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_url_'.$i.'"'.
4890:1): ' value="'.$url.'" /></span>'.
4891:1): (' 'x2).
4892:1): '<span class="LC_nobreak">'.$lt{'key'}.':'.
4893:1): '<input type="text" size="25" name="ltitools_key_'.$i.'" value="'.$key.'" /></span> '.
4894:1): (' 'x2).
4895:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':'.
4896:1): '<input type="text" size="5" name="ltitools_lifetime_'.$i.'" value="'.$lifetime.'" /></span> '.
4897:1): (' 'x2).
4898:1): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
4899:1): '<input type="password" size="20" name="ltitools_secret_'.$i.'" value="'.$secret.'" />'.
4900: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>'.
4901:1): '<input type="hidden" name="ltitools_id_'.$i.'" value="'.$item.'" /></span>'.
4902:1): '</fieldset>'.
4903:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
4904:1): '<span class="LC_nobreak">'.&mt('Display target:');
4905:1): my %currdisp;
4906:1): if (ref($settings->{$item}->{'display'}) eq 'HASH') {
4907:1): if ($settings->{$item}->{'display'}->{'target'} eq 'window') {
4908:1): $currdisp{'window'} = ' checked="checked"';
4909:1): } elsif ($settings->{$item}->{'display'}->{'target'} eq 'tab') {
4910:1): $currdisp{'tab'} = ' checked="checked"';
4911:1): } else {
4912:1): $currdisp{'iframe'} = ' checked="checked"';
4913:1): }
4914:1): if ($settings->{$item}->{'display'}->{'width'} =~ /^(\d+)$/) {
4915:1): $currdisp{'width'} = $1;
4916:1): }
4917:1): if ($settings->{$item}->{'display'}->{'height'} =~ /^(\d+)$/) {
4918:1): $currdisp{'height'} = $1;
4919:1): }
4920:1): $currdisp{'linktext'} = $settings->{$item}->{'display'}->{'linktext'};
4921:1): $currdisp{'explanation'} = $settings->{$item}->{'display'}->{'explanation'};
4922:1): } else {
4923:1): $currdisp{'iframe'} = ' checked="checked"';
4924:1): }
4925:1): foreach my $disp ('iframe','tab','window') {
4926:1): $datatable .= '<label><input type="radio" name="ltitools_target_'.$i.'" value="'.$disp.'"'.$currdisp{$disp}.' />'.
4927:1): $lt{$disp}.'</label>'.(' 'x2);
4928:1): }
4929:1): $datatable .= (' 'x4);
4930:1): foreach my $dimen ('width','height') {
4931:1): $datatable .= '<label>'.$lt{$dimen}.' '.
4932:1): '<input type="text" name="ltitools_'.$dimen.'_'.$i.'" size="5" value="'.$currdisp{$dimen}.'" /></label>'.
4933:1): (' 'x2);
4934:1): }
4935:1): $datatable .= '</span><br />'.
4936:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
4937:1): '<input type="text" name="ltitools_linktext_'.$i.'" size="25" value="'.$currdisp{'linktext'}.'" /></div>'.
4938:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
4939:1): '<textarea name="ltitools_explanation_'.$i.'" rows="5" cols="40">'.$currdisp{'explanation'}.
4940:1): '</textarea></div><div style=""></div>'.
4941:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
4942:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
4943:1): if ($imgsrc) {
4944:1): $datatable .= $imgsrc.
4945:1): '<label><input type="checkbox" name="ltitools_image_del"'.
4946:1): ' value="'.$item.'" />'.&mt('Delete?').'</label></span> '.
4947:1): '<span class="LC_nobreak"> '.&mt('Replace:').' ';
4948:1): } else {
4949:1): $datatable .= '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
4950:1): }
4951:1): if ($switchserver) {
4952:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4953:1): } else {
4954:1): $datatable .= '<input type="file" name="ltitools_image_'.$i.'" value="" />';
4955:1): }
4956:1): $datatable .= '</span></fieldset>';
4957:1): my (%checkedfields,%rolemaps,$userincdom);
4958:1): if (ref($settings->{$item}) eq 'HASH') {
4959:1): if (ref($settings->{$item}->{'fields'}) eq 'HASH') {
4960:1): %checkedfields = %{$settings->{$item}->{'fields'}};
4961:1): }
4962:1): $userincdom = $settings->{$item}->{'incdom'};
4963:1): if (ref($settings->{$item}->{'roles'}) eq 'HASH') {
4964:1): %rolemaps = %{$settings->{$item}->{'roles'}};
4965:1): $checkedfields{'roles'} = 1;
4966:1): }
4967:1): }
4968:1): $datatable .= '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
4969:1): '<span class="LC_nobreak">';
4970:1): my $userfieldstyle = 'display:none;';
4971:1): my $seluserdom = '';
4972:1): my $unseluserdom = ' selected="selected"';
4973:1): foreach my $field (@fields) {
4974:1): my ($checked,$onclick,$id,$spacer);
4975:1): if ($checkedfields{$field}) {
4976:1): $checked = ' checked="checked"';
4977:1): }
4978:1): if ($field eq 'user') {
4979:1): $id = ' id="ltitools_user_field_'.$i.'"';
4980:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','$i'".')"';
4981:1): if ($checked) {
4982:1): $userfieldstyle = 'display:inline-block';
4983:1): if ($userincdom) {
4984:1): $seluserdom = $unseluserdom;
4985:1): $unseluserdom = '';
4986:1): }
4987:1): }
4988:1): } else {
4989:1): $spacer = (' ' x2);
4990:1): }
4991:1): $datatable .= '<label>'.
4992:1): '<input type="checkbox" name="ltitools_fields_'.$i.'" value="'.$field.'"'.$id.$checked.$onclick.' />'.
4993:1): $lt{$field}.'</label>'.$spacer;
4994:1): }
4995:1): $datatable .= '</span>';
4996:1): $datatable .= '<div style="'.$userfieldstyle.'" id="ltitools_user_div_'.$i.'">'.
4997:1): '<span class="LC_nobreak"> : '.
4998:1): '<select name="ltitools_userincdom_'.$i.'">'.
4999:1): '<option value="">'.&mt('Select').'</option>'.
5000:1): '<option value="0"'.$unseluserdom.'>'.&mt('username').'</option>'.
5001:1): '<option value="1"'.$seluserdom.'>'.&mt('username:domain').'</option>'.
5002:1): '</select></span></div>';
5003:1): $datatable .= '</fieldset>'.
5004:1): '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5005:1): foreach my $role (@courseroles) {
5006:1): my ($selected,$selectnone);
5007:1): if (!$rolemaps{$role}) {
5008:1): $selectnone = ' selected="selected"';
5009:1): }
5010:1): $datatable .= '<td align="center">'.
5011:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
5012:1): '<select name="ltitools_roles_'.$role.'_'.$i.'">'.
5013:1): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5014:1): foreach my $ltirole (@ltiroles) {
5015:1): unless ($selectnone) {
5016:1): if ($rolemaps{$role} eq $ltirole) {
5017:1): $selected = ' selected="selected"';
5018:1): } else {
5019:1): $selected = '';
5020:1): }
5021:1): }
5022:1): $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5023:1): }
5024:1): $datatable .= '</select></td>';
5025:1): }
5026:1): $datatable .= '</tr></table></fieldset>';
5027:1): my %courseconfig;
5028:1): if (ref($settings->{$item}) eq 'HASH') {
5029:1): if (ref($settings->{$item}->{'crsconf'}) eq 'HASH') {
5030:1): %courseconfig = %{$settings->{$item}->{'crsconf'}};
5031:1): }
5032:1): }
5033:1): $datatable .= '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5034:1): foreach my $item ('label','title','target','linktext','explanation','append') {
5035:1): my $checked;
5036:1): if ($courseconfig{$item}) {
5037:1): $checked = ' checked="checked"';
5038:1): }
5039:1): $datatable .= '<label>'.
5040:1): '<input type="checkbox" name="ltitools_courseconfig_'.$i.'" value="'.$item.'"'.$checked.' />'.
5041:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5042:1): }
5043:1): $datatable .= '</span></fieldset>'.
5044:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5045:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>';
5046:1): if (ref($settings->{$item}->{'custom'}) eq 'HASH') {
5047:1): my %custom = %{$settings->{$item}->{'custom'}};
5048:1): if (keys(%custom) > 0) {
5049:1): foreach my $key (sort(keys(%custom))) {
5050:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
5051:1): '<label><input type="checkbox" name="ltitools_customdel_'.$i.'" value="'.
5052:1): $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5053:1): '<td><input type="text" name="ltitools_customval_'.$key.'_'.$i.'"'.
5054:1): ' value="'.$custom{$key}.'" /></td></tr>';
5055:1): }
5056:1): }
5057:1): }
5058:1): $datatable .= '<tr><td><span class="LC_nobreak">'.
5059:1): '<label><input type="checkbox" name="ltitools_customadd" value="'.$i.'" />'.
5060:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_custom_name_'.$i.'" />'.
5061:1): '</td><td><input type="text" name="ltitools_custom_value_'.$i.'" /></td></tr>';
5062:1): $datatable .= '</table></fieldset></td></tr>'."\n";
5063:1): $itemcount ++;
5064:1): }
5065:1): }
5066:1): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5067:1): my $chgstr = ' onchange="javascript:reorderLTITools(this.form,'."'ltitools_add_pos'".');"';
5068:1): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5069:1): '<input type="hidden" name="ltitools_maxnum" value="'.$maxnum.'" />'."\n".
5070:1): '<select name="ltitools_add_pos"'.$chgstr.'>';
5071:1): for (my $k=0; $k<$maxnum+1; $k++) {
5072:1): my $vpos = $k+1;
5073:1): my $selstr;
5074:1): if ($k == $maxnum) {
5075:1): $selstr = ' selected="selected" ';
5076:1): }
5077:1): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5078:1): }
5079:1): $datatable .= '</select> '."\n".
5080:1): '<input type="checkbox" name="ltitools_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5081:1): '<td colspan="2">'.
5082:1): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5083:1): '<span class="LC_nobreak">'.$lt{'title'}.':<input type="text" size="20" name="ltitools_add_title" value="" /></span> '."\n".
5084:1): (' 'x2).
5085:1): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="ltitools_add_version">'.
5086:1): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5087:1): (' 'x2).
5088:1): '<span class="LC_nobreak">'.$lt{'msgtype'}.':<select name="ltitools_add_msgtype">'.
5089:1): '<option value="basic-lti-launch-request" selected="selected">Launch</option></select></span> '.
5090:1): '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="ltitools_add_sigmethod">'.
5091:1): '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5092:1): '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5093:1): '<br />'.
5094:1): '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="ltitools_add_url" value="" /></span> '."\n".
5095:1): (' 'x2).
5096:1): '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="ltitools_add_key" value="" /></span> '."\n".
5097:1): (' 'x2).
5098:1): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="ltitools_add_lifetime" value="300" /></span> '."\n".
5099:1): (' 'x2).
5100:1): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="ltitools_add_secret" value="" />'.
5101: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".
5102:1): '</fieldset>'.
5103:1): '<fieldset><legend>'.&mt('Optional settings').'</legend>'.
5104:1): '<span class="LC_nobreak">'.&mt('Display target:');
5105:1): my %defaultdisp;
5106:1): $defaultdisp{'iframe'} = ' checked="checked"';
5107:1): foreach my $disp ('iframe','tab','window') {
5108:1): $datatable .= '<label><input type="radio" name="ltitools_add_target" value="'.$disp.'"'.$defaultdisp{$disp}.' />'.
5109:1): $lt{$disp}.'</label>'.(' 'x2);
5110:1): }
5111:1): $datatable .= (' 'x4);
5112:1): foreach my $dimen ('width','height') {
5113:1): $datatable .= '<label>'.$lt{$dimen}.' '.
5114:1): '<input type="text" name="ltitools_add_'.$dimen.'" size="5" /></label>'.
5115:1): (' 'x2);
5116:1): }
5117:1): $datatable .= '</span><br />'.
5118:1): '<div class="LC_left_float">'.$lt{'linktext'}.'<br />'.
5119:1): '<input type="text" name="ltitools_add_linktext" size="5" /></div>'.
5120:1): '<div class="LC_left_float">'.$lt{'explanation'}.'<br />'.
5121:1): '<textarea name="ltitools_add_explanation" rows="5" cols="40"></textarea>'.
5122:1): '</div><div style=""></div>'.
5123:1): '<div style="padding:0;clear:both;margin:0;border:0"></div>';
5124:1): $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': '.
5125:1): '('.&mt('if larger than 21x21 pixels, image will be scaled').') ';
5126:1): if ($switchserver) {
5127:1): $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5128:1): } else {
5129:1): $datatable .= '<input type="file" name="ltitools_add_image" value="" />';
5130:1): }
5131:1): $datatable .= '</span></fieldset>'.
5132:1): '<fieldset><legend>'.&mt('User data sent on launch').'</legend>'.
5133:1): '<span class="LC_nobreak">';
5134:1): foreach my $field (@fields) {
5135:1): my ($id,$onclick,$spacer);
5136:1): if ($field eq 'user') {
5137:1): $id = ' id="ltitools_user_field_add"';
5138:1): $onclick = ' onclick="toggleLTITools(this.form,'."'$field','add'".')"';
5139:1): } else {
5140:1): $spacer = (' ' x2);
5141:1): }
5142:1): $datatable .= '<label>'.
5143:1): '<input type="checkbox" name="ltitools_add_fields" value="'.$field.'"'.$id.$onclick.' />'.
5144:1): $lt{$field}.'</label>'.$spacer;
5145:1): }
5146:1): $datatable .= '</span>'.
5147:1): '<div style="display:none;" id="ltitools_user_div_add">'.
5148:1): '<span class="LC_nobreak"> : '.
5149:1): '<select name="ltitools_userincdom_add">'.
5150:1): '<option value="" selected="selected">'.&mt('Select').'</option>'.
5151:1): '<option value="0">'.&mt('username').'</option>'.
5152:1): '<option value="1">'.&mt('username:domain').'</option>'.
5153:1): '</select></span></div></fieldset>';
5154:1): $datatable .= '<fieldset><legend>'.&mt('Role mapping').'</legend><table><tr>';
5155:1): foreach my $role (@courseroles) {
5156:1): my ($checked,$checkednone);
5157:1): $datatable .= '<td align="center">'.
5158:1): &Apache::lonnet::plaintext($role,'Course').'<br />'.
5159:1): '<select name="ltitools_add_roles_'.$role.'">'.
5160:1): '<option value="" selected="selected">'.&mt('Select').'</option>';
5161:1): foreach my $ltirole (@ltiroles) {
5162:1): $datatable .= '<option value="'.$ltirole.'">'.$ltirole.'</option>';
5163:1): }
5164:1): $datatable .= '</select></td>';
5165:1): }
5166:1): $datatable .= '</tr></table></fieldset>'.
5167:1): '<fieldset><legend>'.&mt('Configurable in course').'</legend><span class="LC_nobreak">';
5168:1): foreach my $item ('label','title','target','linktext','explanation','append') {
5169:1): $datatable .= '<label>'.
5170:1): '<input type="checkbox" name="ltitools_courseconfig" value="'.$item.'" checked="checked" />'.
5171:1): $lt{'crs'.$item}.'</label>'.(' ' x2)."\n";
5172:1): }
5173:1): $datatable .= '</span></fieldset>'.
5174:1): '<fieldset><legend>'.&mt('Custom items sent on launch').'</legend>'.
5175:1): '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5176:1): '<tr><td><span class="LC_nobreak">'.
5177:1): '<label><input type="checkbox" name="ltitools_add_custom" value="1" />'.
5178:1): &mt('Add').'</label></span></td><td><input type="text" name="ltitools_add_custom_name" />'.
5179:1): '</td><td><input type="text" name="ltitools_add_custom_value" /></td></tr>'.
5180:1): '</table></fieldset>'."\n".
5181:1): '</td>'."\n".
5182:1): '</tr>'."\n";
5183:1): $itemcount ++;
5184:1): return $datatable;
5185:1): }
5186:1):
5187:1): sub ltitools_names {
5188:1): my %lt = &Apache::lonlocal::texthash(
5189:1): 'title' => 'Title',
5190:1): 'version' => 'Version',
5191:1): 'msgtype' => 'Message Type',
5192:1): 'sigmethod' => 'Signature Method',
5193:1): 'url' => 'URL',
5194:1): 'key' => 'Key',
5195:1): 'lifetime' => 'Nonce lifetime (s)',
5196:1): 'secret' => 'Secret',
5197:1): 'icon' => 'Icon',
5198:1): 'user' => 'User',
5199:1): 'fullname' => 'Full Name',
5200:1): 'firstname' => 'First Name',
5201:1): 'lastname' => 'Last Name',
5202:1): 'email' => 'E-mail',
5203:1): 'roles' => 'Role',
5204:1): 'window' => 'Window',
5205:1): 'tab' => 'Tab',
5206:1): 'iframe' => 'iFrame',
5207:1): 'height' => 'Height',
5208:1): 'width' => 'Width',
5209:1): 'linktext' => 'Default Link Text',
5210:1): 'explanation' => 'Default Explanation',
5211:1): 'crstarget' => 'Display target',
5212:1): 'crslabel' => 'Course label',
5213:1): 'crstitle' => 'Course title',
5214:1): 'crslinktext' => 'Link Text',
5215:1): 'crsexplanation' => 'Explanation',
5216:1): 'crsappend' => 'Provider URL',
5217:1): );
5218:1):
5219:1): return %lt;
5220:1): }
5221:1):
5(raebur 5222:2): sub print_lti {
5223:2): my ($position,$dom,$settings,$rowtotal) = @_;
5224:2): my $itemcount = 1;
5225:2): my ($datatable,$css_class);
5226:2): my (%rules,%encrypt,%privkeys,%linkprot);
5227:2): if (ref($settings) eq 'HASH') {
5228:2): if ($position eq 'top') {
5229:2): if (exists($settings->{'encrypt'})) {
5230:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5231:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5232:2): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5233:2): }
5234:2): }
5235:2): }
5236:2): if (exists($settings->{'private'})) {
5237:2): if (ref($settings->{'private'}) eq 'HASH') {
5238:2): if (ref($settings->{'private'}) eq 'HASH') {
5239:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5240:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5241:2): }
5242:2): }
5243:2): }
5244:2): }
5245:2): } elsif ($position eq 'middle') {
5246:2): if (exists($settings->{'rules'})) {
5247:2): if (ref($settings->{'rules'}) eq 'HASH') {
5248:2): %rules = %{$settings->{'rules'}};
5249:2): }
5250:2): }
5251:2): } elsif ($position eq 'bottom') {
5252:2): if (exists($settings->{'linkprot'})) {
5253:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5254:2): %linkprot = %{$settings->{'linkprot'}};
5255:2): if ($linkprot{'lock'}) {
5256:2): delete($linkprot{'lock'});
5257:2): }
5258:2): }
5259:2): }
5260:2): }
5261:2): }
5262:2): if ($position eq 'top') {
5263:2): my @ids=&Apache::lonnet::current_machine_ids();
5264:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
5265:2): my $primary = &Apache::lonnet::domain($dom,'primary');
5266:2): my ($extra,$numshown);
5267:2): foreach my $hostid (sort(keys(%servers))) {
5268:2): my ($showextra,$divsty,$switch);
5269:2): if ($hostid eq $primary) {
5270:2): if ($encrypt{'ltisec_domlinkprot'}) {
5271:2): $showextra = 1;
5272:2): }
5273:2): }
5274:2): if ($encrypt{'ltisec_crslinkprot'}) {
5275:2): $showextra = 1;
5276:2): }
5277:2): unless (grep(/^\Q$hostid\E$/,@ids)) {
5278:2): $switch = 1;
5279:2): }
5280:2): if ($showextra) {
5281:2): $numshown ++;
5282:2): $divsty = 'display:inline-block';
5283:2): } else {
5284:2): $divsty = 'display:none';
5285:2): }
5286:2): $extra .= '<fieldset id="ltisec_info_'.$hostid.'" style="'.$divsty.'">'.
5287:2): '<legend>'.$hostid.'</legend>';
5288:2): if ($switch) {
5289:2): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5290:2): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5291:2): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5292:2): if (exists($privkeys{$hostid})) {
5293:2): $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5294:2): '<span class="LC_nobreak">'.
5295:2): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5296:2): '<span class="LC_nobreak">'.&mt('Change?').
5297:2): '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5298:2): (' 'x2).
5299:2): '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5300:2): '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5301:2): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5302:2): '</span></div>';
5303:2): } else {
5304:2): $extra .= '<span class="LC_nobreak">'.
5305:2): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5306:2): '</span>'."\n";
5307:2): }
5308:2): } elsif (exists($privkeys{$hostid})) {
5309:2): $extra .= '<div id="ltisec_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5310:2): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5311:2): '<span class="LC_nobreak">'.&mt('Change?').
5312:2): '<label><input type="radio" value="0" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5313:2): (' 'x2).
5314:2): '<label><input type="radio" value="1" name="ltisec_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$hostid'".');" />'.&mt('Yes').
5315:2): '</label> </span><div id="ltisec_divchgprivkey_'.$hostid.'" style="display:none" />'.
5316:2): '<span class="LC_nobreak">'.&mt('New Key').':'.
5317:2): '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5318: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>'.
5319:2): '</span></div>';
5320:2): } else {
5321:2): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5322:2): '<input type="password" size="20" name="ltisec_privkey_'.$hostid.'" value="" autocomplete="off" />'.
5323: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>';
5324:2): }
5325:2): $extra .= '</fieldset>';
5326:2): }
5327:2): my %choices = &Apache::lonlocal::texthash (
5328:2): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5329:2): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5330:2): );
5331:2): my @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot);
5332:2): my %defaultchecked = (
5333:2): 'ltisec_crslinkprot' => 'off',
5334:2): 'ltisec_domlinkprot' => 'off',
5335:2): );
5336:2): my ($onclick,$itemcount);
5337:2): $onclick = 'javascript:toggleLTIEncKey(this.form);';
5338:2): ($datatable,$itemcount) = &radiobutton_prefs(\%encrypt,\@toggles,\%defaultchecked,
5339:2): \%choices,$itemcount,$onclick,'','left','no');
5340:2):
5341:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5342:2): my $noprivkeysty = 'display:inline-block';
5343:2): if ($numshown) {
5344:2): $noprivkeysty = 'display:none';
5345:2): }
5346:2): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5347:2): '<td><div id="ltisec_noprivkey" style="'.$noprivkeysty.'" >'.
5348:2): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5349:2): $extra.
5350:2): '</td></tr>';
5351:2): $itemcount ++;
5352:2): $$rowtotal += $itemcount;
5353:2): } elsif ($position eq 'middle') {
5354:2): $datatable = &password_rules('secrets',\$itemcount,\%rules);
5355:2): $$rowtotal += $itemcount;
5356:2): } elsif ($position eq 'bottom') {
5357:2): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
5358:2): }
5359:2): return $datatable;
5360:2): }
5361:2):
1.121 raeburn 5362: sub print_coursedefaults {
1.139 raeburn 5363: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5364: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5365: my $itemcount = 1;
1.160.6.16 raeburn 5366: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 5367: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.16 raeburn 5368: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5369: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 5370: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5371: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 5372: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 5373: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 5374: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 5375: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 5376: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 5377:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
7(raebur 5378:2): );
1.160.6.21 raeburn 5379: my %staticdefaults = (
5380: anonsurvey_threshold => 10,
5381: uploadquota => 500,
1.160.6.57 raeburn 5382: postsubmit => 60,
1.160.6.70 raeburn 5383: mysqltables => 172800,
1.160.6.21 raeburn 5384: );
1.139 raeburn 5385: if ($position eq 'top') {
1.160.6.57 raeburn 5386: %defaultchecked = (
5387: 'uselcmath' => 'on',
5388: 'usejsme' => 'on',
1.160.6.115 raeburn 5389: 'inline_chem' => 'on',
1.160.6.64 raeburn 5390: 'canclone' => 'none',
1.160.6.57 raeburn 5391: );
1.160.6.115 raeburn 5392: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 5393: my $deftex = $Apache::lonnet::deftex;
5394: if (ref($settings) eq 'HASH') {
5395: if ($settings->{'texengine'}) {
5396: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5397: $deftex = $settings->{'texengine'};
5398: }
5399: }
5400: }
5401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5402: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5403: '<span class="LC_nobreak">'.$choices{'texengine'}.
5404: '</span></td><td class="LC_right_item">'.
5405: '<select name="texengine">'."\n";
5406: my %texoptions = (
5407: MathJax => 'MathJax',
5408: mimetex => &mt('Convert to Images'),
5409: tth => &mt('TeX to HTML'),
5410: );
5411: foreach my $renderer ('MathJax','mimetex','tth') {
5412: my $selected = '';
5413: if ($renderer eq $deftex) {
5414: $selected = ' selected="selected"';
5415: }
5416: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5417: }
5418: $mathdisp .= '</select></td></tr>'."\n";
5419: $itemcount ++;
1.139 raeburn 5420: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5421: \%choices,$itemcount);
1.160.6.90 raeburn 5422: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 5423: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5424: $datatable .=
5425: '<tr'.$css_class.'><td valign="top">'.
5426: '<span class="LC_nobreak">'.$choices{'canclone'}.
5427: '</span></td><td class="LC_left_item">';
5428: my $currcanclone = 'none';
5429: my $onclick;
5430: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 5431: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 5432: none => 'No additional course requesters',
5433: domain => "Any course requester in course's domain",
5434: instcode => 'Course requests for official courses ...',
5435: );
5436: my (%codedefaults,@code_order,@posscodes);
5437: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5438: \@code_order) eq 'ok') {
5439: if (@code_order > 0) {
5440: push(@cloneoptions,'instcode');
5441: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
5442: }
5443: }
5444: if (ref($settings) eq 'HASH') {
5445: if ($settings->{'canclone'}) {
5446: if (ref($settings->{'canclone'}) eq 'HASH') {
5447: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
5448: if (@code_order > 0) {
5449: $currcanclone = 'instcode';
5450: @posscodes = @{$settings->{'canclone'}{'instcode'}};
5451: }
5452: }
5453: } elsif ($settings->{'canclone'} eq 'domain') {
5454: $currcanclone = $settings->{'canclone'};
5455: }
5456: }
5457: }
5458: foreach my $option (@cloneoptions) {
5459: my ($checked,$additional);
5460: if ($currcanclone eq $option) {
5461: $checked = ' checked="checked"';
5462: }
5463: if ($option eq 'instcode') {
5464: if (@code_order) {
5465: my $show = 'none';
5466: if ($checked) {
5467: $show = 'block';
5468: }
5469: $additional = '<div id="cloneinstcode" style="display:'.$show.'" />'.
5470: &mt('Institutional codes for new and cloned course have identical:').
5471: '<br />';
5472: foreach my $item (@code_order) {
5473: my $codechk;
5474: if ($checked) {
5475: if (grep(/^\Q$item\E$/,@posscodes)) {
5476: $codechk = ' checked="checked"';
5477: }
5478: }
5479: $additional .= '<label>'.
5480: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
5481: $item.'</label>';
5482: }
5483: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
5484: }
5485: }
5486: $datatable .=
5487: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
5488: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
5489: '</label> '.$additional.'</span><br />';
5490: }
5491: $datatable .= '</td>'.
5492: '</tr>';
5493: $itemcount ++;
1.139 raeburn 5494: } else {
5495: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.71 raeburn 5496: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.160.6.16 raeburn 5497: my $currusecredits = 0;
1.160.6.57 raeburn 5498: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 5499:2): my $ltiauth = 0;
1.160.6.30 raeburn 5500: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 5501: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 5502:2): if ($settings->{'ltiauth'}) {
5503:2): $ltiauth = 1;
5504:2): }
1.139 raeburn 5505: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 5506: if (ref($settings->{'uploadquota'}) eq 'HASH') {
5507: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
5508: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
5509: }
5510: }
1.160.6.16 raeburn 5511: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 5512: foreach my $type (@types) {
5513: next if ($type eq 'community');
5514: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
5515: if ($defcredits{$type} ne '') {
5516: $currusecredits = 1;
5517: }
5518: }
5519: }
5520: if (ref($settings->{'postsubmit'}) eq 'HASH') {
5521: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
5522: $postsubmitclient = 0;
5523: foreach my $type (@types) {
5524: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5525: }
5526: } else {
5527: foreach my $type (@types) {
5528: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
5529: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
5530: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
5531: } else {
5532: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5533: }
5534: } else {
5535: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5536: }
5537: }
5538: }
5539: } else {
5540: foreach my $type (@types) {
5541: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 5542: }
5543: }
1.160.6.70 raeburn 5544: if (ref($settings->{'mysqltables'}) eq 'HASH') {
5545: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
5546: $currmysql{$type} = $settings->{'mysqltables'}{$type};
5547: }
5548: } else {
5549: foreach my $type (@types) {
5550: $currmysql{$type} = $staticdefaults{'mysqltables'};
5551: }
5552: }
1.160.6.58 raeburn 5553: } else {
5554: foreach my $type (@types) {
5555: $deftimeout{$type} = $staticdefaults{'postsubmit'};
5556: }
1.139 raeburn 5557: }
5558: if (!$currdefresponder) {
1.160.6.21 raeburn 5559: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 5560: } elsif ($currdefresponder < 1) {
5561: $currdefresponder = 1;
5562: }
1.160.6.21 raeburn 5563: foreach my $type (@types) {
5564: if ($curruploadquota{$type} eq '') {
5565: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
5566: }
5567: }
1.139 raeburn 5568: $datatable .=
1.160.6.16 raeburn 5569: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5570: $choices{'anonsurvey_threshold'}.
1.139 raeburn 5571: '</span></td>'.
5572: '<td class="LC_right_item"><span class="LC_nobreak">'.
5573: '<input type="text" name="anonsurvey_threshold"'.
5574: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 5575: '</td></tr>'."\n";
5576: $itemcount ++;
5577: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5578: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5579: $choices{'uploadquota'}.
5580: '</span></td>'.
5581: '<td align="right" class="LC_right_item">'.
5582: '<table><tr>';
1.160.6.21 raeburn 5583: foreach my $type (@types) {
5584: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5585: '<input type="text" name="uploadquota_'.$type.'"'.
5586: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
5587: }
5588: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 5589: $itemcount ++;
1.160.6.40 raeburn 5590: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 5591: my $display = 'none';
5592: if ($currusecredits) {
5593: $display = 'block';
5594: }
5595: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 5596: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
5597: foreach my $type (@types) {
5598: next if ($type eq 'community');
5599: $additional .= '<td align="center">'.&mt($type).'<br />'.
5600: '<input type="text" name="'.$type.'_credits"'.
5601: ' value="'.$defcredits{$type}.'" size="3" /></td>';
5602: }
5603: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 5604: %defaultchecked = ('coursecredits' => 'off');
5605: @toggles = ('coursecredits');
5606: my $current = {
5607: 'coursecredits' => $currusecredits,
5608: };
5609: (my $table,$itemcount) =
5610: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5611: \%choices,$itemcount,$onclick,$additional,'left');
5612: $datatable .= $table;
5613: $onclick = "toggleDisplay(this.form,'studentsubmission');";
5614: my $display = 'none';
5615: if ($postsubmitclient) {
5616: $display = 'block';
5617: }
5618: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 5619: &mt('Number of seconds submit is disabled').'<br />'.
5620: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
5621: '<table><tr>';
1.160.6.57 raeburn 5622: foreach my $type (@types) {
5623: $additional .= '<td align="center">'.&mt($type).'<br />'.
5624: '<input type="text" name="'.$type.'_timeout" value="'.
5625: $deftimeout{$type}.'" size="5" /></td>';
5626: }
5627: $additional .= '</tr></table></div>'."\n";
5628: %defaultchecked = ('postsubmit' => 'on');
5629: @toggles = ('postsubmit');
1.160.6.70 raeburn 5630: $current = {
5631: 'postsubmit' => $postsubmitclient,
5632: };
1.160.6.57 raeburn 5633: ($table,$itemcount) =
5634: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5635: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 5636: $datatable .= $table;
1.160.6.70 raeburn 5637: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5638: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5639: $choices{'mysqltables'}.
5640: '</span></td>'.
5641: '<td align="right" class="LC_right_item">'.
5642: '<table><tr>';
5643: foreach my $type (@types) {
5644: $datatable .= '<td align="center">'.&mt($type).'<br />'.
5645: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 5646: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 5647: }
5648: $datatable .= '</tr></table></td></tr>'."\n";
5649: $itemcount ++;
1.160.6.118.2 4(raebur 5650:2): %defaultchecked = ('ltiauth' => 'off');
5651:2): @toggles = ('ltiauth');
5652:2): $current = {
5653:2): 'ltiauth' => $ltiauth,
5654:2): };
5655:2): ($table,$itemcount) =
5656:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
5657:2): \%choices,$itemcount,undef,undef,'left');
5658:2): $datatable .= $table;
5659:2): $itemcount ++;
1.160.6.37 raeburn 5660: }
5661: $$rowtotal += $itemcount;
5662: return $datatable;
5663: }
5664:
5665: sub print_selfenrollment {
5666: my ($position,$dom,$settings,$rowtotal) = @_;
5667: my ($css_class,$datatable);
5668: my $itemcount = 1;
5669: my @types = ('official','unofficial','community','textbook');
5670: if (($position eq 'top') || ($position eq 'middle')) {
5671: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
5672: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
5673: my @rows;
5674: my $key;
5675: if ($position eq 'top') {
5676: $key = 'admin';
5677: if (ref($rowsref) eq 'ARRAY') {
5678: @rows = @{$rowsref};
5679: }
5680: } elsif ($position eq 'middle') {
5681: $key = 'default';
5682: @rows = ('types','registered','approval','limit');
5683: }
5684: foreach my $row (@rows) {
5685: if (defined($titlesref->{$row})) {
5686: $itemcount ++;
5687: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5688: $datatable .= '<tr'.$css_class.'>'.
5689: '<td>'.$titlesref->{$row}.'</td>'.
5690: '<td class="LC_left_item">'.
5691: '<table><tr>';
5692: my (%current,%currentcap);
5693: if (ref($settings) eq 'HASH') {
5694: if (ref($settings->{$key}) eq 'HASH') {
5695: foreach my $type (@types) {
5696: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5697: $current{$type} = $settings->{$key}->{$type}->{$row};
5698: }
5699: if (($row eq 'limit') && ($key eq 'default')) {
5700: if (ref($settings->{$key}->{$type}) eq 'HASH') {
5701: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
5702: }
5703: }
5704: }
5705: }
5706: }
5707: my %roles = (
5708: '0' => &Apache::lonnet::plaintext('dc'),
5709: );
5710:
5711: foreach my $type (@types) {
5712: unless (($row eq 'registered') && ($key eq 'default')) {
5713: $datatable .= '<th>'.&mt($type).'</th>';
5714: }
5715: }
5716: unless (($row eq 'registered') && ($key eq 'default')) {
5717: $datatable .= '</tr><tr>';
5718: }
5719: foreach my $type (@types) {
5720: if ($type eq 'community') {
5721: $roles{'1'} = &mt('Community personnel');
5722: } else {
5723: $roles{'1'} = &mt('Course personnel');
5724: }
5725: $datatable .= '<td style="vertical-align: top">';
5726: if ($position eq 'top') {
5727: my %checked;
5728: if ($current{$type} eq '0') {
5729: $checked{'0'} = ' checked="checked"';
5730: } else {
5731: $checked{'1'} = ' checked="checked"';
5732: }
5733: foreach my $role ('1','0') {
5734: $datatable .= '<span class="LC_nobreak"><label>'.
5735: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
5736: 'value="'.$role.'"'.$checked{$role}.' />'.
5737: $roles{$role}.'</label></span> ';
5738: }
5739: } else {
5740: if ($row eq 'types') {
5741: my %checked;
5742: if ($current{$type} =~ /^(all|dom)$/) {
5743: $checked{$1} = ' checked="checked"';
5744: } else {
5745: $checked{''} = ' checked="checked"';
5746: }
5747: foreach my $val ('','dom','all') {
5748: $datatable .= '<span class="LC_nobreak"><label>'.
5749: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5750: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5751: }
5752: } elsif ($row eq 'registered') {
5753: my %checked;
5754: if ($current{$type} eq '1') {
5755: $checked{'1'} = ' checked="checked"';
5756: } else {
5757: $checked{'0'} = ' checked="checked"';
5758: }
5759: foreach my $val ('0','1') {
5760: $datatable .= '<span class="LC_nobreak"><label>'.
5761: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5762: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5763: }
5764: } elsif ($row eq 'approval') {
5765: my %checked;
5766: if ($current{$type} =~ /^([12])$/) {
5767: $checked{$1} = ' checked="checked"';
5768: } else {
5769: $checked{'0'} = ' checked="checked"';
5770: }
5771: for my $val (0..2) {
5772: $datatable .= '<span class="LC_nobreak"><label>'.
5773: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
5774: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
5775: }
5776: } elsif ($row eq 'limit') {
5777: my %checked;
5778: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
5779: $checked{$1} = ' checked="checked"';
5780: } else {
5781: $checked{'none'} = ' checked="checked"';
5782: }
5783: my $cap;
5784: if ($currentcap{$type} =~ /^\d+$/) {
5785: $cap = $currentcap{$type};
5786: }
5787: foreach my $val ('none','allstudents','selfenrolled') {
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: $datatable .= '<br />'.
5793: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
5794: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
5795: '</span>';
5796: }
5797: }
5798: $datatable .= '</td>';
5799: }
5800: $datatable .= '</tr>';
5801: }
5802: $datatable .= '</table></td></tr>';
5803: }
5804: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 5805: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
5806: }
5807: $$rowtotal += $itemcount;
5808: return $datatable;
5809: }
5810:
5811: sub print_validation_rows {
5812: my ($caller,$dom,$settings,$rowtotal) = @_;
5813: my ($itemsref,$namesref,$fieldsref);
5814: if ($caller eq 'selfenroll') {
5815: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
5816: } elsif ($caller eq 'requestcourses') {
5817: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
5818: }
5819: my %currvalidation;
5820: if (ref($settings) eq 'HASH') {
5821: if (ref($settings->{'validation'}) eq 'HASH') {
5822: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 5823: }
1.160.6.39 raeburn 5824: }
5825: my $datatable;
5826: my $itemcount = 0;
5827: foreach my $item (@{$itemsref}) {
5828: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
5829: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
5830: $namesref->{$item}.
5831: '</span></td>'.
5832: '<td class="LC_left_item">';
5833: if (($item eq 'url') || ($item eq 'button')) {
5834: $datatable .= '<span class="LC_nobreak">'.
5835: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
5836: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
5837: } elsif ($item eq 'fields') {
5838: my @currfields;
5839: if (ref($currvalidation{$item}) eq 'ARRAY') {
5840: @currfields = @{$currvalidation{$item}};
5841: }
5842: foreach my $field (@{$fieldsref}) {
5843: my $check = '';
5844: if (grep(/^\Q$field\E$/,@currfields)) {
5845: $check = ' checked="checked"';
5846: }
5847: $datatable .= '<span class="LC_nobreak"><label>'.
5848: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
5849: ' value="'.$field.'"'.$check.' />'.$field.
5850: '</label></span> ';
5851: }
5852: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 5853: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 5854: $currvalidation{$item}.
1.160.6.37 raeburn 5855: '</textarea>';
1.160.6.39 raeburn 5856: }
5857: $datatable .= '</td></tr>'."\n";
5858: if (ref($rowtotal)) {
1.160.6.37 raeburn 5859: $itemcount ++;
5860: }
1.139 raeburn 5861: }
1.160.6.39 raeburn 5862: if ($caller eq 'requestcourses') {
5863: my %currhash;
1.160.6.51 raeburn 5864: if (ref($settings) eq 'HASH') {
5865: if (ref($settings->{'validation'}) eq 'HASH') {
5866: if ($settings->{'validation'}{'dc'} ne '') {
5867: $currhash{$settings->{'validation'}{'dc'}} = 1;
5868: }
1.160.6.39 raeburn 5869: }
5870: }
5871: my $numinrow = 2;
5872: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
5873: 'validationdc',%currhash);
1.160.6.50 raeburn 5874: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 5875: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 5876: if ($numdc > 1) {
1.160.6.50 raeburn 5877: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 5878: } else {
1.160.6.50 raeburn 5879: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 5880: }
1.160.6.50 raeburn 5881: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 5882: $itemcount ++;
5883: }
5884: if (ref($rowtotal)) {
5885: $$rowtotal += $itemcount;
5886: }
1.121 raeburn 5887: return $datatable;
1.118 jms 5888: }
5889:
1.160.6.98 raeburn 5890: sub print_passwords {
5891: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
5892: my ($datatable,$css_class);
5893: my $itemcount = 0;
5894: my %titles = &Apache::lonlocal::texthash (
5895: captcha => '"Forgot Password" CAPTCHA validation',
5896: link => 'Reset link expiration (hours)',
5897: case => 'Case-sensitive usernames/e-mail',
5898: prelink => 'Information required (form 1)',
5899: postlink => 'Information required (form 2)',
5900: emailsrc => 'LON-CAPA e-mail address type(s)',
5901: customtext => 'Domain specific text (HTML)',
5902: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
5903: intauth_check => 'Check bcrypt cost if authenticated',
5904: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
5905: permanent => 'Permanent e-mail address',
5906: critical => 'Critical notification address',
5907: notify => 'Notification address',
5908: min => 'Minimum password length',
5909: max => 'Maximum password length',
5910: chars => 'Required characters',
5911: numsaved => 'Number of previous passwords to save and disallow reuse',
5912: );
5913: if ($position eq 'top') {
5914: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
5915: my $shownlinklife = 2;
5916: my $prelink = 'both';
5917: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
5918: if (ref($settings) eq 'HASH') {
5919: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
5920: $shownlinklife = $settings->{resetlink};
5921: }
5922: if (ref($settings->{resetcase}) eq 'ARRAY') {
5923: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
5924: }
5925: if ($settings->{resetprelink} =~ /^(both|either)$/) {
5926: $prelink = $settings->{resetprelink};
5927: }
5928: if (ref($settings->{resetpostlink}) eq 'HASH') {
5929: %postlink = %{$settings->{resetpostlink}};
5930: }
5931: if (ref($settings->{resetemail}) eq 'ARRAY') {
5932: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
5933: }
5934: if ($settings->{resetremove}) {
5935: $nostdtext = 1;
5936: }
5937: if ($settings->{resetcustom}) {
5938: $customurl = $settings->{resetcustom};
5939: }
5940: } else {
5941: if (ref($types) eq 'ARRAY') {
5942: foreach my $item (@{$types}) {
5943: $casesens{$item} = 1;
5944: $postlink{$item} = ['username','email'];
5945: }
5946: }
5947: $casesens{'default'} = 1;
5948: $postlink{'default'} = ['username','email'];
5949: $prelink = 'both';
5950: %emailsrc = (
5951: permanent => 1,
5952: critical => 1,
5953: notify => 1,
5954: );
5955: }
5956: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
5957: $itemcount ++;
5958: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5959: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
5960: '<td class="LC_left_item">'.
5961: '<input type="textbox" value="'.$shownlinklife.'" '.
5962: 'name="passwords_link" size="3" /></td></tr>';
5963: $itemcount ++;
5964: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5965: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
5966: '<td class="LC_left_item">';
5967: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
5968: foreach my $item (@{$types}) {
5969: my $checkedcase;
5970: if ($casesens{$item}) {
5971: $checkedcase = ' checked="checked"';
5972: }
5973: $datatable .= '<span class="LC_nobreak"><label>'.
5974: '<input type="checkbox" name="passwords_case_sensitive" value="'.
5975: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 5976: '</span> ';
1.160.6.98 raeburn 5977: }
5978: }
5979: my $checkedcase;
5980: if ($casesens{'default'}) {
5981: $checkedcase = ' checked="checked"';
5982: }
5983: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
5984: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
5985: $othertitle.'</label></span></td>';
5986: $itemcount ++;
5987: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5988: my %checkedpre = (
5989: both => ' checked="checked"',
5990: either => '',
5991: );
5992: if ($prelink eq 'either') {
5993: $checkedpre{either} = ' checked="checked"';
5994: $checkedpre{both} = '';
5995: }
5996: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
5997: '<td class="LC_left_item"><span class="LC_nobreak">'.
5998: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
5999: &mt('Both username and e-mail address').'</label></span> '.
6000: '<span class="LC_nobreak"><label>'.
6001: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6002: &mt('Either username or e-mail address').'</label></span></td></tr>';
6003: $itemcount ++;
6004: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6005: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6006: '<td class="LC_left_item">';
6007: my %postlinked;
6008: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6009: foreach my $item (@{$types}) {
6010: undef(%postlinked);
6011: $datatable .= '<fieldset style="display: inline-block;">'.
6012: '<legend>'.$usertypes->{$item}.'</legend>';
6013: if (ref($postlink{$item}) eq 'ARRAY') {
6014: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6015: }
6016: foreach my $field ('email','username') {
6017: my $checked;
6018: if ($postlinked{$field}) {
6019: $checked = ' checked="checked"';
6020: }
6021: $datatable .= '<span class="LC_nobreak"><label>'.
6022: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6023: $field.'"'.$checked.' />'.$field.'</label>'.
6024: '<span> ';
6025: }
6026: $datatable .= '</fieldset>';
6027: }
6028: }
6029: if (ref($postlink{'default'}) eq 'ARRAY') {
6030: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6031: }
6032: $datatable .= '<fieldset style="display: inline-block;">'.
6033: '<legend>'.$othertitle.'</legend>';
6034: foreach my $field ('email','username') {
6035: my $checked;
6036: if ($postlinked{$field}) {
6037: $checked = ' checked="checked"';
6038: }
6039: $datatable .= '<span class="LC_nobreak"><label>'.
6040: '<input type="checkbox" name="passwords_postlink_default" value="'.
6041: $field.'"'.$checked.' />'.$field.'</label>'.
6042: '<span> ';
6043: }
6044: $datatable .= '</fieldset></td></tr>';
6045: $itemcount ++;
6046: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6047: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6048: '<td class="LC_left_item">';
6049: foreach my $type ('permanent','critical','notify') {
6050: my $checkedemail;
6051: if ($emailsrc{$type}) {
6052: $checkedemail = ' checked="checked"';
6053: }
6054: $datatable .= '<span class="LC_nobreak"><label>'.
6055: '<input type="checkbox" name="passwords_emailsrc" value="'.
6056: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6057: '<span> ';
6058: }
6059: $datatable .= '</td></tr>';
6060: $itemcount ++;
6061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6062: my $switchserver = &check_switchserver($dom,$confname);
6063: my ($showstd,$noshowstd);
6064: if ($nostdtext) {
6065: $noshowstd = ' checked="checked"';
6066: } else {
6067: $showstd = ' checked="checked"';
6068: }
6069: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6070: '<td class="LC_left_item"><span class="LC_nobreak">'.
6071: &mt('Retain standard text:').
6072: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6073: &mt('Yes').'</label>'.' '.
6074: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6075: &mt('No').'</label></span><br />'.
6076: '<span class="LC_fontsize_small">'.
6077: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6078: &mt('Include custom text:');
6079: if ($customurl) {
1.160.6.104 raeburn 6080: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 6081: undef,undef,undef,undef,'background-color:#ffffff');
6082: $datatable .= '<span class="LC_nobreak"> '.$link.
6083: '<label><input type="checkbox" name="passwords_custom_del"'.
6084: ' value="1" />'.&mt('Delete?').'</label></span>'.
6085: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6086: }
6087: if ($switchserver) {
6088: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6089: } else {
6090: $datatable .='<span class="LC_nobreak"> '.
6091: '<input type="file" name="passwords_customfile" /></span>';
6092: }
6093: $datatable .= '</td></tr>';
6094: } elsif ($position eq 'middle') {
6095: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6096: my @items = ('intauth_cost','intauth_check','intauth_switch');
6097: my %defaults;
6098: if (ref($domconf{'defaults'}) eq 'HASH') {
6099: %defaults = %{$domconf{'defaults'}};
6100: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6101: $defaults{'intauth_cost'} = 10;
6102: }
6103: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6104: $defaults{'intauth_check'} = 0;
6105: }
6106: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6107: $defaults{'intauth_switch'} = 0;
6108: }
6109: } else {
6110: %defaults = (
6111: 'intauth_cost' => 10,
6112: 'intauth_check' => 0,
6113: 'intauth_switch' => 0,
6114: );
6115: }
6116: foreach my $item (@items) {
6117: if ($itemcount%2) {
6118: $css_class = '';
6119: } else {
6120: $css_class = ' class="LC_odd_row" ';
6121: }
6122: $datatable .= '<tr'.$css_class.'>'.
6123: '<td><span class="LC_nobreak">'.$titles{$item}.
6124: '</span></td><td class="LC_left_item" colspan="3">';
6125: if ($item eq 'intauth_switch') {
6126: my @options = (0,1,2);
6127: my %optiondesc = &Apache::lonlocal::texthash (
6128: 0 => 'No',
6129: 1 => 'Yes',
6130: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6131: );
6132: $datatable .= '<table width="100%">';
6133: foreach my $option (@options) {
6134: my $checked = ' ';
6135: if ($defaults{$item} eq $option) {
6136: $checked = ' checked="checked"';
6137: }
6138: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6139: '<label><input type="radio" name="'.$item.
6140: '" value="'.$option.'"'.$checked.' />'.
6141: $optiondesc{$option}.'</label></span></td></tr>';
6142: }
6143: $datatable .= '</table>';
6144: } elsif ($item eq 'intauth_check') {
6145: my @options = (0,1,2);
6146: my %optiondesc = &Apache::lonlocal::texthash (
6147: 0 => 'No',
6148: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6149: 2 => 'Yes, disallow login if stored cost is less than domain default',
6150: );
6151: $datatable .= '<table width="100%">';
6152: foreach my $option (@options) {
6153: my $checked = ' ';
6154: my $onclick;
6155: if ($defaults{$item} eq $option) {
6156: $checked = ' checked="checked"';
6157: }
6158: if ($option == 2) {
6159: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6160: }
6161: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6162: '<label><input type="radio" name="'.$item.
6163: '" value="'.$option.'"'.$checked.$onclick.' />'.
6164: $optiondesc{$option}.'</label></span></td></tr>';
6165: }
6166: $datatable .= '</table>';
6167: } else {
6168: $datatable .= '<input type="text" name="'.$item.'" value="'.
6169: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6170: }
6171: $datatable .= '</td></tr>';
6172: $itemcount ++;
6173: }
6174: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 6175:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 6176: } else {
6177: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6178: my %ownerchg = (
6179: by => {},
6180: for => {},
6181: );
6182: my %ownertitles = &Apache::lonlocal::texthash (
6183: by => 'Course owner status(es) allowed',
6184: for => 'Student status(es) allowed',
6185: );
6186: if (ref($settings) eq 'HASH') {
6187: if (ref($settings->{crsownerchg}) eq 'HASH') {
6188: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6189: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6190: }
6191: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6192: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6193: }
6194: }
6195: }
6196: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6197: $datatable .= '<tr '.$css_class.'>'.
6198: '<td>'.
6199: &mt('Requirements').'<ul>'.
6200: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6201: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6202: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6203: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6204: '</ul>'.
6205: '</td>'.
6206: '<td class="LC_left_item">';
6207: foreach my $item ('by','for') {
6208: $datatable .= '<fieldset style="display: inline-block;">'.
6209: '<legend>'.$ownertitles{$item}.'</legend>';
6210: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6211: foreach my $type (@{$types}) {
6212: my $checked;
6213: if ($ownerchg{$item}{$type}) {
6214: $checked = ' checked="checked"';
6215: }
6216: $datatable .= '<span class="LC_nobreak"><label>'.
6217: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6218: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 6219: '</span> ';
1.160.6.98 raeburn 6220: }
6221: }
6222: my $checked;
6223: if ($ownerchg{$item}{'default'}) {
6224: $checked = ' checked="checked"';
6225: }
6226: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6227: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6228: $othertitle.'</label></span></fieldset>';
6229: }
6230: $datatable .= '</td></tr>';
6231: }
6232: return $datatable;
6233: }
6234:
1.160.6.118.2 5(raebur 6235:2): sub password_rules {
6236:2): my ($prefix,$itemcountref,$settings) = @_;
6237:2): my ($min,$max,%chars,$numsaved,$numinrow);
6238:2): my %titles;
6239:2): if ($prefix eq 'passwords') {
6240:2): %titles = &Apache::lonlocal::texthash (
6241:2): min => 'Minimum password length',
6242:2): max => 'Maximum password length',
6243:2): chars => 'Required characters',
6244:2): );
6245:2): } elsif ($prefix eq 'secrets') {
6246:2): %titles = &Apache::lonlocal::texthash (
6247:2): min => 'Minimum secret length',
6248:2): max => 'Maximum secret length',
6249:2): chars => 'Required characters',
6250:2): );
6251:2): }
6252:2): $min = $Apache::lonnet::passwdmin;
6253:2): my $datatable;
6254:2): my $itemcount;
6255:2): if (ref($itemcountref)) {
6256:2): $itemcount = $$itemcountref;
6257:2): }
6258:2): if (ref($settings) eq 'HASH') {
6259:2): if ($settings->{min}) {
6260:2): $min = $settings->{min};
6261:2): }
6262:2): if ($settings->{max}) {
6263:2): $max = $settings->{max};
6264:2): }
6265:2): if (ref($settings->{chars}) eq 'ARRAY') {
6266:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
6267:2): }
6268:2): if ($prefix eq 'passwords') {
6269:2): if ($settings->{numsaved}) {
6270:2): $numsaved = $settings->{numsaved};
6271:2): }
6272:2): }
6273:2): }
6274:2): my %rulenames = &Apache::lonlocal::texthash(
6275:2): uc => 'At least one upper case letter',
6276:2): lc => 'At least one lower case letter',
6277:2): num => 'At least one number',
6278:2): spec => 'At least one non-alphanumeric',
6279:2): );
6280:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6281:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6282:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6283:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6284:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6285:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
6286:2): '</span></td></tr>';
6287:2): $itemcount ++;
6288:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6289:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6290:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6291:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
6292:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6293:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6294:2): '</span></td></tr>';
6295:2): $itemcount ++;
6296:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6297:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6298:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6299:2): '</span></td>';
6300:2): my $numinrow = 2;
6301:2): my @possrules = ('uc','lc','num','spec');
6302:2): $datatable .= '<td class="LC_left_item"><table>';
6303:2): for (my $i=0; $i<@possrules; $i++) {
6304:2): my ($rem,$checked);
6305:2): if ($chars{$possrules[$i]}) {
6306:2): $checked = ' checked="checked"';
6307:2): }
6308:2): $rem = $i%($numinrow);
6309:2): if ($rem == 0) {
6310:2): if ($i > 0) {
6311:2): $datatable .= '</tr>';
6312:2): }
6313:2): $datatable .= '<tr>';
6314:2): }
6315:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
6316:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6317:2): $rulenames{$possrules[$i]}.'</label></span></td>';
6318:2): }
6319:2): my $rem = @possrules%($numinrow);
6320:2): my $colsleft = $numinrow - $rem;
6321:2): if ($colsleft > 1 ) {
6322:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6323:2): ' </td>';
6324:2): } elsif ($colsleft == 1) {
6325:2): $datatable .= '<td class="LC_left_item"> </td>';
6326:2): }
6327:2): $datatable .='</table></td></tr>';
6328:2): $itemcount ++;
6329:2): if ($prefix eq 'passwords') {
6330:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
6331:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6332:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6333:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6334:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
6335:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6336:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6337:2): '</span></td></tr>';
6338:2): $itemcount ++;
6339:2): }
6340:2): if (ref($itemcountref)) {
6341:2): $$itemcountref += $itemcount;
6342:2): }
6343:2): return $datatable;
6344:2): }
6345:2):
1.160.6.113 raeburn 6346: sub print_wafproxy {
6347: my ($position,$dom,$settings,$rowtotal) = @_;
6348: my $css_class;
6349: my $itemcount = 0;
6350: my $datatable;
6351: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6352: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6353: my %lt = &wafproxy_titles();
6354: foreach my $server (sort(keys(%servers))) {
6355: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6356: next if ($serverhome eq '');
6357: my $serverdom;
6358: if ($serverhome ne $server) {
6359: $serverdom = &Apache::lonnet::host_domain($serverhome);
6360: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6361: $othercontrol{$server} = $serverdom;
6362: }
6363: } else {
6364: $serverdom = &Apache::lonnet::host_domain($server);
6365: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
6366: if ($serverdom ne $dom) {
6367: $othercontrol{$server} = $serverdom;
6368: } else {
6369: $setdom = 1;
6370: if (ref($settings) eq 'HASH') {
6371: if (ref($settings->{'alias'}) eq 'HASH') {
6372: $aliases{$dom} = $settings->{'alias'};
6373: if ($aliases{$dom} ne '') {
6374: $showdom = 1;
6375: }
6376: }
6377: if (ref($settings->{'saml'}) eq 'HASH') {
6378: $saml{$dom} = $settings->{'saml'};
6379: }
6380: }
6381: }
6382: }
6383: }
6384: if ($setdom) {
6385: %{$values{$dom}} = ();
6386: if (ref($settings) eq 'HASH') {
6387: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6388: $values{$dom}{$item} = $settings->{$item};
6389: }
6390: }
6391: }
6392: if (keys(%othercontrol)) {
6393: %otherdoms = reverse(%othercontrol);
6394: foreach my $domain (keys(%otherdoms)) {
6395: %{$values{$domain}} = ();
6396: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
6397: if (ref($config{'wafproxy'}) eq 'HASH') {
6398: $aliases{$domain} = $config{'wafproxy'}{'alias'};
6399: if (exists($config{'wafproxy'}{'saml'})) {
6400: $saml{$domain} = $config{'wafproxy'}{'saml'};
6401: }
6402: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
6403: $values{$domain}{$item} = $config{'wafproxy'}{$item};
6404: }
6405: }
6406: }
6407: }
6408: if ($position eq 'top') {
6409: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6410: my %aliasinfo;
6411: foreach my $server (sort(keys(%servers))) {
6412: $itemcount ++;
6413: my $dom_in_effect;
6414: my $aliasrows = '<tr>'.
6415: '<td class="LC_left_item" style="vertical-align: baseline;">'.
6416: &mt('Hostname').': '.
6417: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
6418: if ($othercontrol{$server}) {
6419: $dom_in_effect = $othercontrol{$server};
6420: my ($current,$forsaml);
6421: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
6422: $current = $aliases{$dom_in_effect}{$server};
6423: }
6424: if (ref($saml{$dom_in_effect}) eq 'HASH') {
6425: if ($saml{$dom_in_effect}{$server}) {
6426: $forsaml = 1;
6427: }
6428: }
6429: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6430: &mt('Alias').': ';
6431: if ($current) {
6432: $aliasrows .= $current;
6433: if ($forsaml) {
6434: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
6435: }
6436: } else {
6437: $aliasrows .= &mt('None');
6438: }
6439: $aliasrows .= ' <span class="LC_small">('.
6440: &mt('controlled by domain: [_1]',
6441: '<b>'.$dom_in_effect.'</b>').')</span></td>';
6442: } else {
6443: $dom_in_effect = $dom;
6444: my ($current,$samlon,$samloff);
6445: $samloff = ' checked="checked"';
6446: if (ref($aliases{$dom}) eq 'HASH') {
6447: if ($aliases{$dom}{$server}) {
6448: $current = $aliases{$dom}{$server};
6449: }
6450: }
6451: if (ref($saml{$dom}) eq 'HASH') {
6452: if ($saml{$dom}{$server}) {
6453: $samlon = $samloff;
6454: undef($samloff);
6455: }
6456: }
6457: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
6458: &mt('Alias').': '.
6459: '<input type="text" name="wafproxy_alias_'.$server.'" '.
6460: 'value="'.$current.'" size="30" />'.
6461: (' 'x2).'<span class="LC_nobreak">'.
6462: &mt('Alias used for SSO Auth').': <label>'.
6463: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
6464: &mt('No').'</label> <label>'.
6465: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
6466: &mt('Yes').'</label></span>'.
6467: '</td>';
6468: }
6469: $aliasrows .= '</tr>';
6470: $aliasinfo{$dom_in_effect} .= $aliasrows;
6471: }
6472: if ($aliasinfo{$dom}) {
6473: my ($onclick,$wafon,$wafoff,$showtable);
6474: $onclick = ' onclick="javascript:toggleWAF();"';
6475: $wafoff = ' checked="checked"';
6476: $showtable = ' style="display:none";';
6477: if ($showdom) {
6478: $wafon = $wafoff;
6479: $wafoff = '';
6480: $showtable = ' style="display:inline;"';
6481: }
6482: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6483: $datatable = '<tr'.$css_class.'>'.
6484: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
6485: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
6486: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
6487: &mt('Yes').'</label>'.(' 'x2).'<label>'.
6488: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
6489: &mt('No').'</label></span></td>'.
6490: '<td class="LC_left_item">'.
6491: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
6492: '</table></td></tr>';
6493: $itemcount++;
6494: }
6495: if (keys(%otherdoms)) {
6496: foreach my $key (sort(keys(%otherdoms))) {
6497: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6498: $datatable .= '<tr'.$css_class.'>'.
6499: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
6500: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
6501: '</table></td></tr>';
6502: $itemcount++;
6503: }
6504: }
6505: } else {
6506: my %ip_methods = &remoteip_methods();
6507: if ($setdom) {
6508: $itemcount ++;
6509: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6510: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
6511: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
6512: $wafstyle = ' style="display:none;"';
6513: $nowafstyle = ' style="display:table-row;"';
6514: $currwafdisplay = ' style="display: none"';
6515: $wafrangestyle = ' style="display: none"';
6516: $curr_remotip = 'n';
6517: $ssltossl = ' checked="checked"';
6518: if ($showdom) {
6519: $wafstyle = ' style="display:table-row;"';
6520: $nowafstyle = ' style="display:none;"';
6521: if (keys(%{$values{$dom}})) {
6522: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
6523: $curr_remotip = $values{$dom}{remoteip};
6524: }
6525: if ($curr_remotip eq 'h') {
6526: $currwafdisplay = ' style="display:table-row"';
6527: $wafrangestyle = ' style="display:inline-block;"';
6528: }
6529: if ($values{$dom}{'sslopt'}) {
6530: $alltossl = ' checked="checked"';
6531: $ssltossl = '';
6532: }
6533: }
6534: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
6535: $vpndircheck = ' checked="checked"';
6536: $currwafvpn = ' style="display:table-row;"';
6537: $wafrangestyle = ' style="display:inline-block;"';
6538: } else {
6539: $vpnaliascheck = ' checked="checked"';
6540: $currwafvpn = ' style="display:none;"';
6541: }
6542: }
6543: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6544: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
6545: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
6546: '</tr>'.
6547: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
6548: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
6549: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
6550: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
6551: &mt('Range(s) stored in CIDR notation').'</div></td>'.
6552: '<td class="LC_left_item"><table>'.
6553: '<tr>'.
6554: '<td valign="top">'.$lt{'remoteip'}.': '.
6555: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
6556: foreach my $option ('m','h','n') {
6557: my $sel;
1.160.6.114 raeburn 6558: if ($option eq $curr_remotip) {
6559: $sel = ' selected="selected"';
6560: }
6561: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
6562: $ip_methods{$option}.'</option>';
6563: }
6564: $datatable .= '</select></td></tr>'."\n".
6565: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
6566: $lt{'ipheader'}.': '.
6567: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
6568: 'name="wafproxy_ipheader" />'.
6569: '</td></tr>'."\n".
6570: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
6571: $lt{'trusted'}.':<br />'.
6572: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
6573: $values{$dom}{'trusted'}.'</textarea>'.
6574: '</td></tr>'."\n".
6575: '<tr><td><hr /></td></tr>'."\n".
6576: '<tr>'.
1.160.6.113 raeburn 6577: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
6578: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
6579: $lt{'vpndirect'}.'</label>'.(' 'x2).
6580: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
6581: $lt{'vpnaliased'}.'</label></span></td></tr>';
6582: foreach my $item ('vpnint','vpnext') {
6583: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
6584: '<td valign="top">'.$lt{$item}.':<br />'.
6585: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
6586: $values{$dom}{$item}.'</textarea>'.
6587: '</td></tr>'."\n";
6588: }
6589: $datatable .= '<tr><td><hr /></td></tr>'."\n".
6590: '<tr>'.
6591: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
6592: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
6593: $lt{'alltossl'}.'</label>'.(' 'x2).
6594: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
6595: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
6596: '</table></td></tr>';
6597: }
6598: if (keys(%otherdoms)) {
6599: foreach my $domain (sort(keys(%otherdoms))) {
6600: $itemcount ++;
6601: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6602: $datatable .= '<tr'.$css_class.'>'.
6603: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
6604: '<td class="LC_left_item"><table>';
6605: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
6606: my $showval = &mt('None');
6607: if ($item eq 'ssl') {
6608: $showval = $lt{'ssltossl'};
6609: }
6610: if ($values{$domain}{$item}) {
6611: $showval = $values{$domain}{$item};
6612: if ($item eq 'ssl') {
6613: $showval = $lt{'alltossl'};
6614: } elsif ($item eq 'remoteip') {
6615: $showval = $ip_methods{$values{$domain}{$item}};
6616: }
6617: }
6618: $datatable .= '<tr>'.
6619: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
6620: }
6621: $datatable .= '</table></td></tr>';
6622: }
6623: }
6624: }
6625: $$rowtotal += $itemcount;
6626: return $datatable;
6627: }
6628:
6629: sub wafproxy_titles {
6630: return &Apache::lonlocal::texthash(
6631: remoteip => "Method for determining user's IP",
6632: ipheader => 'Request header containing remote IP',
6633: trusted => 'Trusted IP range(s)',
6634: vpnaccess => 'Access from institutional VPN',
6635: vpndirect => 'via regular hostname (no WAF)',
6636: vpnaliased => 'via aliased hostname (WAF)',
6637: vpnint => 'Internal IP Range(s) for VPN sessions',
6638: vpnext => 'IP Range(s) for backend WAF connections',
6639: sslopt => 'Forwarding http/https',
6640: alltossl => 'WAF forwards both http and https requests to https',
6641: ssltossl => 'WAF forwards http requests to http and https to https',
6642: );
6643: }
6644:
6645: sub remoteip_methods {
6646: return &Apache::lonlocal::texthash(
6647: m => 'Use Apache mod_remoteip',
6648: h => 'Use headers parsed by LON-CAPA',
6649: n => 'Not in use',
6650: );
6651: }
6652:
1.137 raeburn 6653: sub print_usersessions {
6654: my ($position,$dom,$settings,$rowtotal) = @_;
6655: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 6656: my (%by_ip,%by_location,@intdoms);
6657: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 6658:
6659: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 6660: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 6661: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 6662: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 6663: my $itemcount = 1;
6664: if ($position eq 'top') {
1.152 raeburn 6665: if (keys(%serverhomes) > 1) {
1.145 raeburn 6666: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 6667: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 6668: if (ref($settings) eq 'HASH') {
6669: if (ref($settings->{'offloadnow'}) eq 'HASH') {
6670: $curroffloadnow = $settings->{'offloadnow'};
6671: }
1.160.6.105 raeburn 6672: if (ref($settings->{'offloadoth'}) eq 'HASH') {
6673: $curroffloadoth = $settings->{'offloadoth'};
6674: }
1.160.6.61 raeburn 6675: }
1.160.6.105 raeburn 6676: my $other_insts = scalar(keys(%by_location));
6677: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
6678: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 6679: } else {
1.140 raeburn 6680: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6681: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 6682: }
1.137 raeburn 6683: } else {
1.145 raeburn 6684: if (keys(%by_location) == 0) {
6685: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 6686: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 6687: } else {
6688: my %lt = &usersession_titles();
6689: my $numinrow = 5;
6690: my $prefix;
6691: my @types;
6692: if ($position eq 'bottom') {
6693: $prefix = 'remote';
6694: @types = ('version','excludedomain','includedomain');
6695: } else {
6696: $prefix = 'hosted';
6697: @types = ('excludedomain','includedomain');
6698: }
6699: my (%current,%checkedon,%checkedoff);
6700: my @lcversions = &Apache::lonnet::all_loncaparevs();
6701: my @locations = sort(keys(%by_location));
6702: foreach my $type (@types) {
6703: $checkedon{$type} = '';
6704: $checkedoff{$type} = ' checked="checked"';
6705: }
6706: if (ref($settings) eq 'HASH') {
6707: if (ref($settings->{$prefix}) eq 'HASH') {
6708: foreach my $key (keys(%{$settings->{$prefix}})) {
6709: $current{$key} = $settings->{$prefix}{$key};
6710: if ($key eq 'version') {
6711: if ($current{$key} ne '') {
6712: $checkedon{$key} = ' checked="checked"';
6713: $checkedoff{$key} = '';
6714: }
6715: } elsif (ref($current{$key}) eq 'ARRAY') {
6716: $checkedon{$key} = ' checked="checked"';
6717: $checkedoff{$key} = '';
6718: }
1.137 raeburn 6719: }
6720: }
6721: }
1.145 raeburn 6722: foreach my $type (@types) {
6723: next if ($type ne 'version' && !@locations);
6724: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6725: $datatable .= '<tr'.$css_class.'>
6726: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
6727: <span class="LC_nobreak">
6728: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
6729: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
6730: if ($type eq 'version') {
6731: my $selector = '<select name="'.$prefix.'_version">';
6732: foreach my $version (@lcversions) {
6733: my $selected = '';
6734: if ($current{'version'} eq $version) {
6735: $selected = ' selected="selected"';
6736: }
6737: $selector .= ' <option value="'.$version.'"'.
6738: $selected.'>'.$version.'</option>';
6739: }
6740: $selector .= '</select> ';
6741: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
6742: } else {
6743: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
6744: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
6745: ' />'.(' 'x2).
6746: '<input type="button" value="'.&mt('uncheck all').'" '.
6747: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
6748: "\n".
6749: '</div><div><table>';
6750: my $rem;
6751: for (my $i=0; $i<@locations; $i++) {
6752: my ($showloc,$value,$checkedtype);
6753: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
6754: my $ip = $by_location{$locations[$i]}->[0];
6755: if (ref($by_ip{$ip}) eq 'ARRAY') {
6756: $value = join(':',@{$by_ip{$ip}});
6757: $showloc = join(', ',@{$by_ip{$ip}});
6758: if (ref($current{$type}) eq 'ARRAY') {
6759: foreach my $loc (@{$by_ip{$ip}}) {
6760: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
6761: $checkedtype = ' checked="checked"';
6762: last;
6763: }
6764: }
1.138 raeburn 6765: }
6766: }
6767: }
1.145 raeburn 6768: $rem = $i%($numinrow);
6769: if ($rem == 0) {
6770: if ($i > 0) {
6771: $datatable .= '</tr>';
6772: }
6773: $datatable .= '<tr>';
6774: }
6775: $datatable .= '<td class="LC_left_item">'.
6776: '<span class="LC_nobreak"><label>'.
6777: '<input type="checkbox" name="'.$prefix.'_'.$type.
6778: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
6779: '</label></span></td>';
1.137 raeburn 6780: }
1.145 raeburn 6781: $rem = @locations%($numinrow);
6782: my $colsleft = $numinrow - $rem;
6783: if ($colsleft > 1 ) {
6784: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6785: ' </td>';
6786: } elsif ($colsleft == 1) {
6787: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 6788: }
1.145 raeburn 6789: $datatable .= '</tr></table>';
1.137 raeburn 6790: }
1.145 raeburn 6791: $datatable .= '</td></tr>';
6792: $itemcount ++;
1.137 raeburn 6793: }
6794: }
6795: }
6796: $$rowtotal += $itemcount;
6797: return $datatable;
6798: }
6799:
1.138 raeburn 6800: sub build_location_hashes {
6801: my ($intdoms,$by_ip,$by_location) = @_;
6802: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
6803: (ref($by_location) eq 'HASH'));
6804: my %iphost = &Apache::lonnet::get_iphost();
6805: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
6806: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
6807: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
6808: foreach my $id (@{$iphost{$primary_ip}}) {
6809: my $intdom = &Apache::lonnet::internet_dom($id);
6810: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
6811: push(@{$intdoms},$intdom);
6812: }
6813: }
6814: }
6815: foreach my $ip (keys(%iphost)) {
6816: if (ref($iphost{$ip}) eq 'ARRAY') {
6817: foreach my $id (@{$iphost{$ip}}) {
6818: my $location = &Apache::lonnet::internet_dom($id);
6819: if ($location) {
6820: next if (grep(/^\Q$location\E$/,@{$intdoms}));
6821: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6822: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
6823: push(@{$by_ip->{$ip}},$location);
6824: }
6825: } else {
6826: $by_ip->{$ip} = [$location];
6827: }
6828: }
6829: }
6830: }
6831: }
6832: foreach my $ip (sort(keys(%{$by_ip}))) {
6833: if (ref($by_ip->{$ip}) eq 'ARRAY') {
6834: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
6835: my $first = $by_ip->{$ip}->[0];
6836: if (ref($by_location->{$first}) eq 'ARRAY') {
6837: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
6838: push(@{$by_location->{$first}},$ip);
6839: }
6840: } else {
6841: $by_location->{$first} = [$ip];
6842: }
6843: }
6844: }
6845: return;
6846: }
6847:
1.145 raeburn 6848: sub current_offloads_to {
6849: my ($dom,$settings,$servers) = @_;
6850: my (%spareid,%otherdomconfigs);
1.152 raeburn 6851: if (ref($servers) eq 'HASH') {
1.145 raeburn 6852: foreach my $lonhost (sort(keys(%{$servers}))) {
6853: my $gotspares;
1.152 raeburn 6854: if (ref($settings) eq 'HASH') {
6855: if (ref($settings->{'spares'}) eq 'HASH') {
6856: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
6857: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
6858: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
6859: $gotspares = 1;
6860: }
1.145 raeburn 6861: }
6862: }
6863: unless ($gotspares) {
6864: my $gotspares;
6865: my $serverhomeID =
6866: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
6867: my $serverhomedom =
6868: &Apache::lonnet::host_domain($serverhomeID);
6869: if ($serverhomedom ne $dom) {
6870: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
6871: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6872: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6873: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6874: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6875: $gotspares = 1;
6876: }
6877: }
6878: } else {
6879: $otherdomconfigs{$serverhomedom} =
6880: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
6881: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
6882: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
6883: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
6884: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
6885: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
6886: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
6887: $gotspares = 1;
6888: }
6889: }
6890: }
6891: }
6892: }
6893: }
6894: }
6895: unless ($gotspares) {
6896: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
6897: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6898: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6899: } else {
6900: my $server_hostname = &Apache::lonnet::hostname($lonhost);
6901: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
6902: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
6903: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
6904: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
6905: } else {
1.150 raeburn 6906: my %what = (
6907: spareid => 1,
6908: );
6909: my ($result,$returnhash) =
6910: &Apache::lonnet::get_remote_globals($lonhost,\%what);
6911: if ($result eq 'ok') {
6912: if (ref($returnhash) eq 'HASH') {
6913: if (ref($returnhash->{'spareid'}) eq 'HASH') {
6914: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
6915: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
6916: }
6917: }
1.145 raeburn 6918: }
6919: }
6920: }
6921: }
6922: }
6923: }
6924: return %spareid;
6925: }
6926:
6927: sub spares_row {
1.160.6.105 raeburn 6928: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
6929: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 6930: my $css_class;
6931: my $numinrow = 4;
6932: my $itemcount = 1;
6933: my $datatable;
1.152 raeburn 6934: my %typetitles = &sparestype_titles();
6935: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 6936: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 6937: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
6938: my ($othercontrol,$serverdom);
6939: if ($serverhome ne $server) {
6940: $serverdom = &Apache::lonnet::host_domain($serverhome);
6941: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6942: } else {
6943: $serverdom = &Apache::lonnet::host_domain($server);
6944: if ($serverdom ne $dom) {
6945: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
6946: }
6947: }
6948: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 6949: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 6950: if (ref($curroffloadnow) eq 'HASH') {
6951: if ($curroffloadnow->{$server}) {
6952: $checkednow = ' checked="checked"';
6953: }
6954: }
1.160.6.105 raeburn 6955: if (ref($curroffloadoth) eq 'HASH') {
6956: if ($curroffloadoth->{$server}) {
6957: $checkedoth = ' checked="checked"';
6958: }
6959: }
1.145 raeburn 6960: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6961: $datatable .= '<tr'.$css_class.'>
6962: <td rowspan="2">
1.160.6.13 raeburn 6963: <span class="LC_nobreak">'.
6964: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 6965: ,'<b>'.$server.'</b>').'</span><br />'.
6966: '<span class="LC_nobreak">'."\n".
6967: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 6968: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 6969: "\n";
1.160.6.105 raeburn 6970: if ($other_insts) {
6971: $datatable .= '<br />'.
6972: '<span class="LC_nobreak">'."\n".
6973: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
6974: ' '.&mt('Switch other institutions on next access').'</label></span>'.
6975: "\n";
6976: }
1.145 raeburn 6977: my (%current,%canselect);
1.152 raeburn 6978: my @choices =
6979: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
6980: foreach my $type ('primary','default') {
6981: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 6982: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
6983: my @spares = @{$spareid->{$server}{$type}};
6984: if (@spares > 0) {
1.152 raeburn 6985: if ($othercontrol) {
6986: $current{$type} = join(', ',@spares);
6987: } else {
6988: $current{$type} .= '<table>';
6989: my $numspares = scalar(@spares);
6990: for (my $i=0; $i<@spares; $i++) {
6991: my $rem = $i%($numinrow);
6992: if ($rem == 0) {
6993: if ($i > 0) {
6994: $current{$type} .= '</tr>';
6995: }
6996: $current{$type} .= '<tr>';
1.145 raeburn 6997: }
1.152 raeburn 6998: $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'".');" /> '.
6999: $spareid->{$server}{$type}[$i].
7000: '</label></td>'."\n";
7001: }
7002: my $rem = @spares%($numinrow);
7003: my $colsleft = $numinrow - $rem;
7004: if ($colsleft > 1 ) {
7005: $current{$type} .= '<td colspan="'.$colsleft.
7006: '" class="LC_left_item">'.
7007: ' </td>';
7008: } elsif ($colsleft == 1) {
7009: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7010: }
1.152 raeburn 7011: $current{$type} .= '</tr></table>';
1.150 raeburn 7012: }
1.145 raeburn 7013: }
7014: }
7015: if ($current{$type} eq '') {
7016: $current{$type} = &mt('None specified');
7017: }
1.152 raeburn 7018: if ($othercontrol) {
7019: if ($type eq 'primary') {
7020: $canselect{$type} = $othercontrol;
7021: }
7022: } else {
7023: $canselect{$type} =
7024: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7025: '<select name="newspare_'.$type.'_'.$server.'" '.
7026: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7027: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7028: if (@choices > 0) {
7029: foreach my $lonhost (@choices) {
7030: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7031: }
7032: }
7033: $canselect{$type} .= '</select>'."\n";
7034: }
7035: } else {
7036: $current{$type} = &mt('Could not be determined');
7037: if ($type eq 'primary') {
7038: $canselect{$type} = $othercontrol;
7039: }
1.145 raeburn 7040: }
1.152 raeburn 7041: if ($type eq 'default') {
7042: $datatable .= '<tr'.$css_class.'>';
7043: }
7044: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7045: '<td>'.$current{$type}.'</td>'."\n".
7046: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7047: }
7048: $itemcount ++;
7049: }
7050: }
7051: $$rowtotal += $itemcount;
7052: return $datatable;
7053: }
7054:
1.152 raeburn 7055: sub possible_newspares {
7056: my ($server,$currspares,$serverhomes,$altids) = @_;
7057: my $serverhostname = &Apache::lonnet::hostname($server);
7058: my %excluded;
7059: if ($serverhostname ne '') {
7060: %excluded = (
7061: $serverhostname => 1,
7062: );
7063: }
7064: if (ref($currspares) eq 'HASH') {
7065: foreach my $type (keys(%{$currspares})) {
7066: if (ref($currspares->{$type}) eq 'ARRAY') {
7067: if (@{$currspares->{$type}} > 0) {
7068: foreach my $curr (@{$currspares->{$type}}) {
7069: my $hostname = &Apache::lonnet::hostname($curr);
7070: $excluded{$hostname} = 1;
7071: }
7072: }
7073: }
7074: }
7075: }
7076: my @choices;
7077: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7078: if (keys(%{$serverhomes}) > 1) {
7079: foreach my $name (sort(keys(%{$serverhomes}))) {
7080: unless ($excluded{$name}) {
7081: if (exists($altids->{$serverhomes->{$name}})) {
7082: push(@choices,$altids->{$serverhomes->{$name}});
7083: } else {
7084: push(@choices,$serverhomes->{$name});
1.145 raeburn 7085: }
7086: }
7087: }
7088: }
7089: }
1.152 raeburn 7090: return sort(@choices);
1.145 raeburn 7091: }
7092:
1.150 raeburn 7093: sub print_loadbalancing {
7094: my ($dom,$settings,$rowtotal) = @_;
7095: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7096: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7097: my $numinrow = 1;
7098: my $datatable;
7099: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 7100: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 7101: if (ref($settings) eq 'HASH') {
7102: %existing = %{$settings};
7103: }
7104: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7105: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 7106: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7107: } else {
7108: return;
7109: }
7110: my ($othertitle,$usertypes,$types) =
7111: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 7112: my $rownum = 8;
1.150 raeburn 7113: if (ref($types) eq 'ARRAY') {
7114: $rownum += scalar(@{$types});
7115: }
1.160.6.7 raeburn 7116: my @css_class = ('LC_odd_row','LC_even_row');
7117: my $balnum = 0;
7118: my $islast;
7119: my (@toshow,$disabledtext);
7120: if (keys(%currbalancer) > 0) {
7121: @toshow = sort(keys(%currbalancer));
7122: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7123: push(@toshow,'');
7124: }
7125: } else {
7126: @toshow = ('');
7127: $disabledtext = &mt('No existing load balancer');
7128: }
7129: foreach my $lonhost (@toshow) {
7130: if ($balnum == scalar(@toshow)-1) {
7131: $islast = 1;
7132: } else {
7133: $islast = 0;
7134: }
7135: my $cssidx = $balnum%2;
7136: my $targets_div_style = 'display: none';
7137: my $disabled_div_style = 'display: block';
7138: my $homedom_div_style = 'display: none';
7139: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7140: '<td rowspan="'.$rownum.'" valign="top">'.
7141: '<p>';
7142: if ($lonhost eq '') {
7143: $datatable .= '<span class="LC_nobreak">';
7144: if (keys(%currbalancer) > 0) {
7145: $datatable .= &mt('Add balancer:');
7146: } else {
7147: $datatable .= &mt('Enable balancer:');
7148: }
7149: $datatable .= ' '.
7150: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7151: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7152: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7153: '<option value="" selected="selected">'.&mt('None').
7154: '</option>'."\n";
7155: foreach my $server (sort(keys(%servers))) {
7156: next if ($currbalancer{$server});
7157: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7158: }
7159: $datatable .=
7160: '</select>'."\n".
7161: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7162: } else {
7163: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7164: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7165: &mt('Stop balancing').'</label>'.
7166: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7167: $targets_div_style = 'display: block';
7168: $disabled_div_style = 'display: none';
7169: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7170: $homedom_div_style = 'display: block';
7171: }
7172: }
7173: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7174: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7175: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7176: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7177: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7178: my @sparestypes = ('primary','default');
7179: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 7180: my %hostherechecked = (
7181: no => ' checked="checked"',
7182: );
1.160.6.94 raeburn 7183: my %balcookiechecked = (
7184: no => ' checked="checked"',
7185: );
1.160.6.7 raeburn 7186: foreach my $sparetype (@sparestypes) {
7187: my $targettable;
7188: for (my $i=0; $i<$numspares; $i++) {
7189: my $checked;
7190: if (ref($currtargets{$lonhost}) eq 'HASH') {
7191: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7192: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7193: $checked = ' checked="checked"';
7194: }
7195: }
7196: }
7197: my ($chkboxval,$disabled);
7198: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7199: $chkboxval = $spares[$i];
7200: }
7201: if (exists($currbalancer{$spares[$i]})) {
7202: $disabled = ' disabled="disabled"';
7203: }
7204: $targettable .=
1.160.6.55 raeburn 7205: '<td><span class="LC_nobreak"><label>'.
7206: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 7207: $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 7208: '</span></label></span></td>';
1.160.6.7 raeburn 7209: my $rem = $i%($numinrow);
7210: if ($rem == 0) {
7211: if (($i > 0) && ($i < $numspares-1)) {
7212: $targettable .= '</tr>';
7213: }
7214: if ($i < $numspares-1) {
7215: $targettable .= '<tr>';
1.150 raeburn 7216: }
7217: }
7218: }
1.160.6.7 raeburn 7219: if ($targettable ne '') {
7220: my $rem = $numspares%($numinrow);
7221: my $colsleft = $numinrow - $rem;
7222: if ($colsleft > 1 ) {
7223: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7224: ' </td>';
7225: } elsif ($colsleft == 1) {
7226: $targettable .= '<td class="LC_left_item"> </td>';
7227: }
7228: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7229: '<table><tr>'.$targettable.'</tr></table><br />';
7230: }
1.160.6.76 raeburn 7231: $hostherechecked{$sparetype} = '';
7232: if (ref($currtargets{$lonhost}) eq 'HASH') {
7233: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7234: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7235: $hostherechecked{$sparetype} = ' checked="checked"';
7236: $hostherechecked{'no'} = '';
7237: }
7238: }
7239: }
7240: }
1.160.6.94 raeburn 7241: if ($currcookies{$lonhost}) {
7242: %balcookiechecked = (
7243: yes => ' checked="checked"',
7244: );
7245: }
1.160.6.76 raeburn 7246: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7247: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7248: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7249: foreach my $sparetype (@sparestypes) {
7250: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7251: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7252: '</i></label><br />';
1.160.6.7 raeburn 7253: }
1.160.6.94 raeburn 7254: $datatable .= &mt('Use balancer cookie').'<br />'.
7255: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7256: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7257: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7258: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7259: '</div></td></tr>'.
1.160.6.7 raeburn 7260: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7261: $othertitle,$usertypes,$types,\%servers,
7262: \%currbalancer,$lonhost,
7263: $targets_div_style,$homedom_div_style,
7264: $css_class[$cssidx],$balnum,$islast);
7265: $$rowtotal += $rownum;
7266: $balnum ++;
7267: }
7268: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7269: return $datatable;
7270: }
7271:
7272: sub get_loadbalancers_config {
1.160.6.94 raeburn 7273: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 7274: return unless ((ref($servers) eq 'HASH') &&
7275: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 7276: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7277: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 7278: if (keys(%{$existing}) > 0) {
7279: my $oldlonhost;
7280: foreach my $key (sort(keys(%{$existing}))) {
7281: if ($key eq 'lonhost') {
7282: $oldlonhost = $existing->{'lonhost'};
7283: $currbalancer->{$oldlonhost} = 1;
7284: } elsif ($key eq 'targets') {
7285: if ($oldlonhost) {
7286: $currtargets->{$oldlonhost} = $existing->{'targets'};
7287: }
7288: } elsif ($key eq 'rules') {
7289: if ($oldlonhost) {
7290: $currrules->{$oldlonhost} = $existing->{'rules'};
7291: }
7292: } elsif (ref($existing->{$key}) eq 'HASH') {
7293: $currbalancer->{$key} = 1;
7294: $currtargets->{$key} = $existing->{$key}{'targets'};
7295: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 7296: if ($existing->{$key}{'cookie'}) {
7297: $currcookies->{$key} = 1;
7298: }
1.150 raeburn 7299: }
7300: }
1.160.6.7 raeburn 7301: } else {
7302: my ($balancerref,$targetsref) =
7303: &Apache::lonnet::get_lonbalancer_config($servers);
7304: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7305: foreach my $server (sort(keys(%{$balancerref}))) {
7306: $currbalancer->{$server} = 1;
7307: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7308: }
7309: }
7310: }
1.160.6.7 raeburn 7311: return;
1.150 raeburn 7312: }
7313:
7314: sub loadbalancing_rules {
7315: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 7316: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7317: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7318: my $output;
1.160.6.7 raeburn 7319: my $num = 0;
7320: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7321: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7322: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7323: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 7324: $num ++;
1.150 raeburn 7325: my $current;
7326: if (ref($currrules) eq 'HASH') {
7327: $current = $currrules->{$type};
7328: }
1.160.6.55 raeburn 7329: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 7330: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7331: $current = '';
7332: }
7333: }
7334: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 7335: $servers,$currbalancer,$lonhost,$dom,
7336: $targets_div_style,$homedom_div_style,
7337: $css_class,$balnum,$num,$islast);
1.150 raeburn 7338: }
7339: }
7340: return $output;
7341: }
7342:
7343: sub loadbalancing_titles {
7344: my ($dom,$intdom,$usertypes,$types) = @_;
7345: my %othertypes = (
7346: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7347: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7348: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7349: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 7350: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7351: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7352: );
1.160.6.26 raeburn 7353: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 7354: my @available;
1.150 raeburn 7355: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7356: @available = @{$types};
1.150 raeburn 7357: }
1.160.6.89 raeburn 7358: unless (grep(/^default$/,@available)) {
7359: push(@available,'default');
7360: }
7361: unshift(@alltypes,@available);
1.150 raeburn 7362: my %titles;
7363: foreach my $type (@alltypes) {
7364: if ($type =~ /^_LC_/) {
7365: $titles{$type} = $othertypes{$type};
7366: } elsif ($type eq 'default') {
7367: $titles{$type} = &mt('All users from [_1]',$dom);
7368: if (ref($types) eq 'ARRAY') {
7369: if (@{$types} > 0) {
7370: $titles{$type} = &mt('Other users from [_1]',$dom);
7371: }
7372: }
7373: } elsif (ref($usertypes) eq 'HASH') {
7374: $titles{$type} = $usertypes->{$type};
7375: }
7376: }
7377: return (\@alltypes,\%othertypes,\%titles);
7378: }
7379:
7380: sub loadbalance_rule_row {
1.160.6.7 raeburn 7381: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
7382: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 7383: my @rulenames;
1.150 raeburn 7384: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 7385: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 7386: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 7387: } else {
1.160.6.26 raeburn 7388: @rulenames = ('default','homeserver');
7389: if ($type eq '_LC_external') {
7390: push(@rulenames,'externalbalancer');
7391: } else {
7392: push(@rulenames,'specific');
7393: }
7394: push(@rulenames,'none');
1.150 raeburn 7395: }
7396: my $style = $targets_div_style;
1.160.6.55 raeburn 7397: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 7398: $style = $homedom_div_style;
7399: }
1.160.6.7 raeburn 7400: my $space;
7401: if ($islast && $num == 1) {
7402: $space = '<div display="inline-block"> </div>';
7403: }
7404: my $output =
7405: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
7406: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
7407: '<td valaign="top">'.$space.
7408: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 7409: for (my $i=0; $i<@rulenames; $i++) {
7410: my $rule = $rulenames[$i];
7411: my ($checked,$extra);
7412: if ($rulenames[$i] eq 'default') {
7413: $rule = '';
7414: }
7415: if ($rulenames[$i] eq 'specific') {
7416: if (ref($servers) eq 'HASH') {
7417: my $default;
7418: if (($current ne '') && (exists($servers->{$current}))) {
7419: $checked = ' checked="checked"';
7420: }
7421: unless ($checked) {
7422: $default = ' selected="selected"';
7423: }
1.160.6.7 raeburn 7424: $extra =
7425: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
7426: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
7427: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
7428: '<option value=""'.$default.'></option>'."\n";
7429: foreach my $server (sort(keys(%{$servers}))) {
7430: if (ref($currbalancer) eq 'HASH') {
7431: next if (exists($currbalancer->{$server}));
7432: }
1.150 raeburn 7433: my $selected;
1.160.6.7 raeburn 7434: if ($server eq $current) {
1.150 raeburn 7435: $selected = ' selected="selected"';
7436: }
1.160.6.7 raeburn 7437: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 7438: }
7439: $extra .= '</select>';
7440: }
7441: } elsif ($rule eq $current) {
7442: $checked = ' checked="checked"';
7443: }
7444: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 7445: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
7446: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
7447: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 7448: ')"'.$checked.' /> ';
1.160.6.56 raeburn 7449: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 7450: $output .= $ruletitles{'particular'};
7451: } else {
7452: $output .= $ruletitles{$rulenames[$i]};
7453: }
7454: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 7455: }
7456: $output .= '</div></td></tr>'."\n";
7457: return $output;
7458: }
7459:
7460: sub offloadtype_text {
7461: my %ruletitles = &Apache::lonlocal::texthash (
7462: 'default' => 'Offloads to default destinations',
7463: 'homeserver' => "Offloads to user's home server",
7464: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
7465: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 7466: 'none' => 'No offload',
1.160.6.26 raeburn 7467: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
7468: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 7469: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 7470: );
7471: return %ruletitles;
7472: }
7473:
7474: sub sparestype_titles {
7475: my %typestitles = &Apache::lonlocal::texthash (
7476: 'primary' => 'primary',
7477: 'default' => 'default',
7478: );
7479: return %typestitles;
7480: }
7481:
1.28 raeburn 7482: sub contact_titles {
7483: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 7484: 'supportemail' => 'Support E-mail address',
7485: 'adminemail' => 'Default Server Admin E-mail address',
7486: 'errormail' => 'Error reports to be e-mailed to',
7487: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 7488: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
7489: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 7490: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
7491: 'requestsmail' => 'E-mail from course requests requiring approval',
7492: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 7493: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 7494: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 7495: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
7496: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 7497: 'errorweights' => 'Weights used to compute error count',
7498: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 7499: );
7500: my %short_titles = &Apache::lonlocal::texthash (
7501: adminemail => 'Admin E-mail address',
7502: supportemail => 'Support E-mail',
7503: );
7504: return (\%titles,\%short_titles);
7505: }
7506:
1.160.6.78 raeburn 7507: sub helpform_fields {
7508: my %titles = &Apache::lonlocal::texthash (
7509: 'username' => 'Name',
7510: 'user' => 'Username/domain',
7511: 'phone' => 'Phone',
7512: 'cc' => 'Cc e-mail',
7513: 'course' => 'Course Details',
7514: 'section' => 'Sections',
7515: 'screenshot' => 'File upload',
7516: );
7517: my @fields = ('username','phone','user','course','section','cc','screenshot');
7518: my %possoptions = (
7519: username => ['yes','no','req'],
7520: phone => ['yes','no','req'],
7521: user => ['yes','no'],
7522: cc => ['yes','no'],
7523: course => ['yes','no'],
7524: section => ['yes','no'],
7525: screenshot => ['yes','no'],
7526: );
7527: my %fieldoptions = &Apache::lonlocal::texthash (
7528: 'yes' => 'Optional',
7529: 'req' => 'Required',
7530: 'no' => "Not shown",
7531: );
7532: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
7533: }
7534:
1.72 raeburn 7535: sub tool_titles {
7536: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 7537: aboutme => 'Personal web page',
1.86 raeburn 7538: blog => 'Blog',
1.160.6.4 raeburn 7539: webdav => 'WebDAV',
1.86 raeburn 7540: portfolio => 'Portfolio',
1.88 bisitz 7541: official => 'Official courses (with institutional codes)',
7542: unofficial => 'Unofficial courses',
1.98 raeburn 7543: community => 'Communities',
1.160.6.30 raeburn 7544: textbook => 'Textbook courses',
1.86 raeburn 7545: );
1.72 raeburn 7546: return %titles;
7547: }
7548:
1.101 raeburn 7549: sub courserequest_titles {
7550: my %titles = &Apache::lonlocal::texthash (
7551: official => 'Official',
7552: unofficial => 'Unofficial',
7553: community => 'Communities',
1.160.6.30 raeburn 7554: textbook => 'Textbook',
1.101 raeburn 7555: norequest => 'Not allowed',
1.104 raeburn 7556: approval => 'Approval by Dom. Coord.',
1.101 raeburn 7557: validate => 'With validation',
7558: autolimit => 'Numerical limit',
1.103 raeburn 7559: unlimited => '(blank for unlimited)',
1.101 raeburn 7560: );
7561: return %titles;
7562: }
7563:
1.160.6.5 raeburn 7564: sub authorrequest_titles {
7565: my %titles = &Apache::lonlocal::texthash (
7566: norequest => 'Not allowed',
7567: approval => 'Approval by Dom. Coord.',
7568: automatic => 'Automatic approval',
7569: );
7570: return %titles;
7571: }
7572:
1.101 raeburn 7573: sub courserequest_conditions {
7574: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 7575: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 7576: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 7577: );
7578: return %conditions;
7579: }
7580:
7581:
1.27 raeburn 7582: sub print_usercreation {
1.30 raeburn 7583: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 7584: my $numinrow = 4;
1.28 raeburn 7585: my $datatable;
7586: if ($position eq 'top') {
1.30 raeburn 7587: $$rowtotal ++;
1.34 raeburn 7588: my $rowcount = 0;
1.32 raeburn 7589: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 7590: if (ref($rules) eq 'HASH') {
7591: if (keys(%{$rules}) > 0) {
1.32 raeburn 7592: $datatable .= &user_formats_row('username',$settings,$rules,
7593: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 7594: $$rowtotal ++;
1.32 raeburn 7595: $rowcount ++;
7596: }
7597: }
7598: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
7599: if (ref($idrules) eq 'HASH') {
7600: if (keys(%{$idrules}) > 0) {
7601: $datatable .= &user_formats_row('id',$settings,$idrules,
7602: $idruleorder,$numinrow,$rowcount);
7603: $$rowtotal ++;
7604: $rowcount ++;
1.28 raeburn 7605: }
7606: }
1.39 raeburn 7607: if ($rowcount == 0) {
7608: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
7609: $$rowtotal ++;
7610: $rowcount ++;
7611: }
1.34 raeburn 7612: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 7613: my @creators = ('author','course','requestcrs');
1.37 raeburn 7614: my ($rules,$ruleorder) =
7615: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 7616: my %lt = &usercreation_types();
7617: my %checked;
7618: if (ref($settings) eq 'HASH') {
7619: if (ref($settings->{'cancreate'}) eq 'HASH') {
7620: foreach my $item (@creators) {
7621: $checked{$item} = $settings->{'cancreate'}{$item};
7622: }
7623: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
7624: foreach my $item (@creators) {
7625: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
7626: $checked{$item} = 'none';
7627: }
7628: }
7629: }
7630: }
7631: my $rownum = 0;
7632: foreach my $item (@creators) {
7633: $rownum ++;
1.160.6.34 raeburn 7634: if ($checked{$item} eq '') {
7635: $checked{$item} = 'any';
1.34 raeburn 7636: }
7637: my $css_class;
7638: if ($rownum%2) {
7639: $css_class = '';
7640: } else {
7641: $css_class = ' class="LC_odd_row" ';
7642: }
7643: $datatable .= '<tr'.$css_class.'>'.
7644: '<td><span class="LC_nobreak">'.$lt{$item}.
7645: '</span></td><td align="right">';
1.160.6.34 raeburn 7646: my @options = ('any');
7647: if (ref($rules) eq 'HASH') {
7648: if (keys(%{$rules}) > 0) {
7649: push(@options,('official','unofficial'));
1.37 raeburn 7650: }
7651: }
1.160.6.34 raeburn 7652: push(@options,'none');
1.37 raeburn 7653: foreach my $option (@options) {
1.50 raeburn 7654: my $type = 'radio';
1.34 raeburn 7655: my $check = ' ';
1.160.6.34 raeburn 7656: if ($checked{$item} eq $option) {
7657: $check = ' checked="checked" ';
1.34 raeburn 7658: }
7659: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 7660: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 7661: $item.'" value="'.$option.'"'.$check.'/> '.
7662: $lt{$option}.'</label> </span>';
7663: }
7664: $datatable .= '</td></tr>';
7665: }
1.28 raeburn 7666: } else {
7667: my @contexts = ('author','course','domain');
7668: my @authtypes = ('int','krb4','krb5','loc');
7669: my %checked;
7670: if (ref($settings) eq 'HASH') {
7671: if (ref($settings->{'authtypes'}) eq 'HASH') {
7672: foreach my $item (@contexts) {
7673: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
7674: foreach my $auth (@authtypes) {
7675: if ($settings->{'authtypes'}{$item}{$auth}) {
7676: $checked{$item}{$auth} = ' checked="checked" ';
7677: }
7678: }
7679: }
7680: }
1.27 raeburn 7681: }
1.35 raeburn 7682: } else {
7683: foreach my $item (@contexts) {
1.36 raeburn 7684: foreach my $auth (@authtypes) {
1.35 raeburn 7685: $checked{$item}{$auth} = ' checked="checked" ';
7686: }
7687: }
1.27 raeburn 7688: }
1.28 raeburn 7689: my %title = &context_names();
7690: my %authname = &authtype_names();
7691: my $rownum = 0;
7692: my $css_class;
7693: foreach my $item (@contexts) {
7694: if ($rownum%2) {
7695: $css_class = '';
7696: } else {
7697: $css_class = ' class="LC_odd_row" ';
7698: }
1.30 raeburn 7699: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 7700: '<td>'.$title{$item}.
7701: '</td><td class="LC_left_item">'.
7702: '<span class="LC_nobreak">';
7703: foreach my $auth (@authtypes) {
7704: $datatable .= '<label>'.
7705: '<input type="checkbox" name="'.$item.'_auth" '.
7706: $checked{$item}{$auth}.' value="'.$auth.'" />'.
7707: $authname{$auth}.'</label> ';
7708: }
7709: $datatable .= '</span></td></tr>';
7710: $rownum ++;
1.27 raeburn 7711: }
1.30 raeburn 7712: $$rowtotal += $rownum;
1.27 raeburn 7713: }
7714: return $datatable;
7715: }
7716:
1.160.6.34 raeburn 7717: sub print_selfcreation {
7718: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 7719: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
7720: $emaildomain,$datatable);
1.160.6.34 raeburn 7721: if (ref($settings) eq 'HASH') {
7722: if (ref($settings->{'cancreate'}) eq 'HASH') {
7723: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 7724: if (ref($createsettings) eq 'HASH') {
7725: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
7726: @selfcreate = @{$createsettings->{'selfcreate'}};
7727: } elsif ($createsettings->{'selfcreate'} ne '') {
7728: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
7729: @selfcreate = ('email','login','sso');
7730: } elsif ($createsettings->{'selfcreate'} ne 'none') {
7731: @selfcreate = ($createsettings->{'selfcreate'});
7732: }
7733: }
7734: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
7735: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 7736: }
1.160.6.93 raeburn 7737: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
7738: $emailoptions = $createsettings->{'emailoptions'};
7739: }
7740: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
7741: $emailverified = $createsettings->{'emailverified'};
7742: }
7743: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
7744: $emaildomain = $createsettings->{'emaildomain'};
7745: }
1.160.6.34 raeburn 7746: }
7747: }
7748: }
7749: my %radiohash;
7750: my $numinrow = 4;
7751: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 7752: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 7753: if ($position eq 'top') {
7754: my %choices = &Apache::lonlocal::texthash (
7755: cancreate_login => 'Institutional Login',
7756: cancreate_sso => 'Institutional Single Sign On',
7757: );
7758: my @toggles = sort(keys(%choices));
7759: my %defaultchecked = (
7760: 'cancreate_login' => 'off',
7761: 'cancreate_sso' => 'off',
7762: );
1.160.6.35 raeburn 7763: my ($onclick,$itemcount);
1.160.6.34 raeburn 7764: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7765: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 7766: $$rowtotal += $itemcount;
1.160.6.34 raeburn 7767:
7768: if (ref($usertypes) eq 'HASH') {
7769: if (keys(%{$usertypes}) > 0) {
7770: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
7771: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 7772: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 7773: $$rowtotal ++;
7774: }
7775: }
1.160.6.44 raeburn 7776: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
7777: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7778: $fieldtitles{'inststatus'} = &mt('Institutional status');
7779: my $rem;
7780: my $numperrow = 2;
7781: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
7782: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 7783: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 7784: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 7785: '<table>'."\n";
1.160.6.44 raeburn 7786: for (my $i=0; $i<@fields; $i++) {
7787: $rem = $i%($numperrow);
7788: if ($rem == 0) {
7789: if ($i > 0) {
7790: $datatable .= '</tr>';
7791: }
7792: $datatable .= '<tr>';
7793: }
7794: my $currval;
1.160.6.51 raeburn 7795: if (ref($createsettings) eq 'HASH') {
7796: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
7797: $currval = $createsettings->{'shibenv'}{$fields[$i]};
7798: }
1.160.6.44 raeburn 7799: }
7800: $datatable .= '<td class="LC_left_item">'.
7801: '<span class="LC_nobreak">'.
7802: '<input type="text" name="shibenv_'.$fields[$i].'" '.
7803: 'value="'.$currval.'" size="10" /> '.
7804: $fieldtitles{$fields[$i]}.'</span></td>';
7805: }
7806: my $colsleft = $numperrow - $rem;
7807: if ($colsleft > 1 ) {
7808: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7809: ' </td>';
7810: } elsif ($colsleft == 1) {
7811: $datatable .= '<td class="LC_left_item"> </td>';
7812: }
7813: $datatable .= '</tr></table></td></tr>';
7814: $$rowtotal ++;
1.160.6.34 raeburn 7815: } elsif ($position eq 'middle') {
7816: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 7817: my @posstypes;
1.160.6.34 raeburn 7818: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7819: @posstypes = @{$types};
7820: }
7821: unless (grep(/^default$/,@posstypes)) {
7822: push(@posstypes,'default');
7823: }
7824: my %usertypeshash;
7825: if (ref($usertypes) eq 'HASH') {
7826: %usertypeshash = %{$usertypes};
7827: }
7828: $usertypeshash{'default'} = $othertitle;
7829: foreach my $status (@posstypes) {
7830: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
7831: $numinrow,$$rowtotal,\%usertypeshash);
7832: $$rowtotal ++;
1.160.6.34 raeburn 7833: }
7834: } else {
1.160.6.40 raeburn 7835: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 7836: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 7837: );
7838: my @toggles = sort(keys(%choices));
7839: my %defaultchecked = (
7840: 'cancreate_email' => 'off',
7841: );
1.160.6.93 raeburn 7842: my $customclass = 'LC_selfcreate_email';
7843: my $classprefix = 'LC_canmodify_emailusername_';
7844: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 7845: my $display = 'none';
1.160.6.93 raeburn 7846: my $rowstyle = 'display:none';
1.160.6.40 raeburn 7847: if (grep(/^\Qemail\E$/,@selfcreate)) {
7848: $display = 'block';
1.160.6.93 raeburn 7849: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 7850: }
1.160.6.93 raeburn 7851: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
7852: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
7853: \%choices,$$rowtotal,$onclick);
7854: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
7855: $rowstyle);
7856: $$rowtotal ++;
7857: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
7858: $rowstyle);
7859: $$rowtotal ++;
7860: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 7861: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 7862: my ($emailrules,$emailruleorder) =
7863: &Apache::lonnet::inst_userrules($dom,'email');
7864: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7865: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7866: if (ref($types) eq 'ARRAY') {
7867: @posstypes = @{$types};
7868: }
7869: if (@posstypes) {
7870: unless (grep(/^default$/,@posstypes)) {
7871: push(@posstypes,'default');
1.160.6.89 raeburn 7872: }
7873: if (ref($usertypes) eq 'HASH') {
7874: %usertypeshash = %{$usertypes};
7875: }
1.160.6.93 raeburn 7876: my $currassign;
7877: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
7878: $currassign = {
7879: selfassign => $domdefaults{'inststatusguest'},
7880: };
7881: @ordered = @{$domdefaults{'inststatusguest'}};
7882: } else {
7883: $currassign = { selfassign => [] };
7884: }
7885: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
7886: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
7887: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
7888: $numinrow,$othertitle,'selfassign',
7889: $rowtotal,$onclicktypes,$customclass,
7890: $rowstyle);
7891: $$rowtotal ++;
1.160.6.89 raeburn 7892: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7893: foreach my $status (@posstypes) {
7894: my $css_class;
7895: if ($$rowtotal%2) {
7896: $css_class = 'LC_odd_row ';
7897: }
7898: $css_class .= $customclass;
7899: my $rowid = $optionsprefix.$status;
7900: my $hidden = 1;
7901: my $currstyle = 'display:none';
7902: if (grep(/^\Q$status\E$/,@ordered)) {
7903: $currstyle = $rowstyle;
7904: $hidden = 0;
7905: }
7906: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7907: $emailrules,$emailruleorder,$settings,$status,$rowid,
7908: $usertypeshash{$status},$css_class,$currstyle,$intdom);
7909: unless ($hidden) {
7910: $$rowtotal ++;
7911: }
1.160.6.89 raeburn 7912: }
7913: } else {
1.160.6.93 raeburn 7914: my $css_class;
7915: if ($$rowtotal%2) {
7916: $css_class = 'LC_odd_row ';
7917: }
7918: $css_class .= $customclass;
1.160.6.89 raeburn 7919: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 7920: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
7921: $emailrules,$emailruleorder,$settings,'default','',
7922: $othertitle,$css_class,$rowstyle,$intdom);
7923: $$rowtotal ++;
1.160.6.34 raeburn 7924: }
1.160.6.35 raeburn 7925: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
7926: $numinrow = 1;
1.160.6.93 raeburn 7927: if (@posstypes) {
7928: foreach my $status (@posstypes) {
7929: my $rowid = $classprefix.$status;
7930: my $datarowstyle = 'display:none';
7931: if (grep(/^\Q$status\E$/,@ordered)) {
7932: $datarowstyle = $rowstyle;
7933: }
7934: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
7935: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7936: $infotitles,$rowid,$customclass,$datarowstyle);
7937: unless ($datarowstyle eq 'display:none') {
7938: $$rowtotal ++;
7939: }
1.160.6.34 raeburn 7940: }
1.160.6.93 raeburn 7941: } else {
7942: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
7943: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
7944: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 7945: }
7946: }
7947: return $datatable;
7948: }
7949:
1.160.6.93 raeburn 7950: sub selfcreate_javascript {
7951: return <<"ENDSCRIPT";
7952:
7953: <script type="text/javascript">
7954: // <![CDATA[
7955:
7956: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
7957: var x = document.getElementsByClassName(target);
7958: var insttypes = 0;
7959: var insttypeRegExp = new RegExp(prefix);
7960: if ((x.length != undefined) && (x.length > 0)) {
7961: if (form.elements[radio].length != undefined) {
7962: for (var i=0; i<form.elements[radio].length; i++) {
7963: if (form.elements[radio][i].checked) {
7964: if (form.elements[radio][i].value == 1) {
7965: for (var j=0; j<x.length; j++) {
7966: if (x[j].id == 'undefined') {
7967: x[j].style.display = 'table-row';
7968: } else if (insttypeRegExp.test(x[j].id)) {
7969: insttypes ++;
7970: } else {
7971: x[j].style.display = 'table-row';
7972: }
7973: }
7974: } else {
7975: for (var j=0; j<x.length; j++) {
7976: x[j].style.display = 'none';
7977: }
1.160.6.40 raeburn 7978: }
1.160.6.93 raeburn 7979: break;
7980: }
7981: }
7982: if (insttypes > 0) {
7983: toggleDataRow(form,checkbox,target,altprefix);
7984: toggleDataRow(form,checkbox,target,prefix,1);
7985: }
7986: }
7987: }
7988: return;
7989: }
7990:
7991: function toggleDataRow(form,checkbox,target,prefix,docount) {
7992: if (form.elements[checkbox].length != undefined) {
7993: var count = 0;
7994: if (docount) {
7995: for (var i=0; i<form.elements[checkbox].length; i++) {
7996: if (form.elements[checkbox][i].checked) {
7997: count ++;
7998: }
7999: }
8000: }
8001: for (var i=0; i<form.elements[checkbox].length; i++) {
8002: var type = form.elements[checkbox][i].value;
8003: if (document.getElementById(prefix+type)) {
8004: if (form.elements[checkbox][i].checked) {
8005: document.getElementById(prefix+type).style.display = 'table-row';
8006: if (count % 2 == 1) {
8007: document.getElementById(prefix+type).className = target+' LC_odd_row';
8008: } else {
8009: document.getElementById(prefix+type).className = target;
8010: }
8011: count ++;
1.160.6.40 raeburn 8012: } else {
1.160.6.93 raeburn 8013: document.getElementById(prefix+type).style.display = 'none';
8014: }
8015: }
8016: }
8017: }
8018: return;
8019: }
8020:
8021: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8022: var caller = radio+'_'+status;
8023: if (form.elements[caller].length != undefined) {
8024: for (var i=0; i<form.elements[caller].length; i++) {
8025: if (form.elements[caller][i].checked) {
8026: if (document.getElementById(altprefix+'_inst_'+status)) {
8027: var curr = form.elements[caller][i].value;
8028: if (prefix) {
8029: document.getElementById(prefix+'_'+status).style.display = 'none';
8030: }
8031: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8032: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8033: if (curr == 'custom') {
8034: if (prefix) {
8035: document.getElementById(prefix+'_'+status).style.display = 'inline';
8036: }
8037: } else if (curr == 'inst') {
8038: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8039: } else if (curr == 'noninst') {
8040: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 8041: }
1.160.6.93 raeburn 8042: break;
1.160.6.40 raeburn 8043: }
1.160.6.93 raeburn 8044: }
8045: }
8046: }
8047: }
8048:
8049: // ]]>
8050: </script>
8051:
8052: ENDSCRIPT
8053: }
8054:
8055: sub noninst_users {
8056: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8057: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8058: my $class = 'LC_left_item';
8059: if ($css_class) {
8060: $css_class = ' class="'.$css_class.'"';
8061: }
8062: if ($rowid) {
8063: $rowid = ' id="'.$rowid.'"';
8064: }
8065: if ($rowstyle) {
8066: $rowstyle = ' style="'.$rowstyle.'"';
8067: }
8068: my ($output,$description);
8069: if ($type eq 'default') {
8070: $description = &mt('Requests for: [_1]',$typetitle);
8071: } else {
8072: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8073: }
8074: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8075: "<td>$description</td>\n".
8076: '<td class="'.$class.'" colspan="2">'.
8077: '<table><tr>';
8078: my %headers = &Apache::lonlocal::texthash(
8079: approve => 'Processing',
8080: email => 'E-mail',
8081: username => 'Username',
8082: );
8083: foreach my $item ('approve','email','username') {
8084: $output .= '<th>'.$headers{$item}.'</th>';
8085: }
8086: $output .= '</tr><tr>';
8087: foreach my $item ('approve','email','username') {
8088: $output .= '<td valign="top">';
8089: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8090: if ($item eq 'approve') {
8091: %choices = &Apache::lonlocal::texthash (
8092: automatic => 'Automatically approved',
8093: approval => 'Queued for approval',
8094: );
8095: @options = ('automatic','approval');
8096: $hashref = $processing;
8097: $defoption = 'automatic';
8098: $name = 'cancreate_emailprocess_'.$type;
8099: } elsif ($item eq 'email') {
8100: %choices = &Apache::lonlocal::texthash (
8101: any => 'Any e-mail',
8102: inst => 'Institutional only',
8103: noninst => 'Non-institutional only',
8104: custom => 'Custom restrictions',
8105: );
8106: @options = ('any','inst','noninst');
8107: my $showcustom;
8108: if (ref($emailrules) eq 'HASH') {
8109: if (keys(%{$emailrules}) > 0) {
8110: push(@options,'custom');
8111: $showcustom = 'cancreate_emailrule';
8112: if (ref($settings) eq 'HASH') {
8113: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8114: foreach my $rule (@{$settings->{'email_rule'}}) {
8115: if (exists($emailrules->{$rule})) {
8116: $hascustom ++;
8117: }
8118: }
8119: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8120: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8121: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8122: if (exists($emailrules->{$rule})) {
8123: $hascustom ++;
8124: }
8125: }
8126: }
8127: }
8128: }
8129: }
8130: }
8131: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8132: "'cancreate_emaildomain','$type'".');"';
8133: $hashref = $emailoptions;
8134: $defoption = 'any';
8135: $name = 'cancreate_emailoptions_'.$type;
8136: } elsif ($item eq 'username') {
8137: %choices = &Apache::lonlocal::texthash (
8138: all => 'Same as e-mail',
8139: first => 'Omit @domain',
8140: free => 'Free to choose',
8141: );
8142: @options = ('all','first','free');
8143: $hashref = $emailverified;
8144: $defoption = 'all';
8145: $name = 'cancreate_usernameoptions_'.$type;
8146: }
8147: foreach my $option (@options) {
8148: my $checked;
8149: if (ref($hashref) eq 'HASH') {
8150: if ($type eq '') {
8151: if (!exists($hashref->{'default'})) {
8152: if ($option eq $defoption) {
8153: $checked = ' checked="checked"';
8154: }
8155: } else {
8156: if ($hashref->{'default'} eq $option) {
8157: $checked = ' checked="checked"';
8158: }
1.160.6.40 raeburn 8159: }
8160: } else {
1.160.6.93 raeburn 8161: if (!exists($hashref->{$type})) {
8162: if ($option eq $defoption) {
8163: $checked = ' checked="checked"';
8164: }
8165: } else {
8166: if ($hashref->{$type} eq $option) {
8167: $checked = ' checked="checked"';
8168: }
1.160.6.40 raeburn 8169: }
8170: }
1.160.6.93 raeburn 8171: } elsif (($item eq 'email') && ($hascustom)) {
8172: if ($option eq 'custom') {
8173: $checked = ' checked="checked"';
8174: }
8175: } elsif ($option eq $defoption) {
8176: $checked = ' checked="checked"';
8177: }
8178: $output .= '<span class="LC_nobreak"><label>'.
8179: '<input type="radio" name="'.$name.'"'.
8180: $checked.' value="'.$option.'"'.$onclick.' />'.
8181: $choices{$option}.'</label></span><br />';
8182: if ($item eq 'email') {
8183: if ($option eq 'custom') {
8184: my $id = 'cancreate_emailrule_'.$type;
8185: my $display = 'none';
8186: if ($checked) {
8187: $display = 'inline';
8188: }
8189: my $numinrow = 2;
8190: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8191: '<legend>'.&mt('Disallow').'</legend><table>'.
8192: &user_formats_row('email',$settings,$emailrules,
8193: $emailruleorder,$numinrow,'',$type);
8194: '</table></fieldset>';
8195: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8196: my %text = &Apache::lonlocal::texthash (
8197: inst => 'must end:',
8198: noninst => 'cannot end:',
8199: );
8200: my $value;
8201: if (ref($emaildomain) eq 'HASH') {
8202: if (ref($emaildomain->{$type}) eq 'HASH') {
8203: $value = $emaildomain->{$type}->{$option};
8204: }
8205: }
8206: if ($value eq '') {
8207: $value = '@'.$intdom;
8208: }
8209: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8210: my $display = 'none';
8211: if ($checked) {
8212: $display = 'inline';
8213: }
8214: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8215: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8216: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8217: '</div>';
8218: }
1.160.6.40 raeburn 8219: }
8220: }
1.160.6.93 raeburn 8221: $output .= '</td>'."\n";
1.160.6.40 raeburn 8222: }
1.160.6.93 raeburn 8223: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 8224: return $output;
8225: }
8226:
1.160.6.5 raeburn 8227: sub captcha_choice {
1.160.6.93 raeburn 8228: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 8229: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
8230: $vertext,$currver);
1.160.6.5 raeburn 8231: my %lt = &captcha_phrases();
8232: $keyentry = 'hidden';
1.160.6.98 raeburn 8233: my $colspan=2;
1.160.6.5 raeburn 8234: if ($context eq 'cancreate') {
1.160.6.34 raeburn 8235: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 8236: } elsif ($context eq 'login') {
8237: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 8238: } elsif ($context eq 'passwords') {
8239: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8240: $colspan=1;
1.160.6.5 raeburn 8241: }
8242: if (ref($settings) eq 'HASH') {
8243: if ($settings->{'captcha'}) {
8244: $checked{$settings->{'captcha'}} = ' checked="checked"';
8245: } else {
8246: $checked{'original'} = ' checked="checked"';
8247: }
8248: if ($settings->{'captcha'} eq 'recaptcha') {
8249: $pubtext = $lt{'pub'};
8250: $privtext = $lt{'priv'};
8251: $keyentry = 'text';
1.160.6.69 raeburn 8252: $vertext = $lt{'ver'};
8253: $currver = $settings->{'recaptchaversion'};
8254: if ($currver ne '2') {
8255: $currver = 1;
8256: }
1.160.6.5 raeburn 8257: }
8258: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8259: $currpub = $settings->{'recaptchakeys'}{'public'};
8260: $currpriv = $settings->{'recaptchakeys'}{'private'};
8261: }
8262: } else {
8263: $checked{'original'} = ' checked="checked"';
8264: }
1.160.6.93 raeburn 8265: my $css_class;
8266: if ($itemcount%2) {
8267: $css_class = 'LC_odd_row';
8268: }
8269: if ($customcss) {
8270: $css_class .= " $customcss";
8271: }
8272: $css_class =~ s/^\s+//;
8273: if ($css_class) {
8274: $css_class = ' class="'.$css_class.'"';
8275: }
8276: if ($rowstyle) {
8277: $css_class .= ' style="'.$rowstyle.'"';
8278: }
1.160.6.5 raeburn 8279: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 8280: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 8281: '<table><tr><td>'."\n";
8282: foreach my $option ('original','recaptcha','notused') {
8283: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8284: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8285: $lt{$option}.'</label></span>';
8286: unless ($option eq 'notused') {
8287: $output .= (' 'x2)."\n";
8288: }
8289: }
8290: #
8291: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8292: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
8293: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
8294: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
8295: #
8296: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 8297: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 8298: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8299: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8300: $currpub.'" size="40" /></span><br />'."\n".
8301: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8302: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 8303: $currpriv.'" size="40" /></span><br />'.
8304: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8305: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8306: $currver.'" size="3" /></span><br />'.
8307: '</td></tr></table>'."\n".
1.160.6.5 raeburn 8308: '</td></tr>';
8309: return $output;
8310: }
8311:
1.32 raeburn 8312: sub user_formats_row {
1.160.6.93 raeburn 8313: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8314: my $output;
8315: my %text = (
8316: 'username' => 'new usernames',
8317: 'id' => 'IDs',
8318: );
1.160.6.118.2 8(raebur 8319:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 8320: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8321: $output = '<tr '.$css_class.'>'.
8322: '<td><span class="LC_nobreak">'.
8323: &mt("Format rules to check for $text{$type}: ").
8324: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8325: }
1.27 raeburn 8326: my $rem;
8327: if (ref($ruleorder) eq 'ARRAY') {
8328: for (my $i=0; $i<@{$ruleorder}; $i++) {
8329: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8330: my $rem = $i%($numinrow);
8331: if ($rem == 0) {
8332: if ($i > 0) {
8333: $output .= '</tr>';
8334: }
8335: $output .= '<tr>';
8336: }
8337: my $check = ' ';
1.39 raeburn 8338: if (ref($settings) eq 'HASH') {
8339: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8340: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8341: $check = ' checked="checked" ';
8342: }
1.160.6.93 raeburn 8343: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8344: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8345: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8346: $check = ' checked="checked" ';
8347: }
8348: }
1.27 raeburn 8349: }
8350: }
1.160.6.93 raeburn 8351: my $name = $type.'_rule';
8352: if ($type eq 'email') {
8353: $name .= '_'.$status;
8354: }
1.27 raeburn 8355: $output .= '<td class="LC_left_item">'.
8356: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 8357: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8358: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8359: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
8360: }
8361: }
8362: $rem = @{$ruleorder}%($numinrow);
8363: }
1.160.6.93 raeburn 8364: my $colsleft;
8365: if ($rem) {
8366: $colsleft = $numinrow - $rem;
8367: }
1.27 raeburn 8368: if ($colsleft > 1 ) {
8369: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8370: ' </td>';
8371: } elsif ($colsleft == 1) {
8372: $output .= '<td class="LC_left_item"> </td>';
8373: }
1.160.6.118.2 8(raebur 8374:2): $output .= '</tr>';
8375:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
8376:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 8377: }
1.27 raeburn 8378: return $output;
8379: }
8380:
1.34 raeburn 8381: sub usercreation_types {
8382: my %lt = &Apache::lonlocal::texthash (
8383: author => 'When adding a co-author',
8384: course => 'When adding a user to a course',
1.100 raeburn 8385: requestcrs => 'When requesting a course',
1.34 raeburn 8386: any => 'Any',
8387: official => 'Institutional only ',
8388: unofficial => 'Non-institutional only',
8389: none => 'None',
8390: );
8391: return %lt;
1.48 raeburn 8392: }
1.34 raeburn 8393:
1.160.6.34 raeburn 8394: sub selfcreation_types {
8395: my %lt = &Apache::lonlocal::texthash (
8396: selfcreate => 'User creates own account',
8397: any => 'Any',
8398: official => 'Institutional only ',
8399: unofficial => 'Non-institutional only',
8400: email => 'E-mail address',
8401: login => 'Institutional Login',
8402: sso => 'SSO',
8403: );
8404: }
8405:
1.28 raeburn 8406: sub authtype_names {
8407: my %lt = &Apache::lonlocal::texthash(
8408: int => 'Internal',
8409: krb4 => 'Kerberos 4',
8410: krb5 => 'Kerberos 5',
8411: loc => 'Local',
8412: );
8413: return %lt;
8414: }
8415:
8416: sub context_names {
8417: my %context_title = &Apache::lonlocal::texthash(
8418: author => 'Creating users when an Author',
8419: course => 'Creating users when in a course',
8420: domain => 'Creating users when a Domain Coordinator',
8421: );
8422: return %context_title;
8423: }
8424:
1.33 raeburn 8425: sub print_usermodification {
8426: my ($position,$dom,$settings,$rowtotal) = @_;
8427: my $numinrow = 4;
8428: my ($context,$datatable,$rowcount);
8429: if ($position eq 'top') {
8430: $rowcount = 0;
8431: $context = 'author';
8432: foreach my $role ('ca','aa') {
8433: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8434: $numinrow,$rowcount);
8435: $$rowtotal ++;
8436: $rowcount ++;
8437: }
1.160.6.37 raeburn 8438: } elsif ($position eq 'bottom') {
1.33 raeburn 8439: $context = 'course';
8440: $rowcount = 0;
8441: foreach my $role ('st','ep','ta','in','cr') {
8442: $datatable .= &modifiable_userdata_row($context,$role,$settings,
8443: $numinrow,$rowcount);
8444: $$rowtotal ++;
8445: $rowcount ++;
8446: }
8447: }
8448: return $datatable;
8449: }
8450:
1.43 raeburn 8451: sub print_defaults {
1.160.6.40 raeburn 8452: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 8453: my $rownum = 0;
1.160.6.80 raeburn 8454: my ($datatable,$css_class,$titles);
8455: unless ($position eq 'bottom') {
8456: $titles = &defaults_titles($dom);
8457: }
1.160.6.40 raeburn 8458: if ($position eq 'top') {
8459: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
8460: 'datelocale_def','portal_def');
8461: my %defaults;
8462: if (ref($settings) eq 'HASH') {
8463: %defaults = %{$settings};
1.43 raeburn 8464: } else {
1.160.6.40 raeburn 8465: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
8466: foreach my $item (@items) {
8467: $defaults{$item} = $domdefaults{$item};
8468: }
1.43 raeburn 8469: }
1.160.6.40 raeburn 8470: foreach my $item (@items) {
8471: if ($rownum%2) {
8472: $css_class = '';
8473: } else {
8474: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 8475: }
1.160.6.40 raeburn 8476: $datatable .= '<tr'.$css_class.'>'.
8477: '<td><span class="LC_nobreak">'.$titles->{$item}.
8478: '</span></td><td class="LC_right_item" colspan="3">';
8479: if ($item eq 'auth_def') {
8480: my @authtypes = ('internal','krb4','krb5','localauth');
8481: my %shortauth = (
8482: internal => 'int',
8483: krb4 => 'krb4',
8484: krb5 => 'krb5',
8485: localauth => 'loc'
8486: );
8487: my %authnames = &authtype_names();
8488: foreach my $auth (@authtypes) {
8489: my $checked = ' ';
8490: if ($defaults{$item} eq $auth) {
8491: $checked = ' checked="checked" ';
8492: }
8493: $datatable .= '<label><input type="radio" name="'.$item.
8494: '" value="'.$auth.'"'.$checked.'/>'.
8495: $authnames{$shortauth{$auth}}.'</label> ';
8496: }
8497: } elsif ($item eq 'timezone_def') {
8498: my $includeempty = 1;
8499: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
8500: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 8501: my $includeempty = 1;
8502: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
8503: } elsif ($item eq 'lang_def') {
8504: my $includeempty = 1;
8505: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.80 raeburn 8506: } else {
1.160.6.98 raeburn 8507: my $size;
8508: if ($item eq 'portal_def') {
8509: $size = ' size="25"';
8510: }
1.160.6.80 raeburn 8511: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.98 raeburn 8512: $defaults{$item}.'"'.$size.' />';
1.160.6.80 raeburn 8513: }
8514: $datatable .= '</td></tr>';
8515: $rownum ++;
8516: }
1.160.6.118.2 8(raebur 8517:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 8518: my %defaults;
1.160.6.40 raeburn 8519: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 8520: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 8521: my $maxnum = @{$settings->{'inststatusorder'}};
8522: for (my $i=0; $i<$maxnum; $i++) {
8523: $css_class = $rownum%2?' class="LC_odd_row"':'';
8524: my $item = $settings->{'inststatusorder'}->[$i];
8525: my $title = $settings->{'inststatustypes'}->{$item};
8526: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
8527: $datatable .= '<tr'.$css_class.'>'.
8528: '<td><span class="LC_nobreak">'.
8529: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
8530: for (my $k=0; $k<=$maxnum; $k++) {
8531: my $vpos = $k+1;
8532: my $selstr;
8533: if ($k == $i) {
8534: $selstr = ' selected="selected" ';
8535: }
8536: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8537: }
8538: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
8539: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
8540: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 8541: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 8542: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 8543: '</span></td></tr>';
1.160.6.40 raeburn 8544: }
8545: $css_class = $rownum%2?' class="LC_odd_row"':'';
8546: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
8547: $datatable .= '<tr '.$css_class.'>'.
8548: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
8549: for (my $k=0; $k<=$maxnum; $k++) {
8550: my $vpos = $k+1;
8551: my $selstr;
8552: if ($k == $maxnum) {
8553: $selstr = ' selected="selected" ';
8554: }
8555: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
8556: }
8557: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 8558: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 8559: ' '.&mt('(new)').
8560: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 8561: &mt('Name displayed').':'.
1.160.6.40 raeburn 8562: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
8563: '</tr>'."\n";
8564: $rownum ++;
1.141 raeburn 8565: }
1.43 raeburn 8566: }
1.160.6.118.2 8(raebur 8567:2): } else {
8568:2): my ($unamemaprules,$ruleorder) =
8569:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
8570:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
8571:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
8572:2): my $numinrow = 2;
8573:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
8574:2): &user_formats_row('unamemap',$settings,$unamemaprules,
8575:2): $ruleorder,$numinrow).
8576:2): '</table></td></tr>';
8577:2): }
8578:2): if ($datatable eq '') {
8579:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
8580:2): &mt('No rules set for domain in customized localenroll.pm').
8581:2): '</td></tr>';
8582:2): }
1.43 raeburn 8583: }
8584: $$rowtotal += $rownum;
8585: return $datatable;
8586: }
8587:
1.160.6.5 raeburn 8588: sub get_languages_hash {
8589: my %langchoices;
8590: foreach my $id (&Apache::loncommon::languageids()) {
8591: my $code = &Apache::loncommon::supportedlanguagecode($id);
8592: if ($code ne '') {
8593: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
8594: }
8595: }
8596: return %langchoices;
8597: }
8598:
1.43 raeburn 8599: sub defaults_titles {
1.141 raeburn 8600: my ($dom) = @_;
1.43 raeburn 8601: my %titles = &Apache::lonlocal::texthash (
8602: 'auth_def' => 'Default authentication type',
8603: 'auth_arg_def' => 'Default authentication argument',
8604: 'lang_def' => 'Default language',
1.54 raeburn 8605: 'timezone_def' => 'Default timezone',
1.68 raeburn 8606: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 8607: 'portal_def' => 'Portal/Default URL',
1.160.6.80 raeburn 8608: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
8609: 'intauth_check' => 'Check bcrypt cost if authenticated',
8610: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 8611: );
1.141 raeburn 8612: if ($dom) {
8613: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
8614: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
8615: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
8616: $protocol = 'http' if ($protocol ne 'https');
8617: if ($uint_dom) {
8618: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
8619: $uint_dom);
8620: }
8621: }
1.43 raeburn 8622: return (\%titles);
8623: }
8624:
1.160.6.97 raeburn 8625: sub print_scantron {
8626: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
8627: if ($position eq 'top') {
8628: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
8629: } else {
8630: return &print_scantronconfig($dom,$settings,\$rowtotal);
8631: }
8632: }
8633:
8634: sub scantron_javascript {
8635: return <<"ENDSCRIPT";
8636:
8637: <script type="text/javascript">
8638: // <![CDATA[
8639:
8640: function toggleScantron(form) {
8641: var csvfieldset = new Array();
8642: if (document.getElementById('scantroncsv_cols')) {
8643: csvfieldset.push(document.getElementById('scantroncsv_cols'));
8644: }
8645: if (document.getElementById('scantroncsv_options')) {
8646: csvfieldset.push(document.getElementById('scantroncsv_options'));
8647: }
8648: if (csvfieldset.length) {
8649: if (document.getElementById('scantronconfcsv')) {
8650: var scantroncsv = document.getElementById('scantronconfcsv');
8651: if (scantroncsv.checked) {
8652: for (var i=0; i<csvfieldset.length; i++) {
8653: csvfieldset[i].style.display = 'block';
8654: }
8655: } else {
8656: for (var i=0; i<csvfieldset.length; i++) {
8657: csvfieldset[i].style.display = 'none';
8658: }
8659: var csvselects = document.getElementsByClassName('scantronconfig_csv');
8660: if (csvselects.length) {
8661: for (var j=0; j<csvselects.length; j++) {
8662: csvselects[j].selectedIndex = 0;
8663: }
8664: }
8665: }
8666: }
8667: }
8668: return;
8669: }
8670: // ]]>
8671: </script>
8672:
8673: ENDSCRIPT
8674:
8675: }
8676:
1.46 raeburn 8677: sub print_scantronformat {
8678: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
8679: my $itemcount = 1;
1.60 raeburn 8680: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
8681: %confhash);
1.46 raeburn 8682: my $switchserver = &check_switchserver($dom,$confname);
8683: my %lt = &Apache::lonlocal::texthash (
1.95 www 8684: default => 'Default bubblesheet format file error',
8685: custom => 'Custom bubblesheet format file error',
1.46 raeburn 8686: );
8687: my %scantronfiles = (
8688: default => 'default.tab',
8689: custom => 'custom.tab',
8690: );
8691: foreach my $key (keys(%scantronfiles)) {
8692: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
8693: .$scantronfiles{$key};
8694: }
8695: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
8696: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
8697: if (!$switchserver) {
8698: my $servadm = $r->dir_config('lonAdmEMail');
8699: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
8700: if ($configuserok eq 'ok') {
8701: if ($author_ok eq 'ok') {
8702: my %legacyfile = (
1.160.6.97 raeburn 8703: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
8704: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 8705: );
8706: my %md5chk;
8707: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 8708: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
8709: chomp($md5chk{$type});
1.46 raeburn 8710: }
8711: if ($md5chk{'default'} ne $md5chk{'custom'}) {
8712: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 8713: ($scantronurls{$type},my $error) =
1.46 raeburn 8714: &legacy_scantronformat($r,$dom,$confname,
8715: $type,$legacyfile{$type},
8716: $scantronurls{$type},
8717: $scantronfiles{$type});
1.60 raeburn 8718: if ($error ne '') {
8719: $error{$type} = $error;
8720: }
8721: }
8722: if (keys(%error) == 0) {
8723: $is_custom = 1;
1.160.6.97 raeburn 8724: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 8725: $scantronurls{'custom'};
1.160.6.97 raeburn 8726: my $putresult =
1.60 raeburn 8727: &Apache::lonnet::put_dom('configuration',
8728: \%confhash,$dom);
8729: if ($putresult ne 'ok') {
1.160.6.97 raeburn 8730: $error{'custom'} =
1.60 raeburn 8731: '<span class="LC_error">'.
8732: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8733: }
1.46 raeburn 8734: }
8735: } else {
1.60 raeburn 8736: ($scantronurls{'default'},my $error) =
1.46 raeburn 8737: &legacy_scantronformat($r,$dom,$confname,
8738: 'default',$legacyfile{'default'},
8739: $scantronurls{'default'},
8740: $scantronfiles{'default'});
1.60 raeburn 8741: if ($error eq '') {
8742: $confhash{'scantron'}{'scantronformat'} = '';
8743: my $putresult =
8744: &Apache::lonnet::put_dom('configuration',
8745: \%confhash,$dom);
8746: if ($putresult ne 'ok') {
8747: $error{'default'} =
8748: '<span class="LC_error">'.
8749: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
8750: }
8751: } else {
8752: $error{'default'} = $error;
8753: }
1.46 raeburn 8754: }
8755: }
8756: }
8757: } else {
1.95 www 8758: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 8759: }
8760: }
8761: if (ref($settings) eq 'HASH') {
8762: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
8763: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
8764: if ((!@info) || ($info[0] eq 'no_such_dir')) {
8765: $scantronurl = '';
8766: } else {
8767: $scantronurl = $settings->{'scantronformat'};
8768: }
8769: $is_custom = 1;
8770: } else {
8771: $scantronurl = $scantronurls{'default'};
8772: }
8773: } else {
1.60 raeburn 8774: if ($is_custom) {
8775: $scantronurl = $scantronurls{'custom'};
8776: } else {
8777: $scantronurl = $scantronurls{'default'};
8778: }
1.46 raeburn 8779: }
8780: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8781: $datatable .= '<tr'.$css_class.'>';
8782: if (!$is_custom) {
1.65 raeburn 8783: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
8784: '<span class="LC_nobreak">';
1.46 raeburn 8785: if ($scantronurl) {
1.160.6.21 raeburn 8786: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
8787: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 8788: } else {
8789: $datatable = &mt('File unavailable for display');
8790: }
1.65 raeburn 8791: $datatable .= '</span></td>';
1.60 raeburn 8792: if (keys(%error) == 0) {
8793: $datatable .= '<td valign="bottom">';
8794: if (!$switchserver) {
8795: $datatable .= &mt('Upload:').'<br />';
8796: }
8797: } else {
8798: my $errorstr;
8799: foreach my $key (sort(keys(%error))) {
8800: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8801: }
8802: $datatable .= '<td>'.$errorstr;
8803: }
1.46 raeburn 8804: } else {
8805: if (keys(%error) > 0) {
8806: my $errorstr;
8807: foreach my $key (sort(keys(%error))) {
8808: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
8809: }
1.60 raeburn 8810: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 8811: } elsif ($scantronurl) {
1.160.6.26 raeburn 8812: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 8813: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 8814: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 8815: $link.
8816: '<label><input type="checkbox" name="scantronformat_del"'.
8817: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 8818: '<td><span class="LC_nobreak"> '.
8819: &mt('Replace:').'</span><br />';
1.46 raeburn 8820: }
8821: }
8822: if (keys(%error) == 0) {
8823: if ($switchserver) {
8824: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
8825: } else {
1.65 raeburn 8826: $datatable .='<span class="LC_nobreak"> '.
8827: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 8828: }
8829: }
8830: $datatable .= '</td></tr>';
8831: $$rowtotal ++;
8832: return $datatable;
8833: }
8834:
8835: sub legacy_scantronformat {
8836: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
8837: my ($url,$error);
8838: my @statinfo = &Apache::lonnet::stat_file($newurl);
8839: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
8840: (my $result,$url) =
8841: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
8842: '','',$newfile);
8843: if ($result ne 'ok') {
1.130 raeburn 8844: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 8845: }
8846: }
8847: return ($url,$error);
8848: }
1.43 raeburn 8849:
1.160.6.97 raeburn 8850: sub print_scantronconfig {
8851: my ($dom,$settings,$rowtotal) = @_;
8852: my $itemcount = 2;
8853: my $is_checked = ' checked="checked"';
8854: my %optionson = (
8855: hdr => ' checked="checked"',
8856: pad => ' checked="checked"',
8857: rem => ' checked="checked"',
8858: );
8859: my %optionsoff = (
8860: hdr => '',
8861: pad => '',
8862: rem => '',
8863: );
8864: my $currcsvsty = 'none';
8865: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
8866: my @fields = &scantroncsv_fields();
8867: my %titles = &scantronconfig_titles();
8868: if (ref($settings) eq 'HASH') {
8869: if (ref($settings->{config}) eq 'HASH') {
8870: if ($settings->{config}->{dat}) {
8871: $checked{'dat'} = $is_checked;
8872: }
8873: if (ref($settings->{config}->{csv}) eq 'HASH') {
8874: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
8875: %csvfields = %{$settings->{config}->{csv}->{fields}};
8876: if (keys(%csvfields) > 0) {
8877: $checked{'csv'} = $is_checked;
8878: $currcsvsty = 'block';
8879: }
8880: }
8881: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
8882: %csvoptions = %{$settings->{config}->{csv}->{options}};
8883: foreach my $option (keys(%optionson)) {
8884: unless ($csvoptions{$option}) {
8885: $optionsoff{$option} = $optionson{$option};
8886: $optionson{$option} = '';
8887: }
8888: }
8889: }
8890: }
8891: } else {
8892: $checked{'dat'} = $is_checked;
8893: }
8894: } else {
8895: $checked{'dat'} = $is_checked;
8896: }
8897: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
8898: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
8899: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
8900: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
8901: foreach my $item ('dat','csv') {
8902: my $id;
8903: if ($item eq 'csv') {
8904: $id = 'id="scantronconfcsv" ';
8905: }
8906: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
8907: $titles{$item}.'</label>'.(' 'x3);
8908: if ($item eq 'csv') {
8909: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
8910: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
8911: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
8912: foreach my $col (@fields) {
8913: my $selnone;
8914: if ($csvfields{$col} eq '') {
8915: $selnone = ' selected="selected"';
8916: }
8917: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
8918: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
8919: '<option value=""'.$selnone.'></option>';
8920: for (my $i=0; $i<20; $i++) {
8921: my $shown = $i+1;
8922: my $sel;
8923: unless ($selnone) {
8924: if (exists($csvfields{$col})) {
8925: if ($csvfields{$col} == $i) {
8926: $sel = ' selected="selected"';
8927: }
8928: }
8929: }
8930: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
8931: }
8932: $datatable .= '</select></td></tr>';
8933: }
8934: $datatable .= '</table></fieldset>'.
8935: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
8936: '<legend>'.&mt('CSV Options').'</legend>';
8937: foreach my $option ('hdr','pad','rem') {
8938: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
8939: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
8940: &mt('Yes').'</label>'.(' 'x2)."\n".
8941: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
8942: }
8943: $datatable .= '</fieldset>';
8944: $itemcount ++;
8945: }
8946: }
8947: $datatable .= '</td></tr>';
8948: $$rowtotal ++;
8949: return $datatable;
8950: }
8951:
8952: sub scantronconfig_titles {
8953: return &Apache::lonlocal::texthash(
8954: dat => 'Standard format (.dat)',
8955: csv => 'Comma separated values (.csv)',
8956: hdr => 'Remove first line in file (contains column titles)',
8957: pad => 'Prepend 0s to PaperID',
8958: rem => 'Remove leading spaces (except Question Response columns)',
8959: CODE => 'CODE',
8960: ID => 'Student ID',
8961: PaperID => 'Paper ID',
8962: FirstName => 'First Name',
8963: LastName => 'Last Name',
8964: FirstQuestion => 'First Question Response',
8965: Section => 'Section',
8966: );
8967: }
8968:
8969: sub scantroncsv_fields {
8970: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
8971: }
8972:
1.49 raeburn 8973: sub print_coursecategories {
1.57 raeburn 8974: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
8975: my $datatable;
8976: if ($position eq 'top') {
1.160.6.42 raeburn 8977: my (%checked);
8978: my @catitems = ('unauth','auth');
8979: my @cattypes = ('std','domonly','codesrch','none');
8980: $checked{'unauth'} = 'std';
8981: $checked{'auth'} = 'std';
8982: if (ref($settings) eq 'HASH') {
8983: foreach my $type (@cattypes) {
8984: if ($type eq $settings->{'unauth'}) {
8985: $checked{'unauth'} = $type;
8986: }
8987: if ($type eq $settings->{'auth'}) {
8988: $checked{'auth'} = $type;
8989: }
8990: }
8991: }
8992: my %lt = &Apache::lonlocal::texthash (
8993: unauth => 'Catalog type for unauthenticated users',
8994: auth => 'Catalog type for authenticated users',
8995: none => 'No catalog',
8996: std => 'Standard catalog',
8997: domonly => 'Domain-only catalog',
8998: codesrch => "Code search form",
8999: );
9000: my $itemcount = 0;
9001: foreach my $item (@catitems) {
9002: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9003: $datatable .= '<tr '.$css_class.'>'.
9004: '<td>'.$lt{$item}.'</td>'.
9005: '<td class="LC_right_item"><span class="LC_nobreak">';
9006: foreach my $type (@cattypes) {
9007: my $ischecked;
9008: if ($checked{$item} eq $type) {
9009: $ischecked=' checked="checked"';
9010: }
9011: $datatable .= '<label>'.
9012: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9013: ' />'.$lt{$type}.'</label> ';
9014: }
1.160.6.87 raeburn 9015: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 9016: $itemcount ++;
9017: }
9018: $$rowtotal += $itemcount;
9019: } elsif ($position eq 'middle') {
1.57 raeburn 9020: my $toggle_cats_crs = ' ';
9021: my $toggle_cats_dom = ' checked="checked" ';
9022: my $can_cat_crs = ' ';
9023: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9024: my $toggle_catscomm_comm = ' ';
9025: my $toggle_catscomm_dom = ' checked="checked" ';
9026: my $can_catcomm_comm = ' ';
9027: my $can_catcomm_dom = ' checked="checked" ';
9028:
1.57 raeburn 9029: if (ref($settings) eq 'HASH') {
9030: if ($settings->{'togglecats'} eq 'crs') {
9031: $toggle_cats_crs = $toggle_cats_dom;
9032: $toggle_cats_dom = ' ';
9033: }
9034: if ($settings->{'categorize'} eq 'crs') {
9035: $can_cat_crs = $can_cat_dom;
9036: $can_cat_dom = ' ';
9037: }
1.120 raeburn 9038: if ($settings->{'togglecatscomm'} eq 'comm') {
9039: $toggle_catscomm_comm = $toggle_catscomm_dom;
9040: $toggle_catscomm_dom = ' ';
9041: }
9042: if ($settings->{'categorizecomm'} eq 'comm') {
9043: $can_catcomm_comm = $can_catcomm_dom;
9044: $can_catcomm_dom = ' ';
9045: }
1.57 raeburn 9046: }
9047: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 9048: togglecats => 'Show/Hide a course in catalog',
9049: togglecatscomm => 'Show/Hide a community in catalog',
9050: categorize => 'Assign a category to a course',
9051: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9052: );
9053: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 9054: dom => 'Set in Domain',
9055: crs => 'Set in Course',
9056: comm => 'Set in Community',
1.57 raeburn 9057: );
9058: $datatable = '<tr class="LC_odd_row">'.
9059: '<td>'.$title{'togglecats'}.'</td>'.
9060: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9061: '<input type="radio" name="togglecats"'.
9062: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9063: '<label><input type="radio" name="togglecats"'.
9064: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9065: '</tr><tr>'.
9066: '<td>'.$title{'categorize'}.'</td>'.
9067: '<td class="LC_right_item"><span class="LC_nobreak">'.
9068: '<label><input type="radio" name="categorize"'.
9069: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9070: '<label><input type="radio" name="categorize"'.
9071: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9072: '</tr><tr class="LC_odd_row">'.
9073: '<td>'.$title{'togglecatscomm'}.'</td>'.
9074: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9075: '<input type="radio" name="togglecatscomm"'.
9076: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9077: '<label><input type="radio" name="togglecatscomm"'.
9078: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9079: '</tr><tr>'.
9080: '<td>'.$title{'categorizecomm'}.'</td>'.
9081: '<td class="LC_right_item"><span class="LC_nobreak">'.
9082: '<label><input type="radio" name="categorizecomm"'.
9083: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9084: '<label><input type="radio" name="categorizecomm"'.
9085: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 9086: '</tr>';
1.120 raeburn 9087: $$rowtotal += 4;
1.57 raeburn 9088: } else {
9089: my $css_class;
9090: my $itemcount = 1;
9091: my $cathash;
9092: if (ref($settings) eq 'HASH') {
9093: $cathash = $settings->{'cats'};
9094: }
9095: if (ref($cathash) eq 'HASH') {
9096: my (@cats,@trails,%allitems,%idx,@jsarray);
9097: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9098: \%allitems,\%idx,\@jsarray);
9099: my $maxdepth = scalar(@cats);
9100: my $colattrib = '';
9101: if ($maxdepth > 2) {
9102: $colattrib = ' colspan="2" ';
9103: }
9104: my @path;
9105: if (@cats > 0) {
9106: if (ref($cats[0]) eq 'ARRAY') {
9107: my $numtop = @{$cats[0]};
9108: my $maxnum = $numtop;
1.120 raeburn 9109: my %default_names = (
9110: instcode => &mt('Official courses'),
9111: communities => &mt('Communities'),
9112: );
9113:
9114: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9115: ($cathash->{'instcode::0'} eq '') ||
9116: (!grep(/^communities$/,@{$cats[0]})) ||
9117: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 9118: $maxnum ++;
9119: }
9120: my $lastidx;
9121: for (my $i=0; $i<$numtop; $i++) {
9122: my $parent = $cats[0][$i];
9123: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9124: my $item = &escape($parent).'::0';
9125: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9126: $lastidx = $idx{$item};
9127: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9128: .'<select name="'.$item.'"'.$chgstr.'>';
9129: for (my $k=0; $k<=$maxnum; $k++) {
9130: my $vpos = $k+1;
9131: my $selstr;
9132: if ($k == $i) {
9133: $selstr = ' selected="selected" ';
9134: }
9135: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9136: }
1.160.6.29 raeburn 9137: $datatable .= '</select></span></td><td>';
1.120 raeburn 9138: if ($parent eq 'instcode' || $parent eq 'communities') {
9139: $datatable .= '<span class="LC_nobreak">'
9140: .$default_names{$parent}.'</span>';
9141: if ($parent eq 'instcode') {
9142: $datatable .= '<br /><span class="LC_nobreak">('
9143: .&mt('with institutional codes')
9144: .')</span></td><td'.$colattrib.'>';
9145: } else {
9146: $datatable .= '<table><tr><td>';
9147: }
9148: $datatable .= '<span class="LC_nobreak">'
9149: .'<label><input type="radio" name="'
9150: .$parent.'" value="1" checked="checked" />'
9151: .&mt('Display').'</label>';
9152: if ($parent eq 'instcode') {
9153: $datatable .= ' ';
9154: } else {
9155: $datatable .= '</span></td></tr><tr><td>'
9156: .'<span class="LC_nobreak">';
9157: }
9158: $datatable .= '<label><input type="radio" name="'
9159: .$parent.'" value="0" />'
9160: .&mt('Do not display').'</label></span>';
9161: if ($parent eq 'communities') {
9162: $datatable .= '</td></tr></table>';
9163: }
9164: $datatable .= '</td>';
1.57 raeburn 9165: } else {
9166: $datatable .= $parent
1.160.6.29 raeburn 9167: .' <span class="LC_nobreak"><label>'
9168: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9169: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9170: }
9171: my $depth = 1;
9172: push(@path,$parent);
9173: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9174: pop(@path);
9175: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9176: $itemcount ++;
9177: }
1.48 raeburn 9178: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9179: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9180: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9181: for (my $k=0; $k<=$maxnum; $k++) {
9182: my $vpos = $k+1;
9183: my $selstr;
1.57 raeburn 9184: if ($k == $numtop) {
1.48 raeburn 9185: $selstr = ' selected="selected" ';
9186: }
9187: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9188: }
1.59 bisitz 9189: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9190: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9191: .'</tr>'."\n";
1.48 raeburn 9192: $itemcount ++;
1.120 raeburn 9193: foreach my $default ('instcode','communities') {
9194: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9195: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9196: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9197: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9198: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9199: for (my $k=0; $k<=$maxnum; $k++) {
9200: my $vpos = $k+1;
9201: my $selstr;
9202: if ($k == $maxnum) {
9203: $selstr = ' selected="selected" ';
9204: }
9205: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9206: }
1.120 raeburn 9207: $datatable .= '</select></span></td>'.
9208: '<td><span class="LC_nobreak">'.
9209: $default_names{$default}.'</span>';
9210: if ($default eq 'instcode') {
9211: $datatable .= '<br /><span class="LC_nobreak">('
9212: .&mt('with institutional codes').')</span>';
9213: }
9214: $datatable .= '</td>'
9215: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9216: .&mt('Display').'</label> '
9217: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9218: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9219: }
9220: }
9221: }
1.57 raeburn 9222: } else {
9223: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9224: }
9225: } else {
1.160.6.87 raeburn 9226: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9227: .&initialize_categories($itemcount);
1.48 raeburn 9228: }
1.57 raeburn 9229: $$rowtotal += $itemcount;
1.48 raeburn 9230: }
9231: return $datatable;
9232: }
9233:
1.69 raeburn 9234: sub print_serverstatuses {
9235: my ($dom,$settings,$rowtotal) = @_;
9236: my $datatable;
9237: my @pages = &serverstatus_pages();
9238: my (%namedaccess,%machineaccess);
9239: foreach my $type (@pages) {
9240: $namedaccess{$type} = '';
9241: $machineaccess{$type}= '';
9242: }
9243: if (ref($settings) eq 'HASH') {
9244: foreach my $type (@pages) {
9245: if (exists($settings->{$type})) {
9246: if (ref($settings->{$type}) eq 'HASH') {
9247: foreach my $key (keys(%{$settings->{$type}})) {
9248: if ($key eq 'namedusers') {
9249: $namedaccess{$type} = $settings->{$type}->{$key};
9250: } elsif ($key eq 'machines') {
9251: $machineaccess{$type} = $settings->{$type}->{$key};
9252: }
9253: }
9254: }
9255: }
9256: }
9257: }
1.81 raeburn 9258: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9259: my $rownum = 0;
9260: my $css_class;
9261: foreach my $type (@pages) {
9262: $rownum ++;
9263: $css_class = $rownum%2?' class="LC_odd_row"':'';
9264: $datatable .= '<tr'.$css_class.'>'.
9265: '<td><span class="LC_nobreak">'.
9266: $titles->{$type}.'</span></td>'.
9267: '<td class="LC_left_item">'.
9268: '<input type="text" name="'.$type.'_namedusers" '.
9269: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9270: '<td class="LC_right_item">'.
9271: '<span class="LC_nobreak">'.
9272: '<input type="text" name="'.$type.'_machines" '.
9273: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 9274: '</span></td></tr>'."\n";
1.69 raeburn 9275: }
9276: $$rowtotal += $rownum;
9277: return $datatable;
9278: }
9279:
9280: sub serverstatus_pages {
9281: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 9282: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 9283: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 9284: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9285: }
9286:
1.160.6.40 raeburn 9287: sub defaults_javascript {
9288: my ($settings) = @_;
1.160.6.98 raeburn 9289: return unless (ref($settings) eq 'HASH');
1.160.6.40 raeburn 9290: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9291: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9292: if ($maxnum eq '') {
9293: $maxnum = 0;
9294: }
9295: $maxnum ++;
1.160.6.51 raeburn 9296: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 9297: return <<"ENDSCRIPT";
9298: <script type="text/javascript">
9299: // <![CDATA[
9300: function reorderTypes(form,caller) {
9301: var changedVal;
9302: $jstext
9303: var newpos = 'addinststatus_pos';
9304: var current = new Array;
9305: var maxh = $maxnum;
9306: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9307: var oldVal;
9308: if (caller == newpos) {
9309: changedVal = newitemVal;
9310: } else {
9311: var curritem = 'inststatus_pos_'+caller;
9312: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9313: current[newitemVal] = newpos;
9314: }
9315: for (var i=0; i<inststatuses.length; i++) {
9316: if (inststatuses[i] != caller) {
9317: var elementName = 'inststatus_pos_'+inststatuses[i];
9318: if (form.elements[elementName]) {
9319: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9320: current[currVal] = elementName;
9321: }
9322: }
9323: }
9324: for (var j=0; j<maxh; j++) {
9325: if (current[j] == undefined) {
9326: oldVal = j;
9327: }
9328: }
9329: if (oldVal < changedVal) {
9330: for (var k=oldVal+1; k<=changedVal ; k++) {
9331: var elementName = current[k];
9332: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9333: }
9334: } else {
9335: for (var k=changedVal; k<oldVal; k++) {
9336: var elementName = current[k];
9337: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9338: }
9339: }
9340: return;
9341: }
9342:
9343: // ]]>
9344: </script>
9345:
9346: ENDSCRIPT
9347: }
9348: }
9349:
1.160.6.98 raeburn 9350: sub passwords_javascript {
1.160.6.118.2 5(raebur 9351:2): my ($prefix) = @_;
9352:2): my %intalert;
9353:2): if ($prefix eq 'passwords') {
9354:2): %intalert = &Apache::lonlocal::texthash (
9355: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.',
9356:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
9357:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
9358:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
9359:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
9360:2): );
9361:2): } elsif ($prefix eq 'secrets') {
9362:2): %intalert = &Apache::lonlocal::texthash (
9363:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
9364:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
9365:2): );
9366:2): }
1.160.6.99 raeburn 9367: &js_escape(\%intalert);
9368: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 9369:2): my $intauthjs;
9370:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 9371:
9372: function warnIntAuth(field) {
9373: if (field.name == 'intauth_check') {
9374: if (field.value == '2') {
1.160.6.99 raeburn 9375: alert('$intalert{authcheck}');
1.160.6.98 raeburn 9376: }
9377: }
9378: if (field.name == 'intauth_cost') {
9379: field.value.replace(/\s/g,'');
9380: if (field.value != '') {
9381: var regexdigit=/^\\d+\$/;
9382: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 9383: alert('$intalert{authcost}');
9384: }
9385: }
9386: }
9387: return;
9388: }
9389:
1.160.6.118.2 5(raebur 9390:2): ENDSCRIPT
9391:2):
9392:2): }
9393:2):
9394:2): $intauthjs .= <<"ENDSCRIPT";
9395:2):
9396:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 9397: field.value.replace(/^\s+/,'');
9398: field.value.replace(/\s+\$/,'');
9399: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 9400:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 9401: if (field.value == '') {
9402: alert('$intalert{passmin}');
9403: field.value = '$defmin';
9404: } else {
9405: if (!regexdigit.test(field.value)) {
9406: alert('$intalert{passmin}');
9407: field.value = '$defmin';
9408: }
9409: var minval = parseInt(field.value,10);
9410: if (minval < $defmin) {
9411: alert('$intalert{passmin}');
9412: field.value = '$defmin';
9413: }
9414: }
9415: } else {
9416: if (field.value == '0') {
9417: field.value = '';
9418: }
9419: if (field.value != '') {
1.160.6.118.2 5(raebur 9420:2): if (!regexdigit.test(field.value)) {
9421:2): if (field.name == '${prefix}_max') {
9422:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 9423: } else {
1.160.6.118.2 5(raebur 9424:2): if (field.name == '${prefix}_numsaved') {
9425:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 9426: }
9427: }
1.160.6.118.2 5(raebur 9428:2): field.value = '';
1.160.6.98 raeburn 9429: }
9430: }
9431: }
9432: return;
9433: }
9434:
9435: ENDSCRIPT
9436: return &Apache::lonhtmlcommon::scripttag($intauthjs);
9437: }
9438:
1.49 raeburn 9439: sub coursecategories_javascript {
9440: my ($settings) = @_;
1.57 raeburn 9441: my ($output,$jstext,$cathash);
1.49 raeburn 9442: if (ref($settings) eq 'HASH') {
1.57 raeburn 9443: $cathash = $settings->{'cats'};
9444: }
9445: if (ref($cathash) eq 'HASH') {
1.49 raeburn 9446: my (@cats,@jsarray,%idx);
1.57 raeburn 9447: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 9448: if (@jsarray > 0) {
9449: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
9450: for (my $i=0; $i<@jsarray; $i++) {
9451: if (ref($jsarray[$i]) eq 'ARRAY') {
9452: my $catstr = join('","',@{$jsarray[$i]});
9453: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
9454: }
9455: }
9456: }
9457: } else {
9458: $jstext = ' var categories = Array(1);'."\n".
9459: ' categories[0] = Array("instcode_pos");'."\n";
9460: }
1.160.6.42 raeburn 9461: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
9462: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 9463: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
9464: &js_escape(\$instcode_reserved);
9465: &js_escape(\$communities_reserved);
9466: &js_escape(\$choose_again);
1.49 raeburn 9467: $output = <<"ENDSCRIPT";
9468: <script type="text/javascript">
1.109 raeburn 9469: // <![CDATA[
1.49 raeburn 9470: function reorderCats(form,parent,item,idx) {
9471: var changedVal;
9472: $jstext
9473: var newpos = 'addcategory_pos';
9474: if (parent == '') {
9475: var has_instcode = 0;
9476: var maxtop = categories[idx].length;
9477: for (var j=0; j<maxtop; j++) {
9478: if (categories[idx][j] == 'instcode::0') {
9479: has_instcode == 1;
9480: }
9481: }
9482: if (has_instcode == 0) {
9483: categories[idx][maxtop] = 'instcode_pos';
9484: }
9485: } else {
9486: newpos += '_'+parent;
9487: }
9488: var maxh = 1 + categories[idx].length;
9489: var current = new Array;
9490: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9491: if (item == newpos) {
9492: changedVal = newitemVal;
9493: } else {
9494: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
9495: current[newitemVal] = newpos;
9496: }
9497: for (var i=0; i<categories[idx].length; i++) {
9498: var elementName = categories[idx][i];
9499: if (elementName != item) {
9500: if (form.elements[elementName]) {
9501: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
9502: current[currVal] = elementName;
9503: }
9504: }
9505: }
9506: var oldVal;
9507: for (var j=0; j<maxh; j++) {
9508: if (current[j] == undefined) {
9509: oldVal = j;
9510: }
9511: }
9512: if (oldVal < changedVal) {
9513: for (var k=oldVal+1; k<=changedVal ; k++) {
9514: var elementName = current[k];
9515: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
9516: }
9517: } else {
9518: for (var k=changedVal; k<oldVal; k++) {
9519: var elementName = current[k];
9520: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
9521: }
9522: }
9523: return;
9524: }
1.120 raeburn 9525:
9526: function categoryCheck(form) {
9527: if (form.elements['addcategory_name'].value == 'instcode') {
9528: alert('$instcode_reserved\\n$choose_again');
9529: return false;
9530: }
9531: if (form.elements['addcategory_name'].value == 'communities') {
9532: alert('$communities_reserved\\n$choose_again');
9533: return false;
9534: }
9535: return true;
9536: }
9537:
1.109 raeburn 9538: // ]]>
1.49 raeburn 9539: </script>
9540:
9541: ENDSCRIPT
9542: return $output;
9543: }
9544:
1.48 raeburn 9545: sub initialize_categories {
9546: my ($itemcount) = @_;
1.120 raeburn 9547: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 9548: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 9549: instcode => 'Official courses (with institutional codes)',
9550: communities => 'Communities',
9551: );
9552: my $select0 = ' selected="selected"';
9553: my $select1 = '';
9554: foreach my $default ('instcode','communities') {
9555: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 9556: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 9557: if ($default eq 'communities') {
9558: $select1 = $select0;
9559: $select0 = '';
9560: }
9561: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9562: .'<select name="'.$default.'_pos">'
9563: .'<option value="0"'.$select0.'>1</option>'
9564: .'<option value="1"'.$select1.'>2</option>'
9565: .'<option value="2">3</option></select> '
9566: .$default_names{$default}
9567: .'</span></td><td><span class="LC_nobreak">'
9568: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
9569: .&mt('Display').'</label> <label>'
9570: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 9571: .'</label></span></td></tr>';
1.120 raeburn 9572: $itemcount ++;
9573: }
1.48 raeburn 9574: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 9575: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 9576: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 9577: .'<select name="addcategory_pos"'.$chgstr.'>'
9578: .'<option value="0">1</option>'
9579: .'<option value="1">2</option>'
9580: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 9581: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 9582: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
9583: .'</td></tr>';
1.48 raeburn 9584: return $datatable;
9585: }
9586:
9587: sub build_category_rows {
1.49 raeburn 9588: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
9589: my ($text,$name,$item,$chgstr);
1.48 raeburn 9590: if (ref($cats) eq 'ARRAY') {
9591: my $maxdepth = scalar(@{$cats});
9592: if (ref($cats->[$depth]) eq 'HASH') {
9593: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
9594: my $numchildren = @{$cats->[$depth]{$parent}};
9595: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 9596: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 9597: my ($idxnum,$parent_name,$parent_item);
9598: my $higher = $depth - 1;
9599: if ($higher == 0) {
9600: $parent_name = &escape($parent).'::'.$higher;
9601: } else {
9602: if (ref($path) eq 'ARRAY') {
9603: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9604: }
9605: }
9606: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 9607: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 9608: if ($j < $numchildren) {
1.48 raeburn 9609: $name = $cats->[$depth]{$parent}[$j];
9610: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 9611: $idxnum = $idx->{$item};
9612: } else {
9613: $name = $parent_name;
9614: $item = $parent_item;
1.48 raeburn 9615: }
1.49 raeburn 9616: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
9617: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 9618: for (my $i=0; $i<=$numchildren; $i++) {
9619: my $vpos = $i+1;
9620: my $selstr;
9621: if ($j == $i) {
9622: $selstr = ' selected="selected" ';
9623: }
9624: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
9625: }
9626: $text .= '</select> ';
9627: if ($j < $numchildren) {
9628: my $deeper = $depth+1;
9629: $text .= $name.' '
9630: .'<label><input type="checkbox" name="deletecategory" value="'
9631: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
9632: if(ref($path) eq 'ARRAY') {
9633: push(@{$path},$name);
1.49 raeburn 9634: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 9635: pop(@{$path});
9636: }
9637: } else {
1.160.6.87 raeburn 9638: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 9639: if ($j == $numchildren) {
9640: $text .= $name;
9641: } else {
9642: $text .= $item;
9643: }
9644: $text .= '" value="" />';
9645: }
9646: $text .= '</td></tr>';
9647: }
9648: $text .= '</table></td>';
9649: } else {
9650: my $higher = $depth-1;
9651: if ($higher == 0) {
9652: $name = &escape($parent).'::'.$higher;
9653: } else {
9654: if (ref($path) eq 'ARRAY') {
9655: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
9656: }
9657: }
9658: my $colspan;
9659: if ($parent ne 'instcode') {
9660: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 9661: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 9662: }
9663: }
9664: }
9665: }
9666: return $text;
9667: }
9668:
1.33 raeburn 9669: sub modifiable_userdata_row {
1.160.6.93 raeburn 9670: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
9671: $rowid,$customcss,$rowstyle) = @_;
1.160.6.35 raeburn 9672: my ($role,$rolename,$statustype);
9673: $role = $item;
1.160.6.34 raeburn 9674: if ($context eq 'cancreate') {
1.160.6.93 raeburn 9675: if ($item =~ /^(emailusername)_(.+)$/) {
9676: $role = $1;
9677: $statustype = $2;
1.160.6.35 raeburn 9678: if (ref($usertypes) eq 'HASH') {
9679: if ($usertypes->{$statustype}) {
9680: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
9681: } else {
9682: $rolename = &mt('Data provided by user');
9683: }
9684: }
1.160.6.34 raeburn 9685: }
9686: } elsif ($context eq 'selfcreate') {
1.63 raeburn 9687: if (ref($usertypes) eq 'HASH') {
9688: $rolename = $usertypes->{$role};
9689: } else {
9690: $rolename = $role;
9691: }
1.33 raeburn 9692: } else {
1.63 raeburn 9693: if ($role eq 'cr') {
9694: $rolename = &mt('Custom role');
9695: } else {
9696: $rolename = &Apache::lonnet::plaintext($role);
9697: }
1.33 raeburn 9698: }
1.160.6.34 raeburn 9699: my (@fields,%fieldtitles);
9700: if (ref($fieldsref) eq 'ARRAY') {
9701: @fields = @{$fieldsref};
9702: } else {
9703: @fields = ('lastname','firstname','middlename','generation',
9704: 'permanentemail','id');
9705: }
9706: if ((ref($titlesref) eq 'HASH')) {
9707: %fieldtitles = %{$titlesref};
9708: } else {
9709: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9710: }
1.33 raeburn 9711: my $output;
1.160.6.93 raeburn 9712: my $css_class;
9713: if ($rowcount%2) {
9714: $css_class = 'LC_odd_row';
9715: }
9716: if ($customcss) {
9717: $css_class .= " $customcss";
9718: }
9719: $css_class =~ s/^\s+//;
9720: if ($css_class) {
9721: $css_class = ' class="'.$css_class.'"';
9722: }
9723: if ($rowstyle) {
9724: $css_class .= ' style="'.$rowstyle.'"';
9725: }
9726: if ($rowid) {
9727: $rowid = ' id="'.$rowid.'"';
9728: }
9729:
9730: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 9731: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
9732: '<td class="LC_left_item" colspan="2"><table>';
9733: my $rem;
9734: my %checks;
9735: if (ref($settings) eq 'HASH') {
9736: if (ref($settings->{$context}) eq 'HASH') {
9737: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.35 raeburn 9738: my $hashref = $settings->{$context}->{$role};
9739: if ($role eq 'emailusername') {
9740: if ($statustype) {
9741: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
9742: $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.39 raeburn 9743: if (ref($hashref) eq 'HASH') {
1.160.6.35 raeburn 9744: foreach my $field (@fields) {
9745: if ($hashref->{$field}) {
9746: $checks{$field} = $hashref->{$field};
9747: }
9748: }
9749: }
9750: }
9751: }
9752: } else {
9753: if (ref($hashref) eq 'HASH') {
9754: foreach my $field (@fields) {
9755: if ($hashref->{$field}) {
9756: $checks{$field} = ' checked="checked" ';
9757: }
9758: }
1.33 raeburn 9759: }
9760: }
9761: }
9762: }
9763: }
1.160.6.93 raeburn 9764:
9765: my $total = scalar(@fields);
9766: for (my $i=0; $i<$total; $i++) {
9767: $rem = $i%($numinrow);
1.33 raeburn 9768: if ($rem == 0) {
9769: if ($i > 0) {
9770: $output .= '</tr>';
9771: }
9772: $output .= '<tr>';
9773: }
9774: my $check = ' ';
1.160.6.35 raeburn 9775: unless ($role eq 'emailusername') {
9776: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 9777: $check = $checks{$fields[$i]};
1.160.6.35 raeburn 9778: } else {
9779: if ($role eq 'st') {
9780: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 9781: $check = ' checked="checked" ';
1.160.6.35 raeburn 9782: }
1.33 raeburn 9783: }
9784: }
9785: }
9786: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 9787: '<span class="LC_nobreak">';
9788: if ($role eq 'emailusername') {
9789: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
9790: $checks{$fields[$i]} = 'omit';
9791: }
9792: foreach my $option ('required','optional','omit') {
9793: my $checked='';
9794: if ($checks{$fields[$i]} eq $option) {
9795: $checked='checked="checked" ';
9796: }
9797: $output .= '<label>'.
9798: '<input type="radio" name="canmodify_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
9799: &mt($option).'</label>'.(' ' x2);
9800: }
9801: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
9802: } else {
9803: $output .= '<label>'.
9804: '<input type="checkbox" name="canmodify_'.$role.'" '.
9805: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
9806: '</label>';
9807: }
9808: $output .= '</span></td>';
1.33 raeburn 9809: }
1.160.6.93 raeburn 9810: $rem = $total%$numinrow;
9811: my $colsleft;
9812: if ($rem) {
9813: $colsleft = $numinrow - $rem;
9814: }
9815: if ($colsleft > 1) {
1.33 raeburn 9816: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9817: ' </td>';
9818: } elsif ($colsleft == 1) {
9819: $output .= '<td class="LC_left_item"> </td>';
9820: }
9821: $output .= '</tr></table></td></tr>';
9822: return $output;
9823: }
1.28 raeburn 9824:
1.93 raeburn 9825: sub insttypes_row {
1.160.6.93 raeburn 9826: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
9827: $customcss,$rowstyle) = @_;
1.93 raeburn 9828: my %lt = &Apache::lonlocal::texthash (
9829: cansearch => 'Users allowed to search',
9830: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 9831: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 9832: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 9833: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 9834: );
9835: my $showdom;
9836: if ($context eq 'cansearch') {
9837: $showdom = ' ('.$dom.')';
9838: }
1.160.6.5 raeburn 9839: my $class = 'LC_left_item';
9840: if ($context eq 'statustocreate') {
9841: $class = 'LC_right_item';
9842: }
1.160.6.93 raeburn 9843: my $css_class;
9844: if ($$rowtotal%2) {
9845: $css_class = 'LC_odd_row';
9846: }
9847: if ($customcss) {
9848: $css_class .= ' '.$customcss;
9849: }
9850: $css_class =~ s/^\s+//;
9851: if ($css_class) {
9852: $css_class = ' class="'.$css_class.'"';
9853: }
9854: if ($rowstyle) {
9855: $css_class .= ' style="'.$rowstyle.'"';
9856: }
9857: if ($onclick) {
9858: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 9859: }
9860: my $output = '<tr'.$css_class.'>'.
9861: '<td>'.$lt{$context}.$showdom.
9862: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 9863: my $rem;
9864: if (ref($types) eq 'ARRAY') {
9865: for (my $i=0; $i<@{$types}; $i++) {
9866: if (defined($usertypes->{$types->[$i]})) {
9867: my $rem = $i%($numinrow);
9868: if ($rem == 0) {
9869: if ($i > 0) {
9870: $output .= '</tr>';
9871: }
9872: $output .= '<tr>';
1.23 raeburn 9873: }
1.26 raeburn 9874: my $check = ' ';
1.99 raeburn 9875: if (ref($settings) eq 'HASH') {
9876: if (ref($settings->{$context}) eq 'ARRAY') {
9877: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
9878: $check = ' checked="checked" ';
9879: }
1.160.6.101 raeburn 9880: } elsif (ref($settings->{$context}) eq 'HASH') {
9881: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
9882: $check = ' checked="checked" ';
9883: }
1.99 raeburn 9884: } elsif ($context eq 'statustocreate') {
1.26 raeburn 9885: $check = ' checked="checked" ';
9886: }
1.23 raeburn 9887: }
1.26 raeburn 9888: $output .= '<td class="LC_left_item">'.
9889: '<span class="LC_nobreak"><label>'.
1.93 raeburn 9890: '<input type="checkbox" name="'.$context.'" '.
1.160.6.93 raeburn 9891: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
1.26 raeburn 9892: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 9893: }
9894: }
1.26 raeburn 9895: $rem = @{$types}%($numinrow);
1.23 raeburn 9896: }
9897: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 9898: if ($context eq 'overrides') {
9899: if ($colsleft > 1) {
9900: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9901: } else {
9902: $output .= '<td class="LC_left_item">';
9903: }
9904: $output .= ' ';
1.23 raeburn 9905: } else {
1.160.6.101 raeburn 9906: if ($rem == 0) {
9907: $output .= '<tr>';
9908: }
9909: if ($colsleft > 1) {
9910: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
9911: } else {
9912: $output .= '<td class="LC_left_item">';
9913: }
9914: my $defcheck = ' ';
9915: if (ref($settings) eq 'HASH') {
9916: if (ref($settings->{$context}) eq 'ARRAY') {
9917: if (grep(/^default$/,@{$settings->{$context}})) {
9918: $defcheck = ' checked="checked" ';
9919: }
9920: } elsif ($context eq 'statustocreate') {
1.99 raeburn 9921: $defcheck = ' checked="checked" ';
9922: }
1.26 raeburn 9923: }
1.160.6.101 raeburn 9924: $output .= '<span class="LC_nobreak"><label>'.
9925: '<input type="checkbox" name="'.$context.'" '.
9926: 'value="default"'.$defcheck.$onclick.' />'.
9927: $othertitle.'</label></span>';
1.23 raeburn 9928: }
1.160.6.101 raeburn 9929: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 9930: return $output;
1.23 raeburn 9931: }
9932:
9933: sub sorted_searchtitles {
9934: my %searchtitles = &Apache::lonlocal::texthash(
9935: 'uname' => 'username',
9936: 'lastname' => 'last name',
9937: 'lastfirst' => 'last name, first name',
9938: );
9939: my @titleorder = ('uname','lastname','lastfirst');
9940: return (\%searchtitles,\@titleorder);
9941: }
9942:
1.25 raeburn 9943: sub sorted_searchtypes {
9944: my %srchtypes_desc = (
9945: exact => 'is exact match',
9946: contains => 'contains ..',
9947: begins => 'begins with ..',
9948: );
9949: my @srchtypeorder = ('exact','begins','contains');
9950: return (\%srchtypes_desc,\@srchtypeorder);
9951: }
9952:
1.3 raeburn 9953: sub usertype_update_row {
9954: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
9955: my $datatable;
9956: my $numinrow = 4;
9957: foreach my $type (@{$types}) {
9958: if (defined($usertypes->{$type})) {
9959: $$rownums ++;
9960: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
9961: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
9962: '</td><td class="LC_left_item"><table>';
9963: for (my $i=0; $i<@{$fields}; $i++) {
9964: my $rem = $i%($numinrow);
9965: if ($rem == 0) {
9966: if ($i > 0) {
9967: $datatable .= '</tr>';
9968: }
9969: $datatable .= '<tr>';
9970: }
9971: my $check = ' ';
1.39 raeburn 9972: if (ref($settings) eq 'HASH') {
9973: if (ref($settings->{'fields'}) eq 'HASH') {
9974: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
9975: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
9976: $check = ' checked="checked" ';
9977: }
1.3 raeburn 9978: }
9979: }
9980: }
9981:
9982: if ($i == @{$fields}-1) {
9983: my $colsleft = $numinrow - $rem;
9984: if ($colsleft > 1) {
9985: $datatable .= '<td colspan="'.$colsleft.'">';
9986: } else {
9987: $datatable .= '<td>';
9988: }
9989: } else {
9990: $datatable .= '<td>';
9991: }
1.8 raeburn 9992: $datatable .= '<span class="LC_nobreak"><label>'.
9993: '<input type="checkbox" name="updateable_'.$type.
9994: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
9995: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 9996: }
9997: $datatable .= '</tr></table></td></tr>';
9998: }
9999: }
10000: return $datatable;
1.1 raeburn 10001: }
10002:
10003: sub modify_login {
1.160.6.24 raeburn 10004: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 10005: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 10006: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
10007: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlnotsso);
1.160.6.5 raeburn 10008: %title = ( coursecatalog => 'Display course catalog',
10009: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 10010: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 10011: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 10012: loginheader => 'Log-in box header',
10013: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 10014: @offon = ('off','on');
1.112 raeburn 10015: if (ref($domconfig{login}) eq 'HASH') {
10016: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10017: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10018: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10019: }
10020: }
1.160.6.113 raeburn 10021: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10022: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10023: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10024: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10025: $saml{$lonhost} = 1;
10026: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10027: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10028: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10029: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10030: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
10031: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10032: }
10033: }
10034: }
1.112 raeburn 10035: }
1.9 raeburn 10036: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10037: \%domconfig,\%loginhash);
1.160.6.14 raeburn 10038: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10039: foreach my $item (@toggles) {
10040: $loginhash{login}{$item} = $env{'form.'.$item};
10041: }
1.41 raeburn 10042: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10043: if (ref($colchanges{'login'}) eq 'HASH') {
10044: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10045: \%loginhash);
10046: }
1.110 raeburn 10047:
1.149 raeburn 10048: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 10049: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10050: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10051: if (keys(%servers) > 1) {
10052: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10053: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10054: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10055: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10056: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10057: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10058: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10059: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10060: $changes{'loginvia'}{$lonhost} = 1;
10061: } else {
10062: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10063: $changes{'loginvia'}{$lonhost} = 1;
10064: }
10065: } else {
10066: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10067: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10068: $changes{'loginvia'}{$lonhost} = 1;
10069: }
10070: }
10071: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10072: foreach my $item (@loginvia_attribs) {
10073: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10074: }
10075: } else {
10076: foreach my $item (@loginvia_attribs) {
10077: my $new = $env{'form.'.$lonhost.'_'.$item};
10078: if (($item eq 'serverpath') && ($new eq 'custom')) {
10079: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10080: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10081: $new = '/';
10082: }
10083: }
10084: if (($item eq 'custompath') &&
10085: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10086: $new = '';
10087: }
10088: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10089: $changes{'loginvia'}{$lonhost} = 1;
10090: }
10091: if ($item eq 'exempt') {
1.160.6.56 raeburn 10092: $new = &check_exempt_addresses($new);
1.128 raeburn 10093: }
10094: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10095: }
10096: }
1.112 raeburn 10097: } else {
1.128 raeburn 10098: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10099: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 10100: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 10101: foreach my $item (@loginvia_attribs) {
10102: my $new = $env{'form.'.$lonhost.'_'.$item};
10103: if (($item eq 'serverpath') && ($new eq 'custom')) {
10104: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10105: $new = '/';
10106: }
10107: }
10108: if (($item eq 'custompath') &&
10109: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10110: $new = '';
10111: }
10112: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10113: }
1.110 raeburn 10114: }
10115: }
10116: }
10117: }
1.119 raeburn 10118:
1.160.6.5 raeburn 10119: my $servadm = $r->dir_config('lonAdmEMail');
10120: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10121: if (ref($domconfig{'login'}) eq 'HASH') {
10122: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10123: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10124: if ($lang eq 'nolang') {
10125: push(@currlangs,$lang);
10126: } elsif (defined($langchoices{$lang})) {
10127: push(@currlangs,$lang);
10128: } else {
10129: next;
10130: }
10131: }
10132: }
10133: }
10134: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10135: if (@currlangs > 0) {
10136: foreach my $lang (@currlangs) {
10137: if (grep(/^\Q$lang\E$/,@delurls)) {
10138: $changes{'helpurl'}{$lang} = 1;
10139: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10140: $changes{'helpurl'}{$lang} = 1;
10141: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10142: push(@newlangs,$lang);
10143: } else {
10144: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10145: }
10146: }
10147: }
10148: unless (grep(/^nolang$/,@currlangs)) {
10149: if ($env{'form.loginhelpurl_nolang.filename'}) {
10150: $changes{'helpurl'}{'nolang'} = 1;
10151: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10152: push(@newlangs,'nolang');
10153: }
10154: }
10155: if ($env{'form.loginhelpurl_add_lang'}) {
10156: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10157: ($env{'form.loginhelpurl_add_file.filename'})) {
10158: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10159: $addedfile = $env{'form.loginhelpurl_add_lang'};
10160: }
10161: }
10162: if ((@newlangs > 0) || ($addedfile)) {
10163: my $error;
10164: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10165: if ($configuserok eq 'ok') {
10166: if ($switchserver) {
10167: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10168: } elsif ($author_ok eq 'ok') {
10169: my @allnew = @newlangs;
10170: if ($addedfile ne '') {
10171: push(@allnew,$addedfile);
10172: }
10173: foreach my $lang (@allnew) {
10174: my $formelem = 'loginhelpurl_'.$lang;
10175: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10176: $formelem = 'loginhelpurl_add_file';
10177: }
10178: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10179: "help/$lang",'','',$newfile{$lang});
10180: if ($result eq 'ok') {
10181: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10182: $changes{'helpurl'}{$lang} = 1;
10183: } else {
10184: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10185: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10186: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10187: (!grep(/^\Q$lang\E$/,@delurls))) {
10188: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10189: }
10190: }
10191: }
10192: } else {
10193: $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);
10194: }
10195: } else {
10196: $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);
10197: }
10198: if ($error) {
10199: &Apache::lonnet::logthis($error);
10200: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10201: }
10202: }
1.160.6.56 raeburn 10203:
10204: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10205: if (ref($domconfig{'login'}) eq 'HASH') {
10206: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10207: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10208: if ($domservers{$lonhost}) {
10209: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10210: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 10211: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 10212: }
10213: }
10214: }
10215: }
10216: }
10217: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10218: foreach my $lonhost (sort(keys(%domservers))) {
10219: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10220: $changes{'headtag'}{$lonhost} = 1;
10221: } else {
10222: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10223: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10224: }
10225: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10226: push(@newhosts,$lonhost);
10227: } elsif ($currheadtagurls{$lonhost}) {
10228: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10229: if ($currexempt{$lonhost}) {
10230: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
10231: $changes{'headtag'}{$lonhost} = 1;
10232: }
10233: } elsif ($possexempt{$lonhost}) {
10234: $changes{'headtag'}{$lonhost} = 1;
10235: }
10236: if ($possexempt{$lonhost}) {
10237: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10238: }
10239: }
10240: }
10241: }
10242: if (@newhosts) {
10243: my $error;
10244: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10245: if ($configuserok eq 'ok') {
10246: if ($switchserver) {
10247: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10248: } elsif ($author_ok eq 'ok') {
10249: foreach my $lonhost (@newhosts) {
10250: my $formelem = 'loginheadtag_'.$lonhost;
10251: (my $result,$newheadtagurls{$lonhost}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10252: "login/headtag/$lonhost",'','',
10253: $env{'form.loginheadtag_'.$lonhost.'.filename'});
10254: if ($result eq 'ok') {
1.160.6.113 raeburn 10255: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10256: $changes{'headtag'}{$lonhost} = 1;
10257: if ($possexempt{$lonhost}) {
10258: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10259: }
10260: } else {
10261: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10262: $newheadtagurls{$lonhost},$result);
10263: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10264: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10265: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10266: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10267: }
10268: }
10269: }
10270: } else {
10271: $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);
10272: }
10273: } else {
10274: $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);
10275: }
10276: if ($error) {
10277: &Apache::lonnet::logthis($error);
10278: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10279: }
10280: }
10281: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
10282: my @newsamlimgs;
10283: foreach my $lonhost (keys(%domservers)) {
10284: if ($env{'form.saml_'.$lonhost}) {
10285: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
10286: push(@newsamlimgs,$lonhost);
10287: }
10288: foreach my $item ('text','alt','url','title','notsso') {
10289: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
10290: }
10291: if ($saml{$lonhost}) {
10292: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
10293: #FIXME Need to obsolete published image
10294: delete($currsaml{$lonhost}{'img'});
10295: $changes{'saml'}{$lonhost} = 1;
10296: }
10297: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
10298: $changes{'saml'}{$lonhost} = 1;
10299: }
10300: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
10301: $changes{'saml'}{$lonhost} = 1;
10302: }
10303: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
10304: $changes{'saml'}{$lonhost} = 1;
10305: }
10306: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
10307: $changes{'saml'}{$lonhost} = 1;
10308: }
10309: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
10310: $changes{'saml'}{$lonhost} = 1;
10311: }
10312: } else {
10313: $changes{'saml'}{$lonhost} = 1;
10314: }
10315: foreach my $item ('text','alt','url','title','notsso') {
10316: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
10317: }
10318: } else {
10319: if ($saml{$lonhost}) {
10320: $changes{'saml'}{$lonhost} = 1;
10321: delete($currsaml{$lonhost});
10322: }
10323: }
10324: }
10325: foreach my $posshost (keys(%currsaml)) {
10326: unless (exists($domservers{$posshost})) {
10327: delete($currsaml{$posshost});
10328: }
10329: }
10330: %{$loginhash{'login'}{'saml'}} = %currsaml;
10331: if (@newsamlimgs) {
10332: my $error;
10333: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10334: if ($configuserok eq 'ok') {
10335: if ($switchserver) {
10336: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
10337: } elsif ($author_ok eq 'ok') {
10338: foreach my $lonhost (@newsamlimgs) {
10339: my $formelem = 'saml_img_'.$lonhost;
10340: my ($result,$imgurl) = &publishlogo($r,'upload',$formelem,$dom,$confname,
10341: "login/saml/$lonhost",'','',
10342: $env{'form.saml_img_'.$lonhost.'.filename'});
10343: if ($result eq 'ok') {
10344: $currsaml{$lonhost}{'img'} = $imgurl;
10345: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
10346: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 10347: } else {
1.160.6.113 raeburn 10348: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
10349: $lonhost,$result);
1.160.6.56 raeburn 10350: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10351: }
10352: }
10353: } else {
1.160.6.113 raeburn 10354: $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 10355: }
10356: } else {
1.160.6.113 raeburn 10357: $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 10358: }
10359: if ($error) {
10360: &Apache::lonnet::logthis($error);
10361: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10362: }
10363: }
1.160.6.5 raeburn 10364: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
10365:
10366: my $defaulthelpfile = '/adm/loginproblems.html';
10367: my $defaulttext = &mt('Default in use');
10368:
1.1 raeburn 10369: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
10370: $dom);
10371: if ($putresult eq 'ok') {
1.160.6.14 raeburn 10372: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10373: my %defaultchecked = (
10374: 'coursecatalog' => 'on',
1.160.6.14 raeburn 10375: 'helpdesk' => 'on',
1.42 raeburn 10376: 'adminmail' => 'off',
1.43 raeburn 10377: 'newuser' => 'off',
1.42 raeburn 10378: );
1.55 raeburn 10379: if (ref($domconfig{'login'}) eq 'HASH') {
10380: foreach my $item (@toggles) {
10381: if ($defaultchecked{$item} eq 'on') {
10382: if (($domconfig{'login'}{$item} eq '0') &&
10383: ($env{'form.'.$item} eq '1')) {
10384: $changes{$item} = 1;
10385: } elsif (($domconfig{'login'}{$item} eq '' ||
10386: $domconfig{'login'}{$item} eq '1') &&
10387: ($env{'form.'.$item} eq '0')) {
10388: $changes{$item} = 1;
10389: }
10390: } elsif ($defaultchecked{$item} eq 'off') {
10391: if (($domconfig{'login'}{$item} eq '1') &&
10392: ($env{'form.'.$item} eq '0')) {
10393: $changes{$item} = 1;
10394: } elsif (($domconfig{'login'}{$item} eq '' ||
10395: $domconfig{'login'}{$item} eq '0') &&
10396: ($env{'form.'.$item} eq '1')) {
10397: $changes{$item} = 1;
10398: }
1.42 raeburn 10399: }
10400: }
1.41 raeburn 10401: }
1.6 raeburn 10402: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 10403: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 10404: if (exists($changes{'saml'})) {
10405: my $hostid_in_use;
10406: my @hosts = &Apache::lonnet::current_machine_ids();
10407: if (@hosts > 1) {
10408: foreach my $hostid (@hosts) {
10409: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
10410: $hostid_in_use = $hostid;
10411: last;
10412: }
10413: }
10414: } else {
10415: $hostid_in_use = $r->dir_config('lonHostID');
10416: }
10417: if (($hostid_in_use) &&
10418: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
10419: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
10420: }
10421: if (ref($lastactref) eq 'HASH') {
10422: if (ref($changes{'saml'}) eq 'HASH') {
10423: my %updates;
10424: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
10425: $lastactref->{'samllanding'} = \%updates;
10426: }
10427: }
10428: }
1.160.6.27 raeburn 10429: if (ref($lastactref) eq 'HASH') {
10430: $lastactref->{'domainconfig'} = 1;
10431: }
1.1 raeburn 10432: $resulttext = &mt('Changes made:').'<ul>';
10433: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 10434: if ($item eq 'loginvia') {
1.112 raeburn 10435: if (ref($changes{$item}) eq 'HASH') {
10436: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
10437: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 10438: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
10439: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
10440: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
10441: $protocol = 'http' if ($protocol ne 'https');
10442: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
10443:
10444: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
10445: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
10446: } else {
10447: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
10448: }
10449: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
10450: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
10451: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
10452: }
10453: $resulttext .= '</li>';
10454: } else {
10455: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
10456: }
1.112 raeburn 10457: } else {
1.128 raeburn 10458: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 10459: }
10460: }
1.128 raeburn 10461: $resulttext .= '</ul></li>';
1.112 raeburn 10462: }
1.160.6.5 raeburn 10463: } elsif ($item eq 'helpurl') {
10464: if (ref($changes{$item}) eq 'HASH') {
10465: foreach my $lang (sort(keys(%{$changes{$item}}))) {
10466: if (grep(/^\Q$lang\E$/,@delurls)) {
10467: my ($chg,$link);
10468: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
10469: if ($lang eq 'nolang') {
10470: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
10471: } else {
10472: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
10473: }
10474: $resulttext .= '<li>'.$chg.'</li>';
10475: } else {
10476: my $chg;
10477: if ($lang eq 'nolang') {
10478: $chg = &mt('custom log-in help file for no preferred language');
10479: } else {
10480: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
10481: }
10482: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
10483: $loginhash{'login'}{'helpurl'}{$lang}.
10484: '?inhibitmenu=yes',$chg,600,500).
10485: '</li>';
10486: }
10487: }
10488: }
1.160.6.56 raeburn 10489: } elsif ($item eq 'headtag') {
10490: if (ref($changes{$item}) eq 'HASH') {
10491: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10492: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10493: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
10494: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10495: $resulttext .= '<li><a href="'.
10496: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
10497: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
10498: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
10499: if ($possexempt{$lonhost}) {
10500: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
10501: } else {
10502: $resulttext .= &mt('included for any client IP');
10503: }
10504: $resulttext .= '</li>';
10505: }
10506: }
10507: }
1.160.6.113 raeburn 10508: } elsif ($item eq 'saml') {
10509: if (ref($changes{$item}) eq 'HASH') {
10510: my %notlt = (
10511: text => 'Text for log-in by SSO',
10512: img => 'SSO button image',
10513: alt => 'Alt text for button image',
10514: url => 'SSO URL',
10515: title => 'Tooltip for SSO link',
10516: notsso => 'Text for non-SSO log-in',
10517: );
10518: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
10519: if (ref($currsaml{$lonhost}) eq 'HASH') {
10520: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
10521: '<ul>';
10522: foreach my $key ('text','img','alt','url','title','notsso') {
10523: if ($currsaml{$lonhost}{$key} eq '') {
10524: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
10525: } else {
10526: my $value = "'$currsaml{$lonhost}{$key}'";
10527: if ($key eq 'img') {
10528: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
10529: }
10530: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
10531: $value).'</li>';
10532: }
10533: }
10534: $resulttext .= '</ul></li>';
10535: } else {
10536: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
10537: }
10538: }
10539: }
1.160.6.5 raeburn 10540: } elsif ($item eq 'captcha') {
10541: if (ref($loginhash{'login'}) eq 'HASH') {
10542: my $chgtxt;
10543: if ($loginhash{'login'}{$item} eq 'notused') {
10544: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
10545: } else {
10546: my %captchas = &captcha_phrases();
10547: if ($captchas{$loginhash{'login'}{$item}}) {
10548: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
10549: } else {
10550: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
10551: }
10552: }
10553: $resulttext .= '<li>'.$chgtxt.'</li>';
10554: }
10555: } elsif ($item eq 'recaptchakeys') {
10556: if (ref($loginhash{'login'}) eq 'HASH') {
10557: my ($privkey,$pubkey);
10558: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
10559: $pubkey = $loginhash{'login'}{$item}{'public'};
10560: $privkey = $loginhash{'login'}{$item}{'private'};
10561: }
10562: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
10563: if (!$pubkey) {
10564: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
10565: } else {
10566: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
10567: }
10568: if (!$privkey) {
10569: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
10570: } else {
1.160.6.53 raeburn 10571: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 10572: }
10573: $chgtxt .= '</ul>';
10574: $resulttext .= '<li>'.$chgtxt.'</li>';
10575: }
1.160.6.69 raeburn 10576: } elsif ($item eq 'recaptchaversion') {
10577: if (ref($loginhash{'login'}) eq 'HASH') {
10578: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
10579: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
10580: '</li>';
10581: }
10582: }
1.41 raeburn 10583: } else {
10584: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
10585: }
1.1 raeburn 10586: }
1.6 raeburn 10587: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 10588: } else {
10589: $resulttext = &mt('No changes made to log-in page settings');
10590: }
10591: } else {
1.11 albertel 10592: $resulttext = '<span class="LC_error">'.
10593: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 10594: }
1.6 raeburn 10595: if ($errors) {
1.9 raeburn 10596: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 10597: $errors.'</ul>';
10598: }
10599: return $resulttext;
10600: }
10601:
1.160.6.56 raeburn 10602: sub check_exempt_addresses {
10603: my ($iplist) = @_;
10604: $iplist =~ s/^\s+//;
10605: $iplist =~ s/\s+$//;
10606: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
10607: my (@okips,$new);
10608: foreach my $ip (@poss_ips) {
10609: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
10610: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
10611: push(@okips,$ip);
10612: }
10613: }
10614: }
10615: if (@okips > 0) {
10616: $new = join(',',@okips);
10617: } else {
10618: $new = '';
10619: }
10620: return $new;
10621: }
10622:
1.6 raeburn 10623: sub color_font_choices {
10624: my %choices =
10625: &Apache::lonlocal::texthash (
10626: img => "Header",
10627: bgs => "Background colors",
10628: links => "Link colors",
1.55 raeburn 10629: images => "Images",
1.6 raeburn 10630: font => "Font color",
1.160.6.22 raeburn 10631: fontmenu => "Font menu",
1.76 raeburn 10632: pgbg => "Page",
1.6 raeburn 10633: tabbg => "Header",
10634: sidebg => "Border",
10635: link => "Link",
10636: alink => "Active link",
10637: vlink => "Visited link",
10638: );
10639: return %choices;
10640: }
10641:
1.160.6.113 raeburn 10642: sub modify_ipaccess {
10643: my ($dom,$lastactref,%domconfig) = @_;
10644: my (@allpos,%changes,%confhash,$errors,$resulttext);
10645: my (@items,%deletions,%itemids,@warnings);
10646: my ($typeorder,$types) = &commblocktype_text();
10647: if ($env{'form.ipaccess_add'}) {
10648: my $name = $env{'form.ipaccess_name_add'};
10649: my ($newid,$error) = &get_ipaccess_id($dom,$name);
10650: if ($newid) {
10651: $itemids{'add'} = $newid;
10652: push(@items,'add');
10653: $changes{$newid} = 1;
10654: } else {
10655: $error = &mt('Failed to acquire unique ID for new IP access control item');
10656: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10657: }
10658: }
10659: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10660: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
10661: if (@todelete) {
10662: map { $deletions{$_} = 1; } @todelete;
10663: }
10664: my $maxnum = $env{'form.ipaccess_maxnum'};
10665: for (my $i=0; $i<$maxnum; $i++) {
10666: my $itemid = $env{'form.ipaccess_id_'.$i};
10667: $itemid =~ s/\D+//g;
10668: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10669: if ($deletions{$itemid}) {
10670: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
10671: } else {
10672: push(@items,$i);
10673: $itemids{$i} = $itemid;
10674: }
10675: }
10676: }
10677: }
10678: foreach my $idx (@items) {
10679: my $itemid = $itemids{$idx};
10680: next unless ($itemid);
10681: my %current;
10682: unless ($idx eq 'add') {
10683: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10684: %current = %{$domconfig{'ipaccess'}{$itemid}};
10685: }
10686: }
10687: my $position = $env{'form.ipaccess_pos_'.$itemid};
10688: $position =~ s/\D+//g;
10689: if ($position ne '') {
10690: $allpos[$position] = $itemid;
10691: }
10692: my $name = $env{'form.ipaccess_name_'.$idx};
10693: $name =~ s/^\s+|\s+$//g;
10694: $confhash{$itemid}{'name'} = $name;
10695: my $possrange = $env{'form.ipaccess_range_'.$idx};
10696: $possrange =~ s/^\s+|\s+$//g;
10697: unless ($possrange eq '') {
10698: $possrange =~ s/[\r\n]+/\s/g;
10699: $possrange =~ s/\s*-\s*/-/g;
10700: $possrange =~ s/\s+/,/g;
10701: $possrange =~ s/,+/,/g;
10702: if ($possrange ne '') {
10703: my (@ok,$count);
10704: $count = 0;
10705: foreach my $poss (split(/\,/,$possrange)) {
10706: $count ++;
10707: $poss = &validate_ip_pattern($poss);
10708: if ($poss ne '') {
10709: push(@ok,$poss);
10710: }
10711: }
10712: my $diff = $count - scalar(@ok);
10713: if ($diff) {
10714: $errors .= '<li><span class="LC_error">'.
10715: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
10716: $diff,$name).
10717: '</span></li>';
10718: }
10719: if (@ok) {
10720: my @cidr_list;
10721: foreach my $item (@ok) {
10722: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
10723: }
10724: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
10725: }
10726: }
10727: }
10728: foreach my $field ('name','ip') {
10729: unless (($idx eq 'add') || ($changes{$itemid})) {
10730: if ($current{$field} ne $confhash{$itemid}{$field}) {
10731: $changes{$itemid} = 1;
10732: last;
10733: }
10734: }
10735: }
10736: $confhash{$itemid}{'commblocks'} = {};
10737:
10738: my %commblocks;
10739: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
10740: foreach my $type (@{$typeorder}) {
10741: if ($commblocks{$type}) {
10742: $confhash{$itemid}{'commblocks'}{$type} = 'on';
10743: }
10744: unless (($idx eq 'add') || ($changes{$itemid})) {
10745: if (ref($current{'commblocks'}) eq 'HASH') {
10746: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
10747: $changes{$itemid} = 1;
10748: }
10749: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
10750: $changes{$itemid} = 1;
10751: }
10752: }
10753: }
10754: $confhash{$itemid}{'courses'} = {};
10755: my %crsdeletions;
10756: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
10757: if (@delcrs) {
10758: map { $crsdeletions{$_} = 1; } @delcrs;
10759: }
10760: if (ref($current{'courses'}) eq 'HASH') {
10761: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
10762: if ($crsdeletions{$cid}) {
10763: $changes{$itemid} = 1;
10764: } else {
10765: $confhash{$itemid}{'courses'}{$cid} = 1;
10766: }
10767: }
10768: }
10769: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
10770: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
10771: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
10772: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
10773: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
10774: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
10775: $errors .= '<li><span class="LC_error">'.
10776: &mt('Invalid courseID [_1] omitted from list of allowed courses',
10777: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
10778: '</span></li>';
10779: } else {
10780: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
10781: $changes{$itemid} = 1;
10782: }
10783: }
10784: }
10785: if (@allpos > 0) {
10786: my $idx = 0;
10787: foreach my $itemid (@allpos) {
10788: if ($itemid ne '') {
10789: $confhash{$itemid}{'order'} = $idx;
10790: unless ($changes{$itemid}) {
10791: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
10792: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
10793: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
10794: $changes{$itemid} = 1;
10795: }
10796: }
10797: }
10798: }
10799: $idx ++;
10800: }
10801: }
10802: }
10803: if (keys(%changes)) {
10804: my %defaultshash = (
10805: ipaccess => \%confhash,
10806: );
10807: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
10808: $dom);
10809: if ($putresult eq 'ok') {
10810: my $cachetime = 1800;
10811: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
10812: if (ref($lastactref) eq 'HASH') {
10813: $lastactref->{'ipaccess'} = 1;
10814: }
10815: $resulttext = &mt('Changes made:').'<ul>';
10816: my %bynum;
10817: foreach my $itemid (sort(keys(%changes))) {
10818: if (ref($confhash{$itemid}) eq 'HASH') {
10819: my $position = $confhash{$itemid}{'order'};
10820: if ($position =~ /^\d+$/) {
10821: $bynum{$position} = $itemid;
10822: }
10823: }
10824: }
10825: if (keys(%deletions)) {
10826: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
10827: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
10828: }
10829: }
10830: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
10831: my $itemid = $bynum{$pos};
10832: if (ref($confhash{$itemid}) eq 'HASH') {
10833: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
10834: my $position = $pos + 1;
10835: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
10836: if ($confhash{$itemid}{'ip'} eq '') {
10837: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
10838: } else {
10839: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
10840: }
10841: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
10842: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
10843: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
10844: '</li>';
10845: } else {
10846: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
10847: }
10848: if (keys(%{$confhash{$itemid}{'courses'}})) {
10849: my @courses;
10850: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
10851: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
10852: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
10853: }
10854: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
10855: join('</li><li>',@courses).'</li></ul>';
10856: } else {
10857: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
10858: }
10859: $resulttext .= '</ul></li>';
10860: }
10861: }
10862: $resulttext .= '</ul>';
10863: } else {
10864: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
10865: }
10866: } else {
10867: $resulttext = &mt('No changes made');
10868: }
10869: if ($errors) {
10870: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
10871: $errors.'</ul></p>';
10872: }
10873: return $resulttext;
10874: }
10875:
10876: sub get_ipaccess_id {
10877: my ($domain,$location) = @_;
10878: # get lock on ipaccess db
10879: my $lockhash = {
10880: lock => $env{'user.name'}.
10881: ':'.$env{'user.domain'},
10882: };
10883: my $tries = 0;
10884: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10885: my ($id,$error);
10886:
10887: while (($gotlock ne 'ok') && ($tries<10)) {
10888: $tries ++;
10889: sleep (0.1);
10890: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
10891: }
10892: if ($gotlock eq 'ok') {
10893: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
10894: if ($currids{'lock'}) {
10895: delete($currids{'lock'});
10896: if (keys(%currids)) {
10897: my @curr = sort { $a <=> $b } keys(%currids);
10898: if ($curr[-1] =~ /^\d+$/) {
10899: $id = 1 + $curr[-1];
10900: }
10901: } else {
10902: $id = 1;
10903: }
10904: if ($id) {
10905: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
10906: $error = 'nostore';
10907: }
10908: } else {
10909: $error = 'nonumber';
10910: }
10911: }
10912: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
10913: } else {
10914: $error = 'nolock';
10915: }
10916: return ($id,$error);
10917: }
10918:
1.6 raeburn 10919: sub modify_rolecolors {
1.160.6.24 raeburn 10920: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 10921: my ($resulttext,%rolehash);
10922: $rolehash{'rolecolors'} = {};
1.55 raeburn 10923: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
10924: if ($domconfig{'rolecolors'} eq '') {
10925: $domconfig{'rolecolors'} = {};
10926: }
10927: }
1.9 raeburn 10928: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 10929: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
10930: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
10931: $dom);
10932: if ($putresult eq 'ok') {
10933: if (keys(%changes) > 0) {
1.41 raeburn 10934: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 10935: if (ref($lastactref) eq 'HASH') {
10936: $lastactref->{'domainconfig'} = 1;
10937: }
1.6 raeburn 10938: $resulttext = &display_colorchgs($dom,\%changes,$roles,
10939: $rolehash{'rolecolors'});
10940: } else {
10941: $resulttext = &mt('No changes made to default color schemes');
10942: }
10943: } else {
1.11 albertel 10944: $resulttext = '<span class="LC_error">'.
10945: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 10946: }
10947: if ($errors) {
10948: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
10949: $errors.'</ul>';
10950: }
10951: return $resulttext;
10952: }
10953:
10954: sub modify_colors {
1.9 raeburn 10955: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 10956: my (%changes,%choices);
1.51 raeburn 10957: my @bgs;
1.6 raeburn 10958: my @links = ('link','alink','vlink');
1.41 raeburn 10959: my @logintext;
1.6 raeburn 10960: my @images;
10961: my $servadm = $r->dir_config('lonAdmEMail');
10962: my $errors;
1.160.6.22 raeburn 10963: my %defaults;
1.6 raeburn 10964: foreach my $role (@{$roles}) {
10965: if ($role eq 'login') {
1.12 raeburn 10966: %choices = &login_choices();
1.41 raeburn 10967: @logintext = ('textcol','bgcol');
1.12 raeburn 10968: } else {
10969: %choices = &color_font_choices();
10970: }
10971: if ($role eq 'login') {
1.41 raeburn 10972: @images = ('img','logo','domlogo','login');
1.51 raeburn 10973: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 10974: } else {
10975: @images = ('img');
1.160.6.22 raeburn 10976: @bgs = ('pgbg','tabbg','sidebg');
10977: }
10978: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
10979: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
10980: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
10981: }
10982: if ($role eq 'login') {
10983: foreach my $item (@logintext) {
1.160.6.39 raeburn 10984: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
10985: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
10986: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
10987: }
10988: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 10989: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
10990: }
10991: }
10992: } else {
1.160.6.39 raeburn 10993: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
10994: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
10995: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
10996: }
10997: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 10998: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
10999: }
1.6 raeburn 11000: }
1.160.6.22 raeburn 11001: foreach my $item (@bgs) {
1.160.6.39 raeburn 11002: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11003: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11004: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11005: }
11006: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 11007: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11008: }
11009: }
11010: foreach my $item (@links) {
1.160.6.39 raeburn 11011: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11012: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11013: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11014: }
11015: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 11016: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11017: }
1.6 raeburn 11018: }
1.46 raeburn 11019: my ($configuserok,$author_ok,$switchserver) =
11020: &config_check($dom,$confname,$servadm);
1.9 raeburn 11021: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11022: if (ref($domconfig->{$role}) ne 'HASH') {
11023: $domconfig->{$role} = {};
11024: }
1.8 raeburn 11025: foreach my $img (@images) {
1.160.6.118.2 2(raebur 11026:2): if ($role eq 'login') {
11027:2): if (($img eq 'img') || ($img eq 'logo')) {
11028:2): if (defined($env{'form.login_showlogo_'.$img})) {
11029:2): $confhash->{$role}{'showlogo'}{$img} = 1;
11030:2): } else {
11031:2): $confhash->{$role}{'showlogo'}{$img} = 0;
11032:2): }
1.70 raeburn 11033: }
1.160.6.118.2 2(raebur 11034:2): if ($env{'form.login_alt_'.$img} ne '') {
11035:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11036:2): }
11037:2): }
1.18 albertel 11038: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11039: && !defined($domconfig->{$role}{$img})
11040: && !$env{'form.'.$role.'_del_'.$img}
11041: && $env{'form.'.$role.'_import_'.$img}) {
11042: # import the old configured image from the .tab setting
11043: # if they haven't provided a new one
11044: $domconfig->{$role}{$img} =
11045: $env{'form.'.$role.'_import_'.$img};
11046: }
1.6 raeburn 11047: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11048: my $error;
1.6 raeburn 11049: if ($configuserok eq 'ok') {
1.9 raeburn 11050: if ($switchserver) {
1.12 raeburn 11051: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11052: } else {
11053: if ($author_ok eq 'ok') {
11054: my ($result,$logourl) =
11055: &publishlogo($r,'upload',$role.'_'.$img,
11056: $dom,$confname,$img,$width,$height);
11057: if ($result eq 'ok') {
11058: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11059: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11060: } else {
1.12 raeburn 11061: $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 11062: }
11063: } else {
1.46 raeburn 11064: $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 11065: }
11066: }
11067: } else {
1.46 raeburn 11068: $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 11069: }
11070: if ($error) {
1.8 raeburn 11071: &Apache::lonnet::logthis($error);
1.11 albertel 11072: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11073: }
11074: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11075: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11076: my $error;
11077: if ($configuserok eq 'ok') {
11078: # is confname an author?
11079: if ($switchserver eq '') {
11080: if ($author_ok eq 'ok') {
11081: my ($result,$logourl) =
11082: &publishlogo($r,'copy',$domconfig->{$role}{$img},
11083: $dom,$confname,$img,$width,$height);
11084: if ($result eq 'ok') {
11085: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11086: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 11087: }
11088: }
11089: }
11090: }
1.6 raeburn 11091: }
11092: }
11093: }
11094: if (ref($domconfig) eq 'HASH') {
11095: if (ref($domconfig->{$role}) eq 'HASH') {
11096: foreach my $img (@images) {
11097: if ($domconfig->{$role}{$img} ne '') {
11098: if ($env{'form.'.$role.'_del_'.$img}) {
11099: $confhash->{$role}{$img} = '';
1.12 raeburn 11100: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11101: } else {
1.9 raeburn 11102: if ($confhash->{$role}{$img} eq '') {
11103: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11104: }
1.6 raeburn 11105: }
11106: } else {
11107: if ($env{'form.'.$role.'_del_'.$img}) {
11108: $confhash->{$role}{$img} = '';
1.12 raeburn 11109: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11110: }
11111: }
1.160.6.118.2 2(raebur 11112:2): if ($role eq 'login') {
11113:2): if (($img eq 'logo') || ($img eq 'img')) {
11114:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11115:2): if ($confhash->{$role}{'showlogo'}{$img} ne
11116:2): $domconfig->{$role}{'showlogo'}{$img}) {
11117:2): $changes{$role}{'showlogo'}{$img} = 1;
11118:2): }
11119:2): } else {
11120:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11121:2): $changes{$role}{'showlogo'}{$img} = 1;
11122:2): }
1.70 raeburn 11123: }
1.160.6.118.2 2(raebur 11124:2): }
11125:2): if ($img ne 'login') {
11126:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11127:2): if ($confhash->{$role}{'alttext'}{$img} ne
11128:2): $domconfig->{$role}{'alttext'}{$img}) {
11129:2): $changes{$role}{'alttext'}{$img} = 1;
11130:2): }
11131:2): } else {
11132:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11133:2): $changes{$role}{'alttext'}{$img} = 1;
11134:2): }
1.70 raeburn 11135: }
11136: }
11137: }
11138: }
1.6 raeburn 11139: if ($domconfig->{$role}{'font'} ne '') {
11140: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11141: $changes{$role}{'font'} = 1;
11142: }
11143: } else {
11144: if ($confhash->{$role}{'font'}) {
11145: $changes{$role}{'font'} = 1;
11146: }
11147: }
1.107 raeburn 11148: if ($role ne 'login') {
11149: if ($domconfig->{$role}{'fontmenu'} ne '') {
11150: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11151: $changes{$role}{'fontmenu'} = 1;
11152: }
11153: } else {
11154: if ($confhash->{$role}{'fontmenu'}) {
11155: $changes{$role}{'fontmenu'} = 1;
11156: }
1.97 tempelho 11157: }
11158: }
1.6 raeburn 11159: foreach my $item (@bgs) {
11160: if ($domconfig->{$role}{$item} ne '') {
11161: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11162: $changes{$role}{'bgs'}{$item} = 1;
11163: }
11164: } else {
11165: if ($confhash->{$role}{$item}) {
11166: $changes{$role}{'bgs'}{$item} = 1;
11167: }
11168: }
11169: }
11170: foreach my $item (@links) {
11171: if ($domconfig->{$role}{$item} ne '') {
11172: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11173: $changes{$role}{'links'}{$item} = 1;
11174: }
11175: } else {
11176: if ($confhash->{$role}{$item}) {
11177: $changes{$role}{'links'}{$item} = 1;
11178: }
11179: }
11180: }
1.41 raeburn 11181: foreach my $item (@logintext) {
11182: if ($domconfig->{$role}{$item} ne '') {
11183: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11184: $changes{$role}{'logintext'}{$item} = 1;
11185: }
11186: } else {
11187: if ($confhash->{$role}{$item}) {
11188: $changes{$role}{'logintext'}{$item} = 1;
11189: }
11190: }
11191: }
1.6 raeburn 11192: } else {
11193: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11194: \@logintext,$confhash,\%changes);
1.6 raeburn 11195: }
11196: } else {
11197: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11198: \@logintext,$confhash,\%changes);
1.6 raeburn 11199: }
11200: }
11201: return ($errors,%changes);
11202: }
11203:
1.46 raeburn 11204: sub config_check {
11205: my ($dom,$confname,$servadm) = @_;
11206: my ($configuserok,$author_ok,$switchserver,%currroles);
11207: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11208: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11209: $confname,$servadm);
11210: if ($configuserok eq 'ok') {
11211: $switchserver = &check_switchserver($dom,$confname);
11212: if ($switchserver eq '') {
11213: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11214: }
11215: }
11216: return ($configuserok,$author_ok,$switchserver);
11217: }
11218:
1.6 raeburn 11219: sub default_change_checker {
1.41 raeburn 11220: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11221: foreach my $item (@{$links}) {
11222: if ($confhash->{$role}{$item}) {
11223: $changes->{$role}{'links'}{$item} = 1;
11224: }
11225: }
11226: foreach my $item (@{$bgs}) {
11227: if ($confhash->{$role}{$item}) {
11228: $changes->{$role}{'bgs'}{$item} = 1;
11229: }
11230: }
1.41 raeburn 11231: foreach my $item (@{$logintext}) {
11232: if ($confhash->{$role}{$item}) {
11233: $changes->{$role}{'logintext'}{$item} = 1;
11234: }
11235: }
1.6 raeburn 11236: foreach my $img (@{$images}) {
11237: if ($env{'form.'.$role.'_del_'.$img}) {
11238: $confhash->{$role}{$img} = '';
1.12 raeburn 11239: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11240: }
1.70 raeburn 11241: if ($role eq 'login') {
11242: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11243: $changes->{$role}{'showlogo'}{$img} = 1;
11244: }
1.160.6.118.2 2(raebur 11245:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
11246:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11247:2): $changes->{$role}{'alttext'}{$img} = 1;
11248:2): }
11249:2): }
1.70 raeburn 11250: }
1.6 raeburn 11251: }
11252: if ($confhash->{$role}{'font'}) {
11253: $changes->{$role}{'font'} = 1;
11254: }
1.48 raeburn 11255: }
1.6 raeburn 11256:
11257: sub display_colorchgs {
11258: my ($dom,$changes,$roles,$confhash) = @_;
11259: my (%choices,$resulttext);
11260: if (!grep(/^login$/,@{$roles})) {
11261: $resulttext = &mt('Changes made:').'<br />';
11262: }
11263: foreach my $role (@{$roles}) {
11264: if ($role eq 'login') {
11265: %choices = &login_choices();
11266: } else {
11267: %choices = &color_font_choices();
11268: }
11269: if (ref($changes->{$role}) eq 'HASH') {
11270: if ($role ne 'login') {
11271: $resulttext .= '<h4>'.&mt($role).'</h4>';
11272: }
11273: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11274: if ($role ne 'login') {
11275: $resulttext .= '<ul>';
11276: }
11277: if (ref($changes->{$role}{$key}) eq 'HASH') {
11278: if ($role ne 'login') {
11279: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
11280: }
11281: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 11282: if (($role eq 'login') && ($key eq 'showlogo')) {
11283: if ($confhash->{$role}{$key}{$item}) {
11284: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
11285: } else {
11286: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
11287: }
1.160.6.118.2 2(raebur 11288:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
11289:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 11290:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 11291:2): $confhash->{$role}{$key}{$item}).'</li>';
11292:2): } else {
11293:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
11294:2): }
1.70 raeburn 11295: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 11296: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
11297: } else {
1.12 raeburn 11298: my $newitem = $confhash->{$role}{$item};
11299: if ($key eq 'images') {
11300: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
11301: }
11302: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 11303: }
11304: }
11305: if ($role ne 'login') {
11306: $resulttext .= '</ul></li>';
11307: }
11308: } else {
11309: if ($confhash->{$role}{$key} eq '') {
11310: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
11311: } else {
11312: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
11313: }
11314: }
11315: if ($role ne 'login') {
11316: $resulttext .= '</ul>';
11317: }
11318: }
11319: }
11320: }
1.3 raeburn 11321: return $resulttext;
1.1 raeburn 11322: }
11323:
1.9 raeburn 11324: sub thumb_dimensions {
11325: return ('200','50');
11326: }
11327:
1.16 raeburn 11328: sub check_dimensions {
11329: my ($inputfile) = @_;
11330: my ($fullwidth,$fullheight);
11331: if ($inputfile =~ m|^[/\w.\-]+$|) {
11332: if (open(PIPE,"identify $inputfile 2>&1 |")) {
11333: my $imageinfo = <PIPE>;
11334: if (!close(PIPE)) {
11335: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
11336: }
11337: chomp($imageinfo);
11338: my ($fullsize) =
1.21 raeburn 11339: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 11340: if ($fullsize) {
11341: ($fullwidth,$fullheight) = split(/x/,$fullsize);
11342: }
11343: }
11344: }
11345: return ($fullwidth,$fullheight);
11346: }
11347:
1.9 raeburn 11348: sub check_configuser {
11349: my ($uhome,$dom,$confname,$servadm) = @_;
11350: my ($configuserok,%currroles);
11351: if ($uhome eq 'no_host') {
11352: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 11353: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 11354: $configuserok =
11355: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
11356: $configpass,'','','','','',undef,$servadm);
11357: } else {
11358: $configuserok = 'ok';
11359: %currroles =
11360: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
11361: }
11362: return ($configuserok,%currroles);
11363: }
11364:
11365: sub check_authorstatus {
11366: my ($dom,$confname,%currroles) = @_;
11367: my $author_ok;
1.40 raeburn 11368: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 11369: my $start = time;
11370: my $end = 0;
11371: $author_ok =
11372: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 11373: 'au',$end,$start,'','','domconfig');
1.9 raeburn 11374: } else {
11375: $author_ok = 'ok';
11376: }
11377: return $author_ok;
11378: }
11379:
11380: sub publishlogo {
1.46 raeburn 11381: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 11382: my ($output,$fname,$logourl);
11383: if ($action eq 'upload') {
11384: $fname=$env{'form.'.$formname.'.filename'};
11385: chop($env{'form.'.$formname});
11386: } else {
11387: ($fname) = ($formname =~ /([^\/]+)$/);
11388: }
1.46 raeburn 11389: if ($savefileas ne '') {
11390: $fname = $savefileas;
11391: }
1.9 raeburn 11392: $fname=&Apache::lonnet::clean_filename($fname);
11393: # See if there is anything left
11394: unless ($fname) { return ('error: no uploaded file'); }
11395: $fname="$subdir/$fname";
1.160.6.5 raeburn 11396: my $docroot=$r->dir_config('lonDocRoot');
11397: my $filepath="$docroot/priv";
11398: my $relpath = "$dom/$confname";
1.9 raeburn 11399: my ($fnamepath,$file,$fetchthumb);
11400: $file=$fname;
11401: if ($fname=~m|/|) {
11402: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
11403: }
1.160.6.26 raeburn 11404: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 11405: my $count;
1.160.6.5 raeburn 11406: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 11407: $filepath.="/$parts[$count]";
11408: if ((-e $filepath)!=1) {
11409: mkdir($filepath,02770);
11410: }
11411: }
11412: # Check for bad extension and disallow upload
11413: if ($file=~/\.(\w+)$/ &&
11414: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
11415: $output =
1.160.6.25 raeburn 11416: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 11417: } elsif ($file=~/\.(\w+)$/ &&
11418: !defined(&Apache::loncommon::fileembstyle($1))) {
11419: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
11420: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.160.6.18 raeburn 11421: $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 11422: } elsif (-d "$filepath/$file") {
1.160.6.18 raeburn 11423: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 11424: } else {
11425: my $source = $filepath.'/'.$file;
11426: my $logfile;
1.160.6.88 raeburn 11427: if (!open($logfile,">>",$source.'.log')) {
1.160.6.19 raeburn 11428: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 11429: }
11430: print $logfile
11431: "\n================= Publish ".localtime()." ================\n".
11432: $env{'user.name'}.':'.$env{'user.domain'}."\n";
11433: # Save the file
1.160.6.88 raeburn 11434: if (!open(FH,">",$source)) {
1.9 raeburn 11435: &Apache::lonnet::logthis('Failed to create '.$source);
11436: return (&mt('Failed to create file'));
11437: }
11438: if ($action eq 'upload') {
11439: if (!print FH ($env{'form.'.$formname})) {
11440: &Apache::lonnet::logthis('Failed to write to '.$source);
11441: return (&mt('Failed to write file'));
11442: }
11443: } else {
11444: my $original = &Apache::lonnet::filelocation('',$formname);
11445: if(!copy($original,$source)) {
11446: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
11447: return (&mt('Failed to write file'));
11448: }
11449: }
11450: close(FH);
11451: chmod(0660, $source); # Permissions to rw-rw---.
11452:
11453: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
11454: my $copyfile=$targetdir.'/'.$file;
11455:
11456: my @parts=split(/\//,$targetdir);
11457: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
11458: for (my $count=5;$count<=$#parts;$count++) {
11459: $path.="/$parts[$count]";
11460: if (!-e $path) {
11461: print $logfile "\nCreating directory ".$path;
11462: mkdir($path,02770);
11463: }
11464: }
11465: my $versionresult;
11466: if (-e $copyfile) {
11467: $versionresult = &logo_versioning($targetdir,$file,$logfile);
11468: } else {
11469: $versionresult = 'ok';
11470: }
11471: if ($versionresult eq 'ok') {
11472: if (copy($source,$copyfile)) {
11473: print $logfile "\nCopied original source to ".$copyfile."\n";
11474: $output = 'ok';
11475: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 11476: push(@{$modified_urls},[$copyfile,$source]);
11477: my $metaoutput =
11478: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
11479: unless ($registered_cleanup) {
11480: my $handlers = $r->get_handlers('PerlCleanupHandler');
11481: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11482: $registered_cleanup=1;
11483: }
1.9 raeburn 11484: } else {
11485: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
11486: $output = &mt('Failed to copy file to RES space').", $!";
11487: }
11488: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
11489: my $inputfile = $filepath.'/'.$file;
11490: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 11491: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
11492: if ($fullwidth ne '' && $fullheight ne '') {
11493: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
11494: my $thumbsize = $thumbwidth.'x'.$thumbheight;
1.160.6.88 raeburn 11495: my @args = ('convert','-sample',$thumbsize,$inputfile,$outfile);
11496: system({$args[0]} @args);
1.16 raeburn 11497: chmod(0660, $filepath.'/tn-'.$file);
11498: if (-e $outfile) {
11499: my $copyfile=$targetdir.'/tn-'.$file;
11500: if (copy($outfile,$copyfile)) {
11501: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 11502: my $thumb_metaoutput =
11503: &write_metadata($dom,$confname,$formname,
11504: $targetdir,'tn-'.$file,$logfile);
11505: push(@{$modified_urls},[$copyfile,$outfile]);
11506: unless ($registered_cleanup) {
11507: my $handlers = $r->get_handlers('PerlCleanupHandler');
11508: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
11509: $registered_cleanup=1;
11510: }
1.16 raeburn 11511: } else {
11512: print $logfile "\nUnable to write ".$copyfile.
11513: ':'.$!."\n";
11514: }
11515: }
1.9 raeburn 11516: }
11517: }
11518: }
11519: } else {
11520: $output = $versionresult;
11521: }
11522: }
11523: return ($output,$logourl);
11524: }
11525:
11526: sub logo_versioning {
11527: my ($targetdir,$file,$logfile) = @_;
11528: my $target = $targetdir.'/'.$file;
11529: my ($maxversion,$fn,$extn,$output);
11530: $maxversion = 0;
11531: if ($file =~ /^(.+)\.(\w+)$/) {
11532: $fn=$1;
11533: $extn=$2;
11534: }
11535: opendir(DIR,$targetdir);
11536: while (my $filename=readdir(DIR)) {
11537: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
11538: $maxversion=($1>$maxversion)?$1:$maxversion;
11539: }
11540: }
11541: $maxversion++;
11542: print $logfile "\nCreating old version ".$maxversion."\n";
11543: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
11544: if (copy($target,$copyfile)) {
11545: print $logfile "Copied old target to ".$copyfile."\n";
11546: $copyfile=$copyfile.'.meta';
11547: if (copy($target.'.meta',$copyfile)) {
11548: print $logfile "Copied old target metadata to ".$copyfile."\n";
11549: $output = 'ok';
11550: } else {
11551: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
11552: $output = &mt('Failed to copy old meta').", $!, ";
11553: }
11554: } else {
11555: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
11556: $output = &mt('Failed to copy old target').", $!, ";
11557: }
11558: return $output;
11559: }
11560:
11561: sub write_metadata {
11562: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
11563: my (%metadatafields,%metadatakeys,$output);
11564: $metadatafields{'title'}=$formname;
11565: $metadatafields{'creationdate'}=time;
11566: $metadatafields{'lastrevisiondate'}=time;
11567: $metadatafields{'copyright'}='public';
11568: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
11569: $env{'user.domain'};
11570: $metadatafields{'authorspace'}=$confname.':'.$dom;
11571: $metadatafields{'domain'}=$dom;
11572: {
11573: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
11574: my $mfh;
1.160.6.88 raeburn 11575: if (open($mfh,">",$targetdir.'/'.$file.'.meta')) {
1.160.6.13 raeburn 11576: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 11577: unless ($_=~/\./) {
11578: my $unikey=$_;
11579: $unikey=~/^([A-Za-z]+)/;
11580: my $tag=$1;
11581: $tag=~tr/A-Z/a-z/;
11582: print $mfh "\n\<$tag";
11583: foreach (split(/\,/,$metadatakeys{$unikey})) {
11584: my $value=$metadatafields{$unikey.'.'.$_};
11585: $value=~s/\"/\'\'/g;
11586: print $mfh ' '.$_.'="'.$value.'"';
11587: }
11588: print $mfh '>'.
11589: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
11590: .'</'.$tag.'>';
11591: }
11592: }
11593: $output = 'ok';
11594: print $logfile "\nWrote metadata";
11595: close($mfh);
11596: } else {
11597: print $logfile "\nFailed to open metadata file";
1.9 raeburn 11598: $output = &mt('Could not write metadata');
11599: }
11600: }
1.155 raeburn 11601: return $output;
11602: }
11603:
11604: sub notifysubscribed {
11605: foreach my $targetsource (@{$modified_urls}){
11606: next unless (ref($targetsource) eq 'ARRAY');
11607: my ($target,$source)=@{$targetsource};
11608: if ($source ne '') {
1.160.6.88 raeburn 11609: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 11610: print $logfh "\nCleanup phase: Notifications\n";
11611: my @subscribed=&subscribed_hosts($target);
11612: foreach my $subhost (@subscribed) {
11613: print $logfh "\nNotifying host ".$subhost.':';
11614: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
11615: print $logfh $reply;
11616: }
11617: my @subscribedmeta=&subscribed_hosts("$target.meta");
11618: foreach my $subhost (@subscribedmeta) {
11619: print $logfh "\nNotifying host for metadata only ".$subhost.':';
11620: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
11621: $subhost);
11622: print $logfh $reply;
11623: }
11624: print $logfh "\n============ Done ============\n";
1.160 raeburn 11625: close($logfh);
1.155 raeburn 11626: }
11627: }
11628: }
11629: return OK;
11630: }
11631:
11632: sub subscribed_hosts {
11633: my ($target) = @_;
11634: my @subscribed;
1.160.6.88 raeburn 11635: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 11636: while (my $subline=<$fh>) {
11637: if ($subline =~ /^($match_lonid):/) {
11638: my $host = $1;
11639: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
11640: unless (grep(/^\Q$host\E$/,@subscribed)) {
11641: push(@subscribed,$host);
11642: }
11643: }
11644: }
11645: }
11646: }
11647: return @subscribed;
1.9 raeburn 11648: }
11649:
11650: sub check_switchserver {
11651: my ($dom,$confname) = @_;
11652: my ($allowed,$switchserver);
11653: my $home = &Apache::lonnet::homeserver($confname,$dom);
11654: if ($home eq 'no_host') {
11655: $home = &Apache::lonnet::domain($dom,'primary');
11656: }
11657: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 11658: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
11659: if (!$allowed) {
1.160.6.11 raeburn 11660: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 11661: }
11662: return $switchserver;
11663: }
11664:
1.1 raeburn 11665: sub modify_quotas {
1.160.6.30 raeburn 11666: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 11667: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 11668: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 11669: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
11670: $validationfieldsref);
1.86 raeburn 11671: if ($action eq 'quotas') {
11672: $context = 'tools';
1.160.6.26 raeburn 11673: } else {
1.86 raeburn 11674: $context = $action;
11675: }
11676: if ($context eq 'requestcourses') {
1.160.6.30 raeburn 11677: @usertools = ('official','unofficial','community','textbook');
1.106 raeburn 11678: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 11679: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
11680: %titles = &courserequest_titles();
11681: $toolregexp = join('|',@usertools);
11682: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 11683: $confname = $dom.'-domainconfig';
11684: my $servadm = $r->dir_config('lonAdmEMail');
11685: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 11686: ($validationitemsref,$validationnamesref,$validationfieldsref) =
11687: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 11688: } elsif ($context eq 'requestauthor') {
11689: @usertools = ('author');
11690: %titles = &authorrequest_titles();
1.86 raeburn 11691: } else {
1.160.6.4 raeburn 11692: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 11693: %titles = &tool_titles();
1.86 raeburn 11694: }
1.160.6.27 raeburn 11695: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 11696: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 11697: foreach my $key (keys(%env)) {
1.101 raeburn 11698: if ($context eq 'requestcourses') {
11699: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
11700: my $item = $1;
11701: my $type = $2;
11702: if ($type =~ /^limit_(.+)/) {
11703: $limithash{$item}{$1} = $env{$key};
11704: } else {
11705: $confhash{$item}{$type} = $env{$key};
11706: }
11707: }
1.160.6.5 raeburn 11708: } elsif ($context eq 'requestauthor') {
11709: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
11710: $confhash{$1} = $env{$key};
11711: }
1.101 raeburn 11712: } else {
1.86 raeburn 11713: if ($key =~ /^form\.quota_(.+)$/) {
11714: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 11715: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
11716: $confhash{'authorquota'}{$1} = $env{$key};
11717: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 11718: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
11719: }
1.72 raeburn 11720: }
11721: }
1.160.6.5 raeburn 11722: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 11723: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 11724: @approvalnotify = sort(@approvalnotify);
11725: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.30 raeburn 11726: my @crstypes = ('official','unofficial','community','textbook');
11727: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
11728: foreach my $type (@hasuniquecode) {
11729: if (grep(/^\Q$type\E$/,@crstypes)) {
11730: $confhash{'uniquecode'}{$type} = 1;
11731: }
11732: }
1.160.6.46 raeburn 11733: my (%newbook,%allpos);
1.160.6.30 raeburn 11734: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11735: foreach my $type ('textbooks','templates') {
11736: @{$allpos{$type}} = ();
11737: my $invalid;
11738: if ($type eq 'textbooks') {
11739: $invalid = &mt('Invalid LON-CAPA course for textbook');
11740: } else {
11741: $invalid = &mt('Invalid LON-CAPA course for template');
11742: }
11743: if ($env{'form.'.$type.'_addbook'}) {
11744: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
11745: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
11746: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
11747: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
11748: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
11749: } else {
11750: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
11751: my $position = $env{'form.'.$type.'_addbook_pos'};
11752: $position =~ s/\D+//g;
11753: if ($position ne '') {
11754: $allpos{$type}[$position] = $newbook{$type};
11755: }
1.160.6.30 raeburn 11756: }
1.160.6.46 raeburn 11757: } else {
11758: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 11759: }
11760: }
1.160.6.46 raeburn 11761: }
1.160.6.30 raeburn 11762: }
1.102 raeburn 11763: if (ref($domconfig{$action}) eq 'HASH') {
11764: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
11765: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
11766: $changes{'notify'}{'approval'} = 1;
11767: }
11768: } else {
1.144 raeburn 11769: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11770: $changes{'notify'}{'approval'} = 1;
11771: }
11772: }
1.160.6.30 raeburn 11773: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
11774: if (ref($confhash{'uniquecode'}) eq 'HASH') {
11775: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
11776: unless ($confhash{'uniquecode'}{$crstype}) {
11777: $changes{'uniquecode'} = 1;
11778: }
11779: }
11780: unless ($changes{'uniquecode'}) {
11781: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
11782: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
11783: $changes{'uniquecode'} = 1;
11784: }
11785: }
11786: }
11787: } else {
11788: $changes{'uniquecode'} = 1;
11789: }
11790: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
11791: $changes{'uniquecode'} = 1;
11792: }
11793: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11794: foreach my $type ('textbooks','templates') {
11795: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11796: my %deletions;
11797: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
11798: if (@todelete) {
11799: map { $deletions{$_} = 1; } @todelete;
11800: }
11801: my %imgdeletions;
11802: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
11803: if (@todeleteimages) {
11804: map { $imgdeletions{$_} = 1; } @todeleteimages;
11805: }
11806: my $maxnum = $env{'form.'.$type.'_maxnum'};
11807: for (my $i=0; $i<=$maxnum; $i++) {
11808: my $itemid = $env{'form.'.$type.'_id_'.$i};
11809: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
11810: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
11811: if ($deletions{$key}) {
11812: if ($domconfig{$action}{$type}{$key}{'image'}) {
11813: #FIXME need to obsolete item in RES space
11814: }
11815: next;
11816: } else {
11817: my $newpos = $env{'form.'.$itemid};
11818: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 11819: foreach my $item ('subject','title','publisher','author') {
11820: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11821: ($type eq 'templates'));
1.160.6.46 raeburn 11822: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
11823: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
11824: $changes{$type}{$key} = 1;
11825: }
11826: }
11827: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 11828: }
1.160.6.46 raeburn 11829: if ($imgdeletions{$key}) {
11830: $changes{$type}{$key} = 1;
11831: #FIXME need to obsolete item in RES space
11832: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
11833: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 11834: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11835: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11836: } else {
11837: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
11838: $cdom,$cnum,$type,$configuserok,
11839: $switchserver,$author_ok);
11840: if ($imgurl) {
11841: $confhash{$type}{$key}{'image'} = $imgurl;
11842: $changes{$type}{$key} = 1;
11843: }
11844: if ($error) {
11845: &Apache::lonnet::logthis($error);
11846: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11847: }
1.160.6.46 raeburn 11848: }
11849: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
11850: $confhash{$type}{$key}{'image'} =
11851: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 11852: }
11853: }
11854: }
11855: }
11856: }
11857: }
1.102 raeburn 11858: } else {
1.144 raeburn 11859: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 11860: $changes{'notify'}{'approval'} = 1;
11861: }
1.160.6.30 raeburn 11862: if (ref($confhash{'uniquecode'} eq 'HASH')) {
11863: $changes{'uniquecode'} = 1;
11864: }
11865: }
11866: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 11867: foreach my $type ('textbooks','templates') {
11868: if ($newbook{$type}) {
11869: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 11870: foreach my $item ('subject','title','publisher','author') {
11871: next if ((($item eq 'author') || ($item eq 'publisher')) &&
11872: ($type eq 'template'));
1.160.6.46 raeburn 11873: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
11874: if ($env{'form.'.$type.'_addbook_'.$item}) {
11875: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
11876: }
11877: }
11878: if ($type eq 'textbooks') {
11879: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
11880: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 11881: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
11882: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
11883: } else {
11884: my ($imageurl,$error) =
11885: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
11886: $configuserok,$switchserver,$author_ok);
11887: if ($imageurl) {
11888: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
11889: }
11890: if ($error) {
11891: &Apache::lonnet::logthis($error);
11892: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11893: }
1.160.6.46 raeburn 11894: }
11895: }
1.160.6.30 raeburn 11896: }
11897: }
1.160.6.46 raeburn 11898: if (@{$allpos{$type}} > 0) {
11899: my $idx = 0;
11900: foreach my $item (@{$allpos{$type}}) {
11901: if ($item ne '') {
11902: $confhash{$type}{$item}{'order'} = $idx;
11903: if (ref($domconfig{$action}) eq 'HASH') {
11904: if (ref($domconfig{$action}{$type}) eq 'HASH') {
11905: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
11906: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
11907: $changes{$type}{$item} = 1;
11908: }
1.160.6.30 raeburn 11909: }
11910: }
11911: }
1.160.6.46 raeburn 11912: $idx ++;
1.160.6.30 raeburn 11913: }
11914: }
11915: }
11916: }
1.160.6.39 raeburn 11917: if (ref($validationitemsref) eq 'ARRAY') {
11918: foreach my $item (@{$validationitemsref}) {
11919: if ($item eq 'fields') {
11920: my @changed;
11921: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
11922: if (@{$confhash{'validation'}{$item}} > 0) {
11923: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
11924: }
1.160.6.65 raeburn 11925: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11926: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11927: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
11928: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
11929: $domconfig{'requestcourses'}{'validation'}{$item});
11930: } else {
11931: @changed = @{$confhash{'validation'}{$item}};
11932: }
1.160.6.39 raeburn 11933: } else {
11934: @changed = @{$confhash{'validation'}{$item}};
11935: }
11936: } else {
11937: @changed = @{$confhash{'validation'}{$item}};
11938: }
11939: if (@changed) {
11940: if ($confhash{'validation'}{$item}) {
11941: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
11942: } else {
11943: $changes{'validation'}{$item} = &mt('None');
11944: }
11945: }
11946: } else {
11947: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
11948: if ($item eq 'markup') {
11949: if ($env{'form.requestcourses_validation_'.$item}) {
11950: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
11951: }
11952: }
1.160.6.65 raeburn 11953: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11954: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11955: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
11956: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11957: }
11958: } else {
11959: if ($confhash{'validation'}{$item} ne '') {
11960: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11961: }
1.160.6.39 raeburn 11962: }
11963: } else {
11964: if ($confhash{'validation'}{$item} ne '') {
11965: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
11966: }
11967: }
11968: }
11969: }
11970: }
11971: if ($env{'form.validationdc'}) {
11972: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 11973: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 11974: if (exists($domcoords{$newval})) {
11975: $confhash{'validation'}{'dc'} = $newval;
11976: }
11977: }
11978: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 11979: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
11980: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
11981: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
11982: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
11983: if ($confhash{'validation'}{'dc'} eq '') {
11984: $changes{'validation'}{'dc'} = &mt('None');
11985: } else {
11986: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11987: }
1.160.6.39 raeburn 11988: }
1.160.6.65 raeburn 11989: } elsif ($confhash{'validation'}{'dc'} ne '') {
11990: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 11991: }
11992: } elsif ($confhash{'validation'}{'dc'} ne '') {
11993: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11994: }
11995: } elsif ($confhash{'validation'}{'dc'} ne '') {
11996: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
11997: }
1.160.6.65 raeburn 11998: } else {
11999: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12000: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12001: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12002: $changes{'validation'}{'dc'} = &mt('None');
12003: }
12004: }
1.160.6.39 raeburn 12005: }
12006: }
1.102 raeburn 12007: }
12008: } else {
1.86 raeburn 12009: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 12010: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12011: }
1.72 raeburn 12012: foreach my $item (@usertools) {
12013: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12014: my $unset;
1.101 raeburn 12015: if ($context eq 'requestcourses') {
1.104 raeburn 12016: $unset = '0';
12017: if ($type eq '_LC_adv') {
12018: $unset = '';
12019: }
1.101 raeburn 12020: if ($confhash{$item}{$type} eq 'autolimit') {
12021: $confhash{$item}{$type} .= '=';
12022: unless ($limithash{$item}{$type} =~ /\D/) {
12023: $confhash{$item}{$type} .= $limithash{$item}{$type};
12024: }
12025: }
1.160.6.5 raeburn 12026: } elsif ($context eq 'requestauthor') {
12027: $unset = '0';
12028: if ($type eq '_LC_adv') {
12029: $unset = '';
12030: }
1.72 raeburn 12031: } else {
1.101 raeburn 12032: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12033: $confhash{$item}{$type} = 1;
12034: } else {
12035: $confhash{$item}{$type} = 0;
12036: }
1.72 raeburn 12037: }
1.86 raeburn 12038: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 12039: if ($action eq 'requestauthor') {
12040: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12041: $changes{$type} = 1;
12042: }
12043: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12044: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12045: $changes{$item}{$type} = 1;
12046: }
12047: } else {
12048: if ($context eq 'requestcourses') {
1.104 raeburn 12049: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12050: $changes{$item}{$type} = 1;
12051: }
12052: } else {
12053: if (!$confhash{$item}{$type}) {
12054: $changes{$item}{$type} = 1;
12055: }
12056: }
12057: }
12058: } else {
12059: if ($context eq 'requestcourses') {
1.104 raeburn 12060: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12061: $changes{$item}{$type} = 1;
12062: }
1.160.6.5 raeburn 12063: } elsif ($context eq 'requestauthor') {
12064: if ($confhash{$type} ne $unset) {
12065: $changes{$type} = 1;
12066: }
1.72 raeburn 12067: } else {
12068: if (!$confhash{$item}{$type}) {
12069: $changes{$item}{$type} = 1;
12070: }
12071: }
12072: }
1.1 raeburn 12073: }
12074: }
1.160.6.5 raeburn 12075: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12076: if (ref($domconfig{'quotas'}) eq 'HASH') {
12077: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12078: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12079: if (exists($confhash{'defaultquota'}{$key})) {
12080: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12081: $changes{'defaultquota'}{$key} = 1;
12082: }
12083: } else {
12084: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12085: }
12086: }
1.86 raeburn 12087: } else {
12088: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12089: if (exists($confhash{'defaultquota'}{$key})) {
12090: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12091: $changes{'defaultquota'}{$key} = 1;
12092: }
12093: } else {
12094: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12095: }
1.1 raeburn 12096: }
12097: }
1.160.6.20 raeburn 12098: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12099: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12100: if (exists($confhash{'authorquota'}{$key})) {
12101: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12102: $changes{'authorquota'}{$key} = 1;
12103: }
12104: } else {
12105: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12106: }
12107: }
12108: }
1.1 raeburn 12109: }
1.86 raeburn 12110: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12111: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12112: if (ref($domconfig{'quotas'}) eq 'HASH') {
12113: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12114: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12115: $changes{'defaultquota'}{$key} = 1;
12116: }
12117: } else {
12118: if (!exists($domconfig{'quotas'}{$key})) {
12119: $changes{'defaultquota'}{$key} = 1;
12120: }
1.72 raeburn 12121: }
12122: } else {
1.86 raeburn 12123: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12124: }
1.1 raeburn 12125: }
12126: }
1.160.6.20 raeburn 12127: if (ref($confhash{'authorquota'}) eq 'HASH') {
12128: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12129: if (ref($domconfig{'quotas'}) eq 'HASH') {
12130: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12131: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12132: $changes{'authorquota'}{$key} = 1;
12133: }
12134: } else {
12135: $changes{'authorquota'}{$key} = 1;
12136: }
12137: } else {
12138: $changes{'authorquota'}{$key} = 1;
12139: }
12140: }
12141: }
1.1 raeburn 12142: }
1.72 raeburn 12143:
1.160.6.5 raeburn 12144: if ($context eq 'requestauthor') {
12145: $domdefaults{'requestauthor'} = \%confhash;
12146: } else {
12147: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 12148: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 12149: $domdefaults{$key} = $confhash{$key};
12150: }
1.160.6.5 raeburn 12151: }
1.72 raeburn 12152: }
1.160.6.5 raeburn 12153:
1.1 raeburn 12154: my %quotahash = (
1.86 raeburn 12155: $action => { %confhash }
1.1 raeburn 12156: );
12157: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12158: $dom);
12159: if ($putresult eq 'ok') {
12160: if (keys(%changes) > 0) {
1.72 raeburn 12161: my $cachetime = 24*60*60;
12162: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12163: if (ref($lastactref) eq 'HASH') {
12164: $lastactref->{'domdefaults'} = 1;
12165: }
1.1 raeburn 12166: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 12167: unless (($context eq 'requestcourses') ||
12168: ($context eq 'requestauthor')) {
1.86 raeburn 12169: if (ref($changes{'defaultquota'}) eq 'HASH') {
12170: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12171: foreach my $type (@{$types},'default') {
12172: if (defined($changes{'defaultquota'}{$type})) {
12173: my $typetitle = $usertypes->{$type};
12174: if ($type eq 'default') {
12175: $typetitle = $othertitle;
12176: }
1.160.6.28 raeburn 12177: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12178: }
12179: }
1.86 raeburn 12180: $resulttext .= '</ul></li>';
1.72 raeburn 12181: }
1.160.6.20 raeburn 12182: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 12183: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 12184: foreach my $type (@{$types},'default') {
12185: if (defined($changes{'authorquota'}{$type})) {
12186: my $typetitle = $usertypes->{$type};
12187: if ($type eq 'default') {
12188: $typetitle = $othertitle;
12189: }
1.160.6.28 raeburn 12190: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 12191: }
12192: }
12193: $resulttext .= '</ul></li>';
12194: }
1.72 raeburn 12195: }
1.80 raeburn 12196: my %newenv;
1.72 raeburn 12197: foreach my $item (@usertools) {
1.160.6.5 raeburn 12198: my (%haschgs,%inconf);
12199: if ($context eq 'requestauthor') {
12200: %haschgs = %changes;
12201: %inconf = %confhash;
12202: } else {
12203: if (ref($changes{$item}) eq 'HASH') {
12204: %haschgs = %{$changes{$item}};
12205: }
12206: if (ref($confhash{$item}) eq 'HASH') {
12207: %inconf = %{$confhash{$item}};
12208: }
12209: }
12210: if (keys(%haschgs) > 0) {
1.80 raeburn 12211: my $newacc =
12212: &Apache::lonnet::usertools_access($env{'user.name'},
12213: $env{'user.domain'},
1.86 raeburn 12214: $item,'reload',$context);
1.160.6.5 raeburn 12215: if (($context eq 'requestcourses') ||
12216: ($context eq 'requestauthor')) {
1.108 raeburn 12217: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12218: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12219: }
12220: } else {
12221: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12222: $newenv{'environment.availabletools.'.$item} = $newacc;
12223: }
1.80 raeburn 12224: }
1.160.6.5 raeburn 12225: unless ($context eq 'requestauthor') {
12226: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12227: }
1.72 raeburn 12228: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 12229: if ($haschgs{$type}) {
1.72 raeburn 12230: my $typetitle = $usertypes->{$type};
12231: if ($type eq 'default') {
12232: $typetitle = $othertitle;
12233: } elsif ($type eq '_LC_adv') {
12234: $typetitle = 'LON-CAPA Advanced Users';
12235: }
1.160.6.5 raeburn 12236: if ($inconf{$type}) {
1.101 raeburn 12237: if ($context eq 'requestcourses') {
12238: my $cond;
1.160.6.5 raeburn 12239: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12240: if ($1 eq '') {
12241: $cond = &mt('(Automatic processing of any request).');
12242: } else {
12243: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12244: }
12245: } else {
1.160.6.5 raeburn 12246: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12247: }
12248: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 12249: } elsif ($context eq 'requestauthor') {
12250: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12251: $titles{$inconf{$type}},$typetitle);
12252:
1.101 raeburn 12253: } else {
12254: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12255: }
1.72 raeburn 12256: } else {
1.104 raeburn 12257: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 12258: if ($inconf{$type} eq '0') {
1.104 raeburn 12259: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12260: } else {
12261: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12262: }
12263: } else {
12264: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12265: }
1.72 raeburn 12266: }
12267: }
1.26 raeburn 12268: }
1.160.6.5 raeburn 12269: unless ($context eq 'requestauthor') {
12270: $resulttext .= '</ul></li>';
12271: }
1.26 raeburn 12272: }
1.1 raeburn 12273: }
1.160.6.5 raeburn 12274: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12275: if (ref($changes{'notify'}) eq 'HASH') {
12276: if ($changes{'notify'}{'approval'}) {
12277: if (ref($confhash{'notify'}) eq 'HASH') {
12278: if ($confhash{'notify'}{'approval'}) {
12279: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12280: } else {
1.160.6.5 raeburn 12281: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12282: }
12283: }
12284: }
12285: }
12286: }
1.160.6.30 raeburn 12287: if ($action eq 'requestcourses') {
12288: my @offon = ('off','on');
12289: if ($changes{'uniquecode'}) {
12290: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12291: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12292: $resulttext .= '<li>'.
12293: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12294: '</li>';
12295: } else {
12296: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12297: '</li>';
12298: }
12299: }
1.160.6.46 raeburn 12300: foreach my $type ('textbooks','templates') {
12301: if (ref($changes{$type}) eq 'HASH') {
12302: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12303: foreach my $key (sort(keys(%{$changes{$type}}))) {
12304: my %coursehash = &Apache::lonnet::coursedescription($key);
12305: my $coursetitle = $coursehash{'description'};
12306: my $position = $confhash{$type}{$key}{'order'} + 1;
12307: $resulttext .= '<li>';
1.160.6.47 raeburn 12308: foreach my $item ('subject','title','publisher','author') {
12309: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12310: ($type eq 'templates'));
1.160.6.46 raeburn 12311: my $name = $item.':';
12312: $name =~ s/^(\w)/\U$1/;
12313: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12314: }
12315: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12316: if ($type eq 'textbooks') {
12317: if ($confhash{$type}{$key}{'image'}) {
12318: $resulttext .= ' '.&mt('Image: [_1]',
12319: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12320: ' alt="Textbook cover" />').'<br />';
12321: }
12322: }
12323: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 12324: }
1.160.6.46 raeburn 12325: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 12326: }
12327: }
1.160.6.39 raeburn 12328: if (ref($changes{'validation'}) eq 'HASH') {
12329: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12330: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12331: foreach my $item (@{$validationitemsref}) {
12332: if (exists($changes{'validation'}{$item})) {
12333: if ($item eq 'markup') {
12334: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12335: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12336: } else {
12337: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12338: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12339: }
12340: }
12341: }
12342: if (exists($changes{'validation'}{'dc'})) {
12343: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12344: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12345: }
12346: }
12347: }
1.160.6.30 raeburn 12348: }
1.1 raeburn 12349: $resulttext .= '</ul>';
1.80 raeburn 12350: if (keys(%newenv)) {
12351: &Apache::lonnet::appenv(\%newenv);
12352: }
1.1 raeburn 12353: } else {
1.86 raeburn 12354: if ($context eq 'requestcourses') {
12355: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 12356: } elsif ($context eq 'requestauthor') {
12357: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12358: } else {
1.90 weissno 12359: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12360: }
1.1 raeburn 12361: }
12362: } else {
1.11 albertel 12363: $resulttext = '<span class="LC_error">'.
12364: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12365: }
1.160.6.30 raeburn 12366: if ($errors) {
12367: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12368: '<ul>'.$errors.'</ul></p>';
12369: }
1.3 raeburn 12370: return $resulttext;
1.1 raeburn 12371: }
12372:
1.160.6.30 raeburn 12373: sub process_textbook_image {
1.160.6.46 raeburn 12374: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 12375: my $filename = $env{'form.'.$caller.'.filename'};
12376: my ($error,$url);
12377: my ($width,$height) = (50,50);
12378: if ($configuserok eq 'ok') {
12379: if ($switchserver) {
12380: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12381: $switchserver);
12382: } elsif ($author_ok eq 'ok') {
12383: my ($result,$imageurl) =
12384: &publishlogo($r,'upload',$caller,$dom,$confname,
1.160.6.88 raeburn 12385: "$type/$cdom/$cnum/cover",$width,$height);
1.160.6.30 raeburn 12386: if ($result eq 'ok') {
12387: $url = $imageurl;
12388: } else {
12389: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12390: }
12391: } else {
12392: $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);
12393: }
12394: } else {
12395: $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);
12396: }
12397: return ($url,$error);
12398: }
12399:
1.160.6.118.2 1(raebur 12400:1): sub modify_ltitools {
12401:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
12402:1): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
12403:1): my ($newid,@allpos,%changes,%confhash,%encconfig,$errors,$resulttext);
12404:1): my $confname = $dom.'-domainconfig';
12405:1): my $servadm = $r->dir_config('lonAdmEMail');
12406:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12407:1): my (%posslti,%possfield);
12408:1): my @courseroles = ('cc','in','ta','ep','st');
12409:1): my @ltiroles = qw(Instructor ContentDeveloper TeachingAssistant Learner);
12410:1): map { $posslti{$_} = 1; } @ltiroles;
12411:1): my @allfields = ('fullname','firstname','lastname','email','user','roles');
12412:1): map { $possfield{$_} = 1; } @allfields;
12413:1): my %lt = <itools_names();
12414:1): if ($env{'form.ltitools_add'}) {
12415:1): my $title = $env{'form.ltitools_add_title'};
12416:1): $title =~ s/(`)/'/g;
12417:1): ($newid,my $error) = &get_ltitools_id($dom,$title);
12418:1): if ($newid) {
12419:1): my $position = $env{'form.ltitools_add_pos'};
12420:1): $position =~ s/\D+//g;
12421:1): if ($position ne '') {
12422:1): $allpos[$position] = $newid;
12423:1): }
12424:1): $changes{$newid} = 1;
12425:1): foreach my $item ('title','url','key','secret','lifetime') {
12426:1): $env{'form.ltitools_add_'.$item} =~ s/(`)/'/g;
12427:1): if ($item eq 'lifetime') {
12428:1): $env{'form.ltitools_add_'.$item} =~ s/[^\d.]//g;
12429:1): }
12430:1): if ($env{'form.ltitools_add_'.$item}) {
12431:1): if (($item eq 'key') || ($item eq 'secret')) {
12432:1): $encconfig{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12433:1): } else {
12434:1): $confhash{$newid}{$item} = $env{'form.ltitools_add_'.$item};
12435:1): }
12436:1): }
12437:1): }
12438:1): if ($env{'form.ltitools_add_version'} eq 'LTI-1p0') {
12439:1): $confhash{$newid}{'version'} = $env{'form.ltitools_add_version'};
12440:1): }
12441:1): if ($env{'form.ltitools_add_msgtype'} eq 'basic-lti-launch-request') {
12442:1): $confhash{$newid}{'msgtype'} = $env{'form.ltitools_add_msgtype'};
12443:1): }
12444:1): if ($env{'form.ltitools_add_sigmethod'} eq 'HMAC-SHA256') {
12445:1): $confhash{$newid}{'sigmethod'} = $env{'form.ltitools_add_sigmethod'};
12446:1): } else {
12447:1): $confhash{$newid}{'sigmethod'} = 'HMAC-SHA1';
12448:1): }
12449:1): foreach my $item ('width','height','linktext','explanation') {
12450:1): $env{'form.ltitools_add_'.$item} =~ s/^\s+//;
12451:1): $env{'form.ltitools_add_'.$item} =~ s/\s+$//;
12452:1): if (($item eq 'width') || ($item eq 'height')) {
12453:1): if ($env{'form.ltitools_add_'.$item} =~ /^\d+$/) {
12454:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12455:1): }
12456:1): } else {
12457:1): if ($env{'form.ltitools_add_'.$item} ne '') {
12458:1): $confhash{$newid}{'display'}{$item} = $env{'form.ltitools_add_'.$item};
12459:1): }
12460:1): }
12461:1): }
12462:1): if ($env{'form.ltitools_add_target'} eq 'window') {
12463:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12464:1): } elsif ($env{'form.ltitools_add_target'} eq 'tab') {
12465:1): $confhash{$newid}{'display'}{'target'} = $env{'form.ltitools_add_target'};
12466:1): } else {
12467:1): $confhash{$newid}{'display'}{'target'} = 'iframe';
12468:1): }
12469:1): if ($env{'form.ltitools_add_image.filename'} ne '') {
12470:1): my ($imageurl,$error) =
12471:1): &process_ltitools_image($r,$dom,$confname,'ltitools_add_image',$newid,
12472:1): $configuserok,$switchserver,$author_ok);
12473:1): if ($imageurl) {
12474:1): $confhash{$newid}{'image'} = $imageurl;
12475:1): }
12476:1): if ($error) {
12477:1): &Apache::lonnet::logthis($error);
12478:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12479:1): }
12480:1): }
12481:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_add_fields');
12482:1): foreach my $field (@fields) {
12483:1): if ($possfield{$field}) {
12484:1): if ($field eq 'roles') {
12485:1): foreach my $role (@courseroles) {
12486:1): my $choice = $env{'form.ltitools_add_roles_'.$role};
12487:1): if (($choice ne '') && ($posslti{$choice})) {
12488:1): $confhash{$newid}{'roles'}{$role} = $choice;
12489:1): if ($role eq 'cc') {
12490:1): $confhash{$newid}{'roles'}{'co'} = $choice;
12491:1): }
12492:1): }
12493:1): }
12494:1): } else {
12495:1): $confhash{$newid}{'fields'}{$field} = 1;
12496:1): }
12497:1): }
12498:1): }
12499:1): if (ref($confhash{$newid}{'fields'}) eq 'HASH') {
12500:1): if ($confhash{$newid}{'fields'}{'user'}) {
12501:1): if ($env{'form.ltitools_userincdom_add'}) {
12502:1): $confhash{$newid}{'incdom'} = 1;
12503:1): }
12504:1): }
12505:1): }
12506:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig');
12507:1): foreach my $item (@courseconfig) {
12508:1): $confhash{$newid}{'crsconf'}{$item} = 1;
12509:1): }
12510:1): if ($env{'form.ltitools_add_custom'}) {
12511:1): my $name = $env{'form.ltitools_add_custom_name'};
12512:1): my $value = $env{'form.ltitools_add_custom_value'};
12513:1): $value =~ s/(`)/'/g;
12514:1): $name =~ s/(`)/'/g;
12515:1): $confhash{$newid}{'custom'}{$name} = $value;
12516:1): }
12517:1): } else {
12518:1): my $error = &mt('Failed to acquire unique ID for new external tool');
12519:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12520:1): }
12521:1): }
12522:1): if (ref($domconfig{$action}) eq 'HASH') {
12523:1): my %deletions;
12524:1): my @todelete = &Apache::loncommon::get_env_multiple('form.ltitools_del');
12525:1): if (@todelete) {
12526:1): map { $deletions{$_} = 1; } @todelete;
12527:1): }
12528:1): my %customadds;
12529:1): my @newcustom = &Apache::loncommon::get_env_multiple('form.ltitools_customadd');
12530:1): if (@newcustom) {
12531:1): map { $customadds{$_} = 1; } @newcustom;
12532:1): }
12533:1): my %imgdeletions;
12534:1): my @todeleteimages = &Apache::loncommon::get_env_multiple('form.ltitools_image_del');
12535:1): if (@todeleteimages) {
12536:1): map { $imgdeletions{$_} = 1; } @todeleteimages;
12537:1): }
12538:1): my $maxnum = $env{'form.ltitools_maxnum'};
12539:1): for (my $i=0; $i<=$maxnum; $i++) {
12540:1): my $itemid = $env{'form.ltitools_id_'.$i};
12541:1): $itemid =~ s/\D+//g;
12542:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12543:1): if ($deletions{$itemid}) {
12544:1): if ($domconfig{$action}{$itemid}{'image'}) {
12545:1): #FIXME need to obsolete item in RES space
12546:1): }
12547:1): $changes{$itemid} = $domconfig{$action}{$itemid}{'title'};
12548:1): next;
12549:1): } else {
12550:1): my $newpos = $env{'form.ltitools_'.$itemid};
12551:1): $newpos =~ s/\D+//g;
12552:1): foreach my $item ('title','url','lifetime') {
12553:1): $confhash{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12554:1): if ($domconfig{$action}{$itemid}{$item} ne $confhash{$itemid}{$item}) {
12555:1): $changes{$itemid} = 1;
12556:1): }
12557:1): }
12558:1): foreach my $item ('key','secret') {
12559:1): $encconfig{$itemid}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12560:1): if ($domconfig{$action}{$itemid}{$item} ne $encconfig{$itemid}{$item}) {
12561:1): $changes{$itemid} = 1;
12562:1): }
12563:1): }
12564:1): if ($env{'form.ltitools_version_'.$i} eq 'LTI-1p0') {
12565:1): $confhash{$itemid}{'version'} = $env{'form.ltitools_version_'.$i};
12566:1): }
12567:1): if ($env{'form.ltitools_msgtype_'.$i} eq 'basic-lti-launch-request') {
12568:1): $confhash{$itemid}{'msgtype'} = $env{'form.ltitools_msgtype_'.$i};
12569:1): }
12570:1): if ($env{'form.ltitools_sigmethod_'.$i} eq 'HMAC-SHA256') {
12571:1): $confhash{$itemid}{'sigmethod'} = $env{'form.ltitools_sigmethod_'.$i};
12572:1): } else {
12573:1): $confhash{$itemid}{'sigmethod'} = 'HMAC-SHA1';
12574:1): }
12575:1): if ($domconfig{$action}{$itemid}{'sigmethod'} eq '') {
12576:1): if ($confhash{$itemid}{'sigmethod'} ne 'HMAC-SHA1') {
12577:1): $changes{$itemid} = 1;
12578:1): }
12579:1): } elsif ($domconfig{$action}{$itemid}{'sigmethod'} ne $confhash{$itemid}{'sigmethod'}) {
12580:1): $changes{$itemid} = 1;
12581:1): }
12582:1): foreach my $size ('width','height') {
12583:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/^\s+//;
12584:1): $env{'form.ltitools_'.$size.'_'.$i} =~ s/\s+$//;
12585:1): if ($env{'form.ltitools_'.$size.'_'.$i} =~ /^\d+$/) {
12586:1): $confhash{$itemid}{'display'}{$size} = $env{'form.ltitools_'.$size.'_'.$i};
12587:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12588:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne $confhash{$itemid}{'display'}{$size}) {
12589:1): $changes{$itemid} = 1;
12590:1): }
12591:1): } else {
12592:1): $changes{$itemid} = 1;
12593:1): }
12594:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12595:1): if ($domconfig{$action}{$itemid}{'display'}{$size} ne '') {
12596:1): $changes{$itemid} = 1;
12597:1): }
12598:1): }
12599:1): }
12600:1): foreach my $item ('linktext','explanation') {
12601:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/^\s+//;
12602:1): $env{'form.ltitools_'.$item.'_'.$i} =~ s/\s+$//;
12603:1): if ($env{'form.ltitools_'.$item.'_'.$i} ne '') {
12604:1): $confhash{$itemid}{'display'}{$item} = $env{'form.ltitools_'.$item.'_'.$i};
12605:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12606:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne $confhash{$itemid}{'display'}{$item}) {
12607:1): $changes{$itemid} = 1;
12608:1): }
12609:1): } else {
12610:1): $changes{$itemid} = 1;
12611:1): }
12612:1): } elsif (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12613:1): if ($domconfig{$action}{$itemid}{'display'}{$item} ne '') {
12614:1): $changes{$itemid} = 1;
12615:1): }
12616:1): }
12617:1): }
12618:1): if ($env{'form.ltitools_target_'.$i} eq 'window') {
12619:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12620:1): } elsif ($env{'form.ltitools_target_'.$i} eq 'tab') {
12621:1): $confhash{$itemid}{'display'}{'target'} = $env{'form.ltitools_target_'.$i};
12622:1): } else {
12623:1): $confhash{$itemid}{'display'}{'target'} = 'iframe';
12624:1): }
12625:1): if (ref($domconfig{$action}{$itemid}{'display'}) eq 'HASH') {
12626:1): if ($domconfig{$action}{$itemid}{'display'}{'target'} ne $confhash{$itemid}{'display'}{'target'}) {
12627:1): $changes{$itemid} = 1;
12628:1): }
12629:1): } else {
12630:1): $changes{$itemid} = 1;
12631:1): }
12632:1): my @courseconfig = &Apache::loncommon::get_env_multiple('form.ltitools_courseconfig_'.$i);
12633:1): foreach my $item ('label','title','target','linktext','explanation','append') {
12634:1): if (grep(/^\Q$item\E$/,@courseconfig)) {
12635:1): $confhash{$itemid}{'crsconf'}{$item} = 1;
12636:1): if (ref($domconfig{$action}{$itemid}{'crsconf'}) eq 'HASH') {
12637:1): if ($domconfig{$action}{$itemid}{'crsconf'}{$item} ne $confhash{$itemid}{'crsconf'}{$item}) {
12638:1): $changes{$itemid} = 1;
12639:1): }
12640:1): } else {
12641:1): $changes{$itemid} = 1;
12642:1): }
12643:1): }
12644:1): }
12645:1): my @fields = &Apache::loncommon::get_env_multiple('form.ltitools_fields_'.$i);
12646:1): foreach my $field (@fields) {
12647:1): if ($possfield{$field}) {
12648:1): if ($field eq 'roles') {
12649:1): foreach my $role (@courseroles) {
12650:1): my $choice = $env{'form.ltitools_roles_'.$role.'_'.$i};
12651:1): if (($choice ne '') && ($posslti{$choice})) {
12652:1): $confhash{$itemid}{'roles'}{$role} = $choice;
12653:1): if ($role eq 'cc') {
12654:1): $confhash{$itemid}{'roles'}{'co'} = $choice;
12655:1): }
12656:1): }
12657:1): if (ref($domconfig{$action}{$itemid}{'roles'}) eq 'HASH') {
12658:1): if ($domconfig{$action}{$itemid}{'roles'}{$role} ne $confhash{$itemid}{'roles'}{$role}) {
12659:1): $changes{$itemid} = 1;
12660:1): }
12661:1): } elsif ($confhash{$itemid}{'roles'}{$role}) {
12662:1): $changes{$itemid} = 1;
12663:1): }
12664:1): }
12665:1): } else {
12666:1): $confhash{$itemid}{'fields'}{$field} = 1;
12667:1): if (ref($domconfig{$action}{$itemid}{'fields'}) eq 'HASH') {
12668:1): if ($domconfig{$action}{$itemid}{'fields'}{$field} ne $confhash{$itemid}{'fields'}{$field}) {
12669:1): $changes{$itemid} = 1;
12670:1): }
12671:1): } else {
12672:1): $changes{$itemid} = 1;
12673:1): }
12674:1): }
12675:1): }
12676:1): }
12677:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12678:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12679:1): if ($env{'form.ltitools_userincdom_'.$i}) {
12680:1): $confhash{$itemid}{'incdom'} = 1;
12681:1): }
12682:1): if ($domconfig{$action}{$itemid}{'incdom'} ne $confhash{$itemid}{'incdom'}) {
12683:1): $changes{$itemid} = 1;
12684:1): }
12685:1): }
12686:1): }
12687:1): $allpos[$newpos] = $itemid;
12688:1): }
12689:1): if ($imgdeletions{$itemid}) {
12690:1): $changes{$itemid} = 1;
12691:1): #FIXME need to obsolete item in RES space
12692:1): } elsif ($env{'form.ltitools_image_'.$i.'.filename'}) {
12693:1): my ($imgurl,$error) = &process_ltitools_image($r,$dom,$confname,'ltitools_image_'.$i,
12694:1): $itemid,$configuserok,$switchserver,
12695:1): $author_ok);
12696:1): if ($imgurl) {
12697:1): $confhash{$itemid}{'image'} = $imgurl;
12698:1): $changes{$itemid} = 1;
12699:1): }
12700:1): if ($error) {
12701:1): &Apache::lonnet::logthis($error);
12702:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12703:1): }
12704:1): } elsif ($domconfig{$action}{$itemid}{'image'}) {
12705:1): $confhash{$itemid}{'image'} =
12706:1): $domconfig{$action}{$itemid}{'image'};
12707:1): }
12708:1): if ($customadds{$i}) {
12709:1): my $name = $env{'form.ltitools_custom_name_'.$i};
12710:1): $name =~ s/(`)/'/g;
12711:1): $name =~ s/^\s+//;
12712:1): $name =~ s/\s+$//;
12713:1): my $value = $env{'form.ltitools_custom_value_'.$i};
12714:1): $value =~ s/(`)/'/g;
12715:1): $value =~ s/^\s+//;
12716:1): $value =~ s/\s+$//;
12717:1): if ($name ne '') {
12718:1): $confhash{$itemid}{'custom'}{$name} = $value;
12719:1): $changes{$itemid} = 1;
12720:1): }
12721:1): }
12722:1): my %customdels;
12723:1): my @customdeletions = &Apache::loncommon::get_env_multiple('form.ltitools_customdel_'.$i);
12724:1): if (@customdeletions) {
12725:1): $changes{$itemid} = 1;
12726:1): }
12727:1): map { $customdels{$_} = 1; } @customdeletions;
12728:1): if (ref($domconfig{$action}{$itemid}{'custom'}) eq 'HASH') {
12729:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}{'custom'}})) {
12730:1): unless ($customdels{$key}) {
12731:1): if ($env{'form.ltitools_customval_'.$key.'_'.$i} ne '') {
12732:1): $confhash{$itemid}{'custom'}{$key} = $env{'form.ltitools_customval_'.$key.'_'.$i};
12733:1): }
12734:1): if ($domconfig{$action}{$itemid}{'custom'}{$key} ne $env{'form.ltitools_customval_'.$key.'_'.$i}) {
12735:1): $changes{$itemid} = 1;
12736:1): }
12737:1): }
12738:1): }
12739:1): }
12740:1): unless ($changes{$itemid}) {
12741:1): foreach my $key (keys(%{$domconfig{$action}{$itemid}})) {
12742:1): if (ref($domconfig{$action}{$itemid}{$key}) eq 'HASH') {
12743:1): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
12744:1): foreach my $innerkey (keys(%{$domconfig{$action}{$itemid}{$key}})) {
12745:1): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
12746:1): $changes{$itemid} = 1;
12747:1): last;
12748:1): }
12749:1): }
12750:1): } elsif (keys(%{$domconfig{$action}{$itemid}{$key}}) > 0) {
12751:1): $changes{$itemid} = 1;
12752:1): }
12753:1): }
12754:1): last if ($changes{$itemid});
12755:1): }
12756:1): }
12757:1): }
12758:1): }
12759:1): }
12760:1): if (@allpos > 0) {
12761:1): my $idx = 0;
12762:1): foreach my $itemid (@allpos) {
12763:1): if ($itemid ne '') {
12764:1): $confhash{$itemid}{'order'} = $idx;
12765:1): if (ref($domconfig{$action}) eq 'HASH') {
12766:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
12767:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
12768:1): $changes{$itemid} = 1;
12769:1): }
12770:1): }
12771:1): }
12772:1): $idx ++;
12773:1): }
12774:1): }
12775:1): }
12776:1): my %ltitoolshash = (
12777:1): $action => { %confhash }
12778:1): );
12779:1): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,
12780:1): $dom);
12781:1): if ($putresult eq 'ok') {
12782:1): my %ltienchash = (
12783:1): $action => { %encconfig }
12784:1): );
12785:1): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
12786:1): if (keys(%changes) > 0) {
12787:1): my $cachetime = 24*60*60;
12788:1): my %ltiall = %confhash;
12789:1): foreach my $id (keys(%ltiall)) {
12790:1): if (ref($encconfig{$id}) eq 'HASH') {
12791:1): foreach my $item ('key','secret') {
12792:1): $ltiall{$id}{$item} = $encconfig{$id}{$item};
12793:1): }
12794:1): }
12795:1): }
12796:1): &Apache::lonnet::do_cache_new('ltitools',$dom,\%ltiall,$cachetime);
12797:1): if (ref($lastactref) eq 'HASH') {
12798:1): $lastactref->{'ltitools'} = 1;
12799:1): }
12800:1): $resulttext = &mt('Changes made:').'<ul>';
12801:1): my %bynum;
12802:1): foreach my $itemid (sort(keys(%changes))) {
12803:1): my $position = $confhash{$itemid}{'order'};
12804:1): $bynum{$position} = $itemid;
12805:1): }
12806:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12807:1): my $itemid = $bynum{$pos};
12808:1): if (ref($confhash{$itemid}) ne 'HASH') {
12809:1): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12810:1): } else {
12811:1): $resulttext .= '<li><b>'.$confhash{$itemid}{'title'}.'</b>';
12812:1): if ($confhash{$itemid}{'image'}) {
12813:1): $resulttext .= ' '.
12814:1): '<img src="'.$confhash{$itemid}{'image'}.'"'.
12815:1): ' alt="'.&mt('Tool Provider icon').'" />';
12816:1): }
12817:1): $resulttext .= '</li><ul>';
12818:1): my $position = $pos + 1;
12819:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12820:1): foreach my $item ('version','msgtype','sigmethod','url','lifetime') {
12821:1): if ($confhash{$itemid}{$item} ne '') {
12822:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
12823:1): }
12824:1): }
12825:1): if ($encconfig{$itemid}{'key'} ne '') {
12826:1): $resulttext .= '<li>'.$lt{'key'}.': '.$encconfig{$itemid}{'key'}.'</li>';
12827:1): }
12828:1): if ($encconfig{$itemid}{'secret'} ne '') {
12829:1): $resulttext .= '<li>'.$lt{'secret'}.': ';
12830:1): my $num = length($encconfig{$itemid}{'secret'});
12831:1): $resulttext .= ('*'x$num).'</li>';
12832:1): }
12833:1): $resulttext .= '<li>'.&mt('Configurable in course:');
12834:1): my @possconfig = ('label','title','target','linktext','explanation','append');
12835:1): my $numconfig = 0;
12836:1): if (ref($confhash{$itemid}{'crsconf'}) eq 'HASH') {
12837:1): foreach my $item (@possconfig) {
12838:1): if ($confhash{$itemid}{'crsconf'}{$item}) {
12839:1): $numconfig ++;
12840:1): $resulttext .= ' "'.$lt{'crs'.$item}.'"';
12841:1): }
12842:1): }
12843:1): }
12844:1): if (!$numconfig) {
12845:1): $resulttext .= &mt('None');
12846:1): }
12847:1): $resulttext .= '</li>';
12848:1): if (ref($confhash{$itemid}{'display'}) eq 'HASH') {
12849:1): my $displaylist;
12850:1): if ($confhash{$itemid}{'display'}{'target'}) {
12851:1): $displaylist = &mt('Display target').': '.
12852:1): $confhash{$itemid}{'display'}{'target'}.',';
12853:1): }
12854:1): foreach my $size ('width','height') {
12855:1): if ($confhash{$itemid}{'display'}{$size}) {
12856:1): $displaylist .= (' 'x2).$lt{$size}.': '.
12857:1): $confhash{$itemid}{'display'}{$size}.',';
12858:1): }
12859:1): }
12860:1): if ($displaylist) {
12861:1): $displaylist =~ s/,$//;
12862:1): $resulttext .= '<li>'.$displaylist.'</li>';
12863:1): }
12864:1): foreach my $item ('linktext','explanation') {
12865:1): if ($confhash{$itemid}{'display'}{$item}) {
12866:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{'display'}{$item}.'</li>';
12867:1): }
12868:1): }
12869:1): }
12870:1): if (ref($confhash{$itemid}{'fields'}) eq 'HASH') {
12871:1): my $fieldlist;
12872:1): foreach my $field (@allfields) {
12873:1): if ($confhash{$itemid}{'fields'}{$field}) {
12874:1): $fieldlist .= (' 'x2).$lt{$field}.',';
12875:1): }
12876:1): }
12877:1): if ($fieldlist) {
12878:1): $fieldlist =~ s/,$//;
12879:1): if ($confhash{$itemid}{'fields'}{'user'}) {
12880:1): if ($confhash{$itemid}{'incdom'}) {
12881:1): $fieldlist .= ' ('.&mt('username:domain').')';
12882:1): } else {
12883:1): $fieldlist .= ' ('.&mt('username').')';
12884:1): }
12885:1): }
12886:1): $resulttext .= '<li>'.&mt('Data sent').':'.$fieldlist.'</li>';
12887:1): }
12888:1): }
12889:1): if (ref($confhash{$itemid}{'roles'}) eq 'HASH') {
12890:1): my $rolemaps;
12891:1): foreach my $role (@courseroles) {
12892:1): if ($confhash{$itemid}{'roles'}{$role}) {
12893:1): $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
12894:1): $confhash{$itemid}{'roles'}{$role}.',';
12895:1): }
12896:1): }
12897:1): if ($rolemaps) {
12898:1): $rolemaps =~ s/,$//;
12899:1): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
12900:1): }
12901:1): }
12902:1): if (ref($confhash{$itemid}{'custom'}) eq 'HASH') {
12903:1): my $customlist;
12904:1): if (keys(%{$confhash{$itemid}{'custom'}})) {
12905:1): foreach my $key (sort(keys(%{$confhash{$itemid}{'custom'}}))) {
12906:1): $customlist .= $key.':'.$confhash{$itemid}{'custom'}{$key}.(' 'x2);
12907:1): }
12908:1): }
12909:1): if ($customlist) {
12910:1): $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
12911:1): }
12912:1): }
12913:1): $resulttext .= '</ul></li>';
12914:1): }
12915:1): }
12916:1): $resulttext .= '</ul>';
12917:1): } else {
12918:1): $resulttext = &mt('No changes made.');
12919:1): }
12920:1): } else {
12921:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12922:1): }
12923:1): if ($errors) {
12924:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12925:1): $errors.'</ul>';
12926:1): }
12927:1): return $resulttext;
12928:1): }
12929:1):
12930:1): sub process_ltitools_image {
12931:1): my ($r,$dom,$confname,$caller,$itemid,$configuserok,$switchserver,$author_ok) = @_;
12932:1): my $filename = $env{'form.'.$caller.'.filename'};
12933:1): my ($error,$url);
12934:1): my ($width,$height) = (21,21);
12935:1): if ($configuserok eq 'ok') {
12936:1): if ($switchserver) {
12937:1): $error = &mt('Upload of Tool Provider (LTI) icon is not permitted to this server: [_1]',
12938:1): $switchserver);
12939:1): } elsif ($author_ok eq 'ok') {
12940:1): my ($result,$imageurl,$madethumb) =
12941:1): &publishlogo($r,'upload',$caller,$dom,$confname,
12942:1): "ltitools/$itemid/icon",$width,$height);
12943:1): if ($result eq 'ok') {
12944:1): if ($madethumb) {
12945:1): my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
12946:1): my $imagethumb = "$path/tn-".$imagefile;
12947:1): $url = $imagethumb;
12948:1): } else {
12949:1): $url = $imageurl;
12950:1): }
12951:1): } else {
12952:1): $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12953:1): }
12954:1): } else {
12955: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);
12956:1): }
12957:1): } else {
12958: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);
12959:1): }
12960:1): return ($url,$error);
12961:1): }
12962:1):
12963:1): sub get_ltitools_id {
12964:1): my ($cdom,$title) = @_;
12965:1): # get lock on ltitools db
12966:1): my $lockhash = {
12967:1): lock => $env{'user.name'}.
12968:1): ':'.$env{'user.domain'},
12969:1): };
12970:1): my $tries = 0;
12971:1): my $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12972:1): my ($id,$error);
12973:1):
12974:1): while (($gotlock ne 'ok') && ($tries<10)) {
12975:1): $tries ++;
12976:1): sleep (0.1);
12977:1): $gotlock = &Apache::lonnet::newput_dom('ltitools',$lockhash,$cdom);
12978:1): }
12979:1): if ($gotlock eq 'ok') {
12980:1): my %currids = &Apache::lonnet::dump_dom('ltitools',$cdom);
12981:1): if ($currids{'lock'}) {
12982:1): delete($currids{'lock'});
12983:1): if (keys(%currids)) {
12984:1): my @curr = sort { $a <=> $b } keys(%currids);
12985:1): if ($curr[-1] =~ /^\d+$/) {
12986:1): $id = 1 + $curr[-1];
12987:1): }
12988:1): } else {
12989:1): $id = 1;
12990:1): }
12991:1): if ($id) {
12992:1): unless (&Apache::lonnet::newput_dom('ltitools',{ $id => $title },$cdom) eq 'ok') {
12993:1): $error = 'nostore';
12994:1): }
12995:1): } else {
12996:1): $error = 'nonumber';
12997:1): }
12998:1): }
12999:1): my $dellockoutcome = &Apache::lonnet::del_dom('ltitools',['lock'],$cdom);
13000:1): } else {
13001:1): $error = 'nolock';
13002:1): }
13003:1): return ($id,$error);
13004:1): }
13005:1):
5(raebur 13006:2): sub modify_lti {
13007:2): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13008:2): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13009:2): my (%encconfig,$errors,$resulttext);
13010:2):
13011:2): my (%currltisec,%secchanges,%newltisec,%newltienc,%keyset,%newkeyset);
13012:2): $newltisec{'private'}{'keys'} = [];
13013:2): $newltisec{'encrypt'} = {};
13014:2): $newltisec{'rules'} = {};
13015:2): $newltisec{'linkprot'} = {};
13016:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
13017:2): %currltisec = %{$domconfig{'ltisec'}};
13018:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13019:2): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
13020:2): unless ($id =~ /^\d+$/) {
13021:2): delete($currltisec{'linkprot'}{$id});
13022:2): }
13023:2): }
13024:2): }
13025:2): if (ref($currltisec{'private'}) eq 'HASH') {
13026:2): if (ref($currltisec{'private'}{'keys'}) eq 'ARRAY') {
13027:2): $newltisec{'private'}{'keys'} = $currltisec{'private'}{'keys'};
13028:2): map { $keyset{$_} = 1; } @{$currltisec{'private'}{'keys'}};
13029:2): }
13030:2): }
13031:2): }
13032:2): foreach my $item ('crs','dom') {
13033:2): my $formelement = 'form.ltisec_'.$item.'linkprot';
13034:2): if ($env{$formelement}) {
13035:2): $newltisec{'encrypt'}{$item} = 1;
13036:2): if (ref($currltisec{'encrypt'}) eq 'HASH') {
13037:2): unless ($currltisec{'encrypt'}{$item}) {
13038:2): $secchanges{'encrypt'} = 1;
13039:2): }
13040:2): } else {
13041:2): $secchanges{'encrypt'} = 1;
13042:2): }
13043:2): } elsif (ref($currltisec{'encrypt'}) eq 'HASH') {
13044:2): if ($currltisec{'encrypt'}{$item}) {
13045:2): $secchanges{'encrypt'} = 1;
13046:2): }
13047:2): }
13048:2): }
13049:2): unless (exists($currltisec{'rules'})) {
13050:2): $currltisec{'rules'} = {};
13051:2): }
13052:2): &password_rule_changes('secrets',$newltisec{'rules'},$currltisec{'rules'},\%secchanges);
13053:2):
13054:2): my @ids=&Apache::lonnet::current_machine_ids();
13055:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
13056:2):
13057:2): foreach my $hostid (keys(%servers)) {
13058:2): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13059:2): my $newkey;
13060:2): my $keyitem = 'form.ltisec_privkey_'.$hostid;
13061:2): if (exists($env{$keyitem})) {
13062:2): $env{$keyitem} =~ s/(`)/'/g;
13063:2): if ($keyset{$hostid}) {
13064:2): if ($env{'form.ltisec_changeprivkey_'.$hostid}) {
13065:2): if ($env{$keyitem} ne '') {
13066:2): $secchanges{'private'} = 1;
13067:2): $newkeyset{$hostid} = $env{$keyitem};
13068:2): }
13069:2): }
13070:2): } elsif ($env{$keyitem} ne '') {
13071:2): unless (grep(/^\Q$hostid\E$/,@{$newltisec{'private'}{'keys'}})) {
13072:2): push(@{$newltisec{'private'}{'keys'}},$hostid);
13073:2): }
13074:2): $secchanges{'private'} = 1;
13075:2): $newkeyset{$hostid} = $env{$keyitem};
13076:2): }
13077:2): }
13078:2): }
13079:2): }
13080:2):
13081:2): my (%linkprotchg,$linkprotoutput,$is_home);
13082:2): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13083:2): \%linkprotchg,'domain');
13084:2): my $home = &Apache::lonnet::domain($dom,'primary');
13085:2): unless (($home eq 'no_host') || ($home eq '')) {
13086:2): my @ids=&Apache::lonnet::current_machine_ids();
13087:2): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13088:2): }
13089:2):
13090:2): if (keys(%linkprotchg)) {
13091:2): $secchanges{'linkprot'} = 1;
13092:2): my %oldlinkprot;
13093:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13094:2): %oldlinkprot = %{$currltisec{'linkprot'}};
13095:2): }
13096:2): foreach my $id (keys(%linkprotchg)) {
13097:2): if (ref($linkprotchg{$id}) eq 'HASH') {
13098:2): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13099:2): if (($inner eq 'secret') || ($inner eq 'key')) {
13100:2): if ($is_home) {
13101:2): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13102:2): }
13103:2): }
13104:2): }
13105:2): } else {
13106:2): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
13107:2): }
13108:2): }
13109:2): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13110:2): if (keys(%linkprotchg)) {
13111:2): %{$newltisec{'linkprot'}} = %linkprotchg;
13112:2): }
13113:2): }
13114:2): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13115:2): foreach my $id (%{$currltisec{'linkprot'}}) {
13116:2): next if ($id !~ /^\d+$/);
13117:2): unless (exists($linkprotchg{$id})) {
13118:2): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13119:2): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13120:2): if (($inner eq 'secret') || ($inner eq 'key')) {
13121:2): if ($is_home) {
13122:2): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13123:2): }
13124:2): } else {
13125:2): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13126:2): }
13127:2): }
13128:2): } else {
13129:2): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13130:2): }
13131:2): }
13132:2): }
13133:2): }
13134:2): if ($proterror) {
13135:2): $errors .= '<li>'.$proterror.'</li>';
13136:2): }
13137:2):
6(raebur 13138:2): my ($putresult,%keystore);
5(raebur 13139:2): if (keys(%secchanges)) {
13140:2): my %ltienchash;
13141:2): my %ltihash = (
13142:2): 'ltisec' => { %newltisec }
13143:2): );
13144:2): $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
13145:2): if ($putresult eq 'ok') {
13146:2): if ($secchanges{'private'}) {
13147:2): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13148:2): foreach my $hostid (keys(%newkeyset)) {
13149:2): my $storehash = {
13150:2): key => $newkeyset{$hostid},
13151:2): who => $env{'user.name'}.':'.$env{'user.domain'},
13152:2): };
13153:2): $keystore{$hostid} = &Apache::lonnet::store_dom($storehash,'lti','private',
13154:2): $dom,$hostid);
13155:2): }
13156:2): }
13157:2): if (ref($lastactref) eq 'HASH') {
13158:2): if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
13159:2): $lastactref->{'domdefaults'} = 1;
13160:2): }
13161:2): }
13162:2): if (($secchanges{'linkprot'}) && ($is_home)) {
13163:2): my %ltienchash = (
13164:2): 'linkprot' => { %newltienc }
13165:2): );
13166:2): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13167:2): }
13168:2): }
13169:2): } else {
13170:2): return &mt('No changes made.');
13171:2): }
13172:2): if ($putresult eq 'ok') {
13173:2): $resulttext = &mt('Changes made:').'<ul>';
13174:2): foreach my $item (keys(%secchanges)) {
13175:2): if ($item eq 'encrypt') {
13176:2): my %encrypted = (
13177:2): crs => {
13178:2): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13179:2): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13180:2): },
13181:2): dom => {
13182:2): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13183:2): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13184:2): },
13185:2): );
13186:2): foreach my $type ('crs','dom') {
13187:2): my $shown = $encrypted{$type}{'off'};
13188:2): if (ref($newltisec{$item}) eq 'HASH') {
13189:2): if ($newltisec{$item}{$type}) {
13190:2): $shown = $encrypted{$type}{'on'};
13191:2): }
13192:2): }
13193:2): $resulttext .= '<li>'.$shown.'</li>';
13194:2): }
13195:2): } elsif ($item eq 'rules') {
13196:2): my %titles = &Apache::lonlocal::texthash(
13197:2): min => 'Minimum password length',
13198:2): max => 'Maximum password length',
13199:2): chars => 'Required characters',
13200:2): );
13201:2): foreach my $rule ('min','max') {
13202:2): if ($newltisec{rules}{$rule} eq '') {
13203:2): if ($rule eq 'min') {
13204:2): $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13205:2): ' '.&mt('Default of [_1] will be used',
13206:2): $Apache::lonnet::passwdmin).'</li>';
13207:2): } else {
13208:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13209:2): }
13210:2): } else {
13211:2): $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newltisec{rules}{$rule}).'</li>';
13212:2): }
13213:2): }
13214:2): if (ref($newltisec{'rules'}{'chars'}) eq 'ARRAY') {
13215:2): if (@{$newltisec{'rules'}{'chars'}} > 0) {
13216:2): my %rulenames = &Apache::lonlocal::texthash(
13217:2): uc => 'At least one upper case letter',
13218:2): lc => 'At least one lower case letter',
13219:2): num => 'At least one number',
13220:2): spec => 'At least one non-alphanumeric',
13221:2): );
13222:2): my $needed = '<ul><li>'.
13223:2): join('</li><li>',map {$rulenames{$_} } @{$newltisec{'rules'}{'chars'}}).
13224:2): '</li></ul>';
13225:2): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13226:2): } else {
13227:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13228:2): }
13229:2): } else {
13230:2): $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13231:2): }
13232:2): } elsif ($item eq 'private') {
13233:2): if (keys(%newkeyset)) {
13234:2): foreach my $hostid (sort(keys(%newkeyset))) {
13235:2): if ($keystore{$hostid} eq 'ok') {
13236:2): $resulttext .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13237:2): }
13238:2): }
13239:2): }
13240:2): } elsif ($item eq 'linkprot') {
13241:2): $resulttext .= $linkprotoutput;
13242:2): }
13243:2): }
13244:2): $resulttext .= '</ul>';
13245:2): } else {
13246:2): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13247:2): }
13248:2): if ($errors) {
13249:2): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13250:2): $errors.'</ul>';
13251:2): }
13252:2): return $resulttext;
13253:2): }
13254:2):
1.3 raeburn 13255: sub modify_autoenroll {
1.160.6.24 raeburn 13256: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 13257: my ($resulttext,%changes);
13258: my %currautoenroll;
13259: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
13260: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
13261: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
13262: }
13263: }
13264: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
13265: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 13266: sender => 'Sender for notification messages',
1.160.6.68 raeburn 13267: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 13268: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 13269: my @offon = ('off','on');
1.17 raeburn 13270: my $sender_uname = $env{'form.sender_uname'};
13271: my $sender_domain = $env{'form.sender_domain'};
13272: if ($sender_domain eq '') {
13273: $sender_uname = '';
13274: } elsif ($sender_uname eq '') {
13275: $sender_domain = '';
13276: }
1.129 raeburn 13277: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 13278: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
13279: $autofailsafe =~ s{^\s+|\s+$}{}g;
13280: if ($autofailsafe =~ /\D/) {
13281: undef($autofailsafe);
13282: }
1.160.6.68 raeburn 13283: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 13284: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
13285: $failsafe = 'off';
13286: undef($autofailsafe);
1.160.6.68 raeburn 13287: }
1.1 raeburn 13288: my %autoenrollhash = (
1.129 raeburn 13289: autoenroll => { 'run' => $env{'form.autoenroll_run'},
13290: 'sender_uname' => $sender_uname,
13291: 'sender_domain' => $sender_domain,
13292: 'co-owners' => $coowners,
1.160.6.116 raeburn 13293: 'autofailsafe' => $autofailsafe,
13294: 'failsafe' => $failsafe,
1.1 raeburn 13295: }
13296: );
1.4 raeburn 13297: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
13298: $dom);
1.1 raeburn 13299: if ($putresult eq 'ok') {
13300: if (exists($currautoenroll{'run'})) {
13301: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
13302: $changes{'run'} = 1;
13303: }
13304: } elsif ($autorun) {
13305: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 13306: $changes{'run'} = 1;
1.1 raeburn 13307: }
13308: }
1.17 raeburn 13309: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 13310: $changes{'sender'} = 1;
13311: }
1.17 raeburn 13312: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 13313: $changes{'sender'} = 1;
13314: }
1.129 raeburn 13315: if ($currautoenroll{'co-owners'} ne '') {
13316: if ($currautoenroll{'co-owners'} ne $coowners) {
13317: $changes{'coowners'} = 1;
13318: }
13319: } elsif ($coowners) {
13320: $changes{'coowners'} = 1;
1.160.6.68 raeburn 13321: }
1.160.6.116 raeburn 13322: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 13323: $changes{'autofailsafe'} = 1;
13324: }
1.160.6.116 raeburn 13325: if ($currautoenroll{'failsafe'} ne $failsafe) {
13326: $changes{'failsafe'} = 1;
13327: }
1.1 raeburn 13328: if (keys(%changes) > 0) {
13329: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 13330: if ($changes{'run'}) {
1.1 raeburn 13331: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
13332: }
13333: if ($changes{'sender'}) {
1.17 raeburn 13334: if ($sender_uname eq '' || $sender_domain eq '') {
13335: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
13336: } else {
13337: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
13338: }
1.1 raeburn 13339: }
1.129 raeburn 13340: if ($changes{'coowners'}) {
13341: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
13342: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 13343: if (ref($lastactref) eq 'HASH') {
13344: $lastactref->{'domainconfig'} = 1;
13345: }
1.129 raeburn 13346: }
1.160.6.68 raeburn 13347: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 13348: if ($autofailsafe ne '') {
13349: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 13350: } else {
1.160.6.116 raeburn 13351: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 13352: }
1.160.6.116 raeburn 13353: }
13354: if ($changes{'failsafe'}) {
13355: if ($failsafe eq 'off') {
13356: unless ($changes{'autofailsafe'}) {
13357: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
13358: }
13359: } elsif ($failsafe eq 'zero') {
13360: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
13361: } else {
13362: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
13363: }
13364: }
13365: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 13366: &Apache::lonnet::get_domain_defaults($dom,1);
13367: if (ref($lastactref) eq 'HASH') {
13368: $lastactref->{'domdefaults'} = 1;
13369: }
13370: }
1.1 raeburn 13371: $resulttext .= '</ul>';
13372: } else {
13373: $resulttext = &mt('No changes made to auto-enrollment settings');
13374: }
13375: } else {
1.11 albertel 13376: $resulttext = '<span class="LC_error">'.
13377: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13378: }
1.3 raeburn 13379: return $resulttext;
1.1 raeburn 13380: }
13381:
13382: sub modify_autoupdate {
1.3 raeburn 13383: my ($dom,%domconfig) = @_;
1.1 raeburn 13384: my ($resulttext,%currautoupdate,%fields,%changes);
13385: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
13386: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
13387: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
13388: }
13389: }
13390: my @offon = ('off','on');
13391: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 13392: run => 'Auto-update:',
13393: classlists => 'Updates to user information in classlists?',
13394: unexpired => 'Skip updates for users without active or future roles?',
13395: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 13396: );
1.44 raeburn 13397: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13398: my %fieldtitles = &Apache::lonlocal::texthash (
13399: id => 'Student/Employee ID',
1.20 raeburn 13400: permanentemail => 'E-mail address',
1.1 raeburn 13401: lastname => 'Last Name',
13402: firstname => 'First Name',
13403: middlename => 'Middle Name',
1.132 raeburn 13404: generation => 'Generation',
1.1 raeburn 13405: );
1.142 raeburn 13406: $othertitle = &mt('All users');
1.1 raeburn 13407: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 13408: $othertitle = &mt('Other users');
1.1 raeburn 13409: }
13410: foreach my $key (keys(%env)) {
13411: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 13412: my ($usertype,$item) = ($1,$2);
13413: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
13414: if ($usertype eq 'default') {
13415: push(@{$fields{$1}},$2);
13416: } elsif (ref($types) eq 'ARRAY') {
13417: if (grep(/^\Q$usertype\E$/,@{$types})) {
13418: push(@{$fields{$1}},$2);
13419: }
13420: }
13421: }
1.1 raeburn 13422: }
13423: }
1.131 raeburn 13424: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
13425: @lockablenames = sort(@lockablenames);
13426: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
13427: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13428: if (@changed) {
13429: $changes{'lockablenames'} = 1;
13430: }
13431: } else {
13432: if (@lockablenames) {
13433: $changes{'lockablenames'} = 1;
13434: }
13435: }
1.1 raeburn 13436: my %updatehash = (
13437: autoupdate => { run => $env{'form.autoupdate_run'},
13438: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 13439: unexpired => $env{'form.unexpired'},
1.1 raeburn 13440: fields => {%fields},
1.131 raeburn 13441: lockablenames => \@lockablenames,
1.1 raeburn 13442: }
13443: );
1.160.6.113 raeburn 13444: my $lastactivedays;
13445: if ($env{'form.lastactive'}) {
13446: $lastactivedays = $env{'form.lastactivedays'};
13447: $lastactivedays =~ s/^\s+|\s+$//g;
13448: unless ($lastactivedays =~ /^\d+$/) {
13449: undef($lastactivedays);
13450: $env{'form.lastactive'} = 0;
13451: }
13452: }
13453: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 13454: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 13455: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 13456: if (exists($updatehash{autoupdate}{$key})) {
13457: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
13458: $changes{$key} = 1;
13459: }
13460: }
13461: } elsif ($key eq 'fields') {
13462: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 13463: foreach my $item (@{$types},'default') {
1.1 raeburn 13464: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
13465: my $change = 0;
13466: foreach my $type (@{$currautoupdate{$key}{$item}}) {
13467: if (!exists($fields{$item})) {
13468: $change = 1;
1.132 raeburn 13469: last;
1.1 raeburn 13470: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 13471: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 13472: $change = 1;
1.132 raeburn 13473: last;
1.1 raeburn 13474: }
13475: }
13476: }
13477: if ($change) {
13478: push(@{$changes{$key}},$item);
13479: }
1.26 raeburn 13480: }
1.1 raeburn 13481: }
13482: }
1.131 raeburn 13483: } elsif ($key eq 'lockablenames') {
13484: if (ref($currautoupdate{$key}) eq 'ARRAY') {
13485: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
13486: if (@changed) {
13487: $changes{'lockablenames'} = 1;
13488: }
13489: } else {
13490: if (@lockablenames) {
13491: $changes{'lockablenames'} = 1;
13492: }
13493: }
13494: }
13495: }
13496: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
13497: if (@lockablenames) {
13498: $changes{'lockablenames'} = 1;
1.1 raeburn 13499: }
13500: }
1.160.6.113 raeburn 13501: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
13502: if ($updatehash{'autoupdate'}{'unexpired'}) {
13503: $changes{'unexpired'} = 1;
13504: }
13505: }
13506: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
13507: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
13508: $changes{'lastactive'} = 1;
13509: }
13510: }
1.26 raeburn 13511: foreach my $item (@{$types},'default') {
13512: if (defined($fields{$item})) {
13513: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 13514: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
13515: my $change = 0;
13516: if (ref($fields{$item}) eq 'ARRAY') {
13517: foreach my $type (@{$fields{$item}}) {
13518: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
13519: $change = 1;
13520: last;
13521: }
13522: }
13523: }
13524: if ($change) {
13525: push(@{$changes{'fields'}},$item);
13526: }
13527: } else {
1.26 raeburn 13528: push(@{$changes{'fields'}},$item);
13529: }
13530: } else {
13531: push(@{$changes{'fields'}},$item);
1.1 raeburn 13532: }
13533: }
13534: }
13535: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
13536: $dom);
13537: if ($putresult eq 'ok') {
13538: if (keys(%changes) > 0) {
13539: $resulttext = &mt('Changes made:').'<ul>';
13540: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 13541: if ($key eq 'lockablenames') {
13542: $resulttext .= '<li>';
13543: if (@lockablenames) {
13544: $usertypes->{'default'} = $othertitle;
13545: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
13546: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
13547: } else {
13548: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
13549: }
13550: $resulttext .= '</li>';
13551: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 13552: foreach my $item (@{$changes{$key}}) {
13553: my @newvalues;
13554: foreach my $type (@{$fields{$item}}) {
13555: push(@newvalues,$fieldtitles{$type});
13556: }
1.3 raeburn 13557: my $newvaluestr;
13558: if (@newvalues > 0) {
13559: $newvaluestr = join(', ',@newvalues);
13560: } else {
13561: $newvaluestr = &mt('none');
1.6 raeburn 13562: }
1.1 raeburn 13563: if ($item eq 'default') {
1.26 raeburn 13564: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 13565: } else {
1.26 raeburn 13566: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 13567: }
13568: }
13569: } else {
13570: my $newvalue;
13571: if ($key eq 'run') {
13572: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 13573: } elsif ($key eq 'lastactive') {
13574: $newvalue = $offon[$env{'form.lastactive'}];
13575: unless ($lastactivedays eq '') {
13576: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
13577: }
1.1 raeburn 13578: } else {
13579: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 13580: }
1.1 raeburn 13581: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
13582: }
13583: }
13584: $resulttext .= '</ul>';
13585: } else {
1.3 raeburn 13586: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 13587: }
13588: } else {
1.11 albertel 13589: $resulttext = '<span class="LC_error">'.
13590: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13591: }
1.3 raeburn 13592: return $resulttext;
1.1 raeburn 13593: }
13594:
1.125 raeburn 13595: sub modify_autocreate {
13596: my ($dom,%domconfig) = @_;
13597: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
13598: if (ref($domconfig{'autocreate'}) eq 'HASH') {
13599: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
13600: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
13601: }
13602: }
13603: my %title= ( xml => 'Auto-creation of courses in XML course description files',
13604: req => 'Auto-creation of validated requests for official courses',
13605: xmldc => 'Identity of course creator of courses from XML files',
13606: );
13607: my @types = ('xml','req');
13608: foreach my $item (@types) {
13609: $newvals{$item} = $env{'form.autocreate_'.$item};
13610: $newvals{$item} =~ s/\D//g;
13611: $newvals{$item} = 0 if ($newvals{$item} eq '');
13612: }
13613: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 13614: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 13615: unless (exists($domcoords{$newvals{'xmldc'}})) {
13616: $newvals{'xmldc'} = '';
13617: }
13618: %autocreatehash = (
13619: autocreate => { xml => $newvals{'xml'},
13620: req => $newvals{'req'},
13621: }
13622: );
13623: if ($newvals{'xmldc'} ne '') {
13624: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
13625: }
13626: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
13627: $dom);
13628: if ($putresult eq 'ok') {
13629: my @items = @types;
13630: if ($newvals{'xml'}) {
13631: push(@items,'xmldc');
13632: }
13633: foreach my $item (@items) {
13634: if (exists($currautocreate{$item})) {
13635: if ($currautocreate{$item} ne $newvals{$item}) {
13636: $changes{$item} = 1;
13637: }
13638: } elsif ($newvals{$item}) {
13639: $changes{$item} = 1;
13640: }
13641: }
13642: if (keys(%changes) > 0) {
13643: my @offon = ('off','on');
13644: $resulttext = &mt('Changes made:').'<ul>';
13645: foreach my $item (@types) {
13646: if ($changes{$item}) {
13647: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 13648: $resulttext .= '<li>'.
13649: &mt("$title{$item} set to [_1]$newtxt [_2]",
13650: '<b>','</b>').
13651: '</li>';
1.125 raeburn 13652: }
13653: }
13654: if ($changes{'xmldc'}) {
13655: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
13656: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 13657: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 13658: }
13659: $resulttext .= '</ul>';
13660: } else {
13661: $resulttext = &mt('No changes made to auto-creation settings');
13662: }
13663: } else {
13664: $resulttext = '<span class="LC_error">'.
13665: &mt('An error occurred: [_1]',$putresult).'</span>';
13666: }
13667: return $resulttext;
13668: }
13669:
1.23 raeburn 13670: sub modify_directorysrch {
1.160.6.81 raeburn 13671: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 13672: my ($resulttext,%changes);
13673: my %currdirsrch;
13674: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
13675: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
13676: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
13677: }
13678: }
1.160.6.72 raeburn 13679: my %title = ( available => 'Institutional directory search available',
13680: localonly => 'Other domains can search institution',
13681: lcavailable => 'LON-CAPA directory search available',
13682: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 13683: searchby => 'Search types',
13684: searchtypes => 'Search latitude');
13685: my @offon = ('off','on');
1.24 raeburn 13686: my @otherdoms = ('Yes','No');
1.23 raeburn 13687:
1.25 raeburn 13688: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 13689: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
13690: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
13691:
1.44 raeburn 13692: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 13693: if (keys(%{$usertypes}) == 0) {
13694: @cansearch = ('default');
13695: } else {
13696: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
13697: foreach my $type (@{$currdirsrch{'cansearch'}}) {
13698: if (!grep(/^\Q$type\E$/,@cansearch)) {
13699: push(@{$changes{'cansearch'}},$type);
13700: }
1.23 raeburn 13701: }
1.26 raeburn 13702: foreach my $type (@cansearch) {
13703: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
13704: push(@{$changes{'cansearch'}},$type);
13705: }
1.23 raeburn 13706: }
1.26 raeburn 13707: } else {
13708: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 13709: }
13710: }
13711:
13712: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
13713: foreach my $by (@{$currdirsrch{'searchby'}}) {
13714: if (!grep(/^\Q$by\E$/,@searchby)) {
13715: push(@{$changes{'searchby'}},$by);
13716: }
13717: }
13718: foreach my $by (@searchby) {
13719: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
13720: push(@{$changes{'searchby'}},$by);
13721: }
13722: }
13723: } else {
13724: push(@{$changes{'searchby'}},@searchby);
13725: }
1.25 raeburn 13726:
13727: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
13728: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
13729: if (!grep(/^\Q$type\E$/,@searchtypes)) {
13730: push(@{$changes{'searchtypes'}},$type);
13731: }
13732: }
13733: foreach my $type (@searchtypes) {
13734: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
13735: push(@{$changes{'searchtypes'}},$type);
13736: }
13737: }
13738: } else {
13739: if (exists($currdirsrch{'searchtypes'})) {
13740: foreach my $type (@searchtypes) {
13741: if ($type ne $currdirsrch{'searchtypes'}) {
13742: push(@{$changes{'searchtypes'}},$type);
13743: }
13744: }
13745: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
13746: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
13747: }
13748: } else {
13749: push(@{$changes{'searchtypes'}},@searchtypes);
13750: }
13751: }
13752:
1.23 raeburn 13753: my %dirsrch_hash = (
13754: directorysrch => { available => $env{'form.dirsrch_available'},
13755: cansearch => \@cansearch,
1.160.6.72 raeburn 13756: localonly => $env{'form.dirsrch_instlocalonly'},
13757: lclocalonly => $env{'form.dirsrch_domlocalonly'},
13758: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 13759: searchby => \@searchby,
1.25 raeburn 13760: searchtypes => \@searchtypes,
1.23 raeburn 13761: }
13762: );
13763: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
13764: $dom);
13765: if ($putresult eq 'ok') {
13766: if (exists($currdirsrch{'available'})) {
13767: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
13768: $changes{'available'} = 1;
13769: }
13770: } else {
13771: if ($env{'form.dirsrch_available'} eq '1') {
13772: $changes{'available'} = 1;
13773: }
13774: }
1.160.6.72 raeburn 13775: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 13776: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
13777: $changes{'lcavailable'} = 1;
13778: }
1.24 raeburn 13779: } else {
1.160.6.72 raeburn 13780: if ($env{'form.dirsrch_lcavailable'} eq '1') {
13781: $changes{'lcavailable'} = 1;
13782: }
13783: }
13784: if (exists($currdirsrch{'localonly'})) {
13785: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 13786: $changes{'localonly'} = 1;
13787: }
1.160.6.72 raeburn 13788: } else {
13789: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
13790: $changes{'localonly'} = 1;
13791: }
13792: }
13793: if (exists($currdirsrch{'lclocalonly'})) {
13794: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
13795: $changes{'lclocalonly'} = 1;
13796: }
13797: } else {
13798: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
13799: $changes{'lclocalonly'} = 1;
13800: }
1.24 raeburn 13801: }
1.23 raeburn 13802: if (keys(%changes) > 0) {
13803: $resulttext = &mt('Changes made:').'<ul>';
13804: if ($changes{'available'}) {
13805: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
13806: }
1.160.6.72 raeburn 13807: if ($changes{'lcavailable'}) {
13808: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
13809: }
1.24 raeburn 13810: if ($changes{'localonly'}) {
1.160.6.72 raeburn 13811: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
13812: }
13813: if ($changes{'lclocalonly'}) {
13814: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 13815: }
1.23 raeburn 13816: if (ref($changes{'cansearch'}) eq 'ARRAY') {
13817: my $chgtext;
1.26 raeburn 13818: if (ref($usertypes) eq 'HASH') {
13819: if (keys(%{$usertypes}) > 0) {
13820: foreach my $type (@{$types}) {
13821: if (grep(/^\Q$type\E$/,@cansearch)) {
13822: $chgtext .= $usertypes->{$type}.'; ';
13823: }
13824: }
13825: if (grep(/^default$/,@cansearch)) {
13826: $chgtext .= $othertitle;
13827: } else {
13828: $chgtext =~ s/\; $//;
13829: }
1.160.6.13 raeburn 13830: $resulttext .=
13831: '<li>'.
13832: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
13833: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
13834: '</li>';
1.23 raeburn 13835: }
13836: }
13837: }
13838: if (ref($changes{'searchby'}) eq 'ARRAY') {
13839: my ($searchtitles,$titleorder) = &sorted_searchtitles();
13840: my $chgtext;
13841: foreach my $type (@{$titleorder}) {
13842: if (grep(/^\Q$type\E$/,@searchby)) {
13843: if (defined($searchtitles->{$type})) {
13844: $chgtext .= $searchtitles->{$type}.'; ';
13845: }
13846: }
13847: }
13848: $chgtext =~ s/\; $//;
13849: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
13850: }
1.25 raeburn 13851: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
13852: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
13853: my $chgtext;
13854: foreach my $type (@{$srchtypeorder}) {
13855: if (grep(/^\Q$type\E$/,@searchtypes)) {
13856: if (defined($srchtypes_desc->{$type})) {
13857: $chgtext .= $srchtypes_desc->{$type}.'; ';
13858: }
13859: }
13860: }
13861: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 13862: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 13863: }
13864: $resulttext .= '</ul>';
1.160.6.81 raeburn 13865: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
13866: if (ref($lastactref) eq 'HASH') {
13867: $lastactref->{'directorysrch'} = 1;
13868: }
1.23 raeburn 13869: } else {
1.160.6.72 raeburn 13870: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 13871: }
13872: } else {
13873: $resulttext = '<span class="LC_error">'.
1.27 raeburn 13874: &mt('An error occurred: [_1]',$putresult).'</span>';
13875: }
13876: return $resulttext;
13877: }
13878:
1.28 raeburn 13879: sub modify_contacts {
1.160.6.24 raeburn 13880: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 13881: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
13882: if (ref($domconfig{'contacts'}) eq 'HASH') {
13883: foreach my $key (keys(%{$domconfig{'contacts'}})) {
13884: $currsetting{$key} = $domconfig{'contacts'}{$key};
13885: }
13886: }
1.160.6.78 raeburn 13887: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 13888: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 13889: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 13890: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 13891: my @toggles = ('reporterrors','reportupdates','reportstatus');
13892: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 13893: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 13894: foreach my $type (@mailings) {
13895: @{$newsetting{$type}} =
13896: &Apache::loncommon::get_env_multiple('form.'.$type);
13897: foreach my $item (@contacts) {
13898: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
13899: $contacts_hash{contacts}{$type}{$item} = 1;
13900: } else {
13901: $contacts_hash{contacts}{$type}{$item} = 0;
13902: }
1.160.6.78 raeburn 13903: }
1.28 raeburn 13904: $others{$type} = $env{'form.'.$type.'_others'};
13905: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 13906: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 13907: $bcc{$type} = $env{'form.'.$type.'_bcc'};
13908: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 13909: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
13910: $includestr{$type} = $env{'form.'.$type.'_includestr'};
13911: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
13912: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
13913: }
1.134 raeburn 13914: }
1.28 raeburn 13915: }
13916: foreach my $item (@contacts) {
13917: $to{$item} = $env{'form.'.$item};
13918: $contacts_hash{'contacts'}{$item} = $to{$item};
13919: }
1.160.6.23 raeburn 13920: foreach my $item (@toggles) {
13921: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13922: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
13923: }
13924: }
1.160.6.107 raeburn 13925: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
13926: foreach my $item (@lonstatus) {
13927: if ($item eq 'excluded') {
13928: my (%serverhomes,@excluded);
13929: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
13930: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
13931: if (@possexcluded) {
13932: foreach my $id (sort(@possexcluded)) {
13933: if ($serverhomes{$id}) {
13934: push(@excluded,$id);
13935: }
13936: }
13937: }
13938: if (@excluded) {
13939: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
13940: }
13941: } elsif ($item eq 'weights') {
13942: foreach my $type ('E','W','N','U') {
13943: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
13944: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
13945: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
13946: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
13947: $env{'form.error'.$item.'_'.$type};
13948: }
13949: }
13950: }
13951: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
13952: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
13953: if ($env{'form.error'.$item} =~ /^\d+$/) {
13954: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
13955: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
13956: }
13957: }
13958: }
13959: }
1.160.6.78 raeburn 13960: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
13961: foreach my $field (@{$fields}) {
13962: if (ref($possoptions->{$field}) eq 'ARRAY') {
13963: my $value = $env{'form.helpform_'.$field};
13964: $value =~ s/^\s+|\s+$//g;
13965: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 13966: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 13967: if ($field eq 'screenshot') {
13968: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
13969: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 13970: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 13971: }
13972: }
13973: }
13974: }
13975: }
13976: }
1.160.6.101 raeburn 13977: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13978: my (@statuses,%usertypeshash,@overrides);
13979: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
13980: @statuses = @{$types};
13981: if (ref($usertypes) eq 'HASH') {
13982: %usertypeshash = %{$usertypes};
13983: }
13984: }
13985: if (@statuses) {
13986: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
13987: foreach my $type (@possoverrides) {
13988: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
13989: push(@overrides,$type);
13990: }
13991: }
13992: if (@overrides) {
13993: foreach my $type (@overrides) {
13994: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
13995: foreach my $item (@contacts) {
13996: if (grep(/^\Q$item\E$/,@standard)) {
13997: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
13998: $newsetting{'override_'.$type}{$item} = 1;
13999: } else {
14000: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
14001: $newsetting{'override_'.$type}{$item} = 0;
14002: }
14003: }
14004: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
14005: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14006: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
14007: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14008: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
14009: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
14010: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
14011: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14012: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
14013: }
14014: }
14015: }
14016: }
1.28 raeburn 14017: if (keys(%currsetting) > 0) {
14018: foreach my $item (@contacts) {
14019: if ($to{$item} ne $currsetting{$item}) {
14020: $changes{$item} = 1;
14021: }
14022: }
14023: foreach my $type (@mailings) {
14024: foreach my $item (@contacts) {
14025: if (ref($currsetting{$type}) eq 'HASH') {
14026: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14027: push(@{$changes{$type}},$item);
14028: }
14029: } else {
14030: push(@{$changes{$type}},@{$newsetting{$type}});
14031: }
14032: }
14033: if ($others{$type} ne $currsetting{$type}{'others'}) {
14034: push(@{$changes{$type}},'others');
14035: }
1.160.6.78 raeburn 14036: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14037: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14038: push(@{$changes{$type}},'bcc');
14039: }
1.160.6.78 raeburn 14040: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14041: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14042: push(@{$changes{$type}},'include');
14043: }
14044: }
14045: }
14046: if (ref($fields) eq 'ARRAY') {
14047: if (ref($currsetting{'helpform'}) eq 'HASH') {
14048: foreach my $field (@{$fields}) {
14049: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
14050: push(@{$changes{'helpform'}},$field);
14051: }
14052: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14053: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
14054: push(@{$changes{'helpform'}},'maxsize');
14055: }
14056: }
14057: }
14058: } else {
14059: foreach my $field (@{$fields}) {
14060: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14061: push(@{$changes{'helpform'}},$field);
14062: }
14063: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14064: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14065: push(@{$changes{'helpform'}},'maxsize');
14066: }
14067: }
14068: }
1.134 raeburn 14069: }
1.28 raeburn 14070: }
1.160.6.101 raeburn 14071: if (@statuses) {
14072: if (ref($currsetting{'overrides'}) eq 'HASH') {
14073: foreach my $key (keys(%{$currsetting{'overrides'}})) {
14074: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
14075: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
14076: foreach my $item (@contacts,'bcc','others','include') {
14077: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
14078: push(@{$changes{'overrides'}},$key);
14079: last;
14080: }
14081: }
14082: } else {
14083: push(@{$changes{'overrides'}},$key);
14084: }
14085: }
14086: }
14087: foreach my $key (@overrides) {
14088: unless (exists($currsetting{'overrides'}{$key})) {
14089: push(@{$changes{'overrides'}},$key);
14090: }
14091: }
14092: } else {
14093: foreach my $key (@overrides) {
14094: push(@{$changes{'overrides'}},$key);
14095: }
14096: }
14097: }
1.160.6.107 raeburn 14098: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
14099: foreach my $key ('excluded','weights','threshold','sysmail') {
14100: if ($key eq 'excluded') {
14101: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14102: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
14103: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14104: (@{$currsetting{'lonstatus'}{$key}})) {
14105: my @diffs =
14106: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
14107: $currsetting{'lonstatus'}{$key});
14108: if (@diffs) {
14109: push(@{$changes{'lonstatus'}},$key);
14110: }
14111: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
14112: push(@{$changes{'lonstatus'}},$key);
14113: }
14114: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14115: (@{$currsetting{'lonstatus'}{$key}})) {
14116: push(@{$changes{'lonstatus'}},$key);
14117: }
14118: } elsif ($key eq 'weights') {
14119: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14120: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
14121: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14122: foreach my $type ('E','W','N','U') {
14123: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
14124: $currsetting{'lonstatus'}{$key}{$type}) {
14125: push(@{$changes{'lonstatus'}},$key);
14126: last;
14127: }
14128: }
14129: } else {
14130: foreach my $type ('E','W','N','U') {
14131: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
14132: push(@{$changes{'lonstatus'}},$key);
14133: last;
14134: }
14135: }
14136: }
14137: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14138: foreach my $type ('E','W','N','U') {
14139: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
14140: push(@{$changes{'lonstatus'}},$key);
14141: last;
14142: }
14143: }
14144: }
14145: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
14146: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14147: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14148: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
14149: push(@{$changes{'lonstatus'}},$key);
14150: }
14151: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
14152: push(@{$changes{'lonstatus'}},$key);
14153: }
14154: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14155: push(@{$changes{'lonstatus'}},$key);
14156: }
14157: }
14158: }
14159: } else {
14160: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14161: foreach my $key ('excluded','weights','threshold','sysmail') {
14162: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14163: push(@{$changes{'lonstatus'}},$key);
14164: }
14165: }
14166: }
14167: }
1.28 raeburn 14168: } else {
14169: my %default;
14170: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
14171: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
14172: $default{'errormail'} = 'adminemail';
14173: $default{'packagesmail'} = 'adminemail';
14174: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 14175: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 14176: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 14177: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 14178: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 14179: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 14180: foreach my $item (@contacts) {
14181: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 14182: $changes{$item} = 1;
1.160.6.23 raeburn 14183: }
1.28 raeburn 14184: }
14185: foreach my $type (@mailings) {
14186: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
14187: push(@{$changes{$type}},@{$newsetting{$type}});
14188: }
14189: if ($others{$type} ne '') {
14190: push(@{$changes{$type}},'others');
1.134 raeburn 14191: }
1.160.6.78 raeburn 14192: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14193: if ($bcc{$type} ne '') {
14194: push(@{$changes{$type}},'bcc');
14195: }
1.160.6.78 raeburn 14196: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14197: push(@{$changes{$type}},'include');
14198: }
14199: }
14200: }
14201: if (ref($fields) eq 'ARRAY') {
14202: foreach my $field (@{$fields}) {
14203: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14204: push(@{$changes{'helpform'}},$field);
14205: }
14206: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14207: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14208: push(@{$changes{'helpform'}},'maxsize');
14209: }
14210: }
1.134 raeburn 14211: }
1.28 raeburn 14212: }
1.160.6.107 raeburn 14213: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14214: foreach my $key ('excluded','weights','threshold','sysmail') {
14215: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14216: push(@{$changes{'lonstatus'}},$key);
14217: }
14218: }
14219: }
1.28 raeburn 14220: }
1.160.6.23 raeburn 14221: foreach my $item (@toggles) {
14222: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
14223: $changes{$item} = 1;
14224: } elsif ((!$env{'form.'.$item}) &&
14225: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
14226: $changes{$item} = 1;
14227: }
14228: }
1.28 raeburn 14229: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
14230: $dom);
14231: if ($putresult eq 'ok') {
14232: if (keys(%changes) > 0) {
1.160.6.24 raeburn 14233: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14234: if (ref($lastactref) eq 'HASH') {
14235: $lastactref->{'domainconfig'} = 1;
14236: }
1.28 raeburn 14237: my ($titles,$short_titles) = &contact_titles();
14238: $resulttext = &mt('Changes made:').'<ul>';
14239: foreach my $item (@contacts) {
14240: if ($changes{$item}) {
14241: $resulttext .= '<li>'.$titles->{$item}.
14242: &mt(' set to: ').
14243: '<span class="LC_cusr_emph">'.
14244: $to{$item}.'</span></li>';
14245: }
14246: }
14247: foreach my $type (@mailings) {
14248: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 14249: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
14250: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
14251: } else {
14252: $resulttext .= '<li>'.$titles->{$type}.': ';
14253: }
1.28 raeburn 14254: my @text;
14255: foreach my $item (@{$newsetting{$type}}) {
14256: push(@text,$short_titles->{$item});
14257: }
14258: if ($others{$type} ne '') {
14259: push(@text,$others{$type});
14260: }
1.160.6.78 raeburn 14261: if (@text) {
14262: $resulttext .= '<span class="LC_cusr_emph">'.
14263: join(', ',@text).'</span>';
14264: }
14265: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14266: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 14267: my $bcctext;
14268: if (@text) {
14269: $bcctext = ' '.&mt('with Bcc to');
14270: } else {
14271: $bcctext = '(Bcc)';
14272: }
14273: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
14274: } elsif (!@text) {
14275: $resulttext .= &mt('No one');
1.134 raeburn 14276: }
1.160.6.78 raeburn 14277: if ($includestr{$type} ne '') {
14278: if ($includeloc{$type} eq 'b') {
14279: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
14280: } elsif ($includeloc{$type} eq 's') {
14281: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
14282: }
14283: }
14284: } elsif (!@text) {
14285: $resulttext .= &mt('No recipients');
1.134 raeburn 14286: }
14287: $resulttext .= '</li>';
1.28 raeburn 14288: }
14289: }
1.160.6.101 raeburn 14290: if (ref($changes{'overrides'}) eq 'ARRAY') {
14291: my @deletions;
14292: foreach my $type (@{$changes{'overrides'}}) {
14293: if ($usertypeshash{$type}) {
14294: if (grep(/^\Q$type\E/,@overrides)) {
14295: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
14296: $usertypeshash{$type}).'<ul><li>';
14297: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
14298: my @text;
14299: foreach my $item (@contacts) {
14300: if ($newsetting{'override_'.$type}{$item}) {
14301: push(@text,$short_titles->{$item});
14302: }
14303: }
14304: if ($newsetting{'override_'.$type}{'others'} ne '') {
14305: push(@text,$newsetting{'override_'.$type}{'others'});
14306: }
14307:
14308: if (@text) {
14309: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
14310: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
14311: }
14312: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
14313: my $bcctext;
14314: if (@text) {
14315: $bcctext = ' '.&mt('with Bcc to');
14316: } else {
14317: $bcctext = '(Bcc)';
14318: }
14319: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
14320: } elsif (!@text) {
14321: $resulttext .= &mt('Helpdesk e-mail sent to no one');
14322: }
14323: $resulttext .= '</li>';
14324: if ($newsetting{'override_'.$type}{'include'} ne '') {
14325: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
14326: if ($loc eq 'b') {
14327: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
14328: } elsif ($loc eq 's') {
14329: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
14330: }
14331: }
14332: }
14333: $resulttext .= '</li></ul></li>';
14334: } else {
14335: push(@deletions,$usertypeshash{$type});
14336: }
14337: }
14338: }
14339: if (@deletions) {
14340: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
14341: join(', ',@deletions)).'</li>';
14342: }
14343: }
1.160.6.23 raeburn 14344: my @offon = ('off','on');
1.160.6.107 raeburn 14345: my $corelink = &core_link_msu();
1.160.6.23 raeburn 14346: if ($changes{'reporterrors'}) {
14347: $resulttext .= '<li>'.
14348: &mt('E-mail error reports to [_1] set to "'.
14349: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 14350: $corelink).
1.160.6.23 raeburn 14351: '</li>';
14352: }
14353: if ($changes{'reportupdates'}) {
14354: $resulttext .= '<li>'.
14355: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
14356: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 14357: $corelink).
1.160.6.23 raeburn 14358: '</li>';
14359: }
1.160.6.107 raeburn 14360: if ($changes{'reportstatus'}) {
14361: $resulttext .= '<li>'.
14362: &mt('E-mail status if errors above threshold to [_1] set to "'.
14363: $offon[$env{'form.reportstatus'}].'".',
14364: $corelink).
14365: '</li>';
14366: }
14367: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
14368: $resulttext .= '<li>'.
14369: &mt('Nightly status check e-mail settings').':<ul>';
14370: my (%defval,%use_def,%shown);
14371: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
14372: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
14373: $defval{'weights'} =
14374: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
14375: $defval{'excluded'} = &mt('None');
14376: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
14377: foreach my $item ('threshold','sysmail','weights','excluded') {
14378: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
14379: if (($item eq 'threshold') || ($item eq 'sysmail')) {
14380: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
14381: } elsif ($item eq 'weights') {
14382: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
14383: foreach my $type ('E','W','N','U') {
14384: $shown{$item} .= $lonstatus_names->{$type}.'=';
14385: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
14386: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
14387: } else {
14388: $shown{$item} .= $lonstatus_defs->{$type};
14389: }
14390: $shown{$item} .= ', ';
14391: }
14392: $shown{$item} =~ s/, $//;
14393: } else {
14394: $shown{$item} = $defval{$item};
14395: }
14396: } elsif ($item eq 'excluded') {
14397: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
14398: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
14399: } else {
14400: $shown{$item} = $defval{$item};
14401: }
14402: }
14403: } else {
14404: $shown{$item} = $defval{$item};
14405: }
14406: }
14407: } else {
14408: foreach my $item ('threshold','weights','excluded','sysmail') {
14409: $shown{$item} = $defval{$item};
14410: }
14411: }
14412: foreach my $item ('threshold','weights','excluded','sysmail') {
14413: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
14414: $shown{$item}).'</li>';
14415: }
14416: $resulttext .= '</ul></li>';
14417: }
1.160.6.78 raeburn 14418: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
14419: my (@optional,@required,@unused,$maxsizechg);
14420: foreach my $field (@{$changes{'helpform'}}) {
14421: if ($field eq 'maxsize') {
14422: $maxsizechg = 1;
14423: next;
14424: }
14425: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
14426: push(@optional,$field);
14427: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
14428: push(@unused,$field);
14429: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
14430: push(@required,$field);
14431: }
14432: }
14433: if (@optional) {
14434: $resulttext .= '<li>'.
14435: &mt('Help form fields changed to "Optional": [_1].',
14436: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
14437: '</li>';
14438: }
14439: if (@required) {
14440: $resulttext .= '<li>'.
14441: &mt('Help form fields changed to "Required": [_1].',
14442: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
14443: '</li>';
14444: }
14445: if (@unused) {
14446: $resulttext .= '<li>'.
14447: &mt('Help form fields changed to "Not shown": [_1].',
14448: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
14449: '</li>';
14450: }
14451: if ($maxsizechg) {
14452: $resulttext .= '<li>'.
14453: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
14454: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
14455: '</li>';
14456: }
14457: }
1.28 raeburn 14458: $resulttext .= '</ul>';
14459: } else {
1.160.6.78 raeburn 14460: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 14461: }
14462: } else {
14463: $resulttext = '<span class="LC_error">'.
14464: &mt('An error occurred: [_1].',$putresult).'</span>';
14465: }
14466: return $resulttext;
14467: }
14468:
1.160.6.98 raeburn 14469: sub modify_passwords {
14470: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
14471: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
14472: $updatedefaults,$updateconf);
14473: my $customfn = 'resetpw.html';
14474: if (ref($domconfig{'passwords'}) eq 'HASH') {
14475: %current = %{$domconfig{'passwords'}};
14476: }
14477: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14478: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14479: if (ref($types) eq 'ARRAY') {
14480: @oktypes = @{$types};
14481: }
14482: push(@oktypes,'default');
14483:
14484: my %titles = &Apache::lonlocal::texthash (
14485: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
14486: intauth_check => 'Check bcrypt cost if authenticated',
14487: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
14488: permanent => 'Permanent e-mail address',
14489: critical => 'Critical notification address',
14490: notify => 'Notification address',
14491: min => 'Minimum password length',
14492: max => 'Maximum password length',
14493: chars => 'Required characters',
14494: numsaved => 'Number of previous passwords to save',
14495: reset => 'Resetting Forgotten Password',
14496: intauth => 'Encryption of Stored Passwords (Internal Auth)',
14497: rules => 'Rules for LON-CAPA Passwords',
14498: crsownerchg => 'Course Owner Changing Student Passwords',
14499: username => 'Username',
14500: email => 'E-mail address',
14501: );
14502:
14503: #
14504: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
14505: #
14506: my (%curr_defaults,%save_defaults);
14507: if (ref($domconfig{'defaults'}) eq 'HASH') {
14508: foreach my $key (keys(%{$domconfig{'defaults'}})) {
14509: if ($key =~ /^intauth_(cost|check|switch)$/) {
14510: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
14511: } else {
14512: $save_defaults{$key} = $domconfig{'defaults'}{$key};
14513: }
14514: }
14515: }
14516: my %staticdefaults = (
14517: 'resetlink' => 2,
14518: 'resetcase' => \@oktypes,
14519: 'resetprelink' => 'both',
14520: 'resetemail' => ['critical','notify','permanent'],
14521: 'intauth_cost' => 10,
14522: 'intauth_check' => 0,
14523: 'intauth_switch' => 0,
14524: );
1.160.6.99 raeburn 14525: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 14526: foreach my $type (@oktypes) {
14527: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
14528: }
14529: my $linklife = $env{'form.passwords_link'};
14530: $linklife =~ s/^\s+|\s+$//g;
14531: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
14532: $newvalues{'resetlink'} = $linklife;
14533: if ($current{'resetlink'}) {
14534: if ($current{'resetlink'} ne $linklife) {
14535: $changes{'reset'} = 1;
14536: }
1.160.6.102 raeburn 14537: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14538: if ($staticdefaults{'resetlink'} ne $linklife) {
14539: $changes{'reset'} = 1;
14540: }
14541: }
14542: } elsif ($current{'resetlink'}) {
14543: $changes{'reset'} = 1;
14544: }
14545: my @casesens;
14546: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
14547: foreach my $case (sort(@posscase)) {
14548: if (grep(/^\Q$case\E$/,@oktypes)) {
14549: push(@casesens,$case);
14550: }
14551: }
14552: $newvalues{'resetcase'} = \@casesens;
14553: if (ref($current{'resetcase'}) eq 'ARRAY') {
14554: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
14555: if (@diffs > 0) {
14556: $changes{'reset'} = 1;
14557: }
1.160.6.102 raeburn 14558: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14559: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
14560: if (@diffs > 0) {
14561: $changes{'reset'} = 1;
14562: }
14563: }
14564: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
14565: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
14566: if (exists($current{'resetprelink'})) {
14567: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
14568: $changes{'reset'} = 1;
14569: }
1.160.6.102 raeburn 14570: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14571: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
14572: $changes{'reset'} = 1;
14573: }
14574: }
14575: } elsif ($current{'resetprelink'}) {
14576: $changes{'reset'} = 1;
14577: }
14578: foreach my $type (@oktypes) {
14579: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
14580: my @postlink;
14581: foreach my $item (sort(@possplink)) {
14582: if ($item =~ /^(email|username)$/) {
14583: push(@postlink,$item);
14584: }
14585: }
14586: $newvalues{'resetpostlink'}{$type} = \@postlink;
14587: unless ($changes{'reset'}) {
14588: if (ref($current{'resetpostlink'}) eq 'HASH') {
14589: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
14590: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
14591: if (@diffs > 0) {
14592: $changes{'reset'} = 1;
14593: }
14594: } else {
14595: $changes{'reset'} = 1;
14596: }
1.160.6.102 raeburn 14597: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14598: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
14599: if (@diffs > 0) {
14600: $changes{'reset'} = 1;
14601: }
14602: }
14603: }
14604: }
14605: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
14606: my @resetemail;
14607: foreach my $item (sort(@possemailsrc)) {
14608: if ($item =~ /^(permanent|critical|notify)$/) {
14609: push(@resetemail,$item);
14610: }
14611: }
14612: $newvalues{'resetemail'} = \@resetemail;
14613: unless ($changes{'reset'}) {
14614: if (ref($current{'resetemail'}) eq 'ARRAY') {
14615: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
14616: if (@diffs > 0) {
14617: $changes{'reset'} = 1;
14618: }
1.160.6.102 raeburn 14619: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 14620: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
14621: if (@diffs > 0) {
14622: $changes{'reset'} = 1;
14623: }
14624: }
14625: }
14626: if ($env{'form.passwords_stdtext'} == 0) {
14627: $newvalues{'resetremove'} = 1;
14628: unless ($current{'resetremove'}) {
14629: $changes{'reset'} = 1;
14630: }
14631: } elsif ($current{'resetremove'}) {
14632: $changes{'reset'} = 1;
14633: }
14634: if ($env{'form.passwords_customfile.filename'} ne '') {
14635: my $servadm = $r->dir_config('lonAdmEMail');
14636: my $servadm = $r->dir_config('lonAdmEMail');
14637: my ($configuserok,$author_ok,$switchserver) =
14638: &config_check($dom,$confname,$servadm);
14639: my $error;
14640: if ($configuserok eq 'ok') {
14641: if ($switchserver) {
14642: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
14643: } else {
14644: if ($author_ok eq 'ok') {
14645: my ($result,$customurl) =
14646: &publishlogo($r,'upload','passwords_customfile',$dom,
14647: $confname,'customtext/resetpw','','',$customfn);
14648: if ($result eq 'ok') {
14649: $newvalues{'resetcustom'} = $customurl;
14650: $changes{'reset'} = 1;
14651: } else {
14652: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
14653: }
14654: } else {
14655: $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);
14656: }
14657: }
14658: } else {
14659: $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);
14660: }
14661: if ($error) {
14662: &Apache::lonnet::logthis($error);
14663: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14664: }
14665: } elsif ($current{'resetcustom'}) {
14666: if ($env{'form.passwords_custom_del'}) {
14667: $changes{'reset'} = 1;
14668: } else {
14669: $newvalues{'resetcustom'} = $current{'resetcustom'};
14670: }
14671: }
14672: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
14673: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
14674: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
14675: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
14676: $changes{'intauth'} = 1;
14677: }
14678: } else {
14679: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
14680: }
14681: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
14682: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
14683: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
14684: $changes{'intauth'} = 1;
14685: }
14686: } else {
14687: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14688: }
14689: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
14690: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
14691: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
14692: $changes{'intauth'} = 1;
14693: }
14694: } else {
14695: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
14696: }
14697: foreach my $item ('cost','check','switch') {
14698: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
14699: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
14700: $updatedefaults = 1;
14701: }
14702: }
1.160.6.118.2 5(raebur 14703:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 14704: my %crsownerchg = (
14705: by => [],
14706: for => [],
14707: );
14708: foreach my $item ('by','for') {
14709: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
14710: foreach my $type (sort(@posstypes)) {
14711: if (grep(/^\Q$type\E$/,@oktypes)) {
14712: push(@{$crsownerchg{$item}},$type);
14713: }
14714: }
14715: }
14716: $newvalues{'crsownerchg'} = \%crsownerchg;
14717: if (ref($current{'crsownerchg'}) eq 'HASH') {
14718: foreach my $item ('by','for') {
14719: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
14720: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
14721: if (@diffs > 0) {
14722: $changes{'crsownerchg'} = 1;
14723: last;
14724: }
14725: }
14726: }
1.160.6.102 raeburn 14727: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 14728: foreach my $item ('by','for') {
14729: if (@{$crsownerchg{$item}} > 0) {
14730: $changes{'crsownerchg'} = 1;
14731: last;
14732: }
14733: }
14734: }
14735:
14736: my %confighash = (
14737: defaults => \%save_defaults,
14738: passwords => \%newvalues,
14739: );
14740: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
14741:
14742: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
14743: if ($putresult eq 'ok') {
14744: if (keys(%changes) > 0) {
14745: $resulttext = &mt('Changes made: ').'<ul>';
14746: foreach my $key ('reset','intauth','rules','crsownerchg') {
14747: if ($changes{$key}) {
14748: unless ($key eq 'intauth') {
14749: $updateconf = 1;
14750: }
14751: $resulttext .= '<li>'.$titles{$key}.':<ul>';
14752: if ($key eq 'reset') {
14753: if ($confighash{'passwords'}{'captcha'} eq 'original') {
14754: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
14755: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
14756: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 14757: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
14758: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
14759: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
14760: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
14761: }
1.160.6.98 raeburn 14762: } else {
14763: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
14764: }
14765: if ($confighash{'passwords'}{'resetlink'}) {
14766: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
14767: } else {
14768: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
14769: &mt('Will default to 2 hours').'</li>';
14770: }
14771: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
14772: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
14773: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
14774: } else {
14775: my $casesens;
14776: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
14777: if ($type eq 'default') {
14778: $casesens .= $othertitle.', ';
14779: } elsif ($usertypes->{$type} ne '') {
14780: $casesens .= $usertypes->{$type}.', ';
14781: }
14782: }
14783: $casesens =~ s/\Q, \E$//;
14784: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
14785: }
14786: } else {
14787: $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>';
14788: }
14789: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
14790: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
14791: } else {
14792: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
14793: }
14794: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
14795: my $output;
14796: if (ref($types) eq 'ARRAY') {
14797: foreach my $type (@{$types}) {
14798: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
14799: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
14800: $output .= $usertypes->{$type}.' -- '.&mt('none');
14801: } else {
14802: $output .= $usertypes->{$type}.' -- '.
14803: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
14804: }
14805: }
14806: }
14807: }
14808: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
14809: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
14810: $output .= $othertitle.' -- '.&mt('none');
14811: } else {
14812: $output .= $othertitle.' -- '.
14813: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
14814: }
14815: }
14816: if ($output) {
14817: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
14818: } else {
14819: $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>';
14820: }
14821: } else {
14822: $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>';
14823: }
14824: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
14825: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
14826: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
14827: } else {
14828: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
14829: }
14830: } else {
1.160.6.110 raeburn 14831: $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 14832: }
14833: if ($confighash{'passwords'}{'resetremove'}) {
14834: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
14835: } else {
14836: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
14837: }
14838: if ($confighash{'passwords'}{'resetcustom'}) {
14839: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 14840: &mt('custom text'),600,500,undef,undef,
14841: undef,undef,'background-color:#ffffff');
14842: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 14843: } else {
14844: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
14845: }
14846: } elsif ($key eq 'intauth') {
14847: foreach my $item ('cost','switch','check') {
14848: my $value = $save_defaults{$key.'_'.$item};
14849: if ($item eq 'switch') {
14850: my %optiondesc = &Apache::lonlocal::texthash (
14851: 0 => 'No',
14852: 1 => 'Yes',
14853: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
14854: );
14855: if ($value =~ /^(0|1|2)$/) {
14856: $value = $optiondesc{$value};
14857: } else {
14858: $value = &mt('none -- defaults to No');
14859: }
14860: } elsif ($item eq 'check') {
14861: my %optiondesc = &Apache::lonlocal::texthash (
14862: 0 => 'No',
14863: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
14864: 2 => 'Yes, disallow login if stored cost is less than domain default',
14865: );
14866: if ($value =~ /^(0|1|2)$/) {
14867: $value = $optiondesc{$value};
14868: } else {
14869: $value = &mt('none -- defaults to No');
14870: }
14871: }
14872: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
14873: }
14874: } elsif ($key eq 'rules') {
14875: foreach my $rule ('min','max','numsaved') {
14876: if ($confighash{'passwords'}{$rule} eq '') {
14877: if ($rule eq 'min') {
14878: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 14879: ' '.&mt('Default of [_1] will be used',
14880: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 14881: } else {
14882: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14883: }
14884: } else {
14885: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
14886: }
14887: }
1.160.6.104 raeburn 14888: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
14889: if (@{$confighash{'passwords'}{'chars'}} > 0) {
14890: my %rulenames = &Apache::lonlocal::texthash(
14891: uc => 'At least one upper case letter',
14892: lc => 'At least one lower case letter',
14893: num => 'At least one number',
14894: spec => 'At least one non-alphanumeric',
14895: );
14896: my $needed = '<ul><li>'.
14897: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
14898: '</li></ul>';
14899: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14900: } else {
14901: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14902: }
14903: } else {
14904: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
14905: }
1.160.6.98 raeburn 14906: } elsif ($key eq 'crsownerchg') {
14907: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
14908: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
14909: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
14910: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14911: } else {
14912: my %crsownerstr;
14913: foreach my $item ('by','for') {
14914: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
14915: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
14916: if ($type eq 'default') {
14917: $crsownerstr{$item} .= $othertitle.', ';
14918: } elsif ($usertypes->{$type} ne '') {
14919: $crsownerstr{$item} .= $usertypes->{$type}.', ';
14920: }
14921: }
14922: $crsownerstr{$item} =~ s/\Q, \E$//;
14923: }
14924: }
14925: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
14926: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
14927: }
14928: } else {
14929: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
14930: }
14931: }
14932: $resulttext .= '</ul></li>';
14933: }
14934: }
14935: $resulttext .= '</ul>';
14936: } else {
14937: $resulttext = &mt('No changes made to password settings');
14938: }
14939: my $cachetime = 24*60*60;
14940: if ($updatedefaults) {
14941: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14942: if (ref($lastactref) eq 'HASH') {
14943: $lastactref->{'domdefaults'} = 1;
14944: }
14945: }
14946: if ($updateconf) {
14947: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
14948: if (ref($lastactref) eq 'HASH') {
14949: $lastactref->{'passwdconf'} = 1;
14950: }
14951: }
14952: } else {
14953: $resulttext = '<span class="LC_error">'.
14954: &mt('An error occurred: [_1]',$putresult).'</span>';
14955: }
14956: if ($errors) {
14957: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14958: $errors.'</ul></p>';
14959: }
14960: return $resulttext;
14961: }
14962:
1.160.6.118.2 5(raebur 14963:2): sub password_rule_changes {
14964:2): my ($prefix,$newvalues,$current,$changes) = @_;
14965:2): return unless ((ref($newvalues) eq 'HASH') &&
14966:2): (ref($current) eq 'HASH') &&
14967:2): (ref($changes) eq 'HASH'));
14968:2): my (@rules,%staticdefaults);
14969:2): if ($prefix eq 'passwords') {
14970:2): @rules = ('min','max','numsaved');
14971:2): } elsif ($prefix eq 'secrets') {
14972:2): @rules = ('min','max');
14973:2): }
14974:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
14975:2): foreach my $rule (@rules) {
14976:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
14977:2): my $ruleok;
14978:2): if ($rule eq 'min') {
14979:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
14980:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
14981:2): $ruleok = 1;
14982:2): }
14983:2): }
14984:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
14985:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
14986:2): $ruleok = 1;
14987:2): }
14988:2): if ($ruleok) {
14989:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
14990:2): if (exists($current->{$rule})) {
14991:2): if ($newvalues->{$rule} ne $current->{$rule}) {
14992:2): $changes->{'rules'} = 1;
14993:2): }
14994:2): } elsif ($rule eq 'min') {
14995:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
14996:2): $changes->{'rules'} = 1;
14997:2): }
14998:2): } else {
14999:2): $changes->{'rules'} = 1;
15000:2): }
15001:2): } elsif (exists($current->{$rule})) {
15002:2): $changes->{'rules'} = 1;
15003:2): }
15004:2): }
15005:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
15006:2): my @chars;
15007:2): foreach my $item (sort(@posschars)) {
15008:2): if ($item =~ /^(uc|lc|num|spec)$/) {
15009:2): push(@chars,$item);
15010:2): }
15011:2): }
15012:2): $newvalues->{'chars'} = \@chars;
15013:2): unless ($changes->{'rules'}) {
15014:2): if (ref($current->{'chars'}) eq 'ARRAY') {
15015:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
15016:2): if (@diffs > 0) {
15017:2): $changes->{'rules'} = 1;
15018:2): }
15019:2): } else {
15020:2): if (@chars > 0) {
15021:2): $changes->{'rules'} = 1;
15022:2): }
15023:2): }
15024:2): }
15025:2): return;
15026:2): }
15027:2):
1.28 raeburn 15028: sub modify_usercreation {
1.27 raeburn 15029: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15030: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 15031: my $warningmsg;
1.27 raeburn 15032: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15033: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 15034: if ($key eq 'cancreate') {
15035: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15036: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 15037: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 15038: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 15039: } else {
15040: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 15041: }
1.50 raeburn 15042: }
1.43 raeburn 15043: }
1.160.6.34 raeburn 15044: } elsif ($key eq 'email_rule') {
15045: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15046: } else {
15047: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 15048: }
15049: }
1.34 raeburn 15050: }
1.160.6.34 raeburn 15051: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
15052: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
15053: my @contexts = ('author','course','requestcrs');
15054: foreach my $item(@contexts) {
15055: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 15056: }
1.34 raeburn 15057: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15058: foreach my $item (@contexts) {
1.160.6.34 raeburn 15059: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15060: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 15061: }
1.27 raeburn 15062: }
1.34 raeburn 15063: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15064: foreach my $item (@contexts) {
1.43 raeburn 15065: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 15066: if ($cancreate{$item} ne 'any') {
15067: push(@{$changes{'cancreate'}},$item);
15068: }
15069: } else {
15070: if ($cancreate{$item} ne 'none') {
15071: push(@{$changes{'cancreate'}},$item);
15072: }
1.27 raeburn 15073: }
15074: }
15075: } else {
1.43 raeburn 15076: foreach my $item (@contexts) {
1.34 raeburn 15077: push(@{$changes{'cancreate'}},$item);
15078: }
1.27 raeburn 15079: }
1.34 raeburn 15080:
1.27 raeburn 15081: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15082: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15083: if (!grep(/^\Q$type\E$/,@username_rule)) {
15084: push(@{$changes{'username_rule'}},$type);
15085: }
15086: }
15087: foreach my $type (@username_rule) {
15088: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15089: push(@{$changes{'username_rule'}},$type);
15090: }
15091: }
15092: } else {
15093: push(@{$changes{'username_rule'}},@username_rule);
15094: }
15095:
1.32 raeburn 15096: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15097: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15098: if (!grep(/^\Q$type\E$/,@id_rule)) {
15099: push(@{$changes{'id_rule'}},$type);
15100: }
15101: }
15102: foreach my $type (@id_rule) {
15103: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15104: push(@{$changes{'id_rule'}},$type);
15105: }
15106: }
15107: } else {
15108: push(@{$changes{'id_rule'}},@id_rule);
15109: }
15110:
1.43 raeburn 15111: my @authen_contexts = ('author','course','domain');
1.28 raeburn 15112: my @authtypes = ('int','krb4','krb5','loc');
15113: my %authhash;
1.43 raeburn 15114: foreach my $item (@authen_contexts) {
1.28 raeburn 15115: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15116: foreach my $auth (@authtypes) {
15117: if (grep(/^\Q$auth\E$/,@authallowed)) {
15118: $authhash{$item}{$auth} = 1;
15119: } else {
15120: $authhash{$item}{$auth} = 0;
15121: }
15122: }
15123: }
15124: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 15125: foreach my $item (@authen_contexts) {
1.28 raeburn 15126: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15127: foreach my $auth (@authtypes) {
15128: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15129: push(@{$changes{'authtypes'}},$item);
15130: last;
15131: }
15132: }
15133: }
15134: }
15135: } else {
1.43 raeburn 15136: foreach my $item (@authen_contexts) {
1.28 raeburn 15137: push(@{$changes{'authtypes'}},$item);
15138: }
15139: }
15140:
1.160.6.34 raeburn 15141: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15142: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15143: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15144: $save_usercreate{'id_rule'} = \@id_rule;
15145: $save_usercreate{'username_rule'} = \@username_rule,
15146: $save_usercreate{'authtypes'} = \%authhash;
15147:
1.27 raeburn 15148: my %usercreation_hash = (
1.160.6.34 raeburn 15149: usercreation => \%save_usercreate,
15150: );
1.27 raeburn 15151:
15152: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15153: $dom);
1.50 raeburn 15154:
1.160.6.34 raeburn 15155: if ($putresult eq 'ok') {
15156: if (keys(%changes) > 0) {
15157: $resulttext = &mt('Changes made:').'<ul>';
15158: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15159: my %lt = &usercreation_types();
15160: foreach my $type (@{$changes{'cancreate'}}) {
15161: my $chgtext = $lt{$type}.', ';
15162: if ($cancreate{$type} eq 'none') {
15163: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15164: } elsif ($cancreate{$type} eq 'any') {
15165: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15166: } elsif ($cancreate{$type} eq 'official') {
15167: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15168: } elsif ($cancreate{$type} eq 'unofficial') {
15169: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15170: }
15171: $resulttext .= '<li>'.$chgtext.'</li>';
15172: }
15173: }
15174: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15175: my ($rules,$ruleorder) =
15176: &Apache::lonnet::inst_userrules($dom,'username');
15177: my $chgtext = '<ul>';
15178: foreach my $type (@username_rule) {
15179: if (ref($rules->{$type}) eq 'HASH') {
15180: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15181: }
15182: }
15183: $chgtext .= '</ul>';
15184: if (@username_rule > 0) {
15185: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15186: } else {
15187: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15188: }
15189: }
15190: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15191: my ($idrules,$idruleorder) =
15192: &Apache::lonnet::inst_userrules($dom,'id');
15193: my $chgtext = '<ul>';
15194: foreach my $type (@id_rule) {
15195: if (ref($idrules->{$type}) eq 'HASH') {
15196: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15197: }
15198: }
15199: $chgtext .= '</ul>';
15200: if (@id_rule > 0) {
15201: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15202: } else {
15203: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
15204: }
15205: }
15206: my %authname = &authtype_names();
15207: my %context_title = &context_names();
15208: if (ref($changes{'authtypes'}) eq 'ARRAY') {
15209: my $chgtext = '<ul>';
15210: foreach my $type (@{$changes{'authtypes'}}) {
15211: my @allowed;
15212: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
15213: foreach my $auth (@authtypes) {
15214: if ($authhash{$type}{$auth}) {
15215: push(@allowed,$authname{$auth});
15216: }
15217: }
15218: if (@allowed > 0) {
15219: $chgtext .= join(', ',@allowed).'</li>';
15220: } else {
15221: $chgtext .= &mt('none').'</li>';
15222: }
15223: }
15224: $chgtext .= '</ul>';
15225: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
15226: $resulttext .= '</li>';
15227: }
15228: $resulttext .= '</ul>';
15229: } else {
15230: $resulttext = &mt('No changes made to user creation settings');
15231: }
15232: } else {
15233: $resulttext = '<span class="LC_error">'.
15234: &mt('An error occurred: [_1]',$putresult).'</span>';
15235: }
15236: if ($warningmsg ne '') {
15237: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
15238: }
15239: return $resulttext;
15240: }
15241:
15242: sub modify_selfcreation {
1.160.6.93 raeburn 15243: my ($dom,$lastactref,%domconfig) = @_;
15244: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
15245: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
15246: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15247: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
15248: if (ref($typesref) eq 'ARRAY') {
15249: @types = @{$typesref};
15250: }
15251: if (ref($usertypesref) eq 'HASH') {
15252: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 15253: }
1.160.6.93 raeburn 15254: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 15255: #
15256: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
15257: #
15258: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15259: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
15260: if ($key eq 'cancreate') {
15261: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15262: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
15263: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 15264: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
15265: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
15266: ($item eq 'emailusername') || ($item eq 'shibenv') ||
15267: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
15268: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 15269: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15270: } else {
15271: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
15272: }
15273: }
15274: }
15275: } elsif ($key eq 'email_rule') {
15276: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
15277: } else {
15278: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15279: }
15280: }
15281: }
15282: #
15283: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
15284: #
15285: if (ref($domconfig{'usermodification'}) eq 'HASH') {
15286: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
15287: if ($key eq 'selfcreate') {
15288: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
15289: } else {
15290: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
15291: }
15292: }
15293: }
1.160.6.93 raeburn 15294: #
15295: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
15296: #
15297: if (ref($domconfig{'inststatus'}) eq 'HASH') {
15298: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
15299: if ($key eq 'inststatusguest') {
15300: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
15301: } else {
15302: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
15303: }
15304: }
15305: }
1.160.6.34 raeburn 15306:
15307: my @contexts = ('selfcreate');
15308: @{$cancreate{'selfcreate'}} = ();
15309: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 15310: if (@types) {
15311: @{$cancreate{'statustocreate'}} = ();
15312: }
1.160.6.40 raeburn 15313: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 15314: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 15315: %{$cancreate{'emailverified'}} = ();
15316: %{$cancreate{'emailoptions'}} = ();
15317: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 15318: my %selfcreatetypes = (
15319: sso => 'users authenticated by institutional single sign on',
15320: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 15321: email => 'users verified by e-mail',
1.50 raeburn 15322: );
1.160.6.34 raeburn 15323: #
15324: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
15325: # is permitted.
15326: #
1.160.6.40 raeburn 15327:
1.160.6.93 raeburn 15328: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 15329:
1.160.6.93 raeburn 15330: my (@statuses,%email_rule);
1.160.6.35 raeburn 15331: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 15332: if ($item eq 'email') {
1.160.6.40 raeburn 15333: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 15334: if (@types) {
15335: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
15336: foreach my $status (@poss_statuses) {
15337: if (grep(/^\Q$status\E$/,(@types,'default'))) {
15338: push(@statuses,$status);
15339: }
15340: }
15341: $save_inststatus{'inststatusguest'} = \@statuses;
15342: } else {
15343: push(@statuses,'default');
15344: }
15345: if (@statuses) {
15346: my %curr_rule;
15347: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
15348: foreach my $type (@statuses) {
15349: $curr_rule{$type} = $curr_usercreation{'email_rule'};
15350: }
15351: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
15352: foreach my $type (@statuses) {
15353: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
15354: }
15355: }
15356: push(@{$cancreate{'selfcreate'}},'email');
15357: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
15358: my %curremaildom;
15359: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
15360: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
15361: }
15362: foreach my $type (@statuses) {
15363: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
15364: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
15365: }
15366: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
15367: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
15368: }
15369: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
15370: #
15371: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
15372: #
15373: my $chosen = $1;
15374: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
15375: my $emaildom;
15376: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
15377: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
15378: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
15379: if (ref($curremaildom{$type}) eq 'HASH') {
15380: if (exists($curremaildom{$type}{$chosen})) {
15381: if ($curremaildom{$type}{$chosen} ne $emaildom) {
15382: push(@{$changes{'cancreate'}},'emaildomain');
15383: }
15384: } elsif ($emaildom ne '') {
15385: push(@{$changes{'cancreate'}},'emaildomain');
15386: }
15387: } elsif ($emaildom ne '') {
15388: push(@{$changes{'cancreate'}},'emaildomain');
15389: }
15390: }
15391: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15392: } elsif ($chosen eq 'custom') {
15393: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
15394: $email_rule{$type} = [];
15395: if (ref($emailrules) eq 'HASH') {
15396: foreach my $rule (@possemail_rules) {
15397: if (exists($emailrules->{$rule})) {
15398: push(@{$email_rule{$type}},$rule);
15399: }
15400: }
15401: }
15402: if (@{$email_rule{$type}}) {
15403: $cancreate{'emailoptions'}{$type} = 'custom';
15404: if (ref($curr_rule{$type}) eq 'ARRAY') {
15405: if (@{$curr_rule{$type}} > 0) {
15406: foreach my $rule (@{$curr_rule{$type}}) {
15407: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
15408: push(@{$changes{'email_rule'}},$type);
15409: }
15410: }
15411: }
15412: foreach my $type (@{$email_rule{$type}}) {
15413: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
15414: push(@{$changes{'email_rule'}},$type);
15415: }
15416: }
15417: } else {
15418: push(@{$changes{'email_rule'}},$type);
15419: }
15420: }
15421: } else {
15422: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
15423: }
15424: }
15425: }
15426: if (@types) {
15427: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15428: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
15429: if (@changed) {
15430: push(@{$changes{'inststatus'}},'inststatusguest');
15431: }
15432: } else {
15433: push(@{$changes{'inststatus'}},'inststatusguest');
15434: }
15435: }
15436: } else {
15437: delete($env{'form.cancreate_email'});
15438: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15439: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15440: push(@{$changes{'inststatus'}},'inststatusguest');
15441: }
15442: }
15443: }
15444: } else {
15445: $save_inststatus{'inststatusguest'} = [];
15446: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
15447: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
15448: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 15449: }
15450: }
1.160.6.34 raeburn 15451: }
15452: } else {
15453: if ($env{'form.cancreate_'.$item}) {
15454: push(@{$cancreate{'selfcreate'}},$item);
15455: }
15456: }
15457: }
1.160.6.93 raeburn 15458: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 15459: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
15460: #
1.160.6.35 raeburn 15461: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
15462: # 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 15463: #
1.160.6.40 raeburn 15464:
1.160.6.48 raeburn 15465: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 15466: push(@contexts,'emailusername');
1.160.6.93 raeburn 15467: if (@statuses) {
15468: foreach my $type (@statuses) {
1.160.6.35 raeburn 15469: if (ref($infofields) eq 'ARRAY') {
15470: foreach my $field (@{$infofields}) {
15471: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
15472: $cancreate{'emailusername'}{$type}{$field} = $1;
15473: }
15474: }
1.160.6.34 raeburn 15475: }
15476: }
15477: }
15478: #
15479: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 15480: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 15481: #
15482:
15483: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
15484: @approvalnotify = sort(@approvalnotify);
15485: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
15486: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15487: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
15488: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
15489: push(@{$changes{'cancreate'}},'notify');
15490: }
15491: } else {
15492: if ($cancreate{'notify'}{'approval'}) {
15493: push(@{$changes{'cancreate'}},'notify');
15494: }
15495: }
15496: } elsif ($cancreate{'notify'}{'approval'}) {
15497: push(@{$changes{'cancreate'}},'notify');
15498: }
15499:
15500: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
15501: }
15502: #
1.160.6.40 raeburn 15503: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 15504: # institutional log-in.
15505: #
15506: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
15507: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
15508: ($domdefaults{'auth_def'} eq 'localauth'))) {
15509: $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.').' '.
15510: &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.');
15511: }
15512: }
15513: my @fields = ('lastname','firstname','middlename','generation',
15514: 'permanentemail','id');
1.160.6.44 raeburn 15515: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 15516: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
15517: #
15518: # Where usernames may created for institutional log-in and/or institutional single sign on:
15519: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
15520: # may self-create accounts
15521: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
15522: # which the user may supply, if institutional data is unavailable.
15523: #
15524: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 15525: if (@types) {
15526: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
15527: push(@contexts,'statustocreate');
15528: foreach my $type (@types) {
1.160.6.34 raeburn 15529: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
15530: foreach my $field (@fields) {
15531: if (grep(/^\Q$field\E$/,@modifiable)) {
15532: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
15533: } else {
15534: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
15535: }
15536: }
15537: }
15538: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 15539: foreach my $type (@types) {
1.160.6.34 raeburn 15540: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
15541: foreach my $field (@fields) {
15542: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
15543: $curr_usermodify{'selfcreate'}{$type}{$field}) {
15544: push(@{$changes{'selfcreate'}},$type);
15545: last;
15546: }
15547: }
15548: }
15549: }
15550: } else {
1.160.6.93 raeburn 15551: foreach my $type (@types) {
1.160.6.34 raeburn 15552: push(@{$changes{'selfcreate'}},$type);
15553: }
15554: }
15555: }
1.160.6.44 raeburn 15556: foreach my $field (@shibfields) {
15557: if ($env{'form.shibenv_'.$field} ne '') {
15558: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
15559: }
15560: }
15561: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15562: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
15563: foreach my $field (@shibfields) {
15564: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
15565: push(@{$changes{'cancreate'}},'shibenv');
15566: }
15567: }
15568: } else {
15569: foreach my $field (@shibfields) {
15570: if ($env{'form.shibenv_'.$field}) {
15571: push(@{$changes{'cancreate'}},'shibenv');
15572: last;
15573: }
15574: }
15575: }
15576: }
1.160.6.34 raeburn 15577: }
15578: foreach my $item (@contexts) {
15579: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
15580: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
15581: if (ref($cancreate{$item}) eq 'ARRAY') {
15582: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
15583: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15584: push(@{$changes{'cancreate'}},$item);
15585: }
15586: }
15587: }
15588: }
15589: if (ref($cancreate{$item}) eq 'ARRAY') {
15590: foreach my $type (@{$cancreate{$item}}) {
15591: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
15592: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15593: push(@{$changes{'cancreate'}},$item);
15594: }
15595: }
15596: }
15597: }
15598: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
15599: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 15600: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
15601: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15602: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
15603: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 15604: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15605: push(@{$changes{'cancreate'}},$item);
15606: }
15607: }
15608: }
1.160.6.93 raeburn 15609: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15610: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15611: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15612: push(@{$changes{'cancreate'}},$item);
15613: }
1.160.6.34 raeburn 15614: }
15615: }
15616: }
1.160.6.93 raeburn 15617: foreach my $type (keys(%{$cancreate{$item}})) {
15618: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15619: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15620: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
15621: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 15622: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15623: push(@{$changes{'cancreate'}},$item);
15624: }
15625: }
15626: } else {
15627: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15628: push(@{$changes{'cancreate'}},$item);
15629: }
15630: }
15631: }
1.160.6.93 raeburn 15632: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15633: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 15634: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15635: push(@{$changes{'cancreate'}},$item);
15636: }
1.160.6.34 raeburn 15637: }
15638: }
15639: }
15640: }
15641: } elsif ($curr_usercreation{'cancreate'}{$item}) {
15642: if (ref($cancreate{$item}) eq 'ARRAY') {
15643: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
15644: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15645: push(@{$changes{'cancreate'}},$item);
15646: }
15647: }
1.160.6.93 raeburn 15648: }
15649: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
15650: if (ref($cancreate{$item}) eq 'HASH') {
15651: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15652: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 15653: }
15654: }
15655: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 15656: if (ref($cancreate{$item}) eq 'HASH') {
15657: foreach my $type (keys(%{$cancreate{$item}})) {
15658: if (ref($cancreate{$item}{$type}) eq 'HASH') {
15659: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
15660: if ($cancreate{$item}{$type}{$field}) {
15661: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
15662: push(@{$changes{'cancreate'}},$item);
15663: }
15664: last;
15665: }
15666: }
15667: }
15668: }
1.160.6.34 raeburn 15669: }
15670: }
15671: }
15672: #
15673: # Populate %save_usercreate hash with updates to self-creation configuration.
15674: #
15675: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
15676: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 15677: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 15678: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
15679: if (ref($cancreate{'notify'}) eq 'HASH') {
15680: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
15681: }
1.160.6.40 raeburn 15682: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
15683: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
15684: }
1.160.6.93 raeburn 15685: if (ref($cancreate{'emailverified'}) eq 'HASH') {
15686: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
15687: }
15688: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
15689: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
15690: }
15691: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
15692: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
15693: }
1.160.6.34 raeburn 15694: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15695: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
15696: }
1.160.6.44 raeburn 15697: if (ref($cancreate{'shibenv'}) eq 'HASH') {
15698: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
15699: }
1.160.6.34 raeburn 15700: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 15701: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 15702:
15703: my %userconfig_hash = (
15704: usercreation => \%save_usercreate,
15705: usermodification => \%save_usermodify,
1.160.6.93 raeburn 15706: inststatus => \%save_inststatus,
1.160.6.34 raeburn 15707: );
1.160.6.93 raeburn 15708:
1.160.6.34 raeburn 15709: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
15710: $dom);
15711: #
1.160.6.93 raeburn 15712: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 15713: #
1.27 raeburn 15714: if ($putresult eq 'ok') {
15715: if (keys(%changes) > 0) {
15716: $resulttext = &mt('Changes made:').'<ul>';
15717: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 15718: my %lt = &selfcreation_types();
1.34 raeburn 15719: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 15720: my $chgtext = '';
1.45 raeburn 15721: if ($type eq 'selfcreate') {
1.50 raeburn 15722: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 15723: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 15724: } else {
1.160.6.34 raeburn 15725: $chgtext .= &mt('Self-creation of a new account is permitted for:').
15726: '<ul>';
1.50 raeburn 15727: foreach my $case (@{$cancreate{$type}}) {
15728: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
15729: }
15730: $chgtext .= '</ul>';
1.100 raeburn 15731: if (ref($cancreate{$type}) eq 'ARRAY') {
15732: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
15733: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
15734: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 15735: $chgtext .= '<span class="LC_warning">'.
15736: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
15737: '</span><br />';
1.100 raeburn 15738: }
15739: }
15740: }
1.160.6.93 raeburn 15741: if (grep(/^email$/,@{$cancreate{$type}})) {
15742: if (!@statuses) {
15743: $chgtext .= '<span class="LC_warning">'.
15744: &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.").
15745: '</span><br />';
15746:
15747: }
15748: }
1.100 raeburn 15749: }
1.43 raeburn 15750: }
1.160.6.44 raeburn 15751: } elsif ($type eq 'shibenv') {
15752: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 15753: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 15754: } else {
15755: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
15756: '<ul>';
15757: foreach my $field (@shibfields) {
15758: next if ($cancreate{$type}{$field} eq '');
15759: if ($field eq 'inststatus') {
15760: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
15761: } else {
15762: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
15763: }
15764: }
15765: $chgtext .= '</ul>';
1.160.6.93 raeburn 15766: }
1.93 raeburn 15767: } elsif ($type eq 'statustocreate') {
1.96 raeburn 15768: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
15769: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
15770: if (@{$cancreate{'selfcreate'}} > 0) {
15771: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 15772: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 15773: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 15774: $chgtext .= '<br />'.
15775: '<span class="LC_warning">'.
15776: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
15777: '</span>';
15778: }
1.160.6.93 raeburn 15779: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 15780: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 15781: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
15782: } else {
15783: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
15784: }
15785: $chgtext .= '<ul>';
15786: foreach my $case (@{$cancreate{$type}}) {
15787: if ($case eq 'default') {
15788: $chgtext .= '<li>'.$othertitle.'</li>';
15789: } else {
1.160.6.93 raeburn 15790: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 15791: }
15792: }
1.100 raeburn 15793: $chgtext .= '</ul>';
15794: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 15795: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 15796: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
15797: '</span>';
1.100 raeburn 15798: }
15799: }
15800: } else {
15801: if (@{$cancreate{$type}} == 0) {
15802: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
15803: } else {
15804: $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 15805: }
15806: }
1.160.6.93 raeburn 15807: $chgtext .= '<br />';
1.93 raeburn 15808: }
1.160.6.40 raeburn 15809: } elsif ($type eq 'selfcreateprocessing') {
15810: my %choices = &Apache::lonlocal::texthash (
15811: automatic => 'Automatic approval',
15812: approval => 'Queued for approval',
15813: );
1.160.6.93 raeburn 15814: if (@types) {
15815: if (@statuses) {
15816: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
15817: '<ul>';
15818: foreach my $status (@statuses) {
15819: if ($status eq 'default') {
15820: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15821: } else {
15822: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
15823: }
15824: }
15825: $chgtext .= '</ul>';
15826: }
15827: } else {
15828: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
15829: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
15830: }
15831: } elsif ($type eq 'emailverified') {
15832: my %options = &Apache::lonlocal::texthash (
15833: all => 'Same as e-mail',
15834: first => 'Omit @domain',
15835: free => 'Free to choose',
15836: );
15837: if (@types) {
15838: if (@statuses) {
15839: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
15840: '<ul>';
15841: foreach my $status (@statuses) {
15842: if ($status eq 'default') {
15843: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15844: } else {
15845: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
15846: }
15847: }
15848: $chgtext .= '</ul>';
15849: }
1.160.6.40 raeburn 15850: } else {
1.160.6.93 raeburn 15851: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
15852: $options{$cancreate{'emailverified'}{'default'}});
15853: }
15854: } elsif ($type eq 'emailoptions') {
15855: my %options = &Apache::lonlocal::texthash (
15856: any => 'Any e-mail',
15857: inst => 'Institutional only',
15858: noninst => 'Non-institutional only',
15859: custom => 'Custom restrictions',
15860: );
15861: if (@types) {
15862: if (@statuses) {
15863: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
15864: '<ul>';
15865: foreach my $status (@statuses) {
15866: if ($type eq 'default') {
15867: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15868: } else {
15869: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
15870: }
15871: }
15872: $chgtext .= '</ul>';
15873: }
15874: } else {
15875: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
15876: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
15877: } else {
15878: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
15879: $options{$cancreate{'emailoptions'}{'default'}});
15880: }
15881: }
15882: } elsif ($type eq 'emaildomain') {
15883: my $output;
15884: if (@statuses) {
15885: foreach my $type (@statuses) {
15886: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
15887: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
15888: if ($type eq 'default') {
15889: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15890: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15891: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15892: } else {
15893: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
15894: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15895: }
15896: } else {
15897: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15898: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
15899: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15900: } else {
15901: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
15902: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
15903: }
15904: }
15905: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
15906: if ($type eq 'default') {
15907: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15908: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15909: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
15910: } else {
15911: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
15912: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15913: }
15914: } else {
15915: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
15916: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
15917: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
15918: } else {
15919: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
15920: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
15921: }
15922: }
15923: }
15924: }
15925: }
15926: }
15927: if ($output ne '') {
15928: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
15929: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 15930: }
1.160.6.5 raeburn 15931: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 15932: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 15933: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
15934: } else {
15935: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 15936: if ($captchas{$savecaptcha{$type}}) {
15937: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 15938: } else {
15939: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
15940: }
15941: }
15942: } elsif ($type eq 'recaptchakeys') {
15943: my ($privkey,$pubkey);
1.160.6.34 raeburn 15944: if (ref($savecaptcha{$type}) eq 'HASH') {
15945: $pubkey = $savecaptcha{$type}{'public'};
15946: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 15947: }
15948: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
15949: if (!$pubkey) {
15950: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
15951: } else {
15952: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
15953: }
15954: if (!$privkey) {
15955: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
15956: } else {
15957: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
15958: }
15959: $chgtext .= '</ul>';
1.160.6.69 raeburn 15960: } elsif ($type eq 'recaptchaversion') {
15961: if ($savecaptcha{'captcha'} eq 'recaptcha') {
15962: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
15963: }
1.160.6.34 raeburn 15964: } elsif ($type eq 'emailusername') {
15965: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 15966: if (@statuses) {
15967: foreach my $type (@statuses) {
1.160.6.35 raeburn 15968: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
15969: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 15970: $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 15971: '<ul>';
15972: foreach my $field (@{$infofields}) {
15973: if ($cancreate{'emailusername'}{$type}{$field}) {
15974: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
15975: }
15976: }
1.160.6.50 raeburn 15977: $chgtext .= '</ul>';
15978: } else {
1.160.6.93 raeburn 15979: $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 15980: }
15981: } else {
1.160.6.93 raeburn 15982: $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 15983: }
15984: }
15985: }
15986: }
15987: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 15988: my $numapprove = 0;
1.160.6.34 raeburn 15989: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15990: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
15991: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 15992: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
15993: $numapprove ++;
1.160.6.34 raeburn 15994: }
15995: }
1.43 raeburn 15996: }
1.160.6.93 raeburn 15997: unless ($numapprove) {
15998: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
15999: }
1.34 raeburn 16000: }
1.160.6.34 raeburn 16001: if ($chgtext) {
16002: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 16003: }
16004: }
16005: }
1.160.6.93 raeburn 16006: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 16007: my ($emailrules,$emailruleorder) =
16008: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 16009: foreach my $type (@{$changes{'email_rule'}}) {
16010: if (ref($email_rule{$type}) eq 'ARRAY') {
16011: my $chgtext = '<ul>';
16012: foreach my $rule (@{$email_rule{$type}}) {
16013: if (ref($emailrules->{$rule}) eq 'HASH') {
16014: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16015: }
16016: }
16017: $chgtext .= '</ul>';
16018: my $typename;
16019: if (@types) {
16020: if ($type eq 'default') {
16021: $typename = $othertitle;
16022: } else {
16023: $typename = $usertypes{$type};
16024: }
16025: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16026: }
16027: if (@{$email_rule{$type}} > 0) {
16028: $resulttext .= '<li>'.
16029: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16030: $usertypes{$type}).
16031: $chgtext.
16032: '</li>';
16033: } else {
16034: $resulttext .= '<li>'.
16035: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16036: '</li>'.
16037: &mt('(Affiliation: [_1])',$typename);
16038: }
1.43 raeburn 16039: }
16040: }
1.160.6.93 raeburn 16041: }
16042: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16043: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16044: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16045: my $chgtext = '<ul>';
16046: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16047: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16048: }
16049: $chgtext .= '</ul>';
16050: $resulttext .= '<li>'.
16051: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16052: $chgtext.
16053: '</li>';
16054: } else {
16055: $resulttext .= '<li>'.
16056: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16057: '</li>';
16058: }
1.43 raeburn 16059: }
16060: }
1.160.6.34 raeburn 16061: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16062: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16063: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16064: foreach my $type (@{$changes{'selfcreate'}}) {
16065: my $typename = $type;
1.160.6.93 raeburn 16066: if (keys(%usertypes) > 0) {
16067: if ($usertypes{$type} ne '') {
16068: $typename = $usertypes{$type};
1.28 raeburn 16069: }
16070: }
1.160.6.34 raeburn 16071: my @modifiable;
16072: $resulttext .= '<li>'.
16073: &mt('Self-creation of account by users with status: [_1]',
16074: '<span class="LC_cusr_emph">'.$typename.'</span>').
16075: ' - '.&mt('modifiable fields (if institutional data blank): ');
16076: foreach my $field (@fields) {
16077: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16078: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
16079: }
16080: }
16081: if (@modifiable > 0) {
16082: $resulttext .= join(', ',@modifiable);
1.43 raeburn 16083: } else {
1.160.6.34 raeburn 16084: $resulttext .= &mt('none');
1.43 raeburn 16085: }
1.160.6.34 raeburn 16086: $resulttext .= '</li>';
1.28 raeburn 16087: }
1.160.6.34 raeburn 16088: $resulttext .= '</ul></li>';
1.28 raeburn 16089: }
1.27 raeburn 16090: $resulttext .= '</ul>';
1.160.6.93 raeburn 16091: my $cachetime = 24*60*60;
16092: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16093: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16094: if (ref($lastactref) eq 'HASH') {
16095: $lastactref->{'domdefaults'} = 1;
16096: }
1.27 raeburn 16097: } else {
1.160.6.34 raeburn 16098: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 16099: }
16100: } else {
16101: $resulttext = '<span class="LC_error">'.
1.23 raeburn 16102: &mt('An error occurred: [_1]',$putresult).'</span>';
16103: }
1.43 raeburn 16104: if ($warningmsg ne '') {
16105: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16106: }
1.23 raeburn 16107: return $resulttext;
16108: }
16109:
1.160.6.5 raeburn 16110: sub process_captcha {
1.160.6.104 raeburn 16111: my ($container,$changes,$newsettings,$currsettings) = @_;
16112: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 16113: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16114: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16115: $newsettings->{'captcha'} = 'original';
16116: }
1.160.6.104 raeburn 16117: my %current;
16118: if (ref($currsettings) eq 'HASH') {
16119: %current = %{$currsettings};
16120: }
16121: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 16122: if ($container eq 'cancreate') {
16123: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16124: push(@{$changes->{'cancreate'}},'captcha');
16125: } elsif (!defined($changes->{'cancreate'})) {
16126: $changes->{'cancreate'} = ['captcha'];
16127: }
1.160.6.102 raeburn 16128: } elsif ($container eq 'passwords') {
16129: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16130: } else {
16131: $changes->{'captcha'} = 1;
16132: }
16133: }
1.160.6.69 raeburn 16134: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 16135: if ($newsettings->{'captcha'} eq 'recaptcha') {
16136: $newpub = $env{'form.'.$container.'_recaptchapub'};
16137: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 16138: $newpub =~ s/[^\w\-]//g;
16139: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 16140: $newsettings->{'recaptchakeys'} = {
16141: public => $newpub,
16142: private => $newpriv,
16143: };
1.160.6.69 raeburn 16144: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16145: $newversion =~ s/\D//g;
16146: if ($newversion ne '2') {
16147: $newversion = 1;
16148: }
16149: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 16150: }
1.160.6.104 raeburn 16151: if (ref($current{'recaptchakeys'}) eq 'HASH') {
16152: $currpub = $current{'recaptchakeys'}{'public'};
16153: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 16154: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16155: $newsettings->{'recaptchakeys'} = {
16156: public => '',
16157: private => '',
16158: }
16159: }
1.160.6.5 raeburn 16160: }
1.160.6.104 raeburn 16161: if ($current{'captcha'} eq 'recaptcha') {
16162: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 16163: if ($currversion ne '2') {
16164: $currversion = 1;
16165: }
16166: }
16167: if ($currversion ne $newversion) {
16168: if ($container eq 'cancreate') {
16169: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16170: push(@{$changes->{'cancreate'}},'recaptchaversion');
16171: } elsif (!defined($changes->{'cancreate'})) {
16172: $changes->{'cancreate'} = ['recaptchaversion'];
16173: }
1.160.6.102 raeburn 16174: } elsif ($container eq 'passwords') {
16175: $changes->{'reset'} = 1;
1.160.6.69 raeburn 16176: } else {
16177: $changes->{'recaptchaversion'} = 1;
16178: }
16179: }
1.160.6.5 raeburn 16180: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
16181: if ($container eq 'cancreate') {
16182: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16183: push(@{$changes->{'cancreate'}},'recaptchakeys');
16184: } elsif (!defined($changes->{'cancreate'})) {
16185: $changes->{'cancreate'} = ['recaptchakeys'];
16186: }
1.160.6.102 raeburn 16187: } elsif ($container eq 'passwords') {
16188: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16189: } else {
16190: $changes->{'recaptchakeys'} = 1;
16191: }
16192: }
16193: return;
16194: }
16195:
1.33 raeburn 16196: sub modify_usermodification {
16197: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16198: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16199: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16200: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 16201: if ($key eq 'selfcreate') {
16202: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16203: } else {
16204: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
16205: }
1.33 raeburn 16206: }
16207: }
1.160.6.34 raeburn 16208: my @contexts = ('author','course');
1.33 raeburn 16209: my %context_title = (
16210: author => 'In author context',
16211: course => 'In course context',
16212: );
16213: my @fields = ('lastname','firstname','middlename','generation',
16214: 'permanentemail','id');
16215: my %roles = (
16216: author => ['ca','aa'],
16217: course => ['st','ep','ta','in','cr'],
16218: );
16219: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16220: foreach my $context (@contexts) {
16221: foreach my $role (@{$roles{$context}}) {
16222: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
16223: foreach my $item (@fields) {
16224: if (grep(/^\Q$item\E$/,@modifiable)) {
16225: $modifyhash{$context}{$role}{$item} = 1;
16226: } else {
16227: $modifyhash{$context}{$role}{$item} = 0;
16228: }
16229: }
16230: }
16231: if (ref($curr_usermodification{$context}) eq 'HASH') {
16232: foreach my $role (@{$roles{$context}}) {
16233: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
16234: foreach my $field (@fields) {
16235: if ($modifyhash{$context}{$role}{$field} ne
16236: $curr_usermodification{$context}{$role}{$field}) {
16237: push(@{$changes{$context}},$role);
16238: last;
16239: }
16240: }
16241: }
16242: }
16243: } else {
16244: foreach my $context (@contexts) {
16245: foreach my $role (@{$roles{$context}}) {
16246: push(@{$changes{$context}},$role);
16247: }
16248: }
16249: }
16250: }
16251: my %usermodification_hash = (
16252: usermodification => \%modifyhash,
16253: );
16254: my $putresult = &Apache::lonnet::put_dom('configuration',
16255: \%usermodification_hash,$dom);
16256: if ($putresult eq 'ok') {
16257: if (keys(%changes) > 0) {
16258: $resulttext = &mt('Changes made: ').'<ul>';
16259: foreach my $context (@contexts) {
16260: if (ref($changes{$context}) eq 'ARRAY') {
16261: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
16262: if (ref($changes{$context}) eq 'ARRAY') {
16263: foreach my $role (@{$changes{$context}}) {
16264: my $rolename;
1.160.6.34 raeburn 16265: if ($role eq 'cr') {
16266: $rolename = &mt('Custom');
1.33 raeburn 16267: } else {
1.160.6.34 raeburn 16268: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 16269: }
16270: my @modifiable;
1.160.6.34 raeburn 16271: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 16272: foreach my $field (@fields) {
16273: if ($modifyhash{$context}{$role}{$field}) {
16274: push(@modifiable,$fieldtitles{$field});
16275: }
16276: }
16277: if (@modifiable > 0) {
16278: $resulttext .= join(', ',@modifiable);
16279: } else {
16280: $resulttext .= &mt('none');
16281: }
16282: $resulttext .= '</li>';
16283: }
16284: $resulttext .= '</ul></li>';
16285: }
16286: }
16287: }
16288: $resulttext .= '</ul>';
16289: } else {
16290: $resulttext = &mt('No changes made to user modification settings');
16291: }
16292: } else {
16293: $resulttext = '<span class="LC_error">'.
16294: &mt('An error occurred: [_1]',$putresult).'</span>';
16295: }
16296: return $resulttext;
16297: }
16298:
1.43 raeburn 16299: sub modify_defaults {
1.160.6.27 raeburn 16300: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 16301: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 16302: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 16303: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 16304: 'portal_def');
1.43 raeburn 16305: my @authtypes = ('internal','krb4','krb5','localauth');
16306: foreach my $item (@items) {
16307: $newvalues{$item} = $env{'form.'.$item};
16308: if ($item eq 'auth_def') {
16309: if ($newvalues{$item} ne '') {
16310: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
16311: push(@errors,$item);
16312: }
16313: }
16314: } elsif ($item eq 'lang_def') {
16315: if ($newvalues{$item} ne '') {
16316: if ($newvalues{$item} =~ /^(\w+)/) {
16317: my $langcode = $1;
1.103 raeburn 16318: if ($langcode ne 'x_chef') {
16319: if (code2language($langcode) eq '') {
16320: push(@errors,$item);
16321: }
1.43 raeburn 16322: }
16323: } else {
16324: push(@errors,$item);
16325: }
16326: }
1.54 raeburn 16327: } elsif ($item eq 'timezone_def') {
16328: if ($newvalues{$item} ne '') {
1.62 raeburn 16329: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 16330: push(@errors,$item);
16331: }
16332: }
1.68 raeburn 16333: } elsif ($item eq 'datelocale_def') {
16334: if ($newvalues{$item} ne '') {
16335: my @datelocale_ids = DateTime::Locale->ids();
16336: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
16337: push(@errors,$item);
16338: }
16339: }
1.141 raeburn 16340: } elsif ($item eq 'portal_def') {
16341: if ($newvalues{$item} ne '') {
16342: unless ($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])\/?$/) {
16343: push(@errors,$item);
16344: }
16345: }
1.43 raeburn 16346: }
16347: if (grep(/^\Q$item\E$/,@errors)) {
16348: $newvalues{$item} = $domdefaults{$item};
16349: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
16350: $changes{$item} = 1;
16351: }
1.72 raeburn 16352: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 16353: }
1.160.6.98 raeburn 16354: my %staticdefaults = (
16355: 'intauth_cost' => 10,
16356: 'intauth_check' => 0,
16357: 'intauth_switch' => 0,
16358: );
16359: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
16360: if (exists($domdefaults{$item})) {
16361: $newvalues{$item} = $domdefaults{$item};
16362: } else {
16363: $newvalues{$item} = $staticdefaults{$item};
16364: }
16365: }
1.160.6.118.2 8(raebur 16366:2): my ($unamemaprules,$ruleorder);
16367:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
16368:2): if (@possunamemaprules) {
16369:2): ($unamemaprules,$ruleorder) =
16370:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
16371:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
16372:2): if (@{$ruleorder} > 0) {
16373:2): my %possrules;
16374:2): map { $possrules{$_} = 1; } @possunamemaprules;
16375:2): foreach my $rule (@{$ruleorder}) {
16376:2): if ($possrules{$rule}) {
16377:2): push(@{$newvalues{'unamemap_rule'}},$rule);
16378:2): }
16379:2): }
16380:2): }
16381:2): }
16382:2): }
16383:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
16384:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16385:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
16386:2): $newvalues{'unamemap_rule'});
16387:2): if (@rulediffs) {
16388:2): $changes{'unamemap_rule'} = 1;
16389:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
16390:2): }
16391:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
16392:2): $changes{'unamemap_rule'} = 1;
16393:2): delete($domdefaults{'unamemap_rule'});
16394:2): }
16395:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16396:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
16397:2): $changes{'unamemap_rule'} = 1;
16398:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
16399:2): }
16400:2): }
1.43 raeburn 16401: my %defaults_hash = (
1.72 raeburn 16402: defaults => \%newvalues,
16403: );
1.43 raeburn 16404: my $title = &defaults_titles();
1.160.6.40 raeburn 16405:
16406: my $currinststatus;
16407: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16408: $currinststatus = $domconfig{'inststatus'};
16409: } else {
16410: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16411: $currinststatus = {
16412: inststatustypes => $usertypes,
16413: inststatusorder => $types,
16414: inststatusguest => [],
16415: };
16416: }
16417: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
16418: my @allpos;
16419: my %alltypes;
1.160.6.93 raeburn 16420: my @inststatusguest;
16421: if (ref($currinststatus) eq 'HASH') {
16422: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
16423: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
16424: unless (grep(/^\Q$type\E$/,@todelete)) {
16425: push(@inststatusguest,$type);
16426: }
16427: }
16428: }
16429: }
16430: my ($currtitles,$currorder);
1.160.6.40 raeburn 16431: if (ref($currinststatus) eq 'HASH') {
16432: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
16433: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
16434: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
16435: if ($currinststatus->{inststatustypes}->{$type} ne '') {
16436: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
16437: }
16438: }
16439: unless (grep(/^\Q$type\E$/,@todelete)) {
16440: my $position = $env{'form.inststatus_pos_'.$type};
16441: $position =~ s/\D+//g;
16442: $allpos[$position] = $type;
16443: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
16444: $alltypes{$type} =~ s/`//g;
16445: }
16446: }
16447: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
16448: $currtitles =~ s/,$//;
16449: }
16450: }
16451: if ($env{'form.addinststatus'}) {
16452: my $newtype = $env{'form.addinststatus'};
16453: $newtype =~ s/\W//g;
16454: unless (exists($alltypes{$newtype})) {
16455: $alltypes{$newtype} = $env{'form.addinststatus_title'};
16456: $alltypes{$newtype} =~ s/`//g;
16457: my $position = $env{'form.addinststatus_pos'};
16458: $position =~ s/\D+//g;
16459: if ($position ne '') {
16460: $allpos[$position] = $newtype;
16461: }
16462: }
16463: }
1.160.6.93 raeburn 16464: my @orderedstatus;
1.160.6.40 raeburn 16465: foreach my $type (@allpos) {
16466: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
16467: push(@orderedstatus,$type);
16468: }
16469: }
16470: foreach my $type (keys(%alltypes)) {
16471: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
16472: delete($alltypes{$type});
16473: }
16474: }
16475: $defaults_hash{'inststatus'} = {
16476: inststatustypes => \%alltypes,
16477: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 16478: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 16479: };
16480: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
16481: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
16482: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
16483: }
16484: }
16485: if ($currorder ne join(',',@orderedstatus)) {
16486: $changes{'inststatus'}{'inststatusorder'} = 1;
16487: }
16488: my $newtitles;
16489: foreach my $item (@orderedstatus) {
16490: $newtitles .= $alltypes{$item}.',';
16491: }
16492: $newtitles =~ s/,$//;
16493: if ($currtitles ne $newtitles) {
16494: $changes{'inststatus'}{'inststatustypes'} = 1;
16495: }
1.43 raeburn 16496: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
16497: $dom);
16498: if ($putresult eq 'ok') {
16499: if (keys(%changes) > 0) {
16500: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 16501: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 16502: 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";
16503: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 16504: if ($item eq 'inststatus') {
16505: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 16506: if (@orderedstatus) {
1.160.6.40 raeburn 16507: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
16508: foreach my $type (@orderedstatus) {
16509: $resulttext .= $alltypes{$type}.', ';
16510: }
16511: $resulttext =~ s/, $//;
16512: $resulttext .= '</li>';
1.160.6.93 raeburn 16513: } else {
16514: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 16515: }
16516: }
1.160.6.118.2 8(raebur 16517:2): } elsif ($item eq 'unamemap_rule') {
16518:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
16519:2): my @rulenames;
16520:2): if (ref($unamemaprules) eq 'HASH') {
16521:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
16522:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
16523:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
16524:2): }
16525:2): }
16526:2): }
16527:2): if (@rulenames) {
16528:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
16529:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
16530:2): '</li>';
16531:2): } else {
16532:2): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
16533:2): }
16534:2): } else {
16535:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
16536:2): }
1.160.6.40 raeburn 16537: } else {
16538: my $value = $env{'form.'.$item};
16539: if ($value eq '') {
16540: $value = &mt('none');
16541: } elsif ($item eq 'auth_def') {
16542: my %authnames = &authtype_names();
16543: my %shortauth = (
16544: internal => 'int',
16545: krb4 => 'krb4',
16546: krb5 => 'krb5',
16547: localauth => 'loc',
16548: );
16549: $value = $authnames{$shortauth{$value}};
16550: }
16551: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
16552: $mailmsgtext .= "$title->{$item} set to $value\n";
1.43 raeburn 16553: }
16554: }
16555: $resulttext .= '</ul>';
16556: $mailmsgtext .= "\n";
16557: my $cachetime = 24*60*60;
1.72 raeburn 16558: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 16559: if (ref($lastactref) eq 'HASH') {
16560: $lastactref->{'domdefaults'} = 1;
16561: }
1.68 raeburn 16562: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 16563: my $notify = 1;
16564: if (ref($domconfig{'contacts'}) eq 'HASH') {
16565: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
16566: $notify = 0;
16567: }
16568: }
16569: if ($notify) {
16570: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
16571: "LON-CAPA Domain Settings Change - $dom",
16572: $mailmsgtext);
16573: }
1.54 raeburn 16574: }
1.43 raeburn 16575: } else {
1.54 raeburn 16576: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 16577: }
16578: } else {
16579: $resulttext = '<span class="LC_error">'.
16580: &mt('An error occurred: [_1]',$putresult).'</span>';
16581: }
16582: if (@errors > 0) {
16583: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
16584: foreach my $item (@errors) {
16585: $resulttext .= ' "'.$title->{$item}.'",';
16586: }
16587: $resulttext =~ s/,$//;
16588: }
16589: return $resulttext;
16590: }
16591:
1.46 raeburn 16592: sub modify_scantron {
1.160.6.24 raeburn 16593: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 16594: my ($resulttext,%confhash,%changes,$errors);
16595: my $custom = 'custom.tab';
16596: my $default = 'default.tab';
16597: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 16598: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 16599: &config_check($dom,$confname,$servadm);
16600: if ($env{'form.scantronformat.filename'} ne '') {
16601: my $error;
16602: if ($configuserok eq 'ok') {
16603: if ($switchserver) {
1.130 raeburn 16604: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 16605: } else {
16606: if ($author_ok eq 'ok') {
16607: my ($result,$scantronurl) =
16608: &publishlogo($r,'upload','scantronformat',$dom,
16609: $confname,'scantron','','',$custom);
16610: if ($result eq 'ok') {
16611: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 16612: $changes{'scantronformat'} = 1;
1.46 raeburn 16613: } else {
16614: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
16615: }
16616: } else {
16617: $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);
16618: }
16619: }
16620: } else {
16621: $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);
16622: }
16623: if ($error) {
16624: &Apache::lonnet::logthis($error);
16625: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16626: }
16627: }
1.48 raeburn 16628: if (ref($domconfig{'scantron'}) eq 'HASH') {
16629: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
16630: if ($env{'form.scantronformat_del'}) {
16631: $confhash{'scantron'}{'scantronformat'} = '';
16632: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 16633: } else {
16634: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
16635: }
16636: }
16637: }
16638: my @options = ('hdr','pad','rem');
16639: my @fields = &scantroncsv_fields();
16640: my %titles = &scantronconfig_titles();
16641: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
16642: my ($newdat,$currdat,%newcol,%currcol);
16643: if (grep(/^dat$/,@formats)) {
16644: $confhash{'scantron'}{config}{dat} = 1;
16645: $newdat = 1;
16646: } else {
16647: $newdat = 0;
16648: }
16649: if (grep(/^csv$/,@formats)) {
16650: my %bynum;
16651: foreach my $field (@fields) {
16652: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
16653: my $posscol = $1;
16654: if (($posscol < 20) && (!$bynum{$posscol})) {
16655: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
16656: $bynum{$posscol} = $field;
16657: $newcol{$field} = $posscol;
16658: }
16659: }
16660: }
16661: if (keys(%newcol)) {
16662: foreach my $option (@options) {
16663: if ($env{'form.scantroncsv_'.$option}) {
16664: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
16665: }
16666: }
16667: }
16668: }
16669: $currdat = 1;
16670: if (ref($domconfig{'scantron'}) eq 'HASH') {
16671: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
16672: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
16673: $currdat = 0;
16674: }
16675: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16676: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16677: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
16678: }
16679: }
16680: }
16681: }
16682: if ($currdat != $newdat) {
16683: $changes{'config'} = 1;
16684: } else {
16685: foreach my $field (@fields) {
16686: if ($currcol{$field} ne '') {
16687: if ($currcol{$field} ne $newcol{$field}) {
16688: $changes{'config'} = 1;
16689: last;
16690: }
16691: } elsif ($newcol{$field} ne '') {
16692: $changes{'config'} = 1;
16693: last;
1.46 raeburn 16694: }
16695: }
16696: }
16697: if (keys(%confhash) > 0) {
16698: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
16699: $dom);
16700: if ($putresult eq 'ok') {
16701: if (keys(%changes) > 0) {
1.48 raeburn 16702: if (ref($confhash{'scantron'}) eq 'HASH') {
16703: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 16704: if ($changes{'scantronformat'}) {
16705: if ($confhash{'scantron'}{'scantronformat'} eq '') {
16706: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
16707: } else {
16708: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
16709: }
16710: }
16711: if ($changes{'config'}) {
16712: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
16713: if ($confhash{'scantron'}{'config'}{'dat'}) {
16714: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
16715: }
16716: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
16717: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
16718: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
16719: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
16720: foreach my $field (@fields) {
16721: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
16722: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
16723: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
16724: }
16725: }
16726: $resulttext .= '</ul></li>';
16727: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
16728: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
16729: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
16730: foreach my $option (@options) {
16731: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
16732: $resulttext .= '<li>'.$titles{$option}.'</li>';
16733: }
16734: }
16735: $resulttext .= '</ul></li>';
16736: }
16737: }
16738: }
16739: }
16740: }
16741: } else {
16742: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
16743: }
1.46 raeburn 16744: }
1.48 raeburn 16745: $resulttext .= '</ul>';
16746: } else {
1.130 raeburn 16747: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 16748: }
16749: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 16750: if (ref($lastactref) eq 'HASH') {
16751: $lastactref->{'domainconfig'} = 1;
16752: }
1.46 raeburn 16753: } else {
1.160.6.97 raeburn 16754: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16755: }
16756: } else {
16757: $resulttext = '<span class="LC_error">'.
16758: &mt('An error occurred: [_1]',$putresult).'</span>';
16759: }
16760: } else {
1.160.6.97 raeburn 16761: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 16762: }
16763: if ($errors) {
16764: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16765: $errors.'</ul>';
16766: }
16767: return $resulttext;
16768: }
16769:
1.48 raeburn 16770: sub modify_coursecategories {
1.160.6.43 raeburn 16771: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 16772: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
16773: $cathash);
1.48 raeburn 16774: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 16775: my @catitems = ('unauth','auth');
16776: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 16777: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 16778: $cathash = $domconfig{'coursecategories'}{'cats'};
16779: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
16780: $changes{'togglecats'} = 1;
16781: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
16782: }
16783: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
16784: $changes{'categorize'} = 1;
16785: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
16786: }
1.120 raeburn 16787: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
16788: $changes{'togglecatscomm'} = 1;
16789: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
16790: }
16791: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
16792: $changes{'categorizecomm'} = 1;
16793: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
16794: }
1.160.6.42 raeburn 16795: foreach my $item (@catitems) {
16796: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16797: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
16798: $changes{$item} = 1;
16799: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16800: }
16801: }
16802: }
1.57 raeburn 16803: } else {
16804: $changes{'togglecats'} = 1;
16805: $changes{'categorize'} = 1;
1.124 raeburn 16806: $changes{'togglecatscomm'} = 1;
16807: $changes{'categorizecomm'} = 1;
1.87 raeburn 16808: $domconfig{'coursecategories'} = {
16809: togglecats => $env{'form.togglecats'},
16810: categorize => $env{'form.categorize'},
1.124 raeburn 16811: togglecatscomm => $env{'form.togglecatscomm'},
16812: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 16813: };
1.160.6.42 raeburn 16814: foreach my $item (@catitems) {
16815: if ($env{'form.coursecat_'.$item} ne 'std') {
16816: $changes{$item} = 1;
16817: }
16818: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
16819: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
16820: }
16821: }
1.57 raeburn 16822: }
16823: if (ref($cathash) eq 'HASH') {
16824: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 16825: push (@deletecategory,'instcode::0');
16826: }
1.120 raeburn 16827: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
16828: push(@deletecategory,'communities::0');
16829: }
1.48 raeburn 16830: }
1.57 raeburn 16831: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
16832: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16833: if (@deletecategory > 0) {
16834: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 16835: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 16836: foreach my $item (@deletecategory) {
1.57 raeburn 16837: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
16838: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 16839: $deletions{$item} = 1;
1.57 raeburn 16840: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 16841: }
16842: }
16843: }
1.57 raeburn 16844: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 16845: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 16846: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 16847: $reorderings{$item} = 1;
1.57 raeburn 16848: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 16849: }
16850: if ($env{'form.addcategory_name_'.$item} ne '') {
16851: my $newcat = $env{'form.addcategory_name_'.$item};
16852: my $newdepth = $depth+1;
16853: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16854: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 16855: $adds{$newitem} = 1;
16856: }
16857: if ($env{'form.subcat_'.$item} ne '') {
16858: my $newcat = $env{'form.subcat_'.$item};
16859: my $newdepth = $depth+1;
16860: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 16861: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 16862: $adds{$newitem} = 1;
16863: }
16864: }
16865: }
16866: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 16867: if (ref($cathash) eq 'HASH') {
1.48 raeburn 16868: my $newitem = 'instcode::0';
1.57 raeburn 16869: if ($cathash->{$newitem} eq '') {
16870: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16871: $adds{$newitem} = 1;
16872: }
16873: } else {
16874: my $newitem = 'instcode::0';
1.57 raeburn 16875: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 16876: $adds{$newitem} = 1;
16877: }
16878: }
1.120 raeburn 16879: if ($env{'form.communities'} eq '1') {
16880: if (ref($cathash) eq 'HASH') {
16881: my $newitem = 'communities::0';
16882: if ($cathash->{$newitem} eq '') {
16883: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16884: $adds{$newitem} = 1;
16885: }
16886: } else {
16887: my $newitem = 'communities::0';
16888: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
16889: $adds{$newitem} = 1;
16890: }
16891: }
1.48 raeburn 16892: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 16893: if (($env{'form.addcategory_name'} ne 'instcode') &&
16894: ($env{'form.addcategory_name'} ne 'communities')) {
16895: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
16896: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
16897: $adds{$newitem} = 1;
16898: }
1.48 raeburn 16899: }
1.57 raeburn 16900: my $putresult;
1.48 raeburn 16901: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16902: if (keys(%deletions) > 0) {
16903: foreach my $key (keys(%deletions)) {
16904: if ($predelallitems{$key} ne '') {
16905: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
16906: }
16907: }
16908: }
16909: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 16910: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 16911: if (ref($chkcats[0]) eq 'ARRAY') {
16912: my $depth = 0;
16913: my $chg = 0;
16914: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
16915: my $name = $chkcats[0][$i];
16916: my $item;
16917: if ($name eq '') {
16918: $chg ++;
16919: } else {
16920: $item = &escape($name).'::0';
16921: if ($chg) {
1.57 raeburn 16922: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 16923: }
16924: $depth ++;
1.57 raeburn 16925: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 16926: $depth --;
16927: }
16928: }
16929: }
1.57 raeburn 16930: }
16931: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16932: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 16933: if ($putresult eq 'ok') {
1.57 raeburn 16934: my %title = (
1.120 raeburn 16935: togglecats => 'Show/Hide a course in catalog',
16936: categorize => 'Assign a category to a course',
16937: togglecatscomm => 'Show/Hide a community in catalog',
16938: categorizecomm => 'Assign a category to a community',
1.57 raeburn 16939: );
16940: my %level = (
1.120 raeburn 16941: dom => 'set in Domain ("Modify Course/Community")',
16942: crs => 'set in Course ("Course Configuration")',
16943: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 16944: none => 'No catalog',
16945: std => 'Standard catalog',
16946: domonly => 'Domain-only catalog',
16947: codesrch => 'Code search form',
1.57 raeburn 16948: );
1.48 raeburn 16949: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 16950: if ($changes{'togglecats'}) {
16951: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
16952: }
16953: if ($changes{'categorize'}) {
16954: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 16955: }
1.120 raeburn 16956: if ($changes{'togglecatscomm'}) {
16957: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
16958: }
16959: if ($changes{'categorizecomm'}) {
16960: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
16961: }
1.160.6.42 raeburn 16962: if ($changes{'unauth'}) {
16963: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
16964: }
16965: if ($changes{'auth'}) {
16966: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
16967: }
1.57 raeburn 16968: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
16969: my $cathash;
16970: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
16971: $cathash = $domconfig{'coursecategories'}{'cats'};
16972: } else {
16973: $cathash = {};
16974: }
16975: my (@cats,@trails,%allitems);
16976: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
16977: if (keys(%deletions) > 0) {
16978: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
16979: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
16980: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
16981: }
16982: $resulttext .= '</ul></li>';
16983: }
16984: if (keys(%reorderings) > 0) {
16985: my %sort_by_trail;
16986: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
16987: foreach my $key (keys(%reorderings)) {
16988: if ($allitems{$key} ne '') {
16989: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
16990: }
1.48 raeburn 16991: }
1.57 raeburn 16992: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
16993: $resulttext .= '<li>'.$trails[$trail].'</li>';
16994: }
16995: $resulttext .= '</ul></li>';
1.48 raeburn 16996: }
1.57 raeburn 16997: if (keys(%adds) > 0) {
16998: my %sort_by_trail;
16999: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
17000: foreach my $key (keys(%adds)) {
17001: if ($allitems{$key} ne '') {
17002: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17003: }
17004: }
17005: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17006: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 17007: }
1.57 raeburn 17008: $resulttext .= '</ul></li>';
1.48 raeburn 17009: }
1.160.6.92 raeburn 17010: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
17011: if (ref($lastactref) eq 'HASH') {
17012: $lastactref->{'cats'} = 1;
17013: }
1.48 raeburn 17014: }
17015: $resulttext .= '</ul>';
1.160.6.43 raeburn 17016: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 17017: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17018: if ($changes{'auth'}) {
17019: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
17020: }
17021: if ($changes{'unauth'}) {
17022: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
17023: }
17024: my $cachetime = 24*60*60;
17025: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 17026: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 17027: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 17028: }
17029: }
1.48 raeburn 17030: } else {
17031: $resulttext = '<span class="LC_error">'.
1.57 raeburn 17032: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 17033: }
17034: } else {
1.120 raeburn 17035: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 17036: }
17037: return $resulttext;
17038: }
17039:
1.69 raeburn 17040: sub modify_serverstatuses {
17041: my ($dom,%domconfig) = @_;
17042: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
17043: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
17044: %currserverstatus = %{$domconfig{'serverstatuses'}};
17045: }
17046: my @pages = &serverstatus_pages();
17047: foreach my $type (@pages) {
17048: $newserverstatus{$type}{'namedusers'} = '';
17049: $newserverstatus{$type}{'machines'} = '';
17050: if (defined($env{'form.'.$type.'_namedusers'})) {
17051: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
17052: my @okusers;
17053: foreach my $user (@users) {
17054: my ($uname,$udom) = split(/:/,$user);
17055: if (($udom =~ /^$match_domain$/) &&
17056: (&Apache::lonnet::domain($udom)) &&
17057: ($uname =~ /^$match_username$/)) {
17058: if (!grep(/^\Q$user\E/,@okusers)) {
17059: push(@okusers,$user);
17060: }
17061: }
17062: }
17063: if (@okusers > 0) {
17064: @okusers = sort(@okusers);
17065: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
17066: }
17067: }
17068: if (defined($env{'form.'.$type.'_machines'})) {
17069: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
17070: my @okmachines;
17071: foreach my $ip (@machines) {
17072: my @parts = split(/\./,$ip);
17073: next if (@parts < 4);
17074: my $badip = 0;
17075: for (my $i=0; $i<4; $i++) {
17076: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17077: $badip = 1;
17078: last;
17079: }
17080: }
17081: if (!$badip) {
17082: push(@okmachines,$ip);
17083: }
17084: }
17085: @okmachines = sort(@okmachines);
17086: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17087: }
17088: }
17089: my %serverstatushash = (
17090: serverstatuses => \%newserverstatus,
17091: );
17092: foreach my $type (@pages) {
1.83 raeburn 17093: foreach my $setting ('namedusers','machines') {
1.84 raeburn 17094: my (@current,@new);
1.83 raeburn 17095: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 17096: if ($currserverstatus{$type}{$setting} ne '') {
17097: @current = split(/,/,$currserverstatus{$type}{$setting});
17098: }
17099: }
17100: if ($newserverstatus{$type}{$setting} ne '') {
17101: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 17102: }
17103: if (@current > 0) {
17104: if (@new > 0) {
17105: foreach my $item (@current) {
17106: if (!grep(/^\Q$item\E$/,@new)) {
17107: $changes{$type}{$setting} = 1;
1.82 raeburn 17108: last;
17109: }
17110: }
1.84 raeburn 17111: foreach my $item (@new) {
17112: if (!grep(/^\Q$item\E$/,@current)) {
17113: $changes{$type}{$setting} = 1;
17114: last;
1.82 raeburn 17115: }
17116: }
17117: } else {
1.83 raeburn 17118: $changes{$type}{$setting} = 1;
1.69 raeburn 17119: }
1.83 raeburn 17120: } elsif (@new > 0) {
17121: $changes{$type}{$setting} = 1;
1.69 raeburn 17122: }
17123: }
17124: }
17125: if (keys(%changes) > 0) {
1.81 raeburn 17126: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 17127: my $putresult = &Apache::lonnet::put_dom('configuration',
17128: \%serverstatushash,$dom);
17129: if ($putresult eq 'ok') {
17130: $resulttext .= &mt('Changes made:').'<ul>';
17131: foreach my $type (@pages) {
1.84 raeburn 17132: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 17133: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 17134: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 17135: if ($newserverstatus{$type}{'namedusers'} eq '') {
17136: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17137: } else {
17138: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17139: }
1.84 raeburn 17140: }
17141: if ($changes{$type}{'machines'}) {
1.69 raeburn 17142: if ($newserverstatus{$type}{'machines'} eq '') {
17143: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17144: } else {
17145: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
17146: }
17147:
17148: }
17149: $resulttext .= '</ul></li>';
17150: }
17151: }
17152: $resulttext .= '</ul>';
17153: } else {
17154: $resulttext = '<span class="LC_error">'.
17155: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
17156:
17157: }
17158: } else {
17159: $resulttext = &mt('No changes made to access to server status pages');
17160: }
17161: return $resulttext;
17162: }
17163:
1.118 jms 17164: sub modify_helpsettings {
1.160.6.77 raeburn 17165: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 17166: my ($resulttext,$errors,%changes,%helphash);
17167: my %defaultchecked = ('submitbugs' => 'on');
17168: my @offon = ('off','on');
1.118 jms 17169: my @toggles = ('submitbugs');
1.160.6.77 raeburn 17170: my %current = ('submitbugs' => '',
17171: 'adhoc' => {},
17172: );
1.118 jms 17173: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 17174: %current = %{$domconfig{'helpsettings'}};
17175: }
1.160.6.77 raeburn 17176: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 17177: foreach my $item (@toggles) {
17178: if ($defaultchecked{$item} eq 'on') {
17179: if ($current{$item} eq '') {
17180: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 17181: $changes{$item} = 1;
17182: }
1.160.6.73 raeburn 17183: } elsif ($current{$item} ne $env{'form.'.$item}) {
17184: $changes{$item} = 1;
17185: }
17186: } elsif ($defaultchecked{$item} eq 'off') {
17187: if ($current{$item} eq '') {
17188: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 17189: $changes{$item} = 1;
17190: }
1.160.6.73 raeburn 17191: } elsif ($current{$item} ne $env{'form.'.$item}) {
17192: $changes{$item} = 1;
17193: }
17194: }
17195: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
17196: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
17197: }
17198: }
1.160.6.77 raeburn 17199: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 17200: my $confname = $dom.'-domainconfig';
17201: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 17202: my (@allpos,%newsettings,%changedprivs,$newrole);
17203: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 17204: my @accesstypes = ('all','dh','da','none','status','inc','exc');
17205: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 17206: my %lt = &Apache::lonlocal::texthash(
17207: s => 'system',
17208: d => 'domain',
17209: order => 'Display order',
17210: access => 'Role usage',
1.160.6.79 raeburn 17211: all => 'All with domain helpdesk or helpdesk assistant role',
17212: dh => 'All with domain helpdesk role',
17213: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 17214: none => 'None',
17215: status => 'Determined based on institutional status',
17216: inc => 'Include all, but exclude specific personnel',
17217: exc => 'Exclude all, but include specific personnel',
17218: );
17219: for (my $num=0; $num<=$maxnum; $num++) {
17220: my ($prefix,$identifier,$rolename,%curr);
17221: if ($num == $maxnum) {
17222: next unless ($env{'form.newcusthelp'} == $maxnum);
17223: $identifier = 'custhelp'.$num;
17224: $prefix = 'helproles_'.$num;
17225: $rolename = $env{'form.custhelpname'.$num};
17226: $rolename=~s/[^A-Za-z0-9]//gs;
17227: next if ($rolename eq '');
17228: next if (exists($existing{'rolesdef_'.$rolename}));
17229: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17230: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17231: $newprivs{'c'},$confname,$dom);
17232: if ($result ne 'ok') {
17233: $errors .= '<li><span class="LC_error">'.
17234: &mt('An error occurred storing the new custom role: [_1]',
17235: $result).'</span></li>';
17236: next;
17237: } else {
17238: $changedprivs{$rolename} = \%newprivs;
17239: $newrole = $rolename;
17240: }
17241: } else {
17242: $prefix = 'helproles_'.$num;
17243: $rolename = $env{'form.'.$prefix};
17244: next if ($rolename eq '');
17245: next unless (exists($existing{'rolesdef_'.$rolename}));
17246: $identifier = 'custhelp'.$num;
17247: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
17248: my %currprivs;
17249: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
17250: split(/\_/,$existing{'rolesdef_'.$rolename});
17251: foreach my $level ('c','d','s') {
17252: if ($newprivs{$level} ne $currprivs{$level}) {
17253: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
17254: $newprivs{'c'},$confname,$dom);
17255: if ($result ne 'ok') {
17256: $errors .= '<li><span class="LC_error">'.
17257: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
17258: $rolename,$result).'</span></li>';
17259: } else {
17260: $changedprivs{$rolename} = \%newprivs;
17261: }
17262: last;
17263: }
17264: }
17265: if (ref($current{'adhoc'}) eq 'HASH') {
17266: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17267: %curr = %{$current{'adhoc'}{$rolename}};
17268: }
17269: }
17270: }
17271: my $newpos = $env{'form.'.$prefix.'_pos'};
17272: $newpos =~ s/\D+//g;
17273: $allpos[$newpos] = $rolename;
17274: my $newdesc = $env{'form.'.$prefix.'_desc'};
17275: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
17276: if ($curr{'desc'}) {
17277: if ($curr{'desc'} ne $newdesc) {
17278: $changes{'customrole'}{$rolename}{'desc'} = 1;
17279: $newsettings{$rolename}{'desc'} = $newdesc;
17280: }
17281: } elsif ($newdesc ne '') {
17282: $changes{'customrole'}{$rolename}{'desc'} = 1;
17283: $newsettings{$rolename}{'desc'} = $newdesc;
17284: }
17285: my $access = $env{'form.'.$prefix.'_access'};
17286: if (grep(/^\Q$access\E$/,@accesstypes)) {
17287: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
17288: if ($access eq 'status') {
17289: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
17290: if (scalar(@statuses) == 0) {
17291: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
17292: } else {
17293: my (@shownstatus,$numtypes);
17294: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17295: if (ref($types) eq 'ARRAY') {
17296: $numtypes = scalar(@{$types});
17297: foreach my $type (sort(@statuses)) {
17298: if ($type eq 'default') {
17299: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17300: } elsif (grep(/^\Q$type\E$/,@{$types})) {
17301: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
17302: push(@shownstatus,$usertypes->{$type});
17303: }
1.160.6.73 raeburn 17304: }
17305: }
1.160.6.77 raeburn 17306: if (grep(/^default$/,@statuses)) {
17307: push(@shownstatus,$othertitle);
17308: }
17309: if (scalar(@shownstatus) == 1+$numtypes) {
17310: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
17311: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
17312: } else {
17313: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
17314: if (ref($curr{'status'}) eq 'ARRAY') {
17315: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17316: if (@diffs) {
17317: $changes{'customrole'}{$rolename}{$access} = 1;
17318: }
17319: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17320: $changes{'customrole'}{$rolename}{$access} = 1;
17321: }
17322: }
17323: }
17324: } elsif (($access eq 'inc') || ($access eq 'exc')) {
17325: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
17326: my @newspecstaff;
17327: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
17328: foreach my $person (sort(@personnel)) {
17329: if ($domhelpdesk{$person}) {
17330: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
17331: }
17332: }
17333: if (ref($curr{$access}) eq 'ARRAY') {
17334: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
17335: if (@diffs) {
17336: $changes{'customrole'}{$rolename}{$access} = 1;
17337: }
17338: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17339: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 17340: }
1.160.6.77 raeburn 17341: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
17342: my ($uname,$udom) = split(/:/,$person);
17343: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
17344: }
17345: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 17346: }
1.160.6.77 raeburn 17347: } else {
17348: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
17349: }
17350: unless ($curr{'access'} eq $access) {
17351: $changes{'customrole'}{$rolename}{'access'} = 1;
17352: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 17353: }
17354: }
1.160.6.77 raeburn 17355: if (@allpos > 0) {
17356: my $idx = 0;
17357: foreach my $rolename (@allpos) {
17358: if ($rolename ne '') {
17359: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
17360: if (ref($current{'adhoc'}) eq 'HASH') {
17361: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
17362: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
17363: $changes{'customrole'}{$rolename}{'order'} = 1;
17364: $newsettings{$rolename}{'order'} = $idx+1;
17365: }
17366: }
1.160.6.73 raeburn 17367: }
1.160.6.77 raeburn 17368: $idx ++;
1.122 jms 17369: }
17370: }
1.118 jms 17371: }
1.123 jms 17372: my $putresult;
17373: if (keys(%changes) > 0) {
1.160.6.5 raeburn 17374: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
17375: if ($putresult eq 'ok') {
1.160.6.77 raeburn 17376: if (ref($helphash{'helpsettings'}) eq 'HASH') {
17377: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
17378: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
17379: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
17380: }
17381: }
17382: my $cachetime = 24*60*60;
17383: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17384: if (ref($lastactref) eq 'HASH') {
17385: $lastactref->{'domdefaults'} = 1;
17386: }
17387: } else {
17388: $errors .= '<li><span class="LC_error">'.
17389: &mt('An error occurred storing the settings: [_1]',
17390: $putresult).'</span></li>';
17391: }
17392: }
17393: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
17394: $resulttext = &mt('Changes made:').'<ul>';
17395: my (%shownprivs,@levelorder);
17396: @levelorder = ('c','d','s');
17397: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 17398: foreach my $item (sort(keys(%changes))) {
17399: if ($item eq 'submitbugs') {
17400: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
17401: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
17402: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 17403: } elsif ($item eq 'customrole') {
17404: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 17405: my @keyorder = ('order','desc','access','status','exc','inc');
17406: my %keytext = &Apache::lonlocal::texthash(
17407: order => 'Order',
17408: desc => 'Role description',
17409: access => 'Role usage',
1.160.6.83 raeburn 17410: status => 'Allowed institutional types',
1.160.6.77 raeburn 17411: exc => 'Allowed personnel',
17412: inc => 'Disallowed personnel',
17413: );
1.160.6.73 raeburn 17414: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 17415: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
17416: if ($role eq $newrole) {
17417: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
17418: $role).'<ul>';
17419: } else {
17420: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17421: $role).'<ul>';
17422: }
17423: foreach my $key (@keyorder) {
17424: if ($changes{'customrole'}{$role}{$key}) {
17425: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
17426: $keytext{$key},$newsettings{$role}{$key}).
17427: '</li>';
17428: }
17429: }
17430: if (ref($changedprivs{$role}) eq 'HASH') {
17431: $shownprivs{$role} = 1;
17432: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
17433: foreach my $level (@levelorder) {
17434: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17435: next if ($item eq '');
17436: my ($priv) = split(/\&/,$item,2);
17437: if (&Apache::lonnet::plaintext($priv)) {
17438: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17439: unless ($level eq 'c') {
17440: $resulttext .= ' ('.$lt{$level}.')';
17441: }
17442: $resulttext .= '</li>';
17443: }
17444: }
17445: }
17446: $resulttext .= '</ul>';
17447: }
17448: $resulttext .= '</ul></li>';
17449: }
1.160.6.73 raeburn 17450: }
17451: }
1.160.6.5 raeburn 17452: }
17453: }
17454: }
1.160.6.77 raeburn 17455: if (keys(%changedprivs)) {
17456: foreach my $role (sort(keys(%changedprivs))) {
17457: unless ($shownprivs{$role}) {
17458: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
17459: $role).'<ul>'.
17460: '<li>'.&mt('Privileges set to :').'<ul>';
17461: foreach my $level (@levelorder) {
17462: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
17463: next if ($item eq '');
17464: my ($priv) = split(/\&/,$item,2);
17465: if (&Apache::lonnet::plaintext($priv)) {
17466: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
17467: unless ($level eq 'c') {
17468: $resulttext .= ' ('.$lt{$level}.')';
17469: }
17470: $resulttext .= '</li>';
17471: }
17472: }
17473: }
17474: $resulttext .= '</ul></li></ul></li>';
17475: }
17476: }
17477: }
17478: $resulttext .= '</ul>';
17479: } else {
17480: $resulttext = &mt('No changes made to help settings');
1.118 jms 17481: }
17482: if ($errors) {
1.160.6.5 raeburn 17483: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 17484: $errors.'</ul>';
1.118 jms 17485: }
17486: return $resulttext;
17487: }
17488:
1.121 raeburn 17489: sub modify_coursedefaults {
1.160.6.27 raeburn 17490: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 17491: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 17492: my %defaultchecked = (
17493: 'uselcmath' => 'on',
1.160.6.115 raeburn 17494: 'usejsme' => 'on',
17495: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 17496:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 17497: );
1.160.6.118.2 4(raebur 17498:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 17499: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.70 raeburn 17500: 'uploadquota_community','uploadquota_textbook','mysqltables_official',
17501: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook');
1.160.6.30 raeburn 17502: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 17503: my %staticdefaults = (
17504: anonsurvey_threshold => 10,
17505: uploadquota => 500,
1.160.6.57 raeburn 17506: postsubmit => 60,
1.160.6.70 raeburn 17507: mysqltables => 172800,
1.160.6.21 raeburn 17508: );
1.160.6.90 raeburn 17509: my %texoptions = (
17510: MathJax => 'MathJax',
17511: mimetex => &mt('Convert to Images'),
17512: tth => &mt('TeX to HTML'),
17513: );
1.121 raeburn 17514: $defaultshash{'coursedefaults'} = {};
17515:
17516: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
17517: if ($domconfig{'coursedefaults'} eq '') {
17518: $domconfig{'coursedefaults'} = {};
17519: }
17520: }
17521:
17522: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
17523: foreach my $item (@toggles) {
17524: if ($defaultchecked{$item} eq 'on') {
17525: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17526: ($env{'form.'.$item} eq '0')) {
17527: $changes{$item} = 1;
1.160.6.16 raeburn 17528: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 17529: $changes{$item} = 1;
17530: }
17531: } elsif ($defaultchecked{$item} eq 'off') {
17532: if (($domconfig{'coursedefaults'}{$item} eq '') &&
17533: ($env{'form.'.$item} eq '1')) {
17534: $changes{$item} = 1;
17535: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
17536: $changes{$item} = 1;
17537: }
17538: }
17539: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
17540: }
1.160.6.21 raeburn 17541: foreach my $item (@numbers) {
17542: my ($currdef,$newdef);
1.160.6.26 raeburn 17543: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 17544: if ($item eq 'anonsurvey_threshold') {
17545: $currdef = $domconfig{'coursedefaults'}{$item};
17546: $newdef =~ s/\D//g;
17547: if ($newdef eq '' || $newdef < 1) {
17548: $newdef = 1;
17549: }
17550: $defaultshash{'coursedefaults'}{$item} = $newdef;
17551: } else {
1.160.6.70 raeburn 17552: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
17553: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
17554: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 17555: }
17556: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 17557: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 17558: }
17559: if ($currdef ne $newdef) {
17560: if ($item eq 'anonsurvey_threshold') {
17561: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
17562: $changes{$item} = 1;
17563: }
1.160.6.70 raeburn 17564: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
17565: my $setting = $1;
17566: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
17567: $changes{$setting} = 1;
1.160.6.21 raeburn 17568: }
17569: }
1.139 raeburn 17570: }
17571: }
1.160.6.90 raeburn 17572: my $texengine;
17573: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
17574: $texengine = $env{'form.texengine'};
17575: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
17576: if ($currdef eq '') {
17577: unless ($texengine eq $Apache::lonnet::deftex) {
17578: $changes{'texengine'} = 1;
17579: }
17580: } elsif ($currdef ne $texengine) {
17581: $changes{'texengine'} = 1;
17582: }
17583: }
17584: if ($texengine ne '') {
17585: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
17586: }
1.160.6.64 raeburn 17587: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
17588: my @currclonecode;
17589: if (ref($currclone) eq 'HASH') {
17590: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
17591: @currclonecode = @{$currclone->{'instcode'}};
17592: }
17593: }
17594: my $newclone;
17595: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
17596: $newclone = $env{'form.canclone'};
17597: }
17598: if ($newclone eq 'instcode') {
17599: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
17600: my (%codedefaults,@code_order,@clonecode);
17601: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
17602: \@code_order);
17603: foreach my $item (@code_order) {
17604: if (grep(/^\Q$item\E$/,@newcodes)) {
17605: push(@clonecode,$item);
17606: }
17607: }
17608: if (@clonecode) {
17609: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
17610: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
17611: if (@diffs) {
17612: $changes{'canclone'} = 1;
17613: }
17614: } else {
17615: $newclone eq '';
17616: }
17617: } elsif ($newclone ne '') {
17618: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
17619: }
17620: if ($newclone ne $currclone) {
17621: $changes{'canclone'} = 1;
17622: }
1.160.6.57 raeburn 17623: my %credits;
17624: foreach my $type (@types) {
17625: unless ($type eq 'community') {
17626: $credits{$type} = $env{'form.'.$type.'_credits'};
17627: $credits{$type} =~ s/[^\d.]+//g;
17628: }
17629: }
17630: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
17631: ($env{'form.coursecredits'} eq '1')) {
17632: $changes{'coursecredits'} = 1;
17633: foreach my $type (keys(%credits)) {
17634: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17635: }
17636: } else {
17637: if ($env{'form.coursecredits'} eq '1') {
17638: foreach my $type (@types) {
17639: unless ($type eq 'community') {
17640: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
17641: $changes{'coursecredits'} = 1;
17642: }
17643: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
17644: }
17645: }
17646: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17647: foreach my $type (@types) {
17648: unless ($type eq 'community') {
17649: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
17650: $changes{'coursecredits'} = 1;
17651: last;
17652: }
17653: }
17654: }
17655: }
17656: }
17657: if ($env{'form.postsubmit'} eq '1') {
17658: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
17659: my %currtimeout;
17660: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17661: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
17662: $changes{'postsubmit'} = 1;
17663: }
17664: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17665: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
17666: }
17667: } else {
17668: $changes{'postsubmit'} = 1;
17669: }
17670: foreach my $type (@types) {
17671: my $timeout = $env{'form.'.$type.'_timeout'};
17672: $timeout =~ s/\D//g;
17673: if ($timeout == $staticdefaults{'postsubmit'}) {
17674: $timeout = '';
17675: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
17676: $timeout = '0';
17677: }
17678: unless ($timeout eq '') {
17679: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
17680: }
17681: if (exists($currtimeout{$type})) {
17682: if ($timeout ne $currtimeout{$type}) {
17683: $changes{'postsubmit'} = 1;
17684: }
17685: } elsif ($timeout ne '') {
17686: $changes{'postsubmit'} = 1;
17687: }
17688: }
17689: } else {
17690: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
17691: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17692: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
17693: $changes{'postsubmit'} = 1;
17694: }
17695: } else {
17696: $changes{'postsubmit'} = 1;
17697: }
1.160.6.16 raeburn 17698: }
1.121 raeburn 17699: }
17700: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
17701: $dom);
17702: if ($putresult eq 'ok') {
17703: if (keys(%changes) > 0) {
1.160.6.27 raeburn 17704: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 17705: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 17706: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 17707: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 4(raebur 17708:2): ($changes{'inline_chem'}) || ($changes{'ltiauth'})) {
17709:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 17710: if ($changes{$item}) {
17711: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
17712: }
1.160.6.16 raeburn 17713: }
17714: if ($changes{'coursecredits'}) {
17715: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 17716: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
17717: $domdefaults{$type.'credits'} =
17718: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
17719: }
17720: }
17721: }
17722: if ($changes{'postsubmit'}) {
17723: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17724: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
17725: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17726: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
17727: $domdefaults{$type.'postsubtimeout'} =
17728: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17729: }
17730: }
1.160.6.16 raeburn 17731: }
17732: }
1.160.6.21 raeburn 17733: if ($changes{'uploadquota'}) {
17734: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17735: foreach my $type (@types) {
17736: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
17737: }
17738: }
17739: }
1.160.6.64 raeburn 17740: if ($changes{'canclone'}) {
17741: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17742: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17743: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
17744: if (@clonecodes) {
17745: $domdefaults{'canclone'} = join('+',@clonecodes);
17746: }
17747: }
17748: } else {
17749: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
17750: }
17751: }
1.121 raeburn 17752: my $cachetime = 24*60*60;
17753: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17754: if (ref($lastactref) eq 'HASH') {
17755: $lastactref->{'domdefaults'} = 1;
17756: }
1.121 raeburn 17757: }
17758: $resulttext = &mt('Changes made:').'<ul>';
17759: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 17760: if ($item eq 'uselcmath') {
1.121 raeburn 17761: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 17762: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 17763: } else {
1.160.6.57 raeburn 17764: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
17765: }
17766: } elsif ($item eq 'usejsme') {
17767: if ($env{'form.'.$item} eq '1') {
17768: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
17769: } else {
17770: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 17771: }
1.160.6.115 raeburn 17772: } elsif ($item eq 'inline_chem') {
17773: if ($env{'form.'.$item} eq '1') {
17774: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
17775: } else {
17776: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
17777: }
1.160.6.90 raeburn 17778: } elsif ($item eq 'texengine') {
17779: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
17780: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
17781: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
17782: }
1.139 raeburn 17783: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 17784: $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 17785: } elsif ($item eq 'uploadquota') {
17786: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
17787: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
17788: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
17789: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 17790: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
17791:
1.160.6.21 raeburn 17792: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
17793: '</ul>'.
17794: '</li>';
17795: } else {
17796: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
17797: }
1.160.6.70 raeburn 17798: } elsif ($item eq 'mysqltables') {
17799: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
17800: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
17801: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
17802: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
17803: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
17804: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
17805: '</ul>'.
17806: '</li>';
17807: } else {
17808: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
17809: }
1.160.6.57 raeburn 17810: } elsif ($item eq 'postsubmit') {
17811: if ($domdefaults{'postsubmit'} eq 'off') {
17812: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
17813: } else {
17814: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
17815: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
17816: $resulttext .= &mt('durations:').'<ul>';
17817: foreach my $type (@types) {
17818: $resulttext .= '<li>';
17819: my $timeout;
17820: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
17821: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
17822: }
17823: my $display;
17824: if ($timeout eq '0') {
17825: $display = &mt('unlimited');
17826: } elsif ($timeout eq '') {
17827: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
17828: } else {
17829: $display = &mt('[quant,_1,second]',$timeout);
17830: }
17831: if ($type eq 'community') {
17832: $resulttext .= &mt('Communities');
17833: } elsif ($type eq 'official') {
17834: $resulttext .= &mt('Official courses');
17835: } elsif ($type eq 'unofficial') {
17836: $resulttext .= &mt('Unofficial courses');
17837: } elsif ($type eq 'textbook') {
17838: $resulttext .= &mt('Textbook courses');
17839: }
17840: $resulttext .= ' -- '.$display.'</li>';
17841: }
17842: $resulttext .= '</ul>';
17843: }
17844: $resulttext .= '</li>';
17845: }
1.160.6.16 raeburn 17846: } elsif ($item eq 'coursecredits') {
17847: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
17848: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 17849: ($domdefaults{'unofficialcredits'} eq '') &&
17850: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 17851: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17852: } else {
17853: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
17854: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
17855: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 17856: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 17857: '</ul>'.
17858: '</li>';
17859: }
17860: } else {
17861: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
17862: }
1.160.6.64 raeburn 17863: } elsif ($item eq 'canclone') {
17864: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
17865: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
17866: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
17867: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
17868: }
17869: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
17870: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
17871: } else {
17872: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
17873: }
1.160.6.118.2 4(raebur 17874:2): } elsif ($item eq 'ltiauth') {
17875:2): if ($env{'form.'.$item} eq '1') {
17876:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
17877:2): } else {
17878:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
17879:2): }
1.140 raeburn 17880: }
1.121 raeburn 17881: }
17882: $resulttext .= '</ul>';
17883: } else {
17884: $resulttext = &mt('No changes made to course defaults');
17885: }
17886: } else {
17887: $resulttext = '<span class="LC_error">'.
17888: &mt('An error occurred: [_1]',$putresult).'</span>';
17889: }
17890: return $resulttext;
17891: }
17892:
1.160.6.37 raeburn 17893: sub modify_selfenrollment {
17894: my ($dom,$lastactref,%domconfig) = @_;
17895: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
17896: my @types = ('official','unofficial','community','textbook');
17897: my %titles = &tool_titles();
17898: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
17899: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
17900: $ordered{'default'} = ['types','registered','approval','limit'];
17901:
17902: my (%roles,%shown,%toplevel);
17903: $roles{'0'} = &Apache::lonnet::plaintext('dc');
17904:
17905: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
17906: if ($domconfig{'selfenrollment'} eq '') {
17907: $domconfig{'selfenrollment'} = {};
17908: }
17909: }
17910: %toplevel = (
17911: admin => 'Configuration Rights',
17912: default => 'Default settings',
17913: validation => 'Validation of self-enrollment requests',
17914: );
17915: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
17916:
17917: if (ref($ordered{'admin'}) eq 'ARRAY') {
17918: foreach my $item (@{$ordered{'admin'}}) {
17919: foreach my $type (@types) {
17920: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
17921: $selfenrollhash{'admin'}{$type}{$item} = 1;
17922: } else {
17923: $selfenrollhash{'admin'}{$type}{$item} = 0;
17924: }
17925: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
17926: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
17927: if ($selfenrollhash{'admin'}{$type}{$item} ne
17928: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
17929: push(@{$changes{'admin'}{$type}},$item);
17930: }
17931: } else {
17932: if (!$selfenrollhash{'admin'}{$type}{$item}) {
17933: push(@{$changes{'admin'}{$type}},$item);
17934: }
17935: }
17936: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
17937: push(@{$changes{'admin'}{$type}},$item);
17938: }
17939: }
17940: }
17941: }
17942:
17943: foreach my $item (@{$ordered{'default'}}) {
17944: foreach my $type (@types) {
17945: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
17946: if ($item eq 'types') {
17947: unless (($value eq 'all') || ($value eq 'dom')) {
17948: $value = '';
17949: }
17950: } elsif ($item eq 'registered') {
17951: unless ($value eq '1') {
17952: $value = 0;
17953: }
17954: } elsif ($item eq 'approval') {
17955: unless ($value =~ /^[012]$/) {
17956: $value = 0;
17957: }
17958: } else {
17959: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17960: $value = 'none';
17961: }
17962: }
17963: $selfenrollhash{'default'}{$type}{$item} = $value;
17964: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
17965: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17966: if ($selfenrollhash{'default'}{$type}{$item} ne
17967: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
17968: push(@{$changes{'default'}{$type}},$item);
17969: }
17970: } else {
17971: push(@{$changes{'default'}{$type}},$item);
17972: }
17973: } else {
17974: push(@{$changes{'default'}{$type}},$item);
17975: }
17976: if ($item eq 'limit') {
17977: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
17978: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
17979: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
17980: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
17981: }
17982: } else {
17983: $selfenrollhash{'default'}{$type}{'cap'} = '';
17984: }
17985: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
17986: if ($selfenrollhash{'default'}{$type}{'cap'} ne
17987: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
17988: push(@{$changes{'default'}{$type}},'cap');
17989: }
17990: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
17991: push(@{$changes{'default'}{$type}},'cap');
17992: }
17993: }
17994: }
17995: }
17996:
17997: foreach my $item (@{$itemsref}) {
17998: if ($item eq 'fields') {
17999: my @changed;
18000: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
18001: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
18002: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
18003: }
18004: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18005: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
18006: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
18007: $domconfig{'selfenrollment'}{'validation'}{$item});
18008: } else {
18009: @changed = @{$selfenrollhash{'validation'}{$item}};
18010: }
18011: } else {
18012: @changed = @{$selfenrollhash{'validation'}{$item}};
18013: }
18014: if (@changed) {
18015: if ($selfenrollhash{'validation'}{$item}) {
18016: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
18017: } else {
18018: $changes{'validation'}{$item} = &mt('None');
18019: }
18020: }
18021: } else {
18022: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
18023: if ($item eq 'markup') {
18024: if ($env{'form.selfenroll_validation_'.$item}) {
18025: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
18026: }
18027: }
18028: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18029: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
18030: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
18031: }
18032: }
18033: }
18034: }
18035:
18036: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
18037: $dom);
18038: if ($putresult eq 'ok') {
18039: if (keys(%changes) > 0) {
18040: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18041: $resulttext = &mt('Changes made:').'<ul>';
18042: foreach my $key ('admin','default','validation') {
18043: if (ref($changes{$key}) eq 'HASH') {
18044: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
18045: if ($key eq 'validation') {
18046: foreach my $item (@{$itemsref}) {
18047: if (exists($changes{$key}{$item})) {
18048: if ($item eq 'markup') {
18049: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18050: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
18051: } else {
18052: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
18053: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
18054: }
18055: }
18056: }
18057: } else {
18058: foreach my $type (@types) {
18059: if ($type eq 'community') {
18060: $roles{'1'} = &mt('Community personnel');
18061: } else {
18062: $roles{'1'} = &mt('Course personnel');
18063: }
18064: if (ref($changes{$key}{$type}) eq 'ARRAY') {
18065: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18066: if ($key eq 'admin') {
18067: my @mgrdc = ();
18068: if (ref($ordered{$key}) eq 'ARRAY') {
18069: foreach my $item (@{$ordered{'admin'}}) {
18070: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
18071: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
18072: push(@mgrdc,$item);
18073: }
18074: }
18075: }
18076: if (@mgrdc) {
18077: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
18078: } else {
18079: delete($domdefaults{$type.'selfenrolladmdc'});
18080: }
18081: }
18082: } else {
18083: if (ref($ordered{$key}) eq 'ARRAY') {
18084: foreach my $item (@{$ordered{$key}}) {
18085: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18086: $domdefaults{$type.'selfenroll'.$item} =
18087: $selfenrollhash{$key}{$type}{$item};
18088: }
18089: }
18090: }
18091: }
18092: }
18093: $resulttext .= '<li>'.$titles{$type}.'<ul>';
18094: foreach my $item (@{$ordered{$key}}) {
18095: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
18096: $resulttext .= '<li>';
18097: if ($key eq 'admin') {
18098: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
18099: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
18100: } else {
18101: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
18102: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
18103: }
18104: $resulttext .= '</li>';
18105: }
18106: }
18107: $resulttext .= '</ul></li>';
18108: }
18109: }
18110: $resulttext .= '</ul></li>';
18111: }
18112: }
1.160.6.93 raeburn 18113: }
18114: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
18115: my $cachetime = 24*60*60;
18116: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18117: if (ref($lastactref) eq 'HASH') {
18118: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 18119: }
18120: }
18121: $resulttext .= '</ul>';
18122: } else {
18123: $resulttext = &mt('No changes made to self-enrollment settings');
18124: }
18125: } else {
18126: $resulttext = '<span class="LC_error">'.
18127: &mt('An error occurred: [_1]',$putresult).'</span>';
18128: }
18129: return $resulttext;
18130: }
18131:
1.160.6.113 raeburn 18132: sub modify_wafproxy {
18133: my ($dom,$action,$lastactref,%domconfig) = @_;
18134: my %servers = &Apache::lonnet::internet_dom_servers($dom);
18135: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
18136: %wafproxy,%changes,%expirecache,%expiresaml);
18137: foreach my $server (sort(keys(%servers))) {
18138: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
18139: if ($serverhome eq $server) {
18140: my $serverdom = &Apache::lonnet::host_domain($server);
18141: if ($serverdom eq $dom) {
18142: $canset{$server} = 1;
18143: }
18144: }
18145: }
18146: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
18147: %{$values{$dom}} = ();
18148: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
18149: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
18150: }
18151: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
18152: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
18153: }
18154: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18155: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
18156: }
18157: }
18158: my $output;
18159: if (keys(%canset)) {
18160: %{$wafproxy{'alias'}} = ();
18161: %{$wafproxy{'saml'}} = ();
18162: foreach my $key (sort(keys(%canset))) {
18163: if ($env{'form.wafproxy_'.$dom}) {
18164: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
18165: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
18166: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
18167: $changes{'alias'} = 1;
18168: }
18169: if ($env{'form.wafproxy_alias_saml_'.$key}) {
18170: $wafproxy{'saml'}{$key} = 1;
18171: }
18172: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
18173: $changes{'saml'} = 1;
18174: }
18175: } else {
18176: $wafproxy{'alias'}{$key} = '';
18177: $wafproxy{'saml'}{$key} = '';
18178: if ($curralias{$key}) {
18179: $changes{'alias'} = 1;
18180: }
18181: if ($currsaml{$key}) {
18182: $changes{'saml'} = 1;
18183: }
18184: }
18185: if ($wafproxy{'alias'}{$key} eq '') {
18186: if ($curralias{$key}) {
18187: $expirecache{$key} = 1;
18188: }
18189: delete($wafproxy{'alias'}{$key});
18190: }
18191: if ($wafproxy{'saml'}{$key} eq '') {
18192: if ($currsaml{$key}) {
18193: $expiresaml{$key} = 1;
18194: }
18195: delete($wafproxy{'saml'}{$key});
18196: }
18197: }
18198: unless (keys(%{$wafproxy{'alias'}})) {
18199: delete($wafproxy{'alias'});
18200: }
18201: unless (keys(%{$wafproxy{'saml'}})) {
18202: delete($wafproxy{'saml'});
18203: }
18204: # Localization for values in %warn occurs in &mt() calls separately.
18205: my %warn = (
18206: trusted => 'trusted IP range(s)',
18207: vpnint => 'internal IP range(s) for VPN sessions(s)',
18208: vpnext => 'IP range(s) for backend WAF connections',
18209: );
18210: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
18211: my $possible = $env{'form.wafproxy_'.$item};
18212: $possible =~ s/^\s+|\s+$//g;
18213: if ($possible ne '') {
18214: if ($item eq 'remoteip') {
18215: if ($possible =~ /^[mhn]$/) {
18216: $wafproxy{$item} = $possible;
18217: }
18218: } elsif ($item eq 'ipheader') {
18219: if ($wafproxy{'remoteip'} eq 'h') {
18220: $wafproxy{$item} = $possible;
18221: }
18222: } elsif ($item eq 'sslopt') {
18223: if ($possible =~ /^0|1$/) {
18224: $wafproxy{$item} = $possible;
18225: }
18226: } else {
18227: my (@ok,$count);
18228: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
18229: unless ($env{'form.wafproxy_vpnaccess'}) {
18230: $possible = '';
18231: }
18232: } elsif ($item eq 'trusted') {
18233: unless ($wafproxy{'remoteip'} eq 'h') {
18234: $possible = '';
18235: }
18236: }
18237: unless ($possible eq '') {
18238: $possible =~ s/[\r\n]+/\s/g;
18239: $possible =~ s/\s*-\s*/-/g;
18240: $possible =~ s/\s+/,/g;
18241: $possible =~ s/,+/,/g;
18242: }
18243: $count = 0;
18244: if ($possible ne '') {
18245: foreach my $poss (split(/\,/,$possible)) {
18246: $count ++;
18247: $poss = &validate_ip_pattern($poss);
18248: if ($poss ne '') {
18249: push(@ok,$poss);
18250: }
18251: }
18252: my $diff = $count - scalar(@ok);
18253: if ($diff) {
18254: push(@warnings,'<li>'.
18255: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
18256: $diff,$warn{$item}).
18257: '</li>');
18258: }
18259: if (@ok) {
18260: my @cidr_list;
18261: foreach my $item (@ok) {
18262: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
18263: }
18264: $wafproxy{$item} = join(',',@cidr_list);
18265: }
18266: }
18267: }
18268: if ($wafproxy{$item} ne $currvalue{$item}) {
18269: $changes{$item} = 1;
18270: }
18271: } elsif ($currvalue{$item}) {
18272: $changes{$item} = 1;
18273: }
18274: }
18275: } else {
18276: if (keys(%curralias)) {
18277: $changes{'alias'} = 1;
18278: }
18279: if (keys(%currsaml)) {
18280: $changes{'saml'} = 1;
18281: }
18282: if (keys(%currvalue)) {
18283: foreach my $key (keys(%currvalue)) {
18284: $changes{$key} = 1;
18285: }
18286: }
18287: }
18288: if (keys(%changes)) {
18289: my %defaultshash = (
18290: wafproxy => \%wafproxy,
18291: );
18292: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18293: $dom);
18294: if ($putresult eq 'ok') {
18295: my $cachetime = 24*60*60;
18296: my (%domdefaults,$updatedomdefs);
18297: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
18298: if ($changes{$item}) {
18299: unless ($updatedomdefs) {
18300: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18301: $updatedomdefs = 1;
18302: }
18303: if ($wafproxy{$item}) {
18304: $domdefaults{'waf_'.$item} = $wafproxy{$item};
18305: } elsif (exists($domdefaults{'waf_'.$item})) {
18306: delete($domdefaults{'waf_'.$item});
18307: }
18308: }
18309: }
18310: if ($updatedomdefs) {
18311: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18312: if (ref($lastactref) eq 'HASH') {
18313: $lastactref->{'domdefaults'} = 1;
18314: }
18315: }
18316: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
18317: my %updates = %expirecache;
18318: foreach my $key (keys(%expirecache)) {
18319: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
18320: }
18321: if (ref($wafproxy{'alias'}) eq 'HASH') {
18322: my $cachetime = 24*60*60;
18323: foreach my $key (keys(%{$wafproxy{'alias'}})) {
18324: $updates{$key} = 1;
18325: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
18326: $cachetime);
18327: }
18328: }
18329: if (ref($lastactref) eq 'HASH') {
18330: $lastactref->{'proxyalias'} = \%updates;
18331: }
18332: }
18333: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
18334: my %samlupdates = %expiresaml;
18335: foreach my $key (keys(%expiresaml)) {
18336: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
18337: }
18338: if (ref($wafproxy{'saml'}) eq 'HASH') {
18339: my $cachetime = 24*60*60;
18340: foreach my $key (keys(%{$wafproxy{'saml'}})) {
18341: $samlupdates{$key} = 1;
18342: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
18343: $cachetime);
18344: }
18345: }
18346: if (ref($lastactref) eq 'HASH') {
18347: $lastactref->{'proxysaml'} = \%samlupdates;
18348: }
18349: }
18350: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 18351: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 18352: if ($changes{$item}) {
18353: if ($item eq 'alias') {
18354: my $numaliased = 0;
18355: if (ref($wafproxy{'alias'}) eq 'HASH') {
18356: my $shown;
18357: if (keys(%{$wafproxy{'alias'}})) {
18358: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
18359: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
18360: &Apache::lonnet::hostname($server),
18361: $wafproxy{'alias'}{$server}).'</li>';
18362: $numaliased ++;
18363: }
18364: if ($numaliased) {
18365: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
18366: '<ul>'.$shown.'</ul>').'</li>';
18367: }
18368: }
18369: }
18370: unless ($numaliased) {
18371: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
18372: }
18373: } elsif ($item eq 'saml') {
18374: my $shown;
18375: if (ref($wafproxy{'saml'}) eq 'HASH') {
18376: if (keys(%{$wafproxy{'saml'}})) {
18377: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
18378: }
18379: }
18380: if ($shown) {
18381: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
18382: $shown).'</li>';
18383: } else {
18384: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
18385: }
18386: } else {
18387: if ($item eq 'remoteip') {
18388: my %ip_methods = &remoteip_methods();
18389: if ($wafproxy{$item} =~ /^[mh]$/) {
18390: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
18391: $ip_methods{$wafproxy{$item}}).'</li>';
18392: } else {
18393: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
18394: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
18395: '</li>';
18396: } else {
18397: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
18398: }
18399: }
18400: } elsif ($item eq 'ipheader') {
18401: if ($wafproxy{$item}) {
18402: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
18403: $wafproxy{$item}).'</li>';
18404: } else {
18405: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
18406: }
18407: } elsif ($item eq 'trusted') {
18408: if ($wafproxy{$item}) {
18409: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
18410: $wafproxy{$item}).'</li>';
18411: } else {
18412: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
18413: }
18414: } elsif ($item eq 'vpnint') {
18415: if ($wafproxy{$item}) {
18416: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
18417: $wafproxy{$item}).'</li>';
18418: } else {
18419: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
18420: }
18421: } elsif ($item eq 'vpnext') {
18422: if ($wafproxy{$item}) {
18423: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
18424: $wafproxy{$item}).'</li>';
18425: } else {
18426: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
18427: }
18428: } elsif ($item eq 'sslopt') {
18429: if ($wafproxy{$item}) {
18430: $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>';
18431: } else {
18432: $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>';
18433: }
18434: }
18435: }
18436: }
18437: }
18438: } else {
18439: $output = '<span class="LC_error">'.
18440: &mt('An error occurred: [_1]',$putresult).'</span>';
18441: }
18442: } elsif (keys(%canset)) {
18443: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
18444: }
18445: if (@warnings) {
18446: $output .= '<br />'.&mt('Warnings:').'<ul>'.
18447: join("\n",@warnings).'</ul>';
18448: }
18449: return $output;
18450: }
18451:
18452: sub validate_ip_pattern {
18453: my ($pattern) = @_;
18454: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
18455: my ($start,$end) = ($1,$2);
18456: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
18457: if (($start !~ m{/}) && ($end !~ m{/})) {
18458: return $start.'-'.$end;
18459: }
18460: }
18461: } elsif ($pattern ne '') {
18462: $pattern = &Net::CIDR::cidrvalidate($pattern);
18463: if ($pattern ne '') {
18464: return $pattern;
18465: }
18466: }
18467: return;
18468: }
18469:
1.137 raeburn 18470: sub modify_usersessions {
1.160.6.27 raeburn 18471: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 18472: my @hostingtypes = ('version','excludedomain','includedomain');
18473: my @offloadtypes = ('primary','default');
18474: my %types = (
18475: remote => \@hostingtypes,
18476: hosted => \@hostingtypes,
18477: spares => \@offloadtypes,
18478: );
18479: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 18480: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 18481: my (%by_ip,%by_location,@intdoms);
18482: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
18483: my @locations = sort(keys(%by_location));
1.137 raeburn 18484: my (%defaultshash,%changes);
18485: foreach my $prefix (@prefixes) {
18486: $defaultshash{'usersessions'}{$prefix} = {};
18487: }
1.160.6.27 raeburn 18488: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 18489: my $resulttext;
1.138 raeburn 18490: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 18491: foreach my $prefix (@prefixes) {
1.145 raeburn 18492: next if ($prefix eq 'spares');
18493: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 18494: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
18495: if ($type eq 'version') {
18496: my $value = $env{'form.'.$prefix.'_'.$type};
18497: my $okvalue;
18498: if ($value ne '') {
18499: if (grep(/^\Q$value\E$/,@lcversions)) {
18500: $okvalue = $value;
18501: }
18502: }
18503: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18504: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18505: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
18506: if ($inuse == 0) {
18507: $changes{$prefix}{$type} = 1;
18508: } else {
18509: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
18510: $changes{$prefix}{$type} = 1;
18511: }
18512: if ($okvalue ne '') {
18513: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18514: }
18515: }
18516: } else {
18517: if (($inuse == 1) && ($okvalue ne '')) {
18518: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18519: $changes{$prefix}{$type} = 1;
18520: }
18521: }
18522: } else {
18523: if (($inuse == 1) && ($okvalue ne '')) {
18524: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18525: $changes{$prefix}{$type} = 1;
18526: }
18527: }
18528: } else {
18529: if (($inuse == 1) && ($okvalue ne '')) {
18530: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
18531: $changes{$prefix}{$type} = 1;
18532: }
18533: }
18534: } else {
18535: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
18536: my @okvals;
18537: foreach my $val (@vals) {
1.138 raeburn 18538: if ($val =~ /:/) {
18539: my @items = split(/:/,$val);
18540: foreach my $item (@items) {
18541: if (ref($by_location{$item}) eq 'ARRAY') {
18542: push(@okvals,$item);
18543: }
18544: }
18545: } else {
18546: if (ref($by_location{$val}) eq 'ARRAY') {
18547: push(@okvals,$val);
18548: }
1.137 raeburn 18549: }
18550: }
18551: @okvals = sort(@okvals);
18552: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18553: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
18554: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18555: if ($inuse == 0) {
18556: $changes{$prefix}{$type} = 1;
18557: } else {
18558: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18559: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
18560: if (@changed > 0) {
18561: $changes{$prefix}{$type} = 1;
18562: }
18563: }
18564: } else {
18565: if ($inuse == 1) {
18566: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18567: $changes{$prefix}{$type} = 1;
18568: }
18569: }
18570: } else {
18571: if ($inuse == 1) {
18572: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18573: $changes{$prefix}{$type} = 1;
18574: }
18575: }
18576: } else {
18577: if ($inuse == 1) {
18578: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
18579: $changes{$prefix}{$type} = 1;
18580: }
18581: }
18582: }
18583: }
18584: }
1.145 raeburn 18585:
18586: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 18587: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 18588: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
18589: my $savespares;
18590:
18591: foreach my $lonhost (sort(keys(%servers))) {
18592: my $serverhomeID =
18593: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 18594: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 18595: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
18596: my %spareschg;
18597: foreach my $type (@{$types{'spares'}}) {
18598: my @okspares;
18599: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
18600: foreach my $server (@checked) {
1.152 raeburn 18601: if (&Apache::lonnet::hostname($server) ne '') {
18602: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
18603: unless (grep(/^\Q$server\E$/,@okspares)) {
18604: push(@okspares,$server);
18605: }
1.145 raeburn 18606: }
18607: }
18608: }
18609: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
18610: my $newspare;
1.152 raeburn 18611: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
18612: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 18613: $newspare = $new;
18614: }
18615: }
1.152 raeburn 18616: my @spares;
18617: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
18618: @spares = sort(@okspares,$newspare);
18619: } else {
18620: @spares = sort(@okspares);
18621: }
18622: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 18623: if (ref($spareid{$lonhost}) eq 'HASH') {
18624: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 18625: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 18626: if (@diffs > 0) {
18627: $spareschg{$type} = 1;
18628: }
18629: }
18630: }
18631: }
18632: if (keys(%spareschg) > 0) {
18633: $changes{'spares'}{$lonhost} = \%spareschg;
18634: }
18635: }
1.160.6.61 raeburn 18636: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 18637: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 18638: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
18639: my @okoffload;
18640: if (@offloadnow) {
18641: foreach my $server (@offloadnow) {
18642: if (&Apache::lonnet::hostname($server) ne '') {
18643: unless (grep(/^\Q$server\E$/,@okoffload)) {
18644: push(@okoffload,$server);
18645: }
18646: }
18647: }
18648: if (@okoffload) {
18649: foreach my $lonhost (@okoffload) {
18650: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
18651: }
18652: }
18653: }
1.160.6.105 raeburn 18654: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
18655: my @okoffloadoth;
18656: if (@offloadoth) {
18657: foreach my $server (@offloadoth) {
18658: if (&Apache::lonnet::hostname($server) ne '') {
18659: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
18660: push(@okoffloadoth,$server);
18661: }
18662: }
18663: }
18664: if (@okoffloadoth) {
18665: foreach my $lonhost (@okoffloadoth) {
18666: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
18667: }
18668: }
18669: }
1.145 raeburn 18670: if (ref($domconfig{'usersessions'}) eq 'HASH') {
18671: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
18672: if (ref($changes{'spares'}) eq 'HASH') {
18673: if (keys(%{$changes{'spares'}}) > 0) {
18674: $savespares = 1;
18675: }
18676: }
18677: } else {
18678: $savespares = 1;
18679: }
1.160.6.105 raeburn 18680: foreach my $offload ('offloadnow','offloadoth') {
18681: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
18682: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
18683: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
18684: $changes{$offload} = 1;
1.160.6.61 raeburn 18685: last;
18686: }
18687: }
1.160.6.105 raeburn 18688: unless ($changes{$offload}) {
18689: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
18690: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
18691: $changes{$offload} = 1;
18692: last;
18693: }
18694: }
18695: }
18696: } else {
18697: if (($offload eq 'offloadnow') && (@okoffload)) {
18698: $changes{'offloadnow'} = 1;
18699: }
18700: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
18701: $changes{'offloadoth'} = 1;
18702: }
1.160.6.61 raeburn 18703: }
1.160.6.105 raeburn 18704: }
18705: } else {
18706: if (@okoffload) {
1.160.6.61 raeburn 18707: $changes{'offloadnow'} = 1;
18708: }
1.160.6.105 raeburn 18709: if (@okoffloadoth) {
18710: $changes{'offloadoth'} = 1;
18711: }
1.145 raeburn 18712: }
1.147 raeburn 18713: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
18714: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 18715: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18716: $dom);
18717: if ($putresult eq 'ok') {
18718: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18719: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
18720: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
18721: }
18722: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
18723: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
18724: }
1.160.6.61 raeburn 18725: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18726: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
18727: }
1.160.6.105 raeburn 18728: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18729: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
18730: }
1.137 raeburn 18731: }
18732: my $cachetime = 24*60*60;
18733: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 18734: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 18735: if (ref($lastactref) eq 'HASH') {
18736: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 18737: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 18738: }
1.147 raeburn 18739: if (keys(%changes) > 0) {
18740: my %lt = &usersession_titles();
18741: $resulttext = &mt('Changes made:').'<ul>';
18742: foreach my $prefix (@prefixes) {
18743: if (ref($changes{$prefix}) eq 'HASH') {
18744: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
18745: if ($prefix eq 'spares') {
18746: if (ref($changes{$prefix}) eq 'HASH') {
18747: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
18748: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 18749: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 18750: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
18751: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 18752: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
18753: foreach my $type (@{$types{$prefix}}) {
18754: if ($changes{$prefix}{$lonhost}{$type}) {
18755: my $offloadto = &mt('None');
18756: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
18757: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
18758: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
18759: }
1.145 raeburn 18760: }
1.147 raeburn 18761: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 18762: }
1.137 raeburn 18763: }
18764: }
1.147 raeburn 18765: $resulttext .= '</li>';
1.137 raeburn 18766: }
18767: }
1.147 raeburn 18768: } else {
18769: foreach my $type (@{$types{$prefix}}) {
18770: if (defined($changes{$prefix}{$type})) {
18771: my $newvalue;
18772: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
18773: if (ref($defaultshash{'usersessions'}{$prefix})) {
18774: if ($type eq 'version') {
18775: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
18776: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
18777: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
18778: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
18779: }
1.145 raeburn 18780: }
18781: }
18782: }
1.147 raeburn 18783: if ($newvalue eq '') {
18784: if ($type eq 'version') {
18785: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
18786: } else {
18787: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
18788: }
1.145 raeburn 18789: } else {
1.147 raeburn 18790: if ($type eq 'version') {
18791: $newvalue .= ' '.&mt('(or later)');
18792: }
18793: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 18794: }
1.137 raeburn 18795: }
18796: }
18797: }
1.147 raeburn 18798: $resulttext .= '</ul>';
1.137 raeburn 18799: }
18800: }
1.160.6.61 raeburn 18801: if ($changes{'offloadnow'}) {
18802: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
18803: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 18804: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 18805: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
18806: $resulttext .= '<li>'.$lonhost.'</li>';
18807: }
18808: $resulttext .= '</ul>';
18809: } else {
1.160.6.105 raeburn 18810: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
18811: }
18812: } else {
18813: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
18814: }
18815: }
18816: if ($changes{'offloadoth'}) {
18817: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
18818: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
18819: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
18820: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
18821: $resulttext .= '<li>'.$lonhost.'</li>';
18822: }
18823: $resulttext .= '</ul>';
18824: } else {
18825: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 18826: }
18827: } else {
1.160.6.105 raeburn 18828: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 18829: }
18830: }
1.147 raeburn 18831: $resulttext .= '</ul>';
18832: } else {
18833: $resulttext = $nochgmsg;
1.137 raeburn 18834: }
18835: } else {
18836: $resulttext = '<span class="LC_error">'.
18837: &mt('An error occurred: [_1]',$putresult).'</span>';
18838: }
18839: } else {
1.147 raeburn 18840: $resulttext = $nochgmsg;
1.137 raeburn 18841: }
18842: return $resulttext;
18843: }
18844:
1.150 raeburn 18845: sub modify_loadbalancing {
18846: my ($dom,%domconfig) = @_;
18847: my $primary_id = &Apache::lonnet::domain($dom,'primary');
18848: my $intdom = &Apache::lonnet::internet_dom($primary_id);
18849: my ($othertitle,$usertypes,$types) =
18850: &Apache::loncommon::sorted_inst_types($dom);
18851: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 18852: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 18853: my @sparestypes = ('primary','default');
18854: my %typetitles = &sparestype_titles();
18855: my $resulttext;
1.160.6.94 raeburn 18856: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 18857: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18858: %existing = %{$domconfig{'loadbalancing'}};
18859: }
18860: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 18861: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 18862: my ($saveloadbalancing,%defaultshash,%changes);
18863: my ($alltypes,$othertypes,$titles) =
18864: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
18865: my %ruletitles = &offloadtype_text();
18866: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
18867: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
18868: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
18869: if ($balancer eq '') {
18870: next;
18871: }
18872: if (!exists($servers{$balancer})) {
18873: if (exists($currbalancer{$balancer})) {
18874: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 18875: }
1.160.6.7 raeburn 18876: next;
18877: }
18878: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
18879: push(@{$changes{'delete'}},$balancer);
18880: next;
18881: }
18882: if (!exists($currbalancer{$balancer})) {
18883: push(@{$changes{'add'}},$balancer);
18884: }
18885: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
18886: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
18887: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
18888: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
18889: $saveloadbalancing = 1;
18890: }
18891: foreach my $sparetype (@sparestypes) {
18892: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
18893: my @offloadto;
18894: foreach my $target (@targets) {
18895: if (($servers{$target}) && ($target ne $balancer)) {
18896: if ($sparetype eq 'default') {
18897: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
18898: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 18899: }
18900: }
1.160.6.7 raeburn 18901: unless(grep(/^\Q$target\E$/,@offloadto)) {
18902: push(@offloadto,$target);
18903: }
1.150 raeburn 18904: }
18905: }
1.160.6.76 raeburn 18906: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
18907: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
18908: push(@offloadto,$balancer);
18909: }
18910: }
18911: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 18912: }
1.160.6.94 raeburn 18913: if ($env{'form.loadbalancing_cookie_'.$i}) {
18914: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
18915: if (exists($currbalancer{$balancer})) {
18916: unless ($currcookies{$balancer}) {
18917: $changes{'curr'}{$balancer}{'cookie'} = 1;
18918: }
18919: }
18920: } elsif (exists($currbalancer{$balancer})) {
18921: if ($currcookies{$balancer}) {
18922: $changes{'curr'}{$balancer}{'cookie'} = 1;
18923: }
18924: }
1.160.6.7 raeburn 18925: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 18926: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 18927: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
18928: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 18929: if (@targetdiffs > 0) {
1.160.6.7 raeburn 18930: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18931: }
1.160.6.7 raeburn 18932: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18933: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18934: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 18935: }
18936: }
18937: }
18938: } else {
1.160.6.7 raeburn 18939: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
18940: foreach my $sparetype (@sparestypes) {
18941: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
18942: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
18943: $changes{'curr'}{$balancer}{'targets'} = 1;
18944: }
1.150 raeburn 18945: }
18946: }
1.160.6.7 raeburn 18947: }
1.150 raeburn 18948: }
18949: my $ishomedom;
1.160.6.7 raeburn 18950: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
18951: $ishomedom = 1;
1.150 raeburn 18952: }
18953: if (ref($alltypes) eq 'ARRAY') {
18954: foreach my $type (@{$alltypes}) {
18955: my $rule;
1.160.6.7 raeburn 18956: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 18957: (!$ishomedom)) {
1.160.6.7 raeburn 18958: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
18959: }
18960: if ($rule eq 'specific') {
1.160.6.55 raeburn 18961: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
18962: if (exists($servers{$specifiedhost})) {
18963: $rule = $specifiedhost;
18964: }
1.150 raeburn 18965: }
1.160.6.7 raeburn 18966: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
18967: if (ref($currrules{$balancer}) eq 'HASH') {
18968: if ($rule ne $currrules{$balancer}{$type}) {
18969: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18970: }
18971: } elsif ($rule ne '') {
1.160.6.7 raeburn 18972: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 18973: }
18974: }
18975: }
1.160.6.7 raeburn 18976: }
18977: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
18978: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
18979: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
18980: $defaultshash{'loadbalancing'} = {};
18981: }
18982: my $putresult = &Apache::lonnet::put_dom('configuration',
18983: \%defaultshash,$dom);
18984: if ($putresult eq 'ok') {
18985: if (keys(%changes) > 0) {
1.160.6.54 raeburn 18986: my %toupdate;
1.160.6.7 raeburn 18987: if (ref($changes{'delete'}) eq 'ARRAY') {
18988: foreach my $balancer (sort(@{$changes{'delete'}})) {
18989: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 18990: $toupdate{$balancer} = 1;
1.150 raeburn 18991: }
1.160.6.7 raeburn 18992: }
18993: if (ref($changes{'add'}) eq 'ARRAY') {
18994: foreach my $balancer (sort(@{$changes{'add'}})) {
18995: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 18996: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 18997: }
18998: }
18999: if (ref($changes{'curr'}) eq 'HASH') {
19000: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 19001: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 19002: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
19003: if ($changes{'curr'}{$balancer}{'targets'}) {
19004: my %offloadstr;
19005: foreach my $sparetype (@sparestypes) {
19006: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19007: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19008: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19009: }
19010: }
1.150 raeburn 19011: }
1.160.6.7 raeburn 19012: if (keys(%offloadstr) == 0) {
19013: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 19014: } else {
1.160.6.7 raeburn 19015: my $showoffload;
19016: foreach my $sparetype (@sparestypes) {
19017: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
19018: if (defined($offloadstr{$sparetype})) {
19019: $showoffload .= $offloadstr{$sparetype};
19020: } else {
19021: $showoffload .= &mt('None');
19022: }
19023: $showoffload .= (' 'x3);
19024: }
19025: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 19026: }
19027: }
19028: }
1.160.6.7 raeburn 19029: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
19030: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
19031: foreach my $type (@{$alltypes}) {
19032: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
19033: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19034: my $balancetext;
19035: if ($rule eq '') {
19036: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 19037: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 19038: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
19039: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 19040: foreach my $sparetype (@sparestypes) {
19041: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19042: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19043: }
19044: }
1.160.6.55 raeburn 19045: foreach my $item (@{$alltypes}) {
19046: next if ($item =~ /^_LC_ipchange/);
19047: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
19048: if ($hasrule eq 'homeserver') {
19049: map { $toupdate{$_} = 1; } (keys(%libraryservers));
19050: } else {
19051: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
19052: if ($servers{$hasrule}) {
19053: $toupdate{$hasrule} = 1;
19054: }
19055: }
19056: }
19057: }
19058: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
19059: $balancetext = $ruletitles{$rule};
19060: } else {
19061: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19062: $balancetext = $ruletitles{'particular'}.' '.$receiver;
19063: if ($receiver) {
19064: $toupdate{$receiver};
19065: }
19066: }
19067: } else {
19068: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 19069: }
1.160.6.7 raeburn 19070: } else {
19071: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
19072: }
1.160.6.26 raeburn 19073: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 19074: }
19075: }
19076: }
19077: }
1.160.6.94 raeburn 19078: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 19079: if ($currcookies{$balancer}) {
19080: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
19081: $balancer).'</li>';
19082: } else {
19083: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
19084: $balancer).'</li>';
19085: }
1.160.6.94 raeburn 19086: }
1.160.6.106 raeburn 19087: }
19088: }
19089: if (keys(%toupdate)) {
19090: my %thismachine;
19091: my $updatedhere;
19092: my $cachetime = 60*60*24;
19093: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
19094: foreach my $lonhost (keys(%toupdate)) {
19095: if ($thismachine{$lonhost}) {
19096: unless ($updatedhere) {
19097: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
19098: $defaultshash{'loadbalancing'},
19099: $cachetime);
19100: $updatedhere = 1;
1.160.6.54 raeburn 19101: }
1.160.6.106 raeburn 19102: } else {
19103: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
19104: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 19105: }
1.150 raeburn 19106: }
1.160.6.7 raeburn 19107: }
19108: if ($resulttext ne '') {
19109: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 19110: } else {
19111: $resulttext = $nochgmsg;
19112: }
19113: } else {
1.160.6.7 raeburn 19114: $resulttext = $nochgmsg;
1.150 raeburn 19115: }
19116: } else {
1.160.6.7 raeburn 19117: $resulttext = '<span class="LC_error">'.
19118: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 19119: }
19120: } else {
1.160.6.7 raeburn 19121: $resulttext = $nochgmsg;
1.150 raeburn 19122: }
19123: return $resulttext;
19124: }
19125:
1.48 raeburn 19126: sub recurse_check {
19127: my ($chkcats,$categories,$depth,$name) = @_;
19128: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
19129: my $chg = 0;
19130: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
19131: my $category = $chkcats->[$depth]{$name}[$j];
19132: my $item;
19133: if ($category eq '') {
19134: $chg ++;
19135: } else {
19136: my $deeper = $depth + 1;
19137: $item = &escape($category).':'.&escape($name).':'.$depth;
19138: if ($chg) {
19139: $categories->{$item} -= $chg;
19140: }
19141: &recurse_check($chkcats,$categories,$deeper,$category);
19142: $deeper --;
19143: }
19144: }
19145: }
19146: return;
19147: }
19148:
19149: sub recurse_cat_deletes {
19150: my ($item,$coursecategories,$deletions) = @_;
19151: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
19152: my $subdepth = $depth + 1;
19153: if (ref($coursecategories) eq 'HASH') {
19154: foreach my $subitem (keys(%{$coursecategories})) {
19155: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
19156: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
19157: delete($coursecategories->{$subitem});
19158: $deletions->{$subitem} = 1;
19159: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 19160: }
1.48 raeburn 19161: }
19162: }
19163: return;
19164: }
19165:
1.125 raeburn 19166: sub active_dc_picker {
1.160.6.16 raeburn 19167: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 19168: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 19169: my @domcoord = keys(%domcoords);
19170: if (keys(%currhash)) {
19171: foreach my $dc (keys(%currhash)) {
19172: unless (exists($domcoords{$dc})) {
19173: push(@domcoord,$dc);
19174: }
19175: }
19176: }
19177: @domcoord = sort(@domcoord);
19178: my $numdcs = scalar(@domcoord);
19179: my $rows = 0;
19180: my $table;
1.125 raeburn 19181: if ($numdcs > 1) {
1.160.6.16 raeburn 19182: $table = '<table>';
19183: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 19184: my $rem = $i%($numinrow);
19185: if ($rem == 0) {
19186: if ($i > 0) {
1.160.6.16 raeburn 19187: $table .= '</tr>';
1.125 raeburn 19188: }
1.160.6.16 raeburn 19189: $table .= '<tr>';
19190: $rows ++;
1.125 raeburn 19191: }
1.160.6.16 raeburn 19192: my $check = '';
19193: if ($inputtype eq 'radio') {
19194: if (keys(%currhash) == 0) {
19195: if (!$i) {
19196: $check = ' checked="checked"';
19197: }
19198: } elsif (exists($currhash{$domcoord[$i]})) {
19199: $check = ' checked="checked"';
19200: }
19201: } else {
19202: if (exists($currhash{$domcoord[$i]})) {
19203: $check = ' checked="checked"';
1.125 raeburn 19204: }
19205: }
1.160.6.16 raeburn 19206: if ($i == @domcoord - 1) {
1.125 raeburn 19207: my $colsleft = $numinrow - $rem;
19208: if ($colsleft > 1) {
1.160.6.16 raeburn 19209: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 19210: } else {
1.160.6.16 raeburn 19211: $table .= '<td class="LC_left_item">';
1.125 raeburn 19212: }
19213: } else {
1.160.6.16 raeburn 19214: $table .= '<td class="LC_left_item">';
19215: }
19216: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
19217: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
19218: $table .= '<span class="LC_nobreak"><label>'.
19219: '<input type="'.$inputtype.'" name="'.$name.'"'.
19220: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
19221: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 19222: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 19223: }
1.160.6.33 raeburn 19224: $table .= '</label></span></td>';
1.125 raeburn 19225: }
1.160.6.16 raeburn 19226: $table .= '</tr></table>';
19227: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 19228: my ($dcname,$dcdom) = split(':',$domcoord[0]);
19229: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 19230: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 19231: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 19232: if ($user ne $dcname.':'.$dcdom) {
19233: $table .= ' ('.$dcname.':'.$dcdom.')';
19234: }
1.160.6.16 raeburn 19235: } else {
19236: my $check;
19237: if (exists($currhash{$domcoord[0]})) {
19238: $check = ' checked="checked"';
19239: }
1.160.6.50 raeburn 19240: $table = '<span class="LC_nobreak"><label>'.
19241: '<input type="checkbox" name="'.$name.'" '.
19242: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 19243: if ($user ne $dcname.':'.$dcdom) {
19244: $table .= ' ('.$dcname.':'.$dcdom.')';
19245: }
19246: $table .= '</label></span>';
1.160.6.16 raeburn 19247: $rows ++;
19248: }
1.125 raeburn 19249: }
1.160.6.16 raeburn 19250: return ($numdcs,$table,$rows);
1.125 raeburn 19251: }
19252:
1.137 raeburn 19253: sub usersession_titles {
19254: return &Apache::lonlocal::texthash(
19255: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
19256: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 19257: spares => 'Servers offloaded to, when busy',
1.137 raeburn 19258: version => 'LON-CAPA version requirement',
1.138 raeburn 19259: excludedomain => 'Allow all, but exclude specific domains',
19260: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 19261: primary => 'Primary (checked first)',
1.154 raeburn 19262: default => 'Default',
1.137 raeburn 19263: );
19264: }
19265:
1.152 raeburn 19266: sub id_for_thisdom {
19267: my (%servers) = @_;
19268: my %altids;
19269: foreach my $server (keys(%servers)) {
19270: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19271: if ($serverhome ne $server) {
19272: $altids{$serverhome} = $server;
19273: }
19274: }
19275: return %altids;
19276: }
19277:
1.150 raeburn 19278: sub count_servers {
19279: my ($currbalancer,%servers) = @_;
19280: my (@spares,$numspares);
19281: foreach my $lonhost (sort(keys(%servers))) {
19282: next if ($currbalancer eq $lonhost);
19283: push(@spares,$lonhost);
19284: }
19285: if ($currbalancer) {
19286: $numspares = scalar(@spares);
19287: } else {
19288: $numspares = scalar(@spares) - 1;
19289: }
19290: return ($numspares,@spares);
19291: }
19292:
19293: sub lonbalance_targets_js {
1.160.6.7 raeburn 19294: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 19295: my $select = &mt('Select');
19296: my ($alltargets,$allishome,$allinsttypes,@alltypes);
19297: if (ref($servers) eq 'HASH') {
19298: $alltargets = join("','",sort(keys(%{$servers})));
19299: my @homedoms;
19300: foreach my $server (sort(keys(%{$servers}))) {
19301: if (&Apache::lonnet::host_domain($server) eq $dom) {
19302: push(@homedoms,'1');
19303: } else {
19304: push(@homedoms,'0');
19305: }
19306: }
19307: $allishome = join("','",@homedoms);
19308: }
19309: if (ref($types) eq 'ARRAY') {
19310: if (@{$types} > 0) {
19311: @alltypes = @{$types};
19312: }
19313: }
19314: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
19315: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 19316: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 19317: if (ref($settings) eq 'HASH') {
19318: %existing = %{$settings};
19319: }
19320: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 19321: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 19322: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 19323: return <<"END";
19324:
19325: <script type="text/javascript">
19326: // <![CDATA[
19327:
1.160.6.7 raeburn 19328: currBalancers = new Array('$balancers');
19329:
19330: function toggleTargets(balnum) {
19331: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19332: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
19333: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
19334: var prevbalancer = prevhostitem.value;
19335: var baltotal = document.getElementById('loadbalancing_total').value;
19336: prevhostitem.value = balancer;
19337: if (prevbalancer != '') {
19338: var prevIdx = currBalancers.indexOf(prevbalancer);
19339: if (prevIdx != -1) {
19340: currBalancers.splice(prevIdx,1);
19341: }
19342: }
1.150 raeburn 19343: if (balancer == '') {
1.160.6.7 raeburn 19344: hideSpares(balnum);
1.150 raeburn 19345: } else {
1.160.6.7 raeburn 19346: var currIdx = currBalancers.indexOf(balancer);
19347: if (currIdx == -1) {
19348: currBalancers.push(balancer);
19349: }
1.150 raeburn 19350: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 19351: var ishomedom = homedoms[lonhostitem.selectedIndex];
19352: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 19353: }
1.160.6.7 raeburn 19354: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 19355: return;
19356: }
19357:
1.160.6.7 raeburn 19358: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 19359: var alltargets = new Array('$alltargets');
19360: var insttypes = new Array('$allinsttypes');
1.151 raeburn 19361: var offloadtypes = new Array('primary','default');
19362:
1.160.6.7 raeburn 19363: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
19364: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 19365:
1.151 raeburn 19366: for (var i=0; i<offloadtypes.length; i++) {
19367: var count = 0;
19368: for (var j=0; j<alltargets.length; j++) {
19369: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 19370: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
19371: item.value = alltargets[j];
19372: item.style.textAlign='left';
19373: item.style.textFace='normal';
19374: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
19375: if (currBalancers.indexOf(alltargets[j]) == -1) {
19376: item.disabled = '';
19377: } else {
19378: item.disabled = 'disabled';
19379: item.checked = false;
19380: }
1.151 raeburn 19381: count ++;
19382: }
1.150 raeburn 19383: }
19384: }
1.151 raeburn 19385: for (var k=0; k<insttypes.length; k++) {
19386: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 19387: if (ishomedom == 1) {
1.160.6.7 raeburn 19388: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19389: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19390: } else {
1.160.6.7 raeburn 19391: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19392: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 19393: }
19394: } else {
1.160.6.7 raeburn 19395: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
19396: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 19397: }
1.151 raeburn 19398: if ((insttypes[k] != '_LC_external') &&
19399: ((insttypes[k] != '_LC_internetdom') ||
19400: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 19401: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
19402: item.options.length = 0;
19403: item.options[0] = new Option("","",true,true);
19404: var idx = 0;
1.151 raeburn 19405: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 19406: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
19407: idx ++;
19408: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 19409: }
19410: }
19411: }
19412: }
19413: return;
19414: }
19415:
1.160.6.7 raeburn 19416: function hideSpares(balnum) {
1.150 raeburn 19417: var alltargets = new Array('$alltargets');
19418: var insttypes = new Array('$allinsttypes');
19419: var offloadtypes = new Array('primary','default');
19420:
1.160.6.7 raeburn 19421: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
19422: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 19423:
19424: var total = alltargets.length - 1;
19425: for (var i=0; i<offloadtypes; i++) {
19426: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 19427: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
19428: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
19429: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 19430: }
1.150 raeburn 19431: }
19432: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 19433: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
19434: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 19435: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 19436: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
19437: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 19438: }
19439: }
19440: return;
19441: }
19442:
1.160.6.7 raeburn 19443: function checkOffloads(item,balnum,type) {
1.150 raeburn 19444: var alltargets = new Array('$alltargets');
19445: var offloadtypes = new Array('primary','default');
19446: if (item.checked) {
19447: var total = alltargets.length - 1;
19448: var other;
19449: if (type == offloadtypes[0]) {
1.151 raeburn 19450: other = offloadtypes[1];
1.150 raeburn 19451: } else {
1.151 raeburn 19452: other = offloadtypes[0];
1.150 raeburn 19453: }
19454: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 19455: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 19456: if (server == item.value) {
1.160.6.7 raeburn 19457: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
19458: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 19459: }
19460: }
19461: }
19462: }
19463: return;
19464: }
19465:
1.160.6.7 raeburn 19466: function singleServerToggle(balnum,type) {
19467: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 19468: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 19469: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
19470: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19471:
19472: } else {
1.160.6.7 raeburn 19473: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
19474: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 19475: }
19476: return;
19477: }
19478:
1.160.6.7 raeburn 19479: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 19480: if (type == '_LC_external') {
1.160.6.26 raeburn 19481: return;
1.150 raeburn 19482: }
1.160.6.7 raeburn 19483: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 19484: for (var i=0; i<typesRules.length; i++) {
19485: if (formname.elements[typesRules[i]].checked) {
19486: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 19487: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
19488: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 19489: } else {
1.160.6.7 raeburn 19490: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
19491: }
19492: }
19493: }
19494: return;
19495: }
19496:
19497: function balancerDeleteChange(balnum) {
19498: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
19499: var baltotal = document.getElementById('loadbalancing_total').value;
19500: var addtarget;
19501: var removetarget;
19502: var action = 'delete';
19503: if (document.getElementById('loadbalancing_delete_'+balnum)) {
19504: var lonhost = hostitem.value;
19505: var currIdx = currBalancers.indexOf(lonhost);
19506: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
19507: if (currIdx != -1) {
19508: currBalancers.splice(currIdx,1);
19509: }
19510: addtarget = lonhost;
19511: } else {
19512: if (currIdx == -1) {
19513: currBalancers.push(lonhost);
19514: }
19515: removetarget = lonhost;
19516: action = 'undelete';
19517: }
19518: balancerChange(balnum,baltotal,action,addtarget,removetarget);
19519: }
19520: return;
19521: }
19522:
19523: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
19524: if (baltotal > 1) {
19525: var offloadtypes = new Array('primary','default');
19526: var alltargets = new Array('$alltargets');
19527: var insttypes = new Array('$allinsttypes');
19528: for (var i=0; i<baltotal; i++) {
19529: if (i != balnum) {
19530: for (var j=0; j<offloadtypes.length; j++) {
19531: var total = alltargets.length - 1;
19532: for (var k=0; k<total; k++) {
19533: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
19534: var server = serveritem.value;
19535: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19536: if (server == addtarget) {
19537: serveritem.disabled = '';
19538: }
19539: }
19540: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19541: if (server == removetarget) {
19542: serveritem.disabled = 'disabled';
19543: serveritem.checked = false;
19544: }
19545: }
19546: }
19547: }
19548: for (var j=0; j<insttypes.length; j++) {
19549: if (insttypes[j] != '_LC_external') {
19550: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
19551: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
19552: var currSel = singleserver.selectedIndex;
19553: var currVal = singleserver.options[currSel].value;
19554: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
19555: var numoptions = singleserver.options.length;
19556: var needsnew = 1;
19557: for (var k=0; k<numoptions; k++) {
19558: if (singleserver.options[k] == addtarget) {
19559: needsnew = 0;
19560: break;
19561: }
19562: }
19563: if (needsnew == 1) {
19564: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
19565: }
19566: }
19567: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
19568: singleserver.options.length = 0;
19569: if ((currVal) && (currVal != removetarget)) {
19570: singleserver.options[0] = new Option("","",false,false);
19571: } else {
19572: singleserver.options[0] = new Option("","",true,true);
19573: }
19574: var idx = 0;
19575: for (var m=0; m<alltargets.length; m++) {
19576: if (currBalancers.indexOf(alltargets[m]) == -1) {
19577: idx ++;
19578: if (currVal == alltargets[m]) {
19579: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
19580: } else {
19581: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
19582: }
19583: }
19584: }
19585: }
19586: }
19587: }
19588: }
1.150 raeburn 19589: }
19590: }
19591: }
19592: return;
19593: }
19594:
1.152 raeburn 19595: // ]]>
19596: </script>
19597:
19598: END
19599: }
19600:
19601: sub new_spares_js {
19602: my @sparestypes = ('primary','default');
19603: my $types = join("','",@sparestypes);
19604: my $select = &mt('Select');
19605: return <<"END";
19606:
19607: <script type="text/javascript">
19608: // <![CDATA[
19609:
19610: function updateNewSpares(formname,lonhost) {
19611: var types = new Array('$types');
19612: var include = new Array();
19613: var exclude = new Array();
19614: for (var i=0; i<types.length; i++) {
19615: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
19616: for (var j=0; j<spareboxes.length; j++) {
19617: if (formname.elements[spareboxes[j]].checked) {
19618: exclude.push(formname.elements[spareboxes[j]].value);
19619: } else {
19620: include.push(formname.elements[spareboxes[j]].value);
19621: }
19622: }
19623: }
19624: for (var i=0; i<types.length; i++) {
19625: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
19626: var selIdx = newSpare.selectedIndex;
19627: var currnew = newSpare.options[selIdx].value;
19628: var okSpares = new Array();
19629: for (var j=0; j<newSpare.options.length; j++) {
19630: var possible = newSpare.options[j].value;
19631: if (possible != '') {
19632: if (exclude.indexOf(possible) == -1) {
19633: okSpares.push(possible);
19634: } else {
19635: if (currnew == possible) {
19636: selIdx = 0;
19637: }
19638: }
19639: }
19640: }
19641: for (var k=0; k<include.length; k++) {
19642: if (okSpares.indexOf(include[k]) == -1) {
19643: okSpares.push(include[k]);
19644: }
19645: }
19646: okSpares.sort();
19647: newSpare.options.length = 0;
19648: if (selIdx == 0) {
19649: newSpare.options[0] = new Option("$select","",true,true);
19650: } else {
19651: newSpare.options[0] = new Option("$select","",false,false);
19652: }
19653: for (var m=0; m<okSpares.length; m++) {
19654: var idx = m+1;
19655: var selThis = 0;
19656: if (selIdx != 0) {
19657: if (okSpares[m] == currnew) {
19658: selThis = 1;
19659: }
19660: }
19661: if (selThis == 1) {
19662: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
19663: } else {
19664: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
19665: }
19666: }
19667: }
19668: return;
19669: }
19670:
19671: function checkNewSpares(lonhost,type) {
19672: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
19673: var chosen = newSpare.options[newSpare.selectedIndex].value;
19674: if (chosen != '') {
19675: var othertype;
19676: var othernewSpare;
19677: if (type == 'primary') {
19678: othernewSpare = document.getElementById('newspare_default_'+lonhost);
19679: }
19680: if (type == 'default') {
19681: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
19682: }
19683: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
19684: othernewSpare.selectedIndex = 0;
19685: }
19686: }
19687: return;
19688: }
19689:
19690: // ]]>
19691: </script>
19692:
19693: END
19694:
19695: }
19696:
19697: sub common_domprefs_js {
19698: return <<"END";
19699:
19700: <script type="text/javascript">
19701: // <![CDATA[
19702:
1.150 raeburn 19703: function getIndicesByName(formname,item) {
1.152 raeburn 19704: var group = new Array();
1.150 raeburn 19705: for (var i=0;i<formname.elements.length;i++) {
19706: if (formname.elements[i].name == item) {
1.152 raeburn 19707: group.push(formname.elements[i].id);
1.150 raeburn 19708: }
19709: }
1.152 raeburn 19710: return group;
1.150 raeburn 19711: }
19712:
19713: // ]]>
19714: </script>
19715:
19716: END
1.152 raeburn 19717:
1.150 raeburn 19718: }
19719:
1.160.6.5 raeburn 19720: sub recaptcha_js {
19721: my %lt = &captcha_phrases();
19722: return <<"END";
19723:
19724: <script type="text/javascript">
19725: // <![CDATA[
19726:
19727: function updateCaptcha(caller,context) {
19728: var privitem;
19729: var pubitem;
19730: var privtext;
19731: var pubtext;
1.160.6.69 raeburn 19732: var versionitem;
19733: var versiontext;
1.160.6.5 raeburn 19734: if (document.getElementById(context+'_recaptchapub')) {
19735: pubitem = document.getElementById(context+'_recaptchapub');
19736: } else {
19737: return;
19738: }
19739: if (document.getElementById(context+'_recaptchapriv')) {
19740: privitem = document.getElementById(context+'_recaptchapriv');
19741: } else {
19742: return;
19743: }
19744: if (document.getElementById(context+'_recaptchapubtxt')) {
19745: pubtext = document.getElementById(context+'_recaptchapubtxt');
19746: } else {
19747: return;
19748: }
19749: if (document.getElementById(context+'_recaptchaprivtxt')) {
19750: privtext = document.getElementById(context+'_recaptchaprivtxt');
19751: } else {
19752: return;
19753: }
1.160.6.69 raeburn 19754: if (document.getElementById(context+'_recaptchaversion')) {
19755: versionitem = document.getElementById(context+'_recaptchaversion');
19756: } else {
19757: return;
19758: }
19759: if (document.getElementById(context+'_recaptchavertxt')) {
19760: versiontext = document.getElementById(context+'_recaptchavertxt');
19761: } else {
19762: return;
19763: }
1.160.6.5 raeburn 19764: if (caller.checked) {
19765: if (caller.value == 'recaptcha') {
19766: pubitem.type = 'text';
19767: privitem.type = 'text';
19768: pubitem.size = '40';
19769: privitem.size = '40';
19770: pubtext.innerHTML = "$lt{'pub'}";
19771: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 19772: versionitem.type = 'text';
19773: versionitem.size = '3';
19774: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 19775: } else {
19776: pubitem.type = 'hidden';
19777: privitem.type = 'hidden';
1.160.6.69 raeburn 19778: versionitem.type = 'hidden';
1.160.6.5 raeburn 19779: pubtext.innerHTML = '';
19780: privtext.innerHTML = '';
1.160.6.69 raeburn 19781: versiontext.innerHTML = '';
1.160.6.5 raeburn 19782: }
19783: }
19784: return;
19785: }
19786:
19787: // ]]>
19788: </script>
19789:
19790: END
19791:
19792: }
19793:
1.160.6.40 raeburn 19794: sub toggle_display_js {
1.160.6.16 raeburn 19795: return <<"END";
19796:
19797: <script type="text/javascript">
19798: // <![CDATA[
19799:
1.160.6.40 raeburn 19800: function toggleDisplay(domForm,caller) {
19801: if (document.getElementById(caller)) {
19802: var divitem = document.getElementById(caller);
19803: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 19804: var checkval = 1;
19805: var dispval = 'block';
1.160.6.93 raeburn 19806: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 19807: if (caller == 'emailoptions') {
19808: optionsElement = domForm.cancreate_email;
19809: }
1.160.6.57 raeburn 19810: if (caller == 'studentsubmission') {
19811: optionsElement = domForm.postsubmit;
19812: }
1.160.6.64 raeburn 19813: if (caller == 'cloneinstcode') {
19814: optionsElement = domForm.canclone;
19815: checkval = 'instcode';
19816: }
1.160.6.93 raeburn 19817: if (selfcreateRegExp.test(caller)) {
19818: optionsElement = domForm.elements[caller];
19819: checkval = 'other';
19820: dispval = 'inline'
19821: }
1.160.6.40 raeburn 19822: if (optionsElement.length) {
1.160.6.16 raeburn 19823: var currval;
1.160.6.40 raeburn 19824: for (var i=0; i<optionsElement.length; i++) {
19825: if (optionsElement[i].checked) {
19826: currval = optionsElement[i].value;
1.160.6.16 raeburn 19827: }
19828: }
1.160.6.64 raeburn 19829: if (currval == checkval) {
19830: divitem.style.display = dispval;
1.160.6.16 raeburn 19831: } else {
1.160.6.40 raeburn 19832: divitem.style.display = 'none';
1.160.6.16 raeburn 19833: }
19834: }
19835: }
19836: return;
19837: }
19838:
19839: // ]]>
19840: </script>
19841:
19842: END
19843:
19844: }
19845:
1.160.6.5 raeburn 19846: sub captcha_phrases {
19847: return &Apache::lonlocal::texthash (
19848: priv => 'Private key',
19849: pub => 'Public key',
19850: original => 'original (CAPTCHA)',
19851: recaptcha => 'successor (ReCAPTCHA)',
19852: notused => 'unused',
1.160.6.69 raeburn 19853: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 19854: );
19855: }
19856:
1.160.6.24 raeburn 19857: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 19858: my ($dom,$cachekeys) = @_;
19859: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 19860: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19861: my %thismachine;
19862: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 19863:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 19864: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
19865: 'ipaccess');
19866: my %cache_by_lonhost;
19867: if (exists($cachekeys->{'samllanding'})) {
19868: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
19869: my %landing = %{$cachekeys->{'samllanding'}};
19870: my %domservers = &Apache::lonnet::get_servers($dom);
19871: if (keys(%domservers)) {
19872: foreach my $server (keys(%domservers)) {
19873: my @cached;
19874: next if ($thismachine{$server});
19875: if ($landing{$server}) {
19876: push(@cached,&escape('samllanding').':'.&escape($server));
19877: }
19878: if (@cached) {
19879: $cache_by_lonhost{$server} = \@cached;
19880: }
19881: }
19882: }
19883: }
19884: }
1.160.6.61 raeburn 19885: if (keys(%servers)) {
1.160.6.24 raeburn 19886: foreach my $server (keys(%servers)) {
19887: next if ($thismachine{$server});
1.160.6.27 raeburn 19888: my @cached;
19889: foreach my $name (@posscached) {
19890: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 19891: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
19892: if (ref($cachekeys->{$name}) eq 'HASH') {
19893: foreach my $key (keys(%{$cachekeys->{$name}})) {
19894: push(@cached,&escape($name).':'.&escape($key));
19895: }
19896: }
19897: } else {
19898: push(@cached,&escape($name).':'.&escape($dom));
19899: }
1.160.6.27 raeburn 19900: }
19901: }
1.160.6.113 raeburn 19902: if ((exists($cache_by_lonhost{$server})) &&
19903: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
19904: push(@cached,@{$cache_by_lonhost{$server}});
19905: }
1.160.6.27 raeburn 19906: if (@cached) {
19907: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
19908: }
1.160.6.24 raeburn 19909: }
19910: }
19911: return;
19912: }
19913:
1.3 raeburn 19914: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>