Annotation of loncom/interface/domainprefs.pm, revision 1.424
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.424 ! raeburn 4: # $Id: domainprefs.pm,v 1.423 2023/05/22 21:10:55 raeburn Exp $
1.2 albertel 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.286 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.297 raeburn 30: ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 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.210 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.163 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.197 raeburn 98: used by course owners to request creation of a course, and to display/store
1.223 bisitz 99: default quota sizes for Authoring Spaces.
1.101 raeburn 100:
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.325 raeburn 107: (official, unofficial, community, textbook, placement, and lti).
1.271 raeburn 108: In each case the radio buttons 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.232 raeburn 168: use Apache::lonuserutils();
1.235 raeburn 169: use Apache::loncoursequeueadmin();
1.419 raeburn 170: use Apache::courseprefs();
1.69 raeburn 171: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 172: use LONCAPA::Enrollment;
1.81 raeburn 173: use LONCAPA::lonauthcgi();
1.275 raeburn 174: use LONCAPA::SSL;
1.9 raeburn 175: use File::Copy;
1.43 raeburn 176: use Locale::Language;
1.62 raeburn 177: use DateTime::TimeZone;
1.68 raeburn 178: use DateTime::Locale;
1.267 raeburn 179: use Time::HiRes qw( sleep );
1.373 raeburn 180: use Net::CIDR;
1.424 ! raeburn 181: use Crypt::CBC;
1.1 raeburn 182:
1.155 raeburn 183: my $registered_cleanup;
184: my $modified_urls;
185:
1.1 raeburn 186: sub handler {
187: my $r=shift;
188: if ($r->header_only) {
189: &Apache::loncommon::content_type($r,'text/html');
190: $r->send_http_header;
191: return OK;
192: }
193:
1.91 raeburn 194: my $context = 'domain';
1.1 raeburn 195: my $dom = $env{'request.role.domain'};
1.5 albertel 196: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 197: if (&Apache::lonnet::allowed('mau',$dom)) {
198: &Apache::loncommon::content_type($r,'text/html');
199: $r->send_http_header;
200: } else {
201: $env{'user.error.msg'}=
202: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
203: return HTTP_NOT_ACCEPTABLE;
204: }
1.155 raeburn 205:
206: $registered_cleanup=0;
207: @{$modified_urls}=();
208:
1.1 raeburn 209: &Apache::lonhtmlcommon::clear_breadcrumbs();
210: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 211: ['phase','actions']);
1.30 raeburn 212: my $phase = 'pickactions';
1.3 raeburn 213: if ( exists($env{'form.phase'}) ) {
214: $phase = $env{'form.phase'};
215: }
1.150 raeburn 216: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 217: my %domconfig =
1.6 raeburn 218: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 219: 'quotas','autoenroll','autoupdate','autocreate',
220: 'directorysrch','usercreation','usermodification',
221: 'contacts','defaults','scantron','coursecategories',
222: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 223: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 224: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 225: 'ltitools','toolsec','ssl','trust','lti','ltisec',
226: 'privacy','passwords','proctoring','wafproxy','ipaccess'],$dom);
1.320 raeburn 227: my %encconfig =
1.405 raeburn 228: &Apache::lonnet::get_dom('encconfig',['ltitools','lti','proctoring','linkprot'],$dom,undef,1);
1.424 ! raeburn 229: my ($checked_is_home,$is_home);
1.297 raeburn 230: if (ref($domconfig{'ltitools'}) eq 'HASH') {
231: if (ref($encconfig{'ltitools'}) eq 'HASH') {
1.423 raeburn 232: my $home = &Apache::lonnet::domain($dom,'primary');
233: unless (($home eq 'no_host') || ($home eq '')) {
234: my @ids=&Apache::lonnet::current_machine_ids();
235: if (grep(/^\Q$home\E$/,@ids)) {
236: $is_home = 1;
237: }
238: }
1.424 ! raeburn 239: $checked_is_home = 1;
1.297 raeburn 240: foreach my $id (keys(%{$domconfig{'ltitools'}})) {
1.320 raeburn 241: if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
242: (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
1.421 raeburn 243: $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
1.423 raeburn 244: if (($is_home) && ($phase eq 'process')) {
245: $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
246: }
1.297 raeburn 247: }
248: }
249: }
250: }
1.320 raeburn 251: if (ref($domconfig{'lti'}) eq 'HASH') {
252: if (ref($encconfig{'lti'}) eq 'HASH') {
1.424 ! raeburn 253: unless ($checked_is_home) {
! 254: my $home = &Apache::lonnet::domain($dom,'primary');
! 255: unless (($home eq 'no_host') || ($home eq '')) {
! 256: my @ids=&Apache::lonnet::current_machine_ids();
! 257: if (grep(/^\Q$home\E$/,@ids)) {
! 258: $is_home = 1;
! 259: }
! 260: }
! 261: $checked_is_home = 1;
! 262: }
1.320 raeburn 263: foreach my $id (keys(%{$domconfig{'lti'}})) {
264: if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
265: (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
1.424 ! raeburn 266: $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
! 267: if (($is_home) && ($phase eq 'process')) {
! 268: $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1.320 raeburn 269: }
270: }
271: }
272: }
273: }
1.405 raeburn 274: if (ref($domconfig{'ltisec'}) eq 'HASH') {
1.406 raeburn 275: if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
1.405 raeburn 276: if (ref($encconfig{'linkprot'}) eq 'HASH') {
1.406 raeburn 277: foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
278: unless ($id =~ /^\d+$/) {
279: delete($domconfig{'ltisec'}{'linkprot'}{$id});
280: }
281: if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
1.405 raeburn 282: (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
283: foreach my $item ('key','secret') {
1.406 raeburn 284: $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
1.405 raeburn 285: }
286: }
287: }
288: }
289: }
290: }
1.372 raeburn 291: if (ref($domconfig{'proctoring'}) eq 'HASH') {
292: if (ref($encconfig{'proctoring'}) eq 'HASH') {
293: foreach my $provider (keys(%{$domconfig{'proctoring'}})) {
294: if ((ref($domconfig{'proctoring'}{$provider}) eq 'HASH') &&
295: (ref($encconfig{'proctoring'}{$provider}) eq 'HASH')) {
296: foreach my $item ('key','secret') {
297: $domconfig{'proctoring'}{$provider}{$item} = $encconfig{'proctoring'}{$provider}{$item};
298: }
299: }
300: }
301: }
302: }
1.394 raeburn 303: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
304: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
1.373 raeburn 305: 'contacts','privacy','usercreation','selfcreation',
1.374 raeburn 306: 'usermodification','scantron','requestcourses','requestauthor',
1.373 raeburn 307: 'coursecategories','serverstatuses','helpsettings','coursedefaults',
1.372 raeburn 308: 'ltitools','proctoring','selfenrollment','usersessions','ssl',
309: 'trust','lti');
1.171 raeburn 310: my %existing;
311: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
312: %existing = %{$domconfig{'loadbalancing'}};
313: }
314: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 315: push(@prefs_order,'loadbalancing');
316: }
1.30 raeburn 317: my %prefs = (
318: 'rolecolors' =>
319: { text => 'Default color schemes',
1.67 raeburn 320: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 321: header => [{col1 => 'Student Settings',
322: col2 => '',},
323: {col1 => 'Coordinator Settings',
324: col2 => '',},
325: {col1 => 'Author Settings',
326: col2 => '',},
327: {col1 => 'Administrator Settings',
328: col2 => '',}],
1.230 raeburn 329: print => \&print_rolecolors,
330: modify => \&modify_rolecolors,
1.30 raeburn 331: },
1.110 raeburn 332: 'login' =>
1.30 raeburn 333: { text => 'Log-in page options',
1.67 raeburn 334: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 335: header => [{col1 => 'Log-in Page Items',
336: col2 => '',},
337: {col1 => 'Log-in Help',
1.256 raeburn 338: col2 => 'Value'},
339: {col1 => 'Custom HTML in document head',
1.386 raeburn 340: col2 => 'Value'},
341: {col1 => 'SSO',
342: col2 => 'Dual login: SSO and non-SSO options'},
343: ],
1.230 raeburn 344: print => \&print_login,
345: modify => \&modify_login,
1.30 raeburn 346: },
1.43 raeburn 347: 'defaults' =>
1.236 raeburn 348: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 349: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 350: header => [{col1 => 'Setting',
1.236 raeburn 351: col2 => 'Value'},
352: {col1 => 'Institutional user types',
1.409 raeburn 353: col2 => 'Name displayed'},
354: {col1 => 'Mapping for missing usernames via standard log-in',
355: col2 => 'Rules in use'}],
1.230 raeburn 356: print => \&print_defaults,
357: modify => \&modify_defaults,
1.43 raeburn 358: },
1.381 raeburn 359: 'wafproxy' =>
360: { text => 'Web Application Firewall/Reverse Proxy',
1.373 raeburn 361: help => 'Domain_Configuration_WAF_Proxy',
1.381 raeburn 362: header => [{col1 => 'Domain(s)',
363: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
1.373 raeburn 364: },
1.381 raeburn 365: {col1 => 'Domain(s)',
366: col2 => 'WAF Configuration',}],
1.373 raeburn 367: print => \&print_wafproxy,
1.381 raeburn 368: modify => \&modify_wafproxy,
1.373 raeburn 369: },
1.354 raeburn 370: 'passwords' =>
371: { text => 'Passwords (Internal authentication)',
372: help => 'Domain_Configuration_Passwords',
373: header => [{col1 => 'Resetting Forgotten Password',
374: col2 => 'Settings'},
375: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
376: col2 => 'Settings'},
377: {col1 => 'Rules for LON-CAPA Passwords',
378: col2 => 'Settings'},
379: {col1 => 'Course Owner Changing Student Passwords',
380: col2 => 'Settings'}],
381: print => \&print_passwords,
382: modify => \&modify_passwords,
383: },
1.30 raeburn 384: 'quotas' =>
1.413 raeburn 385: { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.213 raeburn 389: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.230 raeburn 390: print => \&print_quotas,
391: modify => \&modify_quotas,
1.30 raeburn 392: },
393: 'autoenroll' =>
394: { text => 'Auto-enrollment settings',
1.67 raeburn 395: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 396: header => [{col1 => 'Configuration setting',
397: col2 => 'Value(s)'}],
1.230 raeburn 398: print => \&print_autoenroll,
399: modify => \&modify_autoenroll,
1.30 raeburn 400: },
401: 'autoupdate' =>
402: { text => 'Auto-update settings',
1.67 raeburn 403: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 404: header => [{col1 => 'Setting',
405: col2 => 'Value',},
1.131 raeburn 406: {col1 => 'Setting',
407: col2 => 'Affiliation'},
1.43 raeburn 408: {col1 => 'User population',
1.227 bisitz 409: col2 => 'Updatable user data'}],
1.230 raeburn 410: print => \&print_autoupdate,
411: modify => \&modify_autoupdate,
1.30 raeburn 412: },
1.125 raeburn 413: 'autocreate' =>
414: { text => 'Auto-course creation settings',
415: help => 'Domain_Configuration_Auto_Creation',
416: header => [{col1 => 'Configuration Setting',
417: col2 => 'Value',}],
1.230 raeburn 418: print => \&print_autocreate,
419: modify => \&modify_autocreate,
1.125 raeburn 420: },
1.30 raeburn 421: 'directorysrch' =>
1.277 raeburn 422: { text => 'Directory searches',
1.67 raeburn 423: help => 'Domain_Configuration_InstDirectory_Search',
1.277 raeburn 424: header => [{col1 => 'Institutional Directory Setting',
425: col2 => 'Value',},
426: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 427: col2 => 'Value',}],
1.230 raeburn 428: print => \&print_directorysrch,
429: modify => \&modify_directorysrch,
1.30 raeburn 430: },
431: 'contacts' =>
1.286 raeburn 432: { text => 'E-mail addresses and helpform',
1.67 raeburn 433: help => 'Domain_Configuration_Contact_Info',
1.286 raeburn 434: header => [{col1 => 'Default e-mail addresses',
435: col2 => 'Value',},
436: {col1 => 'Recipient(s) for notifications',
437: col2 => 'Value',},
1.340 raeburn 438: {col1 => 'Nightly status check e-mail',
439: col2 => 'Settings',},
1.286 raeburn 440: {col1 => 'Ask helpdesk form settings',
441: col2 => 'Value',},],
1.230 raeburn 442: print => \&print_contacts,
443: modify => \&modify_contacts,
1.30 raeburn 444: },
445: 'usercreation' =>
446: { text => 'User creation',
1.67 raeburn 447: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 448: header => [{col1 => 'Format rule type',
449: col2 => 'Format rules in force'},
1.34 raeburn 450: {col1 => 'User account creation',
451: col2 => 'Usernames which may be created',},
1.30 raeburn 452: {col1 => 'Context',
1.43 raeburn 453: col2 => 'Assignable authentication types'}],
1.230 raeburn 454: print => \&print_usercreation,
455: modify => \&modify_usercreation,
1.30 raeburn 456: },
1.224 raeburn 457: 'selfcreation' =>
458: { text => 'Users self-creating accounts',
459: help => 'Domain_Configuration_Self_Creation',
460: header => [{col1 => 'Self-creation with institutional username',
461: col2 => 'Enabled?'},
462: {col1 => 'Institutional user type (login/SSO self-creation)',
463: col2 => 'Information user can enter'},
1.303 raeburn 464: {col1 => 'Self-creation with e-mail verification',
1.224 raeburn 465: col2 => 'Settings'}],
1.230 raeburn 466: print => \&print_selfcreation,
467: modify => \&modify_selfcreation,
1.224 raeburn 468: },
1.69 raeburn 469: 'usermodification' =>
1.33 raeburn 470: { text => 'User modification',
1.67 raeburn 471: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 472: header => [{col1 => 'Target user has role',
1.227 bisitz 473: col2 => 'User information updatable in author context'},
1.33 raeburn 474: {col1 => 'Target user has role',
1.227 bisitz 475: col2 => 'User information updatable in course context'}],
1.230 raeburn 476: print => \&print_usermodification,
477: modify => \&modify_usermodification,
1.33 raeburn 478: },
1.69 raeburn 479: 'scantron' =>
1.346 raeburn 480: { text => 'Bubblesheet format',
1.67 raeburn 481: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 482: header => [ {col1 => 'Bubblesheet format file',
483: col2 => ''},
484: {col1 => 'Bubblesheet data upload formats',
485: col2 => 'Settings'}],
1.230 raeburn 486: print => \&print_scantron,
487: modify => \&modify_scantron,
1.46 raeburn 488: },
1.86 raeburn 489: 'requestcourses' =>
490: {text => 'Request creation of courses',
491: help => 'Domain_Configuration_Request_Courses',
492: header => [{col1 => 'User affiliation',
1.102 raeburn 493: col2 => 'Availability/Processing of requests',},
494: {col1 => 'Setting',
1.216 raeburn 495: col2 => 'Value'},
496: {col1 => 'Available textbooks',
1.235 raeburn 497: col2 => ''},
1.242 raeburn 498: {col1 => 'Available templates',
499: col2 => ''},
1.235 raeburn 500: {col1 => 'Validation (not official courses)',
501: col2 => 'Value'},],
1.230 raeburn 502: print => \&print_quotas,
503: modify => \&modify_quotas,
1.86 raeburn 504: },
1.163 raeburn 505: 'requestauthor' =>
1.223 bisitz 506: {text => 'Request Authoring Space',
1.163 raeburn 507: help => 'Domain_Configuration_Request_Author',
508: header => [{col1 => 'User affiliation',
509: col2 => 'Availability/Processing of requests',},
510: {col1 => 'Setting',
511: col2 => 'Value'}],
1.230 raeburn 512: print => \&print_quotas,
513: modify => \&modify_quotas,
1.163 raeburn 514: },
1.69 raeburn 515: 'coursecategories' =>
1.120 raeburn 516: { text => 'Cataloging of courses/communities',
1.67 raeburn 517: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 518: header => [{col1 => 'Catalog type/availability',
519: col2 => '',},
520: {col1 => 'Category settings for standard catalog',
1.57 raeburn 521: col2 => '',},
522: {col1 => 'Categories',
523: col2 => '',
524: }],
1.230 raeburn 525: print => \&print_coursecategories,
526: modify => \&modify_coursecategories,
1.69 raeburn 527: },
528: 'serverstatuses' =>
1.77 raeburn 529: {text => 'Access to server status pages',
1.69 raeburn 530: help => 'Domain_Configuration_Server_Status',
531: header => [{col1 => 'Status Page',
532: col2 => 'Other named users',
533: col3 => 'Specific IPs',
534: }],
1.230 raeburn 535: print => \&print_serverstatuses,
536: modify => \&modify_serverstatuses,
1.69 raeburn 537: },
1.118 jms 538: 'helpsettings' =>
1.282 raeburn 539: {text => 'Support settings',
1.118 jms 540: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 541: header => [{col1 => 'Help Page Settings (logged-in users)',
542: col2 => 'Value'},
543: {col1 => 'Helpdesk Roles',
544: col2 => 'Settings'},],
1.230 raeburn 545: print => \&print_helpsettings,
546: modify => \&modify_helpsettings,
1.118 jms 547: },
1.121 raeburn 548: 'coursedefaults' =>
549: {text => 'Course/Community defaults',
550: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 551: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
552: col2 => 'Value',},
553: {col1 => 'Defaults which can be overridden for each course by a DC',
554: col2 => 'Value',},],
1.230 raeburn 555: print => \&print_coursedefaults,
556: modify => \&modify_coursedefaults,
1.121 raeburn 557: },
1.231 raeburn 558: 'selfenrollment' =>
559: {text => 'Self-enrollment in Course/Community',
560: help => 'Domain_Configuration_Selfenrollment',
561: header => [{col1 => 'Configuration Rights',
562: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
563: {col1 => 'Defaults',
564: col2 => 'Value'},
565: {col1 => 'Self-enrollment validation (optional)',
566: col2 => 'Value'},],
567: print => \&print_selfenrollment,
568: modify => \&modify_selfenrollment,
569: },
1.120 raeburn 570: 'privacy' =>
1.357 raeburn 571: {text => 'Availability of User Information',
1.120 raeburn 572: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 573: header => [{col1 => 'Role assigned in different domain',
574: col2 => 'Approval options'},
575: {col1 => 'Role assigned in different domain to user of type',
576: col2 => 'User information available in that domain'},
577: {col1 => "Role assigned in user's domain",
578: col2 => 'Information viewable by privileged user'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 581: print => \&print_privacy,
582: modify => \&modify_privacy,
1.120 raeburn 583: },
1.141 raeburn 584: 'usersessions' =>
1.145 raeburn 585: {text => 'User session hosting/offloading',
1.137 raeburn 586: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 587: header => [{col1 => 'Domain server',
588: col2 => 'Servers to offload sessions to when busy'},
589: {col1 => 'Hosting of users from other domains',
1.137 raeburn 590: col2 => 'Rules'},
591: {col1 => "Hosting domain's own users elsewhere",
592: col2 => 'Rules'}],
1.230 raeburn 593: print => \&print_usersessions,
594: modify => \&modify_usersessions,
1.137 raeburn 595: },
1.279 raeburn 596: 'loadbalancing' =>
1.185 raeburn 597: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 598: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 599: header => [{col1 => 'Balancers',
1.150 raeburn 600: col2 => 'Default destinations',
1.183 bisitz 601: col3 => 'User affiliation',
1.150 raeburn 602: col4 => 'Overrides'},
603: ],
1.230 raeburn 604: print => \&print_loadbalancing,
605: modify => \&modify_loadbalancing,
1.150 raeburn 606: },
1.279 raeburn 607: 'ltitools' =>
1.267 raeburn 608: {text => 'External Tools (LTI)',
1.296 raeburn 609: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 610: header => [{col1 => 'Encryption of shared secrets',
611: col2 => 'Settings'},
612: {col1 => 'Rules for shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Providers',
615: col2 => 'Settings',}],
1.267 raeburn 616: print => \&print_ltitools,
617: modify => \&modify_ltitools,
618: },
1.372 raeburn 619: 'proctoring' =>
620: {text => 'Remote Proctoring Integration',
621: help => 'Domain_Configuration_Proctoring',
622: header => [{col1 => 'Name',
623: col2 => 'Configuration'}],
624: print => \&print_proctoring,
625: modify => \&modify_proctoring,
626: },
1.279 raeburn 627: 'ssl' =>
1.275 raeburn 628: {text => 'LON-CAPA Network (SSL)',
629: help => 'Domain_Configuration_Network_SSL',
630: header => [{col1 => 'Server',
631: col2 => 'Certificate Status'},
632: {col1 => 'Connections to other servers',
633: col2 => 'Rules'},
1.293 raeburn 634: {col1 => 'Connections from other servers',
635: col2 => 'Rules'},
1.275 raeburn 636: {col1 => "Replicating domain's published content",
637: col2 => 'Rules'}],
638: print => \&print_ssl,
639: modify => \&modify_ssl,
640: },
1.279 raeburn 641: 'trust' =>
642: {text => 'Trust Settings',
643: help => 'Domain_Configuration_Trust',
644: header => [{col1 => "Access to this domain's content by others",
645: col2 => 'Rules'},
646: {col1 => "Access to other domain's content by this domain",
647: col2 => 'Rules'},
648: {col1 => "Enrollment in this domain's courses by others",
649: col2 => 'Rules',},
650: {col1 => "Co-author roles in this domain for others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles for this domain's users elsewhere",
653: col2 => 'Rules',},
654: {col1 => "Domain roles in this domain assignable to others",
655: col2 => 'Rules'},
656: {col1 => "Course catalog for this domain displayed elsewhere",
657: col2 => 'Rules'},
658: {col1 => "Requests for creation of courses in this domain by others",
659: col2 => 'Rules'},
660: {col1 => "Users in other domains can send messages to this domain",
661: col2 => 'Rules'},],
662: print => \&print_trust,
663: modify => \&modify_trust,
664: },
1.320 raeburn 665: 'lti' =>
1.405 raeburn 666: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 667: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 668: header => [{col1 => 'Encryption of shared secrets',
669: col2 => 'Settings'},
670: {col1 => 'Rules for shared secrets',
671: col2 => 'Settings'},
1.406 raeburn 672: {col1 => 'Link Protectors',
1.405 raeburn 673: col2 => 'Settings'},
674: {col1 => 'Consumers',
675: col2 => 'Settings'},],
1.320 raeburn 676: print => \&print_lti,
677: modify => \&modify_lti,
678: },
1.394 raeburn 679: 'ipaccess' =>
680: {text => 'IP-based access control',
681: help => 'Domain_Configuration_IP_Access',
682: header => [{col1 => 'Setting',
683: col2 => 'Value'},],
684: print => \&print_ipaccess,
685: modify => \&modify_ipaccess,
686: },
1.3 raeburn 687: );
1.110 raeburn 688: if (keys(%servers) > 1) {
689: $prefs{'login'} = { text => 'Log-in page options',
690: help => 'Domain_Configuration_Login_Page',
691: header => [{col1 => 'Log-in Service',
692: col2 => 'Server Setting',},
693: {col1 => 'Log-in Page Items',
1.405 raeburn 694: col2 => 'Settings'},
1.168 raeburn 695: {col1 => 'Log-in Help',
1.256 raeburn 696: col2 => 'Value'},
697: {col1 => 'Custom HTML in document head',
1.386 raeburn 698: col2 => 'Value'},
699: {col1 => 'SSO',
700: col2 => 'Dual login: SSO and non-SSO options'},
701: ],
1.230 raeburn 702: print => \&print_login,
703: modify => \&modify_login,
1.110 raeburn 704: };
705: }
1.174 foxr 706:
1.6 raeburn 707: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 708: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 709: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 710: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 711: text=>"Settings to display/modify"});
1.9 raeburn 712: my $confname = $dom.'-domainconfig';
1.174 foxr 713:
1.3 raeburn 714: if ($phase eq 'process') {
1.212 raeburn 715: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
716: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 717: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 718: $r->rflush();
1.212 raeburn 719: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 720: }
1.30 raeburn 721: } elsif ($phase eq 'display') {
1.192 raeburn 722: my $js = &recaptcha_js().
1.236 raeburn 723: &toggle_display_js();
1.171 raeburn 724: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 725: my ($othertitle,$usertypes,$types) =
726: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 727: $js .= &lonbalance_targets_js($dom,$types,\%servers,
728: $domconfig{'loadbalancing'}).
1.170 raeburn 729: &new_spares_js().
730: &common_domprefs_js().
731: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 732: }
1.216 raeburn 733: if (grep(/^requestcourses$/,@actions)) {
734: my $javascript_validations;
735: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
736: $js .= <<END;
737: <script type="text/javascript">
738: $javascript_validations
739: </script>
740: $coursebrowserjs
741: END
1.394 raeburn 742: } elsif (grep(/^ipaccess$/,@actions)) {
743: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 744: }
1.305 raeburn 745: if (grep(/^selfcreation$/,@actions)) {
746: $js .= &selfcreate_javascript();
747: }
1.286 raeburn 748: if (grep(/^contacts$/,@actions)) {
749: $js .= &contacts_javascript();
750: }
1.346 raeburn 751: if (grep(/^scantron$/,@actions)) {
752: $js .= &scantron_javascript();
753: }
1.150 raeburn 754: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 755: } else {
1.180 raeburn 756: # check if domconfig user exists for the domain.
757: my $servadm = $r->dir_config('lonAdmEMail');
758: my ($configuserok,$author_ok,$switchserver) =
759: &config_check($dom,$confname,$servadm);
760: unless ($configuserok eq 'ok') {
1.181 raeburn 761: &Apache::lonconfigsettings::print_header($r,$phase,$context);
762: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 763: $confname).
1.181 raeburn 764: '<br />'
765: );
1.180 raeburn 766: if ($switchserver) {
1.181 raeburn 767: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
768: '<br />'.
769: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
770: '<br />'.
771: &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).
772: '<br />'.
773: &mt('To do that now, use the following link: [_1]',$switchserver)
774: );
775: } else {
776: $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.').
777: '<br />'.
778: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
779: );
1.180 raeburn 780: }
781: $r->print(&Apache::loncommon::end_page());
782: return OK;
783: }
1.21 raeburn 784: if (keys(%domconfig) == 0) {
785: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 786: my @ids=&Apache::lonnet::current_machine_ids();
787: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 788: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 789: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 790: my $custom_img_count = 0;
791: foreach my $img (@loginimages) {
792: if ($designhash{$dom.'.login.'.$img} ne '') {
793: $custom_img_count ++;
794: }
795: }
796: foreach my $role (@roles) {
797: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
798: $custom_img_count ++;
799: }
800: }
801: if ($custom_img_count > 0) {
1.94 raeburn 802: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 803: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 804: $r->print(
805: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
806: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
807: &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 />'.
808: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
809: if ($switch_server) {
1.30 raeburn 810: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 811: }
1.91 raeburn 812: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 813: return OK;
814: }
815: }
816: }
1.91 raeburn 817: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 818: }
819: return OK;
820: }
821:
822: sub process_changes {
1.205 raeburn 823: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 824: my %domconfig;
825: if (ref($values) eq 'HASH') {
826: %domconfig = %{$values};
827: }
1.3 raeburn 828: my $output;
829: if ($action eq 'login') {
1.205 raeburn 830: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 831: } elsif ($action eq 'rolecolors') {
1.9 raeburn 832: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 833: $lastactref,%domconfig);
1.3 raeburn 834: } elsif ($action eq 'quotas') {
1.216 raeburn 835: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 836: } elsif ($action eq 'autoenroll') {
1.205 raeburn 837: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 838: } elsif ($action eq 'autoupdate') {
839: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 840: } elsif ($action eq 'autocreate') {
841: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 842: } elsif ($action eq 'directorysrch') {
1.295 raeburn 843: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 844: } elsif ($action eq 'usercreation') {
1.28 raeburn 845: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 846: } elsif ($action eq 'selfcreation') {
1.305 raeburn 847: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 848: } elsif ($action eq 'usermodification') {
849: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 850: } elsif ($action eq 'contacts') {
1.205 raeburn 851: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 852: } elsif ($action eq 'defaults') {
1.212 raeburn 853: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 854: } elsif ($action eq 'scantron') {
1.205 raeburn 855: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 856: } elsif ($action eq 'coursecategories') {
1.239 raeburn 857: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 858: } elsif ($action eq 'serverstatuses') {
859: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 860: } elsif ($action eq 'requestcourses') {
1.216 raeburn 861: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 862: } elsif ($action eq 'requestauthor') {
1.216 raeburn 863: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 864: } elsif ($action eq 'helpsettings') {
1.285 raeburn 865: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 866: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 867: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 868: } elsif ($action eq 'selfenrollment') {
869: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 870: } elsif ($action eq 'usersessions') {
1.212 raeburn 871: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 872: } elsif ($action eq 'loadbalancing') {
873: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 874: } elsif ($action eq 'ltitools') {
875: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 876: } elsif ($action eq 'proctoring') {
877: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 878: } elsif ($action eq 'ssl') {
879: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 880: } elsif ($action eq 'trust') {
881: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 882: } elsif ($action eq 'lti') {
883: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 884: } elsif ($action eq 'privacy') {
885: $output = &modify_privacy($dom,%domconfig);
1.354 raeburn 886: } elsif ($action eq 'passwords') {
887: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 888: } elsif ($action eq 'wafproxy') {
889: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 890: } elsif ($action eq 'ipaccess') {
891: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 892: }
893: return $output;
894: }
895:
896: sub print_config_box {
1.9 raeburn 897: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 898: my $rowtotal = 0;
1.49 raeburn 899: my $output;
900: if ($action eq 'coursecategories') {
901: $output = &coursecategories_javascript($settings);
1.236 raeburn 902: } elsif ($action eq 'defaults') {
903: $output = &defaults_javascript($settings);
1.354 raeburn 904: } elsif ($action eq 'passwords') {
1.405 raeburn 905: $output = &passwords_javascript($action);
1.282 raeburn 906: } elsif ($action eq 'helpsettings') {
907: my (%privs,%levelscurrent);
908: my %full=();
909: my %levels=(
910: course => {},
911: domain => {},
912: system => {},
913: );
914: my $context = 'domain';
915: my $crstype = 'Course';
916: my $formname = 'display';
917: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
918: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
919: $output =
920: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
921: \@templateroles);
1.334 raeburn 922: } elsif ($action eq 'ltitools') {
1.421 raeburn 923: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 924: } elsif ($action eq 'lti') {
1.421 raeburn 925: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 926: <i_javascript($dom,$settings);
1.372 raeburn 927: } elsif ($action eq 'proctoring') {
928: $output .= &proctoring_javascript($settings);
1.381 raeburn 929: } elsif ($action eq 'wafproxy') {
930: $output .= &wafproxy_javascript($dom);
1.385 raeburn 931: } elsif ($action eq 'autoupdate') {
932: $output .= &autoupdate_javascript();
1.399 raeburn 933: } elsif ($action eq 'autoenroll') {
934: $output .= &autoenroll_javascript();
1.386 raeburn 935: } elsif ($action eq 'login') {
936: $output .= &saml_javascript();
1.394 raeburn 937: } elsif ($action eq 'ipaccess') {
938: $output .= &ipaccess_javascript($settings);
1.91 raeburn 939: }
1.236 raeburn 940: $output .=
1.30 raeburn 941: '<table class="LC_nested_outer">
1.3 raeburn 942: <tr>
1.306 raeburn 943: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 944: &mt($item->{text}).' '.
945: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
946: '</tr>';
1.30 raeburn 947: $rowtotal ++;
1.110 raeburn 948: my $numheaders = 1;
949: if (ref($item->{'header'}) eq 'ARRAY') {
950: $numheaders = scalar(@{$item->{'header'}});
951: }
952: if ($numheaders > 1) {
1.64 raeburn 953: my $colspan = '';
1.145 raeburn 954: my $rightcolspan = '';
1.369 raeburn 955: my $leftnobr = '';
1.238 raeburn 956: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 957: ($action eq 'directorysrch') ||
1.386 raeburn 958: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 959: $colspan = ' colspan="2"';
960: }
1.145 raeburn 961: if ($action eq 'usersessions') {
962: $rightcolspan = ' colspan="3"';
963: }
1.369 raeburn 964: if ($action eq 'passwords') {
965: $leftnobr = ' LC_nobreak';
966: }
1.30 raeburn 967: $output .= '
1.3 raeburn 968: <tr>
969: <td>
970: <table class="LC_nested">
971: <tr class="LC_info_row">
1.369 raeburn 972: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 973: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 974: </tr>';
1.69 raeburn 975: $rowtotal ++;
1.230 raeburn 976: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 977: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 978: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 979: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 980: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
981: ($action eq 'lti') || ($action eq 'ltitools')) {
1.230 raeburn 982: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 983: } elsif ($action eq 'passwords') {
984: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 985: } elsif ($action eq 'coursecategories') {
1.230 raeburn 986: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 987: } elsif ($action eq 'scantron') {
988: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 989: } elsif ($action eq 'login') {
1.386 raeburn 990: if ($numheaders == 5) {
1.168 raeburn 991: $colspan = ' colspan="2"';
992: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
993: } else {
994: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
995: }
1.230 raeburn 996: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 997: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 998: } elsif ($action eq 'rolecolors') {
1.30 raeburn 999: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1000: }
1.30 raeburn 1001: $output .= '
1.6 raeburn 1002: </table>
1003: </td>
1004: </tr>
1005: <tr>
1006: <td>
1007: <table class="LC_nested">
1008: <tr class="LC_info_row">
1.230 raeburn 1009: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1010: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1011: </tr>';
1012: $rowtotal ++;
1.230 raeburn 1013: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1014: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1015: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1016: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1017: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1018: ($action eq 'ltitools')) {
1.238 raeburn 1019: if ($action eq 'coursecategories') {
1020: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1021: $colspan = ' colspan="2"';
1.279 raeburn 1022: } elsif ($action eq 'trust') {
1023: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1024: } elsif ($action eq 'passwords') {
1025: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.238 raeburn 1026: } else {
1027: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1028: }
1.279 raeburn 1029: if ($action eq 'trust') {
1030: $output .= '
1031: </table>
1032: </td>
1033: </tr>';
1034: my @trusthdrs = qw(2 3 4 5 6 7);
1035: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1036: for (my $i=0; $i<@trusthdrs; $i++) {
1037: $output .= '
1038: <tr>
1039: <td>
1040: <table class="LC_nested">
1041: <tr class="LC_info_row">
1042: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1043: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1044: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1045: </table>
1046: </td>
1047: </tr>';
1048: }
1049: $output .= '
1050: <tr>
1051: <td>
1052: <table class="LC_nested">
1053: <tr class="LC_info_row">
1054: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1055: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1056: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1057: } else {
1058: $output .= '
1.63 raeburn 1059: </table>
1060: </td>
1061: </tr>
1062: <tr>
1063: <td>
1064: <table class="LC_nested">
1065: <tr class="LC_info_row">
1066: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.224 raeburn 1067: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.238 raeburn 1068: </tr>'."\n";
1.279 raeburn 1069: if ($action eq 'coursecategories') {
1070: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1071: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1072: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1073: if ($action eq 'passwords') {
1074: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1075: } else {
1076: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1077: }
1078: $output .= '
1.340 raeburn 1079: </tr>
1080: </table>
1081: </td>
1082: </tr>
1083: <tr>
1084: <td>
1085: <table class="LC_nested">
1086: <tr class="LC_info_row">
1.369 raeburn 1087: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.354 raeburn 1088: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1089: if ($action eq 'passwords') {
1090: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1091: } else {
1092: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1093: }
1094: $output .= '
1.340 raeburn 1095: </table>
1096: </td>
1097: </tr>
1098: <tr>';
1.279 raeburn 1099: } else {
1100: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1101: }
1.238 raeburn 1102: }
1.63 raeburn 1103: $rowtotal ++;
1.236 raeburn 1104: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1105: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1106: ($action eq 'wafproxy')) {
1.230 raeburn 1107: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1108: } elsif ($action eq 'scantron') {
1109: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1110: } elsif ($action eq 'ssl') {
1111: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1112: </table>
1113: </td>
1114: </tr>
1115: <tr>
1116: <td>
1117: <table class="LC_nested">
1118: <tr class="LC_info_row">
1119: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1120: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1121: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1122: </table>
1123: </td>
1124: </tr>
1125: <tr>
1126: <td>
1127: <table class="LC_nested">
1128: <tr class="LC_info_row">
1129: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1130: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1131: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1132: } elsif ($action eq 'login') {
1.386 raeburn 1133: if ($numheaders == 5) {
1.168 raeburn 1134: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1135: </table>
1136: </td>
1137: </tr>
1138: <tr>
1139: <td>
1140: <table class="LC_nested">
1141: <tr class="LC_info_row">
1142: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1143: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1144: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1145: $rowtotal ++;
1146: } else {
1147: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1148: }
1.256 raeburn 1149: $output .= '
1150: </table>
1151: </td>
1152: </tr>
1153: <tr>
1154: <td>
1155: <table class="LC_nested">
1156: <tr class="LC_info_row">';
1.386 raeburn 1157: if ($numheaders == 5) {
1.256 raeburn 1158: $output .= '
1159: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1160: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1161: </tr>';
1162: } else {
1163: $output .= '
1164: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1165: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1166: </tr>';
1167: }
1168: $rowtotal ++;
1.386 raeburn 1169: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1170: </table>
1171: </td>
1172: </tr>
1173: <tr>
1174: <td>
1175: <table class="LC_nested">
1176: <tr class="LC_info_row">';
1177: if ($numheaders == 5) {
1178: $output .= '
1179: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1180: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1181: </tr>';
1182: } else {
1183: $output .= '
1184: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1185: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1186: </tr>';
1187: }
1188: $rowtotal ++;
1189: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1190: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1191: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1192: $rowtotal ++;
1193: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1194: </table>
1195: </td>
1196: </tr>
1197: <tr>
1198: <td>
1199: <table class="LC_nested">
1200: <tr class="LC_info_row">
1201: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1202: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1203: &textbookcourses_javascript($settings).
1204: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1205: </table>
1206: </td>
1207: </tr>
1208: <tr>
1209: <td>
1210: <table class="LC_nested">
1211: <tr class="LC_info_row">
1212: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1213: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1214: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1215: </table>
1216: </td>
1217: </tr>
1218: <tr>
1219: <td>
1220: <table class="LC_nested">
1221: <tr class="LC_info_row">
1.306 raeburn 1222: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1223: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1224: </tr>'.
1225: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1226: } elsif ($action eq 'requestauthor') {
1227: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1228: $rowtotal ++;
1.122 jms 1229: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1230: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1231: </table>
1232: </td>
1233: </tr>
1234: <tr>
1235: <td>
1236: <table class="LC_nested">
1237: <tr class="LC_info_row">
1.306 raeburn 1238: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1239: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1240: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1241: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1242: </tr>'.
1.30 raeburn 1243: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1244: </table>
1245: </td>
1246: </tr>
1247: <tr>
1248: <td>
1249: <table class="LC_nested">
1250: <tr class="LC_info_row">
1.59 bisitz 1251: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1252: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1253: </tr>'.
1.30 raeburn 1254: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1255: $rowtotal += 2;
1.6 raeburn 1256: }
1.3 raeburn 1257: } else {
1.30 raeburn 1258: $output .= '
1.3 raeburn 1259: <tr>
1260: <td>
1261: <table class="LC_nested">
1.30 raeburn 1262: <tr class="LC_info_row">';
1.277 raeburn 1263: if ($action eq 'login') {
1.30 raeburn 1264: $output .= '
1.59 bisitz 1265: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1266: } elsif ($action eq 'serverstatuses') {
1267: $output .= '
1.306 raeburn 1268: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1269: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1270:
1.6 raeburn 1271: } else {
1.30 raeburn 1272: $output .= '
1.306 raeburn 1273: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1274: }
1.72 raeburn 1275: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1276: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1277: &mt($item->{'header'}->[0]->{'col2'});
1278: if ($action eq 'serverstatuses') {
1279: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1280: }
1.69 raeburn 1281: } else {
1.306 raeburn 1282: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1283: &mt($item->{'header'}->[0]->{'col2'});
1284: }
1285: $output .= '</td>';
1286: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1287: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1288: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1289: &mt($item->{'header'}->[0]->{'col3'});
1290: } else {
1.306 raeburn 1291: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1292: &mt($item->{'header'}->[0]->{'col3'});
1293: }
1.69 raeburn 1294: if ($action eq 'serverstatuses') {
1295: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1296: }
1297: $output .= '</td>';
1.6 raeburn 1298: }
1.150 raeburn 1299: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1300: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1301: &mt($item->{'header'}->[0]->{'col4'});
1302: }
1.69 raeburn 1303: $output .= '</tr>';
1.48 raeburn 1304: $rowtotal ++;
1.168 raeburn 1305: if ($action eq 'quotas') {
1.86 raeburn 1306: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1307: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1308: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1309: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1310: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1311: }
1.3 raeburn 1312: }
1.30 raeburn 1313: $output .= '
1.3 raeburn 1314: </table>
1315: </td>
1316: </tr>
1.30 raeburn 1317: </table><br />';
1318: return ($output,$rowtotal);
1.1 raeburn 1319: }
1320:
1.3 raeburn 1321: sub print_login {
1.168 raeburn 1322: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1323: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1324: my %choices = &login_choices();
1.386 raeburn 1325: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1326: %lt = &login_file_options();
1327: $switchserver = &check_switchserver($dom,$confname);
1328: }
1.168 raeburn 1329: if ($caller eq 'service') {
1.149 raeburn 1330: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1331: my $choice = $choices{'disallowlogin'};
1332: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1333: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1334: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1335: '<th>'.$choices{'server'}.'</th>'.
1336: '<th>'.$choices{'serverpath'}.'</th>'.
1337: '<th>'.$choices{'custompath'}.'</th>'.
1338: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1339: my %disallowed;
1340: if (ref($settings) eq 'HASH') {
1341: if (ref($settings->{'loginvia'}) eq 'HASH') {
1342: %disallowed = %{$settings->{'loginvia'}};
1343: }
1344: }
1345: foreach my $lonhost (sort(keys(%servers))) {
1346: my $direct = 'selected="selected"';
1.128 raeburn 1347: if (ref($disallowed{$lonhost}) eq 'HASH') {
1348: if ($disallowed{$lonhost}{'server'} ne '') {
1349: $direct = '';
1350: }
1.110 raeburn 1351: }
1.115 raeburn 1352: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1353: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1354: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1355: '</option>';
1.184 raeburn 1356: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1357: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1358: my $selected = '';
1.128 raeburn 1359: if (ref($disallowed{$lonhost}) eq 'HASH') {
1360: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1361: $selected = 'selected="selected"';
1362: }
1.110 raeburn 1363: }
1364: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1365: $servers{$hostid}.'</option>';
1366: }
1.128 raeburn 1367: $datatable .= '</select></td>'.
1368: '<td><select name="'.$lonhost.'_serverpath">';
1369: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1370: my $pathname = $path;
1371: if ($path eq 'custom') {
1372: $pathname = &mt('Custom Path').' ->';
1373: }
1374: my $selected = '';
1375: if (ref($disallowed{$lonhost}) eq 'HASH') {
1376: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1377: $selected = 'selected="selected"';
1378: }
1379: } elsif ($path eq '') {
1380: $selected = 'selected="selected"';
1381: }
1382: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1383: }
1384: $datatable .= '</select></td>';
1385: my ($custom,$exempt);
1386: if (ref($disallowed{$lonhost}) eq 'HASH') {
1387: $custom = $disallowed{$lonhost}{'custompath'};
1388: $exempt = $disallowed{$lonhost}{'exempt'};
1389: }
1390: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1391: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1392: '</tr>';
1.110 raeburn 1393: }
1394: $datatable .= '</table></td></tr>';
1395: return $datatable;
1.168 raeburn 1396: } elsif ($caller eq 'page') {
1397: my %defaultchecked = (
1398: 'coursecatalog' => 'on',
1.188 raeburn 1399: 'helpdesk' => 'on',
1.168 raeburn 1400: 'adminmail' => 'off',
1401: 'newuser' => 'off',
1402: );
1.188 raeburn 1403: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1404: my (%checkedon,%checkedoff);
1.42 raeburn 1405: foreach my $item (@toggles) {
1.168 raeburn 1406: if ($defaultchecked{$item} eq 'on') {
1407: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1408: $checkedoff{$item} = ' ';
1.168 raeburn 1409: } elsif ($defaultchecked{$item} eq 'off') {
1410: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1411: $checkedon{$item} = ' ';
1412: }
1.1 raeburn 1413: }
1.168 raeburn 1414: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1415: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1416: my @logintext = ('textcol','bgcol');
1417: my @bgs = ('pgbg','mainbg','sidebg');
1418: my @links = ('link','alink','vlink');
1419: my %designhash = &Apache::loncommon::get_domainconf($dom);
1420: my %defaultdesign = %Apache::loncommon::defaultdesign;
1421: my (%is_custom,%designs);
1422: my %defaults = (
1423: font => $defaultdesign{'login.font'},
1424: );
1.6 raeburn 1425: foreach my $item (@images) {
1.168 raeburn 1426: $defaults{$item} = $defaultdesign{'login.'.$item};
1427: $defaults{'showlogo'}{$item} = 1;
1428: }
1429: foreach my $item (@bgs) {
1430: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1431: }
1.41 raeburn 1432: foreach my $item (@logintext) {
1.168 raeburn 1433: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1434: }
1.168 raeburn 1435: foreach my $item (@links) {
1436: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1437: }
1.168 raeburn 1438: if (ref($settings) eq 'HASH') {
1439: foreach my $item (@toggles) {
1440: if ($settings->{$item} eq '1') {
1441: $checkedon{$item} = ' checked="checked" ';
1442: $checkedoff{$item} = ' ';
1443: } elsif ($settings->{$item} eq '0') {
1444: $checkedoff{$item} = ' checked="checked" ';
1445: $checkedon{$item} = ' ';
1446: }
1447: }
1448: foreach my $item (@images) {
1449: if (defined($settings->{$item})) {
1450: $designs{$item} = $settings->{$item};
1451: $is_custom{$item} = 1;
1452: }
1453: if (defined($settings->{'showlogo'}{$item})) {
1454: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1455: }
1456: }
1.402 raeburn 1457: foreach my $item (@alttext) {
1458: if (ref($settings->{'alttext'}) eq 'HASH') {
1459: if ($settings->{'alttext'}->{$item} ne '') {
1460: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1461: }
1462: }
1463: }
1.168 raeburn 1464: foreach my $item (@logintext) {
1465: if ($settings->{$item} ne '') {
1466: $designs{'logintext'}{$item} = $settings->{$item};
1467: $is_custom{$item} = 1;
1468: }
1469: }
1470: if ($settings->{'font'} ne '') {
1471: $designs{'font'} = $settings->{'font'};
1472: $is_custom{'font'} = 1;
1473: }
1474: foreach my $item (@bgs) {
1475: if ($settings->{$item} ne '') {
1476: $designs{'bgs'}{$item} = $settings->{$item};
1477: $is_custom{$item} = 1;
1478: }
1479: }
1480: foreach my $item (@links) {
1481: if ($settings->{$item} ne '') {
1482: $designs{'links'}{$item} = $settings->{$item};
1483: $is_custom{$item} = 1;
1484: }
1485: }
1486: } else {
1487: if ($designhash{$dom.'.login.font'} ne '') {
1488: $designs{'font'} = $designhash{$dom.'.login.font'};
1489: $is_custom{'font'} = 1;
1490: }
1491: foreach my $item (@images) {
1492: if ($designhash{$dom.'.login.'.$item} ne '') {
1493: $designs{$item} = $designhash{$dom.'.login.'.$item};
1494: $is_custom{$item} = 1;
1495: }
1496: }
1497: foreach my $item (@bgs) {
1498: if ($designhash{$dom.'.login.'.$item} ne '') {
1499: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1500: $is_custom{$item} = 1;
1501: }
1.6 raeburn 1502: }
1.168 raeburn 1503: foreach my $item (@links) {
1504: if ($designhash{$dom.'.login.'.$item} ne '') {
1505: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1506: $is_custom{$item} = 1;
1507: }
1.6 raeburn 1508: }
1509: }
1.168 raeburn 1510: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1511: logo => 'Institution Logo',
1512: domlogo => 'Domain Logo',
1513: login => 'Login box');
1514: my $itemcount = 1;
1515: foreach my $item (@toggles) {
1516: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1517: $datatable .=
1518: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1519: '</td><td>'.
1520: '<span class="LC_nobreak"><label><input type="radio" name="'.
1521: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1522: '</label> <label><input type="radio" name="'.$item.'"'.
1523: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1524: '</tr>';
1525: $itemcount ++;
1.6 raeburn 1526: }
1.168 raeburn 1527: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1528: $datatable .= '</tr></table></td></tr>';
1529: } elsif ($caller eq 'help') {
1.386 raeburn 1530: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1531: my $itemcount = 1;
1532: $defaulturl = '/adm/loginproblems.html';
1533: $defaulttype = 'default';
1534: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1535: my @currlangs;
1536: if (ref($settings) eq 'HASH') {
1537: if (ref($settings->{'helpurl'}) eq 'HASH') {
1538: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1539: next if ($settings->{'helpurl'}{$key} eq '');
1540: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1541: $type{$key} = 'custom';
1542: unless ($key eq 'nolang') {
1543: push(@currlangs,$key);
1544: }
1545: }
1546: } elsif ($settings->{'helpurl'} ne '') {
1547: $type{'nolang'} = 'custom';
1548: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1549: }
1550: }
1.168 raeburn 1551: foreach my $lang ('nolang',sort(@currlangs)) {
1552: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1553: $datatable .= '<tr'.$css_class.'>';
1554: if ($url{$lang} eq '') {
1555: $url{$lang} = $defaulturl;
1556: }
1557: if ($type{$lang} eq '') {
1558: $type{$lang} = $defaulttype;
1559: }
1560: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1561: if ($lang eq 'nolang') {
1562: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1563: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1564: } else {
1565: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1566: $langchoices{$lang},
1567: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1568: }
1569: $datatable .= '</span></td>'."\n".
1570: '<td class="LC_left_item">';
1571: if ($type{$lang} eq 'custom') {
1572: $datatable .= '<span class="LC_nobreak"><label>'.
1573: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1574: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1575: } else {
1576: $datatable .= $lt{'upl'};
1577: }
1578: $datatable .='<br />';
1579: if ($switchserver) {
1580: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1581: } else {
1582: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1583: }
1.168 raeburn 1584: $datatable .= '</td></tr>';
1585: $itemcount ++;
1.6 raeburn 1586: }
1.168 raeburn 1587: my @addlangs;
1588: foreach my $lang (sort(keys(%langchoices))) {
1589: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1590: push(@addlangs,$lang);
1591: }
1592: if (@addlangs > 0) {
1593: my %toadd;
1594: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1595: $toadd{''} = &mt('Select');
1596: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1597: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1598: &mt('Add log-in help page for a specific language:').' '.
1599: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1600: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1601: if ($switchserver) {
1602: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1603: } else {
1604: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1605: }
1.168 raeburn 1606: $datatable .= '</td></tr>';
1.169 raeburn 1607: $itemcount ++;
1.6 raeburn 1608: }
1.169 raeburn 1609: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1610: } elsif ($caller eq 'headtag') {
1611: my %domservers = &Apache::lonnet::get_servers($dom);
1612: my $choice = $choices{'headtag'};
1613: $css_class = ' class="LC_odd_row"';
1614: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1615: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1616: '<th>'.$choices{'current'}.'</th>'.
1617: '<th>'.$choices{'action'}.'</th>'.
1618: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1619: my (%currurls,%currexempt);
1620: if (ref($settings) eq 'HASH') {
1621: if (ref($settings->{'headtag'}) eq 'HASH') {
1622: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1623: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1624: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1625: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1626: }
1627: }
1628: }
1629: }
1630: foreach my $lonhost (sort(keys(%domservers))) {
1631: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1632: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1633: if ($currurls{$lonhost}) {
1634: $datatable .= '<td class="LC_right_item"><a href="'.
1635: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1636: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1637: '">'.$lt{'curr'}.'</a></td>'.
1638: '<td><span class="LC_nobreak"><label>'.
1639: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1640: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1641: } else {
1642: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1643: }
1644: $datatable .='<br />';
1645: if ($switchserver) {
1646: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1647: } else {
1648: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1649: }
1.330 raeburn 1650: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1651: }
1652: $datatable .= '</table></td></tr>';
1.386 raeburn 1653: } elsif ($caller eq 'saml') {
1654: my %domservers = &Apache::lonnet::get_servers($dom);
1655: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1656: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1657: '<th>'.$choices{'samllanding'}.'</th>'.
1658: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1659: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1660: foreach my $lonhost (keys(%domservers)) {
1661: $samlurl{$lonhost} = '/adm/sso';
1662: $styleon{$lonhost} = 'display:none';
1663: $styleoff{$lonhost} = '';
1664: }
1.411 raeburn 1665: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1666: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1667: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1668: $saml{$lonhost} = 1;
1669: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1670: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1671: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1672: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1673: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1674: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1675: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1676: $styleon{$lonhost} = '';
1677: $styleoff{$lonhost} = 'display:none';
1678: } else {
1679: $styleon{$lonhost} = 'display:none';
1680: $styleoff{$lonhost} = '';
1681: }
1682: }
1683: }
1684: my $itemcount = 1;
1685: foreach my $lonhost (sort(keys(%domservers))) {
1686: my $samlon = ' ';
1687: my $samloff = ' checked="checked" ';
1688: if ($saml{$lonhost}) {
1689: $samlon = $samloff;
1690: $samloff = ' ';
1691: }
1.412 raeburn 1692: my $samlwinon = '';
1693: my $samlwinoff = ' checked="checked"';
1694: if ($samlwindow{$lonhost}) {
1695: $samlwinon = $samlwinoff;
1696: $samlwinoff = '';
1697: }
1.386 raeburn 1698: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1699: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1700: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1701: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1702: &mt('No').'</label>'.(' 'x2).
1703: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1704: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1705: &mt('Yes').'</label></span></td>'.
1706: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1707: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1708: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1709: '<th>'.&mt('Alt Text').'</th></tr>'.
1710: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1711: $samltext{$lonhost}.'" /></td><td>';
1712: if ($samlimg{$lonhost}) {
1713: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1714: '<span class="LC_nobreak"><label>'.
1715: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1716: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1717: } else {
1718: $datatable .= $lt{'upl'};
1719: }
1720: $datatable .='<br />';
1721: if ($switchserver) {
1722: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1723: } else {
1724: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1725: }
1726: $datatable .= '</td>'.
1.412 raeburn 1727: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1728: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1729: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1730: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1731: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1732: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1733: '<tr'.$css_class.'>'.
1734: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1735: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1736: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1737: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1738: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1739: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1740: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1741: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1742: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1743: '</table></td>'.
1744: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1745: $itemcount ++;
1746: }
1747: $datatable .= '</table></td></tr>';
1.1 raeburn 1748: }
1.6 raeburn 1749: return $datatable;
1750: }
1751:
1752: sub login_choices {
1753: my %choices =
1754: &Apache::lonlocal::texthash (
1.116 bisitz 1755: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1756: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1757: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1758: disallowlogin => "Login page requests redirected",
1759: hostid => "Server",
1.128 raeburn 1760: server => "Redirect to:",
1761: serverpath => "Path",
1762: custompath => "Custom",
1763: exempt => "Exempt IP(s)",
1.110 raeburn 1764: directlogin => "No redirect",
1765: newuser => "Link to create a user account",
1766: img => "Header",
1767: logo => "Main Logo",
1768: domlogo => "Domain Logo",
1769: login => "Log-in Header",
1770: textcol => "Text color",
1771: bgcol => "Box color",
1772: bgs => "Background colors",
1773: links => "Link colors",
1774: font => "Font color",
1775: pgbg => "Header",
1776: mainbg => "Page",
1777: sidebg => "Login box",
1778: link => "Link",
1779: alink => "Active link",
1780: vlink => "Visited link",
1.256 raeburn 1781: headtag => "Custom markup",
1782: action => "Action",
1783: current => "Current",
1.386 raeburn 1784: samllanding => "Dual login?",
1785: samloptions => "Options",
1.402 raeburn 1786: alttext => "Alt text",
1.6 raeburn 1787: );
1788: return %choices;
1789: }
1790:
1.386 raeburn 1791: sub login_file_options {
1792: return &Apache::lonlocal::texthash(
1793: del => 'Delete?',
1794: rep => 'Replace:',
1795: upl => 'Upload:',
1796: curr => 'View contents',
1797: default => 'Default',
1798: custom => 'Custom',
1799: none => 'None',
1800: );
1801: }
1802:
1.394 raeburn 1803: sub print_ipaccess {
1804: my ($dom,$settings,$rowtotal) = @_;
1805: my $css_class;
1806: my $itemcount = 0;
1807: my $datatable;
1808: my %ordered;
1809: if (ref($settings) eq 'HASH') {
1810: foreach my $item (keys(%{$settings})) {
1811: if (ref($settings->{$item}) eq 'HASH') {
1812: my $num = $settings->{$item}{'order'};
1813: if ($num eq '') {
1814: $num = scalar(keys(%{$settings}));
1815: }
1816: $ordered{$num} = $item;
1817: }
1818: }
1819: }
1820: my $maxnum = scalar(keys(%ordered));
1821: if (keys(%ordered)) {
1822: my @items = sort { $a <=> $b } keys(%ordered);
1823: for (my $i=0; $i<@items; $i++) {
1824: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1825: my $item = $ordered{$items[$i]};
1826: my ($name,$ipranges,%commblocks,%courses);
1827: if (ref($settings->{$item}) eq 'HASH') {
1828: $name = $settings->{$item}->{'name'};
1829: $ipranges = $settings->{$item}->{'ip'};
1830: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1831: %commblocks = %{$settings->{$item}->{'commblocks'}};
1832: }
1833: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1834: %courses = %{$settings->{$item}->{'courses'}};
1835: }
1836: }
1837: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1838: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1839: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1840: for (my $k=0; $k<=$maxnum; $k++) {
1841: my $vpos = $k+1;
1842: my $selstr;
1843: if ($k == $i) {
1844: $selstr = ' selected="selected" ';
1845: }
1846: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1847: }
1848: $datatable .= '</select>'.(' 'x2).
1849: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1850: &mt('Delete?').'</label></span></td>'.
1851: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1852: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1853: '</td></tr>';
1854: $itemcount ++;
1855: }
1856: }
1857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1858: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1859: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1860: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1861: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1862: for (my $k=0; $k<$maxnum+1; $k++) {
1863: my $vpos = $k+1;
1864: my $selstr;
1865: if ($k == $maxnum) {
1866: $selstr = ' selected="selected" ';
1867: }
1868: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1869: }
1870: $datatable .= '</select> '."\n".
1871: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1872: '<td colspan="2">'.
1873: &ipaccess_options('add',$itemcount,$dom).
1874: '</td>'."\n".
1875: '</tr>'."\n";
1876: $$rowtotal ++;
1877: return $datatable;
1878: }
1879:
1880: sub ipaccess_options {
1881: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1882: my (%currblocks,%currcourses,$output);
1883: if (ref($blocksref) eq 'HASH') {
1884: %currblocks = %{$blocksref};
1885: }
1886: if (ref($coursesref) eq 'HASH') {
1887: %currcourses = %{$coursesref};
1888: }
1889: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1890: '<span class="LC_nobreak">'.&mt('Name').': '.
1891: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1892: '</span></fieldset>'.
1893: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1894: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1895: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1896: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1897: $ipranges.'</textarea></fieldset>'.
1898: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1899: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1900: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1901: '<table>';
1902: foreach my $cid (sort(keys(%currcourses))) {
1903: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1904: $output .= '<tr><td><span class="LC_nobreak">'.
1905: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1906: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1907: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1908: }
1909: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1910: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1911: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1912: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1913: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1914: '</span></td></tr></table>'."\n".
1915: '</fieldset>';
1916: return $output;
1917: }
1918:
1919: sub blocker_checkboxes {
1920: my ($num,$blocks) = @_;
1921: my ($typeorder,$types) = &commblocktype_text();
1922: my $numinrow = 6;
1923: my $output = '<table>';
1924: for (my $i=0; $i<@{$typeorder}; $i++) {
1925: my $block = $typeorder->[$i];
1926: my $blockstatus;
1927: if (ref($blocks) eq 'HASH') {
1928: if ($blocks->{$block} eq 'on') {
1929: $blockstatus = 'checked="checked"';
1930: }
1931: }
1932: my $rem = $i%($numinrow);
1933: if ($rem == 0) {
1934: if ($i > 0) {
1935: $output .= '</tr>';
1936: }
1937: $output .= '<tr>';
1938: }
1939: if ($i == scalar(@{$typeorder})-1) {
1940: my $colsleft = $numinrow-$rem;
1941: if ($colsleft > 1) {
1942: $output .= '<td colspan="'.$colsleft.'">';
1943: } else {
1944: $output .= '<td>';
1945: }
1946: } else {
1947: $output .= '<td>';
1948: }
1949: my $item = 'ipaccess_block_'.$num;
1950: if ($blockstatus) {
1951: $blockstatus = ' '.$blockstatus;
1952: }
1953: $output .= '<span class="LC_nobreak"><label>'."\n".
1954: '<input type="checkbox" name="'.$item.'"'.
1955: $blockstatus.' value="'.$block.'"'.' />'.
1956: $types->{$block}.'</label></span>'."\n".
1957: '<br /></td>';
1958: }
1959: $output .= '</tr></table>';
1960: return $output;
1961: }
1962:
1963: sub commblocktype_text {
1964: my %types = &Apache::lonlocal::texthash(
1965: 'com' => 'Messaging',
1966: 'chat' => 'Chat Room',
1967: 'boards' => 'Discussion',
1968: 'port' => 'Portfolio',
1969: 'groups' => 'Groups',
1970: 'blogs' => 'Blogs',
1971: 'about' => 'User Information',
1972: 'printout' => 'Printouts',
1973: 'passwd' => 'Change Password',
1974: 'grades' => 'Gradebook',
1.397 raeburn 1975: 'search' => 'Course search',
1976: 'wishlist' => 'Stored links',
1977: 'annotate' => 'Annotations',
1.394 raeburn 1978: );
1.397 raeburn 1979: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 1980: return ($typeorder,\%types);
1981: }
1982:
1.6 raeburn 1983: sub print_rolecolors {
1.30 raeburn 1984: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1985: my %choices = &color_font_choices();
1986: my @bgs = ('pgbg','tabbg','sidebg');
1987: my @links = ('link','alink','vlink');
1988: my @images = ('img');
1989: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1990: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1991: my %defaultdesign = %Apache::loncommon::defaultdesign;
1992: my (%is_custom,%designs);
1.200 raeburn 1993: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1994: if (ref($settings) eq 'HASH') {
1995: if (ref($settings->{$role}) eq 'HASH') {
1996: if ($settings->{$role}->{'img'} ne '') {
1997: $designs{'img'} = $settings->{$role}->{'img'};
1998: $is_custom{'img'} = 1;
1999: }
2000: if ($settings->{$role}->{'font'} ne '') {
2001: $designs{'font'} = $settings->{$role}->{'font'};
2002: $is_custom{'font'} = 1;
2003: }
1.97 tempelho 2004: if ($settings->{$role}->{'fontmenu'} ne '') {
2005: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2006: $is_custom{'fontmenu'} = 1;
2007: }
1.6 raeburn 2008: foreach my $item (@bgs) {
2009: if ($settings->{$role}->{$item} ne '') {
2010: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2011: $is_custom{$item} = 1;
2012: }
2013: }
2014: foreach my $item (@links) {
2015: if ($settings->{$role}->{$item} ne '') {
2016: $designs{'links'}{$item} = $settings->{$role}->{$item};
2017: $is_custom{$item} = 1;
2018: }
2019: }
2020: }
2021: } else {
2022: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2023: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2024: $is_custom{'img'} = 1;
2025: }
1.97 tempelho 2026: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2027: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2028: $is_custom{'fontmenu'} = 1;
2029: }
1.6 raeburn 2030: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2031: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2032: $is_custom{'font'} = 1;
2033: }
2034: foreach my $item (@bgs) {
2035: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2036: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2037: $is_custom{$item} = 1;
2038:
2039: }
2040: }
2041: foreach my $item (@links) {
2042: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2043: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2044: $is_custom{$item} = 1;
2045: }
2046: }
2047: }
2048: my $itemcount = 1;
1.30 raeburn 2049: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2050: $datatable .= '</tr></table></td></tr>';
2051: return $datatable;
2052: }
2053:
1.200 raeburn 2054: sub role_defaults {
2055: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2056: my %defaults;
2057: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2058: return %defaults;
2059: }
2060: my %defaultdesign = %Apache::loncommon::defaultdesign;
2061: if ($role eq 'login') {
2062: %defaults = (
2063: font => $defaultdesign{$role.'.font'},
2064: );
2065: if (ref($logintext) eq 'ARRAY') {
2066: foreach my $item (@{$logintext}) {
2067: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2068: }
2069: }
2070: foreach my $item (@{$images}) {
2071: $defaults{'showlogo'}{$item} = 1;
2072: }
2073: } else {
2074: %defaults = (
2075: img => $defaultdesign{$role.'.img'},
2076: font => $defaultdesign{$role.'.font'},
2077: fontmenu => $defaultdesign{$role.'.fontmenu'},
2078: );
2079: }
2080: foreach my $item (@{$bgs}) {
2081: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2082: }
2083: foreach my $item (@{$links}) {
2084: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2085: }
2086: foreach my $item (@{$images}) {
2087: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2088: }
2089: return %defaults;
2090: }
2091:
1.6 raeburn 2092: sub display_color_options {
1.9 raeburn 2093: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2094: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2095: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2096: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2097: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2098: '<td>'.$choices->{'font'}.'</td>';
2099: if (!$is_custom->{'font'}) {
1.329 raeburn 2100: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2101: } else {
2102: $datatable .= '<td> </td>';
2103: }
1.174 foxr 2104: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2105:
1.8 raeburn 2106: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2107: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2108: ' value="'.$current_color.'" /> '.
1.329 raeburn 2109: ' </span></td></tr>';
1.107 raeburn 2110: unless ($role eq 'login') {
2111: $datatable .= '<tr'.$css_class.'>'.
2112: '<td>'.$choices->{'fontmenu'}.'</td>';
2113: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2114: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2115: } else {
2116: $datatable .= '<td> </td>';
2117: }
1.202 raeburn 2118: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2119: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2120: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2121: '<input class="colorchooser" type="text" size="10" name="'
2122: .$role.'_fontmenu"'.
2123: ' value="'.$current_color.'" /> '.
1.329 raeburn 2124: ' </span></td></tr>';
1.97 tempelho 2125: }
1.9 raeburn 2126: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2127: foreach my $img (@{$images}) {
1.18 albertel 2128: $itemcount ++;
1.6 raeburn 2129: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2130: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2131: '<td>'.$choices->{$img};
1.402 raeburn 2132: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2133: if ($role eq 'login') {
2134: if ($img eq 'login') {
2135: $login_hdr_pick =
1.135 bisitz 2136: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2137: $logincolors =
2138: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2139: $designs,$defaults);
1.402 raeburn 2140: } else {
2141: if ($img ne 'domlogo') {
2142: $datatable.= &logo_display_options($img,$defaults,$designs);
2143: }
2144: if (ref($designs->{'alttext'}) eq 'HASH') {
2145: $alttext = $designs->{'alttext'}{$img};
2146: }
1.70 raeburn 2147: }
2148: }
2149: $datatable .= '</td>';
1.6 raeburn 2150: if ($designs->{$img} ne '') {
2151: $imgfile = $designs->{$img};
1.18 albertel 2152: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2153: } else {
2154: $imgfile = $defaults->{$img};
2155: }
2156: if ($imgfile) {
1.9 raeburn 2157: my ($showfile,$fullsize);
2158: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2159: my $urldir = $1;
2160: my $filename = $2;
2161: my @info = &Apache::lonnet::stat_file($designs->{$img});
2162: if (@info) {
2163: my $thumbfile = 'tn-'.$filename;
2164: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2165: if (@thumb) {
2166: $showfile = $urldir.'/'.$thumbfile;
2167: } else {
2168: $showfile = $imgfile;
2169: }
2170: } else {
2171: $showfile = '';
2172: }
2173: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2174: $showfile = $imgfile;
1.6 raeburn 2175: my $imgdir = $1;
2176: my $filename = $2;
1.159 raeburn 2177: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2178: $showfile = "/$imgdir/tn-".$filename;
2179: } else {
1.159 raeburn 2180: my $input = $londocroot.$imgfile;
2181: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2182: if (!-e $output) {
1.9 raeburn 2183: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2184: my ($fullwidth,$fullheight) = &check_dimensions($input);
2185: if ($fullwidth ne '' && $fullheight ne '') {
2186: if ($fullwidth > $width && $fullheight > $height) {
2187: my $size = $width.'x'.$height;
1.316 raeburn 2188: my @args = ('convert','-sample',$size,$input,$output);
2189: system({$args[0]} @args);
1.159 raeburn 2190: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2191: }
2192: }
1.6 raeburn 2193: }
2194: }
1.16 raeburn 2195: }
1.6 raeburn 2196: if ($showfile) {
1.40 raeburn 2197: if ($showfile =~ m{^/(adm|res)/}) {
2198: if ($showfile =~ m{^/res/}) {
2199: my $local_showfile =
2200: &Apache::lonnet::filelocation('',$showfile);
2201: &Apache::lonnet::repcopy($local_showfile);
2202: }
2203: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2204: }
2205: if ($imgfile) {
2206: if ($imgfile =~ m{^/(adm|res)/}) {
2207: if ($imgfile =~ m{^/res/}) {
2208: my $local_imgfile =
2209: &Apache::lonnet::filelocation('',$imgfile);
2210: &Apache::lonnet::repcopy($local_imgfile);
2211: }
2212: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2213: } else {
2214: $fullsize = $imgfile;
2215: }
2216: }
1.41 raeburn 2217: $datatable .= '<td>';
2218: if ($img eq 'login') {
1.135 bisitz 2219: $datatable .= $login_hdr_pick;
2220: }
1.41 raeburn 2221: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2222: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2223: } else {
1.201 raeburn 2224: $datatable .= '<td> </td><td class="LC_left_item">'.
2225: &mt('Upload:').'<br />';
1.6 raeburn 2226: }
2227: } else {
1.201 raeburn 2228: $datatable .= '<td> </td><td class="LC_left_item">'.
2229: &mt('Upload:').'<br />';
1.6 raeburn 2230: }
1.9 raeburn 2231: if ($switchserver) {
2232: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2233: } else {
1.135 bisitz 2234: if ($img ne 'login') { # suppress file selection for Log-in header
2235: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2236: }
1.9 raeburn 2237: }
1.402 raeburn 2238: if (($role eq 'login') && ($img ne 'login')) {
2239: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2240: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2241: '</label></span>';
2242: }
1.9 raeburn 2243: $datatable .= '</td></tr>';
1.6 raeburn 2244: }
2245: $itemcount ++;
2246: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2247: $datatable .= '<tr'.$css_class.'>'.
2248: '<td>'.$choices->{'bgs'}.'</td>';
2249: my $bgs_def;
2250: foreach my $item (@{$bgs}) {
2251: if (!$is_custom->{$item}) {
1.329 raeburn 2252: $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 2253: }
2254: }
2255: if ($bgs_def) {
1.8 raeburn 2256: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2257: } else {
2258: $datatable .= '<td> </td>';
2259: }
2260: $datatable .= '<td class="LC_right_item">'.
2261: '<table border="0"><tr>';
1.174 foxr 2262:
1.6 raeburn 2263: foreach my $item (@{$bgs}) {
1.306 raeburn 2264: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2265: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2266: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2267: $datatable .= ' ';
1.6 raeburn 2268: }
1.174 foxr 2269: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2270: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2271: }
2272: $datatable .= '</tr></table></td></tr>';
2273: $itemcount ++;
2274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2275: $datatable .= '<tr'.$css_class.'>'.
2276: '<td>'.$choices->{'links'}.'</td>';
2277: my $links_def;
2278: foreach my $item (@{$links}) {
2279: if (!$is_custom->{$item}) {
1.329 raeburn 2280: $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 2281: }
2282: }
2283: if ($links_def) {
1.8 raeburn 2284: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2285: } else {
2286: $datatable .= '<td> </td>';
2287: }
2288: $datatable .= '<td class="LC_right_item">'.
2289: '<table border="0"><tr>';
2290: foreach my $item (@{$links}) {
1.234 raeburn 2291: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2292: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2293: if ($designs->{'links'}{$item}) {
1.174 foxr 2294: $datatable.=' ';
1.6 raeburn 2295: }
1.174 foxr 2296: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2297: '" /></td>';
2298: }
1.30 raeburn 2299: $$rowtotal += $itemcount;
1.3 raeburn 2300: return $datatable;
2301: }
2302:
1.70 raeburn 2303: sub logo_display_options {
2304: my ($img,$defaults,$designs) = @_;
2305: my $checkedon;
2306: if (ref($defaults) eq 'HASH') {
2307: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2308: if ($defaults->{'showlogo'}{$img}) {
2309: $checkedon = 'checked="checked" ';
2310: }
2311: }
2312: }
2313: if (ref($designs) eq 'HASH') {
2314: if (ref($designs->{'showlogo'}) eq 'HASH') {
2315: if (defined($designs->{'showlogo'}{$img})) {
2316: if ($designs->{'showlogo'}{$img} == 0) {
2317: $checkedon = '';
2318: } elsif ($designs->{'showlogo'}{$img} == 1) {
2319: $checkedon = 'checked="checked" ';
2320: }
2321: }
2322: }
2323: }
2324: return '<br /><label> <input type="checkbox" name="'.
2325: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2326: &mt('show').'</label>'."\n";
2327: }
2328:
1.41 raeburn 2329: sub login_header_options {
1.135 bisitz 2330: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2331: my $output = '';
1.41 raeburn 2332: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2333: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2334: if (!$is_custom->{'textcol'}) {
2335: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2336: ' ';
2337: }
2338: if (!$is_custom->{'bgcol'}) {
2339: $output .= $choices->{'bgcol'}.': '.
2340: '<span id="css_'.$role.'_font" style="background-color: '.
2341: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2342: }
2343: $output .= '<br />';
2344: }
2345: $output .='<br />';
2346: return $output;
2347: }
2348:
2349: sub login_text_colors {
1.201 raeburn 2350: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2351: my $color_menu = '<table border="0"><tr>';
2352: foreach my $item (@{$logintext}) {
1.306 raeburn 2353: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2354: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2355: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2356: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2357: }
2358: $color_menu .= '</tr></table><br />';
2359: return $color_menu;
2360: }
2361:
2362: sub image_changes {
2363: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2364: my $output;
1.135 bisitz 2365: if ($img eq 'login') {
1.331 raeburn 2366: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2367: } elsif (!$is_custom) {
1.70 raeburn 2368: if ($img ne 'domlogo') {
1.331 raeburn 2369: $output = &mt('Default image:').'<br />';
1.41 raeburn 2370: } else {
1.331 raeburn 2371: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2372: }
2373: }
1.331 raeburn 2374: if ($img ne 'login') {
1.135 bisitz 2375: if ($img_import) {
2376: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2377: }
2378: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2379: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2380: if ($is_custom) {
2381: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2382: '<input type="checkbox" name="'.
2383: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2384: '</label> '.&mt('Replace:').'</span><br />';
2385: } else {
1.306 raeburn 2386: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2387: }
1.41 raeburn 2388: }
2389: return $output;
2390: }
2391:
1.3 raeburn 2392: sub print_quotas {
1.86 raeburn 2393: my ($dom,$settings,$rowtotal,$action) = @_;
2394: my $context;
2395: if ($action eq 'quotas') {
2396: $context = 'tools';
2397: } else {
2398: $context = $action;
2399: }
1.197 raeburn 2400: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2401: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2402: my $typecount = 0;
1.101 raeburn 2403: my ($css_class,%titles);
1.86 raeburn 2404: if ($context eq 'requestcourses') {
1.325 raeburn 2405: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2406: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2407: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2408: %titles = &courserequest_titles();
1.163 raeburn 2409: } elsif ($context eq 'requestauthor') {
2410: @usertools = ('author');
2411: @options = ('norequest','approval','automatic');
1.210 raeburn 2412: %titles = &authorrequest_titles();
1.86 raeburn 2413: } else {
1.413 raeburn 2414: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2415: %titles = &tool_titles();
1.86 raeburn 2416: }
1.26 raeburn 2417: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2418: foreach my $type (@{$types}) {
1.197 raeburn 2419: my ($currdefquota,$currauthorquota);
1.163 raeburn 2420: unless (($context eq 'requestcourses') ||
2421: ($context eq 'requestauthor')) {
1.86 raeburn 2422: if (ref($settings) eq 'HASH') {
2423: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2424: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2425: } else {
2426: $currdefquota = $settings->{$type};
2427: }
1.197 raeburn 2428: if (ref($settings->{authorquota}) eq 'HASH') {
2429: $currauthorquota = $settings->{authorquota}->{$type};
2430: }
1.78 raeburn 2431: }
1.72 raeburn 2432: }
1.3 raeburn 2433: if (defined($usertypes->{$type})) {
2434: $typecount ++;
2435: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2436: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2437: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2438: '<td class="LC_left_item">';
1.101 raeburn 2439: if ($context eq 'requestcourses') {
2440: $datatable .= '<table><tr>';
2441: }
2442: my %cell;
1.72 raeburn 2443: foreach my $item (@usertools) {
1.101 raeburn 2444: if ($context eq 'requestcourses') {
2445: my ($curroption,$currlimit);
2446: if (ref($settings) eq 'HASH') {
2447: if (ref($settings->{$item}) eq 'HASH') {
2448: $curroption = $settings->{$item}->{$type};
2449: if ($curroption =~ /^autolimit=(\d*)$/) {
2450: $currlimit = $1;
2451: }
2452: }
2453: }
2454: if (!$curroption) {
2455: $curroption = 'norequest';
2456: }
2457: $datatable .= '<th>'.$titles{$item}.'</th>';
2458: foreach my $option (@options) {
2459: my $val = $option;
2460: if ($option eq 'norequest') {
2461: $val = 0;
2462: }
2463: if ($option eq 'validate') {
2464: my $canvalidate = 0;
2465: if (ref($validations{$item}) eq 'HASH') {
2466: if ($validations{$item}{$type}) {
2467: $canvalidate = 1;
2468: }
2469: }
2470: next if (!$canvalidate);
2471: }
2472: my $checked = '';
2473: if ($option eq $curroption) {
2474: $checked = ' checked="checked"';
2475: } elsif ($option eq 'autolimit') {
2476: if ($curroption =~ /^autolimit/) {
2477: $checked = ' checked="checked"';
2478: }
2479: }
2480: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2481: '<input type="radio" name="crsreq_'.$item.
2482: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2483: $titles{$option}.'</label>';
1.101 raeburn 2484: if ($option eq 'autolimit') {
1.127 raeburn 2485: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2486: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2487: 'value="'.$currlimit.'" />';
1.101 raeburn 2488: }
1.127 raeburn 2489: $cell{$item} .= '</span> ';
1.103 raeburn 2490: if ($option eq 'autolimit') {
1.127 raeburn 2491: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2492: }
1.101 raeburn 2493: }
1.163 raeburn 2494: } elsif ($context eq 'requestauthor') {
2495: my $curroption;
2496: if (ref($settings) eq 'HASH') {
2497: $curroption = $settings->{$type};
2498: }
2499: if (!$curroption) {
2500: $curroption = 'norequest';
2501: }
2502: foreach my $option (@options) {
2503: my $val = $option;
2504: if ($option eq 'norequest') {
2505: $val = 0;
2506: }
2507: my $checked = '';
2508: if ($option eq $curroption) {
2509: $checked = ' checked="checked"';
2510: }
2511: $datatable .= '<span class="LC_nobreak"><label>'.
2512: '<input type="radio" name="authorreq_'.$type.
2513: '" value="'.$val.'"'.$checked.' />'.
2514: $titles{$option}.'</label></span> ';
2515: }
1.101 raeburn 2516: } else {
2517: my $checked = 'checked="checked" ';
1.413 raeburn 2518: if ($item eq 'timezone') {
2519: $checked = '';
2520: }
1.101 raeburn 2521: if (ref($settings) eq 'HASH') {
2522: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2523: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2524: $checked = '';
2525: } elsif ($settings->{$item}->{$type} == 1) {
2526: $checked = 'checked="checked" ';
2527: }
1.78 raeburn 2528: }
1.72 raeburn 2529: }
1.101 raeburn 2530: $datatable .= '<span class="LC_nobreak"><label>'.
2531: '<input type="checkbox" name="'.$context.'_'.$item.
2532: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2533: '</label></span> ';
1.72 raeburn 2534: }
1.101 raeburn 2535: }
2536: if ($context eq 'requestcourses') {
2537: $datatable .= '</tr><tr>';
2538: foreach my $item (@usertools) {
1.106 raeburn 2539: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2540: }
2541: $datatable .= '</tr></table>';
1.72 raeburn 2542: }
1.86 raeburn 2543: $datatable .= '</td>';
1.163 raeburn 2544: unless (($context eq 'requestcourses') ||
2545: ($context eq 'requestauthor')) {
1.86 raeburn 2546: $datatable .=
1.197 raeburn 2547: '<td class="LC_right_item">'.
2548: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2549: '<input type="text" name="quota_'.$type.
1.72 raeburn 2550: '" value="'.$currdefquota.
1.197 raeburn 2551: '" size="5" /></span>'.(' ' x 2).
2552: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2553: '<input type="text" name="authorquota_'.$type.
2554: '" value="'.$currauthorquota.
2555: '" size="5" /></span></td>';
1.86 raeburn 2556: }
2557: $datatable .= '</tr>';
1.3 raeburn 2558: }
2559: }
2560: }
1.163 raeburn 2561: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2562: $defaultquota = '20';
1.197 raeburn 2563: $authorquota = '500';
1.86 raeburn 2564: if (ref($settings) eq 'HASH') {
2565: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2566: $defaultquota = $settings->{'defaultquota'}->{'default'};
2567: } elsif (defined($settings->{'default'})) {
2568: $defaultquota = $settings->{'default'};
2569: }
1.197 raeburn 2570: if (ref($settings->{'authorquota'}) eq 'HASH') {
2571: $authorquota = $settings->{'authorquota'}->{'default'};
2572: }
1.3 raeburn 2573: }
2574: }
2575: $typecount ++;
2576: $css_class = $typecount%2?' class="LC_odd_row"':'';
2577: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2578: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2579: '<td class="LC_left_item">';
1.101 raeburn 2580: if ($context eq 'requestcourses') {
2581: $datatable .= '<table><tr>';
2582: }
2583: my %defcell;
1.72 raeburn 2584: foreach my $item (@usertools) {
1.101 raeburn 2585: if ($context eq 'requestcourses') {
2586: my ($curroption,$currlimit);
2587: if (ref($settings) eq 'HASH') {
2588: if (ref($settings->{$item}) eq 'HASH') {
2589: $curroption = $settings->{$item}->{'default'};
2590: if ($curroption =~ /^autolimit=(\d*)$/) {
2591: $currlimit = $1;
2592: }
2593: }
2594: }
2595: if (!$curroption) {
2596: $curroption = 'norequest';
2597: }
2598: $datatable .= '<th>'.$titles{$item}.'</th>';
2599: foreach my $option (@options) {
2600: my $val = $option;
2601: if ($option eq 'norequest') {
2602: $val = 0;
2603: }
2604: if ($option eq 'validate') {
2605: my $canvalidate = 0;
2606: if (ref($validations{$item}) eq 'HASH') {
2607: if ($validations{$item}{'default'}) {
2608: $canvalidate = 1;
2609: }
2610: }
2611: next if (!$canvalidate);
2612: }
2613: my $checked = '';
2614: if ($option eq $curroption) {
2615: $checked = ' checked="checked"';
2616: } elsif ($option eq 'autolimit') {
2617: if ($curroption =~ /^autolimit/) {
2618: $checked = ' checked="checked"';
2619: }
2620: }
2621: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2622: '<input type="radio" name="crsreq_'.$item.
2623: '_default" value="'.$val.'"'.$checked.' />'.
2624: $titles{$option}.'</label>';
2625: if ($option eq 'autolimit') {
1.127 raeburn 2626: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2627: $item.'_limit_default" size="1" '.
2628: 'value="'.$currlimit.'" />';
2629: }
1.127 raeburn 2630: $defcell{$item} .= '</span> ';
1.104 raeburn 2631: if ($option eq 'autolimit') {
1.127 raeburn 2632: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2633: }
1.101 raeburn 2634: }
1.163 raeburn 2635: } elsif ($context eq 'requestauthor') {
2636: my $curroption;
2637: if (ref($settings) eq 'HASH') {
1.172 raeburn 2638: $curroption = $settings->{'default'};
1.163 raeburn 2639: }
2640: if (!$curroption) {
2641: $curroption = 'norequest';
2642: }
2643: foreach my $option (@options) {
2644: my $val = $option;
2645: if ($option eq 'norequest') {
2646: $val = 0;
2647: }
2648: my $checked = '';
2649: if ($option eq $curroption) {
2650: $checked = ' checked="checked"';
2651: }
2652: $datatable .= '<span class="LC_nobreak"><label>'.
2653: '<input type="radio" name="authorreq_default"'.
2654: ' value="'.$val.'"'.$checked.' />'.
2655: $titles{$option}.'</label></span> ';
2656: }
1.101 raeburn 2657: } else {
2658: my $checked = 'checked="checked" ';
2659: if (ref($settings) eq 'HASH') {
2660: if (ref($settings->{$item}) eq 'HASH') {
2661: if ($settings->{$item}->{'default'} == 0) {
2662: $checked = '';
2663: } elsif ($settings->{$item}->{'default'} == 1) {
2664: $checked = 'checked="checked" ';
2665: }
1.78 raeburn 2666: }
1.72 raeburn 2667: }
1.101 raeburn 2668: $datatable .= '<span class="LC_nobreak"><label>'.
2669: '<input type="checkbox" name="'.$context.'_'.$item.
2670: '" value="default" '.$checked.'/>'.$titles{$item}.
2671: '</label></span> ';
2672: }
2673: }
2674: if ($context eq 'requestcourses') {
2675: $datatable .= '</tr><tr>';
2676: foreach my $item (@usertools) {
1.106 raeburn 2677: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2678: }
1.101 raeburn 2679: $datatable .= '</tr></table>';
1.72 raeburn 2680: }
1.86 raeburn 2681: $datatable .= '</td>';
1.163 raeburn 2682: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2683: $datatable .= '<td class="LC_right_item">'.
2684: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2685: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 2686: $defaultquota.'" size="5" /></span>'.(' ' x2).
2687: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2688: '<input type="text" name="authorquota" value="'.
2689: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2690: }
2691: $datatable .= '</tr>';
1.72 raeburn 2692: $typecount ++;
2693: $css_class = $typecount%2?' class="LC_odd_row"':'';
2694: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2695: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2696: if ($context eq 'requestcourses') {
1.109 raeburn 2697: $datatable .= &mt('(overrides affiliation, if set)').
2698: '</td>'.
2699: '<td class="LC_left_item">'.
2700: '<table><tr>';
1.101 raeburn 2701: } else {
1.109 raeburn 2702: $datatable .= &mt('(overrides affiliation, if checked)').
2703: '</td>'.
2704: '<td class="LC_left_item" colspan="2">'.
2705: '<br />';
1.101 raeburn 2706: }
2707: my %advcell;
1.72 raeburn 2708: foreach my $item (@usertools) {
1.101 raeburn 2709: if ($context eq 'requestcourses') {
2710: my ($curroption,$currlimit);
2711: if (ref($settings) eq 'HASH') {
2712: if (ref($settings->{$item}) eq 'HASH') {
2713: $curroption = $settings->{$item}->{'_LC_adv'};
2714: if ($curroption =~ /^autolimit=(\d*)$/) {
2715: $currlimit = $1;
2716: }
2717: }
2718: }
2719: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2720: my $checked = '';
2721: if ($curroption eq '') {
2722: $checked = ' checked="checked"';
2723: }
2724: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2725: '<input type="radio" name="crsreq_'.$item.
2726: '__LC_adv" value=""'.$checked.' />'.
2727: &mt('No override set').'</label></span> ';
1.101 raeburn 2728: foreach my $option (@options) {
2729: my $val = $option;
2730: if ($option eq 'norequest') {
2731: $val = 0;
2732: }
2733: if ($option eq 'validate') {
2734: my $canvalidate = 0;
2735: if (ref($validations{$item}) eq 'HASH') {
2736: if ($validations{$item}{'_LC_adv'}) {
2737: $canvalidate = 1;
2738: }
2739: }
2740: next if (!$canvalidate);
2741: }
2742: my $checked = '';
1.104 raeburn 2743: if ($val eq $curroption) {
1.101 raeburn 2744: $checked = ' checked="checked"';
2745: } elsif ($option eq 'autolimit') {
2746: if ($curroption =~ /^autolimit/) {
2747: $checked = ' checked="checked"';
2748: }
2749: }
2750: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2751: '<input type="radio" name="crsreq_'.$item.
2752: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2753: $titles{$option}.'</label>';
2754: if ($option eq 'autolimit') {
1.127 raeburn 2755: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2756: $item.'_limit__LC_adv" size="1" '.
2757: 'value="'.$currlimit.'" />';
2758: }
1.127 raeburn 2759: $advcell{$item} .= '</span> ';
1.104 raeburn 2760: if ($option eq 'autolimit') {
1.127 raeburn 2761: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2762: }
1.101 raeburn 2763: }
1.163 raeburn 2764: } elsif ($context eq 'requestauthor') {
2765: my $curroption;
2766: if (ref($settings) eq 'HASH') {
2767: $curroption = $settings->{'_LC_adv'};
2768: }
2769: my $checked = '';
2770: if ($curroption eq '') {
2771: $checked = ' checked="checked"';
2772: }
2773: $datatable .= '<span class="LC_nobreak"><label>'.
2774: '<input type="radio" name="authorreq__LC_adv"'.
2775: ' value=""'.$checked.' />'.
2776: &mt('No override set').'</label></span> ';
2777: foreach my $option (@options) {
2778: my $val = $option;
2779: if ($option eq 'norequest') {
2780: $val = 0;
2781: }
2782: my $checked = '';
2783: if ($val eq $curroption) {
2784: $checked = ' checked="checked"';
2785: }
2786: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2787: '<input type="radio" name="authorreq__LC_adv"'.
2788: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2789: $titles{$option}.'</label></span> ';
2790: }
1.101 raeburn 2791: } else {
2792: my $checked = 'checked="checked" ';
2793: if (ref($settings) eq 'HASH') {
2794: if (ref($settings->{$item}) eq 'HASH') {
2795: if ($settings->{$item}->{'_LC_adv'} == 0) {
2796: $checked = '';
2797: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2798: $checked = 'checked="checked" ';
2799: }
1.79 raeburn 2800: }
1.72 raeburn 2801: }
1.101 raeburn 2802: $datatable .= '<span class="LC_nobreak"><label>'.
2803: '<input type="checkbox" name="'.$context.'_'.$item.
2804: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2805: '</label></span> ';
2806: }
2807: }
2808: if ($context eq 'requestcourses') {
2809: $datatable .= '</tr><tr>';
2810: foreach my $item (@usertools) {
1.106 raeburn 2811: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2812: }
1.101 raeburn 2813: $datatable .= '</tr></table>';
1.72 raeburn 2814: }
1.98 raeburn 2815: $datatable .= '</td></tr>';
1.30 raeburn 2816: $$rowtotal += $typecount;
1.3 raeburn 2817: return $datatable;
2818: }
2819:
1.163 raeburn 2820: sub print_requestmail {
1.305 raeburn 2821: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2822: my ($now,$datatable,%currapp);
1.102 raeburn 2823: $now = time;
2824: if (ref($settings) eq 'HASH') {
2825: if (ref($settings->{'notify'}) eq 'HASH') {
2826: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2827: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2828: }
2829: }
2830: }
1.191 raeburn 2831: my $numinrow = 2;
1.224 raeburn 2832: my $css_class;
1.305 raeburn 2833: if ($$rowtotal%2) {
2834: $css_class = 'LC_odd_row';
2835: }
2836: if ($customcss) {
2837: $css_class .= " $customcss";
2838: }
2839: $css_class =~ s/^\s+//;
2840: if ($css_class) {
2841: $css_class = ' class="'.$css_class.'"';
2842: }
2843: if ($rowstyle) {
2844: $css_class .= ' style="'.$rowstyle.'"';
2845: }
1.163 raeburn 2846: my $text;
2847: if ($action eq 'requestcourses') {
2848: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2849: } elsif ($action eq 'requestauthor') {
2850: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2851: } else {
1.224 raeburn 2852: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2853: }
1.224 raeburn 2854: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2855: ' <td>'.$text.'</td>'.
1.102 raeburn 2856: ' <td class="LC_left_item">';
1.191 raeburn 2857: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2858: $action.'notifyapproval',%currapp);
1.191 raeburn 2859: if ($numdc > 0) {
2860: $datatable .= $table;
1.102 raeburn 2861: } else {
2862: $datatable .= &mt('There are no active Domain Coordinators');
2863: }
2864: $datatable .='</td></tr>';
2865: return $datatable;
2866: }
2867:
1.216 raeburn 2868: sub print_studentcode {
2869: my ($settings,$rowtotal) = @_;
2870: my $rownum = 0;
1.218 raeburn 2871: my ($output,%current);
1.325 raeburn 2872: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2873: if (ref($settings) eq 'HASH') {
2874: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2875: foreach my $type (@crstypes) {
2876: $current{$type} = $settings->{'uniquecode'}{$type};
2877: }
1.218 raeburn 2878: }
2879: }
2880: $output .= '<tr>'.
2881: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2882: '<td class="LC_left_item">';
2883: foreach my $type (@crstypes) {
2884: my $check = ' ';
2885: if ($current{$type}) {
2886: $check = ' checked="checked" ';
2887: }
2888: $output .= '<span class="LC_nobreak"><label>'.
2889: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2890: &mt($type).'</label></span>'.(' 'x2).' ';
2891: }
2892: $output .= '</td></tr>';
2893: $$rowtotal ++;
2894: return $output;
1.216 raeburn 2895: }
2896:
2897: sub print_textbookcourses {
1.242 raeburn 2898: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2899: my $rownum = 0;
2900: my $css_class;
2901: my $itemcount = 1;
2902: my $maxnum = 0;
2903: my $bookshash;
2904: if (ref($settings) eq 'HASH') {
1.242 raeburn 2905: $bookshash = $settings->{$type};
1.216 raeburn 2906: }
2907: my %ordered;
2908: if (ref($bookshash) eq 'HASH') {
2909: foreach my $item (keys(%{$bookshash})) {
2910: if (ref($bookshash->{$item}) eq 'HASH') {
2911: my $num = $bookshash->{$item}{'order'};
2912: $ordered{$num} = $item;
2913: }
2914: }
2915: }
2916: my $confname = $dom.'-domainconfig';
2917: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2918: my $maxnum = scalar(keys(%ordered));
2919: my $datatable;
1.216 raeburn 2920: if (keys(%ordered)) {
2921: my @items = sort { $a <=> $b } keys(%ordered);
2922: for (my $i=0; $i<@items; $i++) {
2923: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2924: my $key = $ordered{$items[$i]};
2925: my %coursehash=&Apache::lonnet::coursedescription($key);
2926: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2927: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2928: if (ref($bookshash->{$key}) eq 'HASH') {
2929: $subject = $bookshash->{$key}->{'subject'};
2930: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2931: if ($type eq 'textbooks') {
1.243 raeburn 2932: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2933: $author = $bookshash->{$key}->{'author'};
2934: $image = $bookshash->{$key}->{'image'};
2935: if ($image ne '') {
2936: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2937: my $imagethumb = "$path/tn-".$imagefile;
2938: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2939: }
1.216 raeburn 2940: }
2941: }
1.242 raeburn 2942: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2943: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2944: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2945: for (my $k=0; $k<=$maxnum; $k++) {
2946: my $vpos = $k+1;
2947: my $selstr;
2948: if ($k == $i) {
2949: $selstr = ' selected="selected" ';
2950: }
2951: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2952: }
2953: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2954: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2955: &mt('Delete?').'</label></span></td>'.
2956: '<td colspan="2">'.
1.242 raeburn 2957: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2958: (' 'x2).
1.242 raeburn 2959: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2960: if ($type eq 'textbooks') {
2961: $datatable .= (' 'x2).
1.243 raeburn 2962: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2963: (' 'x2).
1.242 raeburn 2964: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2965: (' 'x2).
2966: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2967: if ($image) {
1.267 raeburn 2968: $datatable .= $imgsrc.
1.242 raeburn 2969: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2970: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2971: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2972: }
2973: if ($switchserver) {
2974: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2975: } else {
2976: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2977: }
1.216 raeburn 2978: }
1.242 raeburn 2979: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2980: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2981: $coursetitle.'</span></td></tr>'."\n";
2982: $itemcount ++;
2983: }
2984: }
2985: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2986: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 2987: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 2988: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2989: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 2990: for (my $k=0; $k<$maxnum+1; $k++) {
2991: my $vpos = $k+1;
2992: my $selstr;
2993: if ($k == $maxnum) {
2994: $selstr = ' selected="selected" ';
2995: }
2996: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2997: }
2998: $datatable .= '</select> '."\n".
1.334 raeburn 2999: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3000: '<td colspan="2">'.
1.242 raeburn 3001: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3002: (' 'x2).
1.242 raeburn 3003: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3004: (' 'x2);
3005: if ($type eq 'textbooks') {
1.243 raeburn 3006: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3007: (' 'x2).
3008: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3009: (' 'x2).
3010: '<span class="LC_nobreak">'.&mt('Image:').' ';
3011: if ($switchserver) {
3012: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3013: } else {
3014: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3015: }
1.334 raeburn 3016: $datatable .= '</span>'."\n";
1.216 raeburn 3017: }
1.334 raeburn 3018: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3019: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3020: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3021: &Apache::loncommon::selectcourse_link
1.334 raeburn 3022: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3023: '</span></td>'."\n".
3024: '</tr>'."\n";
3025: $itemcount ++;
3026: return $datatable;
3027: }
3028:
1.217 raeburn 3029: sub textbookcourses_javascript {
1.242 raeburn 3030: my ($settings) = @_;
3031: return unless(ref($settings) eq 'HASH');
3032: my (%ordered,%total,%jstext);
3033: foreach my $type ('textbooks','templates') {
3034: $total{$type} = 0;
3035: if (ref($settings->{$type}) eq 'HASH') {
3036: foreach my $item (keys(%{$settings->{$type}})) {
3037: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3038: my $num = $settings->{$type}->{$item}{'order'};
3039: $ordered{$type}{$num} = $item;
3040: }
3041: }
3042: $total{$type} = scalar(keys(%{$settings->{$type}}));
3043: }
3044: my @jsarray = ();
3045: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3046: push(@jsarray,$ordered{$type}{$item});
3047: }
3048: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3049: }
3050: return <<"ENDSCRIPT";
3051: <script type="text/javascript">
3052: // <![CDATA[
1.242 raeburn 3053: function reorderBooks(form,item,caller) {
1.217 raeburn 3054: var changedVal;
1.242 raeburn 3055: $jstext{'textbooks'};
3056: $jstext{'templates'};
3057: var newpos;
3058: var maxh;
3059: if (caller == 'textbooks') {
3060: newpos = 'textbooks_addbook_pos';
3061: maxh = 1 + $total{'textbooks'};
3062: } else {
3063: newpos = 'templates_addbook_pos';
3064: maxh = 1 + $total{'templates'};
3065: }
1.217 raeburn 3066: var current = new Array;
3067: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3068: if (item == newpos) {
3069: changedVal = newitemVal;
3070: } else {
3071: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3072: current[newitemVal] = newpos;
3073: }
1.242 raeburn 3074: if (caller == 'textbooks') {
3075: for (var i=0; i<textbooks.length; i++) {
3076: var elementName = 'textbooks_'+textbooks[i];
3077: if (elementName != item) {
3078: if (form.elements[elementName]) {
3079: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3080: current[currVal] = elementName;
3081: }
3082: }
3083: }
3084: }
3085: if (caller == 'templates') {
3086: for (var i=0; i<templates.length; i++) {
3087: var elementName = 'templates_'+templates[i];
3088: if (elementName != item) {
3089: if (form.elements[elementName]) {
3090: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3091: current[currVal] = elementName;
3092: }
1.217 raeburn 3093: }
3094: }
3095: }
3096: var oldVal;
3097: for (var j=0; j<maxh; j++) {
3098: if (current[j] == undefined) {
3099: oldVal = j;
3100: }
3101: }
3102: if (oldVal < changedVal) {
3103: for (var k=oldVal+1; k<=changedVal ; k++) {
3104: var elementName = current[k];
3105: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3106: }
3107: } else {
3108: for (var k=changedVal; k<oldVal; k++) {
3109: var elementName = current[k];
3110: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3111: }
3112: }
3113: return;
3114: }
3115:
3116: // ]]>
3117: </script>
3118:
3119: ENDSCRIPT
3120: }
3121:
1.267 raeburn 3122: sub ltitools_javascript {
3123: my ($settings) = @_;
1.319 raeburn 3124: my $togglejs = <itools_toggle_js();
3125: unless (ref($settings) eq 'HASH') {
3126: return $togglejs;
3127: }
1.267 raeburn 3128: my (%ordered,$total,%jstext);
3129: $total = 0;
3130: foreach my $item (keys(%{$settings})) {
3131: if (ref($settings->{$item}) eq 'HASH') {
3132: my $num = $settings->{$item}{'order'};
3133: $ordered{$num} = $item;
3134: }
3135: }
3136: $total = scalar(keys(%{$settings}));
3137: my @jsarray = ();
3138: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3139: push(@jsarray,$ordered{$item});
3140: }
3141: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3142: return <<"ENDSCRIPT";
3143: <script type="text/javascript">
3144: // <![CDATA[
1.319 raeburn 3145: function reorderLTITools(form,item) {
1.267 raeburn 3146: var changedVal;
3147: $jstext
3148: var newpos = 'ltitools_add_pos';
3149: var maxh = 1 + $total;
3150: var current = new Array;
3151: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3152: if (item == newpos) {
3153: changedVal = newitemVal;
3154: } else {
3155: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3156: current[newitemVal] = newpos;
3157: }
3158: for (var i=0; i<ltitools.length; i++) {
3159: var elementName = 'ltitools_'+ltitools[i];
3160: if (elementName != item) {
3161: if (form.elements[elementName]) {
3162: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3163: current[currVal] = elementName;
3164: }
3165: }
3166: }
3167: var oldVal;
3168: for (var j=0; j<maxh; j++) {
3169: if (current[j] == undefined) {
3170: oldVal = j;
3171: }
3172: }
3173: if (oldVal < changedVal) {
3174: for (var k=oldVal+1; k<=changedVal ; k++) {
3175: var elementName = current[k];
3176: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3177: }
3178: } else {
3179: for (var k=changedVal; k<oldVal; k++) {
3180: var elementName = current[k];
3181: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3182: }
3183: }
3184: return;
3185: }
3186:
3187: // ]]>
3188: </script>
3189:
1.319 raeburn 3190: $togglejs
3191:
3192: ENDSCRIPT
3193: }
3194:
3195: sub ltitools_toggle_js {
3196: return <<"ENDSCRIPT";
3197: <script type="text/javascript">
3198: // <![CDATA[
3199:
3200: function toggleLTITools(form,setting,item) {
3201: var radioname = '';
3202: var divid = '';
3203: if ((setting == 'passback') || (setting == 'roster')) {
3204: radioname = 'ltitools_'+setting+'_'+item;
3205: divid = 'ltitools_'+setting+'time_'+item;
3206: var num = form.elements[radioname].length;
3207: if (num) {
3208: var setvis = '';
3209: for (var i=0; i<num; i++) {
3210: if (form.elements[radioname][i].checked) {
3211: if (form.elements[radioname][i].value == '1') {
3212: if (document.getElementById(divid)) {
3213: document.getElementById(divid).style.display = 'inline-block';
3214: }
3215: setvis = 1;
3216: }
3217: break;
3218: }
3219: }
3220: }
3221: if (!setvis) {
3222: if (document.getElementById(divid)) {
3223: document.getElementById(divid).style.display = 'none';
3224: }
3225: }
3226: }
1.324 raeburn 3227: if (setting == 'user') {
3228: divid = 'ltitools_'+setting+'_div_'+item;
3229: var checkid = 'ltitools_'+setting+'_field_'+item;
3230: if (document.getElementById(divid)) {
3231: if (document.getElementById(checkid)) {
3232: if (document.getElementById(checkid).checked) {
3233: document.getElementById(divid).style.display = 'inline-block';
3234: } else {
3235: document.getElementById(divid).style.display = 'none';
3236: }
3237: }
3238: }
3239: }
1.319 raeburn 3240: return;
3241: }
3242: // ]]>
3243: </script>
3244:
1.267 raeburn 3245: ENDSCRIPT
3246: }
3247:
1.381 raeburn 3248: sub wafproxy_javascript {
3249: my ($dom) = @_;
3250: return <<"ENDSCRIPT";
3251: <script type="text/javascript">
3252: // <![CDATA[
3253: function updateWAF() {
3254: if (document.getElementById('wafproxy_remoteip')) {
3255: var wafremote = 0;
3256: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3257: wafremote = 1;
3258: }
3259: var fields = new Array('header','trust');
3260: for (var i=0; i<fields.length; i++) {
3261: if (document.getElementById('wafproxy_'+fields[i])) {
3262: if (wafremote == 1) {
3263: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3264: }
3265: else {
3266: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3267: }
3268: }
3269: }
3270: if (document.getElementById('wafproxyranges_$dom')) {
3271: if (wafremote == 1) {
3272: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3273: } else {
3274: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3275: if (document.display.wafproxy_vpnaccess[i].checked) {
3276: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3277: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3278: }
3279: }
3280: }
3281: }
3282: }
3283: }
3284: return;
3285: }
3286:
3287: function checkWAF() {
3288: if (document.getElementById('wafproxy_remoteip')) {
3289: var wafvpn = 0;
3290: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3291: if (document.display.wafproxy_vpnaccess[i].checked) {
3292: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3293: wafvpn = 1;
3294: }
3295: break;
3296: }
3297: }
3298: var vpn = new Array('vpnint','vpnext');
3299: for (var i=0; i<vpn.length; i++) {
3300: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3301: if (wafvpn == 1) {
3302: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3303: }
3304: else {
3305: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3306: }
3307: }
3308: }
3309: if (document.getElementById('wafproxyranges_$dom')) {
3310: if (wafvpn == 1) {
3311: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3312: }
3313: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3314: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3315: }
3316: }
3317: }
3318: return;
3319: }
3320:
3321: function toggleWAF() {
3322: if (document.getElementById('wafproxy_table')) {
3323: var wafproxy = 0;
3324: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3325: if (document.display.wafproxy_${dom}[i].checked) {
3326: if (document.display.wafproxy_${dom}[i].value == 1) {
3327: wafproxy = 1;
3328: break;
3329: }
3330: }
3331: }
3332: if (wafproxy == 1) {
3333: document.getElementById('wafproxy_table').style.display='inline';
3334: }
3335: else {
3336: document.getElementById('wafproxy_table').style.display='none';
3337: }
3338: if (document.getElementById('wafproxyrow_${dom}')) {
3339: if (wafproxy == 1) {
3340: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3341: }
3342: else {
3343: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3344: }
3345: }
3346: if (document.getElementById('nowafproxyrow_$dom')) {
3347: if (wafproxy == 1) {
3348: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3349: }
3350: else {
3351: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3352: }
3353: }
3354: }
3355: return;
3356: }
3357: // ]]>
3358: </script>
3359:
3360: ENDSCRIPT
3361: }
3362:
1.372 raeburn 3363: sub proctoring_javascript {
3364: my ($settings) = @_;
3365: my (%ordered,$total,%jstext);
3366: $total = 0;
3367: if (ref($settings) eq 'HASH') {
3368: foreach my $item (keys(%{$settings})) {
3369: if (ref($settings->{$item}) eq 'HASH') {
3370: my $num = $settings->{$item}{'order'};
3371: $ordered{$num} = $item;
3372: }
3373: }
3374: $total = scalar(keys(%{$settings}));
3375: } else {
3376: %ordered = (
3377: 0 => 'proctorio',
3378: 1 => 'examity',
3379: );
3380: $total = 2;
3381: }
3382: my @jsarray = ();
3383: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3384: push(@jsarray,$ordered{$item});
3385: }
3386: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3387: return <<"ENDSCRIPT";
3388: <script type="text/javascript">
3389: // <![CDATA[
3390: function reorderProctoring(form,item) {
3391: var changedVal;
3392: $jstext
3393: var maxh = $total;
3394: var current = new Array;
3395: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3396: for (var i=0; i<proctors.length; i++) {
3397: var elementName = 'proctoring_pos_'+proctors[i];
3398: if (elementName != item) {
3399: if (form.elements[elementName]) {
3400: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3401: current[currVal] = elementName;
3402: }
3403: }
3404: }
3405: var oldVal;
3406: for (var j=0; j<maxh; j++) {
3407: if (current[j] == undefined) {
3408: oldVal = j;
3409: }
3410: }
3411: if (oldVal < changedVal) {
3412: for (var k=oldVal+1; k<=changedVal ; k++) {
3413: var elementName = current[k];
3414: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3415: }
3416: } else {
3417: for (var k=changedVal; k<oldVal; k++) {
3418: var elementName = current[k];
3419: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3420: }
3421: }
3422: return;
3423: }
3424:
3425: function toggleProctoring(form,item) {
3426: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3427: if (fieldsets.length) {
3428: var radioname = 'proctoring_available_'+item;
3429: var num = form.elements[radioname].length;
3430: if (num) {
3431: var setvis = '';
3432: for (var i=0; i<num; i++) {
3433: if (form.elements[radioname][i].checked) {
3434: if (form.elements[radioname][i].value == '1') {
3435: setvis = 1;
3436: break;
3437: }
3438: }
3439: }
3440: for (var j=0; j<fieldsets.length; j++) {
3441: if (setvis) {
3442: fieldsets[j].style.display = 'block';
3443: } else {
3444: fieldsets[j].style.display = 'none';
3445: }
3446: }
3447: }
3448: }
3449: return;
3450: }
3451:
3452: // ]]>
3453: </script>
3454:
3455: ENDSCRIPT
3456: }
3457:
3458:
1.320 raeburn 3459: sub lti_javascript {
1.405 raeburn 3460: my ($dom,$settings) = @_;
3461: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3462: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3463: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3464: return $togglejs.'
3465: <script type="text/javascript">
3466: // <![CDATA[
3467:
3468: '.$linkprot_js.'
3469:
3470: // ]]>
3471: </script>
3472: ';
1.320 raeburn 3473: }
3474: my (%ordered,$total,%jstext);
1.390 raeburn 3475: $total = scalar(keys(%{$settings}));
1.320 raeburn 3476: foreach my $item (keys(%{$settings})) {
3477: if (ref($settings->{$item}) eq 'HASH') {
3478: my $num = $settings->{$item}{'order'};
1.390 raeburn 3479: if ($num eq '') {
3480: $num = $total - 1;
3481: }
1.320 raeburn 3482: $ordered{$num} = $item;
3483: }
3484: }
3485: my @jsarray = ();
3486: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3487: push(@jsarray,$ordered{$item});
3488: }
3489: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3490: return <<"ENDSCRIPT";
3491: <script type="text/javascript">
3492: // <![CDATA[
3493: function reorderLTI(form,item) {
3494: var changedVal;
3495: $jstext
3496: var newpos = 'lti_pos_add';
3497: var maxh = 1 + $total;
3498: var current = new Array;
3499: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3500: if (item == newpos) {
3501: changedVal = newitemVal;
3502: } else {
3503: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3504: current[newitemVal] = newpos;
3505: }
3506: for (var i=0; i<lti.length; i++) {
3507: var elementName = 'lti_pos_'+lti[i];
3508: if (elementName != item) {
3509: if (form.elements[elementName]) {
3510: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3511: current[currVal] = elementName;
3512: }
3513: }
3514: }
3515: var oldVal;
3516: for (var j=0; j<maxh; j++) {
3517: if (current[j] == undefined) {
3518: oldVal = j;
3519: }
3520: }
3521: if (oldVal < changedVal) {
3522: for (var k=oldVal+1; k<=changedVal ; k++) {
3523: var elementName = current[k];
3524: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3525: }
3526: } else {
3527: for (var k=changedVal; k<oldVal; k++) {
3528: var elementName = current[k];
3529: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3530: }
3531: }
3532: return;
3533: }
1.406 raeburn 3534:
3535: $linkprot_js
3536:
1.320 raeburn 3537: // ]]>
3538: </script>
3539:
3540: $togglejs
3541:
3542: ENDSCRIPT
3543: }
3544:
3545: sub lti_toggle_js {
1.405 raeburn 3546: my ($dom) = @_;
1.325 raeburn 3547: my %lcauthparmtext = &Apache::lonlocal::texthash (
3548: localauth => 'Local auth argument',
3549: krb => 'Kerberos domain',
3550: );
1.391 raeburn 3551: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3552: &js_escape(\$crsincalert);
1.405 raeburn 3553: my %servers = &Apache::lonnet::get_servers($dom,'library');
3554: my $primary = &Apache::lonnet::domain($dom,'primary');
3555: my $course_servers = "'".join("','",keys(%servers))."'";
3556:
1.320 raeburn 3557: return <<"ENDSCRIPT";
3558: <script type="text/javascript">
3559: // <![CDATA[
3560:
3561: function toggleLTI(form,setting,item) {
1.391 raeburn 3562: if ((setting == 'requser') || (setting == 'crsinc')) {
3563: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3564: var setvis = '';
3565: var radioname = 'lti_requser_'+item;
3566: var num = form.elements[radioname].length;
3567: if (num) {
3568: for (var i=0; i<num; i++) {
3569: if (form.elements[radioname][i].checked) {
3570: if (form.elements[radioname][i].value == '1') {
3571: setvis = 1;
3572: break;
3573: }
3574: }
3575: }
3576: }
3577: if (usrfieldsets.length) {
3578: for (var j=0; j<usrfieldsets.length; j++) {
3579: if (setvis) {
3580: usrfieldsets[j].style.display = 'block';
3581: } else {
3582: usrfieldsets[j].style.display = 'none';
3583: }
3584: }
3585: }
3586: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3587: if (crsfieldsets.length) {
3588: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3589: var num = form.elements[radioname].length;
3590: if (num) {
1.391 raeburn 3591: var crsvis = '';
1.345 raeburn 3592: for (var i=0; i<num; i++) {
3593: if (form.elements[radioname][i].checked) {
3594: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3595: if (setvis == '') {
3596: if (setting == 'crsinc'){
3597: alert("$crsincalert");
3598: form.elements[radioname][0].checked = true;
3599: }
3600: } else {
3601: crsvis = 1;
3602: }
3603: break;
1.345 raeburn 3604: }
3605: }
3606: }
1.391 raeburn 3607: setvis = crsvis;
3608: }
3609: for (var j=0; j<crsfieldsets.length; j++) {
3610: if (setvis) {
3611: crsfieldsets[j].style.display = 'block';
3612: } else {
3613: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3614: }
3615: }
3616: }
1.363 raeburn 3617: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3618: var radioname = '';
3619: var divid = '';
3620: if (setting == 'user') {
3621: radioname = 'lti_mapuser_'+item;
3622: divid = 'lti_userfield_'+item;
1.343 raeburn 3623: } else if (setting == 'crs') {
1.320 raeburn 3624: radioname = 'lti_mapcrs_'+item;
3625: divid = 'lti_crsfield_'+item;
1.363 raeburn 3626: } else if (setting == 'callback') {
3627: radioname = 'lti_callback_'+item;
3628: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3629: } else {
1.351 raeburn 3630: radioname = 'lti_passback_'+item;
1.337 raeburn 3631: divid = 'lti_passback_'+item;
1.320 raeburn 3632: }
3633: var num = form.elements[radioname].length;
3634: if (num) {
3635: var setvis = '';
3636: for (var i=0; i<num; i++) {
3637: if (form.elements[radioname][i].checked) {
1.363 raeburn 3638: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3639: if (form.elements[radioname][i].value == '1') {
3640: if (document.getElementById(divid)) {
3641: document.getElementById(divid).style.display = 'inline-block';
3642: }
3643: setvis = 1;
3644: break;
3645: }
3646: } else {
3647: if (form.elements[radioname][i].value == 'other') {
3648: if (document.getElementById(divid)) {
3649: document.getElementById(divid).style.display = 'inline-block';
3650: }
3651: setvis = 1;
3652: break;
1.320 raeburn 3653: }
3654: }
3655: }
3656: }
3657: if (!setvis) {
3658: if (document.getElementById(divid)) {
3659: document.getElementById(divid).style.display = 'none';
3660: }
3661: }
3662: }
3663: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3664: var numsec = form.elements['lti_crssec_'+item].length;
3665: if (numsec) {
3666: var setvis = '';
3667: for (var i=0; i<numsec; i++) {
3668: if (form.elements['lti_crssec_'+item][i].checked) {
3669: if (form.elements['lti_crssec_'+item][i].value == '1') {
3670: if (document.getElementById('lti_crssecfield_'+item)) {
3671: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3672: setvis = 1;
3673: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3674: if (numsrcsec) {
3675: var setsrcvis = '';
3676: for (var j=0; j<numsrcsec; j++) {
3677: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3678: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3679: if (document.getElementById('lti_secsrcfield_'+item)) {
3680: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3681: setsrcvis = 1;
3682: }
3683: }
3684: }
3685: }
3686: if (!setsrcvis) {
3687: if (document.getElementById('lti_secsrcfield_'+item)) {
3688: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3689: }
3690: }
3691: }
3692: }
3693: }
3694: }
3695: }
3696: if (!setvis) {
3697: if (document.getElementById('lti_crssecfield_'+item)) {
3698: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3699: }
3700: if (document.getElementById('lti_secsrcfield_'+item)) {
3701: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3702: }
3703: }
3704: }
1.325 raeburn 3705: } else if (setting == 'lcauth') {
3706: var numauth = form.elements['lti_lcauth_'+item].length;
3707: if (numauth) {
3708: for (var i=0; i<numauth; i++) {
3709: if (form.elements['lti_lcauth_'+item][i].checked) {
3710: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3711: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3712: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3713: } else {
3714: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3715: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3716: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3717: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3718: } else {
3719: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3720: }
3721: }
3722: }
3723: }
3724: }
3725: }
3726: }
1.326 raeburn 3727: } else if (setting == 'lcmenu') {
3728: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3729: var divid = 'lti_menufield_'+item;
3730: var setvis = '';
3731: for (var i=0; i<menus.length; i++) {
3732: var radioname = menus[i];
3733: var num = form.elements[radioname].length;
3734: if (num) {
3735: for (var j=0; j<num; j++) {
3736: if (form.elements[radioname][j].checked) {
3737: if (form.elements[radioname][j].value == '1') {
3738: if (document.getElementById(divid)) {
3739: document.getElementById(divid).style.display = 'inline-block';
3740: }
3741: setvis = 1;
3742: break;
3743: }
3744: }
3745: }
3746: }
3747: if (setvis == 1) {
3748: break;
3749: }
3750: }
3751: if (!setvis) {
3752: if (document.getElementById(divid)) {
3753: document.getElementById(divid).style.display = 'none';
3754: }
3755: }
1.320 raeburn 3756: }
3757: return;
3758: }
1.405 raeburn 3759:
1.320 raeburn 3760: // ]]>
3761: </script>
3762:
3763: ENDSCRIPT
3764: }
3765:
1.385 raeburn 3766: sub autoupdate_javascript {
3767: return <<"ENDSCRIPT";
3768: <script type="text/javascript">
3769: // <![CDATA[
3770: function toggleLastActiveDays(form) {
3771: var radioname = 'lastactive';
3772: var divid = 'lastactive_div';
3773: var num = form.elements[radioname].length;
3774: if (num) {
3775: var setvis = '';
3776: for (var i=0; i<num; i++) {
3777: if (form.elements[radioname][i].checked) {
3778: if (form.elements[radioname][i].value == '1') {
3779: if (document.getElementById(divid)) {
3780: document.getElementById(divid).style.display = 'inline-block';
3781: }
3782: setvis = 1;
3783: }
3784: break;
3785: }
3786: }
3787: if (!setvis) {
3788: if (document.getElementById(divid)) {
3789: document.getElementById(divid).style.display = 'none';
3790: }
3791: }
3792: }
3793: return;
3794: }
3795: // ]]>
3796: </script>
3797:
3798: ENDSCRIPT
3799: }
3800:
1.399 raeburn 3801: sub autoenroll_javascript {
3802: return <<"ENDSCRIPT";
3803: <script type="text/javascript">
3804: // <![CDATA[
3805: function toggleFailsafe(form) {
3806: var radioname = 'autoenroll_failsafe';
3807: var divid = 'autoenroll_failsafe_div';
3808: var num = form.elements[radioname].length;
3809: if (num) {
3810: var setvis = '';
3811: for (var i=0; i<num; i++) {
3812: if (form.elements[radioname][i].checked) {
3813: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3814: if (document.getElementById(divid)) {
3815: document.getElementById(divid).style.display = 'inline-block';
3816: }
3817: setvis = 1;
3818: }
3819: break;
3820: }
3821: }
3822: if (!setvis) {
3823: if (document.getElementById(divid)) {
3824: document.getElementById(divid).style.display = 'none';
3825: }
3826: }
3827: }
3828: return;
3829: }
3830: // ]]>
3831: </script>
3832:
3833: ENDSCRIPT
3834: }
3835:
1.386 raeburn 3836: sub saml_javascript {
3837: return <<"ENDSCRIPT";
3838: <script type="text/javascript">
3839: // <![CDATA[
3840: function toggleSamlOptions(form,hostid) {
3841: var radioname = 'saml_'+hostid;
3842: var tablecellon = 'samloptionson_'+hostid;
3843: var tablecelloff = 'samloptionsoff_'+hostid;
3844: var num = form.elements[radioname].length;
3845: if (num) {
3846: var setvis = '';
3847: for (var i=0; i<num; i++) {
3848: if (form.elements[radioname][i].checked) {
3849: if (form.elements[radioname][i].value == '1') {
3850: if (document.getElementById(tablecellon)) {
3851: document.getElementById(tablecellon).style.display='';
3852: }
3853: if (document.getElementById(tablecelloff)) {
3854: document.getElementById(tablecelloff).style.display='none';
3855: }
3856: setvis = 1;
3857: }
3858: break;
3859: }
3860: }
3861: if (!setvis) {
3862: if (document.getElementById(tablecellon)) {
3863: document.getElementById(tablecellon).style.display='none';
3864: }
3865: if (document.getElementById(tablecelloff)) {
3866: document.getElementById(tablecelloff).style.display='';
3867: }
3868: }
3869: }
3870: return;
3871: }
3872: // ]]>
3873: </script>
3874:
3875: ENDSCRIPT
3876: }
3877:
1.394 raeburn 3878: sub ipaccess_javascript {
3879: my ($settings) = @_;
3880: my (%ordered,$total,%jstext);
3881: $total = 0;
3882: if (ref($settings) eq 'HASH') {
3883: foreach my $item (keys(%{$settings})) {
3884: if (ref($settings->{$item}) eq 'HASH') {
3885: my $num = $settings->{$item}{'order'};
3886: $ordered{$num} = $item;
3887: }
3888: }
3889: $total = scalar(keys(%{$settings}));
3890: }
3891: my @jsarray = ();
3892: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3893: push(@jsarray,$ordered{$item});
3894: }
3895: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3896: return <<"ENDSCRIPT";
3897: <script type="text/javascript">
3898: // <![CDATA[
3899: function reorderIPaccess(form,item) {
3900: var changedVal;
3901: $jstext
3902: var newpos = 'ipaccess_pos_add';
3903: var maxh = 1 + $total;
3904: var current = new Array;
3905: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3906: if (item == newpos) {
3907: changedVal = newitemVal;
3908: } else {
3909: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3910: current[newitemVal] = newpos;
3911: }
3912: for (var i=0; i<ipaccess.length; i++) {
3913: var elementName = 'ipaccess_pos_'+ipaccess[i];
3914: if (elementName != item) {
3915: if (form.elements[elementName]) {
3916: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3917: current[currVal] = elementName;
3918: }
3919: }
3920: }
3921: var oldVal;
3922: for (var j=0; j<maxh; j++) {
3923: if (current[j] == undefined) {
3924: oldVal = j;
3925: }
3926: }
3927: if (oldVal < changedVal) {
3928: for (var k=oldVal+1; k<=changedVal ; k++) {
3929: var elementName = current[k];
3930: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3931: }
3932: } else {
3933: for (var k=changedVal; k<oldVal; k++) {
3934: var elementName = current[k];
3935: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3936: }
3937: }
3938: return;
3939: }
3940: // ]]>
3941: </script>
3942:
3943: ENDSCRIPT
3944: }
3945:
1.3 raeburn 3946: sub print_autoenroll {
1.30 raeburn 3947: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3948: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3949: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3950: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3951: $failsafesty = 'none';
3952: %failsafechecked = (
3953: off => ' checked="checked"',
3954: );
1.3 raeburn 3955: if (ref($settings) eq 'HASH') {
3956: if (exists($settings->{'run'})) {
3957: if ($settings->{'run'} eq '0') {
3958: $runoff = ' checked="checked" ';
3959: $runon = ' ';
3960: } else {
3961: $runon = ' checked="checked" ';
3962: $runoff = ' ';
3963: }
3964: } else {
3965: if ($autorun) {
3966: $runon = ' checked="checked" ';
3967: $runoff = ' ';
3968: } else {
3969: $runoff = ' checked="checked" ';
3970: $runon = ' ';
3971: }
3972: }
1.129 raeburn 3973: if (exists($settings->{'co-owners'})) {
3974: if ($settings->{'co-owners'} eq '0') {
3975: $coownersoff = ' checked="checked" ';
3976: $coownerson = ' ';
3977: } else {
3978: $coownerson = ' checked="checked" ';
3979: $coownersoff = ' ';
3980: }
3981: } else {
3982: $coownersoff = ' checked="checked" ';
3983: $coownerson = ' ';
3984: }
1.3 raeburn 3985: if (exists($settings->{'sender_domain'})) {
3986: $defdom = $settings->{'sender_domain'};
3987: }
1.399 raeburn 3988: if (exists($settings->{'failsafe'})) {
3989: $failsafe = $settings->{'failsafe'};
3990: if ($failsafe eq 'zero') {
1.400 raeburn 3991: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 3992: $failsafechecked{'off'} = '';
3993: $failsafesty = 'inline-block';
3994: } elsif ($failsafe eq 'any') {
3995: $failsafechecked{'any'} = ' checked="checked"';
3996: $failsafechecked{'off'} = '';
3997: }
3998: $autofailsafe = $settings->{'autofailsafe'};
3999: } elsif (exists($settings->{'autofailsafe'})) {
4000: $autofailsafe = $settings->{'autofailsafe'};
4001: if ($autofailsafe ne '') {
4002: $failsafechecked{'zero'} = ' checked="checked"';
4003: $failsafe = 'zero';
1.400 raeburn 4004: $failsafechecked{'off'} = '';
1.399 raeburn 4005: }
1.274 raeburn 4006: }
1.14 raeburn 4007: } else {
4008: if ($autorun) {
4009: $runon = ' checked="checked" ';
4010: $runoff = ' ';
4011: } else {
4012: $runoff = ' checked="checked" ';
4013: $runon = ' ';
4014: }
1.3 raeburn 4015: }
4016: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4017: my $notif_sender;
4018: if (ref($settings) eq 'HASH') {
4019: $notif_sender = $settings->{'sender_uname'};
4020: }
1.3 raeburn 4021: my $datatable='<tr class="LC_odd_row">'.
4022: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4023: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4024: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4025: $runon.' value="1" />'.&mt('Yes').'</label> '.
4026: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4027: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4028: '</tr><tr>'.
4029: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4030: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4031: &mt('username').': '.
4032: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4033: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4034: ': '.$domform.'</span></td></tr>'.
4035: '<tr class="LC_odd_row">'.
4036: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4037: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4038: '<input type="radio" name="autoassign_coowners"'.
4039: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4040: '<label><input type="radio" name="autoassign_coowners"'.
4041: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4042: '</tr><tr>'.
4043: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4044: '<td class="LC_left_item"><span class="LC_nobreak">'.
4045: '<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> '.
4046: '<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 />'.
4047: '<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>'.
1.399 raeburn 4048: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4049: '<span class="LC_nobreak">'.
4050: &mt('Threshold for number of students in section to drop: [_1]',
4051: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4052: '</span></div></td></tr>';
1.274 raeburn 4053: $$rowtotal += 4;
1.3 raeburn 4054: return $datatable;
4055: }
4056:
4057: sub print_autoupdate {
1.30 raeburn 4058: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4059: my ($enable,$datatable);
1.3 raeburn 4060: if ($position eq 'top') {
1.385 raeburn 4061: my %choices = &Apache::lonlocal::texthash (
4062: run => 'Auto-update active?',
4063: classlists => 'Update information in classlists?',
4064: unexpired => 'Skip updates for users without active or future roles?',
4065: lastactive => 'Skip updates for inactive users?',
4066: );
4067: my $itemcount = 0;
1.3 raeburn 4068: my $updateon = ' ';
4069: my $updateoff = ' checked="checked" ';
4070: if (ref($settings) eq 'HASH') {
4071: if ($settings->{'run'} eq '1') {
4072: $updateon = $updateoff;
4073: $updateoff = ' ';
4074: }
4075: }
1.385 raeburn 4076: $enable = '<tr class="LC_odd_row">'.
4077: '<td>'.$choices{'run'}.'</td>'.
4078: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4079: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4080: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4081: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4082: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4083: '</tr>';
1.385 raeburn 4084: my @toggles = ('classlists','unexpired');
4085: my %defaultchecked = ('classlists' => 'off',
4086: 'unexpired' => 'off'
4087: );
4088: $$rowtotal ++;
4089: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4090: \%choices,$itemcount,'','','left','no');
4091: $datatable = $enable.$datatable;
4092: $$rowtotal += $itemcount;
4093: my $lastactiveon = ' ';
4094: my $lastactiveoff = ' checked="checked" ';
4095: my $lastactivestyle = 'none';
4096: my $lastactivedays;
4097: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4098: if (ref($settings) eq 'HASH') {
4099: if ($settings->{'lastactive'} =~ /^\d+$/) {
4100: $lastactiveon = $lastactiveoff;
4101: $lastactiveoff = ' ';
4102: $lastactivestyle = 'inline-block';
4103: $lastactivedays = $settings->{'lastactive'};
4104: }
4105: }
4106: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4107: $datatable .= '<tr'.$css_class.'>'.
4108: '<td>'.$choices{'lastactive'}.'</td>'.
4109: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4110: '<input type="radio" name="lastactive"'.
4111: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4112: ' <label>'.
4113: '<input type="radio" name="lastactive"'.
4114: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4115: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4116: ': '.&mt('inactive = no activity in last [_1] days',
4117: '<input type="text" size="5" name="lastactivedays" value="'.
4118: $lastactivedays.'" />').
4119: '</span></td>'.
4120: '</tr>';
4121: $$rowtotal ++;
1.131 raeburn 4122: } elsif ($position eq 'middle') {
4123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4124: my $numinrow = 3;
4125: my $locknamesettings;
4126: $datatable .= &insttypes_row($settings,$types,$usertypes,
4127: $dom,$numinrow,$othertitle,
1.305 raeburn 4128: 'lockablenames',$rowtotal);
1.131 raeburn 4129: $$rowtotal ++;
1.3 raeburn 4130: } else {
1.44 raeburn 4131: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4132: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4133: 'permanentemail','id');
1.33 raeburn 4134: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4135: my $numrows = 0;
1.26 raeburn 4136: if (ref($types) eq 'ARRAY') {
4137: if (@{$types} > 0) {
4138: $datatable =
4139: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4140: \@fields,$types,\$numrows);
1.30 raeburn 4141: $$rowtotal += @{$types};
1.26 raeburn 4142: }
1.3 raeburn 4143: }
4144: $datatable .=
4145: &usertype_update_row($settings,{'default' => $othertitle},
4146: \%fieldtitles,\@fields,['default'],
4147: \$numrows);
1.30 raeburn 4148: $$rowtotal ++;
1.3 raeburn 4149: }
4150: return $datatable;
4151: }
4152:
1.125 raeburn 4153: sub print_autocreate {
4154: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4155: my (%createon,%createoff,%currhash);
1.125 raeburn 4156: my @types = ('xml','req');
4157: if (ref($settings) eq 'HASH') {
4158: foreach my $item (@types) {
4159: $createoff{$item} = ' checked="checked" ';
4160: $createon{$item} = ' ';
4161: if (exists($settings->{$item})) {
4162: if ($settings->{$item}) {
4163: $createon{$item} = ' checked="checked" ';
4164: $createoff{$item} = ' ';
4165: }
4166: }
4167: }
1.210 raeburn 4168: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4169: $currhash{$settings->{'xmldc'}} = 1;
4170: }
1.125 raeburn 4171: } else {
4172: foreach my $item (@types) {
4173: $createoff{$item} = ' checked="checked" ';
4174: $createon{$item} = ' ';
4175: }
4176: }
4177: $$rowtotal += 2;
1.191 raeburn 4178: my $numinrow = 2;
1.125 raeburn 4179: my $datatable='<tr class="LC_odd_row">'.
4180: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4181: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4182: '<input type="radio" name="autocreate_xml"'.
4183: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4184: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4185: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4186: '</td></tr><tr>'.
4187: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4188: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4189: '<input type="radio" name="autocreate_req"'.
4190: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4191: '<label><input type="radio" name="autocreate_req"'.
4192: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4193: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4194: 'autocreate_xmldc',%currhash);
1.247 raeburn 4195: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4196: if ($numdc > 1) {
1.247 raeburn 4197: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4198: '</td><td class="LC_left_item">';
1.125 raeburn 4199: } else {
1.247 raeburn 4200: $datatable .= &mt('Course creation processed as:').
4201: '</td><td class="LC_right_item">';
1.125 raeburn 4202: }
1.247 raeburn 4203: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4204: $$rowtotal += $rows;
1.125 raeburn 4205: return $datatable;
4206: }
4207:
1.23 raeburn 4208: sub print_directorysrch {
1.277 raeburn 4209: my ($position,$dom,$settings,$rowtotal) = @_;
4210: my $datatable;
4211: if ($position eq 'top') {
4212: my $instsrchon = ' ';
4213: my $instsrchoff = ' checked="checked" ';
4214: my ($exacton,$containson,$beginson);
4215: my $instlocalon = ' ';
4216: my $instlocaloff = ' checked="checked" ';
4217: if (ref($settings) eq 'HASH') {
4218: if ($settings->{'available'} eq '1') {
4219: $instsrchon = $instsrchoff;
4220: $instsrchoff = ' ';
4221: }
4222: if ($settings->{'localonly'} eq '1') {
4223: $instlocalon = $instlocaloff;
4224: $instlocaloff = ' ';
4225: }
4226: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4227: foreach my $type (@{$settings->{'searchtypes'}}) {
4228: if ($type eq 'exact') {
4229: $exacton = ' checked="checked" ';
4230: } elsif ($type eq 'contains') {
4231: $containson = ' checked="checked" ';
4232: } elsif ($type eq 'begins') {
4233: $beginson = ' checked="checked" ';
4234: }
4235: }
4236: } else {
4237: if ($settings->{'searchtypes'} eq 'exact') {
4238: $exacton = ' checked="checked" ';
4239: } elsif ($settings->{'searchtypes'} eq 'contains') {
4240: $containson = ' checked="checked" ';
4241: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4242: $exacton = ' checked="checked" ';
4243: $containson = ' checked="checked" ';
4244: }
4245: }
1.277 raeburn 4246: }
4247: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4249:
4250: my $numinrow = 4;
4251: my $cansrchrow = 0;
4252: $datatable='<tr class="LC_odd_row">'.
4253: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4254: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4255: '<input type="radio" name="dirsrch_available"'.
4256: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4257: '<label><input type="radio" name="dirsrch_available"'.
4258: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4259: '</tr><tr>'.
4260: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4261: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4262: '<input type="radio" name="dirsrch_instlocalonly"'.
4263: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4264: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4265: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4266: '</tr>';
4267: $$rowtotal += 2;
4268: if (ref($usertypes) eq 'HASH') {
4269: if (keys(%{$usertypes}) > 0) {
4270: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4271: $numinrow,$othertitle,'cansearch',
4272: $rowtotal);
1.277 raeburn 4273: $cansrchrow = 1;
1.25 raeburn 4274: }
1.23 raeburn 4275: }
1.277 raeburn 4276: if ($cansrchrow) {
4277: $$rowtotal ++;
4278: $datatable .= '<tr>';
4279: } else {
4280: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4281: }
1.277 raeburn 4282: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4283: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4284: foreach my $title (@{$titleorder}) {
4285: if (defined($searchtitles->{$title})) {
4286: my $check = ' ';
4287: if (ref($settings) eq 'HASH') {
4288: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4289: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4290: $check = ' checked="checked" ';
4291: }
1.39 raeburn 4292: }
1.25 raeburn 4293: }
1.277 raeburn 4294: $datatable .= '<td class="LC_left_item">'.
4295: '<span class="LC_nobreak"><label>'.
4296: '<input type="checkbox" name="searchby" '.
4297: 'value="'.$title.'"'.$check.'/>'.
4298: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4299: }
4300: }
1.277 raeburn 4301: $datatable .= '</tr></table></td></tr>';
4302: $$rowtotal ++;
4303: if ($cansrchrow) {
4304: $datatable .= '<tr class="LC_odd_row">';
4305: } else {
4306: $datatable .= '<tr>';
4307: }
4308: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4309: '<td class="LC_left_item" colspan="2">'.
4310: '<span class="LC_nobreak"><label>'.
4311: '<input type="checkbox" name="searchtypes" '.
4312: $exacton.' value="exact" />'.&mt('Exact match').
4313: '</label> '.
4314: '<label><input type="checkbox" name="searchtypes" '.
4315: $beginson.' value="begins" />'.&mt('Begins with').
4316: '</label> '.
4317: '<label><input type="checkbox" name="searchtypes" '.
4318: $containson.' value="contains" />'.&mt('Contains').
4319: '</label></span></td></tr>';
4320: $$rowtotal ++;
1.26 raeburn 4321: } else {
1.277 raeburn 4322: my $domsrchon = ' checked="checked" ';
4323: my $domsrchoff = ' ';
4324: my $domlocalon = ' ';
4325: my $domlocaloff = ' checked="checked" ';
4326: if (ref($settings) eq 'HASH') {
4327: if ($settings->{'lclocalonly'} eq '1') {
4328: $domlocalon = $domlocaloff;
4329: $domlocaloff = ' ';
4330: }
4331: if ($settings->{'lcavailable'} eq '0') {
4332: $domsrchoff = $domsrchon;
4333: $domsrchon = ' ';
4334: }
4335: }
4336: $datatable='<tr class="LC_odd_row">'.
4337: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4338: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4339: '<input type="radio" name="dirsrch_domavailable"'.
4340: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4341: '<label><input type="radio" name="dirsrch_domavailable"'.
4342: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4343: '</tr><tr>'.
4344: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4345: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4346: '<input type="radio" name="dirsrch_domlocalonly"'.
4347: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4348: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4349: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4350: '</tr>';
4351: $$rowtotal += 2;
1.26 raeburn 4352: }
1.25 raeburn 4353: return $datatable;
4354: }
4355:
1.28 raeburn 4356: sub print_contacts {
1.286 raeburn 4357: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4358: my $datatable;
4359: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4360: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4361: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4362: if ($position eq 'top') {
4363: if (ref($settings) eq 'HASH') {
4364: foreach my $item (@contacts) {
4365: if (exists($settings->{$item})) {
4366: $to{$item} = $settings->{$item};
4367: }
4368: }
4369: }
4370: } elsif ($position eq 'middle') {
4371: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4372: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4373: foreach my $type (@mailings) {
4374: $otheremails{$type} = '';
4375: }
1.340 raeburn 4376: } elsif ($position eq 'lower') {
4377: if (ref($settings) eq 'HASH') {
4378: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4379: %lonstatus = %{$settings->{'lonstatus'}};
4380: }
4381: }
1.286 raeburn 4382: } else {
4383: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4384: foreach my $type (@mailings) {
4385: $otheremails{$type} = '';
4386: }
1.286 raeburn 4387: $bccemails{'helpdeskmail'} = '';
4388: $bccemails{'otherdomsmail'} = '';
4389: $includestr{'helpdeskmail'} = '';
4390: $includestr{'otherdomsmail'} = '';
4391: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4392: }
1.28 raeburn 4393: if (ref($settings) eq 'HASH') {
1.340 raeburn 4394: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4395: foreach my $type (@mailings) {
4396: if (exists($settings->{$type})) {
4397: if (ref($settings->{$type}) eq 'HASH') {
4398: foreach my $item (@contacts) {
4399: if ($settings->{$type}{$item}) {
4400: $checked{$type}{$item} = ' checked="checked" ';
4401: }
4402: }
4403: $otheremails{$type} = $settings->{$type}{'others'};
4404: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4405: $bccemails{$type} = $settings->{$type}{'bcc'};
4406: if ($settings->{$type}{'include'} ne '') {
4407: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4408: $includestr{$type} = &unescape($includestr{$type});
4409: }
4410: }
4411: }
4412: } elsif ($type eq 'lonstatusmail') {
4413: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4414: }
1.28 raeburn 4415: }
4416: }
1.286 raeburn 4417: if ($position eq 'bottom') {
4418: foreach my $type (@mailings) {
4419: $bccemails{$type} = $settings->{$type}{'bcc'};
4420: if ($settings->{$type}{'include'} ne '') {
4421: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4422: $includestr{$type} = &unescape($includestr{$type});
4423: }
4424: }
4425: if (ref($settings->{'helpform'}) eq 'HASH') {
4426: if (ref($fields) eq 'ARRAY') {
4427: foreach my $field (@{$fields}) {
4428: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4429: }
1.286 raeburn 4430: }
4431: if (exists($settings->{'helpform'}{'maxsize'})) {
4432: $maxsize = $settings->{'helpform'}{'maxsize'};
4433: } else {
1.289 raeburn 4434: $maxsize = '1.0';
1.286 raeburn 4435: }
4436: } else {
4437: if (ref($fields) eq 'ARRAY') {
4438: foreach my $field (@{$fields}) {
4439: $currfield{$field} = 'yes';
1.134 raeburn 4440: }
1.28 raeburn 4441: }
1.286 raeburn 4442: $maxsize = '1.0';
1.28 raeburn 4443: }
4444: }
4445: } else {
1.286 raeburn 4446: if ($position eq 'top') {
4447: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4448: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4449: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4450: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4451: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4452: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4453: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4454: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4455: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4456: } elsif ($position eq 'bottom') {
4457: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4458: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4459: if (ref($fields) eq 'ARRAY') {
4460: foreach my $field (@{$fields}) {
4461: $currfield{$field} = 'yes';
4462: }
4463: }
4464: $maxsize = '1.0';
4465: }
1.28 raeburn 4466: }
4467: my ($titles,$short_titles) = &contact_titles();
4468: my $rownum = 0;
4469: my $css_class;
1.286 raeburn 4470: if ($position eq 'top') {
4471: foreach my $item (@contacts) {
4472: $css_class = $rownum%2?' class="LC_odd_row"':'';
4473: $datatable .= '<tr'.$css_class.'>'.
4474: '<td><span class="LC_nobreak">'.$titles->{$item}.
4475: '</span></td><td class="LC_right_item">'.
4476: '<input type="text" name="'.$item.'" value="'.
4477: $to{$item}.'" /></td></tr>';
4478: $rownum ++;
4479: }
1.315 raeburn 4480: } elsif ($position eq 'bottom') {
4481: $css_class = $rownum%2?' class="LC_odd_row"':'';
4482: $datatable .= '<tr'.$css_class.'>'.
4483: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4484: &mt('(e-mail, subject, and description always shown)').
4485: '</td><td class="LC_left_item">';
4486: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4487: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4488: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4489: foreach my $field (@{$fields}) {
4490: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4491: if (($field eq 'screenshot') || ($field eq 'cc')) {
4492: $datatable .= ' '.&mt('(logged-in users)');
4493: }
4494: $datatable .='</td><td>';
4495: my $clickaction;
4496: if ($field eq 'screenshot') {
4497: $clickaction = ' onclick="screenshotSize(this);"';
4498: }
4499: if (ref($possoptions->{$field}) eq 'ARRAY') {
4500: foreach my $option (@{$possoptions->{$field}}) {
4501: my $checked;
4502: if ($currfield{$field} eq $option) {
4503: $checked = ' checked="checked"';
4504: }
4505: $datatable .= '<span class="LC_nobreak"><label>'.
4506: '<input type="radio" name="helpform_'.$field.'" '.
4507: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4508: '</label></span>'.(' 'x2);
4509: }
4510: }
4511: if ($field eq 'screenshot') {
4512: my $display;
4513: if ($currfield{$field} eq 'no') {
4514: $display = ' style="display:none"';
4515: }
1.334 raeburn 4516: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4517: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4518: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4519: }
4520: $datatable .= '</td></tr>';
4521: }
4522: $datatable .= '</table>';
4523: }
4524: $datatable .= '</td></tr>'."\n";
4525: $rownum ++;
4526: }
1.340 raeburn 4527: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4528: foreach my $type (@mailings) {
4529: $css_class = $rownum%2?' class="LC_odd_row"':'';
4530: $datatable .= '<tr'.$css_class.'>'.
4531: '<td><span class="LC_nobreak">'.
4532: $titles->{$type}.': </span></td>'.
4533: '<td class="LC_left_item">';
4534: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4535: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4536: }
4537: $datatable .= '<span class="LC_nobreak">';
4538: foreach my $item (@contacts) {
4539: $datatable .= '<label>'.
4540: '<input type="checkbox" name="'.$type.'"'.
4541: $checked{$type}{$item}.
4542: ' value="'.$item.'" />'.$short_titles->{$item}.
4543: '</label> ';
4544: }
4545: $datatable .= '</span><br />'.&mt('Others').': '.
4546: '<input type="text" name="'.$type.'_others" '.
4547: 'value="'.$otheremails{$type}.'" />';
4548: my %locchecked;
4549: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4550: foreach my $loc ('s','b') {
4551: if ($includeloc{$type} eq $loc) {
4552: $locchecked{$loc} = ' checked="checked"';
4553: last;
4554: }
4555: }
4556: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4557: '<input type="text" name="'.$type.'_bcc" '.
4558: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4559: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4560: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4561: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4562: '<span class="LC_nobreak">'.&mt('Location:').' '.
4563: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4564: (' 'x2).
4565: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4566: '</span></fieldset>';
4567: }
4568: $datatable .= '</td></tr>'."\n";
4569: $rownum ++;
4570: }
1.28 raeburn 4571: }
1.286 raeburn 4572: if ($position eq 'middle') {
4573: my %choices;
1.340 raeburn 4574: my $corelink = &core_link_msu();
4575: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4576: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4577: $corelink);
4578: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4579: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4580: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4581: 'reportupdates' => 'on',
4582: 'reportstatus' => 'on');
1.286 raeburn 4583: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4584: \%choices,$rownum);
4585: $datatable .= $reports;
1.340 raeburn 4586: } elsif ($position eq 'lower') {
1.378 raeburn 4587: my (%current,%excluded,%weights);
1.340 raeburn 4588: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4589: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4590: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4591: } else {
1.378 raeburn 4592: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4593: }
4594: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4595: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4596: } else {
1.378 raeburn 4597: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4598: }
4599: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4600: foreach my $type ('E','W','N','U') {
1.340 raeburn 4601: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4602: $weights{$type} = $lonstatus{'weights'}{$type};
4603: } else {
4604: $weights{$type} = $defaults->{$type};
4605: }
4606: }
4607: } else {
1.341 raeburn 4608: foreach my $type ('E','W','N','U') {
1.340 raeburn 4609: $weights{$type} = $defaults->{$type};
4610: }
4611: }
4612: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4613: if (@{$lonstatus{'excluded'}} > 0) {
4614: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4615: }
4616: }
1.378 raeburn 4617: foreach my $item ('errorthreshold','errorsysmail') {
4618: $css_class = $rownum%2?' class="LC_odd_row"':'';
4619: $datatable .= '<tr'.$css_class.'>'.
4620: '<td class="LC_left_item"><span class="LC_nobreak">'.
4621: $titles->{$item}.
4622: '</span></td><td class="LC_left_item">'.
4623: '<input type="text" name="'.$item.'" value="'.
4624: $current{$item}.'" size="5" /></td></tr>';
4625: $rownum ++;
4626: }
1.340 raeburn 4627: $css_class = $rownum%2?' class="LC_odd_row"':'';
4628: $datatable .= '<tr'.$css_class.'>'.
4629: '<td class="LC_left_item">'.
4630: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4631: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4632: foreach my $type ('E','W','N','U') {
1.340 raeburn 4633: $datatable .= '<td>'.$names->{$type}.'<br />'.
4634: '<input type="text" name="errorweights_'.$type.'" value="'.
4635: $weights{$type}.'" size="5" /></td>';
4636: }
4637: $datatable .= '</tr></table></tr>';
4638: $rownum ++;
4639: $css_class = $rownum%2?' class="LC_odd_row"':'';
4640: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4641: $titles->{'errorexcluded'}.'</td>'.
4642: '<td class="LC_left_item"><table>';
4643: my $numinrow = 4;
4644: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4645: for (my $i=0; $i<@ids; $i++) {
4646: my $rem = $i%($numinrow);
4647: if ($rem == 0) {
4648: if ($i > 0) {
4649: $datatable .= '</tr>';
4650: }
4651: $datatable .= '<tr>';
4652: }
4653: my $check;
4654: if ($excluded{$ids[$i]}) {
4655: $check = ' checked="checked" ';
4656: }
4657: $datatable .= '<td class="LC_left_item">'.
4658: '<span class="LC_nobreak"><label>'.
4659: '<input type="checkbox" name="errorexcluded" '.
4660: 'value="'.$ids[$i].'"'.$check.' />'.
4661: $ids[$i].'</label></span></td>';
4662: }
4663: my $colsleft = $numinrow - @ids%($numinrow);
4664: if ($colsleft > 1 ) {
4665: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4666: ' </td>';
4667: } elsif ($colsleft == 1) {
4668: $datatable .= '<td class="LC_left_item"> </td>';
4669: }
4670: $datatable .= '</tr></table></td></tr>';
4671: $rownum ++;
1.286 raeburn 4672: } elsif ($position eq 'bottom') {
1.315 raeburn 4673: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4674: my (@posstypes,%usertypeshash);
4675: if (ref($types) eq 'ARRAY') {
4676: @posstypes = @{$types};
4677: }
4678: if (@posstypes) {
4679: if (ref($usertypes) eq 'HASH') {
4680: %usertypeshash = %{$usertypes};
4681: }
4682: my @overridden;
4683: my $numinrow = 4;
4684: if (ref($settings) eq 'HASH') {
4685: if (ref($settings->{'overrides'}) eq 'HASH') {
4686: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4687: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4688: push(@overridden,$key);
4689: foreach my $item (@contacts) {
4690: if ($settings->{'overrides'}{$key}{$item}) {
4691: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4692: }
4693: }
4694: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4695: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4696: $includeloc{'override_'.$key} = '';
4697: $includestr{'override_'.$key} = '';
4698: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4699: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4700: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4701: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4702: }
1.286 raeburn 4703: }
4704: }
4705: }
1.315 raeburn 4706: }
4707: my $customclass = 'LC_helpdesk_override';
4708: my $optionsprefix = 'LC_options_helpdesk_';
4709:
4710: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4711:
4712: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4713: $numinrow,$othertitle,'overrides',
4714: \$rownum,$onclicktypes,$customclass);
4715: $rownum ++;
4716: $usertypeshash{'default'} = $othertitle;
4717: foreach my $status (@posstypes) {
4718: my $css_class;
4719: if ($rownum%2) {
4720: $css_class = 'LC_odd_row ';
4721: }
4722: $css_class .= $customclass;
4723: my $rowid = $optionsprefix.$status;
4724: my $hidden = 1;
4725: my $currstyle = 'display:none';
4726: if (grep(/^\Q$status\E$/,@overridden)) {
4727: $currstyle = 'display:table-row';
4728: $hidden = 0;
4729: }
4730: my $key = 'override_'.$status;
4731: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4732: $includeloc{$key},$includestr{$key},$status,$rowid,
4733: $usertypeshash{$status},$css_class,$currstyle,
4734: \@contacts,$short_titles);
4735: unless ($hidden) {
4736: $rownum ++;
1.286 raeburn 4737: }
4738: }
1.134 raeburn 4739: }
1.28 raeburn 4740: }
1.30 raeburn 4741: $$rowtotal += $rownum;
1.28 raeburn 4742: return $datatable;
4743: }
4744:
1.340 raeburn 4745: sub core_link_msu {
4746: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4747: &mt('LON-CAPA core group - MSU'),600,500);
4748: }
4749:
1.315 raeburn 4750: sub overridden_helpdesk {
4751: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4752: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4753: my $class = 'LC_left_item';
4754: if ($css_class) {
4755: $css_class = ' class="'.$css_class.'"';
4756: }
4757: if ($rowid) {
4758: $rowid = ' id="'.$rowid.'"';
4759: }
4760: if ($rowstyle) {
4761: $rowstyle = ' style="'.$rowstyle.'"';
4762: }
4763: my ($output,$description);
4764: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4765: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4766: "<td>$description</td>\n".
4767: '<td class="'.$class.'" colspan="2">'.
4768: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4769: '<span class="LC_nobreak">';
4770: if (ref($contacts) eq 'ARRAY') {
4771: foreach my $item (@{$contacts}) {
4772: my $check;
4773: if (ref($checked) eq 'HASH') {
4774: $check = $checked->{$item};
4775: }
4776: my $title;
4777: if (ref($short_titles) eq 'HASH') {
4778: $title = $short_titles->{$item};
4779: }
4780: $output .= '<label>'.
4781: '<input type="checkbox" name="override_'.$type.'"'.$check.
4782: ' value="'.$item.'" />'.$title.'</label> ';
4783: }
4784: }
4785: $output .= '</span><br />'.&mt('Others').': '.
4786: '<input type="text" name="override_'.$type.'_others" '.
4787: 'value="'.$otheremails.'" />';
4788: my %locchecked;
4789: foreach my $loc ('s','b') {
4790: if ($includeloc eq $loc) {
4791: $locchecked{$loc} = ' checked="checked"';
4792: last;
4793: }
4794: }
4795: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4796: '<input type="text" name="override_'.$type.'_bcc" '.
4797: 'value="'.$bccemails.'" /></fieldset>'.
4798: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4799: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4800: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4801: '<span class="LC_nobreak">'.&mt('Location:').' '.
4802: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4803: (' 'x2).
4804: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4805: '</span></fieldset>'.
4806: '</td></tr>'."\n";
4807: return $output;
4808: }
4809:
1.286 raeburn 4810: sub contacts_javascript {
4811: return <<"ENDSCRIPT";
4812:
4813: <script type="text/javascript">
4814: // <![CDATA[
4815:
4816: function screenshotSize(field) {
4817: if (document.getElementById('help_screenshotsize')) {
4818: if (field.value == 'no') {
1.289 raeburn 4819: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4820: } else {
4821: document.getElementById('help_screenshotsize').style.display="";
4822: }
4823: }
4824: return;
4825: }
4826:
1.315 raeburn 4827: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4828: if (form.elements[checkbox].length != undefined) {
4829: var count = 0;
4830: if (docount) {
4831: for (var i=0; i<form.elements[checkbox].length; i++) {
4832: if (form.elements[checkbox][i].checked) {
4833: count ++;
4834: }
4835: }
4836: }
4837: for (var i=0; i<form.elements[checkbox].length; i++) {
4838: var type = form.elements[checkbox][i].value;
4839: if (document.getElementById(prefix+type)) {
4840: if (form.elements[checkbox][i].checked) {
4841: document.getElementById(prefix+type).style.display = 'table-row';
4842: if (count % 2 == 1) {
4843: document.getElementById(prefix+type).className = target+' LC_odd_row';
4844: } else {
4845: document.getElementById(prefix+type).className = target;
4846: }
4847: count ++;
4848: } else {
4849: document.getElementById(prefix+type).style.display = 'none';
4850: }
4851: }
4852: }
4853: }
4854: return;
4855: }
4856:
4857:
1.286 raeburn 4858: // ]]>
4859: </script>
4860:
4861: ENDSCRIPT
4862: }
4863:
1.118 jms 4864: sub print_helpsettings {
1.282 raeburn 4865: my ($position,$dom,$settings,$rowtotal) = @_;
4866: my $confname = $dom.'-domainconfig';
1.285 raeburn 4867: my $formname = 'display';
1.168 raeburn 4868: my ($datatable,$itemcount);
1.282 raeburn 4869: if ($position eq 'top') {
4870: $itemcount = 1;
4871: my (%choices,%defaultchecked,@toggles);
4872: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4873: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4874: &mt('LON-CAPA bug tracker'),600,500));
4875: %defaultchecked = ('submitbugs' => 'on');
4876: @toggles = ('submitbugs');
4877: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4878: \%choices,$itemcount);
4879: $$rowtotal ++;
4880: } else {
4881: my $css_class;
4882: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4883: my (%customroles,%ordered,%current);
1.301 raeburn 4884: if (ref($settings) eq 'HASH') {
4885: if (ref($settings->{'adhoc'}) eq 'HASH') {
4886: %current = %{$settings->{'adhoc'}};
4887: }
1.285 raeburn 4888: }
4889: my $count = 0;
4890: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4891: if ($key=~/^rolesdef\_(\w+)$/) {
4892: my $rolename = $1;
1.285 raeburn 4893: my (%privs,$order);
1.282 raeburn 4894: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4895: $customroles{$rolename} = \%privs;
1.285 raeburn 4896: if (ref($current{$rolename}) eq 'HASH') {
4897: $order = $current{$rolename}{'order'};
4898: }
4899: if ($order eq '') {
4900: $order = $count;
4901: }
4902: $ordered{$order} = $rolename;
4903: $count++;
4904: }
4905: }
4906: my $maxnum = scalar(keys(%ordered));
4907: my @roles_by_num = ();
4908: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4909: push(@roles_by_num,$item);
4910: }
4911: my $context = 'domprefs';
4912: my $crstype = 'Course';
4913: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4914: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4915: my ($numstatustypes,@jsarray);
4916: if (ref($types) eq 'ARRAY') {
4917: if (@{$types} > 0) {
4918: $numstatustypes = scalar(@{$types});
4919: push(@accesstypes,'status');
4920: @jsarray = ('bystatus');
1.282 raeburn 4921: }
4922: }
1.290 raeburn 4923: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4924: if (keys(%domhelpdesk)) {
4925: push(@accesstypes,('inc','exc'));
4926: push(@jsarray,('notinc','notexc'));
4927: }
4928: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4929: my $context = 'domprefs';
4930: my $crstype = 'Course';
1.285 raeburn 4931: my $prefix = 'helproles_';
4932: my $add_class = 'LC_hidden';
4933: foreach my $num (@roles_by_num) {
4934: my $role = $ordered{$num};
4935: my ($desc,$access,@statuses);
4936: if (ref($current{$role}) eq 'HASH') {
4937: $desc = $current{$role}{'desc'};
4938: $access = $current{$role}{'access'};
4939: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4940: @statuses = @{$current{$role}{'insttypes'}};
4941: }
4942: }
4943: if ($desc eq '') {
4944: $desc = $role;
4945: }
4946: my $identifier = 'custhelp'.$num;
1.282 raeburn 4947: my %full=();
4948: my %levels= (
4949: course => {},
4950: domain => {},
4951: system => {},
4952: );
4953: my %levelscurrent=(
4954: course => {},
4955: domain => {},
4956: system => {},
4957: );
4958: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4959: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4960: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 4961: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 4962: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 4963: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4964: for (my $k=0; $k<=$maxnum; $k++) {
4965: my $vpos = $k+1;
4966: my $selstr;
4967: if ($k == $num) {
4968: $selstr = ' selected="selected" ';
4969: }
4970: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4971: }
4972: $datatable .= '</select>'.(' 'x2).
4973: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4974: '</td>'.
4975: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4976: &mt('Name shown to users:').
4977: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4978: '</fieldset>'.
4979: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4980: $othertitle,$usertypes,$types,\%domhelpdesk).
4981: '<fieldset>'.
4982: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 4983: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 4984: \%levelscurrent,$identifier,
4985: 'LC_hidden',$prefix.$num.'_privs').
4986: '</fieldset></td>';
1.282 raeburn 4987: $itemcount ++;
4988: }
4989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4990: my $newcust = 'custhelp'.$count;
4991: my (%privs,%levelscurrent);
4992: my %full=();
4993: my %levels= (
4994: course => {},
4995: domain => {},
4996: system => {},
4997: );
4998: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4999: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5000: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5001: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5002: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5003: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5004: for (my $k=0; $k<$maxnum+1; $k++) {
5005: my $vpos = $k+1;
5006: my $selstr;
5007: if ($k == $maxnum) {
5008: $selstr = ' selected="selected" ';
5009: }
5010: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5011: }
5012: $datatable .= '</select> '."\n".
1.282 raeburn 5013: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5014: '</label></span></td>'.
1.285 raeburn 5015: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5016: '<span class="LC_nobreak">'.
5017: &mt('Internal name:').
5018: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5019: '</span>'.(' 'x4).
5020: '<span class="LC_nobreak">'.
5021: &mt('Name shown to users:').
5022: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5023: '</span></fieldset>'.
5024: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5025: $usertypes,$types,\%domhelpdesk).
5026: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5027: &Apache::lonuserutils::custom_role_header($context,$crstype,
5028: \@templateroles,$newcust).
5029: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5030: \%levelscurrent,$newcust).
1.334 raeburn 5031: '</fieldset>'.
5032: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5033: '</td></tr>';
1.282 raeburn 5034: $count ++;
5035: $$rowtotal += $count;
5036: }
1.166 raeburn 5037: return $datatable;
1.121 raeburn 5038: }
5039:
1.285 raeburn 5040: sub adhocbutton {
5041: my ($prefix,$num,$field,$visibility) = @_;
5042: my %lt = &Apache::lonlocal::texthash(
5043: show => 'Show details',
5044: hide => 'Hide details',
5045: );
5046: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5047: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5048: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5049: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5050: }
5051:
5052: sub helpsettings_javascript {
5053: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5054: return unless(ref($roles_by_num) eq 'ARRAY');
5055: my %html_js_lt = &Apache::lonlocal::texthash(
5056: show => 'Show details',
5057: hide => 'Hide details',
5058: );
5059: &html_escape(\%html_js_lt);
5060: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5061: return <<"ENDSCRIPT";
5062: <script type="text/javascript">
5063: // <![CDATA[
5064:
5065: function reorderHelpRoles(form,item) {
5066: var changedVal;
5067: $jstext
5068: var newpos = 'helproles_${total}_pos';
5069: var maxh = 1 + $total;
5070: var current = new Array();
5071: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5072: if (item == newpos) {
5073: changedVal = newitemVal;
5074: } else {
5075: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5076: current[newitemVal] = newpos;
5077: }
5078: for (var i=0; i<helproles.length; i++) {
5079: var elementName = 'helproles_'+helproles[i]+'_pos';
5080: if (elementName != item) {
5081: if (form.elements[elementName]) {
5082: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5083: current[currVal] = elementName;
5084: }
5085: }
5086: }
5087: var oldVal;
5088: for (var j=0; j<maxh; j++) {
5089: if (current[j] == undefined) {
5090: oldVal = j;
5091: }
5092: }
5093: if (oldVal < changedVal) {
5094: for (var k=oldVal+1; k<=changedVal ; k++) {
5095: var elementName = current[k];
5096: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5097: }
5098: } else {
5099: for (var k=changedVal; k<oldVal; k++) {
5100: var elementName = current[k];
5101: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5102: }
5103: }
5104: return;
5105: }
5106:
5107: function helpdeskAccess(num) {
5108: var curraccess = null;
5109: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5110: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5111: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5112: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5113: }
5114: }
5115: }
5116: var shown = Array();
5117: var hidden = Array();
5118: if (curraccess == 'none') {
5119: hidden = Array('$hiddenstr');
5120: } else {
5121: if (curraccess == 'status') {
5122: shown = Array('bystatus');
5123: hidden = Array('notinc','notexc');
5124: } else {
5125: if (curraccess == 'exc') {
5126: shown = Array('notexc');
5127: hidden = Array('notinc','bystatus');
5128: }
5129: if (curraccess == 'inc') {
5130: shown = Array('notinc');
5131: hidden = Array('notexc','bystatus');
5132: }
1.293 raeburn 5133: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5134: hidden = Array('notinc','notexc','bystatus');
5135: }
5136: }
5137: }
5138: if (hidden.length > 0) {
5139: for (var i=0; i<hidden.length; i++) {
5140: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5141: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5142: }
5143: }
5144: }
5145: if (shown.length > 0) {
5146: for (var i=0; i<shown.length; i++) {
5147: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5148: if (shown[i] == 'privs') {
5149: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5150: } else {
5151: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5152: }
5153: }
5154: }
5155: }
5156: return;
5157: }
5158:
5159: function toggleHelpdeskItem(num,field) {
5160: if (document.getElementById('helproles_'+num+'_'+field)) {
5161: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5162: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5163: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5164: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5165: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5166: }
5167: } else {
5168: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5169: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5170: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5171: }
5172: }
5173: }
5174: return;
5175: }
5176:
5177: // ]]>
5178: </script>
5179:
5180: ENDSCRIPT
5181: }
5182:
5183: sub helpdeskroles_access {
5184: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5185: $usertypes,$types,$domhelpdesk) = @_;
5186: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5187: my %lt = &Apache::lonlocal::texthash(
5188: 'rou' => 'Role usage',
5189: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5190: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5191: 'dh' => 'All with domain helpdesk role',
5192: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5193: 'none' => 'None',
5194: 'status' => 'Determined based on institutional status',
5195: 'inc' => 'Include all, but exclude specific personnel',
5196: 'exc' => 'Exclude all, but include specific personnel',
5197: );
5198: my %usecheck = (
5199: all => ' checked="checked"',
5200: );
5201: my %displaydiv = (
5202: status => 'none',
5203: inc => 'none',
5204: exc => 'none',
5205: priv => 'block',
5206: );
5207: my $output;
5208: if (ref($current) eq 'HASH') {
5209: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5210: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5211: $usecheck{$current->{access}} = $usecheck{'all'};
5212: delete($usecheck{'all'});
5213: if ($current->{access} =~ /^(status|inc|exc)$/) {
5214: my $access = $1;
5215: $displaydiv{$access} = 'inline';
5216: } elsif ($current->{access} eq 'none') {
5217: $displaydiv{'priv'} = 'none';
5218: }
5219: }
5220: }
5221: }
5222: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5223: '<p>'.$lt{'whi'}.'</p>';
5224: foreach my $access (@{$accesstypes}) {
5225: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5226: ' onclick="helpdeskAccess('."'$num'".');" />'.
5227: $lt{$access}.'</label>';
5228: if ($access eq 'status') {
5229: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5230: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5231: $othertitle,$usertypes,$types).
5232: '</div>';
5233: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5234: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5235: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5236: '</div>';
5237: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5238: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5239: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5240: '</div>';
5241: }
5242: $output .= '</p>';
5243: }
5244: $output .= '</fieldset>';
5245: return $output;
5246: }
5247:
1.121 raeburn 5248: sub radiobutton_prefs {
1.192 raeburn 5249: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5250: $additional,$align,$firstval) = @_;
1.121 raeburn 5251: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5252: (ref($choices) eq 'HASH'));
5253:
1.170 raeburn 5254: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5255:
5256: foreach my $item (@{$toggles}) {
5257: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5258: $checkedon{$item} = ' checked="checked" ';
5259: $checkedoff{$item} = ' ';
1.121 raeburn 5260: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5261: $checkedoff{$item} = ' checked="checked" ';
5262: $checkedon{$item} = ' ';
5263: }
5264: }
5265: if (ref($settings) eq 'HASH') {
1.121 raeburn 5266: foreach my $item (@{$toggles}) {
1.118 jms 5267: if ($settings->{$item} eq '1') {
5268: $checkedon{$item} = ' checked="checked" ';
5269: $checkedoff{$item} = ' ';
5270: } elsif ($settings->{$item} eq '0') {
5271: $checkedoff{$item} = ' checked="checked" ';
5272: $checkedon{$item} = ' ';
5273: }
5274: }
1.121 raeburn 5275: }
1.192 raeburn 5276: if ($onclick) {
5277: $onclick = ' onclick="'.$onclick.'"';
5278: }
1.121 raeburn 5279: foreach my $item (@{$toggles}) {
1.118 jms 5280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5281: $datatable .=
1.306 raeburn 5282: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5283: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5284: '</span></td>';
5285: if ($align eq 'left') {
5286: $datatable .= '<td class="LC_left_item">';
5287: } else {
5288: $datatable .= '<td class="LC_right_item">';
5289: }
1.385 raeburn 5290: $datatable .= '<span class="LC_nobreak">';
5291: if ($firstval eq 'no') {
5292: $datatable .=
5293: '<label><input type="radio" name="'.
5294: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5295: '</label> <label><input type="radio" name="'.$item.'" '.
5296: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5297: } else {
5298: $datatable .=
5299: '<label><input type="radio" name="'.
5300: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5301: '</label> <label><input type="radio" name="'.$item.'" '.
5302: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5303: }
5304: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5305: $itemcount ++;
1.121 raeburn 5306: }
5307: return ($datatable,$itemcount);
5308: }
5309:
1.267 raeburn 5310: sub print_ltitools {
1.421 raeburn 5311: my ($position,$dom,$settings,$rowtotal) = @_;
5312: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5313: if (ref($settings) eq 'HASH') {
1.421 raeburn 5314: if ($position eq 'top') {
5315: if (exists($settings->{'encrypt'})) {
5316: if (ref($settings->{'encrypt'}) eq 'HASH') {
5317: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5318: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5319: }
5320: }
1.267 raeburn 5321: }
1.421 raeburn 5322: if (exists($settings->{'private'})) {
5323: if (ref($settings->{'private'}) eq 'HASH') {
5324: if (ref($settings->{'private'}) eq 'HASH') {
5325: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5326: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5327: }
5328: }
5329: }
5330: }
1.421 raeburn 5331: } elsif ($position eq 'middle') {
5332: if (exists($settings->{'rules'})) {
5333: if (ref($settings->{'rules'}) eq 'HASH') {
5334: %rules = %{$settings->{'rules'}};
1.273 raeburn 5335: }
5336: }
1.421 raeburn 5337: } else {
5338: foreach my $key ('encrypt','private','rules') {
5339: if (exists($settings->{$key})) {
5340: delete($settings->{$key});
1.267 raeburn 5341: }
5342: }
5343: }
5344: }
1.421 raeburn 5345: my $datatable;
5346: my $itemcount = 1;
5347: if ($position eq 'top') {
5348: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5349: } elsif ($position eq 'middle') {
5350: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5351: $$rowtotal += $itemcount;
5352: } else {
5353: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5354: }
5355: return $datatable;
5356: }
5357:
5358: sub ltitools_names {
5359: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5360: 'title' => 'Title',
5361: 'version' => 'Version',
5362: 'msgtype' => 'Message Type',
1.323 raeburn 5363: 'sigmethod' => 'Signature Method',
1.296 raeburn 5364: 'url' => 'URL',
5365: 'key' => 'Key',
1.322 raeburn 5366: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5367: 'secret' => 'Secret',
5368: 'icon' => 'Icon',
1.324 raeburn 5369: 'user' => 'User',
1.296 raeburn 5370: 'fullname' => 'Full Name',
5371: 'firstname' => 'First Name',
5372: 'lastname' => 'Last Name',
5373: 'email' => 'E-mail',
5374: 'roles' => 'Role',
1.298 raeburn 5375: 'window' => 'Window',
5376: 'tab' => 'Tab',
1.296 raeburn 5377: 'iframe' => 'iFrame',
5378: 'height' => 'Height',
5379: 'width' => 'Width',
5380: 'linktext' => 'Default Link Text',
5381: 'explanation' => 'Default Explanation',
5382: 'passback' => 'Tool can return grades:',
5383: 'roster' => 'Tool can retrieve roster:',
5384: 'crstarget' => 'Display target',
5385: 'crslabel' => 'Course label',
5386: 'crstitle' => 'Course title',
5387: 'crslinktext' => 'Link Text',
5388: 'crsexplanation' => 'Explanation',
1.318 raeburn 5389: 'crsappend' => 'Provider URL',
1.267 raeburn 5390: );
5391: return %lt;
5392: }
5393:
1.421 raeburn 5394: sub secrets_form {
5395: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5396: my @ids=&Apache::lonnet::current_machine_ids();
5397: my %servers = &Apache::lonnet::get_servers($dom,'library');
5398: my $primary = &Apache::lonnet::domain($dom,'primary');
5399: my ($css_class,$extra,$numshown,$itemcount,$output);
5400: $itemcount = 0;
5401: foreach my $hostid (sort(keys(%servers))) {
5402: my ($showextra,$divsty,$switch);
5403: if ($hostid eq $primary) {
5404: if ($context eq 'ltisec') {
5405: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5406: $showextra = 1;
5407: }
5408: if ($encrypt->{'ltisec_crslinkprot'}) {
5409: $showextra = 1;
5410: }
5411: } else {
5412: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5413: $showextra = 1;
5414: }
5415: }
5416: unless (grep(/^\Q$hostid\E$/,@ids)) {
5417: $switch = 1;
5418: }
5419: if ($showextra) {
5420: $numshown ++;
5421: $divsty = 'display:inline-block';
5422: } else {
5423: $divsty = 'display:none';
5424: }
5425: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5426: '<legend>'.$hostid.'</legend>';
5427: if ($switch) {
5428: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5429: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5430: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5431: if (exists($privkeys->{$hostid})) {
5432: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5433: '<span class="LC_nobreak">'.
5434: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5435: '<span class="LC_nobreak">'.&mt('Change?').
5436: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5437: (' 'x2).
5438: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5439: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5440: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5441: '</span></div>';
5442: } else {
5443: $extra .= '<span class="LC_nobreak">'.
5444: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5445: '</span>'."\n";
5446: }
5447: } elsif (exists($privkeys->{$hostid})) {
5448: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5449: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5450: '<span class="LC_nobreak">'.&mt('Change?').
5451: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5452: (' 'x2).
5453: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5454: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5455: '<span class="LC_nobreak">'.&mt('New Key').':'.
5456: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5457: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5458: '</span></div>';
5459: } else {
5460: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5461: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5462: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5463: }
5464: $extra .= '</fieldset>';
5465: }
5466: }
5467: my (%choices,@toggles,%defaultchecked);
5468: if ($context eq 'ltisec') {
5469: %choices = &Apache::lonlocal::texthash (
5470: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5471: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5472: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5473: );
5474: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5475: %defaultchecked = (
5476: 'ltisec_crslinkprot' => 'off',
5477: 'ltisec_domlinkprot' => 'off',
5478: 'ltisec_consumers' => 'off',
5479: );
5480: } else {
5481: %choices = &Apache::lonlocal::texthash (
5482: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5483: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5484: );
5485: @toggles = qw(toolsec_crs toolsec_dom);
5486: %defaultchecked = (
5487: 'toolsec_crs' => 'off',
5488: 'toolsec_dom' => 'off',
5489: );
5490: }
5491: my ($onclick,$itemcount);
5492: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5493: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5494: \%choices,$itemcount,$onclick,'','left','no');
5495:
5496: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5497: my $noprivkeysty = 'display:inline-block';
5498: if ($numshown) {
5499: $noprivkeysty = 'display:none';
5500: }
5501: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5502: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5503: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5504: $extra.
5505: '</td></tr>';
5506: $itemcount ++;
5507: $$rowtotal += $itemcount;
5508: return $output;
5509: }
5510:
1.372 raeburn 5511: sub print_proctoring {
5512: my ($dom,$settings,$rowtotal) = @_;
5513: my $itemcount = 1;
5514: my (%ordered,%providernames,%current,%currentdef);
5515: my $confname = $dom.'-domainconfig';
5516: my $switchserver = &check_switchserver($dom,$confname);
5517: if (ref($settings) eq 'HASH') {
5518: foreach my $item (keys(%{$settings})) {
5519: if (ref($settings->{$item}) eq 'HASH') {
5520: my $num = $settings->{$item}{'order'};
5521: $ordered{$num} = $item;
5522: }
5523: }
5524: } else {
5525: %ordered = (
5526: 1 => 'proctorio',
5527: 2 => 'examity',
5528: );
5529: }
5530: %providernames = &proctoring_providernames();
5531: my $maxnum = scalar(keys(%ordered));
5532: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5533: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5534: if (ref($requref) eq 'HASH') {
5535: %requserfields = %{$requref};
5536: }
5537: if (ref($opturef) eq 'HASH') {
5538: %optuserfields = %{$opturef};
5539: }
5540: if (ref($defref) eq 'HASH') {
5541: %defaults = %{$defref};
5542: }
5543: if (ref($extref) eq 'HASH') {
5544: %extended = %{$extref};
5545: }
5546: if (ref($crsref) eq 'HASH') {
5547: %crsconf = %{$crsref};
5548: }
5549: if (ref($rolesref) eq 'ARRAY') {
5550: @courseroles = @{$rolesref};
5551: }
5552: if (ref($ltiref) eq 'ARRAY') {
5553: @ltiroles = @{$ltiref};
5554: }
5555: my $datatable;
5556: my $css_class;
5557: if (keys(%ordered)) {
5558: my @items = sort { $a <=> $b } keys(%ordered);
5559: for (my $i=0; $i<@items; $i++) {
5560: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5561: my $provider = $ordered{$items[$i]};
5562: my $optionsty = 'none';
5563: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5564: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5565: if (ref($settings) eq 'HASH') {
5566: if (ref($settings->{$provider}) eq 'HASH') {
5567: %current = %{$settings->{$provider}};
5568: if ($current{'available'}) {
5569: $optionsty = 'block';
5570: $available = 1;
5571: }
5572: if ($current{'lifetime'} =~ /^\d+$/) {
5573: $lifetime = $current{'lifetime'};
5574: }
5575: if ($current{'version'} =~ /^\d+\.\d+$/) {
5576: $version = $current{'version'};
5577: }
5578: if ($current{'image'} ne '') {
5579: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5580: }
5581: if (ref($current{'fields'}) eq 'ARRAY') {
5582: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5583: }
5584: $userincdom = $current{'incdom'};
5585: if (ref($current{'roles'}) eq 'HASH') {
5586: %rolemaps = %{$current{'roles'}};
5587: $checkedfields{'roles'} = 1;
5588: }
5589: if (ref($current{'defaults'}) eq 'ARRAY') {
5590: foreach my $val (@{$current{'defaults'}}) {
5591: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5592: $inuse{$val} = 1;
5593: } else {
5594: foreach my $poss (keys(%{$extended{$provider}})) {
5595: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5596: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5597: $inuse{$poss} = $val;
5598: last;
5599: }
5600: }
5601: }
5602: }
5603: }
5604: } elsif (ref($current{'defaults'}) eq 'HASH') {
5605: foreach my $key (keys(%{$current{'defaults'}})) {
5606: my $currval = $current{'defaults'}{$key};
5607: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5608: $inuse{$key} = 1;
5609: } else {
5610: my $match;
5611: foreach my $poss (keys(%{$extended{$provider}})) {
5612: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5613: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5614: $inuse{$poss} = $key;
5615: last;
5616: }
5617: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5618: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5619: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5620: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5621: $currentdef{$inner} = $currval;
5622: $match = 1;
5623: last;
5624: }
5625: } elsif ($inner eq $key) {
5626: $currentdef{$key} = $currval;
5627: $match = 1;
5628: last;
5629: }
5630: }
5631: }
5632: last if ($match);
5633: }
5634: }
5635: }
5636: }
5637: if (ref($current{'crsconf'}) eq 'ARRAY') {
5638: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5639: }
5640: }
5641: }
5642: my %lt = &proctoring_titles($provider);
5643: my %fieldtitles = &proctoring_fieldtitles($provider);
5644: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5645: my %checkedavailable = (
5646: yes => '',
5647: no => ' checked="checked"',
5648: );
5649: if ($available) {
5650: $checkedavailable{'yes'} = $checkedavailable{'no'};
5651: $checkedavailable{'no'} = '';
5652: }
5653: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5654: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5655: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5656: for (my $k=0; $k<$maxnum; $k++) {
5657: my $vpos = $k+1;
5658: my $selstr;
5659: if ($k == $i) {
5660: $selstr = ' selected="selected" ';
5661: }
5662: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5663: }
5664: if ($version eq '') {
5665: if ($provider eq 'proctorio') {
5666: $version = '1.0';
5667: } elsif ($provider eq 'examity') {
5668: $version = '1.1';
5669: }
5670: }
5671: if ($lifetime eq '') {
5672: $lifetime = '300';
5673: }
5674: $datatable .=
5675: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5676: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5677: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5678: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5679: '</td>'.
5680: '<td colspan="2">'.
5681: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5682: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5683: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5684: (' 'x2).
5685: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5686: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5687: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5688: (' 'x2).
5689: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5690: '<br />'.
5691: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5692: '<br />'.
5693: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5694: (' 'x2).
5695: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5696: '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.proctoring_'.$provider.'_secret.type='."'text'".' } else { this.form.proctoring_'.$provider.'_secret.type='."'password'".' }" />'.$lt{'visible'}.'</label></span><br />'."\n";
5697: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5698: if ($imgsrc) {
5699: $datatable .= $imgsrc.
5700: '<label><input type="checkbox" name="proctoring_image_del"'.
5701: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5702: '<span class="LC_nobreak"> '.&mt('Replace:');
5703: }
5704: $datatable .= ' ';
5705: if ($switchserver) {
5706: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5707: } else {
5708: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5709: }
5710: unless ($imgsrc) {
5711: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5712: }
5713: $datatable .= '</fieldset>'."\n";
5714: if (ref($requserfields{$provider}) eq 'ARRAY') {
5715: if (@{$requserfields{$provider}} > 0) {
5716: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5717: foreach my $field (@{$requserfields{$provider}}) {
5718: $datatable .= '<span class="LC_nobreak">'.
5719: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5720: $lt{$field}.'</label>';
5721: if ($field eq 'user') {
5722: my $seluserdom = '';
5723: my $unseluserdom = ' selected="selected"';
5724: if ($userincdom) {
5725: $seluserdom = $unseluserdom;
5726: $unseluserdom = '';
5727: }
5728: $datatable .= ': '.
5729: '<select name="proctoring_userincdom_'.$provider.'">'.
5730: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5731: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5732: '</select> ';
5733: } else {
5734: $datatable .= ' ';
5735: if ($field eq 'roles') {
5736: $showroles = 1;
5737: }
5738: }
5739: $datatable .= '</span> ';
5740: }
5741: }
5742: $datatable .= '</fieldset>'."\n";
5743: }
5744: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5745: if (@{$optuserfields{$provider}} > 0) {
5746: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5747: foreach my $field (@{$optuserfields{$provider}}) {
5748: my $checked;
5749: if ($checkedfields{$field}) {
5750: $checked = ' checked="checked"';
5751: }
5752: $datatable .= '<span class="LC_nobreak">'.
5753: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5754: }
5755: $datatable .= '</fieldset>'."\n";
5756: }
5757: }
5758: if (ref($defaults{$provider}) eq 'ARRAY') {
5759: if (@{$defaults{$provider}}) {
5760: my (%options,@selectboxes);
5761: if (ref($extended{$provider}) eq 'HASH') {
5762: %options = %{$extended{$provider}};
5763: }
5764: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5765: my ($rem,$numinrow,$dropdowns);
5766: if ($provider eq 'proctorio') {
5767: $datatable .= '<table>';
5768: $numinrow = 4;
5769: }
5770: my $i = 0;
5771: foreach my $field (@{$defaults{$provider}}) {
5772: my $checked;
5773: if ($inuse{$field}) {
5774: $checked = ' checked="checked"';
5775: }
5776: if ($provider eq 'examity') {
5777: if ($field eq 'display') {
5778: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5779: foreach my $option ('iframe','tab','window') {
5780: my $checkdisp;
5781: if ($currentdef{'target'} eq $option) {
5782: $checkdisp = ' checked="checked"';
5783: }
5784: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5785: $fieldtitles{$option}.'</label>'.(' 'x2);
5786: }
5787: $datatable .= (' 'x4);
5788: foreach my $dimen ('width','height') {
5789: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5790: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5791: 'value="'.$currentdef{$dimen}.'" /></label>'.
5792: (' 'x2);
5793: }
5794: $datatable .= '</span><br />'.
5795: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5796: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5797: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5798: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5799: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5800: $currentdef{'explanation'}.
5801: '</textarea></div><div style=""></div><br />';
5802: }
5803: } else {
5804: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5805: my ($output,$selnone);
5806: unless ($checked) {
5807: $selnone = ' selected="selected"';
5808: }
5809: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5810: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5811: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5812: foreach my $option (@{$options{$field}}) {
5813: my $sel;
5814: if ($inuse{$field} eq $option) {
5815: $sel = ' selected="selected"';
5816: }
5817: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5818: }
5819: $output .= '</select></span>';
5820: push(@selectboxes,$output);
5821: } else {
5822: $rem = $i%($numinrow);
5823: if ($rem == 0) {
5824: if ($i > 0) {
5825: $datatable .= '</tr>';
5826: }
5827: $datatable .= '<tr>';
5828: }
5829: $datatable .= '<td class="LC_left_item">'.
5830: '<span class="LC_nobreak">'.
5831: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5832: $fieldtitles{$field}.'</label></span></td>';
5833: $i++;
5834: }
5835: }
5836: }
5837: if ($provider eq 'proctorio') {
5838: if ($numinrow) {
5839: $rem = $i%$numinrow;
5840: }
5841: my $colsleft = $numinrow - $rem;
5842: if ($colsleft > 1) {
5843: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5844: } else {
5845: $datatable .= '<td class="LC_left_item">';
5846: }
5847: $datatable .= ' '.
5848: '</td></tr></table>';
5849: if (@selectboxes) {
5850: $datatable .= '<hr /><table>';
5851: $numinrow = 2;
5852: for (my $i=0; $i<@selectboxes; $i++) {
5853: $rem = $i%($numinrow);
5854: if ($rem == 0) {
5855: if ($i > 0) {
5856: $datatable .= '</tr>';
5857: }
5858: $datatable .= '<tr>';
5859: }
5860: $datatable .= '<td class="LC_left_item">'.
5861: $selectboxes[$i].'</td>';
5862: }
5863: if ($numinrow) {
5864: $rem = $i%$numinrow;
5865: }
5866: $colsleft = $numinrow - $rem;
5867: if ($colsleft > 1) {
5868: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5869: } else {
5870: $datatable .= '<td class="LC_left_item">';
5871: }
5872: $datatable .= ' '.
5873: '</td></tr></table>';
5874: }
5875: }
5876: $datatable .= '</fieldset>';
5877: }
5878: if (ref($crsconf{$provider}) eq 'ARRAY') {
5879: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5880: '<legend>'.&mt('Configurable in course').'</legend>';
5881: my ($rem,$numinrow);
5882: if ($provider eq 'proctorio') {
5883: $datatable .= '<table>';
5884: $numinrow = 4;
5885: }
5886: my $i = 0;
5887: foreach my $item (@{$crsconf{$provider}}) {
5888: my $name;
5889: if ($provider eq 'examity') {
5890: $name = $lt{'crs'.$item};
5891: } elsif ($provider eq 'proctorio') {
5892: $name = $fieldtitles{$item};
5893: $rem = $i%($numinrow);
5894: if ($rem == 0) {
5895: if ($i > 0) {
5896: $datatable .= '</tr>';
5897: }
5898: $datatable .= '<tr>';
5899: }
5900: $datatable .= '<td class="LC_left_item>';
5901: }
5902: my $checked;
5903: if ($crsconfig{$item}) {
5904: $checked = ' checked="checked"';
5905: }
5906: $datatable .= '<span class="LC_nobreak"><label>'.
5907: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5908: $name.'</label></span>';
5909: if ($provider eq 'examity') {
5910: $datatable .= ' ';
5911: }
5912: $datatable .= "\n";
5913: $i++;
5914: }
5915: if ($provider eq 'proctorio') {
5916: if ($numinrow) {
5917: $rem = $i%$numinrow;
5918: }
5919: my $colsleft = $numinrow - $rem;
5920: if ($colsleft > 1) {
5921: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5922: } else {
5923: $datatable .= '<td class="LC_left_item">';
5924: }
5925: $datatable .= ' '.
5926: '</td></tr></table>';
5927: }
5928: $datatable .= '</fieldset>';
5929: }
5930: if ($showroles) {
5931: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5932: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5933: foreach my $role (@courseroles) {
5934: my ($selected,$selectnone);
5935: if (!$rolemaps{$role}) {
5936: $selectnone = ' selected="selected"';
5937: }
5938: $datatable .= '<td style="text-align: center">'.
5939: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5940: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5941: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5942: foreach my $ltirole (@ltiroles) {
5943: unless ($selectnone) {
5944: if ($rolemaps{$role} eq $ltirole) {
5945: $selected = ' selected="selected"';
5946: } else {
5947: $selected = '';
5948: }
5949: }
5950: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5951: }
5952: $datatable .= '</select></td>';
5953: }
5954: $datatable .= '</tr></table></fieldset>'.
5955: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5956: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
5957: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
5958: '<tr><td></td><td>lms</td>'.
5959: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
5960: ' value="Loncapa" disabled="disabled"/></td></tr>';
5961: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
5962: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
5963: my %custom = %{$settings->{$provider}->{'custom'}};
5964: if (keys(%custom) > 0) {
5965: foreach my $key (sort(keys(%custom))) {
5966: next if ($key eq 'lms');
5967: $datatable .= '<tr><td><span class="LC_nobreak">'.
5968: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
5969: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
5970: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
5971: ' value="'.$custom{$key}.'" /></td></tr>';
5972: }
5973: }
5974: }
5975: $datatable .= '<tr><td><span class="LC_nobreak">'.
5976: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
5977: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
5978: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
5979: '</table></fieldset></td></tr>'."\n";
5980: }
5981: $datatable .= '</td></tr>';
5982: }
5983: $itemcount ++;
5984: }
5985: }
5986: return $datatable;
5987: }
5988:
5989: sub proctoring_data {
5990: my $requserfields = {
5991: proctorio => ['user'],
5992: examity => ['roles','user'],
5993: };
5994: my $optuserfields = {
5995: proctorio => ['fullname'],
5996: examity => ['fullname','firstname','lastname','email'],
5997: };
5998: my $defaults = {
5999: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6000: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6001: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6002: 'closetabs','onescreen','print','downloads','cache','rightclick',
6003: 'reentry','calculator','whiteboard'],
6004: examity => ['display'],
6005: };
6006: my $extended = {
6007: proctorio => {
6008: verifyid => ['verifyidauto','verifyidlive'],
6009: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6010: tabslinks => ['notabs','linksonly'],
6011: reentry => ['noreentry','agentreentry'],
6012: calculator => ['calculatorbasic','calculatorsci'],
6013: },
6014: examity => {
6015: display => {
6016: target => ['iframe','tab','window'],
6017: width => '',
6018: height => '',
6019: linktext => '',
6020: explanation => '',
6021: },
6022: },
6023: };
6024: my $crsconf = {
6025: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6026: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6027: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6028: 'closetabs','onescreen','print','downloads','cache','rightclick',
6029: 'reentry','calculator','whiteboard'],
6030: examity => ['label','title','target','linktext','explanation','append'],
6031: };
6032: my $courseroles = ['cc','in','ta','ep','st'];
6033: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6034: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6035: }
6036:
6037: sub proctoring_titles {
6038: my ($item) = @_;
6039: my (%common_lt,%custom_lt);
6040: %common_lt = &Apache::lonlocal::texthash (
6041: 'avai' => 'Available?',
6042: 'base' => 'Basic Settings',
6043: 'requ' => 'User data required to be sent on launch',
6044: 'optu' => 'User data optionally sent on launch',
6045: 'udsl' => 'User data sent on launch',
6046: 'defa' => 'Defaults for items configurable in course',
6047: 'sigmethod' => 'Signature Method',
6048: 'key' => 'Key',
6049: 'lifetime' => 'Nonce lifetime (s)',
6050: 'secret' => 'Secret',
6051: 'icon' => 'Icon',
6052: 'fullname' => 'Full Name',
6053: 'visible' => 'Visible input',
6054: 'username' => 'username',
6055: 'user' => 'User',
6056: );
6057: if ($item eq 'proctorio') {
6058: %custom_lt = &Apache::lonlocal::texthash (
6059: 'version' => 'OAuth version',
6060: 'url' => 'API URL',
6061: 'uname:dom' => 'username-domain',
6062: );
6063: } elsif ($item eq 'examity') {
6064: %custom_lt = &Apache::lonlocal::texthash (
6065: 'version' => 'LTI Version',
6066: 'url' => 'URL',
6067: 'uname:dom' => 'username:domain',
6068: 'msgtype' => 'Message Type',
6069: 'firstname' => 'First Name',
6070: 'lastname' => 'Last Name',
6071: 'email' => 'E-mail',
6072: 'roles' => 'Role',
6073: 'crstarget' => 'Display target',
6074: 'crslabel' => 'Course label',
6075: 'crstitle' => 'Course title',
6076: 'crslinktext' => 'Link Text',
6077: 'crsexplanation' => 'Explanation',
6078: 'crsappend' => 'Provider URL',
6079: );
6080: }
6081: my %lt = (%common_lt,%custom_lt);
6082: return %lt;
6083: }
6084:
6085: sub proctoring_fieldtitles {
6086: my ($item) = @_;
6087: if ($item eq 'proctorio') {
6088: return &Apache::lonlocal::texthash (
6089: 'recordvideo' => 'Record video',
6090: 'recordaudio' => 'Record audio',
6091: 'recordscreen' => 'Record screen',
6092: 'recordwebtraffic' => 'Record web traffic',
6093: 'recordroomstart' => 'Record room scan',
6094: 'verifyvideo' => 'Verify webcam',
6095: 'verifyaudio' => 'Verify microphone',
6096: 'verifydesktop' => 'Verify desktop recording',
6097: 'verifyid' => 'Photo ID verification',
6098: 'verifysignature' => 'Require signature',
6099: 'fullscreen' => 'Fullscreen',
6100: 'clipboard' => 'Disable copy/paste',
6101: 'tabslinks' => 'New tabs/windows',
6102: 'closetabs' => 'Close other tabs',
6103: 'onescreen' => 'Limit to single screen',
6104: 'print' => 'Disable Printing',
6105: 'downloads' => 'Disable Downloads',
6106: 'cache' => 'Empty cache after exam',
6107: 'rightclick' => 'Disable right click',
6108: 'reentry' => 'Re-entry to exam',
6109: 'calculator' => 'Onscreen calculator',
6110: 'whiteboard' => 'Onscreen whiteboard',
6111: 'verifyidauto' => 'Automated verification',
6112: 'verifyidlive' => 'Live agent verification',
6113: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6114: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6115: 'fullscreensever' => 'Forced, navigation away ends exam',
6116: 'notabs' => 'Disaallowed',
6117: 'linksonly' => 'Allowed from links in exam',
6118: 'noreentry' => 'Disallowed',
6119: 'agentreentry' => 'Agent required for re-entry',
6120: 'calculatorbasic' => 'Basic',
6121: 'calculatorsci' => 'Scientific',
6122: );
6123: } elsif ($item eq 'examity') {
6124: return &Apache::lonlocal::texthash (
6125: 'target' => 'Display target',
6126: 'window' => 'Window',
6127: 'tab' => 'Tab',
6128: 'iframe' => 'iFrame',
6129: 'height' => 'Height (pixels)',
6130: 'width' => 'Width (pixels)',
6131: 'linktext' => 'Default Link Text',
6132: 'explanation' => 'Default Explanation',
6133: 'append' => 'Provider URL',
6134: );
6135: }
6136: }
6137:
6138: sub proctoring_providernames {
6139: return (
6140: proctorio => 'Proctorio',
6141: examity => 'Examity',
6142: );
6143: }
6144:
1.320 raeburn 6145: sub print_lti {
1.405 raeburn 6146: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6147: my $itemcount = 1;
1.405 raeburn 6148: my ($datatable,$css_class);
6149: my (%rules,%encrypt,%privkeys,%linkprot);
1.320 raeburn 6150: if (ref($settings) eq 'HASH') {
1.405 raeburn 6151: if ($position eq 'top') {
6152: if (exists($settings->{'encrypt'})) {
6153: if (ref($settings->{'encrypt'}) eq 'HASH') {
6154: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6155: if ($key eq 'consumers') {
6156: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6157: } else {
6158: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6159: }
6160: }
6161: }
6162: }
6163: if (exists($settings->{'private'})) {
6164: if (ref($settings->{'private'}) eq 'HASH') {
6165: if (ref($settings->{'private'}) eq 'HASH') {
6166: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6167: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6168: }
6169: }
6170: }
6171: }
6172: } elsif ($position eq 'middle') {
6173: if (exists($settings->{'rules'})) {
6174: if (ref($settings->{'rules'}) eq 'HASH') {
6175: %rules = %{$settings->{'rules'}};
6176: }
6177: }
6178: } elsif ($position eq 'lower') {
6179: if (exists($settings->{'linkprot'})) {
6180: if (ref($settings->{'linkprot'}) eq 'HASH') {
6181: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6182: if ($linkprot{'lock'}) {
6183: delete($linkprot{'lock'});
6184: }
1.405 raeburn 6185: }
6186: }
6187: } else {
6188: foreach my $key ('encrypt','private','rules','linkprot') {
6189: if (exists($settings->{$key})) {
6190: delete($settings->{$key});
1.390 raeburn 6191: }
1.320 raeburn 6192: }
6193: }
6194: }
1.405 raeburn 6195: if ($position eq 'top') {
1.421 raeburn 6196: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
6197: } elsif ($position eq 'middle') {
6198: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6199: $$rowtotal += $itemcount;
6200: } elsif ($position eq 'lower') {
6201: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
6202: } else {
1.424 ! raeburn 6203: my ($switchserver,$switchmessage);
! 6204: $switchserver = &check_switchserver($dom);
! 6205: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6206: my $maxnum = 0;
6207: my %ordered;
6208: if (ref($settings) eq 'HASH') {
6209: foreach my $item (keys(%{$settings})) {
6210: if (ref($settings->{$item}) eq 'HASH') {
6211: my $num = $settings->{$item}{'order'};
6212: if ($num eq '') {
6213: $num = scalar(keys(%{$settings}));
6214: }
6215: $ordered{$num} = $item;
1.405 raeburn 6216: }
1.352 raeburn 6217: }
1.405 raeburn 6218: }
6219: $maxnum = scalar(keys(%ordered));
6220: my %lt = <i_names();
6221: if (keys(%ordered)) {
6222: my @items = sort { $a <=> $b } keys(%ordered);
6223: for (my $i=0; $i<@items; $i++) {
6224: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6225: my $item = $ordered{$items[$i]};
1.424 ! raeburn 6226: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6227: if (ref($settings->{$item}) eq 'HASH') {
6228: $key = $settings->{$item}->{'key'};
1.424 ! raeburn 6229: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6230: $lifetime = $settings->{$item}->{'lifetime'};
6231: $consumer = $settings->{$item}->{'consumer'};
6232: $requser = $settings->{$item}->{'requser'};
6233: $crsinc = $settings->{$item}->{'crsinc'};
6234: $current = $settings->{$item};
6235: }
6236: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6237: my %checkedrequser = (
6238: yes => ' checked="checked"',
6239: no => '',
6240: );
6241: if (!$requser) {
6242: $checkedrequser{'no'} = $checkedrequser{'yes'};
6243: $checkedrequser{'yes'} = '';
6244: }
6245: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6246: my %checkedcrsinc = (
1.391 raeburn 6247: yes => ' checked="checked"',
6248: no => '',
1.405 raeburn 6249: );
6250: if (!$crsinc) {
6251: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6252: $checkedcrsinc{'yes'} = '';
6253: }
6254: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6255: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6256: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6257: for (my $k=0; $k<=$maxnum; $k++) {
6258: my $vpos = $k+1;
6259: my $selstr;
6260: if ($k == $i) {
6261: $selstr = ' selected="selected" ';
6262: }
6263: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6264: }
1.405 raeburn 6265: $datatable .= '</select>'.(' 'x2).
6266: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6267: &mt('Delete?').'</label></span></td>'.
6268: '<td colspan="2">'.
6269: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6270: '<span class="LC_nobreak">'.$lt{'consumer'}.
6271: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6272: (' 'x2).
6273: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6274: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6275: (' 'x2).
6276: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 ! raeburn 6277: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
! 6278: if ($key ne '') {
! 6279: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
! 6280: if ($switchserver) {
! 6281: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
! 6282: } else {
! 6283: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
! 6284: }
! 6285: $datatable .= '</span> '.(' 'x2);
! 6286: } elsif (!$switchserver) {
! 6287: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
! 6288: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
! 6289: '</span> '.(' 'x2);
! 6290: }
! 6291: if ($switchserver) {
! 6292: if ($usable ne '') {
! 6293: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
! 6294: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
! 6295: '<span class="LC_nobreak">'.&mt('Change secret?').
! 6296: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
! 6297: (' 'x2).
! 6298: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
! 6299: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
! 6300: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
! 6301: '</div>';
! 6302: } elsif ($key eq '') {
! 6303: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
! 6304: } else {
! 6305: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
! 6306: }
! 6307: } else {
! 6308: if ($usable ne '') {
! 6309: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
! 6310: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
! 6311: '<span class="LC_nobreak">'.&mt('Change?').
! 6312: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
! 6313: (' 'x2).
! 6314: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
! 6315: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
! 6316: '<span class="LC_nobreak">'.&mt('New Secret').':'.
! 6317: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
! 6318: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
! 6319: } else {
! 6320: $datatable .=
! 6321: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
! 6322: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
! 6323: '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
! 6324: }
! 6325: }
! 6326: $datatable .= '<br /><br />'.
1.405 raeburn 6327: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6328: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6329: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6330: '<br /><br />'.
6331: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6332: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6333: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6334: (' 'x4).
6335: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6336: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6337: $itemcount ++;
1.320 raeburn 6338: }
6339: }
1.405 raeburn 6340: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6341: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6342: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6343: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6344: '<select name="lti_pos_add"'.$chgstr.'>';
6345: for (my $k=0; $k<$maxnum+1; $k++) {
6346: my $vpos = $k+1;
6347: my $selstr;
6348: if ($k == $maxnum) {
6349: $selstr = ' selected="selected" ';
6350: }
6351: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6352: }
1.405 raeburn 6353: $datatable .= '</select> '."\n".
6354: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6355: '<td colspan="2">'.
6356: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6357: '<span class="LC_nobreak">'.$lt{'consumer'}.
6358: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6359: (' 'x2).
6360: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6361: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6362: (' 'x2).
1.424 ! raeburn 6363: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
! 6364: if ($switchserver) {
! 6365: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
! 6366: } else {
! 6367: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
! 6368: (' 'x2).
! 6369: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
! 6370: '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
! 6371: }
! 6372: $datatable .= '<br /><br />'.
1.405 raeburn 6373: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6374: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6375: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6376: '<br /><br />'.
6377: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6378: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6379: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6380: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6381: '</td>'."\n".
6382: '</tr>'."\n";
6383: $itemcount ++;
1.320 raeburn 6384: }
1.405 raeburn 6385: $$rowtotal += $itemcount;
6386: return $datatable;
1.320 raeburn 6387: }
6388:
6389: sub lti_names {
6390: my %lt = &Apache::lonlocal::texthash(
6391: 'version' => 'LTI Version',
6392: 'url' => 'URL',
6393: 'key' => 'Key',
1.322 raeburn 6394: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6395: 'consumer' => 'Consumer',
1.320 raeburn 6396: 'secret' => 'Secret',
1.345 raeburn 6397: 'requser' => "User's identity sent",
1.391 raeburn 6398: 'crsinc' => "Course's identity sent",
1.320 raeburn 6399: 'email' => 'Email address',
6400: 'sourcedid' => 'User ID',
6401: 'other' => 'Other',
6402: 'passback' => 'Can return grades to Consumer:',
6403: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6404: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6405: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6406: );
6407: return %lt;
6408: }
6409:
6410: sub lti_options {
1.325 raeburn 6411: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6412: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6413: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6414: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6415: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6416: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6417: $checked{'mapcrstype'} = {};
6418: $checked{'makeuser'} = {};
6419: $checked{'selfenroll'} = {};
6420: $checked{'crssec'} = {};
6421: $checked{'crssecsrc'} = {};
1.325 raeburn 6422: $checked{'lcauth'} = {};
1.326 raeburn 6423: $checked{'menuitem'} = {};
1.325 raeburn 6424: if ($num eq 'add') {
6425: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6426: }
1.320 raeburn 6427: my $userfieldsty = 'none';
6428: my $crsfieldsty = 'none';
6429: my $crssecfieldsty = 'none';
6430: my $secsrcfieldsty = 'none';
1.363 raeburn 6431: my $callbacksty = 'none';
1.337 raeburn 6432: my $passbacksty = 'none';
1.345 raeburn 6433: my $optionsty = 'block';
1.391 raeburn 6434: my $crssty = 'block';
1.325 raeburn 6435: my $lcauthparm;
6436: my $lcauthparmstyle = 'display:none';
6437: my $lcauthparmtext;
1.326 raeburn 6438: my $menusty;
1.325 raeburn 6439: my $numinrow = 4;
1.326 raeburn 6440: my %menutitles = <imenu_titles();
1.320 raeburn 6441:
6442: if (ref($current) eq 'HASH') {
1.345 raeburn 6443: if (!$current->{'requser'}) {
6444: $optionsty = 'none';
1.391 raeburn 6445: $crssty = 'none';
6446: } elsif (!$current->{'crsinc'}) {
6447: $crssty = 'none';
1.345 raeburn 6448: }
1.320 raeburn 6449: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6450: $checked{'mapuser'}{'sourcedid'} = '';
6451: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
6452: $checked{'mapuser'}{'email'} = ' checked="checked"';
6453: } else {
6454: $checked{'mapuser'}{'other'} = ' checked="checked"';
6455: $userfield = $current->{'mapuser'};
6456: $userfieldsty = 'inline-block';
6457: }
6458: }
6459: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6460: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6461: if ($current->{'mapcrs'} eq 'context_id') {
6462: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
6463: } else {
6464: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6465: $cidfield = $current->{'mapcrs'};
6466: $crsfieldsty = 'inline-block';
6467: }
6468: }
6469: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6470: foreach my $type (@{$current->{'mapcrstype'}}) {
6471: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6472: }
6473: }
1.392 raeburn 6474: if (!$current->{'storecrs'}) {
6475: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6476: $checked{'storecrs'}{'Y'} = '';
6477: }
1.345 raeburn 6478: if ($current->{'makecrs'}) {
1.320 raeburn 6479: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6480: }
1.320 raeburn 6481: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6482: foreach my $role (@{$current->{'makeuser'}}) {
6483: $checked{'makeuser'}{$role} = ' checked="checked"';
6484: }
6485: }
1.325 raeburn 6486: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6487: $checked{'lcauth'}{$1} = ' checked="checked"';
6488: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6489: $lcauthparm = $current->{'lcauthparm'};
6490: $lcauthparmstyle = 'display:table-row';
6491: if ($current->{'lcauth'} eq 'localauth') {
6492: $lcauthparmtext = &mt('Local auth argument');
6493: } else {
6494: $lcauthparmtext = &mt('Kerberos domain');
6495: }
6496: }
6497: }
1.320 raeburn 6498: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6499: foreach my $role (@{$current->{'selfenroll'}}) {
6500: $checked{'selfenroll'}{$role} = ' checked="checked"';
6501: }
6502: }
6503: if (ref($current->{'maproles'}) eq 'HASH') {
6504: %rolemaps = %{$current->{'maproles'}};
6505: }
6506: if ($current->{'section'} ne '') {
6507: $checked{'crssec'}{'Y'} = ' checked="checked"';
6508: $crssecfieldsty = 'inline-block';
6509: if ($current->{'section'} eq 'course_section_sourcedid') {
6510: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6511: } else {
6512: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6513: $crssecsrc = $current->{'section'};
6514: $secsrcfieldsty = 'inline-block';
6515: }
6516: } else {
6517: $checked{'crssec'}{'N'} = ' checked="checked"';
6518: }
1.363 raeburn 6519: if ($current->{'callback'} ne '') {
6520: $callback = $current->{'callback'};
6521: $checked{'callback'}{'Y'} = ' checked="checked"';
6522: $callbacksty = 'inline-block';
6523: } else {
6524: $checked{'callback'}{'N'} = ' checked="checked"';
6525: }
1.326 raeburn 6526: if ($current->{'topmenu'}) {
6527: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6528: } else {
6529: $checked{'topmenu'}{'N'} = ' checked="checked"';
6530: }
6531: if ($current->{'inlinemenu'}) {
6532: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6533: } else {
6534: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6535: }
6536: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6537: $menusty = 'inline-block';
6538: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6539: foreach my $item (@{$current->{'lcmenu'}}) {
6540: if (exists($menutitles{$item})) {
6541: $checked{'menuitem'}{$item} = ' checked="checked"';
6542: }
6543: }
6544: }
6545: } else {
6546: $menusty = 'none';
6547: }
1.320 raeburn 6548: } else {
6549: $checked{'makecrs'}{'N'} = ' checked="checked"';
6550: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6551: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6552: $checked{'topmenu'}{'N'} = ' checked="checked"';
6553: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6554: $checked{'menuitem'}{'grades'} = ' checked="checked"';
6555: $menusty = 'inline-block';
1.320 raeburn 6556: }
1.325 raeburn 6557: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6558: my %coursetypetitles = &Apache::lonlocal::texthash (
6559: official => 'Official',
6560: unofficial => 'Unofficial',
6561: community => 'Community',
6562: textbook => 'Textbook',
6563: placement => 'Placement Test',
1.325 raeburn 6564: lti => 'LTI Provider',
1.320 raeburn 6565: );
1.325 raeburn 6566: my @authtypes = ('internal','krb4','krb5','localauth');
6567: my %shortauth = (
6568: internal => 'int',
6569: krb4 => 'krb4',
6570: krb5 => 'krb5',
6571: localauth => 'loc'
6572: );
6573: my %authnames = &authtype_names();
1.320 raeburn 6574: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6575: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6576: my @courseroles = ('cc','in','ta','ep','st');
6577: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6578: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6579: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6580: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6581: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6582: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6583: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6584: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6585: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6586: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6587: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6588: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6589: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6590: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6591: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6592: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6593: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6594: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6595: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6596: foreach my $option ('sourcedid','email','other') {
6597: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6598: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6599: ($option eq 'other' ? '' : (' 'x2) );
6600: }
6601: $output .= '</span></div>'.
6602: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6603: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6604: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6605: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6606: foreach my $ltirole (@ltiroles) {
6607: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
6608: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
6609: }
6610: $output .= '</fieldset>'.
1.391 raeburn 6611: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6612: '<table>'.
6613: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6614: '</table>'.
6615: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6616: '<td class="LC_left_item">';
6617: foreach my $auth ('lti',@authtypes) {
6618: my $authtext;
6619: if ($auth eq 'lti') {
6620: $authtext = &mt('None');
6621: } else {
6622: $authtext = $authnames{$shortauth{$auth}};
6623: }
6624: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6625: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6626: $authtext.'</label></span> ';
6627: }
6628: $output .= '</td></tr>'.
6629: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6630: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6631: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6632: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6633: '</table></fieldset>'.
1.391 raeburn 6634: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6635: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6636: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6637: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6638: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6639: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6640: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6641: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6642: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6643: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6644: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6645: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6646: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6647: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6648: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6649: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6650: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6651: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6652: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6653: (' 'x2);
6654: }
6655: $output .= '</span></div></fieldset>'.
6656: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6657: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6658: &mt('Unique course identifier').': ';
6659: foreach my $option ('course_offering_sourcedid','context_id','other') {
6660: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6661: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6662: ($option eq 'other' ? '' : (' 'x2) );
6663: }
1.334 raeburn 6664: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6665: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6666: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6667: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6668: foreach my $type (@coursetypes) {
6669: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6670: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6671: (' 'x2);
6672: }
1.392 raeburn 6673: $output .= '</span><br /><br />'.
6674: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6675: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6676: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6677: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6678: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6679: '</fieldset>'.
1.391 raeburn 6680: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6681: foreach my $ltirole (@lticourseroles) {
6682: my ($selected,$selectnone);
6683: if ($rolemaps{$ltirole} eq '') {
6684: $selectnone = ' selected="selected"';
6685: }
6686: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6687: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6688: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6689: foreach my $role (@courseroles) {
6690: unless ($selectnone) {
6691: if ($rolemaps{$ltirole} eq $role) {
6692: $selected = ' selected="selected"';
6693: } else {
6694: $selected = '';
6695: }
6696: }
6697: $output .= '<option value="'.$role.'"'.$selected.'>'.
6698: &Apache::lonnet::plaintext($role,'Course').
6699: '</option>';
6700: }
6701: $output .= '</select></td>';
6702: }
6703: $output .= '</tr></table></fieldset>'.
6704: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6705: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6706: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6707: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6708: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6709: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6710: '</fieldset>'.
1.391 raeburn 6711: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6712: foreach my $lticrsrole (@lticourseroles) {
6713: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6714: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6715: }
6716: $output .= '</fieldset>'.
1.391 raeburn 6717: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6718: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6719: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6720: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6721: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6722: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6723: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6724: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6725: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6726: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6727: &mt('Standard field').'</label>'.(' 'x2).
6728: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6729: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6730: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6731: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6732: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6733: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6734: foreach my $extra ('roster','passback') {
1.320 raeburn 6735: my $checkedon = '';
6736: my $checkedoff = ' checked="checked"';
1.337 raeburn 6737: if ($extra eq 'passback') {
6738: $pb1p1chk = ' checked="checked"';
6739: $pb1p0chk = '';
6740: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
6741: } else {
6742: $onclickpb = '';
6743: }
1.320 raeburn 6744: if (ref($current) eq 'HASH') {
6745: if (($current->{$extra})) {
6746: $checkedon = $checkedoff;
6747: $checkedoff = '';
1.337 raeburn 6748: if ($extra eq 'passback') {
6749: $passbacksty = 'inline-block';
6750: }
6751: if ($current->{'passbackformat'} eq '1.0') {
6752: $pb1p0chk = ' checked="checked"';
6753: $pb1p1chk = '';
6754: }
1.320 raeburn 6755: }
6756: }
6757: $output .= $lt{$extra}.' '.
1.337 raeburn 6758: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6759: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6760: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6761: &mt('Yes').'</label><br />';
6762: }
1.337 raeburn 6763: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6764: '<span class="LC_nobreak">'.&mt('Grade format').
6765: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6766: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6767: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6768: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6769: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6770: $output .= '</span></div></fieldset>';
1.320 raeburn 6771: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6772: #
6773: # $output .= '</fieldset>'.
6774: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6775: return $output;
6776: }
6777:
1.326 raeburn 6778: sub ltimenu_titles {
6779: return &Apache::lonlocal::texthash(
6780: fullname => 'Full name',
6781: coursetitle => 'Course title',
6782: role => 'Role',
6783: logout => 'Logout',
6784: grades => 'Grades',
6785: );
6786: }
6787:
1.405 raeburn 6788: sub check_switchserver {
6789: my ($home) = @_;
6790: my $switchserver;
6791: if ($home ne '') {
6792: my $allowed;
6793: my @ids=&Apache::lonnet::current_machine_ids();
6794: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
6795: if (!$allowed) {
6796: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
6797: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
6798: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
6799: }
6800: }
6801: return $switchserver;
6802: }
6803:
1.121 raeburn 6804: sub print_coursedefaults {
1.139 raeburn 6805: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6806: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6807: my $itemcount = 1;
1.192 raeburn 6808: my %choices = &Apache::lonlocal::texthash (
6809: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6810: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 6811: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6812: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6813: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6814: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6815: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6816: texengine => 'Default method to display mathematics',
1.257 raeburn 6817: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6818: canclone => "People who may clone a course (besides course's owner and coordinators)",
6819: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6820: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6821: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6822: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.192 raeburn 6823: );
1.198 raeburn 6824: my %staticdefaults = (
6825: anonsurvey_threshold => 10,
6826: uploadquota => 500,
1.257 raeburn 6827: postsubmit => 60,
1.276 raeburn 6828: mysqltables => 172800,
1.422 raeburn 6829: domexttool => 1,
6830: exttool => 0,
1.198 raeburn 6831: );
1.139 raeburn 6832: if ($position eq 'top') {
1.257 raeburn 6833: %defaultchecked = (
6834: 'canuse_pdfforms' => 'off',
6835: 'uselcmath' => 'on',
6836: 'usejsme' => 'on',
1.398 raeburn 6837: 'inline_chem' => 'on',
1.289 raeburn 6838: 'canclone' => 'none',
1.257 raeburn 6839: );
1.398 raeburn 6840: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6841: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6842: if (ref($settings) eq 'HASH') {
6843: if ($settings->{'texengine'}) {
6844: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6845: $deftex = $settings->{'texengine'};
6846: }
6847: }
6848: }
6849: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6850: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6851: '<span class="LC_nobreak">'.$choices{'texengine'}.
6852: '</span></td><td class="LC_right_item">'.
6853: '<select name="texengine">'."\n";
6854: my %texoptions = (
6855: MathJax => 'MathJax',
6856: mimetex => &mt('Convert to Images'),
6857: tth => &mt('TeX to HTML'),
6858: );
6859: foreach my $renderer ('MathJax','mimetex','tth') {
6860: my $selected = '';
6861: if ($renderer eq $deftex) {
6862: $selected = ' selected="selected"';
6863: }
6864: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6865: }
6866: $mathdisp .= '</select></td></tr>'."\n";
6867: $itemcount ++;
1.139 raeburn 6868: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6869: \%choices,$itemcount);
1.314 raeburn 6870: $datatable = $mathdisp.$datatable;
1.264 raeburn 6871: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6872: $datatable .=
1.306 raeburn 6873: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6874: '<span class="LC_nobreak">'.$choices{'canclone'}.
6875: '</span></td><td class="LC_left_item">';
6876: my $currcanclone = 'none';
6877: my $onclick;
6878: my @cloneoptions = ('none','domain');
1.380 raeburn 6879: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6880: none => 'No additional course requesters',
6881: domain => "Any course requester in course's domain",
6882: instcode => 'Course requests for official courses ...',
6883: );
6884: my (%codedefaults,@code_order,@posscodes);
6885: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6886: \@code_order) eq 'ok') {
6887: if (@code_order > 0) {
6888: push(@cloneoptions,'instcode');
6889: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6890: }
6891: }
6892: if (ref($settings) eq 'HASH') {
6893: if ($settings->{'canclone'}) {
6894: if (ref($settings->{'canclone'}) eq 'HASH') {
6895: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6896: if (@code_order > 0) {
6897: $currcanclone = 'instcode';
6898: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6899: }
6900: }
6901: } elsif ($settings->{'canclone'} eq 'domain') {
6902: $currcanclone = $settings->{'canclone'};
6903: }
6904: }
1.289 raeburn 6905: }
1.264 raeburn 6906: foreach my $option (@cloneoptions) {
6907: my ($checked,$additional);
6908: if ($currcanclone eq $option) {
6909: $checked = ' checked="checked"';
6910: }
6911: if ($option eq 'instcode') {
6912: if (@code_order) {
6913: my $show = 'none';
6914: if ($checked) {
6915: $show = 'block';
6916: }
1.317 raeburn 6917: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 6918: &mt('Institutional codes for new and cloned course have identical:').
6919: '<br />';
6920: foreach my $item (@code_order) {
6921: my $codechk;
6922: if ($checked) {
6923: if (grep(/^\Q$item\E$/,@posscodes)) {
6924: $codechk = ' checked="checked"';
6925: }
6926: }
6927: $additional .= '<label>'.
6928: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6929: $item.'</label>';
6930: }
6931: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6932: }
6933: }
6934: $datatable .=
6935: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6936: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6937: '</label> '.$additional.'</span><br />';
6938: }
6939: $datatable .= '</td>'.
6940: '</tr>';
6941: $itemcount ++;
1.139 raeburn 6942: } else {
6943: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.276 raeburn 6944: my ($currdefresponder,%defcredits,%curruploadquota,%deftimeout,%currmysql);
1.192 raeburn 6945: my $currusecredits = 0;
1.257 raeburn 6946: my $postsubmitclient = 1;
1.405 raeburn 6947: my $ltiauth = 0;
1.422 raeburn 6948: my %domexttool;
6949: my %exttool;
1.271 raeburn 6950: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 6951: if (ref($settings) eq 'HASH') {
1.404 raeburn 6952: if ($settings->{'ltiauth'}) {
6953: $ltiauth = 1;
1.405 raeburn 6954: }
1.422 raeburn 6955: if (ref($settings->{'domexttool'}) eq 'HASH') {
6956: foreach my $type (@types) {
6957: if ($settings->{'domexttool'}->{$type}) {
6958: $domexttool{$type} = ' checked="checked"';
6959: }
6960: }
6961: } else {
6962: foreach my $type (@types) {
6963: if ($staticdefaults{'domexttool'}) {
6964: $domexttool{$type} = ' checked="checked"';
6965: }
6966: }
6967: }
6968: if (ref($settings->{'exttool'}) eq 'HASH') {
6969: foreach my $type (@types) {
6970: if ($settings->{'exttool'}->{$type}) {
6971: $exttool{$type} = ' checked="checked"';
6972: }
6973: }
6974: }
1.139 raeburn 6975: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 6976: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6977: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6978: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6979: }
6980: }
1.192 raeburn 6981: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 6982: foreach my $type (@types) {
6983: next if ($type eq 'community');
6984: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6985: if ($defcredits{$type} ne '') {
6986: $currusecredits = 1;
6987: }
6988: }
6989: }
6990: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6991: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6992: $postsubmitclient = 0;
6993: foreach my $type (@types) {
6994: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6995: }
6996: } else {
6997: foreach my $type (@types) {
6998: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6999: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7000: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7001: } else {
7002: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7003: }
7004: } else {
7005: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7006: }
7007: }
7008: }
7009: } else {
7010: foreach my $type (@types) {
7011: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7012: }
7013: }
1.276 raeburn 7014: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7015: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7016: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7017: }
7018: } else {
7019: foreach my $type (@types) {
7020: $currmysql{$type} = $staticdefaults{'mysqltables'};
7021: }
7022: }
1.258 raeburn 7023: } else {
7024: foreach my $type (@types) {
7025: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7026: if ($staticdefaults{'domexttool'}) {
7027: $domexttool{$type} = ' checked="checked"';
7028: }
1.258 raeburn 7029: }
1.139 raeburn 7030: }
7031: if (!$currdefresponder) {
1.198 raeburn 7032: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7033: } elsif ($currdefresponder < 1) {
7034: $currdefresponder = 1;
7035: }
1.198 raeburn 7036: foreach my $type (@types) {
7037: if ($curruploadquota{$type} eq '') {
7038: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7039: }
7040: }
1.139 raeburn 7041: $datatable .=
1.192 raeburn 7042: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7043: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7044: '</span></td>'.
7045: '<td class="LC_right_item"><span class="LC_nobreak">'.
7046: '<input type="text" name="anonsurvey_threshold"'.
7047: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7048: '</td></tr>'."\n";
7049: $itemcount ++;
7050: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7051: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7052: $choices{'uploadquota'}.
7053: '</span></td>'.
1.306 raeburn 7054: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7055: '<table><tr>';
1.198 raeburn 7056: foreach my $type (@types) {
1.306 raeburn 7057: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7058: '<input type="text" name="uploadquota_'.$type.'"'.
7059: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7060: }
7061: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7062: $itemcount ++;
1.236 raeburn 7063: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7064: my $display = 'none';
1.192 raeburn 7065: if ($currusecredits) {
7066: $display = 'block';
7067: }
7068: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7069: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7070: foreach my $type (@types) {
7071: next if ($type eq 'community');
1.306 raeburn 7072: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7073: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7074: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7075: }
7076: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7077: %defaultchecked = ('coursecredits' => 'off');
7078: @toggles = ('coursecredits');
7079: my $current = {
7080: 'coursecredits' => $currusecredits,
7081: };
7082: (my $table,$itemcount) =
7083: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7084: \%choices,$itemcount,$onclick,$additional,'left');
7085: $datatable .= $table;
7086: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7087: my $display = 'none';
7088: if ($postsubmitclient) {
7089: $display = 'block';
7090: }
7091: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7092: &mt('Number of seconds submit is disabled').'<br />'.
7093: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7094: '<table><tr>';
1.257 raeburn 7095: foreach my $type (@types) {
1.306 raeburn 7096: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7097: '<input type="text" name="'.$type.'_timeout" value="'.
7098: $deftimeout{$type}.'" size="5" /></td>';
7099: }
7100: $additional .= '</tr></table></div>'."\n";
7101: %defaultchecked = ('postsubmit' => 'on');
7102: @toggles = ('postsubmit');
1.280 raeburn 7103: $current = {
7104: 'postsubmit' => $postsubmitclient,
7105: };
1.257 raeburn 7106: ($table,$itemcount) =
7107: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7108: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7109: $datatable .= $table;
1.276 raeburn 7110: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7111: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7112: $choices{'mysqltables'}.
7113: '</span></td>'.
1.306 raeburn 7114: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7115: '<table><tr>';
7116: foreach my $type (@types) {
1.306 raeburn 7117: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7118: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7119: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7120: }
7121: $datatable .= '</tr></table></td></tr>'."\n";
7122: $itemcount ++;
1.404 raeburn 7123: %defaultchecked = ('ltiauth' => 'off');
7124: @toggles = ('ltiauth');
7125: $current = {
7126: 'ltiauth' => $ltiauth,
7127: };
7128: ($table,$itemcount) =
7129: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7130: \%choices,$itemcount,undef,undef,'left');
7131: $datatable .= $table;
1.422 raeburn 7132: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7133: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7134: $choices{'domexttool'}.
7135: '</span></td>'.
7136: '<td style="text-align: right" class="LC_right_item">'.
7137: '<table><tr>';
7138: foreach my $type (@types) {
7139: $datatable .= '<td style="text-align: left">'.
7140: '<span class="LC_nobreak">'.
7141: '<input type="checkbox" name="domexttool"'.
7142: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7143: &mt($type).'</span></td>'."\n";
7144: }
7145: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7146: $itemcount ++;
1.422 raeburn 7147: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7148: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7149: $choices{'exttool'}.
7150: '</span></td>'.
7151: '<td style="text-align: right" class="LC_right_item">'.
7152: '<table><tr>';
7153: foreach my $type (@types) {
7154: $datatable .= '<td style="text-align: left">'.
7155: '<span class="LC_nobreak">'.
7156: '<input type="checkbox" name="exttool"'.
7157: ' value="'.$type.'"'.$exttool{$type}.' />'.
7158: &mt($type).'</span></td>'."\n";
7159: }
7160: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7161: }
1.192 raeburn 7162: $$rowtotal += $itemcount;
1.121 raeburn 7163: return $datatable;
1.118 jms 7164: }
7165:
1.231 raeburn 7166: sub print_selfenrollment {
7167: my ($position,$dom,$settings,$rowtotal) = @_;
7168: my ($css_class,$datatable);
7169: my $itemcount = 1;
1.271 raeburn 7170: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7171: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7172: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7173: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7174: my @rows;
7175: my $key;
7176: if ($position eq 'top') {
7177: $key = 'admin';
7178: if (ref($rowsref) eq 'ARRAY') {
7179: @rows = @{$rowsref};
7180: }
7181: } elsif ($position eq 'middle') {
7182: $key = 'default';
7183: @rows = ('types','registered','approval','limit');
7184: }
7185: foreach my $row (@rows) {
7186: if (defined($titlesref->{$row})) {
7187: $itemcount ++;
7188: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7189: $datatable .= '<tr'.$css_class.'>'.
7190: '<td>'.$titlesref->{$row}.'</td>'.
7191: '<td class="LC_left_item">'.
7192: '<table><tr>';
7193: my (%current,%currentcap);
7194: if (ref($settings) eq 'HASH') {
7195: if (ref($settings->{$key}) eq 'HASH') {
7196: foreach my $type (@types) {
7197: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7198: $current{$type} = $settings->{$key}->{$type}->{$row};
7199: }
7200: if (($row eq 'limit') && ($key eq 'default')) {
7201: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7202: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7203: }
7204: }
7205: }
7206: }
7207: }
7208: my %roles = (
7209: '0' => &Apache::lonnet::plaintext('dc'),
7210: );
7211:
7212: foreach my $type (@types) {
7213: unless (($row eq 'registered') && ($key eq 'default')) {
7214: $datatable .= '<th>'.&mt($type).'</th>';
7215: }
7216: }
7217: unless (($row eq 'registered') && ($key eq 'default')) {
7218: $datatable .= '</tr><tr>';
7219: }
7220: foreach my $type (@types) {
7221: if ($type eq 'community') {
7222: $roles{'1'} = &mt('Community personnel');
7223: } else {
7224: $roles{'1'} = &mt('Course personnel');
7225: }
7226: $datatable .= '<td style="vertical-align: top">';
7227: if ($position eq 'top') {
7228: my %checked;
7229: if ($current{$type} eq '0') {
7230: $checked{'0'} = ' checked="checked"';
7231: } else {
7232: $checked{'1'} = ' checked="checked"';
7233: }
7234: foreach my $role ('1','0') {
7235: $datatable .= '<span class="LC_nobreak"><label>'.
7236: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7237: 'value="'.$role.'"'.$checked{$role}.' />'.
7238: $roles{$role}.'</label></span> ';
7239: }
7240: } else {
7241: if ($row eq 'types') {
7242: my %checked;
7243: if ($current{$type} =~ /^(all|dom)$/) {
7244: $checked{$1} = ' checked="checked"';
7245: } else {
7246: $checked{''} = ' checked="checked"';
7247: }
7248: foreach my $val ('','dom','all') {
7249: $datatable .= '<span class="LC_nobreak"><label>'.
7250: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7251: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7252: }
7253: } elsif ($row eq 'registered') {
7254: my %checked;
7255: if ($current{$type} eq '1') {
7256: $checked{'1'} = ' checked="checked"';
7257: } else {
7258: $checked{'0'} = ' checked="checked"';
7259: }
7260: foreach my $val ('0','1') {
7261: $datatable .= '<span class="LC_nobreak"><label>'.
7262: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7263: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7264: }
7265: } elsif ($row eq 'approval') {
7266: my %checked;
7267: if ($current{$type} =~ /^([12])$/) {
7268: $checked{$1} = ' checked="checked"';
7269: } else {
7270: $checked{'0'} = ' checked="checked"';
7271: }
7272: for my $val (0..2) {
7273: $datatable .= '<span class="LC_nobreak"><label>'.
7274: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7275: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7276: }
7277: } elsif ($row eq 'limit') {
7278: my %checked;
7279: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7280: $checked{$1} = ' checked="checked"';
7281: } else {
7282: $checked{'none'} = ' checked="checked"';
7283: }
7284: my $cap;
7285: if ($currentcap{$type} =~ /^\d+$/) {
7286: $cap = $currentcap{$type};
7287: }
7288: foreach my $val ('none','allstudents','selfenrolled') {
7289: $datatable .= '<span class="LC_nobreak"><label>'.
7290: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7291: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7292: }
7293: $datatable .= '<br />'.
7294: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7295: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7296: '</span>';
7297: }
7298: }
7299: $datatable .= '</td>';
7300: }
7301: $datatable .= '</tr>';
7302: }
7303: $datatable .= '</table></td></tr>';
7304: }
7305: } elsif ($position eq 'bottom') {
1.235 raeburn 7306: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7307: }
7308: $$rowtotal += $itemcount;
7309: return $datatable;
7310: }
7311:
7312: sub print_validation_rows {
7313: my ($caller,$dom,$settings,$rowtotal) = @_;
7314: my ($itemsref,$namesref,$fieldsref);
7315: if ($caller eq 'selfenroll') {
7316: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7317: } elsif ($caller eq 'requestcourses') {
7318: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7319: }
7320: my %currvalidation;
7321: if (ref($settings) eq 'HASH') {
7322: if (ref($settings->{'validation'}) eq 'HASH') {
7323: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7324: }
1.235 raeburn 7325: }
7326: my $datatable;
7327: my $itemcount = 0;
7328: foreach my $item (@{$itemsref}) {
7329: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7330: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7331: $namesref->{$item}.
7332: '</span></td>'.
7333: '<td class="LC_left_item">';
7334: if (($item eq 'url') || ($item eq 'button')) {
7335: $datatable .= '<span class="LC_nobreak">'.
7336: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7337: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7338: } elsif ($item eq 'fields') {
7339: my @currfields;
7340: if (ref($currvalidation{$item}) eq 'ARRAY') {
7341: @currfields = @{$currvalidation{$item}};
7342: }
7343: foreach my $field (@{$fieldsref}) {
7344: my $check = '';
7345: if (grep(/^\Q$field\E$/,@currfields)) {
7346: $check = ' checked="checked"';
7347: }
7348: $datatable .= '<span class="LC_nobreak"><label>'.
7349: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7350: ' value="'.$field.'"'.$check.' />'.$field.
7351: '</label></span> ';
7352: }
7353: } elsif ($item eq 'markup') {
1.334 raeburn 7354: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7355: $currvalidation{$item}.
1.231 raeburn 7356: '</textarea>';
1.235 raeburn 7357: }
7358: $datatable .= '</td></tr>'."\n";
7359: if (ref($rowtotal)) {
1.231 raeburn 7360: $itemcount ++;
7361: }
7362: }
1.235 raeburn 7363: if ($caller eq 'requestcourses') {
7364: my %currhash;
1.248 raeburn 7365: if (ref($settings) eq 'HASH') {
7366: if (ref($settings->{'validation'}) eq 'HASH') {
7367: if ($settings->{'validation'}{'dc'} ne '') {
7368: $currhash{$settings->{'validation'}{'dc'}} = 1;
7369: }
1.235 raeburn 7370: }
7371: }
7372: my $numinrow = 2;
7373: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7374: 'validationdc',%currhash);
1.247 raeburn 7375: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7376: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7377: if ($numdc > 1) {
1.247 raeburn 7378: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7379: } else {
1.247 raeburn 7380: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7381: }
1.247 raeburn 7382: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7383: $itemcount ++;
7384: }
7385: if (ref($rowtotal)) {
7386: $$rowtotal += $itemcount;
7387: }
1.231 raeburn 7388: return $datatable;
7389: }
7390:
1.357 raeburn 7391: sub print_privacy {
7392: my ($position,$dom,$settings,$rowtotal) = @_;
7393: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7394: my $itemcount = 0;
1.417 raeburn 7395: if ($position eq 'top') {
7396: $numinrow = 2;
7397: } else {
1.357 raeburn 7398: @items = ('domain','author','course','community');
7399: %names = &Apache::lonlocal::texthash (
7400: domain => 'Assigned domain role(s)',
7401: author => 'Assigned co-author role(s)',
7402: course => 'Assigned course role(s)',
1.416 raeburn 7403: community => 'Assigned community role(s)',
1.357 raeburn 7404: );
7405: $numinrow = 4;
7406: ($othertitle,$usertypes,$types) =
7407: &Apache::loncommon::sorted_inst_types($dom);
7408: }
7409: if (($position eq 'top') || ($position eq 'middle')) {
7410: my (%by_ip,%by_location,@intdoms,@instdoms);
7411: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7412: if ($position eq 'top') {
7413: my %curr;
7414: my @options = ('none','user','domain','auto');
7415: my %titles = &Apache::lonlocal::texthash (
7416: none => 'Not allowed',
7417: user => 'User authorizes',
7418: domain => 'DC authorizes',
7419: auto => 'Unrestricted',
7420: instdom => 'Other domain shares institution/provider',
7421: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7422: notify => 'Notify when role needs authorization',
1.357 raeburn 7423: );
7424: my %names = &Apache::lonlocal::texthash (
7425: domain => 'Domain role',
7426: author => 'Co-author role',
7427: course => 'Course role',
7428: community => 'Community role',
7429: );
7430: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7431: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7432: foreach my $domtype ('instdom','extdom') {
7433: my (%checked,$skip);
7434: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7435: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7436: '<td class="LC_left_item">';
7437: if ($domtype eq 'instdom') {
7438: unless (@instdoms > 1) {
7439: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7440: $skip = 1;
7441: }
7442: } elsif ($domtype eq 'extdom') {
7443: if (keys(%by_location) == 0) {
7444: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7445: $skip = 1;
7446: }
7447: }
7448: unless ($skip) {
7449: foreach my $roletype ('domain','author','course','community') {
7450: $checked{'auto'} = ' checked="checked"';
7451: if (ref($settings) eq 'HASH') {
7452: if (ref($settings->{approval}) eq 'HASH') {
7453: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7454: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7455: $checked{$1} = ' checked="checked"';
7456: $checked{'auto'} = '';
7457: }
7458: }
7459: }
7460: }
7461: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7462: foreach my $option (@options) {
7463: $datatable .= '<span class="LC_nobreak"><label>'.
7464: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7465: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7466: '</label></span> ';
7467: }
7468: $datatable .= '</fieldset>';
7469: }
7470: }
7471: $datatable .= '</td></tr>';
7472: $itemcount ++;
7473: }
1.417 raeburn 7474: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7475: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7476: '<td class="LC_left_item">';
7477: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7478: my %curr;
7479: if (ref($settings) eq 'HASH') {
7480: if ($settings->{'notify'} ne '') {
7481: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7482: }
7483: }
7484: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7485: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7486: 'privacy_notify',%curr);
7487: if ($numdc > 0) {
7488: $datatable .= $table;
7489: } else {
7490: $datatable .= &mt('There are no active Domain Coordinators');
7491: }
7492: } else {
7493: $datatable .= &mt('Nothing to set here, as there are no other domains');
7494: }
7495: $datatable .='</td></tr>';
1.357 raeburn 7496: } elsif ($position eq 'middle') {
7497: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7498: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7499: foreach my $item (@{$types}) {
7500: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7501: $numinrow,$itemcount,'','','','','',
7502: '',$usertypes->{$item});
7503: $itemcount ++;
7504: }
7505: }
7506: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7507: $numinrow,$itemcount,'','','','','',
7508: '',$othertitle);
7509: $itemcount ++;
7510: } else {
1.360 raeburn 7511: my (@insttypes,%insttitles);
7512: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7513: @insttypes = @{$types};
7514: %insttitles = %{$usertypes};
7515: }
7516: foreach my $item (@insttypes,'default') {
7517: my $title;
7518: if ($item eq 'default') {
7519: $title = $othertitle;
7520: } else {
7521: $title = $insttitles{$item};
7522: }
7523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7524: $datatable .= '<tr'.$css_class.'>'.
7525: '<td class="LC_left_item">'.$title.'</td>'.
7526: '<td class="LC_left_item">'.
7527: &mt('Nothing to set here, as there are no other domains').
7528: '</td></tr>';
7529: $itemcount ++;
7530: }
1.357 raeburn 7531: }
7532: }
7533: } else {
7534: my $prefix;
7535: if ($position eq 'lower') {
7536: $prefix = 'priv';
7537: } else {
7538: $prefix = 'unpriv';
7539: }
7540: foreach my $item (@items) {
7541: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7542: $numinrow,$itemcount,'','','','','',
7543: '',$names{$item});
7544: $itemcount ++;
7545: }
7546: }
7547: if (ref($rowtotal)) {
7548: $$rowtotal += $itemcount;
7549: }
7550: return $datatable;
7551: }
7552:
1.354 raeburn 7553: sub print_passwords {
7554: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7555: my ($datatable,$css_class);
7556: my $itemcount = 0;
7557: my %titles = &Apache::lonlocal::texthash (
7558: captcha => '"Forgot Password" CAPTCHA validation',
7559: link => 'Reset link expiration (hours)',
7560: case => 'Case-sensitive usernames/e-mail',
7561: prelink => 'Information required (form 1)',
7562: postlink => 'Information required (form 2)',
7563: emailsrc => 'LON-CAPA e-mail address type(s)',
7564: customtext => 'Domain specific text (HTML)',
7565: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7566: intauth_check => 'Check bcrypt cost if authenticated',
7567: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7568: permanent => 'Permanent e-mail address',
7569: critical => 'Critical notification address',
7570: notify => 'Notification address',
7571: min => 'Minimum password length',
7572: max => 'Maximum password length',
7573: chars => 'Required characters',
7574: expire => 'Password expiration (days)',
1.356 raeburn 7575: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7576: );
7577: if ($position eq 'top') {
7578: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7579: my $shownlinklife = 2;
7580: my $prelink = 'both';
7581: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7582: if (ref($settings) eq 'HASH') {
7583: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7584: $shownlinklife = $settings->{resetlink};
7585: }
7586: if (ref($settings->{resetcase}) eq 'ARRAY') {
7587: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7588: }
7589: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7590: $prelink = $settings->{resetprelink};
7591: }
7592: if (ref($settings->{resetpostlink}) eq 'HASH') {
7593: %postlink = %{$settings->{resetpostlink}};
7594: }
7595: if (ref($settings->{resetemail}) eq 'ARRAY') {
7596: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7597: }
7598: if ($settings->{resetremove}) {
7599: $nostdtext = 1;
7600: }
7601: if ($settings->{resetcustom}) {
7602: $customurl = $settings->{resetcustom};
7603: }
7604: } else {
7605: if (ref($types) eq 'ARRAY') {
7606: foreach my $item (@{$types}) {
7607: $casesens{$item} = 1;
7608: $postlink{$item} = ['username','email'];
7609: }
7610: }
7611: $casesens{'default'} = 1;
7612: $postlink{'default'} = ['username','email'];
7613: $prelink = 'both';
7614: %emailsrc = (
7615: permanent => 1,
7616: critical => 1,
7617: notify => 1,
7618: );
7619: }
7620: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7621: $itemcount ++;
7622: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7623: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7624: '<td class="LC_left_item">'.
7625: '<input type="textbox" value="'.$shownlinklife.'" '.
7626: 'name="passwords_link" size="3" /></td></tr>';
7627: $itemcount ++;
7628: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7629: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7630: '<td class="LC_left_item">';
7631: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7632: foreach my $item (@{$types}) {
7633: my $checkedcase;
7634: if ($casesens{$item}) {
7635: $checkedcase = ' checked="checked"';
7636: }
7637: $datatable .= '<span class="LC_nobreak"><label>'.
7638: '<input type="checkbox" name="passwords_case_sensitive" value="'.
7639: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 7640: '</span> ';
1.354 raeburn 7641: }
7642: }
7643: my $checkedcase;
7644: if ($casesens{'default'}) {
7645: $checkedcase = ' checked="checked"';
7646: }
7647: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7648: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
7649: $othertitle.'</label></span></td>';
7650: $itemcount ++;
7651: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7652: my %checkedpre = (
7653: both => ' checked="checked"',
7654: either => '',
7655: );
7656: if ($prelink eq 'either') {
7657: $checkedpre{either} = ' checked="checked"';
7658: $checkedpre{both} = '';
7659: }
7660: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7661: '<td class="LC_left_item"><span class="LC_nobreak">'.
7662: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7663: &mt('Both username and e-mail address').'</label></span> '.
7664: '<span class="LC_nobreak"><label>'.
7665: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7666: &mt('Either username or e-mail address').'</label></span></td></tr>';
7667: $itemcount ++;
7668: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7669: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7670: '<td class="LC_left_item">';
7671: my %postlinked;
7672: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7673: foreach my $item (@{$types}) {
7674: undef(%postlinked);
7675: $datatable .= '<fieldset style="display: inline-block;">'.
7676: '<legend>'.$usertypes->{$item}.'</legend>';
7677: if (ref($postlink{$item}) eq 'ARRAY') {
7678: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7679: }
7680: foreach my $field ('email','username') {
7681: my $checked;
7682: if ($postlinked{$field}) {
7683: $checked = ' checked="checked"';
7684: }
7685: $datatable .= '<span class="LC_nobreak"><label>'.
7686: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7687: $field.'"'.$checked.' />'.$field.'</label>'.
7688: '<span> ';
7689: }
7690: $datatable .= '</fieldset>';
7691: }
7692: }
7693: if (ref($postlink{'default'}) eq 'ARRAY') {
7694: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7695: }
7696: $datatable .= '<fieldset style="display: inline-block;">'.
7697: '<legend>'.$othertitle.'</legend>';
7698: foreach my $field ('email','username') {
7699: my $checked;
7700: if ($postlinked{$field}) {
7701: $checked = ' checked="checked"';
7702: }
7703: $datatable .= '<span class="LC_nobreak"><label>'.
7704: '<input type="checkbox" name="passwords_postlink_default" value="'.
7705: $field.'"'.$checked.' />'.$field.'</label>'.
7706: '<span> ';
7707: }
7708: $datatable .= '</fieldset></td></tr>';
7709: $itemcount ++;
7710: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7711: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7712: '<td class="LC_left_item">';
7713: foreach my $type ('permanent','critical','notify') {
7714: my $checkedemail;
7715: if ($emailsrc{$type}) {
7716: $checkedemail = ' checked="checked"';
7717: }
7718: $datatable .= '<span class="LC_nobreak"><label>'.
7719: '<input type="checkbox" name="passwords_emailsrc" value="'.
7720: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7721: '<span> ';
7722: }
7723: $datatable .= '</td></tr>';
7724: $itemcount ++;
7725: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7726: my $switchserver = &check_switchserver($dom,$confname);
7727: my ($showstd,$noshowstd);
7728: if ($nostdtext) {
7729: $noshowstd = ' checked="checked"';
7730: } else {
7731: $showstd = ' checked="checked"';
7732: }
7733: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7734: '<td class="LC_left_item"><span class="LC_nobreak">'.
7735: &mt('Retain standard text:').
7736: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7737: &mt('Yes').'</label>'.' '.
7738: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7739: &mt('No').'</label></span><br />'.
7740: '<span class="LC_fontsize_small">'.
7741: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7742: &mt('Include custom text:');
7743: if ($customurl) {
1.369 raeburn 7744: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 7745: undef,undef,undef,undef,'background-color:#ffffff');
7746: $datatable .= '<span class="LC_nobreak"> '.$link.
7747: '<label><input type="checkbox" name="passwords_custom_del"'.
7748: ' value="1" />'.&mt('Delete?').'</label></span>'.
7749: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7750: }
7751: if ($switchserver) {
7752: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7753: } else {
7754: $datatable .='<span class="LC_nobreak"> '.
7755: '<input type="file" name="passwords_customfile" /></span>';
7756: }
7757: $datatable .= '</td></tr>';
7758: } elsif ($position eq 'middle') {
7759: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7760: my @items = ('intauth_cost','intauth_check','intauth_switch');
7761: my %defaults;
7762: if (ref($domconf{'defaults'}) eq 'HASH') {
7763: %defaults = %{$domconf{'defaults'}};
7764: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7765: $defaults{'intauth_cost'} = 10;
7766: }
7767: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7768: $defaults{'intauth_check'} = 0;
7769: }
7770: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7771: $defaults{'intauth_switch'} = 0;
7772: }
7773: } else {
7774: %defaults = (
7775: 'intauth_cost' => 10,
7776: 'intauth_check' => 0,
7777: 'intauth_switch' => 0,
7778: );
7779: }
7780: foreach my $item (@items) {
7781: if ($itemcount%2) {
7782: $css_class = '';
7783: } else {
7784: $css_class = ' class="LC_odd_row" ';
7785: }
7786: $datatable .= '<tr'.$css_class.'>'.
7787: '<td><span class="LC_nobreak">'.$titles{$item}.
7788: '</span></td><td class="LC_left_item" colspan="3">';
7789: if ($item eq 'intauth_switch') {
7790: my @options = (0,1,2);
7791: my %optiondesc = &Apache::lonlocal::texthash (
7792: 0 => 'No',
7793: 1 => 'Yes',
7794: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7795: );
7796: $datatable .= '<table width="100%">';
7797: foreach my $option (@options) {
7798: my $checked = ' ';
7799: if ($defaults{$item} eq $option) {
7800: $checked = ' checked="checked"';
7801: }
7802: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7803: '<label><input type="radio" name="'.$item.
7804: '" value="'.$option.'"'.$checked.' />'.
7805: $optiondesc{$option}.'</label></span></td></tr>';
7806: }
7807: $datatable .= '</table>';
7808: } elsif ($item eq 'intauth_check') {
7809: my @options = (0,1,2);
7810: my %optiondesc = &Apache::lonlocal::texthash (
7811: 0 => 'No',
7812: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7813: 2 => 'Yes, disallow login if stored cost is less than domain default',
7814: );
7815: $datatable .= '<table width="100%">';
7816: foreach my $option (@options) {
7817: my $checked = ' ';
7818: my $onclick;
7819: if ($defaults{$item} eq $option) {
7820: $checked = ' checked="checked"';
7821: }
7822: if ($option == 2) {
7823: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7824: }
7825: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7826: '<label><input type="radio" name="'.$item.
7827: '" value="'.$option.'"'.$checked.$onclick.' />'.
7828: $optiondesc{$option}.'</label></span></td></tr>';
7829: }
7830: $datatable .= '</table>';
7831: } else {
7832: $datatable .= '<input type="text" name="'.$item.'" value="'.
7833: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7834: }
7835: $datatable .= '</td></tr>';
7836: $itemcount ++;
7837: }
7838: } elsif ($position eq 'lower') {
1.405 raeburn 7839: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 7840: } else {
1.359 raeburn 7841: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7842: my %ownerchg = (
7843: by => {},
7844: for => {},
7845: );
7846: my %ownertitles = &Apache::lonlocal::texthash (
7847: by => 'Course owner status(es) allowed',
7848: for => 'Student status(es) allowed',
7849: );
1.354 raeburn 7850: if (ref($settings) eq 'HASH') {
1.359 raeburn 7851: if (ref($settings->{crsownerchg}) eq 'HASH') {
7852: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7853: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7854: }
7855: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7856: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7857: }
1.354 raeburn 7858: }
7859: }
7860: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7861: $datatable .= '<tr '.$css_class.'>'.
7862: '<td>'.
7863: &mt('Requirements').'<ul>'.
1.359 raeburn 7864: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 7865: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7866: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 7867: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 7868: '</ul>'.
7869: '</td>'.
1.359 raeburn 7870: '<td class="LC_left_item">';
7871: foreach my $item ('by','for') {
7872: $datatable .= '<fieldset style="display: inline-block;">'.
7873: '<legend>'.$ownertitles{$item}.'</legend>';
7874: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7875: foreach my $type (@{$types}) {
7876: my $checked;
7877: if ($ownerchg{$item}{$type}) {
7878: $checked = ' checked="checked"';
7879: }
7880: $datatable .= '<span class="LC_nobreak"><label>'.
7881: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7882: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 7883: '</span> ';
1.359 raeburn 7884: }
7885: }
7886: my $checked;
7887: if ($ownerchg{$item}{'default'}) {
7888: $checked = ' checked="checked"';
7889: }
7890: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7891: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7892: $othertitle.'</label></span></fieldset>';
7893: }
7894: $datatable .= '</td></tr>';
1.354 raeburn 7895: }
7896: return $datatable;
7897: }
7898:
1.405 raeburn 7899: sub password_rules {
7900: my ($prefix,$itemcountref,$settings) = @_;
7901: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
7902: my %titles;
7903: if ($prefix eq 'passwords') {
7904: %titles = &Apache::lonlocal::texthash (
7905: min => 'Minimum password length',
7906: max => 'Maximum password length',
7907: chars => 'Required characters',
7908: );
1.421 raeburn 7909: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 7910: %titles = &Apache::lonlocal::texthash (
7911: min => 'Minimum secret length',
7912: max => 'Maximum secret length',
7913: chars => 'Required characters',
7914: );
7915: }
7916: $min = $Apache::lonnet::passwdmin;
7917: my $datatable;
7918: my $itemcount;
7919: if (ref($itemcountref)) {
7920: $itemcount = $$itemcountref;
7921: }
7922: if (ref($settings) eq 'HASH') {
7923: if ($settings->{min}) {
7924: $min = $settings->{min};
7925: }
7926: if ($settings->{max}) {
7927: $max = $settings->{max};
7928: }
7929: if (ref($settings->{chars}) eq 'ARRAY') {
7930: map { $chars{$_} = 1; } (@{$settings->{chars}});
7931: }
7932: if ($prefix eq 'passwords') {
7933: if ($settings->{expire}) {
7934: $expire = $settings->{expire};
7935: }
7936: if ($settings->{numsaved}) {
7937: $numsaved = $settings->{numsaved};
7938: }
7939: }
7940: }
7941: my %rulenames = &Apache::lonlocal::texthash(
7942: uc => 'At least one upper case letter',
7943: lc => 'At least one lower case letter',
7944: num => 'At least one number',
7945: spec => 'At least one non-alphanumeric',
7946: );
7947: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7948: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7949: '<td class="LC_left_item"><span class="LC_nobreak">'.
7950: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7951: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7952: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7953: '</span></td></tr>';
7954: $itemcount ++;
7955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7956: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7957: '<td class="LC_left_item"><span class="LC_nobreak">'.
7958: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7959: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7960: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7961: '</span></td></tr>';
7962: $itemcount ++;
7963: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7964: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7965: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7966: '</span></td>';
7967: my $numinrow = 2;
7968: my @possrules = ('uc','lc','num','spec');
7969: $datatable .= '<td class="LC_left_item"><table>';
7970: for (my $i=0; $i<@possrules; $i++) {
7971: my ($rem,$checked);
7972: if ($chars{$possrules[$i]}) {
7973: $checked = ' checked="checked"';
7974: }
7975: $rem = $i%($numinrow);
7976: if ($rem == 0) {
7977: if ($i > 0) {
7978: $datatable .= '</tr>';
7979: }
7980: $datatable .= '<tr>';
7981: }
7982: $datatable .= '<td><span class="LC_nobreak"><label>'.
7983: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7984: $rulenames{$possrules[$i]}.'</label></span></td>';
7985: }
7986: my $rem = @possrules%($numinrow);
7987: my $colsleft = $numinrow - $rem;
7988: if ($colsleft > 1 ) {
7989: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7990: ' </td>';
7991: } elsif ($colsleft == 1) {
7992: $datatable .= '<td class="LC_left_item"> </td>';
7993: }
7994: $datatable .='</table></td></tr>';
7995: $itemcount ++;
7996: if ($prefix eq 'passwords') {
7997: $titles{'expire'} = &mt('Password expiration (days)');
7998: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8000: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8001: '<td class="LC_left_item"><span class="LC_nobreak">'.
8002: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8003: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8004: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8005: '</span></td></tr>';
8006: $itemcount ++;
8007: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8008: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8009: '<td class="LC_left_item"><span class="LC_nobreak">'.
8010: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8011: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8012: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8013: '</span></td></tr>';
8014: $itemcount ++;
8015: }
8016: if (ref($itemcountref)) {
8017: $$itemcountref += $itemcount;
8018: }
8019: return $datatable;
8020: }
8021:
1.373 raeburn 8022: sub print_wafproxy {
8023: my ($position,$dom,$settings,$rowtotal) = @_;
8024: my $css_class;
8025: my $itemcount = 0;
8026: my $datatable;
8027: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8028: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8029: my %lt = &wafproxy_titles();
1.373 raeburn 8030: foreach my $server (sort(keys(%servers))) {
8031: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8032: next if ($serverhome eq '');
1.373 raeburn 8033: my $serverdom;
8034: if ($serverhome ne $server) {
8035: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8036: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8037: $othercontrol{$server} = $serverdom;
8038: }
1.373 raeburn 8039: } else {
8040: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8041: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8042: if ($serverdom ne $dom) {
8043: $othercontrol{$server} = $serverdom;
8044: } else {
8045: $setdom = 1;
8046: if (ref($settings) eq 'HASH') {
8047: if (ref($settings->{'alias'}) eq 'HASH') {
8048: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8049: if ($aliases{$dom} ne '') {
8050: $showdom = 1;
8051: }
1.373 raeburn 8052: }
1.388 raeburn 8053: if (ref($settings->{'saml'}) eq 'HASH') {
8054: $saml{$dom} = $settings->{'saml'};
8055: }
1.373 raeburn 8056: }
8057: }
8058: }
8059: }
1.381 raeburn 8060: if ($setdom) {
8061: %{$values{$dom}} = ();
8062: if (ref($settings) eq 'HASH') {
8063: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8064: $values{$dom}{$item} = $settings->{$item};
8065: }
8066: }
8067: }
1.373 raeburn 8068: if (keys(%othercontrol)) {
8069: %otherdoms = reverse(%othercontrol);
8070: foreach my $domain (keys(%otherdoms)) {
8071: %{$values{$domain}} = ();
8072: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8073: if (ref($config{'wafproxy'}) eq 'HASH') {
8074: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.388 raeburn 8075: if (exists($config{'wafproxy'}{'saml'})) {
8076: $saml{$domain} = $config{'wafproxy'}{'saml'};
8077: }
1.383 raeburn 8078: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8079: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8080: }
8081: }
8082: }
8083: }
8084: if ($position eq 'top') {
8085: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8086: my %aliasinfo;
1.373 raeburn 8087: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8088: $itemcount ++;
8089: my $dom_in_effect;
8090: my $aliasrows = '<tr>'.
1.383 raeburn 8091: '<td class="LC_left_item" style="vertical-align: baseline;">'.
8092: &mt('Hostname').': '.
8093: '<i>'.&Apache::lonnet::hostname($server).'</i></td><td> </td>';
1.373 raeburn 8094: if ($othercontrol{$server}) {
1.381 raeburn 8095: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8096: my ($current,$forsaml);
1.383 raeburn 8097: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8098: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8099: }
1.388 raeburn 8100: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8101: if ($saml{$dom_in_effect}{$server}) {
8102: $forsaml = 1;
8103: }
8104: }
1.383 raeburn 8105: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8106: &mt('Alias').': ';
1.373 raeburn 8107: if ($current) {
1.381 raeburn 8108: $aliasrows .= $current;
1.388 raeburn 8109: if ($forsaml) {
1.396 raeburn 8110: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8111: }
1.373 raeburn 8112: } else {
1.383 raeburn 8113: $aliasrows .= &mt('None');
1.373 raeburn 8114: }
1.383 raeburn 8115: $aliasrows .= ' <span class="LC_small">('.
8116: &mt('controlled by domain: [_1]',
8117: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8118: } else {
1.381 raeburn 8119: $dom_in_effect = $dom;
1.388 raeburn 8120: my ($current,$samlon,$samloff);
8121: $samloff = ' checked="checked"';
1.373 raeburn 8122: if (ref($aliases{$dom}) eq 'HASH') {
8123: if ($aliases{$dom}{$server}) {
8124: $current = $aliases{$dom}{$server};
8125: }
8126: }
1.388 raeburn 8127: if (ref($saml{$dom}) eq 'HASH') {
8128: if ($saml{$dom}{$server}) {
8129: $samlon = $samloff;
8130: undef($samloff);
8131: }
8132: }
1.383 raeburn 8133: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8134: &mt('Alias').': '.
1.381 raeburn 8135: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8136: 'value="'.$current.'" size="30" />'.
8137: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8138: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8139: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
8140: &mt('No').'</label> <label>'.
8141: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8142: &mt('Yes').'</label></span>'.
8143: '</td>';
1.381 raeburn 8144: }
8145: $aliasrows .= '</tr>';
8146: $aliasinfo{$dom_in_effect} .= $aliasrows;
8147: }
8148: if ($aliasinfo{$dom}) {
8149: my ($onclick,$wafon,$wafoff,$showtable);
8150: $onclick = ' onclick="javascript:toggleWAF();"';
8151: $wafoff = ' checked="checked"';
8152: $showtable = ' style="display:none";';
8153: if ($showdom) {
8154: $wafon = $wafoff;
8155: $wafoff = '';
8156: $showtable = ' style="display:inline;"';
8157: }
8158: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8159: $datatable = '<tr'.$css_class.'>'.
8160: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8161: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8162: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8163: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8164: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8165: &mt('No').'</label></span></td>'.
8166: '<td class="LC_left_item">'.
8167: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8168: '</table></td></tr>';
8169: $itemcount++;
8170: }
1.383 raeburn 8171: if (keys(%otherdoms)) {
8172: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8173: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8174: $datatable .= '<tr'.$css_class.'>'.
8175: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8176: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8177: '</table></td></tr>';
1.381 raeburn 8178: $itemcount++;
1.373 raeburn 8179: }
8180: }
8181: } else {
1.383 raeburn 8182: my %ip_methods = &remoteip_methods();
1.373 raeburn 8183: if ($setdom) {
8184: $itemcount ++;
8185: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8186: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8187: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8188: $wafstyle = ' style="display:none;"';
8189: $nowafstyle = ' style="display:table-row;"';
8190: $currwafdisplay = ' style="display: none"';
8191: $wafrangestyle = ' style="display: none"';
8192: $curr_remotip = 'n';
1.382 raeburn 8193: $ssltossl = ' checked="checked"';
1.381 raeburn 8194: if ($showdom) {
8195: $wafstyle = ' style="display:table-row;"';
8196: $nowafstyle = ' style="display:none;"';
8197: if (keys(%{$values{$dom}})) {
8198: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8199: $curr_remotip = $values{$dom}{remoteip};
8200: }
8201: if ($curr_remotip eq 'h') {
8202: $currwafdisplay = ' style="display:table-row"';
8203: $wafrangestyle = ' style="display:inline-block;"';
8204: }
1.382 raeburn 8205: if ($values{$dom}{'sslopt'}) {
8206: $alltossl = ' checked="checked"';
8207: $ssltossl = '';
8208: }
1.381 raeburn 8209: }
8210: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8211: $vpndircheck = ' checked="checked"';
8212: $currwafvpn = ' style="display:table-row;"';
8213: $wafrangestyle = ' style="display:inline-block;"';
8214: } else {
8215: $vpnaliascheck = ' checked="checked"';
8216: $currwafvpn = ' style="display:none;"';
8217: }
8218: }
8219: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8220: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8221: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8222: '</tr>'.
8223: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8224: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8225: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8226: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8227: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8228: '<td class="LC_left_item"><table>'.
8229: '<tr>'.
8230: '<td valign="top">'.$lt{'remoteip'}.': '.
8231: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8232: foreach my $option ('m','h','n') {
8233: my $sel;
8234: if ($option eq $curr_remotip) {
8235: $sel = ' selected="selected"';
8236: }
8237: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8238: $ip_methods{$option}.'</option>';
8239: }
8240: $datatable .= '</select></td></tr>'."\n".
8241: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8242: $lt{'ipheader'}.': '.
8243: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8244: 'name="wafproxy_ipheader" />'.
8245: '</td></tr>'."\n".
8246: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8247: $lt{'trusted'}.':<br />'.
1.381 raeburn 8248: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8249: $values{$dom}{'trusted'}.'</textarea>'.
8250: '</td></tr>'."\n".
8251: '<tr><td><hr /></td></tr>'."\n".
8252: '<tr>'.
8253: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8254: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8255: $lt{'vpndirect'}.'</label>'.(' 'x2).
8256: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8257: $lt{'vpnaliased'}.'</label></span></td></tr>';
8258: foreach my $item ('vpnint','vpnext') {
8259: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8260: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8261: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8262: $values{$dom}{$item}.'</textarea>'.
8263: '</td></tr>'."\n";
1.373 raeburn 8264: }
1.382 raeburn 8265: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8266: '<tr>'.
8267: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8268: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8269: $lt{'alltossl'}.'</label>'.(' 'x2).
8270: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8271: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8272: '</table></td></tr>';
1.373 raeburn 8273: }
8274: if (keys(%otherdoms)) {
8275: foreach my $domain (sort(keys(%otherdoms))) {
8276: $itemcount ++;
8277: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8278: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8279: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8280: '<td class="LC_left_item"><table>';
1.382 raeburn 8281: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8282: my $showval = &mt('None');
1.382 raeburn 8283: if ($item eq 'ssl') {
8284: $showval = $lt{'ssltossl'};
8285: }
1.373 raeburn 8286: if ($values{$domain}{$item}) {
1.381 raeburn 8287: $showval = $values{$domain}{$item};
1.382 raeburn 8288: if ($item eq 'ssl') {
8289: $showval = $lt{'alltossl'};
1.383 raeburn 8290: } elsif ($item eq 'remoteip') {
8291: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8292: }
1.373 raeburn 8293: }
8294: $datatable .= '<tr>'.
8295: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8296: }
1.381 raeburn 8297: $datatable .= '</table></td></tr>';
1.373 raeburn 8298: }
8299: }
8300: }
8301: $$rowtotal += $itemcount;
8302: return $datatable;
8303: }
8304:
8305: sub wafproxy_titles {
8306: return &Apache::lonlocal::texthash(
1.381 raeburn 8307: remoteip => "Method for determining user's IP",
8308: ipheader => 'Request header containing remote IP',
8309: trusted => 'Trusted IP range(s)',
8310: vpnaccess => 'Access from institutional VPN',
8311: vpndirect => 'via regular hostname (no WAF)',
8312: vpnaliased => 'via aliased hostname (WAF)',
8313: vpnint => 'Internal IP Range(s) for VPN sessions',
8314: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8315: sslopt => 'Forwarding http/https',
1.381 raeburn 8316: alltossl => 'WAF forwards both http and https requests to https',
8317: ssltossl => 'WAF forwards http requests to http and https to https',
8318: );
8319: }
8320:
8321: sub remoteip_methods {
8322: return &Apache::lonlocal::texthash(
8323: m => 'Use Apache mod_remoteip',
8324: h => 'Use headers parsed by LON-CAPA',
8325: n => 'Not in use',
1.373 raeburn 8326: );
8327: }
8328:
1.137 raeburn 8329: sub print_usersessions {
8330: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8331: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8332: my (%by_ip,%by_location,@intdoms,@instdoms);
8333: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8334:
8335: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8336: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8337: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8338: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8339: if ($position eq 'top') {
1.152 raeburn 8340: if (keys(%serverhomes) > 1) {
1.145 raeburn 8341: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8342: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8343: if (ref($settings) eq 'HASH') {
8344: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8345: $curroffloadnow = $settings->{'offloadnow'};
8346: }
1.371 raeburn 8347: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8348: $curroffloadoth = $settings->{'offloadoth'};
8349: }
1.261 raeburn 8350: }
1.371 raeburn 8351: my $other_insts = scalar(keys(%by_location));
8352: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8353: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8354: } else {
1.140 raeburn 8355: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8356: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8357: '</td></tr>';
1.140 raeburn 8358: }
1.137 raeburn 8359: } else {
1.279 raeburn 8360: my %titles = &usersession_titles();
8361: my ($prefix,@types);
8362: if ($position eq 'bottom') {
8363: $prefix = 'remote';
8364: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8365: } else {
1.279 raeburn 8366: $prefix = 'hosted';
8367: @types = ('excludedomain','includedomain');
8368: }
8369: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8370: }
8371: $$rowtotal += $itemcount;
8372: return $datatable;
8373: }
8374:
8375: sub rules_by_location {
8376: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8377: my ($datatable,$itemcount,$css_class);
8378: if (keys(%{$by_location}) == 0) {
8379: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8380: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8381: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8382: '</td></tr>';
8383: $itemcount = 1;
8384: } else {
8385: $itemcount = 0;
8386: my $numinrow = 5;
8387: my (%current,%checkedon,%checkedoff);
8388: my @locations = sort(keys(%{$by_location}));
8389: foreach my $type (@{$types}) {
8390: $checkedon{$type} = '';
8391: $checkedoff{$type} = ' checked="checked"';
8392: }
8393: if (ref($settings) eq 'HASH') {
8394: if (ref($settings->{$prefix}) eq 'HASH') {
8395: foreach my $key (keys(%{$settings->{$prefix}})) {
8396: $current{$key} = $settings->{$prefix}{$key};
8397: if ($key eq 'version') {
8398: if ($current{$key} ne '') {
1.145 raeburn 8399: $checkedon{$key} = ' checked="checked"';
8400: $checkedoff{$key} = '';
8401: }
1.279 raeburn 8402: } elsif (ref($current{$key}) eq 'ARRAY') {
8403: $checkedon{$key} = ' checked="checked"';
8404: $checkedoff{$key} = '';
1.137 raeburn 8405: }
8406: }
8407: }
1.279 raeburn 8408: }
8409: foreach my $type (@{$types}) {
8410: next if ($type ne 'version' && !@locations);
8411: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8412: $datatable .= '<tr'.$css_class.'>
8413: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8414: <span class="LC_nobreak">
8415: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8416: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8417: if ($type eq 'version') {
8418: my @lcversions = &Apache::lonnet::all_loncaparevs();
8419: my $selector = '<select name="'.$prefix.'_version">';
8420: foreach my $version (@lcversions) {
8421: my $selected = '';
8422: if ($current{'version'} eq $version) {
8423: $selected = ' selected="selected"';
1.145 raeburn 8424: }
1.279 raeburn 8425: $selector .= ' <option value="'.$version.'"'.
8426: $selected.'>'.$version.'</option>';
8427: }
8428: $selector .= '</select> ';
8429: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8430: } else {
8431: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8432: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8433: ' />'.(' 'x2).
8434: '<input type="button" value="'.&mt('uncheck all').'" '.
8435: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8436: "\n".
8437: '</div><div><table>';
8438: my $rem;
8439: for (my $i=0; $i<@locations; $i++) {
8440: my ($showloc,$value,$checkedtype);
8441: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8442: my $ip = $by_location->{$locations[$i]}->[0];
8443: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8444: $value = join(':',@{$by_ip->{$ip}});
8445: $showloc = join(', ',@{$by_ip->{$ip}});
8446: if (ref($current{$type}) eq 'ARRAY') {
8447: foreach my $loc (@{$by_ip->{$ip}}) {
8448: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8449: $checkedtype = ' checked="checked"';
8450: last;
1.145 raeburn 8451: }
1.138 raeburn 8452: }
8453: }
8454: }
1.137 raeburn 8455: }
1.279 raeburn 8456: $rem = $i%($numinrow);
8457: if ($rem == 0) {
8458: if ($i > 0) {
8459: $datatable .= '</tr>';
8460: }
8461: $datatable .= '<tr>';
8462: }
8463: $datatable .= '<td class="LC_left_item">'.
8464: '<span class="LC_nobreak"><label>'.
8465: '<input type="checkbox" name="'.$prefix.'_'.$type.
8466: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8467: '</label></span></td>';
8468: }
8469: $rem = @locations%($numinrow);
8470: my $colsleft = $numinrow - $rem;
8471: if ($colsleft > 1 ) {
8472: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8473: ' </td>';
8474: } elsif ($colsleft == 1) {
8475: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8476: }
1.279 raeburn 8477: $datatable .= '</tr></table>';
1.137 raeburn 8478: }
1.279 raeburn 8479: $datatable .= '</td></tr>';
8480: $itemcount ++;
1.137 raeburn 8481: }
8482: }
1.279 raeburn 8483: return ($datatable,$itemcount);
1.137 raeburn 8484: }
8485:
1.275 raeburn 8486: sub print_ssl {
8487: my ($position,$dom,$settings,$rowtotal) = @_;
8488: my ($css_class,$datatable);
8489: my $itemcount = 1;
8490: if ($position eq 'top') {
1.281 raeburn 8491: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8492: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8493: my $same_institution;
8494: if ($intdom ne '') {
8495: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8496: if (ref($internet_names) eq 'ARRAY') {
8497: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8498: $same_institution = 1;
8499: }
8500: }
8501: }
1.275 raeburn 8502: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8503: $datatable = '<tr'.$css_class.'><td colspan="2">';
8504: if ($same_institution) {
8505: my %domservers = &Apache::lonnet::get_servers($dom);
8506: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8507: } else {
8508: $datatable .= &mt("You need to be logged into one of your own domain's servers to display information about the status of LON-CAPA SSL certificates.");
8509: }
8510: $datatable .= '</td></tr>';
1.275 raeburn 8511: $itemcount ++;
8512: } else {
8513: my %titles = &ssl_titles();
8514: my (%by_ip,%by_location,@intdoms,@instdoms);
8515: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8516: my @alldoms = &Apache::lonnet::all_domains();
8517: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8518: my @domservers = &Apache::lonnet::get_servers($dom);
8519: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8520: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8521: if (($position eq 'connto') || ($position eq 'connfrom')) {
8522: my $legacy;
8523: unless (ref($settings) eq 'HASH') {
8524: my $name;
8525: if ($position eq 'connto') {
8526: $name = 'loncAllowInsecure';
8527: } else {
8528: $name = 'londAllowInsecure';
8529: }
8530: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8531: my @ids=&Apache::lonnet::current_machine_ids();
8532: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8533: my %what = (
8534: $name => 1,
8535: );
8536: my ($result,$returnhash) =
8537: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8538: if ($result eq 'ok') {
8539: if (ref($returnhash) eq 'HASH') {
8540: $legacy = $returnhash->{$name};
8541: }
8542: }
8543: } else {
8544: $legacy = $Apache::lonnet::perlvar{$name};
8545: }
8546: }
1.275 raeburn 8547: foreach my $type ('dom','intdom','other') {
8548: my %checked;
8549: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8550: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8551: '<td class="LC_right_item">';
8552: my $skip;
8553: if ($type eq 'dom') {
8554: unless (keys(%servers) > 1) {
8555: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8556: $skip = 1;
8557: }
8558: }
8559: if ($type eq 'intdom') {
8560: unless (@instdoms > 1) {
8561: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8562: $skip = 1;
8563: }
8564: } elsif ($type eq 'other') {
8565: if (keys(%by_location) == 0) {
8566: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8567: $skip = 1;
8568: }
8569: }
8570: unless ($skip) {
8571: $checked{'yes'} = ' checked="checked"';
8572: if (ref($settings) eq 'HASH') {
1.293 raeburn 8573: if (ref($settings->{$position}) eq 'HASH') {
8574: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8575: $checked{$1} = $checked{'yes'};
8576: delete($checked{'yes'});
8577: }
8578: }
1.293 raeburn 8579: } else {
8580: if ($legacy == 0) {
8581: $checked{'req'} = $checked{'yes'};
8582: delete($checked{'yes'});
8583: }
1.275 raeburn 8584: }
8585: foreach my $option ('no','yes','req') {
8586: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8587: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8588: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8589: '</label></span>'.(' 'x2);
8590: }
8591: }
8592: $datatable .= '</td></tr>';
8593: $itemcount ++;
8594: }
8595: } else {
8596: my $prefix = 'replication';
8597: my @types = ('certreq','nocertreq');
1.279 raeburn 8598: if (keys(%by_location) == 0) {
8599: $datatable .= '<tr'.$css_class.'><td>'.
8600: &mt('Nothing to set here, as there are no other institutions').
8601: '</td></tr>';
8602: $itemcount ++;
1.275 raeburn 8603: } else {
1.279 raeburn 8604: ($datatable,$itemcount) =
8605: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8606: }
8607: }
8608: }
8609: $$rowtotal += $itemcount;
8610: return $datatable;
8611: }
8612:
8613: sub ssl_titles {
8614: return &Apache::lonlocal::texthash (
8615: dom => 'LON-CAPA servers/VMs from same domain',
8616: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8617: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8618: connto => 'Connections to other servers',
8619: connfrom => 'Connections from other servers',
1.275 raeburn 8620: replication => 'Replicating content to other institutions',
8621: certreq => 'Client certificate required, but specific domains exempt',
8622: nocertreq => 'No client certificate required, except for specific domains',
8623: no => 'SSL not used',
8624: yes => 'SSL Optional (used if available)',
8625: req => 'SSL Required',
8626: );
1.279 raeburn 8627: }
8628:
8629: sub print_trust {
8630: my ($prefix,$dom,$settings,$rowtotal) = @_;
8631: my ($css_class,$datatable,%checked,%choices);
8632: my (%by_ip,%by_location,@intdoms,@instdoms);
8633: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8634: my $itemcount = 1;
8635: my %titles = &trust_titles();
8636: my @types = ('exc','inc');
8637: if ($prefix eq 'top') {
8638: $prefix = 'content';
8639: } elsif ($prefix eq 'bottom') {
8640: $prefix = 'msg';
8641: }
8642: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8643: $$rowtotal += $itemcount;
8644: return $datatable;
8645: }
8646:
8647: sub trust_titles {
8648: return &Apache::lonlocal::texthash(
8649: content => "Access to this domain's content by others",
8650: shared => "Access to other domain's content by this domain",
8651: enroll => "Enrollment in this domain's courses by others",
8652: othcoau => "Co-author roles in this domain for others",
8653: coaurem => "Co-author roles for this domain's users elsewhere",
8654: domroles => "Domain roles in this domain assignable to others",
8655: catalog => "Course Catalog for this domain displayed elsewhere",
8656: reqcrs => "Requests for creation of courses in this domain by others",
8657: msg => "Users in other domains can send messages to this domain",
8658: exc => "Allow all, but exclude specific domains",
8659: inc => "Deny all, but include specific domains",
8660: );
1.275 raeburn 8661: }
8662:
1.138 raeburn 8663: sub build_location_hashes {
1.275 raeburn 8664: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 8665: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 8666: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 8667: my %iphost = &Apache::lonnet::get_iphost();
8668: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
8669: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
8670: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
8671: foreach my $id (@{$iphost{$primary_ip}}) {
8672: my $intdom = &Apache::lonnet::internet_dom($id);
8673: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
8674: push(@{$intdoms},$intdom);
8675: }
8676: }
8677: }
8678: foreach my $ip (keys(%iphost)) {
8679: if (ref($iphost{$ip}) eq 'ARRAY') {
8680: foreach my $id (@{$iphost{$ip}}) {
8681: my $location = &Apache::lonnet::internet_dom($id);
8682: if ($location) {
1.275 raeburn 8683: if (grep(/^\Q$location\E$/,@{$intdoms})) {
8684: my $dom = &Apache::lonnet::host_domain($id);
8685: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
8686: push(@{$instdoms},$dom);
8687: }
8688: next;
8689: }
1.138 raeburn 8690: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8691: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
8692: push(@{$by_ip->{$ip}},$location);
8693: }
8694: } else {
8695: $by_ip->{$ip} = [$location];
8696: }
8697: }
8698: }
8699: }
8700: }
8701: foreach my $ip (sort(keys(%{$by_ip}))) {
8702: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8703: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
8704: my $first = $by_ip->{$ip}->[0];
8705: if (ref($by_location->{$first}) eq 'ARRAY') {
8706: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
8707: push(@{$by_location->{$first}},$ip);
8708: }
8709: } else {
8710: $by_location->{$first} = [$ip];
8711: }
8712: }
8713: }
8714: return;
8715: }
8716:
1.145 raeburn 8717: sub current_offloads_to {
8718: my ($dom,$settings,$servers) = @_;
8719: my (%spareid,%otherdomconfigs);
1.152 raeburn 8720: if (ref($servers) eq 'HASH') {
1.145 raeburn 8721: foreach my $lonhost (sort(keys(%{$servers}))) {
8722: my $gotspares;
1.152 raeburn 8723: if (ref($settings) eq 'HASH') {
8724: if (ref($settings->{'spares'}) eq 'HASH') {
8725: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
8726: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
8727: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
8728: $gotspares = 1;
8729: }
1.145 raeburn 8730: }
8731: }
8732: unless ($gotspares) {
8733: my $gotspares;
8734: my $serverhomeID =
8735: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
8736: my $serverhomedom =
8737: &Apache::lonnet::host_domain($serverhomeID);
8738: if ($serverhomedom ne $dom) {
8739: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
8740: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8741: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8742: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8743: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8744: $gotspares = 1;
8745: }
8746: }
8747: } else {
8748: $otherdomconfigs{$serverhomedom} =
8749: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
8750: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
8751: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
8752: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
8753: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
8754: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
8755: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
8756: $gotspares = 1;
8757: }
8758: }
8759: }
8760: }
8761: }
8762: }
8763: }
8764: unless ($gotspares) {
8765: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
8766: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8767: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8768: } else {
8769: my $server_hostname = &Apache::lonnet::hostname($lonhost);
8770: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
8771: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
8772: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
8773: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
8774: } else {
1.150 raeburn 8775: my %what = (
8776: spareid => 1,
8777: );
8778: my ($result,$returnhash) =
8779: &Apache::lonnet::get_remote_globals($lonhost,\%what);
8780: if ($result eq 'ok') {
8781: if (ref($returnhash) eq 'HASH') {
8782: if (ref($returnhash->{'spareid'}) eq 'HASH') {
8783: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
8784: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
8785: }
8786: }
1.145 raeburn 8787: }
8788: }
8789: }
8790: }
8791: }
8792: }
8793: return %spareid;
8794: }
8795:
8796: sub spares_row {
1.371 raeburn 8797: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
8798: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 8799: my $css_class;
8800: my $numinrow = 4;
8801: my $itemcount = 1;
8802: my $datatable;
1.152 raeburn 8803: my %typetitles = &sparestype_titles();
8804: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 8805: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 8806: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
8807: my ($othercontrol,$serverdom);
8808: if ($serverhome ne $server) {
8809: $serverdom = &Apache::lonnet::host_domain($serverhome);
8810: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8811: } else {
8812: $serverdom = &Apache::lonnet::host_domain($server);
8813: if ($serverdom ne $dom) {
8814: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
8815: }
8816: }
8817: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 8818: my ($checkednow,$checkedoth);
1.261 raeburn 8819: if (ref($curroffloadnow) eq 'HASH') {
8820: if ($curroffloadnow->{$server}) {
8821: $checkednow = ' checked="checked"';
8822: }
8823: }
1.371 raeburn 8824: if (ref($curroffloadoth) eq 'HASH') {
8825: if ($curroffloadoth->{$server}) {
8826: $checkedoth = ' checked="checked"';
8827: }
8828: }
1.145 raeburn 8829: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8830: $datatable .= '<tr'.$css_class.'>
8831: <td rowspan="2">
1.183 bisitz 8832: <span class="LC_nobreak">'.
8833: &mt('[_1] when busy, offloads to:'
1.261 raeburn 8834: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 8835: '<span class="LC_nobreak">'."\n".
1.261 raeburn 8836: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 8837: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 8838: "\n";
1.371 raeburn 8839: if ($other_insts) {
8840: $datatable .= '<br />'.
8841: '<span class="LC_nobreak">'."\n".
8842: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
8843: ' '.&mt('Switch other institutions on next access').'</label></span>'.
8844: "\n";
8845: }
1.145 raeburn 8846: my (%current,%canselect);
1.152 raeburn 8847: my @choices =
8848: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
8849: foreach my $type ('primary','default') {
8850: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 8851: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
8852: my @spares = @{$spareid->{$server}{$type}};
8853: if (@spares > 0) {
1.152 raeburn 8854: if ($othercontrol) {
8855: $current{$type} = join(', ',@spares);
8856: } else {
8857: $current{$type} .= '<table>';
8858: my $numspares = scalar(@spares);
8859: for (my $i=0; $i<@spares; $i++) {
8860: my $rem = $i%($numinrow);
8861: if ($rem == 0) {
8862: if ($i > 0) {
8863: $current{$type} .= '</tr>';
8864: }
8865: $current{$type} .= '<tr>';
1.145 raeburn 8866: }
1.152 raeburn 8867: $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'".');" /> '.
8868: $spareid->{$server}{$type}[$i].
8869: '</label></td>'."\n";
8870: }
8871: my $rem = @spares%($numinrow);
8872: my $colsleft = $numinrow - $rem;
8873: if ($colsleft > 1 ) {
8874: $current{$type} .= '<td colspan="'.$colsleft.
8875: '" class="LC_left_item">'.
8876: ' </td>';
8877: } elsif ($colsleft == 1) {
8878: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8879: }
1.152 raeburn 8880: $current{$type} .= '</tr></table>';
1.150 raeburn 8881: }
1.145 raeburn 8882: }
8883: }
8884: if ($current{$type} eq '') {
8885: $current{$type} = &mt('None specified');
8886: }
1.152 raeburn 8887: if ($othercontrol) {
8888: if ($type eq 'primary') {
8889: $canselect{$type} = $othercontrol;
8890: }
8891: } else {
8892: $canselect{$type} =
8893: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8894: '<select name="newspare_'.$type.'_'.$server.'" '.
8895: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8896: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8897: if (@choices > 0) {
8898: foreach my $lonhost (@choices) {
8899: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8900: }
8901: }
8902: $canselect{$type} .= '</select>'."\n";
8903: }
8904: } else {
8905: $current{$type} = &mt('Could not be determined');
8906: if ($type eq 'primary') {
8907: $canselect{$type} = $othercontrol;
8908: }
1.145 raeburn 8909: }
1.152 raeburn 8910: if ($type eq 'default') {
8911: $datatable .= '<tr'.$css_class.'>';
8912: }
8913: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8914: '<td>'.$current{$type}.'</td>'."\n".
8915: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8916: }
8917: $itemcount ++;
8918: }
8919: }
8920: $$rowtotal += $itemcount;
8921: return $datatable;
8922: }
8923:
1.152 raeburn 8924: sub possible_newspares {
8925: my ($server,$currspares,$serverhomes,$altids) = @_;
8926: my $serverhostname = &Apache::lonnet::hostname($server);
8927: my %excluded;
8928: if ($serverhostname ne '') {
8929: %excluded = (
8930: $serverhostname => 1,
8931: );
8932: }
8933: if (ref($currspares) eq 'HASH') {
8934: foreach my $type (keys(%{$currspares})) {
8935: if (ref($currspares->{$type}) eq 'ARRAY') {
8936: if (@{$currspares->{$type}} > 0) {
8937: foreach my $curr (@{$currspares->{$type}}) {
8938: my $hostname = &Apache::lonnet::hostname($curr);
8939: $excluded{$hostname} = 1;
8940: }
8941: }
8942: }
8943: }
8944: }
8945: my @choices;
8946: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8947: if (keys(%{$serverhomes}) > 1) {
8948: foreach my $name (sort(keys(%{$serverhomes}))) {
8949: unless ($excluded{$name}) {
8950: if (exists($altids->{$serverhomes->{$name}})) {
8951: push(@choices,$altids->{$serverhomes->{$name}});
8952: } else {
8953: push(@choices,$serverhomes->{$name});
1.145 raeburn 8954: }
8955: }
8956: }
8957: }
8958: }
1.152 raeburn 8959: return sort(@choices);
1.145 raeburn 8960: }
8961:
1.150 raeburn 8962: sub print_loadbalancing {
8963: my ($dom,$settings,$rowtotal) = @_;
8964: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8965: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8966: my $numinrow = 1;
8967: my $datatable;
8968: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 8969: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 8970: if (ref($settings) eq 'HASH') {
8971: %existing = %{$settings};
8972: }
8973: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8974: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 8975: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8976: } else {
8977: return;
8978: }
8979: my ($othertitle,$usertypes,$types) =
8980: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 8981: my $rownum = 8;
1.150 raeburn 8982: if (ref($types) eq 'ARRAY') {
8983: $rownum += scalar(@{$types});
8984: }
1.171 raeburn 8985: my @css_class = ('LC_odd_row','LC_even_row');
8986: my $balnum = 0;
8987: my $islast;
8988: my (@toshow,$disabledtext);
8989: if (keys(%currbalancer) > 0) {
8990: @toshow = sort(keys(%currbalancer));
8991: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8992: push(@toshow,'');
8993: }
8994: } else {
8995: @toshow = ('');
8996: $disabledtext = &mt('No existing load balancer');
8997: }
8998: foreach my $lonhost (@toshow) {
8999: if ($balnum == scalar(@toshow)-1) {
9000: $islast = 1;
9001: } else {
9002: $islast = 0;
9003: }
9004: my $cssidx = $balnum%2;
9005: my $targets_div_style = 'display: none';
9006: my $disabled_div_style = 'display: block';
9007: my $homedom_div_style = 'display: none';
9008: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9009: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9010: '<p>';
9011: if ($lonhost eq '') {
1.210 raeburn 9012: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9013: if (keys(%currbalancer) > 0) {
9014: $datatable .= &mt('Add balancer:');
9015: } else {
9016: $datatable .= &mt('Enable balancer:');
9017: }
9018: $datatable .= ' '.
9019: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9020: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9021: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9022: '<option value="" selected="selected">'.&mt('None').
9023: '</option>'."\n";
9024: foreach my $server (sort(keys(%servers))) {
9025: next if ($currbalancer{$server});
9026: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9027: }
1.210 raeburn 9028: $datatable .=
1.171 raeburn 9029: '</select>'."\n".
9030: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9031: } else {
9032: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9033: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9034: &mt('Stop balancing').'</label>'.
9035: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9036: $targets_div_style = 'display: block';
9037: $disabled_div_style = 'display: none';
9038: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9039: $homedom_div_style = 'display: block';
9040: }
9041: }
1.306 raeburn 9042: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9043: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9044: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9045: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9046: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9047: my @sparestypes = ('primary','default');
9048: my %typetitles = &sparestype_titles();
1.284 raeburn 9049: my %hostherechecked = (
9050: no => ' checked="checked"',
9051: );
1.342 raeburn 9052: my %balcookiechecked = (
9053: no => ' checked="checked"',
9054: );
1.171 raeburn 9055: foreach my $sparetype (@sparestypes) {
9056: my $targettable;
9057: for (my $i=0; $i<$numspares; $i++) {
9058: my $checked;
9059: if (ref($currtargets{$lonhost}) eq 'HASH') {
9060: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9061: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9062: $checked = ' checked="checked"';
9063: }
9064: }
9065: }
9066: my ($chkboxval,$disabled);
9067: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9068: $chkboxval = $spares[$i];
9069: }
9070: if (exists($currbalancer{$spares[$i]})) {
9071: $disabled = ' disabled="disabled"';
9072: }
1.210 raeburn 9073: $targettable .=
1.253 raeburn 9074: '<td><span class="LC_nobreak"><label>'.
9075: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9076: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.253 raeburn 9077: '</span></label></span></td>';
1.171 raeburn 9078: my $rem = $i%($numinrow);
9079: if ($rem == 0) {
9080: if (($i > 0) && ($i < $numspares-1)) {
9081: $targettable .= '</tr>';
9082: }
9083: if ($i < $numspares-1) {
9084: $targettable .= '<tr>';
1.150 raeburn 9085: }
9086: }
9087: }
1.171 raeburn 9088: if ($targettable ne '') {
9089: my $rem = $numspares%($numinrow);
9090: my $colsleft = $numinrow - $rem;
9091: if ($colsleft > 1 ) {
9092: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9093: ' </td>';
9094: } elsif ($colsleft == 1) {
9095: $targettable .= '<td class="LC_left_item"> </td>';
9096: }
9097: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9098: '<table><tr>'.$targettable.'</tr></table><br />';
9099: }
1.284 raeburn 9100: $hostherechecked{$sparetype} = '';
9101: if (ref($currtargets{$lonhost}) eq 'HASH') {
9102: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9103: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9104: $hostherechecked{$sparetype} = ' checked="checked"';
9105: $hostherechecked{'no'} = '';
9106: }
9107: }
9108: }
9109: }
1.342 raeburn 9110: if ($currcookies{$lonhost}) {
9111: %balcookiechecked = (
9112: yes => ' checked="checked"',
9113: );
9114: }
1.284 raeburn 9115: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9116: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9117: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9118: foreach my $sparetype (@sparestypes) {
9119: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9120: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9121: '</i></label><br />';
1.171 raeburn 9122: }
1.342 raeburn 9123: $datatable .= &mt('Use balancer cookie').'<br />'.
9124: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9125: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9126: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9127: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9128: '</div></td></tr>'.
1.171 raeburn 9129: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9130: $othertitle,$usertypes,$types,\%servers,
9131: \%currbalancer,$lonhost,
9132: $targets_div_style,$homedom_div_style,
9133: $css_class[$cssidx],$balnum,$islast);
9134: $$rowtotal += $rownum;
9135: $balnum ++;
9136: }
9137: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9138: return $datatable;
9139: }
9140:
9141: sub get_loadbalancers_config {
1.342 raeburn 9142: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9143: return unless ((ref($servers) eq 'HASH') &&
9144: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9145: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9146: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9147: if (keys(%{$existing}) > 0) {
9148: my $oldlonhost;
9149: foreach my $key (sort(keys(%{$existing}))) {
9150: if ($key eq 'lonhost') {
9151: $oldlonhost = $existing->{'lonhost'};
9152: $currbalancer->{$oldlonhost} = 1;
9153: } elsif ($key eq 'targets') {
9154: if ($oldlonhost) {
9155: $currtargets->{$oldlonhost} = $existing->{'targets'};
9156: }
9157: } elsif ($key eq 'rules') {
9158: if ($oldlonhost) {
9159: $currrules->{$oldlonhost} = $existing->{'rules'};
9160: }
9161: } elsif (ref($existing->{$key}) eq 'HASH') {
9162: $currbalancer->{$key} = 1;
9163: $currtargets->{$key} = $existing->{$key}{'targets'};
9164: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9165: if ($existing->{$key}{'cookie'}) {
9166: $currcookies->{$key} = 1;
9167: }
1.150 raeburn 9168: }
9169: }
1.171 raeburn 9170: } else {
9171: my ($balancerref,$targetsref) =
9172: &Apache::lonnet::get_lonbalancer_config($servers);
9173: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9174: foreach my $server (sort(keys(%{$balancerref}))) {
9175: $currbalancer->{$server} = 1;
9176: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9177: }
9178: }
9179: }
1.171 raeburn 9180: return;
1.150 raeburn 9181: }
9182:
9183: sub loadbalancing_rules {
9184: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9185: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9186: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9187: my $output;
1.171 raeburn 9188: my $num = 0;
1.210 raeburn 9189: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9190: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9191: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9192: foreach my $type (@{$alltypes}) {
1.171 raeburn 9193: $num ++;
1.150 raeburn 9194: my $current;
9195: if (ref($currrules) eq 'HASH') {
9196: $current = $currrules->{$type};
9197: }
1.253 raeburn 9198: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9199: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9200: $current = '';
9201: }
9202: }
9203: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9204: $servers,$currbalancer,$lonhost,$dom,
9205: $targets_div_style,$homedom_div_style,
9206: $css_class,$balnum,$num,$islast);
1.150 raeburn 9207: }
9208: }
9209: return $output;
9210: }
9211:
9212: sub loadbalancing_titles {
9213: my ($dom,$intdom,$usertypes,$types) = @_;
9214: my %othertypes = (
9215: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9216: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9217: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9218: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9219: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9220: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9221: );
1.209 raeburn 9222: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9223: my @available;
1.150 raeburn 9224: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9225: @available = @{$types};
1.150 raeburn 9226: }
1.302 raeburn 9227: unless (grep(/^default$/,@available)) {
9228: push(@available,'default');
9229: }
9230: unshift(@alltypes,@available);
1.150 raeburn 9231: my %titles;
9232: foreach my $type (@alltypes) {
9233: if ($type =~ /^_LC_/) {
9234: $titles{$type} = $othertypes{$type};
9235: } elsif ($type eq 'default') {
9236: $titles{$type} = &mt('All users from [_1]',$dom);
9237: if (ref($types) eq 'ARRAY') {
9238: if (@{$types} > 0) {
9239: $titles{$type} = &mt('Other users from [_1]',$dom);
9240: }
9241: }
9242: } elsif (ref($usertypes) eq 'HASH') {
9243: $titles{$type} = $usertypes->{$type};
9244: }
9245: }
9246: return (\@alltypes,\%othertypes,\%titles);
9247: }
9248:
9249: sub loadbalance_rule_row {
1.171 raeburn 9250: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9251: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9252: my @rulenames;
1.150 raeburn 9253: my %ruletitles = &offloadtype_text();
1.209 raeburn 9254: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9255: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9256: } else {
1.209 raeburn 9257: @rulenames = ('default','homeserver');
9258: if ($type eq '_LC_external') {
9259: push(@rulenames,'externalbalancer');
9260: } else {
9261: push(@rulenames,'specific');
9262: }
9263: push(@rulenames,'none');
1.150 raeburn 9264: }
9265: my $style = $targets_div_style;
1.253 raeburn 9266: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9267: $style = $homedom_div_style;
9268: }
1.171 raeburn 9269: my $space;
9270: if ($islast && $num == 1) {
1.317 raeburn 9271: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9272: }
1.210 raeburn 9273: my $output =
1.306 raeburn 9274: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9275: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9276: '<td valaign="top">'.$space.
9277: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9278: for (my $i=0; $i<@rulenames; $i++) {
9279: my $rule = $rulenames[$i];
9280: my ($checked,$extra);
9281: if ($rulenames[$i] eq 'default') {
9282: $rule = '';
9283: }
9284: if ($rulenames[$i] eq 'specific') {
9285: if (ref($servers) eq 'HASH') {
9286: my $default;
9287: if (($current ne '') && (exists($servers->{$current}))) {
9288: $checked = ' checked="checked"';
9289: }
9290: unless ($checked) {
9291: $default = ' selected="selected"';
9292: }
1.210 raeburn 9293: $extra =
1.171 raeburn 9294: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9295: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9296: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9297: '<option value=""'.$default.'></option>'."\n";
9298: foreach my $server (sort(keys(%{$servers}))) {
9299: if (ref($currbalancer) eq 'HASH') {
9300: next if (exists($currbalancer->{$server}));
9301: }
1.150 raeburn 9302: my $selected;
1.171 raeburn 9303: if ($server eq $current) {
1.150 raeburn 9304: $selected = ' selected="selected"';
9305: }
1.171 raeburn 9306: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9307: }
9308: $extra .= '</select>';
9309: }
9310: } elsif ($rule eq $current) {
9311: $checked = ' checked="checked"';
9312: }
9313: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9314: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9315: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9316: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9317: ')"'.$checked.' /> ';
9318: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9319: $output .= $ruletitles{'particular'};
9320: } else {
9321: $output .= $ruletitles{$rulenames[$i]};
9322: }
9323: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9324: }
9325: $output .= '</div></td></tr>'."\n";
9326: return $output;
9327: }
9328:
9329: sub offloadtype_text {
9330: my %ruletitles = &Apache::lonlocal::texthash (
9331: 'default' => 'Offloads to default destinations',
9332: 'homeserver' => "Offloads to user's home server",
9333: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9334: 'specific' => 'Offloads to specific server',
1.161 raeburn 9335: 'none' => 'No offload',
1.209 raeburn 9336: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9337: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9338: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9339: );
9340: return %ruletitles;
9341: }
9342:
9343: sub sparestype_titles {
9344: my %typestitles = &Apache::lonlocal::texthash (
9345: 'primary' => 'primary',
9346: 'default' => 'default',
9347: );
9348: return %typestitles;
9349: }
9350:
1.28 raeburn 9351: sub contact_titles {
9352: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9353: 'supportemail' => 'Support E-mail address',
9354: 'adminemail' => 'Default Server Admin E-mail address',
9355: 'errormail' => 'Error reports to be e-mailed to',
9356: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9357: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9358: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9359: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9360: 'requestsmail' => 'E-mail from course requests requiring approval',
9361: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9362: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9363: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9364: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9365: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9366: 'errorweights' => 'Weights used to compute error count',
9367: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9368: );
9369: my %short_titles = &Apache::lonlocal::texthash (
9370: adminemail => 'Admin E-mail address',
9371: supportemail => 'Support E-mail',
9372: );
9373: return (\%titles,\%short_titles);
9374: }
9375:
1.286 raeburn 9376: sub helpform_fields {
9377: my %titles = &Apache::lonlocal::texthash (
9378: 'username' => 'Name',
9379: 'user' => 'Username/domain',
9380: 'phone' => 'Phone',
9381: 'cc' => 'Cc e-mail',
9382: 'course' => 'Course Details',
9383: 'section' => 'Sections',
1.289 raeburn 9384: 'screenshot' => 'File upload',
1.286 raeburn 9385: );
9386: my @fields = ('username','phone','user','course','section','cc','screenshot');
9387: my %possoptions = (
9388: username => ['yes','no','req'],
1.289 raeburn 9389: phone => ['yes','no','req'],
1.286 raeburn 9390: user => ['yes','no'],
1.289 raeburn 9391: cc => ['yes','no'],
1.286 raeburn 9392: course => ['yes','no'],
9393: section => ['yes','no'],
9394: screenshot => ['yes','no'],
9395: );
9396: my %fieldoptions = &Apache::lonlocal::texthash (
9397: 'yes' => 'Optional',
9398: 'req' => 'Required',
9399: 'no' => "Not shown",
9400: );
9401: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9402: }
9403:
1.72 raeburn 9404: sub tool_titles {
9405: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9406: aboutme => 'Personal web page',
1.86 raeburn 9407: blog => 'Blog',
1.162 raeburn 9408: webdav => 'WebDAV',
1.86 raeburn 9409: portfolio => 'Portfolio',
1.413 raeburn 9410: timezone => 'Can set time zone',
1.88 bisitz 9411: official => 'Official courses (with institutional codes)',
9412: unofficial => 'Unofficial courses',
1.98 raeburn 9413: community => 'Communities',
1.216 raeburn 9414: textbook => 'Textbook courses',
1.271 raeburn 9415: placement => 'Placement tests',
1.86 raeburn 9416: );
1.72 raeburn 9417: return %titles;
9418: }
9419:
1.101 raeburn 9420: sub courserequest_titles {
9421: my %titles = &Apache::lonlocal::texthash (
9422: official => 'Official',
9423: unofficial => 'Unofficial',
9424: community => 'Communities',
1.216 raeburn 9425: textbook => 'Textbook',
1.271 raeburn 9426: placement => 'Placement tests',
1.325 raeburn 9427: lti => 'LTI Provider',
1.101 raeburn 9428: norequest => 'Not allowed',
1.325 raeburn 9429: approval => 'Approval by DC',
1.101 raeburn 9430: validate => 'With validation',
9431: autolimit => 'Numerical limit',
1.103 raeburn 9432: unlimited => '(blank for unlimited)',
1.101 raeburn 9433: );
9434: return %titles;
9435: }
9436:
1.163 raeburn 9437: sub authorrequest_titles {
9438: my %titles = &Apache::lonlocal::texthash (
9439: norequest => 'Not allowed',
9440: approval => 'Approval by Dom. Coord.',
9441: automatic => 'Automatic approval',
9442: );
9443: return %titles;
1.210 raeburn 9444: }
1.163 raeburn 9445:
1.101 raeburn 9446: sub courserequest_conditions {
9447: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9448: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9449: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9450: );
9451: return %conditions;
9452: }
9453:
9454:
1.27 raeburn 9455: sub print_usercreation {
1.30 raeburn 9456: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9457: my $numinrow = 4;
1.28 raeburn 9458: my $datatable;
9459: if ($position eq 'top') {
1.30 raeburn 9460: $$rowtotal ++;
1.34 raeburn 9461: my $rowcount = 0;
1.32 raeburn 9462: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9463: if (ref($rules) eq 'HASH') {
9464: if (keys(%{$rules}) > 0) {
1.32 raeburn 9465: $datatable .= &user_formats_row('username',$settings,$rules,
9466: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9467: $$rowtotal ++;
1.32 raeburn 9468: $rowcount ++;
9469: }
9470: }
9471: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9472: if (ref($idrules) eq 'HASH') {
9473: if (keys(%{$idrules}) > 0) {
9474: $datatable .= &user_formats_row('id',$settings,$idrules,
9475: $idruleorder,$numinrow,$rowcount);
9476: $$rowtotal ++;
9477: $rowcount ++;
1.28 raeburn 9478: }
9479: }
1.39 raeburn 9480: if ($rowcount == 0) {
9481: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9482: $$rowtotal ++;
9483: $rowcount ++;
9484: }
1.34 raeburn 9485: } elsif ($position eq 'middle') {
1.224 raeburn 9486: my @creators = ('author','course','requestcrs');
1.37 raeburn 9487: my ($rules,$ruleorder) =
9488: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9489: my %lt = &usercreation_types();
9490: my %checked;
9491: if (ref($settings) eq 'HASH') {
9492: if (ref($settings->{'cancreate'}) eq 'HASH') {
9493: foreach my $item (@creators) {
9494: $checked{$item} = $settings->{'cancreate'}{$item};
9495: }
9496: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9497: foreach my $item (@creators) {
9498: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9499: $checked{$item} = 'none';
9500: }
9501: }
9502: }
9503: }
9504: my $rownum = 0;
9505: foreach my $item (@creators) {
9506: $rownum ++;
1.224 raeburn 9507: if ($checked{$item} eq '') {
9508: $checked{$item} = 'any';
1.34 raeburn 9509: }
9510: my $css_class;
9511: if ($rownum%2) {
9512: $css_class = '';
9513: } else {
9514: $css_class = ' class="LC_odd_row" ';
9515: }
9516: $datatable .= '<tr'.$css_class.'>'.
9517: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9518: '</span></td><td style="text-align: right">';
1.224 raeburn 9519: my @options = ('any');
9520: if (ref($rules) eq 'HASH') {
9521: if (keys(%{$rules}) > 0) {
9522: push(@options,('official','unofficial'));
1.37 raeburn 9523: }
9524: }
1.224 raeburn 9525: push(@options,'none');
1.37 raeburn 9526: foreach my $option (@options) {
1.50 raeburn 9527: my $type = 'radio';
1.34 raeburn 9528: my $check = ' ';
1.224 raeburn 9529: if ($checked{$item} eq $option) {
9530: $check = ' checked="checked" ';
1.34 raeburn 9531: }
9532: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9533: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9534: $item.'" value="'.$option.'"'.$check.'/> '.
9535: $lt{$option}.'</label> </span>';
9536: }
9537: $datatable .= '</td></tr>';
9538: }
1.28 raeburn 9539: } else {
9540: my @contexts = ('author','course','domain');
1.325 raeburn 9541: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9542: my %checked;
9543: if (ref($settings) eq 'HASH') {
9544: if (ref($settings->{'authtypes'}) eq 'HASH') {
9545: foreach my $item (@contexts) {
9546: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9547: foreach my $auth (@authtypes) {
9548: if ($settings->{'authtypes'}{$item}{$auth}) {
9549: $checked{$item}{$auth} = ' checked="checked" ';
9550: }
9551: }
9552: }
9553: }
1.27 raeburn 9554: }
1.35 raeburn 9555: } else {
9556: foreach my $item (@contexts) {
1.36 raeburn 9557: foreach my $auth (@authtypes) {
1.35 raeburn 9558: $checked{$item}{$auth} = ' checked="checked" ';
9559: }
9560: }
1.27 raeburn 9561: }
1.28 raeburn 9562: my %title = &context_names();
9563: my %authname = &authtype_names();
9564: my $rownum = 0;
9565: my $css_class;
9566: foreach my $item (@contexts) {
9567: if ($rownum%2) {
9568: $css_class = '';
9569: } else {
9570: $css_class = ' class="LC_odd_row" ';
9571: }
1.30 raeburn 9572: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9573: '<td>'.$title{$item}.
9574: '</td><td class="LC_left_item">'.
9575: '<span class="LC_nobreak">';
9576: foreach my $auth (@authtypes) {
9577: $datatable .= '<label>'.
9578: '<input type="checkbox" name="'.$item.'_auth" '.
9579: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9580: $authname{$auth}.'</label> ';
9581: }
9582: $datatable .= '</span></td></tr>';
9583: $rownum ++;
1.27 raeburn 9584: }
1.30 raeburn 9585: $$rowtotal += $rownum;
1.27 raeburn 9586: }
9587: return $datatable;
9588: }
9589:
1.224 raeburn 9590: sub print_selfcreation {
9591: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9592: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9593: $emaildomain,$datatable);
1.224 raeburn 9594: if (ref($settings) eq 'HASH') {
9595: if (ref($settings->{'cancreate'}) eq 'HASH') {
9596: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9597: if (ref($createsettings) eq 'HASH') {
9598: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9599: @selfcreate = @{$createsettings->{'selfcreate'}};
9600: } elsif ($createsettings->{'selfcreate'} ne '') {
9601: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9602: @selfcreate = ('email','login','sso');
9603: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9604: @selfcreate = ($createsettings->{'selfcreate'});
9605: }
9606: }
9607: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9608: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9609: }
1.305 raeburn 9610: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9611: $emailoptions = $createsettings->{'emailoptions'};
9612: }
1.303 raeburn 9613: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9614: $emailverified = $createsettings->{'emailverified'};
9615: }
9616: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9617: $emaildomain = $createsettings->{'emaildomain'};
9618: }
1.224 raeburn 9619: }
9620: }
9621: }
9622: my %radiohash;
9623: my $numinrow = 4;
9624: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9625: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9626: if ($position eq 'top') {
9627: my %choices = &Apache::lonlocal::texthash (
9628: cancreate_login => 'Institutional Login',
9629: cancreate_sso => 'Institutional Single Sign On',
9630: );
9631: my @toggles = sort(keys(%choices));
9632: my %defaultchecked = (
9633: 'cancreate_login' => 'off',
9634: 'cancreate_sso' => 'off',
9635: );
1.228 raeburn 9636: my ($onclick,$itemcount);
1.224 raeburn 9637: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9638: \%choices,$itemcount,$onclick);
1.228 raeburn 9639: $$rowtotal += $itemcount;
9640:
1.224 raeburn 9641: if (ref($usertypes) eq 'HASH') {
9642: if (keys(%{$usertypes}) > 0) {
9643: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
9644: $dom,$numinrow,$othertitle,
1.305 raeburn 9645: 'statustocreate',$rowtotal);
1.224 raeburn 9646: $$rowtotal ++;
9647: }
9648: }
1.240 raeburn 9649: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
9650: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
9651: $fieldtitles{'inststatus'} = &mt('Institutional status');
9652: my $rem;
9653: my $numperrow = 2;
9654: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
9655: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 9656: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 9657: '<td class="LC_left_item">'."\n".
1.334 raeburn 9658: '<table>'."\n";
1.240 raeburn 9659: for (my $i=0; $i<@fields; $i++) {
9660: $rem = $i%($numperrow);
9661: if ($rem == 0) {
9662: if ($i > 0) {
9663: $datatable .= '</tr>';
9664: }
9665: $datatable .= '<tr>';
9666: }
9667: my $currval;
1.248 raeburn 9668: if (ref($createsettings) eq 'HASH') {
9669: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
9670: $currval = $createsettings->{'shibenv'}{$fields[$i]};
9671: }
1.240 raeburn 9672: }
9673: $datatable .= '<td class="LC_left_item">'.
9674: '<span class="LC_nobreak">'.
9675: '<input type="text" name="shibenv_'.$fields[$i].'" '.
9676: 'value="'.$currval.'" size="10" /> '.
9677: $fieldtitles{$fields[$i]}.'</span></td>';
9678: }
9679: my $colsleft = $numperrow - $rem;
9680: if ($colsleft > 1 ) {
9681: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9682: ' </td>';
9683: } elsif ($colsleft == 1) {
9684: $datatable .= '<td class="LC_left_item"> </td>';
9685: }
9686: $datatable .= '</tr></table></td></tr>';
9687: $$rowtotal ++;
1.224 raeburn 9688: } elsif ($position eq 'middle') {
9689: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 9690: my @posstypes;
1.224 raeburn 9691: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9692: @posstypes = @{$types};
9693: }
9694: unless (grep(/^default$/,@posstypes)) {
9695: push(@posstypes,'default');
9696: }
9697: my %usertypeshash;
9698: if (ref($usertypes) eq 'HASH') {
9699: %usertypeshash = %{$usertypes};
9700: }
9701: $usertypeshash{'default'} = $othertitle;
9702: foreach my $status (@posstypes) {
9703: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
9704: $numinrow,$$rowtotal,\%usertypeshash);
9705: $$rowtotal ++;
1.224 raeburn 9706: }
9707: } else {
1.236 raeburn 9708: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 9709: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 9710: );
9711: my @toggles = sort(keys(%choices));
9712: my %defaultchecked = (
9713: 'cancreate_email' => 'off',
9714: );
1.305 raeburn 9715: my $customclass = 'LC_selfcreate_email';
9716: my $classprefix = 'LC_canmodify_emailusername_';
9717: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 9718: my $display = 'none';
1.305 raeburn 9719: my $rowstyle = 'display:none';
1.236 raeburn 9720: if (grep(/^\Qemail\E$/,@selfcreate)) {
9721: $display = 'block';
1.305 raeburn 9722: $rowstyle = 'display:table-row';
1.236 raeburn 9723: }
1.305 raeburn 9724: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
9725: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
9726: \%choices,$$rowtotal,$onclick);
9727: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
9728: $rowstyle);
9729: $$rowtotal ++;
9730: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
9731: $rowstyle);
9732: $$rowtotal ++;
9733: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 9734: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 9735: my ($emailrules,$emailruleorder) =
9736: &Apache::lonnet::inst_userrules($dom,'email');
9737: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9738: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9739: if (ref($types) eq 'ARRAY') {
9740: @posstypes = @{$types};
9741: }
9742: if (@posstypes) {
9743: unless (grep(/^default$/,@posstypes)) {
9744: push(@posstypes,'default');
1.302 raeburn 9745: }
9746: if (ref($usertypes) eq 'HASH') {
9747: %usertypeshash = %{$usertypes};
9748: }
1.305 raeburn 9749: my $currassign;
9750: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
9751: $currassign = {
9752: selfassign => $domdefaults{'inststatusguest'},
9753: };
9754: @ordered = @{$domdefaults{'inststatusguest'}};
9755: } else {
9756: $currassign = { selfassign => [] };
9757: }
9758: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
9759: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
9760: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
9761: $numinrow,$othertitle,'selfassign',
9762: $rowtotal,$onclicktypes,$customclass,
9763: $rowstyle);
9764: $$rowtotal ++;
1.302 raeburn 9765: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9766: foreach my $status (@posstypes) {
9767: my $css_class;
9768: if ($$rowtotal%2) {
9769: $css_class = 'LC_odd_row ';
9770: }
9771: $css_class .= $customclass;
9772: my $rowid = $optionsprefix.$status;
9773: my $hidden = 1;
9774: my $currstyle = 'display:none';
9775: if (grep(/^\Q$status\E$/,@ordered)) {
9776: $currstyle = $rowstyle;
9777: $hidden = 0;
9778: }
9779: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9780: $emailrules,$emailruleorder,$settings,$status,$rowid,
9781: $usertypeshash{$status},$css_class,$currstyle,$intdom);
9782: unless ($hidden) {
9783: $$rowtotal ++;
9784: }
1.224 raeburn 9785: }
1.302 raeburn 9786: } else {
1.305 raeburn 9787: my $css_class;
9788: if ($$rowtotal%2) {
9789: $css_class = 'LC_odd_row ';
9790: }
9791: $css_class .= $customclass;
1.302 raeburn 9792: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 9793: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
9794: $emailrules,$emailruleorder,$settings,'default','',
9795: $othertitle,$css_class,$rowstyle,$intdom);
9796: $$rowtotal ++;
1.224 raeburn 9797: }
9798: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 9799: $numinrow = 1;
1.305 raeburn 9800: if (@posstypes) {
9801: foreach my $status (@posstypes) {
9802: my $rowid = $classprefix.$status;
9803: my $datarowstyle = 'display:none';
9804: if (grep(/^\Q$status\E$/,@ordered)) {
9805: $datarowstyle = $rowstyle;
9806: }
9807: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
9808: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9809: $infotitles,$rowid,$customclass,$datarowstyle);
9810: unless ($datarowstyle eq 'display:none') {
9811: $$rowtotal ++;
9812: }
1.224 raeburn 9813: }
1.305 raeburn 9814: } else {
9815: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
9816: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
9817: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 9818: }
9819: }
9820: return $datatable;
9821: }
9822:
1.305 raeburn 9823: sub selfcreate_javascript {
9824: return <<"ENDSCRIPT";
9825:
9826: <script type="text/javascript">
9827: // <![CDATA[
9828:
9829: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
9830: var x = document.getElementsByClassName(target);
9831: var insttypes = 0;
9832: var insttypeRegExp = new RegExp(prefix);
9833: if ((x.length != undefined) && (x.length > 0)) {
9834: if (form.elements[radio].length != undefined) {
9835: for (var i=0; i<form.elements[radio].length; i++) {
9836: if (form.elements[radio][i].checked) {
9837: if (form.elements[radio][i].value == 1) {
9838: for (var j=0; j<x.length; j++) {
9839: if (x[j].id == 'undefined') {
9840: x[j].style.display = 'table-row';
9841: } else if (insttypeRegExp.test(x[j].id)) {
9842: insttypes ++;
9843: } else {
9844: x[j].style.display = 'table-row';
9845: }
9846: }
9847: } else {
9848: for (var j=0; j<x.length; j++) {
9849: x[j].style.display = 'none';
9850: }
1.236 raeburn 9851: }
1.305 raeburn 9852: break;
9853: }
9854: }
9855: if (insttypes > 0) {
9856: toggleDataRow(form,checkbox,target,altprefix);
9857: toggleDataRow(form,checkbox,target,prefix,1);
9858: }
9859: }
9860: }
9861: return;
9862: }
9863:
9864: function toggleDataRow(form,checkbox,target,prefix,docount) {
9865: if (form.elements[checkbox].length != undefined) {
9866: var count = 0;
9867: if (docount) {
9868: for (var i=0; i<form.elements[checkbox].length; i++) {
9869: if (form.elements[checkbox][i].checked) {
9870: count ++;
1.236 raeburn 9871: }
1.305 raeburn 9872: }
9873: }
9874: for (var i=0; i<form.elements[checkbox].length; i++) {
9875: var type = form.elements[checkbox][i].value;
9876: if (document.getElementById(prefix+type)) {
9877: if (form.elements[checkbox][i].checked) {
9878: document.getElementById(prefix+type).style.display = 'table-row';
9879: if (count % 2 == 1) {
9880: document.getElementById(prefix+type).className = target+' LC_odd_row';
9881: } else {
9882: document.getElementById(prefix+type).className = target;
1.236 raeburn 9883: }
1.305 raeburn 9884: count ++;
1.236 raeburn 9885: } else {
1.305 raeburn 9886: document.getElementById(prefix+type).style.display = 'none';
9887: }
9888: }
9889: }
9890: }
9891: return;
9892: }
9893:
9894: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9895: var caller = radio+'_'+status;
9896: if (form.elements[caller].length != undefined) {
9897: for (var i=0; i<form.elements[caller].length; i++) {
9898: if (form.elements[caller][i].checked) {
9899: if (document.getElementById(altprefix+'_inst_'+status)) {
9900: var curr = form.elements[caller][i].value;
9901: if (prefix) {
9902: document.getElementById(prefix+'_'+status).style.display = 'none';
9903: }
9904: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9905: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9906: if (curr == 'custom') {
9907: if (prefix) {
9908: document.getElementById(prefix+'_'+status).style.display = 'inline';
9909: }
9910: } else if (curr == 'inst') {
9911: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9912: } else if (curr == 'noninst') {
9913: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 9914: }
1.305 raeburn 9915: break;
1.236 raeburn 9916: }
9917: }
9918: }
9919: }
9920: }
9921:
1.305 raeburn 9922: // ]]>
9923: </script>
9924:
9925: ENDSCRIPT
9926: }
9927:
9928: sub noninst_users {
9929: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9930: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9931: my $class = 'LC_left_item';
9932: if ($css_class) {
9933: $css_class = ' class="'.$css_class.'"';
9934: }
9935: if ($rowid) {
9936: $rowid = ' id="'.$rowid.'"';
9937: }
9938: if ($rowstyle) {
9939: $rowstyle = ' style="'.$rowstyle.'"';
9940: }
9941: my ($output,$description);
9942: if ($type eq 'default') {
9943: $description = &mt('Requests for: [_1]',$typetitle);
9944: } else {
9945: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9946: }
9947: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9948: "<td>$description</td>\n".
9949: '<td class="'.$class.'" colspan="2">'.
9950: '<table><tr>';
9951: my %headers = &Apache::lonlocal::texthash(
9952: approve => 'Processing',
9953: email => 'E-mail',
9954: username => 'Username',
9955: );
9956: foreach my $item ('approve','email','username') {
9957: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 9958: }
1.305 raeburn 9959: $output .= '</tr><tr>';
9960: foreach my $item ('approve','email','username') {
1.306 raeburn 9961: $output .= '<td style="vertical-align: top">';
1.305 raeburn 9962: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9963: if ($item eq 'approve') {
9964: %choices = &Apache::lonlocal::texthash (
9965: automatic => 'Automatically approved',
9966: approval => 'Queued for approval',
9967: );
9968: @options = ('automatic','approval');
9969: $hashref = $processing;
9970: $defoption = 'automatic';
9971: $name = 'cancreate_emailprocess_'.$type;
9972: } elsif ($item eq 'email') {
9973: %choices = &Apache::lonlocal::texthash (
9974: any => 'Any e-mail',
9975: inst => 'Institutional only',
9976: noninst => 'Non-institutional only',
9977: custom => 'Custom restrictions',
9978: );
9979: @options = ('any','inst','noninst');
9980: my $showcustom;
9981: if (ref($emailrules) eq 'HASH') {
9982: if (keys(%{$emailrules}) > 0) {
9983: push(@options,'custom');
9984: $showcustom = 'cancreate_emailrule';
9985: if (ref($settings) eq 'HASH') {
9986: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9987: foreach my $rule (@{$settings->{'email_rule'}}) {
9988: if (exists($emailrules->{$rule})) {
9989: $hascustom ++;
9990: }
9991: }
9992: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9993: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9994: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9995: if (exists($emailrules->{$rule})) {
9996: $hascustom ++;
9997: }
9998: }
9999: }
10000: }
10001: }
10002: }
10003: }
10004: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10005: "'cancreate_emaildomain','$type'".');"';
10006: $hashref = $emailoptions;
10007: $defoption = 'any';
10008: $name = 'cancreate_emailoptions_'.$type;
10009: } elsif ($item eq 'username') {
10010: %choices = &Apache::lonlocal::texthash (
10011: all => 'Same as e-mail',
10012: first => 'Omit @domain',
10013: free => 'Free to choose',
10014: );
10015: @options = ('all','first','free');
10016: $hashref = $emailverified;
10017: $defoption = 'all';
10018: $name = 'cancreate_usernameoptions_'.$type;
10019: }
10020: foreach my $option (@options) {
10021: my $checked;
10022: if (ref($hashref) eq 'HASH') {
10023: if ($type eq '') {
10024: if (!exists($hashref->{'default'})) {
10025: if ($option eq $defoption) {
10026: $checked = ' checked="checked"';
10027: }
10028: } else {
10029: if ($hashref->{'default'} eq $option) {
10030: $checked = ' checked="checked"';
10031: }
1.303 raeburn 10032: }
10033: } else {
1.305 raeburn 10034: if (!exists($hashref->{$type})) {
10035: if ($option eq $defoption) {
10036: $checked = ' checked="checked"';
10037: }
10038: } else {
10039: if ($hashref->{$type} eq $option) {
10040: $checked = ' checked="checked"';
10041: }
1.303 raeburn 10042: }
10043: }
1.305 raeburn 10044: } elsif (($item eq 'email') && ($hascustom)) {
10045: if ($option eq 'custom') {
10046: $checked = ' checked="checked"';
10047: }
10048: } elsif ($option eq $defoption) {
10049: $checked = ' checked="checked"';
10050: }
10051: $output .= '<span class="LC_nobreak"><label>'.
10052: '<input type="radio" name="'.$name.'"'.
10053: $checked.' value="'.$option.'"'.$onclick.' />'.
10054: $choices{$option}.'</label></span><br />';
10055: if ($item eq 'email') {
10056: if ($option eq 'custom') {
10057: my $id = 'cancreate_emailrule_'.$type;
10058: my $display = 'none';
10059: if ($checked) {
10060: $display = 'inline';
1.303 raeburn 10061: }
1.305 raeburn 10062: my $numinrow = 2;
10063: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10064: '<legend>'.&mt('Disallow').'</legend><table>'.
10065: &user_formats_row('email',$settings,$emailrules,
10066: $emailruleorder,$numinrow,'',$type);
10067: '</table></fieldset>';
10068: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10069: my %text = &Apache::lonlocal::texthash (
10070: inst => 'must end:',
10071: noninst => 'cannot end:',
10072: );
10073: my $value;
10074: if (ref($emaildomain) eq 'HASH') {
10075: if (ref($emaildomain->{$type}) eq 'HASH') {
10076: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10077: }
10078: }
1.305 raeburn 10079: if ($value eq '') {
10080: $value = '@'.$intdom;
10081: }
10082: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10083: my $display = 'none';
10084: if ($checked) {
10085: $display = 'inline';
10086: }
10087: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10088: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10089: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10090: '</div>';
1.303 raeburn 10091: }
10092: }
10093: }
1.305 raeburn 10094: $output .= '</td>'."\n";
1.303 raeburn 10095: }
1.305 raeburn 10096: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10097: return $output;
10098: }
10099:
1.165 raeburn 10100: sub captcha_choice {
1.305 raeburn 10101: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10102: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10103: $vertext,$currver);
1.165 raeburn 10104: my %lt = &captcha_phrases();
10105: $keyentry = 'hidden';
1.354 raeburn 10106: my $colspan=2;
1.165 raeburn 10107: if ($context eq 'cancreate') {
1.224 raeburn 10108: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10109: } elsif ($context eq 'login') {
10110: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10111: } elsif ($context eq 'passwords') {
10112: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10113: $colspan=1;
1.165 raeburn 10114: }
10115: if (ref($settings) eq 'HASH') {
10116: if ($settings->{'captcha'}) {
10117: $checked{$settings->{'captcha'}} = ' checked="checked"';
10118: } else {
10119: $checked{'original'} = ' checked="checked"';
10120: }
10121: if ($settings->{'captcha'} eq 'recaptcha') {
10122: $pubtext = $lt{'pub'};
10123: $privtext = $lt{'priv'};
10124: $keyentry = 'text';
1.269 raeburn 10125: $vertext = $lt{'ver'};
10126: $currver = $settings->{'recaptchaversion'};
10127: if ($currver ne '2') {
10128: $currver = 1;
10129: }
1.165 raeburn 10130: }
10131: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10132: $currpub = $settings->{'recaptchakeys'}{'public'};
10133: $currpriv = $settings->{'recaptchakeys'}{'private'};
10134: }
10135: } else {
10136: $checked{'original'} = ' checked="checked"';
10137: }
1.305 raeburn 10138: my $css_class;
10139: if ($itemcount%2) {
10140: $css_class = 'LC_odd_row';
10141: }
10142: if ($customcss) {
10143: $css_class .= " $customcss";
10144: }
10145: $css_class =~ s/^\s+//;
10146: if ($css_class) {
10147: $css_class = ' class="'.$css_class.'"';
10148: }
10149: if ($rowstyle) {
10150: $css_class .= ' style="'.$rowstyle.'"';
10151: }
1.169 raeburn 10152: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10153: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10154: '<table><tr><td>'."\n";
10155: foreach my $option ('original','recaptcha','notused') {
10156: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10157: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10158: $lt{$option}.'</label></span>';
10159: unless ($option eq 'notused') {
10160: $output .= (' 'x2)."\n";
10161: }
10162: }
10163: #
10164: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10165: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10166: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10167: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10168: #
1.165 raeburn 10169: $output .= '</td></tr>'."\n".
1.305 raeburn 10170: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10171: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10172: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10173: $currpub.'" size="40" /></span><br />'."\n".
10174: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10175: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10176: $currpriv.'" size="40" /></span><br />'.
10177: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10178: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10179: $currver.'" size="3" /></span><br />'.
10180: '</td></tr></table>'."\n".
1.165 raeburn 10181: '</td></tr>';
10182: return $output;
10183: }
10184:
1.32 raeburn 10185: sub user_formats_row {
1.305 raeburn 10186: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10187: my $output;
10188: my %text = (
10189: 'username' => 'new usernames',
10190: 'id' => 'IDs',
10191: );
1.409 raeburn 10192: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10193: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10194: $output = '<tr '.$css_class.'>'.
10195: '<td><span class="LC_nobreak">'.
10196: &mt("Format rules to check for $text{$type}: ").
10197: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10198: }
1.27 raeburn 10199: my $rem;
10200: if (ref($ruleorder) eq 'ARRAY') {
10201: for (my $i=0; $i<@{$ruleorder}; $i++) {
10202: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10203: my $rem = $i%($numinrow);
10204: if ($rem == 0) {
10205: if ($i > 0) {
10206: $output .= '</tr>';
10207: }
10208: $output .= '<tr>';
10209: }
10210: my $check = ' ';
1.39 raeburn 10211: if (ref($settings) eq 'HASH') {
10212: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10213: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10214: $check = ' checked="checked" ';
10215: }
1.305 raeburn 10216: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10217: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10218: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10219: $check = ' checked="checked" ';
10220: }
10221: }
1.27 raeburn 10222: }
10223: }
1.305 raeburn 10224: my $name = $type.'_rule';
10225: if ($type eq 'email') {
10226: $name .= '_'.$status;
10227: }
1.27 raeburn 10228: $output .= '<td class="LC_left_item">'.
10229: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10230: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10231: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10232: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10233: }
10234: }
10235: $rem = @{$ruleorder}%($numinrow);
10236: }
1.305 raeburn 10237: my $colsleft;
10238: if ($rem) {
10239: $colsleft = $numinrow - $rem;
10240: }
1.27 raeburn 10241: if ($colsleft > 1 ) {
10242: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10243: ' </td>';
10244: } elsif ($colsleft == 1) {
10245: $output .= '<td class="LC_left_item"> </td>';
10246: }
1.409 raeburn 10247: $output .= '</tr>';
10248: unless (($type eq 'email') || ($type eq 'unamemap')) {
10249: $output .= '</table></td></tr>';
1.305 raeburn 10250: }
1.27 raeburn 10251: return $output;
10252: }
10253:
1.34 raeburn 10254: sub usercreation_types {
10255: my %lt = &Apache::lonlocal::texthash (
10256: author => 'When adding a co-author',
10257: course => 'When adding a user to a course',
1.100 raeburn 10258: requestcrs => 'When requesting a course',
1.34 raeburn 10259: any => 'Any',
10260: official => 'Institutional only ',
10261: unofficial => 'Non-institutional only',
10262: none => 'None',
10263: );
10264: return %lt;
1.48 raeburn 10265: }
1.34 raeburn 10266:
1.224 raeburn 10267: sub selfcreation_types {
10268: my %lt = &Apache::lonlocal::texthash (
10269: selfcreate => 'User creates own account',
10270: any => 'Any',
10271: official => 'Institutional only ',
10272: unofficial => 'Non-institutional only',
10273: email => 'E-mail address',
10274: login => 'Institutional Login',
10275: sso => 'SSO',
10276: );
10277: }
10278:
1.28 raeburn 10279: sub authtype_names {
10280: my %lt = &Apache::lonlocal::texthash(
10281: int => 'Internal',
10282: krb4 => 'Kerberos 4',
10283: krb5 => 'Kerberos 5',
10284: loc => 'Local',
1.325 raeburn 10285: lti => 'LTI',
1.28 raeburn 10286: );
10287: return %lt;
10288: }
10289:
10290: sub context_names {
10291: my %context_title = &Apache::lonlocal::texthash(
10292: author => 'Creating users when an Author',
10293: course => 'Creating users when in a course',
10294: domain => 'Creating users when a Domain Coordinator',
10295: );
10296: return %context_title;
10297: }
10298:
1.33 raeburn 10299: sub print_usermodification {
10300: my ($position,$dom,$settings,$rowtotal) = @_;
10301: my $numinrow = 4;
10302: my ($context,$datatable,$rowcount);
10303: if ($position eq 'top') {
10304: $rowcount = 0;
10305: $context = 'author';
10306: foreach my $role ('ca','aa') {
10307: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10308: $numinrow,$rowcount);
10309: $$rowtotal ++;
10310: $rowcount ++;
10311: }
1.230 raeburn 10312: } elsif ($position eq 'bottom') {
1.33 raeburn 10313: $context = 'course';
10314: $rowcount = 0;
10315: foreach my $role ('st','ep','ta','in','cr') {
10316: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10317: $numinrow,$rowcount);
10318: $$rowtotal ++;
10319: $rowcount ++;
10320: }
10321: }
10322: return $datatable;
10323: }
10324:
1.43 raeburn 10325: sub print_defaults {
1.236 raeburn 10326: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10327: my $rownum = 0;
1.294 raeburn 10328: my ($datatable,$css_class,$titles);
10329: unless ($position eq 'bottom') {
10330: $titles = &defaults_titles($dom);
10331: }
1.236 raeburn 10332: if ($position eq 'top') {
10333: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10334: 'datelocale_def','portal_def');
10335: my %defaults;
10336: if (ref($settings) eq 'HASH') {
10337: %defaults = %{$settings};
1.43 raeburn 10338: } else {
1.236 raeburn 10339: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10340: foreach my $item (@items) {
10341: $defaults{$item} = $domdefaults{$item};
10342: }
1.43 raeburn 10343: }
1.236 raeburn 10344: foreach my $item (@items) {
10345: if ($rownum%2) {
10346: $css_class = '';
10347: } else {
10348: $css_class = ' class="LC_odd_row" ';
10349: }
10350: $datatable .= '<tr'.$css_class.'>'.
10351: '<td><span class="LC_nobreak">'.$titles->{$item}.
10352: '</span></td><td class="LC_right_item" colspan="3">';
10353: if ($item eq 'auth_def') {
1.325 raeburn 10354: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10355: my %shortauth = (
10356: internal => 'int',
10357: krb4 => 'krb4',
10358: krb5 => 'krb5',
1.325 raeburn 10359: localauth => 'loc',
10360: lti => 'lti',
1.236 raeburn 10361: );
10362: my %authnames = &authtype_names();
10363: foreach my $auth (@authtypes) {
10364: my $checked = ' ';
10365: if ($defaults{$item} eq $auth) {
10366: $checked = ' checked="checked" ';
10367: }
10368: $datatable .= '<label><input type="radio" name="'.$item.
10369: '" value="'.$auth.'"'.$checked.'/>'.
10370: $authnames{$shortauth{$auth}}.'</label> ';
10371: }
10372: } elsif ($item eq 'timezone_def') {
10373: my $includeempty = 1;
10374: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10375: } elsif ($item eq 'datelocale_def') {
10376: my $includeempty = 1;
10377: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10378: } elsif ($item eq 'lang_def') {
1.263 raeburn 10379: my $includeempty = 1;
10380: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10381: } elsif ($item eq 'portal_def') {
10382: $datatable .= '<input type="text" name="'.$item.'" value="'.
10383: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10384: my $portalsty = 'none';
10385: if ($defaults{$item}) {
10386: $portalsty = 'block';
10387: }
10388: foreach my $field ('email','web') {
10389: my $checkedoff = ' checked="checked"';
10390: my $checkedon;
10391: if ($defaults{$item.'_'.$field}) {
10392: $checkedon = $checkedoff;
10393: $checkedoff = '';
10394: }
10395: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10396: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10397: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10398: (' 'x2).
10399: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10400: '</div>';
10401: }
1.236 raeburn 10402: } else {
1.414 raeburn 10403: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10404: }
1.236 raeburn 10405: $datatable .= '</td></tr>';
10406: $rownum ++;
10407: }
1.409 raeburn 10408: } elsif ($position eq 'middle') {
1.294 raeburn 10409: my %defaults;
10410: if (ref($settings) eq 'HASH') {
1.354 raeburn 10411: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10412: my $maxnum = @{$settings->{'inststatusorder'}};
10413: for (my $i=0; $i<$maxnum; $i++) {
10414: $css_class = $rownum%2?' class="LC_odd_row"':'';
10415: my $item = $settings->{'inststatusorder'}->[$i];
10416: my $title = $settings->{'inststatustypes'}->{$item};
10417: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10418: $datatable .= '<tr'.$css_class.'>'.
10419: '<td><span class="LC_nobreak">'.
10420: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10421: for (my $k=0; $k<=$maxnum; $k++) {
10422: my $vpos = $k+1;
10423: my $selstr;
10424: if ($k == $i) {
10425: $selstr = ' selected="selected" ';
10426: }
10427: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10428: }
10429: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10430: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10431: &mt('delete').'</span></td>'.
1.380 raeburn 10432: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10433: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10434: '</span></td></tr>';
10435: }
10436: $css_class = $rownum%2?' class="LC_odd_row"':'';
10437: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10438: $datatable .= '<tr '.$css_class.'>'.
10439: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10440: for (my $k=0; $k<=$maxnum; $k++) {
10441: my $vpos = $k+1;
10442: my $selstr;
10443: if ($k == $maxnum) {
10444: $selstr = ' selected="selected" ';
10445: }
10446: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10447: }
10448: $datatable .= '</select> '.&mt('Internal ID:').
10449: '<input type="text" size="10" name="addinststatus" value="" />'.
10450: ' '.&mt('(new)').
10451: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10452: &mt('Name displayed').':'.
1.354 raeburn 10453: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10454: '</tr>'."\n";
10455: $rownum ++;
1.294 raeburn 10456: }
1.354 raeburn 10457: }
1.409 raeburn 10458: } else {
10459: my ($unamemaprules,$ruleorder) =
10460: &Apache::lonnet::inst_userrules($dom,'unamemap');
10461: $css_class = $rownum%2?' class="LC_odd_row"':'';
10462: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10463: my $numinrow = 2;
10464: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10465: &user_formats_row('unamemap',$settings,$unamemaprules,
10466: $ruleorder,$numinrow).
10467: '</table></td></tr>';
10468: }
10469: if ($datatable eq '') {
10470: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10471: &mt('No rules set for domain in customized localenroll.pm').
10472: '</td></tr>';
10473: }
1.354 raeburn 10474: }
10475: $$rowtotal += $rownum;
1.43 raeburn 10476: return $datatable;
10477: }
10478:
1.168 raeburn 10479: sub get_languages_hash {
10480: my %langchoices;
10481: foreach my $id (&Apache::loncommon::languageids()) {
10482: my $code = &Apache::loncommon::supportedlanguagecode($id);
10483: if ($code ne '') {
10484: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10485: }
10486: }
10487: return %langchoices;
10488: }
10489:
1.43 raeburn 10490: sub defaults_titles {
1.141 raeburn 10491: my ($dom) = @_;
1.43 raeburn 10492: my %titles = &Apache::lonlocal::texthash (
10493: 'auth_def' => 'Default authentication type',
10494: 'auth_arg_def' => 'Default authentication argument',
10495: 'lang_def' => 'Default language',
1.54 raeburn 10496: 'timezone_def' => 'Default timezone',
1.68 raeburn 10497: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10498: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10499: 'email' => 'Email links use portal URL',
10500: 'web' => 'Public web links use portal URL',
1.294 raeburn 10501: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10502: 'intauth_check' => 'Check bcrypt cost if authenticated',
10503: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10504: );
1.141 raeburn 10505: if ($dom) {
10506: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10507: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10508: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10509: $protocol = 'http' if ($protocol ne 'https');
10510: if ($uint_dom) {
10511: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10512: $uint_dom);
10513: }
10514: }
1.43 raeburn 10515: return (\%titles);
10516: }
10517:
1.346 raeburn 10518: sub print_scantron {
10519: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10520: if ($position eq 'top') {
10521: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10522: } else {
10523: return &print_scantronconfig($dom,$settings,\$rowtotal);
10524: }
10525: }
10526:
10527: sub scantron_javascript {
10528: return <<"ENDSCRIPT";
10529:
10530: <script type="text/javascript">
10531: // <![CDATA[
10532:
10533: function toggleScantron(form) {
1.347 raeburn 10534: var csvfieldset = new Array();
1.346 raeburn 10535: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10536: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10537: }
10538: if (document.getElementById('scantroncsv_options')) {
10539: csvfieldset.push(document.getElementById('scantroncsv_options'));
10540: }
10541: if (csvfieldset.length) {
1.346 raeburn 10542: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10543: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10544: if (scantroncsv.checked) {
1.347 raeburn 10545: for (var i=0; i<csvfieldset.length; i++) {
10546: csvfieldset[i].style.display = 'block';
10547: }
1.346 raeburn 10548: } else {
1.347 raeburn 10549: for (var i=0; i<csvfieldset.length; i++) {
10550: csvfieldset[i].style.display = 'none';
10551: }
1.346 raeburn 10552: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10553: if (csvselects.length) {
10554: for (var j=0; j<csvselects.length; j++) {
10555: csvselects[j].selectedIndex = 0;
10556: }
10557: }
10558: }
10559: }
10560: }
10561: return;
10562: }
10563: // ]]>
10564: </script>
10565:
10566: ENDSCRIPT
10567:
10568: }
10569:
1.46 raeburn 10570: sub print_scantronformat {
10571: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10572: my $itemcount = 1;
1.60 raeburn 10573: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10574: %confhash);
1.46 raeburn 10575: my $switchserver = &check_switchserver($dom,$confname);
10576: my %lt = &Apache::lonlocal::texthash (
1.95 www 10577: default => 'Default bubblesheet format file error',
10578: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10579: );
10580: my %scantronfiles = (
10581: default => 'default.tab',
10582: custom => 'custom.tab',
10583: );
10584: foreach my $key (keys(%scantronfiles)) {
10585: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10586: .$scantronfiles{$key};
10587: }
10588: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10589: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10590: if (!$switchserver) {
10591: my $servadm = $r->dir_config('lonAdmEMail');
10592: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10593: if ($configuserok eq 'ok') {
10594: if ($author_ok eq 'ok') {
10595: my %legacyfile = (
1.346 raeburn 10596: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10597: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10598: );
10599: my %md5chk;
10600: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10601: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10602: chomp($md5chk{$type});
1.46 raeburn 10603: }
10604: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10605: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10606: ($scantronurls{$type},my $error) =
1.46 raeburn 10607: &legacy_scantronformat($r,$dom,$confname,
10608: $type,$legacyfile{$type},
10609: $scantronurls{$type},
10610: $scantronfiles{$type});
1.60 raeburn 10611: if ($error ne '') {
10612: $error{$type} = $error;
10613: }
10614: }
10615: if (keys(%error) == 0) {
10616: $is_custom = 1;
1.346 raeburn 10617: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10618: $scantronurls{'custom'};
1.346 raeburn 10619: my $putresult =
1.60 raeburn 10620: &Apache::lonnet::put_dom('configuration',
10621: \%confhash,$dom);
10622: if ($putresult ne 'ok') {
1.346 raeburn 10623: $error{'custom'} =
1.60 raeburn 10624: '<span class="LC_error">'.
10625: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10626: }
1.46 raeburn 10627: }
10628: } else {
1.60 raeburn 10629: ($scantronurls{'default'},my $error) =
1.46 raeburn 10630: &legacy_scantronformat($r,$dom,$confname,
10631: 'default',$legacyfile{'default'},
10632: $scantronurls{'default'},
10633: $scantronfiles{'default'});
1.60 raeburn 10634: if ($error eq '') {
10635: $confhash{'scantron'}{'scantronformat'} = '';
10636: my $putresult =
10637: &Apache::lonnet::put_dom('configuration',
10638: \%confhash,$dom);
10639: if ($putresult ne 'ok') {
10640: $error{'default'} =
10641: '<span class="LC_error">'.
10642: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10643: }
10644: } else {
10645: $error{'default'} = $error;
10646: }
1.46 raeburn 10647: }
10648: }
10649: }
10650: } else {
1.95 www 10651: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 10652: }
10653: }
10654: if (ref($settings) eq 'HASH') {
10655: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
10656: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
10657: if ((!@info) || ($info[0] eq 'no_such_dir')) {
10658: $scantronurl = '';
10659: } else {
10660: $scantronurl = $settings->{'scantronformat'};
10661: }
10662: $is_custom = 1;
10663: } else {
10664: $scantronurl = $scantronurls{'default'};
10665: }
10666: } else {
1.60 raeburn 10667: if ($is_custom) {
10668: $scantronurl = $scantronurls{'custom'};
10669: } else {
10670: $scantronurl = $scantronurls{'default'};
10671: }
1.46 raeburn 10672: }
10673: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10674: $datatable .= '<tr'.$css_class.'>';
10675: if (!$is_custom) {
1.65 raeburn 10676: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
10677: '<span class="LC_nobreak">';
1.46 raeburn 10678: if ($scantronurl) {
1.199 raeburn 10679: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
10680: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 10681: } else {
10682: $datatable = &mt('File unavailable for display');
10683: }
1.65 raeburn 10684: $datatable .= '</span></td>';
1.60 raeburn 10685: if (keys(%error) == 0) {
1.306 raeburn 10686: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 10687: if (!$switchserver) {
10688: $datatable .= &mt('Upload:').'<br />';
10689: }
10690: } else {
10691: my $errorstr;
10692: foreach my $key (sort(keys(%error))) {
10693: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10694: }
10695: $datatable .= '<td>'.$errorstr;
10696: }
1.46 raeburn 10697: } else {
10698: if (keys(%error) > 0) {
10699: my $errorstr;
10700: foreach my $key (sort(keys(%error))) {
10701: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
10702: }
1.60 raeburn 10703: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 10704: } elsif ($scantronurl) {
1.199 raeburn 10705: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
10706: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 10707: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 10708: $link.
10709: '<label><input type="checkbox" name="scantronformat_del"'.
10710: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 10711: '<td><span class="LC_nobreak"> '.
10712: &mt('Replace:').'</span><br />';
1.46 raeburn 10713: }
10714: }
10715: if (keys(%error) == 0) {
10716: if ($switchserver) {
10717: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
10718: } else {
1.65 raeburn 10719: $datatable .='<span class="LC_nobreak"> '.
10720: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 10721: }
10722: }
10723: $datatable .= '</td></tr>';
10724: $$rowtotal ++;
10725: return $datatable;
10726: }
10727:
10728: sub legacy_scantronformat {
10729: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
10730: my ($url,$error);
10731: my @statinfo = &Apache::lonnet::stat_file($newurl);
10732: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 10733: my $modified = [];
1.46 raeburn 10734: (my $result,$url) =
1.421 raeburn 10735: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
10736: 'scantron','','',$newfile,$modified);
10737: if ($result eq 'ok') {
10738: &update_modify_urls($r,$modified);
10739: } else {
1.130 raeburn 10740: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 10741: }
10742: }
10743: return ($url,$error);
10744: }
1.43 raeburn 10745:
1.346 raeburn 10746: sub print_scantronconfig {
10747: my ($dom,$settings,$rowtotal) = @_;
10748: my $itemcount = 2;
10749: my $is_checked = ' checked="checked"';
1.347 raeburn 10750: my %optionson = (
10751: hdr => ' checked="checked"',
10752: pad => ' checked="checked"',
10753: rem => ' checked="checked"',
10754: );
10755: my %optionsoff = (
10756: hdr => '',
10757: pad => '',
10758: rem => '',
10759: );
1.346 raeburn 10760: my $currcsvsty = 'none';
1.347 raeburn 10761: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 10762: my @fields = &scantroncsv_fields();
10763: my %titles = &scantronconfig_titles();
10764: if (ref($settings) eq 'HASH') {
10765: if (ref($settings->{config}) eq 'HASH') {
10766: if ($settings->{config}->{dat}) {
10767: $checked{'dat'} = $is_checked;
10768: }
10769: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 10770: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
10771: %csvfields = %{$settings->{config}->{csv}->{fields}};
10772: if (keys(%csvfields) > 0) {
10773: $checked{'csv'} = $is_checked;
10774: $currcsvsty = 'block';
10775: }
10776: }
10777: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
10778: %csvoptions = %{$settings->{config}->{csv}->{options}};
10779: foreach my $option (keys(%optionson)) {
10780: unless ($csvoptions{$option}) {
10781: $optionsoff{$option} = $optionson{$option};
10782: $optionson{$option} = '';
10783: }
10784: }
1.346 raeburn 10785: }
10786: }
10787: } else {
10788: $checked{'dat'} = $is_checked;
10789: }
10790: } else {
10791: $checked{'dat'} = $is_checked;
10792: }
10793: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
10794: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10795: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
10796: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
10797: foreach my $item ('dat','csv') {
10798: my $id;
10799: if ($item eq 'csv') {
10800: $id = 'id="scantronconfcsv" ';
1.347 raeburn 10801: }
1.346 raeburn 10802: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
10803: $titles{$item}.'</label>'.(' 'x3);
10804: if ($item eq 'csv') {
10805: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
10806: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
10807: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
10808: foreach my $col (@fields) {
10809: my $selnone;
10810: if ($csvfields{$col} eq '') {
10811: $selnone = ' selected="selected"';
10812: }
10813: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
10814: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
10815: '<option value=""'.$selnone.'></option>';
10816: for (my $i=0; $i<20; $i++) {
10817: my $shown = $i+1;
10818: my $sel;
10819: unless ($selnone) {
10820: if (exists($csvfields{$col})) {
10821: if ($csvfields{$col} == $i) {
10822: $sel = ' selected="selected"';
10823: }
10824: }
10825: }
10826: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
10827: }
10828: $datatable .= '</select></td></tr>';
10829: }
1.347 raeburn 10830: $datatable .= '</table></fieldset>'.
10831: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
10832: '<legend>'.&mt('CSV Options').'</legend>';
10833: foreach my $option ('hdr','pad','rem') {
10834: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
10835: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
10836: &mt('Yes').'</label>'.(' 'x2)."\n".
10837: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
10838: }
10839: $datatable .= '</fieldset>';
1.346 raeburn 10840: $itemcount ++;
10841: }
10842: }
10843: $datatable .= '</td></tr>';
10844: $$rowtotal ++;
10845: return $datatable;
10846: }
10847:
10848: sub scantronconfig_titles {
10849: return &Apache::lonlocal::texthash(
10850: dat => 'Standard format (.dat)',
10851: csv => 'Comma separated values (.csv)',
1.347 raeburn 10852: hdr => 'Remove first line in file (contains column titles)',
10853: pad => 'Prepend 0s to PaperID',
1.348 raeburn 10854: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 10855: CODE => 'CODE',
10856: ID => 'Student ID',
10857: PaperID => 'Paper ID',
10858: FirstName => 'First Name',
10859: LastName => 'Last Name',
10860: FirstQuestion => 'First Question Response',
10861: Section => 'Section',
10862: );
10863: }
10864:
10865: sub scantroncsv_fields {
10866: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10867: }
10868:
1.49 raeburn 10869: sub print_coursecategories {
1.57 raeburn 10870: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10871: my $datatable;
10872: if ($position eq 'top') {
1.238 raeburn 10873: my (%checked);
10874: my @catitems = ('unauth','auth');
10875: my @cattypes = ('std','domonly','codesrch','none');
10876: $checked{'unauth'} = 'std';
10877: $checked{'auth'} = 'std';
10878: if (ref($settings) eq 'HASH') {
10879: foreach my $type (@cattypes) {
10880: if ($type eq $settings->{'unauth'}) {
10881: $checked{'unauth'} = $type;
10882: }
10883: if ($type eq $settings->{'auth'}) {
10884: $checked{'auth'} = $type;
10885: }
10886: }
10887: }
10888: my %lt = &Apache::lonlocal::texthash (
10889: unauth => 'Catalog type for unauthenticated users',
10890: auth => 'Catalog type for authenticated users',
10891: none => 'No catalog',
10892: std => 'Standard catalog',
10893: domonly => 'Domain-only catalog',
10894: codesrch => "Code search form",
10895: );
10896: my $itemcount = 0;
10897: foreach my $item (@catitems) {
10898: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10899: $datatable .= '<tr '.$css_class.'>'.
10900: '<td>'.$lt{$item}.'</td>'.
10901: '<td class="LC_right_item"><span class="LC_nobreak">';
10902: foreach my $type (@cattypes) {
10903: my $ischecked;
10904: if ($checked{$item} eq $type) {
10905: $ischecked=' checked="checked"';
10906: }
10907: $datatable .= '<label>'.
10908: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10909: ' />'.$lt{$type}.'</label> ';
10910: }
1.327 raeburn 10911: $datatable .= '</span></td></tr>';
1.238 raeburn 10912: $itemcount ++;
10913: }
10914: $$rowtotal += $itemcount;
10915: } elsif ($position eq 'middle') {
1.57 raeburn 10916: my $toggle_cats_crs = ' ';
10917: my $toggle_cats_dom = ' checked="checked" ';
10918: my $can_cat_crs = ' ';
10919: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10920: my $toggle_catscomm_comm = ' ';
10921: my $toggle_catscomm_dom = ' checked="checked" ';
10922: my $can_catcomm_comm = ' ';
10923: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 10924: my $toggle_catsplace_place = ' ';
10925: my $toggle_catsplace_dom = ' checked="checked" ';
10926: my $can_catplace_place = ' ';
10927: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 10928:
1.57 raeburn 10929: if (ref($settings) eq 'HASH') {
10930: if ($settings->{'togglecats'} eq 'crs') {
10931: $toggle_cats_crs = $toggle_cats_dom;
10932: $toggle_cats_dom = ' ';
10933: }
10934: if ($settings->{'categorize'} eq 'crs') {
10935: $can_cat_crs = $can_cat_dom;
10936: $can_cat_dom = ' ';
10937: }
1.120 raeburn 10938: if ($settings->{'togglecatscomm'} eq 'comm') {
10939: $toggle_catscomm_comm = $toggle_catscomm_dom;
10940: $toggle_catscomm_dom = ' ';
10941: }
10942: if ($settings->{'categorizecomm'} eq 'comm') {
10943: $can_catcomm_comm = $can_catcomm_dom;
10944: $can_catcomm_dom = ' ';
10945: }
1.272 raeburn 10946: if ($settings->{'togglecatsplace'} eq 'place') {
10947: $toggle_catsplace_place = $toggle_catsplace_dom;
10948: $toggle_catsplace_dom = ' ';
10949: }
10950: if ($settings->{'categorizeplace'} eq 'place') {
10951: $can_catplace_place = $can_catplace_dom;
10952: $can_catplace_dom = ' ';
10953: }
1.57 raeburn 10954: }
10955: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 10956: togglecats => 'Show/Hide a course in catalog',
10957: togglecatscomm => 'Show/Hide a community in catalog',
10958: togglecatsplace => 'Show/Hide a placement test in catalog',
10959: categorize => 'Assign a category to a course',
10960: categorizecomm => 'Assign a category to a community',
10961: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 10962: );
10963: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 10964: dom => 'Set in Domain',
10965: crs => 'Set in Course',
10966: comm => 'Set in Community',
10967: place => 'Set in Placement Test',
1.57 raeburn 10968: );
10969: $datatable = '<tr class="LC_odd_row">'.
10970: '<td>'.$title{'togglecats'}.'</td>'.
10971: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10972: '<input type="radio" name="togglecats"'.
10973: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10974: '<label><input type="radio" name="togglecats"'.
10975: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10976: '</tr><tr>'.
10977: '<td>'.$title{'categorize'}.'</td>'.
10978: '<td class="LC_right_item"><span class="LC_nobreak">'.
10979: '<label><input type="radio" name="categorize"'.
10980: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10981: '<label><input type="radio" name="categorize"'.
10982: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10983: '</tr><tr class="LC_odd_row">'.
10984: '<td>'.$title{'togglecatscomm'}.'</td>'.
10985: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10986: '<input type="radio" name="togglecatscomm"'.
10987: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10988: '<label><input type="radio" name="togglecatscomm"'.
10989: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10990: '</tr><tr>'.
10991: '<td>'.$title{'categorizecomm'}.'</td>'.
10992: '<td class="LC_right_item"><span class="LC_nobreak">'.
10993: '<label><input type="radio" name="categorizecomm"'.
10994: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10995: '<label><input type="radio" name="categorizecomm"'.
10996: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 10997: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 10998: '<td>'.$title{'togglecatsplace'}.'</td>'.
10999: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11000: '<input type="radio" name="togglecatsplace"'.
11001: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11002: '<label><input type="radio" name="togglecatscomm"'.
11003: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11004: '</tr><tr>'.
11005: '<td>'.$title{'categorizeplace'}.'</td>'.
11006: '<td class="LC_right_item"><span class="LC_nobreak">'.
11007: '<label><input type="radio" name="categorizeplace"'.
11008: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11009: '<label><input type="radio" name="categorizeplace"'.
11010: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11011: '</tr>';
1.272 raeburn 11012: $$rowtotal += 6;
1.57 raeburn 11013: } else {
11014: my $css_class;
11015: my $itemcount = 1;
11016: my $cathash;
11017: if (ref($settings) eq 'HASH') {
11018: $cathash = $settings->{'cats'};
11019: }
11020: if (ref($cathash) eq 'HASH') {
11021: my (@cats,@trails,%allitems,%idx,@jsarray);
11022: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11023: \%allitems,\%idx,\@jsarray);
11024: my $maxdepth = scalar(@cats);
11025: my $colattrib = '';
11026: if ($maxdepth > 2) {
11027: $colattrib = ' colspan="2" ';
11028: }
11029: my @path;
11030: if (@cats > 0) {
11031: if (ref($cats[0]) eq 'ARRAY') {
11032: my $numtop = @{$cats[0]};
11033: my $maxnum = $numtop;
1.120 raeburn 11034: my %default_names = (
11035: instcode => &mt('Official courses'),
11036: communities => &mt('Communities'),
1.272 raeburn 11037: placement => &mt('Placement Tests'),
1.120 raeburn 11038: );
11039:
11040: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11041: ($cathash->{'instcode::0'} eq '') ||
11042: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11043: ($cathash->{'communities::0'} eq '') ||
11044: (!grep(/^placement$/,@{$cats[0]})) ||
11045: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11046: $maxnum ++;
11047: }
11048: my $lastidx;
11049: for (my $i=0; $i<$numtop; $i++) {
11050: my $parent = $cats[0][$i];
11051: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11052: my $item = &escape($parent).'::0';
11053: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11054: $lastidx = $idx{$item};
11055: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11056: .'<select name="'.$item.'"'.$chgstr.'>';
11057: for (my $k=0; $k<=$maxnum; $k++) {
11058: my $vpos = $k+1;
11059: my $selstr;
11060: if ($k == $i) {
11061: $selstr = ' selected="selected" ';
11062: }
11063: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11064: }
1.214 raeburn 11065: $datatable .= '</select></span></td><td>';
1.272 raeburn 11066: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11067: $datatable .= '<span class="LC_nobreak">'
11068: .$default_names{$parent}.'</span>';
11069: if ($parent eq 'instcode') {
11070: $datatable .= '<br /><span class="LC_nobreak">('
11071: .&mt('with institutional codes')
11072: .')</span></td><td'.$colattrib.'>';
11073: } else {
11074: $datatable .= '<table><tr><td>';
11075: }
11076: $datatable .= '<span class="LC_nobreak">'
11077: .'<label><input type="radio" name="'
11078: .$parent.'" value="1" checked="checked" />'
11079: .&mt('Display').'</label>';
11080: if ($parent eq 'instcode') {
11081: $datatable .= ' ';
11082: } else {
11083: $datatable .= '</span></td></tr><tr><td>'
11084: .'<span class="LC_nobreak">';
11085: }
11086: $datatable .= '<label><input type="radio" name="'
11087: .$parent.'" value="0" />'
11088: .&mt('Do not display').'</label></span>';
1.272 raeburn 11089: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11090: $datatable .= '</td></tr></table>';
11091: }
11092: $datatable .= '</td>';
1.57 raeburn 11093: } else {
11094: $datatable .= $parent
1.214 raeburn 11095: .' <span class="LC_nobreak"><label>'
11096: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11097: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11098: }
11099: my $depth = 1;
11100: push(@path,$parent);
11101: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11102: pop(@path);
11103: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11104: $itemcount ++;
11105: }
1.48 raeburn 11106: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11107: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11108: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11109: for (my $k=0; $k<=$maxnum; $k++) {
11110: my $vpos = $k+1;
11111: my $selstr;
1.57 raeburn 11112: if ($k == $numtop) {
1.48 raeburn 11113: $selstr = ' selected="selected" ';
11114: }
11115: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11116: }
1.59 bisitz 11117: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11118: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11119: .'</tr>'."\n";
1.48 raeburn 11120: $itemcount ++;
1.272 raeburn 11121: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11122: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11123: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11124: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11125: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11126: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11127: for (my $k=0; $k<=$maxnum; $k++) {
11128: my $vpos = $k+1;
11129: my $selstr;
11130: if ($k == $maxnum) {
11131: $selstr = ' selected="selected" ';
11132: }
11133: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11134: }
1.120 raeburn 11135: $datatable .= '</select></span></td>'.
11136: '<td><span class="LC_nobreak">'.
11137: $default_names{$default}.'</span>';
11138: if ($default eq 'instcode') {
11139: $datatable .= '<br /><span class="LC_nobreak">('
11140: .&mt('with institutional codes').')</span>';
11141: }
11142: $datatable .= '</td>'
11143: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11144: .&mt('Display').'</label> '
11145: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11146: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11147: }
11148: }
11149: }
1.57 raeburn 11150: } else {
11151: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11152: }
11153: } else {
1.327 raeburn 11154: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11155: .&initialize_categories($itemcount);
1.48 raeburn 11156: }
1.57 raeburn 11157: $$rowtotal += $itemcount;
1.48 raeburn 11158: }
11159: return $datatable;
11160: }
11161:
1.69 raeburn 11162: sub print_serverstatuses {
11163: my ($dom,$settings,$rowtotal) = @_;
11164: my $datatable;
11165: my @pages = &serverstatus_pages();
11166: my (%namedaccess,%machineaccess);
11167: foreach my $type (@pages) {
11168: $namedaccess{$type} = '';
11169: $machineaccess{$type}= '';
11170: }
11171: if (ref($settings) eq 'HASH') {
11172: foreach my $type (@pages) {
11173: if (exists($settings->{$type})) {
11174: if (ref($settings->{$type}) eq 'HASH') {
11175: foreach my $key (keys(%{$settings->{$type}})) {
11176: if ($key eq 'namedusers') {
11177: $namedaccess{$type} = $settings->{$type}->{$key};
11178: } elsif ($key eq 'machines') {
11179: $machineaccess{$type} = $settings->{$type}->{$key};
11180: }
11181: }
11182: }
11183: }
11184: }
11185: }
1.81 raeburn 11186: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11187: my $rownum = 0;
11188: my $css_class;
11189: foreach my $type (@pages) {
11190: $rownum ++;
11191: $css_class = $rownum%2?' class="LC_odd_row"':'';
11192: $datatable .= '<tr'.$css_class.'>'.
11193: '<td><span class="LC_nobreak">'.
11194: $titles->{$type}.'</span></td>'.
11195: '<td class="LC_left_item">'.
11196: '<input type="text" name="'.$type.'_namedusers" '.
11197: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11198: '<td class="LC_right_item">'.
11199: '<span class="LC_nobreak">'.
11200: '<input type="text" name="'.$type.'_machines" '.
11201: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11202: '</span></td></tr>'."\n";
1.69 raeburn 11203: }
11204: $$rowtotal += $rownum;
11205: return $datatable;
11206: }
11207:
11208: sub serverstatus_pages {
11209: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11210: 'checksums','clusterstatus','certstatus','metadata_keywords',
11211: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11212: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11213: }
11214:
1.236 raeburn 11215: sub defaults_javascript {
11216: my ($settings) = @_;
1.354 raeburn 11217: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11218: my $portal_js = <<"ENDPORTAL";
11219:
11220: function portalExtras(caller) {
11221: var x = caller.value;
11222: var y = new Array('email','web');
11223: for (var i=0; i<y.length; i++) {
11224: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11225: var z = document.getElementById('portal_def_'+y[i]+'_div');
11226: if (x.length > 0) {
11227: z.style.display = 'block';
11228: } else {
11229: z.style.display = 'none';
11230: }
11231: }
11232: }
11233: }
11234: ENDPORTAL
1.236 raeburn 11235: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11236: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11237: if ($maxnum eq '') {
11238: $maxnum = 0;
11239: }
11240: $maxnum ++;
1.249 raeburn 11241: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11242: return <<"ENDSCRIPT";
11243: <script type="text/javascript">
11244: // <![CDATA[
11245: function reorderTypes(form,caller) {
11246: var changedVal;
11247: $jstext
11248: var newpos = 'addinststatus_pos';
11249: var current = new Array;
11250: var maxh = $maxnum;
11251: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11252: var oldVal;
11253: if (caller == newpos) {
11254: changedVal = newitemVal;
11255: } else {
11256: var curritem = 'inststatus_pos_'+caller;
11257: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11258: current[newitemVal] = newpos;
11259: }
11260: for (var i=0; i<inststatuses.length; i++) {
11261: if (inststatuses[i] != caller) {
11262: var elementName = 'inststatus_pos_'+inststatuses[i];
11263: if (form.elements[elementName]) {
11264: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11265: current[currVal] = elementName;
11266: }
11267: }
11268: }
11269: for (var j=0; j<maxh; j++) {
11270: if (current[j] == undefined) {
11271: oldVal = j;
11272: }
11273: }
11274: if (oldVal < changedVal) {
11275: for (var k=oldVal+1; k<=changedVal ; k++) {
11276: var elementName = current[k];
11277: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11278: }
11279: } else {
11280: for (var k=changedVal; k<oldVal; k++) {
11281: var elementName = current[k];
11282: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11283: }
11284: }
11285: return;
11286: }
11287:
1.414 raeburn 11288: $portal_js
11289:
11290: // ]]>
11291: </script>
11292:
11293: ENDSCRIPT
11294: } else {
11295: return <<"ENDSCRIPT";
11296: <script type="text/javascript">
11297: // <![CDATA[
11298: $portal_js
1.236 raeburn 11299: // ]]>
11300: </script>
11301:
11302: ENDSCRIPT
11303: }
1.354 raeburn 11304: return;
11305: }
11306:
11307: sub passwords_javascript {
1.405 raeburn 11308: my ($prefix) = @_;
11309: my %intalert;
11310: if ($prefix eq 'passwords') {
11311: %intalert = &Apache::lonlocal::texthash (
11312: 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.',
11313: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11314: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11315: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11316: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11317: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11318: );
1.421 raeburn 11319: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11320: %intalert = &Apache::lonlocal::texthash (
11321: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11322: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11323: );
11324: }
1.365 raeburn 11325: &js_escape(\%intalert);
11326: my $defmin = $Apache::lonnet::passwdmin;
1.405 raeburn 11327: my $intauthjs;
11328: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11329:
11330: function warnIntAuth(field) {
11331: if (field.name == 'intauth_check') {
11332: if (field.value == '2') {
1.365 raeburn 11333: alert('$intalert{authcheck}');
1.354 raeburn 11334: }
11335: }
11336: if (field.name == 'intauth_cost') {
11337: field.value.replace(/\s/g,'');
11338: if (field.value != '') {
11339: var regexdigit=/^\\d+\$/;
11340: if (!regexdigit.test(field.value)) {
1.365 raeburn 11341: alert('$intalert{authcost}');
11342: }
11343: }
11344: }
11345: return;
11346: }
11347:
1.405 raeburn 11348: ENDSCRIPT
11349:
11350: }
11351:
11352: $intauthjs .= <<"ENDSCRIPT";
11353:
11354: function warnInt$prefix(field) {
1.365 raeburn 11355: field.value.replace(/^\s+/,'');
11356: field.value.replace(/\s+\$/,'');
11357: var regexdigit=/^\\d+\$/;
1.408 raeburn 11358: if (field.name == '${prefix}_min') {
1.365 raeburn 11359: if (field.value == '') {
11360: alert('$intalert{passmin}');
11361: field.value = '$defmin';
11362: } else {
11363: if (!regexdigit.test(field.value)) {
11364: alert('$intalert{passmin}');
11365: field.value = '$defmin';
11366: }
1.366 raeburn 11367: var minval = parseInt(field.value,10);
1.365 raeburn 11368: if (minval < $defmin) {
11369: alert('$intalert{passmin}');
11370: field.value = '$defmin';
11371: }
11372: }
11373: } else {
11374: if (field.value == '0') {
11375: field.value = '';
11376: }
11377: if (field.value != '') {
1.408 raeburn 11378: if (field.name == '${prefix}_expire') {
1.365 raeburn 11379: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11380: if (!regexpposnum.test(field.value)) {
11381: alert('$intalert{passexp}');
11382: field.value = '';
11383: } else {
11384: var expval = parseFloat(field.value);
11385: if (expval == 0) {
11386: alert('$intalert{passexp}');
11387: field.value = '';
11388: }
11389: }
11390: } else {
11391: if (!regexdigit.test(field.value)) {
1.408 raeburn 11392: if (field.name == '${prefix}_max') {
1.365 raeburn 11393: alert('$intalert{passmax}');
11394: } else {
1.408 raeburn 11395: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11396: alert('$intalert{passnum}');
11397: }
11398: }
1.370 raeburn 11399: field.value = '';
1.365 raeburn 11400: }
1.354 raeburn 11401: }
11402: }
11403: }
11404: return;
11405: }
11406:
11407: ENDSCRIPT
11408: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11409: }
11410:
1.49 raeburn 11411: sub coursecategories_javascript {
11412: my ($settings) = @_;
1.57 raeburn 11413: my ($output,$jstext,$cathash);
1.49 raeburn 11414: if (ref($settings) eq 'HASH') {
1.57 raeburn 11415: $cathash = $settings->{'cats'};
11416: }
11417: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11418: my (@cats,@jsarray,%idx);
1.57 raeburn 11419: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11420: if (@jsarray > 0) {
11421: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11422: for (my $i=0; $i<@jsarray; $i++) {
11423: if (ref($jsarray[$i]) eq 'ARRAY') {
11424: my $catstr = join('","',@{$jsarray[$i]});
11425: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11426: }
11427: }
11428: }
11429: } else {
11430: $jstext = ' var categories = Array(1);'."\n".
11431: ' categories[0] = Array("instcode_pos");'."\n";
11432: }
1.237 bisitz 11433: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11434: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11435: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11436: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11437: &js_escape(\$instcode_reserved);
11438: &js_escape(\$communities_reserved);
1.272 raeburn 11439: &js_escape(\$placement_reserved);
1.265 damieng 11440: &js_escape(\$choose_again);
1.49 raeburn 11441: $output = <<"ENDSCRIPT";
11442: <script type="text/javascript">
1.109 raeburn 11443: // <![CDATA[
1.49 raeburn 11444: function reorderCats(form,parent,item,idx) {
11445: var changedVal;
11446: $jstext
11447: var newpos = 'addcategory_pos';
11448: if (parent == '') {
11449: var has_instcode = 0;
11450: var maxtop = categories[idx].length;
11451: for (var j=0; j<maxtop; j++) {
11452: if (categories[idx][j] == 'instcode::0') {
11453: has_instcode == 1;
11454: }
11455: }
11456: if (has_instcode == 0) {
11457: categories[idx][maxtop] = 'instcode_pos';
11458: }
11459: } else {
11460: newpos += '_'+parent;
11461: }
11462: var maxh = 1 + categories[idx].length;
11463: var current = new Array;
11464: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11465: if (item == newpos) {
11466: changedVal = newitemVal;
11467: } else {
11468: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11469: current[newitemVal] = newpos;
11470: }
11471: for (var i=0; i<categories[idx].length; i++) {
11472: var elementName = categories[idx][i];
11473: if (elementName != item) {
11474: if (form.elements[elementName]) {
11475: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11476: current[currVal] = elementName;
11477: }
11478: }
11479: }
11480: var oldVal;
11481: for (var j=0; j<maxh; j++) {
11482: if (current[j] == undefined) {
11483: oldVal = j;
11484: }
11485: }
11486: if (oldVal < changedVal) {
11487: for (var k=oldVal+1; k<=changedVal ; k++) {
11488: var elementName = current[k];
11489: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11490: }
11491: } else {
11492: for (var k=changedVal; k<oldVal; k++) {
11493: var elementName = current[k];
11494: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11495: }
11496: }
11497: return;
11498: }
1.120 raeburn 11499:
11500: function categoryCheck(form) {
11501: if (form.elements['addcategory_name'].value == 'instcode') {
11502: alert('$instcode_reserved\\n$choose_again');
11503: return false;
11504: }
11505: if (form.elements['addcategory_name'].value == 'communities') {
11506: alert('$communities_reserved\\n$choose_again');
11507: return false;
11508: }
1.272 raeburn 11509: if (form.elements['addcategory_name'].value == 'placement') {
11510: alert('$placement_reserved\\n$choose_again');
11511: return false;
11512: }
1.120 raeburn 11513: return true;
11514: }
11515:
1.109 raeburn 11516: // ]]>
1.49 raeburn 11517: </script>
11518:
11519: ENDSCRIPT
11520: return $output;
11521: }
11522:
1.48 raeburn 11523: sub initialize_categories {
11524: my ($itemcount) = @_;
1.120 raeburn 11525: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11526: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11527: instcode => 'Official courses (with institutional codes)',
11528: communities => 'Communities',
1.272 raeburn 11529: placement => 'Placement Tests',
1.120 raeburn 11530: );
1.328 raeburn 11531: my %selnum = (
11532: instcode => '0',
11533: communities => '1',
11534: placement => '2',
11535: );
11536: my %selected;
1.272 raeburn 11537: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11538: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11539: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11540: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11541: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11542: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11543: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11544: .'<option value="0"'.$selected{'0'}.'>1</option>'
11545: .'<option value="1"'.$selected{'1'}.'>2</option>'
11546: .'<option value="2"'.$selected{'2'}.'>3</option>'
11547: .'<option value="3">4</option></select> '
1.120 raeburn 11548: .$default_names{$default}
11549: .'</span></td><td><span class="LC_nobreak">'
11550: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11551: .&mt('Display').'</label> <label>'
11552: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11553: .'</label></span></td></tr>';
1.120 raeburn 11554: $itemcount ++;
11555: }
1.48 raeburn 11556: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11557: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11558: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11559: .'<select name="addcategory_pos"'.$chgstr.'>'
11560: .'<option value="0">1</option>'
11561: .'<option value="1">2</option>'
1.328 raeburn 11562: .'<option value="2">3</option>'
11563: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11564: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11565: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11566: .'</td></tr>';
1.48 raeburn 11567: return $datatable;
11568: }
11569:
11570: sub build_category_rows {
1.49 raeburn 11571: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11572: my ($text,$name,$item,$chgstr);
1.48 raeburn 11573: if (ref($cats) eq 'ARRAY') {
11574: my $maxdepth = scalar(@{$cats});
11575: if (ref($cats->[$depth]) eq 'HASH') {
11576: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11577: my $numchildren = @{$cats->[$depth]{$parent}};
11578: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11579: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11580: my ($idxnum,$parent_name,$parent_item);
11581: my $higher = $depth - 1;
11582: if ($higher == 0) {
11583: $parent_name = &escape($parent).'::'.$higher;
11584: } else {
11585: if (ref($path) eq 'ARRAY') {
11586: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11587: }
11588: }
11589: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11590: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11591: if ($j < $numchildren) {
1.48 raeburn 11592: $name = $cats->[$depth]{$parent}[$j];
11593: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11594: $idxnum = $idx->{$item};
11595: } else {
11596: $name = $parent_name;
11597: $item = $parent_item;
1.48 raeburn 11598: }
1.49 raeburn 11599: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11600: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11601: for (my $i=0; $i<=$numchildren; $i++) {
11602: my $vpos = $i+1;
11603: my $selstr;
11604: if ($j == $i) {
11605: $selstr = ' selected="selected" ';
11606: }
11607: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11608: }
11609: $text .= '</select> ';
11610: if ($j < $numchildren) {
11611: my $deeper = $depth+1;
11612: $text .= $name.' '
11613: .'<label><input type="checkbox" name="deletecategory" value="'
11614: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11615: if(ref($path) eq 'ARRAY') {
11616: push(@{$path},$name);
1.49 raeburn 11617: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11618: pop(@{$path});
11619: }
11620: } else {
1.330 raeburn 11621: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11622: if ($j == $numchildren) {
11623: $text .= $name;
11624: } else {
11625: $text .= $item;
11626: }
11627: $text .= '" value="" />';
11628: }
11629: $text .= '</td></tr>';
11630: }
11631: $text .= '</table></td>';
11632: } else {
11633: my $higher = $depth-1;
11634: if ($higher == 0) {
11635: $name = &escape($parent).'::'.$higher;
11636: } else {
11637: if (ref($path) eq 'ARRAY') {
11638: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11639: }
11640: }
11641: my $colspan;
11642: if ($parent ne 'instcode') {
11643: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 11644: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 11645: }
11646: }
11647: }
11648: }
11649: return $text;
11650: }
11651:
1.33 raeburn 11652: sub modifiable_userdata_row {
1.305 raeburn 11653: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 11654: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 11655: my ($role,$rolename,$statustype);
11656: $role = $item;
1.224 raeburn 11657: if ($context eq 'cancreate') {
1.305 raeburn 11658: if ($item =~ /^(emailusername)_(.+)$/) {
11659: $role = $1;
11660: $statustype = $2;
1.228 raeburn 11661: if (ref($usertypes) eq 'HASH') {
11662: if ($usertypes->{$statustype}) {
11663: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
11664: } else {
11665: $rolename = &mt('Data provided by user');
11666: }
11667: }
1.224 raeburn 11668: }
11669: } elsif ($context eq 'selfcreate') {
1.63 raeburn 11670: if (ref($usertypes) eq 'HASH') {
11671: $rolename = $usertypes->{$role};
11672: } else {
11673: $rolename = $role;
11674: }
1.325 raeburn 11675: } elsif ($context eq 'lti') {
11676: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 11677: } elsif ($context eq 'privacy') {
11678: $rolename = $itemdesc;
1.33 raeburn 11679: } else {
1.63 raeburn 11680: if ($role eq 'cr') {
11681: $rolename = &mt('Custom role');
11682: } else {
11683: $rolename = &Apache::lonnet::plaintext($role);
11684: }
1.33 raeburn 11685: }
1.224 raeburn 11686: my (@fields,%fieldtitles);
11687: if (ref($fieldsref) eq 'ARRAY') {
11688: @fields = @{$fieldsref};
11689: } else {
11690: @fields = ('lastname','firstname','middlename','generation',
11691: 'permanentemail','id');
11692: }
11693: if ((ref($titlesref) eq 'HASH')) {
11694: %fieldtitles = %{$titlesref};
11695: } else {
11696: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
11697: }
1.33 raeburn 11698: my $output;
1.305 raeburn 11699: my $css_class;
11700: if ($rowcount%2) {
11701: $css_class = 'LC_odd_row';
11702: }
11703: if ($customcss) {
11704: $css_class .= " $customcss";
11705: }
11706: $css_class =~ s/^\s+//;
11707: if ($css_class) {
11708: $css_class = ' class="'.$css_class.'"';
11709: }
11710: if ($rowstyle) {
11711: $css_class .= ' style="'.$rowstyle.'"';
11712: }
11713: if ($rowid) {
11714: $rowid = ' id="'.$rowid.'"';
11715: }
11716: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 11717: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
11718: '<td class="LC_left_item" colspan="2"><table>';
11719: my $rem;
11720: my %checks;
1.325 raeburn 11721: my %current;
1.33 raeburn 11722: if (ref($settings) eq 'HASH') {
1.325 raeburn 11723: my $hashref;
11724: if ($context eq 'lti') {
11725: if (ref($settings) eq 'HASH') {
11726: $hashref = $settings->{'instdata'};
11727: }
1.357 raeburn 11728: } elsif ($context eq 'privacy') {
11729: my ($key,$inner) = split(/_/,$role);
11730: if (ref($settings) eq 'HASH') {
11731: if (ref($settings->{$key}) eq 'HASH') {
11732: $hashref = $settings->{$key}->{$inner};
11733: }
11734: }
1.325 raeburn 11735: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 11736: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 11737: $hashref = $settings->{'lti_instdata'};
11738: }
11739: if ($role eq 'emailusername') {
11740: if ($statustype) {
11741: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
11742: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 11743: }
1.325 raeburn 11744: }
11745: }
11746: }
11747: if (ref($hashref) eq 'HASH') {
11748: foreach my $field (@fields) {
11749: if ($hashref->{$field}) {
11750: if ($role eq 'emailusername') {
11751: $checks{$field} = $hashref->{$field};
11752: } else {
11753: $checks{$field} = ' checked="checked" ';
1.33 raeburn 11754: }
11755: }
11756: }
11757: }
11758: }
1.305 raeburn 11759:
11760: my $total = scalar(@fields);
11761: for (my $i=0; $i<$total; $i++) {
11762: $rem = $i%($numinrow);
1.33 raeburn 11763: if ($rem == 0) {
11764: if ($i > 0) {
11765: $output .= '</tr>';
11766: }
11767: $output .= '<tr>';
11768: }
11769: my $check = ' ';
1.228 raeburn 11770: unless ($role eq 'emailusername') {
11771: if (exists($checks{$fields[$i]})) {
1.354 raeburn 11772: $check = $checks{$fields[$i]};
1.357 raeburn 11773: } elsif ($context eq 'privacy') {
11774: if ($role =~ /^priv_(domain|course)$/) {
11775: if (ref($settings) ne 'HASH') {
11776: $check = ' checked="checked" ';
11777: }
11778: } elsif ($role =~ /^priv_(author|community)$/) {
11779: if (ref($settings) ne 'HASH') {
11780: unless ($fields[$i] eq 'id') {
11781: $check = ' checked="checked" ';
11782: }
11783: }
11784: } elsif ($role =~ /^(unpriv|othdom)_/) {
11785: if (ref($settings) ne 'HASH') {
11786: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
11787: $check = ' checked="checked" ';
11788: }
11789: }
11790: }
1.325 raeburn 11791: } elsif ($context ne 'lti') {
1.228 raeburn 11792: if ($role eq 'st') {
11793: if (ref($settings) ne 'HASH') {
11794: $check = ' checked="checked" ';
11795: }
1.33 raeburn 11796: }
11797: }
11798: }
11799: $output .= '<td class="LC_left_item">'.
1.228 raeburn 11800: '<span class="LC_nobreak">';
1.325 raeburn 11801: my $prefix = 'canmodify';
1.228 raeburn 11802: if ($role eq 'emailusername') {
11803: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
11804: $checks{$fields[$i]} = 'omit';
11805: }
11806: foreach my $option ('required','optional','omit') {
11807: my $checked='';
11808: if ($checks{$fields[$i]} eq $option) {
11809: $checked='checked="checked" ';
11810: }
11811: $output .= '<label>'.
1.325 raeburn 11812: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 11813: &mt($option).'</label>'.(' ' x2);
11814: }
11815: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
11816: } else {
1.325 raeburn 11817: if ($context eq 'lti') {
11818: $prefix = 'lti';
1.357 raeburn 11819: } elsif ($context eq 'privacy') {
11820: $prefix = 'privacy';
1.325 raeburn 11821: }
1.228 raeburn 11822: $output .= '<label>'.
1.325 raeburn 11823: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 11824: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
11825: '</label>';
11826: }
11827: $output .= '</span></td>';
1.33 raeburn 11828: }
1.305 raeburn 11829: $rem = $total%$numinrow;
11830: my $colsleft;
11831: if ($rem) {
11832: $colsleft = $numinrow - $rem;
11833: }
11834: if ($colsleft > 1) {
1.33 raeburn 11835: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
11836: ' </td>';
11837: } elsif ($colsleft == 1) {
11838: $output .= '<td class="LC_left_item"> </td>';
11839: }
11840: $output .= '</tr></table></td></tr>';
11841: return $output;
11842: }
1.28 raeburn 11843:
1.93 raeburn 11844: sub insttypes_row {
1.305 raeburn 11845: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
11846: $customcss,$rowstyle) = @_;
1.93 raeburn 11847: my %lt = &Apache::lonlocal::texthash (
11848: cansearch => 'Users allowed to search',
11849: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 11850: lockablenames => 'User preference to lock name',
1.305 raeburn 11851: selfassign => 'Self-reportable affiliations',
1.315 raeburn 11852: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 11853: );
11854: my $showdom;
11855: if ($context eq 'cansearch') {
11856: $showdom = ' ('.$dom.')';
11857: }
1.165 raeburn 11858: my $class = 'LC_left_item';
11859: if ($context eq 'statustocreate') {
11860: $class = 'LC_right_item';
11861: }
1.305 raeburn 11862: my $css_class;
11863: if ($$rowtotal%2) {
11864: $css_class = 'LC_odd_row';
11865: }
11866: if ($customcss) {
11867: $css_class .= ' '.$customcss;
11868: }
11869: $css_class =~ s/^\s+//;
11870: if ($css_class) {
11871: $css_class = ' class="'.$css_class.'"';
11872: }
11873: if ($rowstyle) {
11874: $css_class .= ' style="'.$rowstyle.'"';
11875: }
11876: if ($onclick) {
11877: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 11878: }
11879: my $output = '<tr'.$css_class.'>'.
11880: '<td>'.$lt{$context}.$showdom.
11881: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 11882: my $rem;
11883: if (ref($types) eq 'ARRAY') {
11884: for (my $i=0; $i<@{$types}; $i++) {
11885: if (defined($usertypes->{$types->[$i]})) {
11886: my $rem = $i%($numinrow);
11887: if ($rem == 0) {
11888: if ($i > 0) {
11889: $output .= '</tr>';
11890: }
11891: $output .= '<tr>';
1.23 raeburn 11892: }
1.26 raeburn 11893: my $check = ' ';
1.99 raeburn 11894: if (ref($settings) eq 'HASH') {
11895: if (ref($settings->{$context}) eq 'ARRAY') {
11896: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
11897: $check = ' checked="checked" ';
11898: }
1.315 raeburn 11899: } elsif (ref($settings->{$context}) eq 'HASH') {
11900: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
11901: $check = ' checked="checked" ';
11902: }
1.99 raeburn 11903: } elsif ($context eq 'statustocreate') {
1.26 raeburn 11904: $check = ' checked="checked" ';
11905: }
1.23 raeburn 11906: }
1.26 raeburn 11907: $output .= '<td class="LC_left_item">'.
11908: '<span class="LC_nobreak"><label>'.
1.93 raeburn 11909: '<input type="checkbox" name="'.$context.'" '.
1.305 raeburn 11910: 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 11911: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 11912: }
11913: }
1.26 raeburn 11914: $rem = @{$types}%($numinrow);
1.23 raeburn 11915: }
11916: my $colsleft = $numinrow - $rem;
1.315 raeburn 11917: if ($context eq 'overrides') {
11918: if ($colsleft > 1) {
11919: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11920: } else {
11921: $output .= '<td class="LC_left_item">';
11922: }
11923: $output .= ' ';
1.23 raeburn 11924: } else {
1.334 raeburn 11925: if ($rem == 0) {
1.315 raeburn 11926: $output .= '<tr>';
11927: }
11928: if ($colsleft > 1) {
11929: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11930: } else {
11931: $output .= '<td class="LC_left_item">';
11932: }
11933: my $defcheck = ' ';
11934: if (ref($settings) eq 'HASH') {
11935: if (ref($settings->{$context}) eq 'ARRAY') {
11936: if (grep(/^default$/,@{$settings->{$context}})) {
11937: $defcheck = ' checked="checked" ';
11938: }
11939: } elsif ($context eq 'statustocreate') {
1.99 raeburn 11940: $defcheck = ' checked="checked" ';
11941: }
1.26 raeburn 11942: }
1.315 raeburn 11943: $output .= '<span class="LC_nobreak"><label>'.
11944: '<input type="checkbox" name="'.$context.'" '.
11945: 'value="default"'.$defcheck.$onclick.' />'.
11946: $othertitle.'</label></span>';
1.23 raeburn 11947: }
1.315 raeburn 11948: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11949: return $output;
1.23 raeburn 11950: }
11951:
11952: sub sorted_searchtitles {
11953: my %searchtitles = &Apache::lonlocal::texthash(
11954: 'uname' => 'username',
11955: 'lastname' => 'last name',
11956: 'lastfirst' => 'last name, first name',
11957: );
11958: my @titleorder = ('uname','lastname','lastfirst');
11959: return (\%searchtitles,\@titleorder);
11960: }
11961:
1.25 raeburn 11962: sub sorted_searchtypes {
11963: my %srchtypes_desc = (
11964: exact => 'is exact match',
11965: contains => 'contains ..',
11966: begins => 'begins with ..',
11967: );
11968: my @srchtypeorder = ('exact','begins','contains');
11969: return (\%srchtypes_desc,\@srchtypeorder);
11970: }
11971:
1.3 raeburn 11972: sub usertype_update_row {
11973: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11974: my $datatable;
11975: my $numinrow = 4;
11976: foreach my $type (@{$types}) {
11977: if (defined($usertypes->{$type})) {
11978: $$rownums ++;
11979: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11980: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11981: '</td><td class="LC_left_item"><table>';
11982: for (my $i=0; $i<@{$fields}; $i++) {
11983: my $rem = $i%($numinrow);
11984: if ($rem == 0) {
11985: if ($i > 0) {
11986: $datatable .= '</tr>';
11987: }
11988: $datatable .= '<tr>';
11989: }
11990: my $check = ' ';
1.39 raeburn 11991: if (ref($settings) eq 'HASH') {
11992: if (ref($settings->{'fields'}) eq 'HASH') {
11993: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11994: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11995: $check = ' checked="checked" ';
11996: }
1.3 raeburn 11997: }
11998: }
11999: }
12000:
12001: if ($i == @{$fields}-1) {
12002: my $colsleft = $numinrow - $rem;
12003: if ($colsleft > 1) {
12004: $datatable .= '<td colspan="'.$colsleft.'">';
12005: } else {
12006: $datatable .= '<td>';
12007: }
12008: } else {
12009: $datatable .= '<td>';
12010: }
1.8 raeburn 12011: $datatable .= '<span class="LC_nobreak"><label>'.
12012: '<input type="checkbox" name="updateable_'.$type.
12013: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12014: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12015: }
12016: $datatable .= '</tr></table></td></tr>';
12017: }
12018: }
12019: return $datatable;
1.1 raeburn 12020: }
12021:
12022: sub modify_login {
1.205 raeburn 12023: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12024: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12025: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12026: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12027: %title = ( coursecatalog => 'Display course catalog',
12028: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12029: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12030: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12031: loginheader => 'Log-in box header',
12032: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12033: @offon = ('off','on');
1.112 raeburn 12034: if (ref($domconfig{login}) eq 'HASH') {
12035: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12036: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12037: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12038: }
12039: }
1.386 raeburn 12040: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12041: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12042: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12043: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12044: $saml{$lonhost} = 1;
12045: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12046: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12047: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12048: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12049: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12050: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12051: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12052: }
12053: }
12054: }
1.112 raeburn 12055: }
1.9 raeburn 12056: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12057: \%domconfig,\%loginhash);
1.188 raeburn 12058: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12059: foreach my $item (@toggles) {
12060: $loginhash{login}{$item} = $env{'form.'.$item};
12061: }
1.41 raeburn 12062: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12063: if (ref($colchanges{'login'}) eq 'HASH') {
12064: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12065: \%loginhash);
12066: }
1.110 raeburn 12067:
1.149 raeburn 12068: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12069: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12070: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12071: if (keys(%servers) > 1) {
12072: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12073: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12074: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12075: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12076: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12077: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12078: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12079: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12080: $changes{'loginvia'}{$lonhost} = 1;
12081: } else {
12082: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12083: $changes{'loginvia'}{$lonhost} = 1;
12084: }
12085: } else {
12086: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12087: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12088: $changes{'loginvia'}{$lonhost} = 1;
12089: }
12090: }
12091: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12092: foreach my $item (@loginvia_attribs) {
12093: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12094: }
12095: } else {
12096: foreach my $item (@loginvia_attribs) {
12097: my $new = $env{'form.'.$lonhost.'_'.$item};
12098: if (($item eq 'serverpath') && ($new eq 'custom')) {
12099: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12100: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12101: $new = '/';
12102: }
12103: }
12104: if (($item eq 'custompath') &&
12105: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12106: $new = '';
12107: }
12108: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12109: $changes{'loginvia'}{$lonhost} = 1;
12110: }
12111: if ($item eq 'exempt') {
1.256 raeburn 12112: $new = &check_exempt_addresses($new);
1.128 raeburn 12113: }
12114: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12115: }
12116: }
1.112 raeburn 12117: } else {
1.128 raeburn 12118: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12119: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12120: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12121: foreach my $item (@loginvia_attribs) {
12122: my $new = $env{'form.'.$lonhost.'_'.$item};
12123: if (($item eq 'serverpath') && ($new eq 'custom')) {
12124: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12125: $new = '/';
12126: }
12127: }
12128: if (($item eq 'custompath') &&
12129: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12130: $new = '';
12131: }
12132: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12133: }
1.110 raeburn 12134: }
12135: }
12136: }
12137: }
1.119 raeburn 12138:
1.168 raeburn 12139: my $servadm = $r->dir_config('lonAdmEMail');
12140: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12141: if (ref($domconfig{'login'}) eq 'HASH') {
12142: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12143: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12144: if ($lang eq 'nolang') {
12145: push(@currlangs,$lang);
12146: } elsif (defined($langchoices{$lang})) {
12147: push(@currlangs,$lang);
12148: } else {
12149: next;
12150: }
12151: }
12152: }
12153: }
12154: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12155: if (@currlangs > 0) {
12156: foreach my $lang (@currlangs) {
12157: if (grep(/^\Q$lang\E$/,@delurls)) {
12158: $changes{'helpurl'}{$lang} = 1;
12159: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12160: $changes{'helpurl'}{$lang} = 1;
12161: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12162: push(@newlangs,$lang);
12163: } else {
12164: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12165: }
12166: }
12167: }
12168: unless (grep(/^nolang$/,@currlangs)) {
12169: if ($env{'form.loginhelpurl_nolang.filename'}) {
12170: $changes{'helpurl'}{'nolang'} = 1;
12171: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12172: push(@newlangs,'nolang');
12173: }
12174: }
12175: if ($env{'form.loginhelpurl_add_lang'}) {
12176: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12177: ($env{'form.loginhelpurl_add_file.filename'})) {
12178: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12179: $addedfile = $env{'form.loginhelpurl_add_lang'};
12180: }
12181: }
12182: if ((@newlangs > 0) || ($addedfile)) {
12183: my $error;
12184: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12185: if ($configuserok eq 'ok') {
12186: if ($switchserver) {
12187: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12188: } elsif ($author_ok eq 'ok') {
12189: my @allnew = @newlangs;
12190: if ($addedfile ne '') {
12191: push(@allnew,$addedfile);
12192: }
1.421 raeburn 12193: my $modified = [];
1.168 raeburn 12194: foreach my $lang (@allnew) {
12195: my $formelem = 'loginhelpurl_'.$lang;
12196: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12197: $formelem = 'loginhelpurl_add_file';
12198: }
1.421 raeburn 12199: (my $result,$newurl{$lang}) =
12200: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12201: "help/$lang",'','',$newfile{$lang},
12202: $modified);
1.168 raeburn 12203: if ($result eq 'ok') {
12204: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12205: $changes{'helpurl'}{$lang} = 1;
12206: } else {
12207: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12208: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12209: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12210: (!grep(/^\Q$lang\E$/,@delurls))) {
12211: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12212: }
12213: }
12214: }
1.421 raeburn 12215: &update_modify_urls($r,$modified);
1.168 raeburn 12216: } else {
12217: $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);
12218: }
12219: } else {
12220: $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);
12221: }
12222: if ($error) {
12223: &Apache::lonnet::logthis($error);
12224: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12225: }
12226: }
1.256 raeburn 12227:
12228: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12229: if (ref($domconfig{'login'}) eq 'HASH') {
12230: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12231: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12232: if ($domservers{$lonhost}) {
12233: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12234: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12235: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12236: }
12237: }
12238: }
12239: }
12240: }
12241: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12242: foreach my $lonhost (sort(keys(%domservers))) {
12243: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12244: $changes{'headtag'}{$lonhost} = 1;
12245: } else {
12246: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12247: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12248: }
12249: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12250: push(@newhosts,$lonhost);
12251: } elsif ($currheadtagurls{$lonhost}) {
12252: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12253: if ($currexempt{$lonhost}) {
1.289 raeburn 12254: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12255: $changes{'headtag'}{$lonhost} = 1;
12256: }
12257: } elsif ($possexempt{$lonhost}) {
12258: $changes{'headtag'}{$lonhost} = 1;
12259: }
12260: if ($possexempt{$lonhost}) {
12261: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12262: }
12263: }
12264: }
12265: }
12266: if (@newhosts) {
12267: my $error;
12268: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12269: if ($configuserok eq 'ok') {
12270: if ($switchserver) {
12271: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12272: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12273: my $modified = [];
1.256 raeburn 12274: foreach my $lonhost (@newhosts) {
12275: my $formelem = 'loginheadtag_'.$lonhost;
1.421 raeburn 12276: (my $result,$newheadtagurls{$lonhost}) =
12277: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12278: "login/headtag/$lonhost",'','',
12279: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12280: $modified);
1.256 raeburn 12281: if ($result eq 'ok') {
12282: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12283: $changes{'headtag'}{$lonhost} = 1;
12284: if ($possexempt{$lonhost}) {
12285: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12286: }
12287: } else {
12288: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12289: $newheadtagurls{$lonhost},$result);
12290: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12291: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12292: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12293: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12294: }
12295: }
12296: }
1.421 raeburn 12297: &update_modify_urls($r,$modified);
1.256 raeburn 12298: } else {
12299: $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);
12300: }
12301: } else {
12302: $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);
12303: }
12304: if ($error) {
12305: &Apache::lonnet::logthis($error);
12306: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12307: }
12308: }
1.386 raeburn 12309: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12310: my @newsamlimgs;
12311: foreach my $lonhost (keys(%domservers)) {
12312: if ($env{'form.saml_'.$lonhost}) {
12313: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12314: push(@newsamlimgs,$lonhost);
12315: }
1.412 raeburn 12316: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12317: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12318: }
12319: if ($saml{$lonhost}) {
1.412 raeburn 12320: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12321: $env{'form.saml_window_'.$lonhost} = '';
12322: }
1.386 raeburn 12323: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12324: #FIXME Need to obsolete published image
12325: delete($currsaml{$lonhost}{'img'});
12326: $changes{'saml'}{$lonhost} = 1;
12327: }
12328: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12329: $changes{'saml'}{$lonhost} = 1;
12330: }
12331: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12332: $changes{'saml'}{$lonhost} = 1;
12333: }
12334: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12335: $changes{'saml'}{$lonhost} = 1;
12336: }
12337: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12338: $changes{'saml'}{$lonhost} = 1;
12339: }
1.412 raeburn 12340: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12341: $changes{'saml'}{$lonhost} = 1;
12342: }
1.386 raeburn 12343: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12344: $changes{'saml'}{$lonhost} = 1;
12345: }
12346: } else {
12347: $changes{'saml'}{$lonhost} = 1;
12348: }
1.412 raeburn 12349: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12350: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12351: }
12352: } else {
1.389 raeburn 12353: if ($saml{$lonhost}) {
12354: $changes{'saml'}{$lonhost} = 1;
12355: delete($currsaml{$lonhost});
12356: }
1.386 raeburn 12357: }
12358: }
12359: foreach my $posshost (keys(%currsaml)) {
12360: unless (exists($domservers{$posshost})) {
12361: delete($currsaml{$posshost});
12362: }
12363: }
12364: %{$loginhash{'login'}{'saml'}} = %currsaml;
12365: if (@newsamlimgs) {
12366: my $error;
12367: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12368: if ($configuserok eq 'ok') {
12369: if ($switchserver) {
12370: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12371: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12372: my $modified = [];
1.386 raeburn 12373: foreach my $lonhost (@newsamlimgs) {
12374: my $formelem = 'saml_img_'.$lonhost;
1.421 raeburn 12375: my ($result,$imgurl) =
12376: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12377: "login/saml/$lonhost",'','',
12378: $env{'form.saml_img_'.$lonhost.'.filename'},
12379: $modified);
1.386 raeburn 12380: if ($result eq 'ok') {
12381: $currsaml{$lonhost}{'img'} = $imgurl;
12382: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12383: $changes{'saml'}{$lonhost} = 1;
12384: } else {
12385: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12386: $lonhost,$result);
12387: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12388: }
12389: }
1.421 raeburn 12390: &update_modify_urls($r,$modified);
1.386 raeburn 12391: } else {
12392: $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);
12393: }
12394: } else {
12395: $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);
12396: }
12397: if ($error) {
12398: &Apache::lonnet::logthis($error);
12399: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12400: }
12401: }
1.169 raeburn 12402: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12403:
12404: my $defaulthelpfile = '/adm/loginproblems.html';
12405: my $defaulttext = &mt('Default in use');
12406:
1.1 raeburn 12407: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12408: $dom);
12409: if ($putresult eq 'ok') {
1.188 raeburn 12410: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12411: my %defaultchecked = (
12412: 'coursecatalog' => 'on',
1.188 raeburn 12413: 'helpdesk' => 'on',
1.42 raeburn 12414: 'adminmail' => 'off',
1.43 raeburn 12415: 'newuser' => 'off',
1.42 raeburn 12416: );
1.55 raeburn 12417: if (ref($domconfig{'login'}) eq 'HASH') {
12418: foreach my $item (@toggles) {
12419: if ($defaultchecked{$item} eq 'on') {
12420: if (($domconfig{'login'}{$item} eq '0') &&
12421: ($env{'form.'.$item} eq '1')) {
12422: $changes{$item} = 1;
12423: } elsif (($domconfig{'login'}{$item} eq '' ||
12424: $domconfig{'login'}{$item} eq '1') &&
12425: ($env{'form.'.$item} eq '0')) {
12426: $changes{$item} = 1;
12427: }
12428: } elsif ($defaultchecked{$item} eq 'off') {
12429: if (($domconfig{'login'}{$item} eq '1') &&
12430: ($env{'form.'.$item} eq '0')) {
12431: $changes{$item} = 1;
12432: } elsif (($domconfig{'login'}{$item} eq '' ||
12433: $domconfig{'login'}{$item} eq '0') &&
12434: ($env{'form.'.$item} eq '1')) {
12435: $changes{$item} = 1;
12436: }
1.42 raeburn 12437: }
12438: }
1.41 raeburn 12439: }
1.6 raeburn 12440: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12441: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12442: if (exists($changes{'saml'})) {
12443: my $hostid_in_use;
12444: my @hosts = &Apache::lonnet::current_machine_ids();
12445: if (@hosts > 1) {
12446: foreach my $hostid (@hosts) {
12447: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12448: $hostid_in_use = $hostid;
12449: last;
12450: }
12451: }
12452: } else {
12453: $hostid_in_use = $r->dir_config('lonHostID');
12454: }
12455: if (($hostid_in_use) &&
12456: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12457: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12458: }
12459: if (ref($lastactref) eq 'HASH') {
12460: if (ref($changes{'saml'}) eq 'HASH') {
12461: my %updates;
12462: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12463: $lastactref->{'samllanding'} = \%updates;
12464: }
12465: }
12466: }
1.212 raeburn 12467: if (ref($lastactref) eq 'HASH') {
12468: $lastactref->{'domainconfig'} = 1;
12469: }
1.1 raeburn 12470: $resulttext = &mt('Changes made:').'<ul>';
12471: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12472: if ($item eq 'loginvia') {
1.112 raeburn 12473: if (ref($changes{$item}) eq 'HASH') {
12474: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12475: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12476: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12477: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12478: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12479: $protocol = 'http' if ($protocol ne 'https');
12480: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12481:
12482: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12483: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12484: } else {
12485: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12486: }
12487: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12488: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12489: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12490: }
12491: $resulttext .= '</li>';
12492: } else {
12493: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12494: }
1.112 raeburn 12495: } else {
1.128 raeburn 12496: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12497: }
12498: }
1.128 raeburn 12499: $resulttext .= '</ul></li>';
1.112 raeburn 12500: }
1.168 raeburn 12501: } elsif ($item eq 'helpurl') {
12502: if (ref($changes{$item}) eq 'HASH') {
12503: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12504: if (grep(/^\Q$lang\E$/,@delurls)) {
12505: my ($chg,$link);
12506: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12507: if ($lang eq 'nolang') {
12508: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12509: } else {
12510: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12511: }
12512: $resulttext .= '<li>'.$chg.'</li>';
12513: } else {
12514: my $chg;
12515: if ($lang eq 'nolang') {
12516: $chg = &mt('custom log-in help file for no preferred language');
12517: } else {
12518: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12519: }
12520: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12521: $loginhash{'login'}{'helpurl'}{$lang}.
12522: '?inhibitmenu=yes',$chg,600,500).
12523: '</li>';
12524: }
12525: }
12526: }
1.256 raeburn 12527: } elsif ($item eq 'headtag') {
12528: if (ref($changes{$item}) eq 'HASH') {
12529: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12530: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12531: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12532: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12533: $resulttext .= '<li><a href="'.
12534: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12535: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12536: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12537: if ($possexempt{$lonhost}) {
12538: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12539: } else {
12540: $resulttext .= &mt('included for any client IP');
12541: }
12542: $resulttext .= '</li>';
12543: }
12544: }
12545: }
1.386 raeburn 12546: } elsif ($item eq 'saml') {
12547: if (ref($changes{$item}) eq 'HASH') {
12548: my %notlt = (
12549: text => 'Text for log-in by SSO',
12550: img => 'SSO button image',
12551: alt => 'Alt text for button image',
12552: url => 'SSO URL',
12553: title => 'Tooltip for SSO link',
1.412 raeburn 12554: window => 'Pop-up window if iframe',
1.386 raeburn 12555: notsso => 'Text for non-SSO log-in',
12556: );
12557: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12558: if (ref($currsaml{$lonhost}) eq 'HASH') {
12559: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12560: '<ul>';
1.412 raeburn 12561: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12562: if ($currsaml{$lonhost}{$key} eq '') {
12563: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12564: } else {
12565: my $value = "'$currsaml{$lonhost}{$key}'";
12566: if ($key eq 'img') {
12567: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12568: } elsif ($key eq 'window') {
12569: $value = 'On';
1.386 raeburn 12570: }
12571: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12572: $value).'</li>';
12573: }
12574: }
12575: $resulttext .= '</ul></li>';
12576: } else {
12577: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12578: }
12579: }
12580: }
1.169 raeburn 12581: } elsif ($item eq 'captcha') {
12582: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12583: my $chgtxt;
1.169 raeburn 12584: if ($loginhash{'login'}{$item} eq 'notused') {
12585: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12586: } else {
12587: my %captchas = &captcha_phrases();
12588: if ($captchas{$loginhash{'login'}{$item}}) {
12589: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12590: } else {
12591: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12592: }
12593: }
12594: $resulttext .= '<li>'.$chgtxt.'</li>';
12595: }
12596: } elsif ($item eq 'recaptchakeys') {
12597: if (ref($loginhash{'login'}) eq 'HASH') {
12598: my ($privkey,$pubkey);
12599: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
12600: $pubkey = $loginhash{'login'}{$item}{'public'};
12601: $privkey = $loginhash{'login'}{$item}{'private'};
12602: }
12603: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
12604: if (!$pubkey) {
12605: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
12606: } else {
12607: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
12608: }
12609: if (!$privkey) {
12610: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
12611: } else {
1.251 raeburn 12612: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 12613: }
12614: $chgtxt .= '</ul>';
12615: $resulttext .= '<li>'.$chgtxt.'</li>';
12616: }
1.269 raeburn 12617: } elsif ($item eq 'recaptchaversion') {
12618: if (ref($loginhash{'login'}) eq 'HASH') {
12619: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 12620: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 12621: '</li>';
12622: }
12623: }
1.41 raeburn 12624: } else {
12625: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
12626: }
1.1 raeburn 12627: }
1.6 raeburn 12628: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 12629: } else {
12630: $resulttext = &mt('No changes made to log-in page settings');
12631: }
12632: } else {
1.11 albertel 12633: $resulttext = '<span class="LC_error">'.
12634: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12635: }
1.6 raeburn 12636: if ($errors) {
1.9 raeburn 12637: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 12638: $errors.'</ul>';
12639: }
12640: return $resulttext;
12641: }
12642:
1.256 raeburn 12643: sub check_exempt_addresses {
12644: my ($iplist) = @_;
12645: $iplist =~ s/^\s+//;
12646: $iplist =~ s/\s+$//;
12647: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
12648: my (@okips,$new);
12649: foreach my $ip (@poss_ips) {
12650: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
12651: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
12652: push(@okips,$ip);
12653: }
12654: }
12655: }
12656: if (@okips > 0) {
12657: $new = join(',',@okips);
12658: } else {
12659: $new = '';
12660: }
12661: return $new;
12662: }
12663:
1.6 raeburn 12664: sub color_font_choices {
12665: my %choices =
12666: &Apache::lonlocal::texthash (
12667: img => "Header",
12668: bgs => "Background colors",
12669: links => "Link colors",
1.55 raeburn 12670: images => "Images",
1.6 raeburn 12671: font => "Font color",
1.201 raeburn 12672: fontmenu => "Font menu",
1.76 raeburn 12673: pgbg => "Page",
1.6 raeburn 12674: tabbg => "Header",
12675: sidebg => "Border",
12676: link => "Link",
12677: alink => "Active link",
12678: vlink => "Visited link",
12679: );
12680: return %choices;
12681: }
12682:
1.394 raeburn 12683: sub modify_ipaccess {
12684: my ($dom,$lastactref,%domconfig) = @_;
12685: my (@allpos,%changes,%confhash,$errors,$resulttext);
12686: my (@items,%deletions,%itemids,@warnings);
12687: my ($typeorder,$types) = &commblocktype_text();
12688: if ($env{'form.ipaccess_add'}) {
12689: my $name = $env{'form.ipaccess_name_add'};
12690: my ($newid,$error) = &get_ipaccess_id($dom,$name);
12691: if ($newid) {
12692: $itemids{'add'} = $newid;
12693: push(@items,'add');
12694: $changes{$newid} = 1;
12695: } else {
12696: $error = &mt('Failed to acquire unique ID for new IP access control item');
12697: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12698: }
12699: }
12700: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12701: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
12702: if (@todelete) {
12703: map { $deletions{$_} = 1; } @todelete;
12704: }
12705: my $maxnum = $env{'form.ipaccess_maxnum'};
12706: for (my $i=0; $i<$maxnum; $i++) {
12707: my $itemid = $env{'form.ipaccess_id_'.$i};
12708: $itemid =~ s/\D+//g;
12709: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12710: if ($deletions{$itemid}) {
12711: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
12712: } else {
12713: push(@items,$i);
12714: $itemids{$i} = $itemid;
12715: }
12716: }
12717: }
12718: }
12719: foreach my $idx (@items) {
12720: my $itemid = $itemids{$idx};
12721: next unless ($itemid);
12722: my %current;
12723: unless ($idx eq 'add') {
12724: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12725: %current = %{$domconfig{'ipaccess'}{$itemid}};
12726: }
12727: }
12728: my $position = $env{'form.ipaccess_pos_'.$itemid};
12729: $position =~ s/\D+//g;
12730: if ($position ne '') {
12731: $allpos[$position] = $itemid;
12732: }
12733: my $name = $env{'form.ipaccess_name_'.$idx};
12734: $name =~ s/^\s+|\s+$//g;
12735: $confhash{$itemid}{'name'} = $name;
12736: my $possrange = $env{'form.ipaccess_range_'.$idx};
12737: $possrange =~ s/^\s+|\s+$//g;
12738: unless ($possrange eq '') {
12739: $possrange =~ s/[\r\n]+/\s/g;
12740: $possrange =~ s/\s*-\s*/-/g;
12741: $possrange =~ s/\s+/,/g;
12742: $possrange =~ s/,+/,/g;
12743: if ($possrange ne '') {
12744: my (@ok,$count);
12745: $count = 0;
12746: foreach my $poss (split(/\,/,$possrange)) {
12747: $count ++;
12748: $poss = &validate_ip_pattern($poss);
12749: if ($poss ne '') {
12750: push(@ok,$poss);
12751: }
12752: }
12753: my $diff = $count - scalar(@ok);
12754: if ($diff) {
12755: $errors .= '<li><span class="LC_error">'.
12756: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
12757: $diff,$name).
12758: '</span></li>';
12759: }
12760: if (@ok) {
12761: my @cidr_list;
12762: foreach my $item (@ok) {
12763: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
12764: }
12765: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
12766: }
12767: }
12768: }
12769: foreach my $field ('name','ip') {
12770: unless (($idx eq 'add') || ($changes{$itemid})) {
12771: if ($current{$field} ne $confhash{$itemid}{$field}) {
12772: $changes{$itemid} = 1;
12773: last;
12774: }
12775: }
12776: }
12777: $confhash{$itemid}{'commblocks'} = {};
12778:
12779: my %commblocks;
12780: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
12781: foreach my $type (@{$typeorder}) {
12782: if ($commblocks{$type}) {
12783: $confhash{$itemid}{'commblocks'}{$type} = 'on';
12784: }
12785: unless (($idx eq 'add') || ($changes{$itemid})) {
12786: if (ref($current{'commblocks'}) eq 'HASH') {
12787: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
12788: $changes{$itemid} = 1;
12789: }
12790: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
12791: $changes{$itemid} = 1;
12792: }
12793: }
12794: }
12795: $confhash{$itemid}{'courses'} = {};
12796: my %crsdeletions;
12797: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
12798: if (@delcrs) {
12799: map { $crsdeletions{$_} = 1; } @delcrs;
12800: }
12801: if (ref($current{'courses'}) eq 'HASH') {
12802: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
12803: if ($crsdeletions{$cid}) {
12804: $changes{$itemid} = 1;
12805: } else {
12806: $confhash{$itemid}{'courses'}{$cid} = 1;
12807: }
12808: }
12809: }
12810: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
12811: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
12812: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
12813: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
12814: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
12815: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
12816: $errors .= '<li><span class="LC_error">'.
12817: &mt('Invalid courseID [_1] omitted from list of allowed courses',
12818: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
12819: '</span></li>';
12820: } else {
12821: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
12822: $changes{$itemid} = 1;
12823: }
12824: }
12825: }
12826: if (@allpos > 0) {
12827: my $idx = 0;
12828: foreach my $itemid (@allpos) {
12829: if ($itemid ne '') {
12830: $confhash{$itemid}{'order'} = $idx;
12831: unless ($changes{$itemid}) {
12832: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
12833: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
12834: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
12835: $changes{$itemid} = 1;
12836: }
12837: }
12838: }
12839: }
12840: $idx ++;
12841: }
12842: }
12843: }
12844: if (keys(%changes)) {
12845: my %defaultshash = (
12846: ipaccess => \%confhash,
12847: );
12848: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
12849: $dom);
12850: if ($putresult eq 'ok') {
12851: my $cachetime = 1800;
12852: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
12853: if (ref($lastactref) eq 'HASH') {
12854: $lastactref->{'ipaccess'} = 1;
12855: }
12856: $resulttext = &mt('Changes made:').'<ul>';
12857: my %bynum;
12858: foreach my $itemid (sort(keys(%changes))) {
12859: if (ref($confhash{$itemid}) eq 'HASH') {
12860: my $position = $confhash{$itemid}{'order'};
12861: if ($position =~ /^\d+$/) {
12862: $bynum{$position} = $itemid;
12863: }
12864: }
12865: }
12866: if (keys(%deletions)) {
12867: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
12868: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
12869: }
12870: }
12871: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
12872: my $itemid = $bynum{$pos};
12873: if (ref($confhash{$itemid}) eq 'HASH') {
12874: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
12875: my $position = $pos + 1;
12876: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
12877: if ($confhash{$itemid}{'ip'} eq '') {
12878: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
12879: } else {
12880: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
12881: }
12882: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
12883: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
12884: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
12885: '</li>';
12886: } else {
12887: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
12888: }
12889: if (keys(%{$confhash{$itemid}{'courses'}})) {
12890: my @courses;
12891: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
12892: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
12893: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
12894: }
12895: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
12896: join('</li><li>',@courses).'</li></ul>';
12897: } else {
12898: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
12899: }
1.395 raeburn 12900: $resulttext .= '</ul></li>';
1.394 raeburn 12901: }
12902: }
1.395 raeburn 12903: $resulttext .= '</ul>';
1.394 raeburn 12904: } else {
12905: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12906: }
12907: } else {
12908: $resulttext = &mt('No changes made');
12909: }
12910: if ($errors) {
12911: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12912: $errors.'</ul></p>';
12913: }
12914: return $resulttext;
12915: }
12916:
12917: sub get_ipaccess_id {
12918: my ($domain,$location) = @_;
12919: # get lock on ipaccess db
12920: my $lockhash = {
12921: lock => $env{'user.name'}.
12922: ':'.$env{'user.domain'},
12923: };
12924: my $tries = 0;
12925: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12926: my ($id,$error);
12927:
12928: while (($gotlock ne 'ok') && ($tries<10)) {
12929: $tries ++;
12930: sleep (0.1);
12931: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12932: }
12933: if ($gotlock eq 'ok') {
12934: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12935: if ($currids{'lock'}) {
12936: delete($currids{'lock'});
12937: if (keys(%currids)) {
12938: my @curr = sort { $a <=> $b } keys(%currids);
12939: if ($curr[-1] =~ /^\d+$/) {
12940: $id = 1 + $curr[-1];
12941: }
12942: } else {
12943: $id = 1;
12944: }
12945: if ($id) {
12946: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12947: $error = 'nostore';
12948: }
12949: } else {
12950: $error = 'nonumber';
12951: }
12952: }
12953: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12954: } else {
12955: $error = 'nolock';
12956: }
12957: return ($id,$error);
12958: }
12959:
1.6 raeburn 12960: sub modify_rolecolors {
1.205 raeburn 12961: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12962: my ($resulttext,%rolehash);
12963: $rolehash{'rolecolors'} = {};
1.55 raeburn 12964: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12965: if ($domconfig{'rolecolors'} eq '') {
12966: $domconfig{'rolecolors'} = {};
12967: }
12968: }
1.9 raeburn 12969: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12970: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12971: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12972: $dom);
12973: if ($putresult eq 'ok') {
12974: if (keys(%changes) > 0) {
1.41 raeburn 12975: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 12976: if (ref($lastactref) eq 'HASH') {
12977: $lastactref->{'domainconfig'} = 1;
12978: }
1.6 raeburn 12979: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12980: $rolehash{'rolecolors'});
12981: } else {
12982: $resulttext = &mt('No changes made to default color schemes');
12983: }
12984: } else {
1.11 albertel 12985: $resulttext = '<span class="LC_error">'.
12986: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12987: }
12988: if ($errors) {
12989: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12990: $errors.'</ul>';
12991: }
12992: return $resulttext;
12993: }
12994:
12995: sub modify_colors {
1.9 raeburn 12996: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12997: my (%changes,%choices);
1.51 raeburn 12998: my @bgs;
1.6 raeburn 12999: my @links = ('link','alink','vlink');
1.41 raeburn 13000: my @logintext;
1.6 raeburn 13001: my @images;
13002: my $servadm = $r->dir_config('lonAdmEMail');
13003: my $errors;
1.200 raeburn 13004: my %defaults;
1.6 raeburn 13005: foreach my $role (@{$roles}) {
13006: if ($role eq 'login') {
1.12 raeburn 13007: %choices = &login_choices();
1.41 raeburn 13008: @logintext = ('textcol','bgcol');
1.12 raeburn 13009: } else {
13010: %choices = &color_font_choices();
13011: }
13012: if ($role eq 'login') {
1.41 raeburn 13013: @images = ('img','logo','domlogo','login');
1.51 raeburn 13014: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13015: } else {
13016: @images = ('img');
1.200 raeburn 13017: @bgs = ('pgbg','tabbg','sidebg');
13018: }
13019: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13020: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13021: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13022: }
13023: if ($role eq 'login') {
13024: foreach my $item (@logintext) {
1.234 raeburn 13025: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13026: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13027: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13028: }
13029: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13030: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13031: }
13032: }
13033: } else {
1.234 raeburn 13034: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13035: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13036: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13037: }
13038: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13039: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13040: }
1.6 raeburn 13041: }
1.200 raeburn 13042: foreach my $item (@bgs) {
1.234 raeburn 13043: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13044: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13045: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13046: }
13047: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13048: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13049: }
13050: }
13051: foreach my $item (@links) {
1.234 raeburn 13052: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13053: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13054: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13055: }
13056: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13057: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13058: }
1.6 raeburn 13059: }
1.46 raeburn 13060: my ($configuserok,$author_ok,$switchserver) =
13061: &config_check($dom,$confname,$servadm);
1.9 raeburn 13062: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13063: if (ref($domconfig->{$role}) ne 'HASH') {
13064: $domconfig->{$role} = {};
13065: }
1.8 raeburn 13066: foreach my $img (@images) {
1.402 raeburn 13067: if ($role eq 'login') {
13068: if (($img eq 'img') || ($img eq 'logo')) {
13069: if (defined($env{'form.login_showlogo_'.$img})) {
13070: $confhash->{$role}{'showlogo'}{$img} = 1;
13071: } else {
13072: $confhash->{$role}{'showlogo'}{$img} = 0;
13073: }
13074: }
13075: if ($env{'form.login_alt_'.$img} ne '') {
13076: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13077: }
1.402 raeburn 13078: }
1.18 albertel 13079: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13080: && !defined($domconfig->{$role}{$img})
13081: && !$env{'form.'.$role.'_del_'.$img}
13082: && $env{'form.'.$role.'_import_'.$img}) {
13083: # import the old configured image from the .tab setting
13084: # if they haven't provided a new one
13085: $domconfig->{$role}{$img} =
13086: $env{'form.'.$role.'_import_'.$img};
13087: }
1.6 raeburn 13088: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13089: my $error;
1.6 raeburn 13090: if ($configuserok eq 'ok') {
1.9 raeburn 13091: if ($switchserver) {
1.12 raeburn 13092: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13093: } else {
13094: if ($author_ok eq 'ok') {
1.421 raeburn 13095: my $modified = [];
1.9 raeburn 13096: my ($result,$logourl) =
1.421 raeburn 13097: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13098: $dom,$confname,$img,$width,$height,
13099: '',$modified);
1.9 raeburn 13100: if ($result eq 'ok') {
13101: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13102: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13103: &update_modify_urls($r,$modified);
1.9 raeburn 13104: } else {
1.12 raeburn 13105: $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 13106: }
13107: } else {
1.46 raeburn 13108: $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 13109: }
13110: }
13111: } else {
1.46 raeburn 13112: $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 13113: }
13114: if ($error) {
1.8 raeburn 13115: &Apache::lonnet::logthis($error);
1.11 albertel 13116: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13117: }
13118: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13119: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13120: my $error;
13121: if ($configuserok eq 'ok') {
13122: # is confname an author?
13123: if ($switchserver eq '') {
13124: if ($author_ok eq 'ok') {
1.421 raeburn 13125: my $modified = [];
1.9 raeburn 13126: my ($result,$logourl) =
1.421 raeburn 13127: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13128: $dom,$confname,$img,$width,$height,
13129: '',$modified);
1.9 raeburn 13130: if ($result eq 'ok') {
13131: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13132: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13133: &update_modify_urls($r,$modified);
1.9 raeburn 13134: }
13135: }
13136: }
13137: }
1.6 raeburn 13138: }
13139: }
13140: }
13141: if (ref($domconfig) eq 'HASH') {
13142: if (ref($domconfig->{$role}) eq 'HASH') {
13143: foreach my $img (@images) {
13144: if ($domconfig->{$role}{$img} ne '') {
13145: if ($env{'form.'.$role.'_del_'.$img}) {
13146: $confhash->{$role}{$img} = '';
1.12 raeburn 13147: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13148: } else {
1.9 raeburn 13149: if ($confhash->{$role}{$img} eq '') {
13150: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13151: }
1.6 raeburn 13152: }
13153: } else {
13154: if ($env{'form.'.$role.'_del_'.$img}) {
13155: $confhash->{$role}{$img} = '';
1.12 raeburn 13156: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13157: }
13158: }
1.402 raeburn 13159: if ($role eq 'login') {
13160: if (($img eq 'logo') || ($img eq 'img')) {
13161: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13162: if ($confhash->{$role}{'showlogo'}{$img} ne
13163: $domconfig->{$role}{'showlogo'}{$img}) {
13164: $changes{$role}{'showlogo'}{$img} = 1;
13165: }
13166: } else {
13167: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13168: $changes{$role}{'showlogo'}{$img} = 1;
13169: }
1.70 raeburn 13170: }
1.402 raeburn 13171: }
13172: if ($img ne 'login') {
13173: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13174: if ($confhash->{$role}{'alttext'}{$img} ne
13175: $domconfig->{$role}{'alttext'}{$img}) {
13176: $changes{$role}{'alttext'}{$img} = 1;
13177: }
13178: } else {
13179: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13180: $changes{$role}{'alttext'}{$img} = 1;
13181: }
1.70 raeburn 13182: }
13183: }
13184: }
13185: }
1.6 raeburn 13186: if ($domconfig->{$role}{'font'} ne '') {
13187: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13188: $changes{$role}{'font'} = 1;
13189: }
13190: } else {
13191: if ($confhash->{$role}{'font'}) {
13192: $changes{$role}{'font'} = 1;
13193: }
13194: }
1.107 raeburn 13195: if ($role ne 'login') {
13196: if ($domconfig->{$role}{'fontmenu'} ne '') {
13197: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13198: $changes{$role}{'fontmenu'} = 1;
13199: }
13200: } else {
13201: if ($confhash->{$role}{'fontmenu'}) {
13202: $changes{$role}{'fontmenu'} = 1;
13203: }
1.97 tempelho 13204: }
13205: }
1.6 raeburn 13206: foreach my $item (@bgs) {
13207: if ($domconfig->{$role}{$item} ne '') {
13208: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13209: $changes{$role}{'bgs'}{$item} = 1;
13210: }
13211: } else {
13212: if ($confhash->{$role}{$item}) {
13213: $changes{$role}{'bgs'}{$item} = 1;
13214: }
13215: }
13216: }
13217: foreach my $item (@links) {
13218: if ($domconfig->{$role}{$item} ne '') {
13219: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13220: $changes{$role}{'links'}{$item} = 1;
13221: }
13222: } else {
13223: if ($confhash->{$role}{$item}) {
13224: $changes{$role}{'links'}{$item} = 1;
13225: }
13226: }
13227: }
1.41 raeburn 13228: foreach my $item (@logintext) {
13229: if ($domconfig->{$role}{$item} ne '') {
13230: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13231: $changes{$role}{'logintext'}{$item} = 1;
13232: }
13233: } else {
13234: if ($confhash->{$role}{$item}) {
13235: $changes{$role}{'logintext'}{$item} = 1;
13236: }
13237: }
13238: }
1.6 raeburn 13239: } else {
13240: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13241: \@logintext,$confhash,\%changes);
1.6 raeburn 13242: }
13243: } else {
13244: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13245: \@logintext,$confhash,\%changes);
1.6 raeburn 13246: }
13247: }
13248: return ($errors,%changes);
13249: }
13250:
1.46 raeburn 13251: sub config_check {
13252: my ($dom,$confname,$servadm) = @_;
13253: my ($configuserok,$author_ok,$switchserver,%currroles);
13254: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13255: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13256: $confname,$servadm);
13257: if ($configuserok eq 'ok') {
13258: $switchserver = &check_switchserver($dom,$confname);
13259: if ($switchserver eq '') {
13260: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13261: }
13262: }
13263: return ($configuserok,$author_ok,$switchserver);
13264: }
13265:
1.6 raeburn 13266: sub default_change_checker {
1.41 raeburn 13267: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13268: foreach my $item (@{$links}) {
13269: if ($confhash->{$role}{$item}) {
13270: $changes->{$role}{'links'}{$item} = 1;
13271: }
13272: }
13273: foreach my $item (@{$bgs}) {
13274: if ($confhash->{$role}{$item}) {
13275: $changes->{$role}{'bgs'}{$item} = 1;
13276: }
13277: }
1.41 raeburn 13278: foreach my $item (@{$logintext}) {
13279: if ($confhash->{$role}{$item}) {
13280: $changes->{$role}{'logintext'}{$item} = 1;
13281: }
13282: }
1.6 raeburn 13283: foreach my $img (@{$images}) {
13284: if ($env{'form.'.$role.'_del_'.$img}) {
13285: $confhash->{$role}{$img} = '';
1.12 raeburn 13286: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13287: }
1.70 raeburn 13288: if ($role eq 'login') {
13289: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13290: $changes->{$role}{'showlogo'}{$img} = 1;
13291: }
1.402 raeburn 13292: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13293: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13294: $changes->{$role}{'alttext'}{$img} = 1;
13295: }
13296: }
1.70 raeburn 13297: }
1.6 raeburn 13298: }
13299: if ($confhash->{$role}{'font'}) {
13300: $changes->{$role}{'font'} = 1;
13301: }
1.48 raeburn 13302: }
1.6 raeburn 13303:
13304: sub display_colorchgs {
13305: my ($dom,$changes,$roles,$confhash) = @_;
13306: my (%choices,$resulttext);
13307: if (!grep(/^login$/,@{$roles})) {
13308: $resulttext = &mt('Changes made:').'<br />';
13309: }
13310: foreach my $role (@{$roles}) {
13311: if ($role eq 'login') {
13312: %choices = &login_choices();
13313: } else {
13314: %choices = &color_font_choices();
13315: }
13316: if (ref($changes->{$role}) eq 'HASH') {
13317: if ($role ne 'login') {
13318: $resulttext .= '<h4>'.&mt($role).'</h4>';
13319: }
13320: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13321: if ($role ne 'login') {
13322: $resulttext .= '<ul>';
13323: }
13324: if (ref($changes->{$role}{$key}) eq 'HASH') {
13325: if ($role ne 'login') {
13326: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13327: }
13328: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13329: if (($role eq 'login') && ($key eq 'showlogo')) {
13330: if ($confhash->{$role}{$key}{$item}) {
13331: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13332: } else {
13333: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13334: }
1.402 raeburn 13335: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13336: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13337: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13338: $confhash->{$role}{$key}{$item}).'</li>';
13339: } else {
13340: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13341: }
1.70 raeburn 13342: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13343: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13344: } else {
1.12 raeburn 13345: my $newitem = $confhash->{$role}{$item};
13346: if ($key eq 'images') {
1.306 raeburn 13347: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13348: }
13349: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13350: }
13351: }
13352: if ($role ne 'login') {
13353: $resulttext .= '</ul></li>';
13354: }
13355: } else {
13356: if ($confhash->{$role}{$key} eq '') {
13357: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13358: } else {
13359: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13360: }
13361: }
13362: if ($role ne 'login') {
13363: $resulttext .= '</ul>';
13364: }
13365: }
13366: }
13367: }
1.3 raeburn 13368: return $resulttext;
1.1 raeburn 13369: }
13370:
1.9 raeburn 13371: sub thumb_dimensions {
13372: return ('200','50');
13373: }
13374:
1.16 raeburn 13375: sub check_dimensions {
13376: my ($inputfile) = @_;
13377: my ($fullwidth,$fullheight);
13378: if ($inputfile =~ m|^[/\w.\-]+$|) {
13379: if (open(PIPE,"identify $inputfile 2>&1 |")) {
13380: my $imageinfo = <PIPE>;
13381: if (!close(PIPE)) {
13382: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
13383: }
13384: chomp($imageinfo);
13385: my ($fullsize) =
1.21 raeburn 13386: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 13387: if ($fullsize) {
13388: ($fullwidth,$fullheight) = split(/x/,$fullsize);
13389: }
13390: }
13391: }
13392: return ($fullwidth,$fullheight);
13393: }
13394:
1.9 raeburn 13395: sub check_configuser {
13396: my ($uhome,$dom,$confname,$servadm) = @_;
13397: my ($configuserok,%currroles);
13398: if ($uhome eq 'no_host') {
13399: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 13400: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 13401: $configuserok =
13402: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
13403: $configpass,'','','','','',undef,$servadm);
13404: } else {
13405: $configuserok = 'ok';
13406: %currroles =
13407: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
13408: }
13409: return ($configuserok,%currroles);
13410: }
13411:
13412: sub check_authorstatus {
13413: my ($dom,$confname,%currroles) = @_;
13414: my $author_ok;
1.40 raeburn 13415: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 13416: my $start = time;
13417: my $end = 0;
13418: $author_ok =
13419: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 13420: 'au',$end,$start,'','','domconfig');
1.9 raeburn 13421: } else {
13422: $author_ok = 'ok';
13423: }
13424: return $author_ok;
13425: }
13426:
1.421 raeburn 13427: sub update_modify_urls {
13428: my ($r,$modified) = @_;
13429: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
13430: push(@{$modified_urls},$modified);
13431: unless ($registered_cleanup) {
13432: my $handlers = $r->get_handlers('PerlCleanupHandler');
13433: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
13434: $registered_cleanup=1;
1.9 raeburn 13435: }
13436: }
1.155 raeburn 13437: }
13438:
13439: sub notifysubscribed {
13440: foreach my $targetsource (@{$modified_urls}){
13441: next unless (ref($targetsource) eq 'ARRAY');
13442: my ($target,$source)=@{$targetsource};
13443: if ($source ne '') {
1.316 raeburn 13444: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 13445: print $logfh "\nCleanup phase: Notifications\n";
13446: my @subscribed=&subscribed_hosts($target);
13447: foreach my $subhost (@subscribed) {
13448: print $logfh "\nNotifying host ".$subhost.':';
13449: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
13450: print $logfh $reply;
13451: }
13452: my @subscribedmeta=&subscribed_hosts("$target.meta");
13453: foreach my $subhost (@subscribedmeta) {
13454: print $logfh "\nNotifying host for metadata only ".$subhost.':';
13455: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
13456: $subhost);
13457: print $logfh $reply;
13458: }
13459: print $logfh "\n============ Done ============\n";
1.160 raeburn 13460: close($logfh);
1.155 raeburn 13461: }
13462: }
13463: }
13464: return OK;
13465: }
13466:
13467: sub subscribed_hosts {
13468: my ($target) = @_;
13469: my @subscribed;
1.316 raeburn 13470: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 13471: while (my $subline=<$fh>) {
13472: if ($subline =~ /^($match_lonid):/) {
13473: my $host = $1;
13474: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
13475: unless (grep(/^\Q$host\E$/,@subscribed)) {
13476: push(@subscribed,$host);
13477: }
13478: }
13479: }
13480: }
13481: }
13482: return @subscribed;
1.9 raeburn 13483: }
13484:
13485: sub check_switchserver {
13486: my ($dom,$confname) = @_;
1.424 ! raeburn 13487: my ($allowed,$switchserver,$home);
! 13488: if ($confname eq '') {
1.9 raeburn 13489: $home = &Apache::lonnet::domain($dom,'primary');
1.424 ! raeburn 13490: } else {
! 13491: $home = &Apache::lonnet::homeserver($confname,$dom);
! 13492: if ($home eq 'no_host') {
! 13493: $home = &Apache::lonnet::domain($dom,'primary');
! 13494: }
1.9 raeburn 13495: }
13496: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 13497: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
13498: if (!$allowed) {
1.180 raeburn 13499: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 13500: }
13501: return $switchserver;
13502: }
13503:
1.1 raeburn 13504: sub modify_quotas {
1.216 raeburn 13505: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 13506: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 13507: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 13508: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
13509: $validationfieldsref);
1.86 raeburn 13510: if ($action eq 'quotas') {
13511: $context = 'tools';
1.163 raeburn 13512: } else {
1.86 raeburn 13513: $context = $action;
13514: }
13515: if ($context eq 'requestcourses') {
1.325 raeburn 13516: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 13517: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 13518: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
13519: %titles = &courserequest_titles();
13520: $toolregexp = join('|',@usertools);
13521: %conditions = &courserequest_conditions();
1.216 raeburn 13522: $confname = $dom.'-domainconfig';
13523: my $servadm = $r->dir_config('lonAdmEMail');
13524: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 13525: ($validationitemsref,$validationnamesref,$validationfieldsref) =
13526: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 13527: } elsif ($context eq 'requestauthor') {
13528: @usertools = ('author');
13529: %titles = &authorrequest_titles();
1.86 raeburn 13530: } else {
1.413 raeburn 13531: @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 13532: %titles = &tool_titles();
1.86 raeburn 13533: }
1.212 raeburn 13534: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 13535: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 13536: foreach my $key (keys(%env)) {
1.101 raeburn 13537: if ($context eq 'requestcourses') {
13538: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
13539: my $item = $1;
13540: my $type = $2;
13541: if ($type =~ /^limit_(.+)/) {
13542: $limithash{$item}{$1} = $env{$key};
13543: } else {
13544: $confhash{$item}{$type} = $env{$key};
13545: }
13546: }
1.163 raeburn 13547: } elsif ($context eq 'requestauthor') {
13548: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
13549: $confhash{$1} = $env{$key};
13550: }
1.101 raeburn 13551: } else {
1.86 raeburn 13552: if ($key =~ /^form\.quota_(.+)$/) {
13553: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 13554: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
13555: $confhash{'authorquota'}{$1} = $env{$key};
13556: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 13557: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
13558: }
1.72 raeburn 13559: }
13560: }
1.163 raeburn 13561: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 13562: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 13563: @approvalnotify = sort(@approvalnotify);
13564: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 13565: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 13566: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
13567: foreach my $type (@hasuniquecode) {
13568: if (grep(/^\Q$type\E$/,@crstypes)) {
13569: $confhash{'uniquecode'}{$type} = 1;
13570: }
1.216 raeburn 13571: }
1.242 raeburn 13572: my (%newbook,%allpos);
1.216 raeburn 13573: if ($context eq 'requestcourses') {
1.242 raeburn 13574: foreach my $type ('textbooks','templates') {
13575: @{$allpos{$type}} = ();
13576: my $invalid;
13577: if ($type eq 'textbooks') {
13578: $invalid = &mt('Invalid LON-CAPA course for textbook');
13579: } else {
13580: $invalid = &mt('Invalid LON-CAPA course for template');
13581: }
13582: if ($env{'form.'.$type.'_addbook'}) {
13583: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
13584: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
13585: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
13586: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
13587: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
13588: } else {
13589: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
13590: my $position = $env{'form.'.$type.'_addbook_pos'};
13591: $position =~ s/\D+//g;
13592: if ($position ne '') {
13593: $allpos{$type}[$position] = $newbook{$type};
13594: }
1.216 raeburn 13595: }
1.242 raeburn 13596: } else {
13597: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 13598: }
13599: }
1.242 raeburn 13600: }
1.216 raeburn 13601: }
1.102 raeburn 13602: if (ref($domconfig{$action}) eq 'HASH') {
13603: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
13604: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
13605: $changes{'notify'}{'approval'} = 1;
13606: }
13607: } else {
1.144 raeburn 13608: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13609: $changes{'notify'}{'approval'} = 1;
13610: }
13611: }
1.218 raeburn 13612: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
13613: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13614: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
13615: unless ($confhash{'uniquecode'}{$crstype}) {
13616: $changes{'uniquecode'} = 1;
13617: }
13618: }
13619: unless ($changes{'uniquecode'}) {
13620: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
13621: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
13622: $changes{'uniquecode'} = 1;
13623: }
13624: }
13625: }
13626: } else {
13627: $changes{'uniquecode'} = 1;
13628: }
13629: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
13630: $changes{'uniquecode'} = 1;
1.216 raeburn 13631: }
13632: if ($context eq 'requestcourses') {
1.242 raeburn 13633: foreach my $type ('textbooks','templates') {
13634: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13635: my %deletions;
13636: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
13637: if (@todelete) {
13638: map { $deletions{$_} = 1; } @todelete;
13639: }
13640: my %imgdeletions;
13641: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
13642: if (@todeleteimages) {
13643: map { $imgdeletions{$_} = 1; } @todeleteimages;
13644: }
13645: my $maxnum = $env{'form.'.$type.'_maxnum'};
13646: for (my $i=0; $i<=$maxnum; $i++) {
13647: my $itemid = $env{'form.'.$type.'_id_'.$i};
13648: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13649: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13650: if ($deletions{$key}) {
13651: if ($domconfig{$action}{$type}{$key}{'image'}) {
13652: #FIXME need to obsolete item in RES space
13653: }
13654: next;
13655: } else {
13656: my $newpos = $env{'form.'.$itemid};
13657: $newpos =~ s/\D+//g;
1.243 raeburn 13658: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 13659: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 13660: ($type eq 'templates'));
1.242 raeburn 13661: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13662: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13663: $changes{$type}{$key} = 1;
13664: }
13665: }
13666: $allpos{$type}[$newpos] = $key;
13667: }
13668: if ($imgdeletions{$key}) {
13669: $changes{$type}{$key} = 1;
1.216 raeburn 13670: #FIXME need to obsolete item in RES space
1.242 raeburn 13671: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13672: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 13673: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13674: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13675: } else {
13676: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13677: $cdom,$cnum,$type,$configuserok,
13678: $switchserver,$author_ok);
13679: if ($imgurl) {
13680: $confhash{$type}{$key}{'image'} = $imgurl;
13681: $changes{$type}{$key} = 1;
13682: }
13683: if ($error) {
13684: &Apache::lonnet::logthis($error);
13685: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13686: }
13687: }
1.242 raeburn 13688: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13689: $confhash{$type}{$key}{'image'} =
13690: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 13691: }
13692: }
13693: }
13694: }
13695: }
13696: }
1.102 raeburn 13697: } else {
1.144 raeburn 13698: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13699: $changes{'notify'}{'approval'} = 1;
13700: }
1.218 raeburn 13701: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 13702: $changes{'uniquecode'} = 1;
13703: }
13704: }
13705: if ($context eq 'requestcourses') {
1.242 raeburn 13706: foreach my $type ('textbooks','templates') {
13707: if ($newbook{$type}) {
13708: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 13709: foreach my $item ('subject','title','publisher','author') {
13710: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13711: ($type eq 'template'));
1.242 raeburn 13712: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13713: if ($env{'form.'.$type.'_addbook_'.$item}) {
13714: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13715: }
13716: }
13717: if ($type eq 'textbooks') {
13718: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13719: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 13720: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13721: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13722: } else {
13723: my ($imageurl,$error) =
13724: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13725: $configuserok,$switchserver,$author_ok);
13726: if ($imageurl) {
13727: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13728: }
13729: if ($error) {
13730: &Apache::lonnet::logthis($error);
13731: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13732: }
1.242 raeburn 13733: }
13734: }
1.216 raeburn 13735: }
13736: }
1.242 raeburn 13737: if (@{$allpos{$type}} > 0) {
13738: my $idx = 0;
13739: foreach my $item (@{$allpos{$type}}) {
13740: if ($item ne '') {
13741: $confhash{$type}{$item}{'order'} = $idx;
13742: if (ref($domconfig{$action}) eq 'HASH') {
13743: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13744: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13745: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13746: $changes{$type}{$item} = 1;
13747: }
1.216 raeburn 13748: }
13749: }
13750: }
1.242 raeburn 13751: $idx ++;
1.216 raeburn 13752: }
13753: }
13754: }
13755: }
1.235 raeburn 13756: if (ref($validationitemsref) eq 'ARRAY') {
13757: foreach my $item (@{$validationitemsref}) {
13758: if ($item eq 'fields') {
13759: my @changed;
13760: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13761: if (@{$confhash{'validation'}{$item}} > 0) {
13762: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13763: }
1.266 raeburn 13764: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13765: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13766: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13767: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13768: $domconfig{'requestcourses'}{'validation'}{$item});
13769: } else {
13770: @changed = @{$confhash{'validation'}{$item}};
13771: }
1.235 raeburn 13772: } else {
13773: @changed = @{$confhash{'validation'}{$item}};
13774: }
13775: } else {
13776: @changed = @{$confhash{'validation'}{$item}};
13777: }
13778: if (@changed) {
13779: if ($confhash{'validation'}{$item}) {
13780: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13781: } else {
13782: $changes{'validation'}{$item} = &mt('None');
13783: }
13784: }
13785: } else {
13786: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13787: if ($item eq 'markup') {
13788: if ($env{'form.requestcourses_validation_'.$item}) {
13789: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13790: }
13791: }
1.266 raeburn 13792: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13793: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13794: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13795: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13796: }
13797: } else {
13798: if ($confhash{'validation'}{$item} ne '') {
13799: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13800: }
1.235 raeburn 13801: }
13802: } else {
13803: if ($confhash{'validation'}{$item} ne '') {
13804: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13805: }
13806: }
13807: }
13808: }
13809: }
13810: if ($env{'form.validationdc'}) {
13811: my $newval = $env{'form.validationdc'};
1.285 raeburn 13812: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 13813: if (exists($domcoords{$newval})) {
13814: $confhash{'validation'}{'dc'} = $newval;
13815: }
13816: }
13817: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 13818: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13819: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13820: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13821: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13822: if ($confhash{'validation'}{'dc'} eq '') {
13823: $changes{'validation'}{'dc'} = &mt('None');
13824: } else {
13825: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13826: }
1.235 raeburn 13827: }
1.266 raeburn 13828: } elsif ($confhash{'validation'}{'dc'} ne '') {
13829: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 13830: }
13831: } elsif ($confhash{'validation'}{'dc'} ne '') {
13832: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13833: }
13834: } elsif ($confhash{'validation'}{'dc'} ne '') {
13835: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 13836: }
1.266 raeburn 13837: } else {
13838: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13839: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13840: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13841: $changes{'validation'}{'dc'} = &mt('None');
13842: }
13843: }
1.235 raeburn 13844: }
13845: }
1.102 raeburn 13846: }
13847: } else {
1.86 raeburn 13848: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 13849: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 13850: }
1.72 raeburn 13851: foreach my $item (@usertools) {
13852: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13853: my $unset;
1.101 raeburn 13854: if ($context eq 'requestcourses') {
1.104 raeburn 13855: $unset = '0';
13856: if ($type eq '_LC_adv') {
13857: $unset = '';
13858: }
1.101 raeburn 13859: if ($confhash{$item}{$type} eq 'autolimit') {
13860: $confhash{$item}{$type} .= '=';
13861: unless ($limithash{$item}{$type} =~ /\D/) {
13862: $confhash{$item}{$type} .= $limithash{$item}{$type};
13863: }
13864: }
1.163 raeburn 13865: } elsif ($context eq 'requestauthor') {
13866: $unset = '0';
13867: if ($type eq '_LC_adv') {
13868: $unset = '';
13869: }
1.72 raeburn 13870: } else {
1.101 raeburn 13871: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13872: $confhash{$item}{$type} = 1;
13873: } else {
13874: $confhash{$item}{$type} = 0;
13875: }
1.72 raeburn 13876: }
1.86 raeburn 13877: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 13878: if ($action eq 'requestauthor') {
13879: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13880: $changes{$type} = 1;
13881: }
13882: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13883: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13884: $changes{$item}{$type} = 1;
13885: }
13886: } else {
13887: if ($context eq 'requestcourses') {
1.104 raeburn 13888: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13889: $changes{$item}{$type} = 1;
13890: }
13891: } else {
13892: if (!$confhash{$item}{$type}) {
13893: $changes{$item}{$type} = 1;
13894: }
13895: }
13896: }
13897: } else {
13898: if ($context eq 'requestcourses') {
1.104 raeburn 13899: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13900: $changes{$item}{$type} = 1;
13901: }
1.163 raeburn 13902: } elsif ($context eq 'requestauthor') {
13903: if ($confhash{$type} ne $unset) {
13904: $changes{$type} = 1;
13905: }
1.72 raeburn 13906: } else {
13907: if (!$confhash{$item}{$type}) {
13908: $changes{$item}{$type} = 1;
13909: }
13910: }
13911: }
1.1 raeburn 13912: }
13913: }
1.163 raeburn 13914: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13915: if (ref($domconfig{'quotas'}) eq 'HASH') {
13916: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13917: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13918: if (exists($confhash{'defaultquota'}{$key})) {
13919: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13920: $changes{'defaultquota'}{$key} = 1;
13921: }
13922: } else {
13923: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13924: }
13925: }
1.86 raeburn 13926: } else {
13927: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13928: if (exists($confhash{'defaultquota'}{$key})) {
13929: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13930: $changes{'defaultquota'}{$key} = 1;
13931: }
13932: } else {
13933: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13934: }
1.1 raeburn 13935: }
13936: }
1.197 raeburn 13937: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13938: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
13939: if (exists($confhash{'authorquota'}{$key})) {
13940: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
13941: $changes{'authorquota'}{$key} = 1;
13942: }
13943: } else {
13944: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
13945: }
13946: }
13947: }
1.1 raeburn 13948: }
1.86 raeburn 13949: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13950: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13951: if (ref($domconfig{'quotas'}) eq 'HASH') {
13952: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13953: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13954: $changes{'defaultquota'}{$key} = 1;
13955: }
13956: } else {
13957: if (!exists($domconfig{'quotas'}{$key})) {
13958: $changes{'defaultquota'}{$key} = 1;
13959: }
1.72 raeburn 13960: }
13961: } else {
1.86 raeburn 13962: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13963: }
1.1 raeburn 13964: }
13965: }
1.197 raeburn 13966: if (ref($confhash{'authorquota'}) eq 'HASH') {
13967: foreach my $key (keys(%{$confhash{'authorquota'}})) {
13968: if (ref($domconfig{'quotas'}) eq 'HASH') {
13969: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
13970: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
13971: $changes{'authorquota'}{$key} = 1;
13972: }
13973: } else {
13974: $changes{'authorquota'}{$key} = 1;
13975: }
13976: } else {
13977: $changes{'authorquota'}{$key} = 1;
13978: }
13979: }
13980: }
1.1 raeburn 13981: }
1.72 raeburn 13982:
1.163 raeburn 13983: if ($context eq 'requestauthor') {
13984: $domdefaults{'requestauthor'} = \%confhash;
13985: } else {
13986: foreach my $key (keys(%confhash)) {
1.242 raeburn 13987: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 13988: $domdefaults{$key} = $confhash{$key};
13989: }
1.163 raeburn 13990: }
1.72 raeburn 13991: }
1.163 raeburn 13992:
1.1 raeburn 13993: my %quotahash = (
1.86 raeburn 13994: $action => { %confhash }
1.1 raeburn 13995: );
13996: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13997: $dom);
13998: if ($putresult eq 'ok') {
13999: if (keys(%changes) > 0) {
1.72 raeburn 14000: my $cachetime = 24*60*60;
14001: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14002: if (ref($lastactref) eq 'HASH') {
14003: $lastactref->{'domdefaults'} = 1;
14004: }
1.1 raeburn 14005: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14006: unless (($context eq 'requestcourses') ||
1.163 raeburn 14007: ($context eq 'requestauthor')) {
1.86 raeburn 14008: if (ref($changes{'defaultquota'}) eq 'HASH') {
14009: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14010: foreach my $type (@{$types},'default') {
14011: if (defined($changes{'defaultquota'}{$type})) {
14012: my $typetitle = $usertypes->{$type};
14013: if ($type eq 'default') {
14014: $typetitle = $othertitle;
14015: }
1.213 raeburn 14016: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14017: }
14018: }
1.86 raeburn 14019: $resulttext .= '</ul></li>';
1.72 raeburn 14020: }
1.197 raeburn 14021: if (ref($changes{'authorquota'}) eq 'HASH') {
1.223 bisitz 14022: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.197 raeburn 14023: foreach my $type (@{$types},'default') {
14024: if (defined($changes{'authorquota'}{$type})) {
14025: my $typetitle = $usertypes->{$type};
14026: if ($type eq 'default') {
14027: $typetitle = $othertitle;
14028: }
1.213 raeburn 14029: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.197 raeburn 14030: }
14031: }
14032: $resulttext .= '</ul></li>';
14033: }
1.72 raeburn 14034: }
1.80 raeburn 14035: my %newenv;
1.72 raeburn 14036: foreach my $item (@usertools) {
1.163 raeburn 14037: my (%haschgs,%inconf);
14038: if ($context eq 'requestauthor') {
14039: %haschgs = %changes;
1.210 raeburn 14040: %inconf = %confhash;
1.163 raeburn 14041: } else {
14042: if (ref($changes{$item}) eq 'HASH') {
14043: %haschgs = %{$changes{$item}};
14044: }
14045: if (ref($confhash{$item}) eq 'HASH') {
14046: %inconf = %{$confhash{$item}};
14047: }
14048: }
14049: if (keys(%haschgs) > 0) {
1.80 raeburn 14050: my $newacc =
14051: &Apache::lonnet::usertools_access($env{'user.name'},
14052: $env{'user.domain'},
1.86 raeburn 14053: $item,'reload',$context);
1.210 raeburn 14054: if (($context eq 'requestcourses') ||
1.163 raeburn 14055: ($context eq 'requestauthor')) {
1.108 raeburn 14056: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14057: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14058: }
14059: } else {
14060: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14061: $newenv{'environment.availabletools.'.$item} = $newacc;
14062: }
1.80 raeburn 14063: }
1.163 raeburn 14064: unless ($context eq 'requestauthor') {
14065: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14066: }
1.72 raeburn 14067: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14068: if ($haschgs{$type}) {
1.72 raeburn 14069: my $typetitle = $usertypes->{$type};
14070: if ($type eq 'default') {
14071: $typetitle = $othertitle;
14072: } elsif ($type eq '_LC_adv') {
14073: $typetitle = 'LON-CAPA Advanced Users';
14074: }
1.163 raeburn 14075: if ($inconf{$type}) {
1.101 raeburn 14076: if ($context eq 'requestcourses') {
14077: my $cond;
1.163 raeburn 14078: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14079: if ($1 eq '') {
14080: $cond = &mt('(Automatic processing of any request).');
14081: } else {
14082: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14083: }
14084: } else {
1.163 raeburn 14085: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14086: }
14087: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14088: } elsif ($context eq 'requestauthor') {
14089: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14090: $titles{$inconf{$type}},$typetitle);
14091:
1.101 raeburn 14092: } else {
14093: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14094: }
1.72 raeburn 14095: } else {
1.104 raeburn 14096: if ($type eq '_LC_adv') {
1.163 raeburn 14097: if ($inconf{$type} eq '0') {
1.104 raeburn 14098: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14099: } else {
14100: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14101: }
14102: } else {
14103: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14104: }
1.72 raeburn 14105: }
14106: }
1.26 raeburn 14107: }
1.163 raeburn 14108: unless ($context eq 'requestauthor') {
14109: $resulttext .= '</ul></li>';
14110: }
1.26 raeburn 14111: }
1.1 raeburn 14112: }
1.163 raeburn 14113: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14114: if (ref($changes{'notify'}) eq 'HASH') {
14115: if ($changes{'notify'}{'approval'}) {
14116: if (ref($confhash{'notify'}) eq 'HASH') {
14117: if ($confhash{'notify'}{'approval'}) {
14118: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14119: } else {
1.163 raeburn 14120: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14121: }
14122: }
14123: }
14124: }
14125: }
1.216 raeburn 14126: if ($action eq 'requestcourses') {
14127: my @offon = ('off','on');
14128: if ($changes{'uniquecode'}) {
1.218 raeburn 14129: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14130: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14131: $resulttext .= '<li>'.
14132: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14133: '</li>';
14134: } else {
14135: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14136: '</li>';
14137: }
1.216 raeburn 14138: }
1.242 raeburn 14139: foreach my $type ('textbooks','templates') {
14140: if (ref($changes{$type}) eq 'HASH') {
14141: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14142: foreach my $key (sort(keys(%{$changes{$type}}))) {
14143: my %coursehash = &Apache::lonnet::coursedescription($key);
14144: my $coursetitle = $coursehash{'description'};
14145: my $position = $confhash{$type}{$key}{'order'} + 1;
14146: $resulttext .= '<li>';
1.243 raeburn 14147: foreach my $item ('subject','title','publisher','author') {
14148: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14149: ($type eq 'templates'));
1.242 raeburn 14150: my $name = $item.':';
14151: $name =~ s/^(\w)/\U$1/;
14152: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14153: }
14154: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14155: if ($type eq 'textbooks') {
14156: if ($confhash{$type}{$key}{'image'}) {
14157: $resulttext .= ' '.&mt('Image: [_1]',
14158: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14159: ' alt="Textbook cover" />').'<br />';
14160: }
14161: }
14162: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14163: }
1.242 raeburn 14164: $resulttext .= '</ul></li>';
1.216 raeburn 14165: }
14166: }
1.235 raeburn 14167: if (ref($changes{'validation'}) eq 'HASH') {
14168: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14169: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14170: foreach my $item (@{$validationitemsref}) {
14171: if (exists($changes{'validation'}{$item})) {
14172: if ($item eq 'markup') {
14173: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14174: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14175: } else {
14176: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14177: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14178: }
14179: }
14180: }
14181: if (exists($changes{'validation'}{'dc'})) {
14182: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14183: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14184: }
14185: }
14186: }
1.216 raeburn 14187: }
1.1 raeburn 14188: $resulttext .= '</ul>';
1.80 raeburn 14189: if (keys(%newenv)) {
14190: &Apache::lonnet::appenv(\%newenv);
14191: }
1.1 raeburn 14192: } else {
1.86 raeburn 14193: if ($context eq 'requestcourses') {
14194: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14195: } elsif ($context eq 'requestauthor') {
14196: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14197: } else {
1.90 weissno 14198: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14199: }
1.1 raeburn 14200: }
14201: } else {
1.11 albertel 14202: $resulttext = '<span class="LC_error">'.
14203: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14204: }
1.216 raeburn 14205: if ($errors) {
14206: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14207: '<ul>'.$errors.'</ul></p>';
14208: }
1.3 raeburn 14209: return $resulttext;
1.1 raeburn 14210: }
14211:
1.216 raeburn 14212: sub process_textbook_image {
1.242 raeburn 14213: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14214: my $filename = $env{'form.'.$caller.'.filename'};
14215: my ($error,$url);
14216: my ($width,$height) = (50,50);
14217: if ($configuserok eq 'ok') {
14218: if ($switchserver) {
14219: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14220: $switchserver);
14221: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14222: my $modified = [];
1.216 raeburn 14223: my ($result,$imageurl) =
1.421 raeburn 14224: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14225: "$type/$cdom/$cnum/cover",$width,$height,
14226: '',$modified);
1.216 raeburn 14227: if ($result eq 'ok') {
14228: $url = $imageurl;
1.421 raeburn 14229: &update_modify_urls($r,$modified);
1.216 raeburn 14230: } else {
14231: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14232: }
14233: } else {
14234: $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);
14235: }
14236: } else {
14237: $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);
14238: }
14239: return ($url,$error);
14240: }
14241:
1.267 raeburn 14242: sub modify_ltitools {
14243: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14244: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14245: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14246:
1.267 raeburn 14247: my $confname = $dom.'-domainconfig';
14248: my $servadm = $r->dir_config('lonAdmEMail');
14249: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14250:
14251: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14252: my $toolserror =
14253: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14254: $lastactref,$configuserok,$switchserver,$author_ok);
14255:
14256: my $home = &Apache::lonnet::domain($dom,'primary');
14257: unless (($home eq 'no_host') || ($home eq '')) {
14258: my @ids=&Apache::lonnet::current_machine_ids();
14259: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14260: }
14261:
14262: if (keys(%ltitoolschg)) {
14263: foreach my $id (keys(%ltitoolschg)) {
14264: if (ref($ltitoolschg{$id}) eq 'HASH') {
14265: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14266: if (($inner eq 'secret') || ($inner eq 'key')) {
14267: if ($is_home) {
14268: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14269: }
14270: }
14271: }
1.267 raeburn 14272: }
1.421 raeburn 14273: }
14274: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14275: if (keys(%ltitoolschg)) {
14276: %newltitools = %ltitoolschg;
14277: }
14278: }
14279: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14280: foreach my $id (%{$domconfig{'ltitools'}}) {
14281: next if ($id !~ /^\d+$/);
14282: unless (exists($ltitoolschg{$id})) {
14283: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14284: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14285: if (($inner eq 'secret') || ($inner eq 'key')) {
14286: if ($is_home) {
14287: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14288: }
14289: } else {
14290: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14291: }
14292: }
14293: } else {
14294: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14295: }
1.421 raeburn 14296: }
14297: }
14298: }
14299: if ($toolserror) {
14300: $errors = '<li>'.$toolserror.'</li>';
14301: }
14302: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14303: $resulttext = &mt('No changes made.');
14304: if ($errors) {
14305: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14306: $errors.'</ul>';
14307: }
14308: return $resulttext;
14309: }
14310: my %ltitoolshash = (
14311: $action => { %newltitools }
14312: );
14313: if (keys(%secchanges)) {
14314: $ltitoolshash{'toolsec'} = \%newtoolsec;
14315: }
14316: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14317: if ($putresult eq 'ok') {
14318: my %keystore;
14319: if ($is_home) {
14320: my %toolsenchash = (
14321: $action => { %newtoolsenc }
14322: );
14323: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14324: my $cachetime = 24*60*60;
14325: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14326: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14327: }
14328: $resulttext = &mt('Changes made:').'<ul>';
14329: if (keys(%secchanges) > 0) {
1.423 raeburn 14330: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14331: }
14332: if (keys(%ltitoolschg) > 0) {
14333: $resulttext .= $ltitoolsoutput;
14334: }
1.423 raeburn 14335: my $cachetime = 24*60*60;
14336: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14337: if (ref($lastactref) eq 'HASH') {
14338: $lastactref->{'ltitools'} = 1;
14339: }
1.421 raeburn 14340: } else {
14341: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14342: }
14343: if ($errors) {
14344: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14345: $errors.'</ul></p>';
14346: }
14347: return $resulttext;
14348: }
14349:
14350: sub fetch_secrets {
14351: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14352: my %keyset;
14353: %{$currsec} = ();
14354: $newsec->{'private'}{'keys'} = [];
14355: $newsec->{'encrypt'} = {};
14356: $newsec->{'rules'} = {};
14357: if ($context eq 'ltisec') {
14358: $newsec->{'linkprot'} = {};
14359: }
14360: if (ref($domconfig->{$context}) eq 'HASH') {
14361: %{$currsec} = %{$domconfig->{$context}};
14362: if ($context eq 'ltisec') {
14363: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14364: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14365: unless ($id =~ /^\d+$/) {
14366: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14367: }
1.267 raeburn 14368: }
14369: }
1.421 raeburn 14370: }
14371: if (ref($currsec->{'private'}) eq 'HASH') {
14372: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14373: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14374: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14375: }
1.421 raeburn 14376: }
14377: }
14378: my @items= ('crs','dom');
14379: if ($context eq 'ltisec') {
14380: push(@items,'consumers');
14381: }
14382: foreach my $item (@items) {
14383: my $formelement;
14384: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14385: $formelement = 'form.'.$context.'_'.$item;
14386: } else {
14387: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14388: }
14389: if ($env{$formelement}) {
14390: $newsec->{'encrypt'}{$item} = 1;
14391: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14392: unless ($currsec->{'encrypt'}{$item}) {
14393: $secchanges->{'encrypt'} = 1;
14394: }
14395: } else {
14396: $secchanges->{'encrypt'} = 1;
1.267 raeburn 14397: }
1.421 raeburn 14398: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
14399: if ($currsec->{'encrypt'}{$item}) {
14400: $secchanges->{'encrypt'} = 1;
1.323 raeburn 14401: }
1.421 raeburn 14402: }
14403: }
14404: my $secrets;
14405: if ($context eq 'ltisec') {
14406: $secrets = 'ltisecrets';
14407: } else {
14408: $secrets = 'toolsecrets';
14409: }
14410: unless (exists($currsec->{'rules'})) {
14411: $currsec->{'rules'} = {};
14412: }
14413: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
14414:
14415: my @ids=&Apache::lonnet::current_machine_ids();
14416: my %servers = &Apache::lonnet::get_servers($dom,'library');
14417:
14418: foreach my $hostid (keys(%servers)) {
14419: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
14420: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
14421: if (exists($env{$keyitem})) {
14422: $env{$keyitem} =~ s/(`)/'/g;
14423: if ($keyset{$hostid}) {
14424: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
14425: if ($env{$keyitem} ne '') {
14426: $secchanges->{'private'} = 1;
14427: $newkeyset->{$hostid} = $env{$keyitem};
14428: }
1.296 raeburn 14429: }
1.421 raeburn 14430: } elsif ($env{$keyitem} ne '') {
14431: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
14432: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 14433: }
1.421 raeburn 14434: $secchanges->{'private'} = 1;
14435: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 14436: }
14437: }
1.421 raeburn 14438: }
14439: }
14440: }
14441:
14442: sub store_security {
1.424 ! raeburn 14443: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 14444: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
14445: (ref($keystore) eq 'HASH'));
14446: if (keys(%{$secchanges})) {
14447: if ($secchanges->{'private'}) {
14448: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
14449: foreach my $hostid (keys(%{$newkeyset})) {
14450: my $storehash = {
14451: key => $newkeyset->{$hostid},
14452: who => $env{'user.name'}.':'.$env{'user.domain'},
14453: };
14454: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
14455: $dom,$hostid);
14456: }
14457: }
14458: }
14459: }
14460:
14461: sub lti_security_results {
1.423 raeburn 14462: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 14463: my $output;
1.423 raeburn 14464: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
14465: my $needs_update;
1.421 raeburn 14466: foreach my $item (keys(%{$secchanges})) {
14467: if ($item eq 'encrypt') {
1.423 raeburn 14468: $needs_update = 1;
1.421 raeburn 14469: my %encrypted;
14470: if ($context eq 'lti') {
14471: %encrypted = (
14472: crs => {
14473: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
14474: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
14475: },
14476: dom => {
14477: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
14478: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
14479: },
14480: consumers => {
14481: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
14482: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
14483: },
14484: );
1.267 raeburn 14485: } else {
1.421 raeburn 14486: %encrypted = (
14487: crs => {
14488: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
14489: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
14490: },
14491: dom => {
14492: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
14493: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
14494: },
14495: );
14496:
14497: }
14498: my @types= ('crs','dom');
14499: if ($context eq 'lti') {
1.423 raeburn 14500: foreach my $type (@types) {
14501: undef($domdefaults{'linkprotenc_'.$type});
14502: }
1.421 raeburn 14503: push(@types,'consumers');
1.423 raeburn 14504: undef($domdefaults{'ltienc_consumers'});
14505: } elsif ($context eq 'ltitools') {
14506: foreach my $type (@types) {
14507: undef($domdefaults{'toolenc_'.$type});
14508: }
1.267 raeburn 14509: }
1.421 raeburn 14510: foreach my $type (@types) {
14511: my $shown = $encrypted{$type}{'off'};
14512: if (ref($newsec->{$item}) eq 'HASH') {
14513: if ($newsec->{$item}{$type}) {
1.423 raeburn 14514: if ($context eq 'lti') {
14515: if ($type eq 'consumers') {
14516: $domdefaults{'ltienc_consumers'} = 1;
14517: } else {
14518: $domdefaults{'linkprotenc_'.$type} = 1;
14519: }
14520: } elsif ($context eq 'ltitools') {
14521: $domdefaults{'toolenc_'.$type} = 1;
14522: }
1.421 raeburn 14523: $shown = $encrypted{$type}{'on'};
1.319 raeburn 14524: }
1.267 raeburn 14525: }
1.421 raeburn 14526: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 14527: }
1.421 raeburn 14528: } elsif ($item eq 'rules') {
14529: my %titles = &Apache::lonlocal::texthash(
14530: min => 'Minimum password length',
14531: max => 'Maximum password length',
14532: chars => 'Required characters',
14533: );
14534: foreach my $rule ('min','max') {
14535: if ($newsec->{rules}{$rule} eq '') {
14536: if ($rule eq 'min') {
14537: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
14538: ' '.&mt('Default of [_1] will be used',
14539: $Apache::lonnet::passwdmin).'</li>';
14540: } else {
14541: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
14542: }
14543: } else {
14544: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
14545: }
14546: }
14547: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
14548: if (@{$newsec->{'rules'}{'chars'}} > 0) {
14549: my %rulenames = &Apache::lonlocal::texthash(
14550: uc => 'At least one upper case letter',
14551: lc => 'At least one lower case letter',
14552: num => 'At least one number',
14553: spec => 'At least one non-alphanumeric',
14554: );
14555: my $needed = '<ul><li>'.
14556: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
14557: '</li></ul>';
14558: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
14559: } else {
14560: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 14561: }
1.421 raeburn 14562: } else {
14563: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 14564: }
1.421 raeburn 14565: } elsif ($item eq 'private') {
1.423 raeburn 14566: $needs_update = 1;
14567: if ($context eq 'lti') {
14568: undef($domdefaults{'ltiprivhosts'});
14569: } elsif ($context eq 'ltitools') {
14570: undef($domdefaults{'toolprivhosts'});
14571: }
1.421 raeburn 14572: if (keys(%{$newkeyset})) {
1.423 raeburn 14573: my @privhosts;
1.421 raeburn 14574: foreach my $hostid (sort(keys(%{$newkeyset}))) {
14575: if ($keystore->{$hostid} eq 'ok') {
14576: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 14577: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
14578: push(@privhosts,$hostid);
14579: }
14580: }
14581: }
14582: if (@privhosts) {
14583: if ($context eq 'lti') {
14584: $domdefaults{'ltiprivhosts'} = \@privhosts;
14585: } elsif ($context eq 'ltitools') {
14586: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 14587: }
14588: }
14589: }
1.421 raeburn 14590: } elsif ($item eq 'linkprot') {
14591: next;
1.267 raeburn 14592: }
14593: }
1.423 raeburn 14594: if ($needs_update) {
14595: my $cachetime = 24*60*60;
14596: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
14597: }
1.421 raeburn 14598: return $output;
14599: }
14600:
14601: sub modify_proctoring {
14602: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14603: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
14604: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
14605: my $confname = $dom.'-domainconfig';
14606: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 14607: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14608: my %providernames = &proctoring_providernames();
14609: my $maxnum = scalar(keys(%providernames));
14610:
14611: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
14612: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
14613: if (ref($requref) eq 'HASH') {
14614: %requserfields = %{$requref};
14615: }
14616: if (ref($opturef) eq 'HASH') {
14617: %optuserfields = %{$opturef};
14618: }
14619: if (ref($defref) eq 'HASH') {
14620: %defaults = %{$defref};
14621: }
14622: if (ref($extref) eq 'HASH') {
14623: %extended = %{$extref};
14624: }
14625: if (ref($crsref) eq 'HASH') {
14626: %crsconf = %{$crsref};
14627: }
14628: if (ref($rolesref) eq 'ARRAY') {
14629: @courseroles = @{$rolesref};
14630: }
14631: if (ref($ltiref) eq 'ARRAY') {
14632: @ltiroles = @{$ltiref};
14633: }
14634:
14635: if (ref($domconfig{$action}) eq 'HASH') {
14636: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
14637: if (@todeleteimages) {
14638: map { $imgdeletions{$_} = 1; } @todeleteimages;
14639: }
14640: }
14641: my %customadds;
14642: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
14643: if (@newcustom) {
14644: map { $customadds{$_} = 1; } @newcustom;
14645: }
14646: foreach my $provider (sort(keys(%providernames))) {
14647: $confhash{$provider} = {};
14648: my $pos = $env{'form.proctoring_pos_'.$provider};
14649: $pos =~ s/\D+//g;
14650: $allpos[$pos] = $provider;
14651: my (%current,%currentenc);
14652: my $showroles = 0;
14653: if (ref($domconfig{$action}) eq 'HASH') {
14654: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14655: %current = %{$domconfig{$action}{$provider}};
14656: foreach my $item ('key','secret') {
14657: $currentenc{$item} = $current{$item};
14658: delete($current{$item});
14659: }
14660: }
14661: }
14662: if ($env{'form.proctoring_available_'.$provider}) {
14663: $confhash{$provider}{'available'} = 1;
14664: unless ($current{'available'}) {
14665: $changes{$provider} = 1;
14666: }
14667: } else {
14668: %{$confhash{$provider}} = %current;
14669: %{$encconfhash{$provider}} = %currentenc;
14670: $confhash{$provider}{'available'} = 0;
14671: if ($current{'available'}) {
14672: $changes{$provider} = 1;
14673: }
14674: }
14675: if ($confhash{$provider}{'available'}) {
14676: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
14677: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
14678: if ($field eq 'lifetime') {
14679: if ($possval =~ /^\d+$/) {
14680: $confhash{$provider}{$field} = $possval;
14681: }
14682: } elsif ($field eq 'version') {
14683: if ($possval =~ /^\d+\.\d+$/) {
14684: $confhash{$provider}{$field} = $possval;
14685: }
14686: } elsif ($field eq 'sigmethod') {
14687: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
14688: $confhash{$provider}{$field} = $possval;
14689: }
14690: } elsif ($field eq 'url') {
14691: $confhash{$provider}{$field} = $possval;
14692: } elsif (($field eq 'key') || ($field eq 'secret')) {
14693: $encconfhash{$provider}{$field} = $possval;
14694: unless ($currentenc{$field} eq $possval) {
14695: $changes{$provider} = 1;
14696: }
14697: }
14698: unless (($field eq 'key') || ($field eq 'secret')) {
14699: unless ($current{$field} eq $confhash{$provider}{$field}) {
14700: $changes{$provider} = 1;
14701: }
14702: }
14703: }
14704: if ($imgdeletions{$provider}) {
14705: $changes{$provider} = 1;
14706: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
14707: my ($imageurl,$error) =
14708: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
14709: $configuserok,$switchserver,$author_ok);
14710: if ($imageurl) {
14711: $confhash{$provider}{'image'} = $imageurl;
14712: $changes{$provider} = 1;
14713: }
14714: if ($error) {
14715: &Apache::lonnet::logthis($error);
14716: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14717: }
14718: } elsif (exists($current{'image'})) {
14719: $confhash{$provider}{'image'} = $current{'image'};
14720: }
14721: if (ref($requserfields{$provider}) eq 'ARRAY') {
14722: if (@{$requserfields{$provider}} > 0) {
14723: if (grep(/^user$/,@{$requserfields{$provider}})) {
14724: if ($env{'form.proctoring_userincdom_'.$provider}) {
14725: $confhash{$provider}{'incdom'} = 1;
14726: }
14727: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
14728: $changes{$provider} = 1;
14729: }
14730: }
14731: if (grep(/^roles$/,@{$requserfields{$provider}})) {
14732: $showroles = 1;
14733: }
14734: }
14735: }
14736: $confhash{$provider}{'fields'} = [];
14737: if (ref($optuserfields{$provider}) eq 'ARRAY') {
14738: if (@{$optuserfields{$provider}} > 0) {
14739: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
14740: foreach my $field (@{$optuserfields{$provider}}) {
14741: if (grep(/^\Q$field\E$/,@optfields)) {
14742: push(@{$confhash{$provider}{'fields'}},$field);
14743: }
14744: }
14745: }
14746: if (ref($current{'fields'}) eq 'ARRAY') {
14747: unless ($changes{$provider}) {
14748: my @new = sort(@{$confhash{$provider}{'fields'}});
14749: my @old = sort(@{$current{'fields'}});
14750: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14751: if (@diffs) {
14752: $changes{$provider} = 1;
14753: }
14754: }
14755: } elsif (@{$confhash{$provider}{'fields'}}) {
14756: $changes{$provider} = 1;
14757: }
14758: }
14759: if (ref($defaults{$provider}) eq 'ARRAY') {
14760: if (@{$defaults{$provider}} > 0) {
14761: my %options;
14762: if (ref($extended{$provider}) eq 'HASH') {
14763: %options = %{$extended{$provider}};
14764: }
14765: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
14766: foreach my $field (@{$defaults{$provider}}) {
14767: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
14768: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
14769: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
14770: push(@{$confhash{$provider}{'defaults'}},$poss);
14771: }
14772: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
14773: foreach my $inner (keys(%{$options{$field}})) {
14774: if (ref($options{$field}{$inner}) eq 'ARRAY') {
14775: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
14776: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
14777: $confhash{$provider}{'defaults'}{$inner} = $poss;
14778: }
14779: } else {
14780: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
14781: }
14782: }
14783: } else {
14784: if (grep(/^\Q$field\E$/,@checked)) {
14785: push(@{$confhash{$provider}{'defaults'}},$field);
14786: }
14787: }
14788: }
14789: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
14790: if (ref($current{'defaults'}) eq 'ARRAY') {
14791: unless ($changes{$provider}) {
14792: my @new = sort(@{$confhash{$provider}{'defaults'}});
14793: my @old = sort(@{$current{'defaults'}});
14794: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14795: if (@diffs) {
14796: $changes{$provider} = 1;
14797: }
14798: }
14799: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
14800: if (@{$current{'defaults'}}) {
14801: $changes{$provider} = 1;
14802: }
14803: }
14804: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
14805: if (ref($current{'defaults'}) eq 'HASH') {
14806: unless ($changes{$provider}) {
14807: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
14808: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
14809: $changes{$provider} = 1;
14810: last;
14811: }
14812: }
14813: }
14814: unless ($changes{$provider}) {
14815: foreach my $key (keys(%{$current{'defaults'}})) {
14816: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
14817: $changes{$provider} = 1;
14818: last;
14819: }
14820: }
14821: }
14822: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
14823: $changes{$provider} = 1;
14824: }
14825: }
14826: }
14827: }
14828: if (ref($crsconf{$provider}) eq 'ARRAY') {
14829: if (@{$crsconf{$provider}} > 0) {
14830: $confhash{$provider}{'crsconf'} = [];
14831: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
14832: foreach my $crsfield (@{$crsconf{$provider}}) {
14833: if (grep(/^\Q$crsfield\E$/,@checked)) {
14834: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
14835: }
14836: }
14837: if (ref($current{'crsconf'}) eq 'ARRAY') {
14838: unless ($changes{$provider}) {
14839: my @new = sort(@{$confhash{$provider}{'crsconf'}});
14840: my @old = sort(@{$current{'crsconf'}});
14841: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
14842: if (@diffs) {
14843: $changes{$provider} = 1;
14844: }
14845: }
14846: } elsif (@{$confhash{$provider}{'crsconf'}}) {
14847: $changes{$provider} = 1;
14848: }
14849: }
14850: }
14851: if ($showroles) {
14852: $confhash{$provider}{'roles'} = {};
14853: foreach my $role (@courseroles) {
14854: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
14855: if (grep(/^\Q$poss\E$/,@ltiroles)) {
14856: $confhash{$provider}{'roles'}{$role} = $poss;
14857: }
14858: }
14859: unless ($changes{$provider}) {
14860: if (ref($current{'roles'}) eq 'HASH') {
14861: foreach my $role (keys(%{$current{'roles'}})) {
14862: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
14863: $changes{$provider} = 1;
14864: last
14865: }
14866: }
14867: unless ($changes{$provider}) {
14868: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
14869: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
14870: $changes{$provider} = 1;
14871: last;
14872: }
14873: }
14874: }
14875: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
14876: $changes{$provider} = 1;
14877: }
14878: }
14879: }
14880: if (ref($current{'custom'}) eq 'HASH') {
14881: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
14882: foreach my $key (keys(%{$current{'custom'}})) {
14883: if (grep(/^\Q$key\E$/,@customdels)) {
14884: $changes{$provider} = 1;
14885: } else {
14886: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
14887: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
14888: $changes{$provider} = 1;
14889: }
14890: }
14891: }
14892: }
14893: if ($customadds{$provider}) {
14894: my $name = $env{'form.proctoring_custom_name_'.$provider};
14895: $name =~ s/(`)/'/g;
14896: $name =~ s/^\s+//;
14897: $name =~ s/\s+$//;
14898: my $value = $env{'form.proctoring_custom_value_'.$provider};
14899: $value =~ s/(`)/'/g;
14900: $value =~ s/^\s+//;
14901: $value =~ s/\s+$//;
14902: if ($name ne '') {
14903: $confhash{$provider}{'custom'}{$name} = $value;
14904: $changes{$provider} = 1;
14905: }
14906: }
14907: }
14908: }
14909: if (@allpos > 0) {
14910: my $idx = 0;
14911: foreach my $provider (@allpos) {
14912: if ($provider ne '') {
14913: $confhash{$provider}{'order'} = $idx;
14914: unless ($changes{$provider}) {
14915: if (ref($domconfig{$action}) eq 'HASH') {
14916: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
14917: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
14918: $changes{$provider} = 1;
14919: }
14920: }
14921: }
14922: }
14923: $idx ++;
14924: }
14925: }
14926: }
14927: my %proc_hash = (
14928: $action => { %confhash }
14929: );
14930: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
14931: $dom);
14932: if ($putresult eq 'ok') {
14933: my %proc_enchash = (
14934: $action => { %encconfhash }
14935: );
1.384 raeburn 14936: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 14937: if (keys(%changes) > 0) {
14938: my $cachetime = 24*60*60;
14939: my %procall = %confhash;
14940: foreach my $provider (keys(%procall)) {
14941: if (ref($encconfhash{$provider}) eq 'HASH') {
14942: foreach my $key ('key','secret') {
14943: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
14944: }
14945: }
14946: }
14947: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
14948: if (ref($lastactref) eq 'HASH') {
14949: $lastactref->{'proctoring'} = 1;
14950: }
14951: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
14952: my %bynum;
14953: foreach my $provider (sort(keys(%changes))) {
14954: my $position = $confhash{$provider}{'order'};
14955: $bynum{$position} = $provider;
14956: }
14957: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14958: my $provider = $bynum{$pos};
14959: my %lt = &proctoring_titles($provider);
14960: my %fieldtitles = &proctoring_fieldtitles($provider);
14961: if (!$confhash{$provider}{'available'}) {
14962: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
14963: } else {
14964: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
14965: if ($confhash{$provider}{'image'}) {
14966: $resulttext .= ' '.
14967: '<img src="'.$confhash{$provider}{'image'}.'"'.
14968: ' alt="'.&mt('Proctoring icon').'" />';
14969: }
14970: $resulttext .= '<ul>';
14971: my $position = $pos + 1;
14972: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14973: foreach my $key ('version','sigmethod','url','lifetime') {
14974: if ($confhash{$provider}{$key} ne '') {
14975: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
14976: }
14977: }
14978: if ($encconfhash{$provider}{'key'} ne '') {
14979: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
14980: }
14981: if ($encconfhash{$provider}{'secret'} ne '') {
14982: $resulttext .= '<li>'.$lt{'secret'}.': ';
14983: my $num = length($encconfhash{$provider}{'secret'});
14984: $resulttext .= ('*'x$num).'</li>';
14985: }
14986: my (@fields,$showroles);
14987: if (ref($requserfields{$provider}) eq 'ARRAY') {
14988: push(@fields,@{$requserfields{$provider}});
14989: }
14990: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
14991: push(@fields,@{$confhash{$provider}{'fields'}});
14992: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
14993: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
14994: }
14995: if (@fields) {
14996: if (grep(/^roles$/,@fields)) {
14997: $showroles = 1;
14998: }
14999: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15000: join('", "', map { $lt{$_}; } @fields).'"</li>';
15001: }
15002: if (ref($requserfields{$provider}) eq 'ARRAY') {
15003: if (grep(/^user$/,@{$requserfields{$provider}})) {
15004: if ($confhash{$provider}{'incdom'}) {
15005: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15006: } else {
15007: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15008: }
15009: }
15010: }
15011: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15012: if (@{$confhash{$provider}{'defaults'}} > 0) {
15013: $resulttext .= '<li>'.$lt{'defa'};
15014: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15015: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15016: }
15017: $resulttext =~ s/,$//;
15018: $resulttext .= '</li>';
15019: }
15020: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15021: if (keys(%{$confhash{$provider}{'defaults'}})) {
15022: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15023: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15024: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15025: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15026: }
15027: }
15028: $resulttext .= '</ul></li>';
15029: }
15030: }
15031: if (ref($crsconf{$provider}) eq 'ARRAY') {
15032: if (@{$crsconf{$provider}} > 0) {
15033: $resulttext .= '<li>'.&mt('Configurable in course:');
15034: my $numconfig = 0;
15035: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15036: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15037: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15038: $numconfig ++;
15039: if ($provider eq 'examity') {
15040: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15041: } else {
15042: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15043: }
15044: }
15045: $resulttext =~ s/,$//;
15046: }
15047: }
15048: if (!$numconfig) {
15049: $resulttext .= ' '.&mt('None');
15050: }
15051: $resulttext .= '</li>';
15052: }
15053: }
15054: if ($showroles) {
15055: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15056: my $rolemaps;
15057: foreach my $role (@courseroles) {
15058: if ($confhash{$provider}{'roles'}{$role}) {
15059: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15060: $confhash{$provider}{'roles'}{$role}.',';
15061: }
15062: }
15063: if ($rolemaps) {
15064: $rolemaps =~ s/,$//;
15065: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15066: }
15067: }
15068: }
15069: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15070: my $customlist;
15071: if (keys(%{$confhash{$provider}{'custom'}})) {
15072: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15073: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15074: }
15075: $customlist =~ s/,$//;
15076: }
15077: if ($customlist) {
15078: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15079: }
15080: }
15081: $resulttext .= '</ul></li>';
15082: }
15083: }
15084: $resulttext .= '</ul>';
15085: } else {
15086: $resulttext = &mt('No changes made.');
15087: }
15088: } else {
15089: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15090: }
15091: if ($errors) {
15092: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15093: $errors.'</ul>';
15094: }
15095: return $resulttext;
15096: }
15097:
15098: sub process_proctoring_image {
15099: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15100: my $filename = $env{'form.'.$caller.'.filename'};
15101: my ($error,$url);
15102: my ($width,$height) = (21,21);
15103: if ($configuserok eq 'ok') {
15104: if ($switchserver) {
15105: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15106: $switchserver);
15107: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15108: my $modified = [];
1.372 raeburn 15109: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15110: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15111: "proctoring/$provider/icon",$width,$height,
15112: '',$modified);
1.372 raeburn 15113: if ($result eq 'ok') {
15114: if ($madethumb) {
15115: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15116: my $imagethumb = "$path/tn-".$imagefile;
15117: $url = $imagethumb;
15118: } else {
15119: $url = $imageurl;
15120: }
1.421 raeburn 15121: &update_modify_urls($r,$modified);
1.372 raeburn 15122: } else {
15123: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15124: }
15125: } else {
15126: $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);
15127: }
15128: } else {
15129: $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);
15130: }
15131: return ($url,$error);
15132: }
15133:
1.320 raeburn 15134: sub modify_lti {
15135: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15136: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 ! raeburn 15137: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15138: my (%posslti,%posslticrs,%posscrstype);
15139: my @courseroles = ('cc','in','ta','ep','st');
15140: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15141: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15142: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15143: my %coursetypetitles = &Apache::lonlocal::texthash (
15144: official => 'Official',
15145: unofficial => 'Unofficial',
15146: community => 'Community',
15147: textbook => 'Textbook',
15148: placement => 'Placement Test',
1.392 raeburn 15149: lti => 'LTI Provider',
1.320 raeburn 15150: );
1.325 raeburn 15151: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15152: my %lt = <i_names();
15153: map { $posslti{$_} = 1; } @ltiroles;
15154: map { $posslticrs{$_} = 1; } @lticourseroles;
15155: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15156:
1.326 raeburn 15157: my %menutitles = <imenu_titles();
1.421 raeburn 15158: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15159:
1.421 raeburn 15160: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15161:
1.406 raeburn 15162: my (%linkprotchg,$linkprotoutput,$is_home);
15163: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15164: \%linkprotchg,'domain');
15165: my $home = &Apache::lonnet::domain($dom,'primary');
15166: unless (($home eq 'no_host') || ($home eq '')) {
15167: my @ids=&Apache::lonnet::current_machine_ids();
15168: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15169: }
15170:
15171: if (keys(%linkprotchg)) {
15172: $secchanges{'linkprot'} = 1;
15173: my %oldlinkprot;
15174: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15175: %oldlinkprot = %{$currltisec{'linkprot'}};
15176: }
15177: foreach my $id (keys(%linkprotchg)) {
15178: if (ref($linkprotchg{$id}) eq 'HASH') {
15179: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15180: if (($inner eq 'secret') || ($inner eq 'key')) {
15181: if ($is_home) {
15182: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15183: }
15184: }
15185: }
15186: } else {
15187: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15188: }
15189: }
15190: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15191: if (keys(%linkprotchg)) {
15192: %{$newltisec{'linkprot'}} = %linkprotchg;
15193: }
15194: }
15195: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15196: foreach my $id (%{$currltisec{'linkprot'}}) {
15197: next if ($id !~ /^\d+$/);
15198: unless (exists($linkprotchg{$id})) {
15199: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15200: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15201: if (($inner eq 'secret') || ($inner eq 'key')) {
15202: if ($is_home) {
15203: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15204: }
15205: } else {
15206: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15207: }
15208: }
15209: } else {
15210: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15211: }
15212: }
15213: }
15214: }
15215: if ($proterror) {
15216: $errors .= '<li>'.$proterror.'</li>';
15217: }
1.320 raeburn 15218: my (@items,%deletions,%itemids);
15219: if ($env{'form.lti_add'}) {
15220: my $consumer = $env{'form.lti_consumer_add'};
15221: $consumer =~ s/(`)/'/g;
15222: ($newid,my $error) = &get_lti_id($dom,$consumer);
15223: if ($newid) {
15224: $itemids{'add'} = $newid;
15225: push(@items,'add');
15226: $changes{$newid} = 1;
15227: } else {
15228: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
15229: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15230: }
15231: }
15232: if (ref($domconfig{$action}) eq 'HASH') {
15233: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15234: if (@todelete) {
15235: map { $deletions{$_} = 1; } @todelete;
15236: }
15237: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15238: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15239: my $itemid = $env{'form.lti_id_'.$i};
15240: $itemid =~ s/\D+//g;
15241: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15242: if ($deletions{$itemid}) {
15243: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15244: } else {
1.390 raeburn 15245: push(@items,$i);
15246: $itemids{$i} = $itemid;
1.320 raeburn 15247: }
15248: }
15249: }
15250: }
1.424 ! raeburn 15251: my (%keystore,$secstored);
! 15252: if ($is_home) {
! 15253: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
! 15254: }
! 15255:
! 15256: my ($cipher,$privnum);
! 15257: if ((@items > 0) && ($is_home)) {
! 15258: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
! 15259: $newltisec{'encrypt'},$keystore{$home});
! 15260: }
1.320 raeburn 15261: foreach my $idx (@items) {
15262: my $itemid = $itemids{$idx};
15263: next unless ($itemid);
1.424 ! raeburn 15264: my %currlti;
! 15265: unless ($idx eq 'add') {
! 15266: if (ref($domconfig{$action}) eq 'HASH') {
! 15267: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
! 15268: %currlti = %{$domconfig{$action}{$itemid}};
! 15269: }
! 15270: }
! 15271: }
1.390 raeburn 15272: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15273: $position =~ s/\D+//g;
15274: if ($position ne '') {
15275: $allpos[$position] = $itemid;
15276: }
1.424 ! raeburn 15277: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15278: my $formitem = 'form.lti_'.$item.'_'.$idx;
15279: $env{$formitem} =~ s/(`)/'/g;
15280: if ($item eq 'lifetime') {
15281: $env{$formitem} =~ s/[^\d.]//g;
15282: }
15283: if ($env{$formitem} ne '') {
1.424 ! raeburn 15284: $confhash{$itemid}{$item} = $env{$formitem};
! 15285: unless (($idx eq 'add') || ($changes{$itemid})) {
! 15286: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
! 15287: $changes{$itemid} = 1;
1.320 raeburn 15288: }
15289: }
15290: }
15291: }
15292: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15293: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15294: }
1.345 raeburn 15295: if ($confhash{$itemid}{'requser'}) {
15296: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15297: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15298: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15299: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15300: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15301: my $mapuser = $env{'form.lti_customuser_'.$idx};
15302: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15303: $mapuser =~ s/^\s+|\s+$//g;
15304: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15305: }
15306: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15307: my @makeuser;
15308: foreach my $ltirole (sort(@possmakeuser)) {
15309: if ($posslti{$ltirole}) {
15310: push(@makeuser,$ltirole);
15311: }
15312: }
15313: $confhash{$itemid}{'makeuser'} = \@makeuser;
15314: if (@makeuser) {
15315: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15316: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
15317: $confhash{$itemid}{'lcauth'} = $lcauth;
15318: if ($lcauth ne 'internal') {
15319: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
15320: $lcauthparm =~ s/^(\s+|\s+)$//g;
15321: $lcauthparm =~ s/`//g;
15322: if ($lcauthparm ne '') {
15323: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
15324: }
15325: }
15326: } else {
15327: $confhash{$itemid}{'lcauth'} = 'lti';
15328: }
1.320 raeburn 15329: }
1.345 raeburn 15330: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
15331: if (@possinstdata) {
15332: foreach my $field (@possinstdata) {
15333: if (exists($fieldtitles{$field})) {
15334: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 15335: }
15336: }
15337: }
1.363 raeburn 15338: if ($env{'form.lti_callback_'.$idx}) {
15339: if ($env{'form.lti_callbackparam_'.$idx}) {
15340: my $callback = $env{'form.lti_callbackparam_'.$idx};
15341: $callback =~ s/^\s+|\s+$//g;
15342: $confhash{$itemid}{'callback'} = $callback;
15343: }
15344: }
1.391 raeburn 15345: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 15346: if ($env{'form.lti_'.$field.'_'.$idx}) {
15347: $confhash{$itemid}{$field} = 1;
15348: }
1.320 raeburn 15349: }
1.345 raeburn 15350: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
15351: $confhash{$itemid}{lcmenu} = [];
15352: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
15353: foreach my $field (@possmenu) {
15354: if (exists($menutitles{$field})) {
15355: if ($field eq 'grades') {
15356: next unless ($env{'form.lti_inlinemenu_'.$idx});
15357: }
15358: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 15359: }
15360: }
15361: }
1.391 raeburn 15362: if ($confhash{$itemid}{'crsinc'}) {
15363: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
15364: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
15365: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
15366: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
15367: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
15368: $mapcrs =~ s/(`)/'/g;
15369: $mapcrs =~ s/^\s+|\s+$//g;
15370: $confhash{$itemid}{'mapcrs'} = $mapcrs;
15371: }
15372: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
15373: my @crstypes;
15374: foreach my $type (sort(@posstypes)) {
15375: if ($posscrstype{$type}) {
15376: push(@crstypes,$type);
15377: }
15378: }
15379: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 15380: if ($env{'form.lti_storecrs_'.$idx}) {
15381: $confhash{$itemid}{'storecrs'} = 1;
15382: }
1.391 raeburn 15383: if ($env{'form.lti_makecrs_'.$idx}) {
15384: $confhash{$itemid}{'makecrs'} = 1;
15385: }
15386: foreach my $ltirole (@lticourseroles) {
15387: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
15388: if (grep(/^\Q$possrole\E$/,@courseroles)) {
15389: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
15390: }
15391: }
15392: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
15393: my @selfenroll;
15394: foreach my $type (sort(@possenroll)) {
15395: if ($posslticrs{$type}) {
15396: push(@selfenroll,$type);
15397: }
15398: }
15399: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
15400: if ($env{'form.lti_crssec_'.$idx}) {
15401: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
15402: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
15403: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
15404: my $section = $env{'form.lti_customsection_'.$idx};
15405: $section =~ s/(`)/'/g;
15406: $section =~ s/^\s+|\s+$//g;
15407: if ($section ne '') {
15408: $confhash{$itemid}{'section'} = $section;
15409: }
15410: }
15411: }
15412: foreach my $field ('passback','roster') {
15413: if ($env{'form.lti_'.$field.'_'.$idx}) {
15414: $confhash{$itemid}{$field} = 1;
15415: }
15416: }
15417: if ($env{'form.lti_passback_'.$idx}) {
15418: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
15419: $confhash{$itemid}{'passbackformat'} = '1.0';
15420: } else {
15421: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 15422: }
15423: }
1.391 raeburn 15424: }
15425: unless (($idx eq 'add') || ($changes{$itemid})) {
15426: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 15427: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 ! raeburn 15428: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 15429: $changes{$itemid} = 1;
15430: }
1.345 raeburn 15431: }
15432: unless ($changes{$itemid}) {
1.424 ! raeburn 15433: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
! 15434: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 15435: $changes{$itemid} = 1;
15436: }
15437: }
1.345 raeburn 15438: }
1.391 raeburn 15439: foreach my $field ('mapcrstype','selfenroll') {
15440: unless ($changes{$itemid}) {
1.424 ! raeburn 15441: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15442: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 ! raeburn 15443: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15444: $confhash{$itemid}{$field});
15445: if (@diffs) {
15446: $changes{$itemid} = 1;
15447: }
1.424 ! raeburn 15448: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15449: $changes{$itemid} = 1;
15450: }
15451: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15452: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 15453: $changes{$itemid} = 1;
15454: }
15455: }
1.391 raeburn 15456: }
15457: }
15458: unless ($changes{$itemid}) {
1.424 ! raeburn 15459: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 15460: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 ! raeburn 15461: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
! 15462: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 15463: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 15464: $changes{$itemid} = 1;
15465: last;
15466: }
15467: }
1.391 raeburn 15468: unless ($changes{$itemid}) {
15469: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
15470: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 ! raeburn 15471: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 15472: $changes{$itemid} = 1;
15473: last;
15474: }
15475: }
15476: }
1.424 ! raeburn 15477: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 15478: $changes{$itemid} = 1;
1.345 raeburn 15479: }
1.391 raeburn 15480: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15481: unless ($changes{$itemid}) {
15482: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
15483: $changes{$itemid} = 1;
15484: }
15485: }
15486: }
15487: }
15488: }
15489: unless ($changes{$itemid}) {
15490: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 ! raeburn 15491: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 15492: $changes{$itemid} = 1;
1.320 raeburn 15493: }
1.391 raeburn 15494: }
15495: unless ($changes{$itemid}) {
15496: foreach my $field ('makeuser','lcmenu') {
1.424 ! raeburn 15497: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 15498: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 ! raeburn 15499: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 15500: $confhash{$itemid}{$field});
15501: if (@diffs) {
15502: $changes{$itemid} = 1;
15503: }
1.424 ! raeburn 15504: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 15505: $changes{$itemid} = 1;
15506: }
15507: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
15508: if (@{$confhash{$itemid}{$field}} > 0) {
15509: $changes{$itemid} = 1;
15510: }
1.345 raeburn 15511: }
1.320 raeburn 15512: }
15513: }
15514: }
15515: }
15516: }
1.424 ! raeburn 15517: if ($is_home) {
! 15518: my $keyitem = 'form.lti_key_'.$idx;
! 15519: $env{$keyitem} =~ s/(`)/'/g;
! 15520: if ($env{$keyitem} ne '') {
! 15521: $ltienc{$itemid}{'key'} = $env{$keyitem};
! 15522: unless ($changes{$itemid}) {
! 15523: if ($currlti{'key'} ne $env{$keyitem}) {
! 15524: $changes{$itemid} = 1;
! 15525: }
! 15526: }
! 15527: }
! 15528: my $secretitem = 'form.lti_secret_'.$idx;
! 15529: $env{$secretitem} =~ s/(`)/'/g;
! 15530: if ($currlti{'usable'}) {
! 15531: if ($env{'form.lti_changesecret_'.$idx}) {
! 15532: if ($env{$secretitem} ne '') {
! 15533: if ($privnum && $cipher) {
! 15534: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
! 15535: $confhash{$itemid}{'cipher'} = $privnum;
! 15536: } else {
! 15537: $ltienc{$itemid}{'secret'} = $env{$secretitem};
! 15538: }
! 15539: $changes{$itemid} = 1;
! 15540: }
! 15541: } else {
! 15542: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
! 15543: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
! 15544: }
! 15545: if (ref($ltienc{$itemid}) eq 'HASH') {
! 15546: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
! 15547: $confhash{$itemid}{'usable'} = 1;
! 15548: }
! 15549: }
! 15550: } elsif ($env{$secretitem} ne '') {
! 15551: if ($privnum && $cipher) {
! 15552: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
! 15553: $confhash{$itemid}{'cipher'} = $privnum;
! 15554: } else {
! 15555: $ltienc{$itemid}{'secret'} = $env{$secretitem};
! 15556: }
! 15557: if (ref($ltienc{$itemid}) eq 'HASH') {
! 15558: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
! 15559: $confhash{$itemid}{'usable'} = 1;
! 15560: }
! 15561: }
! 15562: $changes{$itemid} = 1;
! 15563: }
! 15564: }
! 15565: unless ($changes{$itemid}) {
! 15566: foreach my $key (keys(%currlti)) {
! 15567: if (ref($currlti{$key}) eq 'HASH') {
! 15568: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
! 15569: foreach my $innerkey (keys(%{$currlti{$key}})) {
! 15570: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
! 15571: $changes{$itemid} = 1;
! 15572: last;
! 15573: }
! 15574: }
! 15575: } elsif (keys(%{$currlti{$key}}) > 0) {
! 15576: $changes{$itemid} = 1;
! 15577: }
! 15578: }
! 15579: last if ($changes{$itemid});
! 15580: }
! 15581: }
1.320 raeburn 15582: }
15583: if (@allpos > 0) {
15584: my $idx = 0;
15585: foreach my $itemid (@allpos) {
15586: if ($itemid ne '') {
15587: $confhash{$itemid}{'order'} = $idx;
15588: if (ref($domconfig{$action}) eq 'HASH') {
15589: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15590: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
15591: $changes{$itemid} = 1;
15592: }
15593: }
15594: }
15595: $idx ++;
15596: }
15597: }
15598: }
1.424 ! raeburn 15599:
! 15600: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
! 15601: return &mt('No changes made.');
! 15602: }
! 15603:
1.320 raeburn 15604: my %ltihash = (
1.405 raeburn 15605: $action => { %confhash }
15606: );
1.424 ! raeburn 15607: my %ltienchash;
! 15608:
! 15609: if ($is_home) {
! 15610: %ltienchash = (
! 15611: $action => { %ltienc }
! 15612: );
! 15613: }
1.405 raeburn 15614: if (keys(%secchanges)) {
15615: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 15616: if ($secchanges{'linkprot'}) {
15617: if ($is_home) {
15618: $ltienchash{'linkprot'} = \%newltienc;
15619: }
15620: }
1.405 raeburn 15621: }
15622: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 15623: if ($putresult eq 'ok') {
1.424 ! raeburn 15624: if (keys(%ltienchash)) {
! 15625: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 15626: }
15627: $resulttext = &mt('Changes made:').'<ul>';
15628: if (keys(%secchanges) > 0) {
1.423 raeburn 15629: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 15630: if (exists($secchanges{'linkprot'})) {
15631: $resulttext .= $linkprotoutput;
1.405 raeburn 15632: }
15633: }
1.320 raeburn 15634: if (keys(%changes) > 0) {
15635: my $cachetime = 24*60*60;
1.424 ! raeburn 15636: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 15637: if (ref($lastactref) eq 'HASH') {
15638: $lastactref->{'lti'} = 1;
15639: }
15640: my %bynum;
15641: foreach my $itemid (sort(keys(%changes))) {
1.424 ! raeburn 15642: if (ref($confhash{$itemid}) eq 'HASH') {
! 15643: my $position = $confhash{$itemid}{'order'};
! 15644: $bynum{$position} = $itemid;
! 15645: }
1.320 raeburn 15646: }
15647: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15648: my $itemid = $bynum{$pos};
1.424 ! raeburn 15649: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 15650: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 15651: my $position = $pos + 1;
15652: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15653: foreach my $item ('version','lifetime') {
15654: if ($confhash{$itemid}{$item} ne '') {
15655: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
15656: }
15657: }
1.424 ! raeburn 15658: if ($ltienc{$itemid}{'key'} ne '') {
! 15659: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 15660: }
1.424 ! raeburn 15661: if ($ltienc{$itemid}{'secret'} ne '') {
! 15662: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 15663: }
1.345 raeburn 15664: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 15665: if ($confhash{$itemid}{'callback'}) {
15666: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
15667: } else {
1.392 raeburn 15668: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 15669: }
1.345 raeburn 15670: if ($confhash{$itemid}{'mapuser'}) {
15671: my $shownmapuser;
15672: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
15673: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
15674: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
15675: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
15676: } else {
15677: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 15678: }
1.345 raeburn 15679: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 15680: }
1.345 raeburn 15681: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
15682: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
15683: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
15684: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
15685: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
15686: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
15687: } else {
15688: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
15689: $confhash{$itemid}{'lcauth'});
15690: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
15691: $resulttext .= '; '.&mt('a randomly generated password will be created');
15692: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
15693: if ($confhash{$itemid}{'lcauthparm'} ne '') {
15694: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
15695: }
15696: } else {
15697: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
15698: }
15699: }
15700: $resulttext .= '</li>';
15701: } else {
15702: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
15703: }
1.320 raeburn 15704: }
1.345 raeburn 15705: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
15706: if (@{$confhash{$itemid}{'instdata'}} > 0) {
15707: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
15708: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 15709: } else {
1.345 raeburn 15710: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 15711: }
1.320 raeburn 15712: }
1.391 raeburn 15713: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 15714: $resulttext .= '<li>'.$lt{$item}.': ';
15715: if ($confhash{$itemid}{$item}) {
15716: $resulttext .= &mt('Yes');
15717: } else {
15718: $resulttext .= &mt('No');
1.337 raeburn 15719: }
1.345 raeburn 15720: $resulttext .= '</li>';
1.320 raeburn 15721: }
1.345 raeburn 15722: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15723: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15724: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 15725: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15726: } else {
15727: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15728: }
15729: }
15730: if ($confhash{$itemid}{'crsinc'}) {
15731: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
15732: my $rolemaps;
15733: foreach my $role (@ltiroles) {
15734: if ($confhash{$itemid}{'maproles'}{$role}) {
15735: $rolemaps .= (' 'x2).$role.'='.
15736: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
15737: 'Course').',';
15738: }
15739: }
15740: if ($rolemaps) {
15741: $rolemaps =~ s/,$//;
15742: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15743: }
15744: }
15745: if ($confhash{$itemid}{'mapcrs'}) {
15746: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
15747: }
15748: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
15749: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
15750: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
15751: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
15752: '</li>';
15753: } else {
15754: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
15755: }
15756: }
1.392 raeburn 15757: if ($confhash{$itemid}{'storecrs'}) {
15758: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
15759: }
1.391 raeburn 15760: if ($confhash{$itemid}{'makecrs'}) {
15761: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
15762: } else {
15763: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
15764: }
15765: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
15766: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
15767: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
15768: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
15769: '</li>';
15770: } else {
15771: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
15772: }
15773: }
15774: if ($confhash{$itemid}{'section'}) {
15775: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
15776: $resulttext .= '<li>'.&mt('User section from standard field:').
15777: ' (course_section_sourcedid)'.'</li>';
15778: } else {
15779: $resulttext .= '<li>'.&mt('User section from:').' '.
15780: $confhash{$itemid}{'section'}.'</li>';
15781: }
1.345 raeburn 15782: } else {
1.391 raeburn 15783: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
15784: }
15785: foreach my $item ('passback','roster','topmenu','inlinemenu') {
15786: $resulttext .= '<li>'.$lt{$item}.': ';
15787: if ($confhash{$itemid}{$item}) {
15788: $resulttext .= &mt('Yes');
15789: if ($item eq 'passback') {
15790: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
15791: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
15792: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
15793: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
15794: }
15795: }
15796: } else {
15797: $resulttext .= &mt('No');
15798: }
15799: $resulttext .= '</li>';
15800: }
15801: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
15802: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
15803: $resulttext .= '<li>'.&mt('Menu items:').' '.
15804: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
15805: } else {
15806: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
15807: }
1.345 raeburn 15808: }
1.326 raeburn 15809: }
15810: }
1.320 raeburn 15811: $resulttext .= '</ul></li>';
15812: }
15813: }
1.424 ! raeburn 15814: if (keys(%deletions)) {
! 15815: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
! 15816: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
! 15817: }
! 15818: }
1.320 raeburn 15819: }
1.405 raeburn 15820: $resulttext .= '</ul>';
1.424 ! raeburn 15821: if (ref($lastactref) eq 'HASH') {
! 15822: if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
! 15823: $lastactref->{'domdefaults'} = 1;
! 15824: }
! 15825: }
1.320 raeburn 15826: } else {
15827: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15828: }
15829: if ($errors) {
15830: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15831: $errors.'</ul>';
15832: }
15833: return $resulttext;
15834: }
15835:
1.424 ! raeburn 15836: sub get_priv_creds {
! 15837: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
! 15838: my ($needenc,$cipher,$privnum);
! 15839: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
! 15840: if (($encchg) && (ref($encrypt) eq 'HASH')) {
! 15841: $needenc = $encrypt->{'consumers'}
! 15842: } else {
! 15843: $needenc = $domdefs{'ltienc_consumers'};
! 15844: }
! 15845: if ($needenc) {
! 15846: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
! 15847: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
! 15848: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
! 15849: my $privkey = $privhash{'key'};
! 15850: $privnum = $privhash{'version'};
! 15851: if (($privnum) && ($privkey ne '')) {
! 15852: $cipher = Crypt::CBC->new({'key' => $privkey,
! 15853: 'cipher' => 'DES'});
! 15854: }
! 15855: }
! 15856: }
! 15857: return ($cipher,$privnum);
! 15858: }
! 15859:
1.320 raeburn 15860: sub get_lti_id {
15861: my ($domain,$consumer) = @_;
15862: # get lock on lti db
15863: my $lockhash = {
15864: lock => $env{'user.name'}.
15865: ':'.$env{'user.domain'},
15866: };
15867: my $tries = 0;
15868: my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15869: my ($id,$error);
15870:
15871: while (($gotlock ne 'ok') && ($tries<10)) {
15872: $tries ++;
15873: sleep (0.1);
15874: $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
15875: }
15876: if ($gotlock eq 'ok') {
15877: my %currids = &Apache::lonnet::dump_dom('lti',$domain);
15878: if ($currids{'lock'}) {
15879: delete($currids{'lock'});
15880: if (keys(%currids)) {
15881: my @curr = sort { $a <=> $b } keys(%currids);
15882: if ($curr[-1] =~ /^\d+$/) {
15883: $id = 1 + $curr[-1];
15884: }
15885: } else {
15886: $id = 1;
15887: }
15888: if ($id) {
15889: unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
15890: $error = 'nostore';
15891: }
15892: } else {
15893: $error = 'nonumber';
15894: }
15895: }
15896: my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
15897: } else {
15898: $error = 'nolock';
15899: }
15900: return ($id,$error);
15901: }
15902:
1.3 raeburn 15903: sub modify_autoenroll {
1.205 raeburn 15904: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 15905: my ($resulttext,%changes);
15906: my %currautoenroll;
15907: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
15908: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
15909: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
15910: }
15911: }
15912: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
15913: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 15914: sender => 'Sender for notification messages',
1.274 raeburn 15915: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 15916: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 15917: my @offon = ('off','on');
1.17 raeburn 15918: my $sender_uname = $env{'form.sender_uname'};
15919: my $sender_domain = $env{'form.sender_domain'};
15920: if ($sender_domain eq '') {
15921: $sender_uname = '';
15922: } elsif ($sender_uname eq '') {
15923: $sender_domain = '';
15924: }
1.129 raeburn 15925: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 15926: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
15927: $autofailsafe =~ s{^\s+|\s+$}{}g;
15928: if ($autofailsafe =~ /\D/) {
15929: undef($autofailsafe);
15930: }
1.274 raeburn 15931: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 15932: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
15933: $failsafe = 'off';
1.400 raeburn 15934: undef($autofailsafe);
1.274 raeburn 15935: }
1.1 raeburn 15936: my %autoenrollhash = (
1.129 raeburn 15937: autoenroll => { 'run' => $env{'form.autoenroll_run'},
15938: 'sender_uname' => $sender_uname,
15939: 'sender_domain' => $sender_domain,
15940: 'co-owners' => $coowners,
1.399 raeburn 15941: 'autofailsafe' => $autofailsafe,
1.400 raeburn 15942: 'failsafe' => $failsafe,
1.1 raeburn 15943: }
15944: );
1.4 raeburn 15945: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
15946: $dom);
1.1 raeburn 15947: if ($putresult eq 'ok') {
15948: if (exists($currautoenroll{'run'})) {
15949: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
15950: $changes{'run'} = 1;
15951: }
15952: } elsif ($autorun) {
15953: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 15954: $changes{'run'} = 1;
1.1 raeburn 15955: }
15956: }
1.17 raeburn 15957: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 15958: $changes{'sender'} = 1;
15959: }
1.17 raeburn 15960: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 15961: $changes{'sender'} = 1;
15962: }
1.129 raeburn 15963: if ($currautoenroll{'co-owners'} ne '') {
15964: if ($currautoenroll{'co-owners'} ne $coowners) {
15965: $changes{'coowners'} = 1;
15966: }
15967: } elsif ($coowners) {
15968: $changes{'coowners'} = 1;
1.274 raeburn 15969: }
1.399 raeburn 15970: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 15971: $changes{'autofailsafe'} = 1;
15972: }
1.399 raeburn 15973: if ($currautoenroll{'failsafe'} ne $failsafe) {
15974: $changes{'failsafe'} = 1;
15975: }
1.1 raeburn 15976: if (keys(%changes) > 0) {
15977: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 15978: if ($changes{'run'}) {
1.1 raeburn 15979: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
15980: }
15981: if ($changes{'sender'}) {
1.17 raeburn 15982: if ($sender_uname eq '' || $sender_domain eq '') {
15983: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
15984: } else {
15985: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
15986: }
1.1 raeburn 15987: }
1.129 raeburn 15988: if ($changes{'coowners'}) {
15989: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
15990: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 15991: if (ref($lastactref) eq 'HASH') {
15992: $lastactref->{'domainconfig'} = 1;
15993: }
1.129 raeburn 15994: }
1.274 raeburn 15995: if ($changes{'autofailsafe'}) {
1.399 raeburn 15996: if ($autofailsafe ne '') {
15997: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 15998: } else {
1.399 raeburn 15999: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16000: }
1.399 raeburn 16001: }
16002: if ($changes{'failsafe'}) {
16003: if ($failsafe eq 'off') {
16004: unless ($changes{'autofailsafe'}) {
16005: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16006: }
16007: } elsif ($failsafe eq 'zero') {
16008: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16009: } else {
16010: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16011: }
16012: }
16013: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16014: &Apache::lonnet::get_domain_defaults($dom,1);
16015: if (ref($lastactref) eq 'HASH') {
16016: $lastactref->{'domdefaults'} = 1;
16017: }
16018: }
1.1 raeburn 16019: $resulttext .= '</ul>';
16020: } else {
16021: $resulttext = &mt('No changes made to auto-enrollment settings');
16022: }
16023: } else {
1.11 albertel 16024: $resulttext = '<span class="LC_error">'.
16025: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16026: }
1.3 raeburn 16027: return $resulttext;
1.1 raeburn 16028: }
16029:
16030: sub modify_autoupdate {
1.3 raeburn 16031: my ($dom,%domconfig) = @_;
1.1 raeburn 16032: my ($resulttext,%currautoupdate,%fields,%changes);
16033: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16034: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16035: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16036: }
16037: }
16038: my @offon = ('off','on');
16039: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16040: run => 'Auto-update:',
16041: classlists => 'Updates to user information in classlists?',
16042: unexpired => 'Skip updates for users without active or future roles?',
16043: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16044: );
1.44 raeburn 16045: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16046: my %fieldtitles = &Apache::lonlocal::texthash (
16047: id => 'Student/Employee ID',
1.20 raeburn 16048: permanentemail => 'E-mail address',
1.1 raeburn 16049: lastname => 'Last Name',
16050: firstname => 'First Name',
16051: middlename => 'Middle Name',
1.132 raeburn 16052: generation => 'Generation',
1.1 raeburn 16053: );
1.142 raeburn 16054: $othertitle = &mt('All users');
1.1 raeburn 16055: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16056: $othertitle = &mt('Other users');
1.1 raeburn 16057: }
16058: foreach my $key (keys(%env)) {
16059: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16060: my ($usertype,$item) = ($1,$2);
16061: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16062: if ($usertype eq 'default') {
16063: push(@{$fields{$1}},$2);
16064: } elsif (ref($types) eq 'ARRAY') {
16065: if (grep(/^\Q$usertype\E$/,@{$types})) {
16066: push(@{$fields{$1}},$2);
16067: }
16068: }
16069: }
1.1 raeburn 16070: }
16071: }
1.131 raeburn 16072: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16073: @lockablenames = sort(@lockablenames);
16074: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16075: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16076: if (@changed) {
16077: $changes{'lockablenames'} = 1;
16078: }
16079: } else {
16080: if (@lockablenames) {
16081: $changes{'lockablenames'} = 1;
16082: }
16083: }
1.1 raeburn 16084: my %updatehash = (
16085: autoupdate => { run => $env{'form.autoupdate_run'},
16086: classlists => $env{'form.classlists'},
1.385 raeburn 16087: unexpired => $env{'form.unexpired'},
1.1 raeburn 16088: fields => {%fields},
1.131 raeburn 16089: lockablenames => \@lockablenames,
1.1 raeburn 16090: }
16091: );
1.385 raeburn 16092: my $lastactivedays;
16093: if ($env{'form.lastactive'}) {
16094: $lastactivedays = $env{'form.lastactivedays'};
16095: $lastactivedays =~ s/^\s+|\s+$//g;
16096: unless ($lastactivedays =~ /^\d+$/) {
16097: undef($lastactivedays);
16098: $env{'form.lastactive'} = 0;
16099: }
16100: }
16101: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16102: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16103: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16104: if (exists($updatehash{autoupdate}{$key})) {
16105: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16106: $changes{$key} = 1;
16107: }
16108: }
16109: } elsif ($key eq 'fields') {
16110: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16111: foreach my $item (@{$types},'default') {
1.1 raeburn 16112: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16113: my $change = 0;
16114: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16115: if (!exists($fields{$item})) {
16116: $change = 1;
1.132 raeburn 16117: last;
1.1 raeburn 16118: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16119: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16120: $change = 1;
1.132 raeburn 16121: last;
1.1 raeburn 16122: }
16123: }
16124: }
16125: if ($change) {
16126: push(@{$changes{$key}},$item);
16127: }
1.26 raeburn 16128: }
1.1 raeburn 16129: }
16130: }
1.131 raeburn 16131: } elsif ($key eq 'lockablenames') {
16132: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16133: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16134: if (@changed) {
16135: $changes{'lockablenames'} = 1;
16136: }
16137: } else {
16138: if (@lockablenames) {
16139: $changes{'lockablenames'} = 1;
16140: }
16141: }
16142: }
16143: }
16144: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16145: if (@lockablenames) {
16146: $changes{'lockablenames'} = 1;
1.1 raeburn 16147: }
16148: }
1.385 raeburn 16149: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16150: if ($updatehash{'autoupdate'}{'unexpired'}) {
16151: $changes{'unexpired'} = 1;
16152: }
16153: }
16154: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16155: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16156: $changes{'lastactive'} = 1;
16157: }
16158: }
1.26 raeburn 16159: foreach my $item (@{$types},'default') {
16160: if (defined($fields{$item})) {
16161: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16162: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16163: my $change = 0;
16164: if (ref($fields{$item}) eq 'ARRAY') {
16165: foreach my $type (@{$fields{$item}}) {
16166: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16167: $change = 1;
16168: last;
16169: }
16170: }
16171: }
16172: if ($change) {
16173: push(@{$changes{'fields'}},$item);
16174: }
16175: } else {
1.26 raeburn 16176: push(@{$changes{'fields'}},$item);
16177: }
16178: } else {
16179: push(@{$changes{'fields'}},$item);
1.1 raeburn 16180: }
16181: }
16182: }
16183: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16184: $dom);
16185: if ($putresult eq 'ok') {
16186: if (keys(%changes) > 0) {
16187: $resulttext = &mt('Changes made:').'<ul>';
16188: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16189: if ($key eq 'lockablenames') {
16190: $resulttext .= '<li>';
16191: if (@lockablenames) {
16192: $usertypes->{'default'} = $othertitle;
16193: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16194: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16195: } else {
16196: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16197: }
16198: $resulttext .= '</li>';
16199: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16200: foreach my $item (@{$changes{$key}}) {
16201: my @newvalues;
16202: foreach my $type (@{$fields{$item}}) {
16203: push(@newvalues,$fieldtitles{$type});
16204: }
1.3 raeburn 16205: my $newvaluestr;
16206: if (@newvalues > 0) {
16207: $newvaluestr = join(', ',@newvalues);
16208: } else {
16209: $newvaluestr = &mt('none');
1.6 raeburn 16210: }
1.1 raeburn 16211: if ($item eq 'default') {
1.26 raeburn 16212: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16213: } else {
1.26 raeburn 16214: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16215: }
16216: }
16217: } else {
16218: my $newvalue;
16219: if ($key eq 'run') {
16220: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16221: } elsif ($key eq 'lastactive') {
16222: $newvalue = $offon[$env{'form.lastactive'}];
16223: unless ($lastactivedays eq '') {
16224: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16225: }
1.1 raeburn 16226: } else {
16227: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16228: }
1.1 raeburn 16229: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16230: }
16231: }
16232: $resulttext .= '</ul>';
16233: } else {
1.3 raeburn 16234: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16235: }
16236: } else {
1.11 albertel 16237: $resulttext = '<span class="LC_error">'.
16238: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16239: }
1.3 raeburn 16240: return $resulttext;
1.1 raeburn 16241: }
16242:
1.125 raeburn 16243: sub modify_autocreate {
16244: my ($dom,%domconfig) = @_;
16245: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16246: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16247: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16248: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16249: }
16250: }
16251: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16252: req => 'Auto-creation of validated requests for official courses',
16253: xmldc => 'Identity of course creator of courses from XML files',
16254: );
16255: my @types = ('xml','req');
16256: foreach my $item (@types) {
16257: $newvals{$item} = $env{'form.autocreate_'.$item};
16258: $newvals{$item} =~ s/\D//g;
16259: $newvals{$item} = 0 if ($newvals{$item} eq '');
16260: }
16261: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16262: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16263: unless (exists($domcoords{$newvals{'xmldc'}})) {
16264: $newvals{'xmldc'} = '';
16265: }
16266: %autocreatehash = (
16267: autocreate => { xml => $newvals{'xml'},
16268: req => $newvals{'req'},
16269: }
16270: );
16271: if ($newvals{'xmldc'} ne '') {
16272: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16273: }
16274: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16275: $dom);
16276: if ($putresult eq 'ok') {
16277: my @items = @types;
16278: if ($newvals{'xml'}) {
16279: push(@items,'xmldc');
16280: }
16281: foreach my $item (@items) {
16282: if (exists($currautocreate{$item})) {
16283: if ($currautocreate{$item} ne $newvals{$item}) {
16284: $changes{$item} = 1;
16285: }
16286: } elsif ($newvals{$item}) {
16287: $changes{$item} = 1;
16288: }
16289: }
16290: if (keys(%changes) > 0) {
16291: my @offon = ('off','on');
16292: $resulttext = &mt('Changes made:').'<ul>';
16293: foreach my $item (@types) {
16294: if ($changes{$item}) {
16295: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16296: $resulttext .= '<li>'.
16297: &mt("$title{$item} set to [_1]$newtxt [_2]",
16298: '<b>','</b>').
16299: '</li>';
1.125 raeburn 16300: }
16301: }
16302: if ($changes{'xmldc'}) {
16303: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16304: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16305: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16306: }
16307: $resulttext .= '</ul>';
16308: } else {
16309: $resulttext = &mt('No changes made to auto-creation settings');
16310: }
16311: } else {
16312: $resulttext = '<span class="LC_error">'.
16313: &mt('An error occurred: [_1]',$putresult).'</span>';
16314: }
16315: return $resulttext;
16316: }
16317:
1.23 raeburn 16318: sub modify_directorysrch {
1.295 raeburn 16319: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 16320: my ($resulttext,%changes);
16321: my %currdirsrch;
16322: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
16323: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
16324: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
16325: }
16326: }
1.277 raeburn 16327: my %title = ( available => 'Institutional directory search available',
16328: localonly => 'Other domains can search institution',
16329: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 16330: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 16331: searchby => 'Search types',
16332: searchtypes => 'Search latitude');
16333: my @offon = ('off','on');
1.24 raeburn 16334: my @otherdoms = ('Yes','No');
1.23 raeburn 16335:
1.25 raeburn 16336: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 16337: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
16338: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
16339:
1.44 raeburn 16340: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 16341: if (keys(%{$usertypes}) == 0) {
16342: @cansearch = ('default');
16343: } else {
16344: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
16345: foreach my $type (@{$currdirsrch{'cansearch'}}) {
16346: if (!grep(/^\Q$type\E$/,@cansearch)) {
16347: push(@{$changes{'cansearch'}},$type);
16348: }
1.23 raeburn 16349: }
1.26 raeburn 16350: foreach my $type (@cansearch) {
16351: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
16352: push(@{$changes{'cansearch'}},$type);
16353: }
1.23 raeburn 16354: }
1.26 raeburn 16355: } else {
16356: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 16357: }
16358: }
16359:
16360: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
16361: foreach my $by (@{$currdirsrch{'searchby'}}) {
16362: if (!grep(/^\Q$by\E$/,@searchby)) {
16363: push(@{$changes{'searchby'}},$by);
16364: }
16365: }
16366: foreach my $by (@searchby) {
16367: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
16368: push(@{$changes{'searchby'}},$by);
16369: }
16370: }
16371: } else {
16372: push(@{$changes{'searchby'}},@searchby);
16373: }
1.25 raeburn 16374:
16375: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
16376: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
16377: if (!grep(/^\Q$type\E$/,@searchtypes)) {
16378: push(@{$changes{'searchtypes'}},$type);
16379: }
16380: }
16381: foreach my $type (@searchtypes) {
16382: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
16383: push(@{$changes{'searchtypes'}},$type);
16384: }
16385: }
16386: } else {
16387: if (exists($currdirsrch{'searchtypes'})) {
16388: foreach my $type (@searchtypes) {
16389: if ($type ne $currdirsrch{'searchtypes'}) {
16390: push(@{$changes{'searchtypes'}},$type);
16391: }
16392: }
16393: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
16394: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
16395: }
16396: } else {
16397: push(@{$changes{'searchtypes'}},@searchtypes);
16398: }
16399: }
16400:
1.23 raeburn 16401: my %dirsrch_hash = (
16402: directorysrch => { available => $env{'form.dirsrch_available'},
16403: cansearch => \@cansearch,
1.277 raeburn 16404: localonly => $env{'form.dirsrch_instlocalonly'},
16405: lclocalonly => $env{'form.dirsrch_domlocalonly'},
16406: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 16407: searchby => \@searchby,
1.25 raeburn 16408: searchtypes => \@searchtypes,
1.23 raeburn 16409: }
16410: );
16411: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
16412: $dom);
16413: if ($putresult eq 'ok') {
16414: if (exists($currdirsrch{'available'})) {
16415: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
16416: $changes{'available'} = 1;
16417: }
16418: } else {
16419: if ($env{'form.dirsrch_available'} eq '1') {
16420: $changes{'available'} = 1;
16421: }
16422: }
1.277 raeburn 16423: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 16424: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
16425: $changes{'lcavailable'} = 1;
16426: }
1.277 raeburn 16427: } else {
16428: if ($env{'form.dirsrch_lcavailable'} eq '1') {
16429: $changes{'lcavailable'} = 1;
16430: }
16431: }
1.24 raeburn 16432: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 16433: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
16434: $changes{'localonly'} = 1;
16435: }
1.24 raeburn 16436: } else {
1.277 raeburn 16437: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 16438: $changes{'localonly'} = 1;
16439: }
16440: }
1.277 raeburn 16441: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 16442: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
16443: $changes{'lclocalonly'} = 1;
16444: }
1.277 raeburn 16445: } else {
16446: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
16447: $changes{'lclocalonly'} = 1;
16448: }
16449: }
1.23 raeburn 16450: if (keys(%changes) > 0) {
16451: $resulttext = &mt('Changes made:').'<ul>';
16452: if ($changes{'available'}) {
16453: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
16454: }
1.277 raeburn 16455: if ($changes{'lcavailable'}) {
16456: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
16457: }
1.24 raeburn 16458: if ($changes{'localonly'}) {
1.277 raeburn 16459: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 16460: }
1.277 raeburn 16461: if ($changes{'lclocalonly'}) {
16462: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 16463: }
1.23 raeburn 16464: if (ref($changes{'cansearch'}) eq 'ARRAY') {
16465: my $chgtext;
1.26 raeburn 16466: if (ref($usertypes) eq 'HASH') {
16467: if (keys(%{$usertypes}) > 0) {
16468: foreach my $type (@{$types}) {
16469: if (grep(/^\Q$type\E$/,@cansearch)) {
16470: $chgtext .= $usertypes->{$type}.'; ';
16471: }
16472: }
16473: if (grep(/^default$/,@cansearch)) {
16474: $chgtext .= $othertitle;
16475: } else {
16476: $chgtext =~ s/\; $//;
16477: }
1.210 raeburn 16478: $resulttext .=
1.178 raeburn 16479: '<li>'.
16480: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
16481: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
16482: '</li>';
1.23 raeburn 16483: }
16484: }
16485: }
16486: if (ref($changes{'searchby'}) eq 'ARRAY') {
16487: my ($searchtitles,$titleorder) = &sorted_searchtitles();
16488: my $chgtext;
16489: foreach my $type (@{$titleorder}) {
16490: if (grep(/^\Q$type\E$/,@searchby)) {
16491: if (defined($searchtitles->{$type})) {
16492: $chgtext .= $searchtitles->{$type}.'; ';
16493: }
16494: }
16495: }
16496: $chgtext =~ s/\; $//;
16497: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
16498: }
1.25 raeburn 16499: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
16500: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
16501: my $chgtext;
16502: foreach my $type (@{$srchtypeorder}) {
16503: if (grep(/^\Q$type\E$/,@searchtypes)) {
16504: if (defined($srchtypes_desc->{$type})) {
16505: $chgtext .= $srchtypes_desc->{$type}.'; ';
16506: }
16507: }
16508: }
16509: $chgtext =~ s/\; $//;
1.178 raeburn 16510: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 16511: }
16512: $resulttext .= '</ul>';
1.295 raeburn 16513: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
16514: if (ref($lastactref) eq 'HASH') {
16515: $lastactref->{'directorysrch'} = 1;
16516: }
1.23 raeburn 16517: } else {
1.277 raeburn 16518: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 16519: }
16520: } else {
16521: $resulttext = '<span class="LC_error">'.
1.27 raeburn 16522: &mt('An error occurred: [_1]',$putresult).'</span>';
16523: }
16524: return $resulttext;
16525: }
16526:
1.28 raeburn 16527: sub modify_contacts {
1.205 raeburn 16528: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 16529: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
16530: if (ref($domconfig{'contacts'}) eq 'HASH') {
16531: foreach my $key (keys(%{$domconfig{'contacts'}})) {
16532: $currsetting{$key} = $domconfig{'contacts'}{$key};
16533: }
16534: }
1.286 raeburn 16535: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 16536: my @contacts = ('supportemail','adminemail');
1.286 raeburn 16537: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 16538: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 16539: my @toggles = ('reporterrors','reportupdates','reportstatus');
16540: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 16541: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 16542: foreach my $type (@mailings) {
16543: @{$newsetting{$type}} =
16544: &Apache::loncommon::get_env_multiple('form.'.$type);
16545: foreach my $item (@contacts) {
16546: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
16547: $contacts_hash{contacts}{$type}{$item} = 1;
16548: } else {
16549: $contacts_hash{contacts}{$type}{$item} = 0;
16550: }
1.289 raeburn 16551: }
1.28 raeburn 16552: $others{$type} = $env{'form.'.$type.'_others'};
16553: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 16554: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16555: $bcc{$type} = $env{'form.'.$type.'_bcc'};
16556: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 16557: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
16558: $includestr{$type} = $env{'form.'.$type.'_includestr'};
16559: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
16560: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16561: }
1.134 raeburn 16562: }
1.28 raeburn 16563: }
16564: foreach my $item (@contacts) {
16565: $to{$item} = $env{'form.'.$item};
16566: $contacts_hash{'contacts'}{$item} = $to{$item};
16567: }
1.203 raeburn 16568: foreach my $item (@toggles) {
16569: if ($env{'form.'.$item} =~ /^(0|1)$/) {
16570: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
16571: }
16572: }
1.340 raeburn 16573: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
16574: foreach my $item (@lonstatus) {
16575: if ($item eq 'excluded') {
16576: my (%serverhomes,@excluded);
16577: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
16578: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
16579: if (@possexcluded) {
16580: foreach my $id (sort(@possexcluded)) {
16581: if ($serverhomes{$id}) {
16582: push(@excluded,$id);
16583: }
16584: }
16585: }
16586: if (@excluded) {
16587: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
16588: }
16589: } elsif ($item eq 'weights') {
1.377 raeburn 16590: foreach my $type ('E','W','N','U') {
1.340 raeburn 16591: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
16592: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
16593: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
16594: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
16595: $env{'form.error'.$item.'_'.$type};
16596: }
16597: }
16598: }
16599: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
16600: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
16601: if ($env{'form.error'.$item} =~ /^\d+$/) {
16602: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
16603: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
16604: }
16605: }
16606: }
16607: }
1.286 raeburn 16608: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
16609: foreach my $field (@{$fields}) {
16610: if (ref($possoptions->{$field}) eq 'ARRAY') {
16611: my $value = $env{'form.helpform_'.$field};
16612: $value =~ s/^\s+|\s+$//g;
16613: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 16614: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 16615: if ($field eq 'screenshot') {
16616: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
16617: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 16618: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 16619: }
16620: }
16621: }
16622: }
16623: }
16624: }
1.315 raeburn 16625: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
16626: my (@statuses,%usertypeshash,@overrides);
16627: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
16628: @statuses = @{$types};
16629: if (ref($usertypes) eq 'HASH') {
16630: %usertypeshash = %{$usertypes};
16631: }
16632: }
16633: if (@statuses) {
16634: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
16635: foreach my $type (@possoverrides) {
16636: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
16637: push(@overrides,$type);
16638: }
16639: }
16640: if (@overrides) {
16641: foreach my $type (@overrides) {
16642: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
16643: foreach my $item (@contacts) {
16644: if (grep(/^\Q$item\E$/,@standard)) {
16645: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
16646: $newsetting{'override_'.$type}{$item} = 1;
16647: } else {
16648: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
16649: $newsetting{'override_'.$type}{$item} = 0;
16650: }
16651: }
16652: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
16653: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16654: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
16655: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
16656: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
16657: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
16658: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
16659: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
16660: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
16661: }
16662: }
16663: }
16664: }
1.28 raeburn 16665: if (keys(%currsetting) > 0) {
16666: foreach my $item (@contacts) {
16667: if ($to{$item} ne $currsetting{$item}) {
16668: $changes{$item} = 1;
16669: }
16670: }
16671: foreach my $type (@mailings) {
16672: foreach my $item (@contacts) {
16673: if (ref($currsetting{$type}) eq 'HASH') {
16674: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
16675: push(@{$changes{$type}},$item);
16676: }
16677: } else {
16678: push(@{$changes{$type}},@{$newsetting{$type}});
16679: }
16680: }
16681: if ($others{$type} ne $currsetting{$type}{'others'}) {
16682: push(@{$changes{$type}},'others');
16683: }
1.289 raeburn 16684: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16685: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
16686: push(@{$changes{$type}},'bcc');
16687: }
1.286 raeburn 16688: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
16689: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
16690: push(@{$changes{$type}},'include');
16691: }
16692: }
16693: }
16694: if (ref($fields) eq 'ARRAY') {
16695: if (ref($currsetting{'helpform'}) eq 'HASH') {
16696: foreach my $field (@{$fields}) {
16697: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
16698: push(@{$changes{'helpform'}},$field);
16699: }
16700: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16701: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
16702: push(@{$changes{'helpform'}},'maxsize');
16703: }
16704: }
16705: }
16706: } else {
16707: foreach my $field (@{$fields}) {
16708: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16709: push(@{$changes{'helpform'}},$field);
16710: }
16711: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16712: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16713: push(@{$changes{'helpform'}},'maxsize');
16714: }
16715: }
16716: }
1.134 raeburn 16717: }
1.28 raeburn 16718: }
1.315 raeburn 16719: if (@statuses) {
16720: if (ref($currsetting{'overrides'}) eq 'HASH') {
16721: foreach my $key (keys(%{$currsetting{'overrides'}})) {
16722: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
16723: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
16724: foreach my $item (@contacts,'bcc','others','include') {
16725: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
16726: push(@{$changes{'overrides'}},$key);
16727: last;
16728: }
16729: }
16730: } else {
16731: push(@{$changes{'overrides'}},$key);
16732: }
16733: }
16734: }
16735: foreach my $key (@overrides) {
16736: unless (exists($currsetting{'overrides'}{$key})) {
16737: push(@{$changes{'overrides'}},$key);
16738: }
16739: }
16740: } else {
16741: foreach my $key (@overrides) {
16742: push(@{$changes{'overrides'}},$key);
16743: }
16744: }
16745: }
1.340 raeburn 16746: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
16747: foreach my $key ('excluded','weights','threshold','sysmail') {
16748: if ($key eq 'excluded') {
16749: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16750: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
16751: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16752: (@{$currsetting{'lonstatus'}{$key}})) {
16753: my @diffs =
16754: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
16755: $currsetting{'lonstatus'}{$key});
16756: if (@diffs) {
16757: push(@{$changes{'lonstatus'}},$key);
16758: }
16759: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
16760: push(@{$changes{'lonstatus'}},$key);
16761: }
16762: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
16763: (@{$currsetting{'lonstatus'}{$key}})) {
16764: push(@{$changes{'lonstatus'}},$key);
16765: }
16766: } elsif ($key eq 'weights') {
16767: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
16768: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
16769: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16770: foreach my $type ('E','W','N','U') {
1.340 raeburn 16771: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
16772: $currsetting{'lonstatus'}{$key}{$type}) {
16773: push(@{$changes{'lonstatus'}},$key);
16774: last;
16775: }
16776: }
16777: } else {
1.341 raeburn 16778: foreach my $type ('E','W','N','U') {
1.340 raeburn 16779: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
16780: push(@{$changes{'lonstatus'}},$key);
16781: last;
16782: }
16783: }
16784: }
16785: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 16786: foreach my $type ('E','W','N','U') {
1.340 raeburn 16787: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
16788: push(@{$changes{'lonstatus'}},$key);
16789: last;
16790: }
16791: }
16792: }
16793: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
16794: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16795: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16796: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
16797: push(@{$changes{'lonstatus'}},$key);
16798: }
16799: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
16800: push(@{$changes{'lonstatus'}},$key);
16801: }
16802: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
16803: push(@{$changes{'lonstatus'}},$key);
16804: }
16805: }
16806: }
16807: } else {
16808: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16809: foreach my $key ('excluded','weights','threshold','sysmail') {
16810: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16811: push(@{$changes{'lonstatus'}},$key);
16812: }
16813: }
16814: }
16815: }
1.28 raeburn 16816: } else {
16817: my %default;
16818: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
16819: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
16820: $default{'errormail'} = 'adminemail';
16821: $default{'packagesmail'} = 'adminemail';
16822: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 16823: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 16824: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 16825: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 16826: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 16827: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 16828: foreach my $item (@contacts) {
16829: if ($to{$item} ne $default{$item}) {
1.286 raeburn 16830: $changes{$item} = 1;
1.203 raeburn 16831: }
1.28 raeburn 16832: }
16833: foreach my $type (@mailings) {
16834: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
16835: push(@{$changes{$type}},@{$newsetting{$type}});
16836: }
16837: if ($others{$type} ne '') {
16838: push(@{$changes{$type}},'others');
1.134 raeburn 16839: }
1.286 raeburn 16840: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16841: if ($bcc{$type} ne '') {
16842: push(@{$changes{$type}},'bcc');
16843: }
1.286 raeburn 16844: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
16845: push(@{$changes{$type}},'include');
16846: }
1.134 raeburn 16847: }
1.28 raeburn 16848: }
1.286 raeburn 16849: if (ref($fields) eq 'ARRAY') {
16850: foreach my $field (@{$fields}) {
16851: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
16852: push(@{$changes{'helpform'}},$field);
16853: }
16854: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
16855: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
16856: push(@{$changes{'helpform'}},'maxsize');
16857: }
16858: }
16859: }
1.289 raeburn 16860: }
1.340 raeburn 16861: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
16862: foreach my $key ('excluded','weights','threshold','sysmail') {
16863: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
16864: push(@{$changes{'lonstatus'}},$key);
16865: }
16866: }
16867: }
1.28 raeburn 16868: }
1.203 raeburn 16869: foreach my $item (@toggles) {
16870: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
16871: $changes{$item} = 1;
16872: } elsif ((!$env{'form.'.$item}) &&
16873: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
16874: $changes{$item} = 1;
16875: }
16876: }
1.28 raeburn 16877: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
16878: $dom);
16879: if ($putresult eq 'ok') {
16880: if (keys(%changes) > 0) {
1.205 raeburn 16881: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16882: if (ref($lastactref) eq 'HASH') {
16883: $lastactref->{'domainconfig'} = 1;
16884: }
1.28 raeburn 16885: my ($titles,$short_titles) = &contact_titles();
16886: $resulttext = &mt('Changes made:').'<ul>';
16887: foreach my $item (@contacts) {
16888: if ($changes{$item}) {
16889: $resulttext .= '<li>'.$titles->{$item}.
16890: &mt(' set to: ').
16891: '<span class="LC_cusr_emph">'.
16892: $to{$item}.'</span></li>';
16893: }
16894: }
16895: foreach my $type (@mailings) {
16896: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 16897: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 16898: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 16899: } else {
16900: $resulttext .= '<li>'.$titles->{$type}.': ';
16901: }
1.28 raeburn 16902: my @text;
16903: foreach my $item (@{$newsetting{$type}}) {
16904: push(@text,$short_titles->{$item});
16905: }
16906: if ($others{$type} ne '') {
16907: push(@text,$others{$type});
16908: }
1.286 raeburn 16909: if (@text) {
16910: $resulttext .= '<span class="LC_cusr_emph">'.
16911: join(', ',@text).'</span>';
16912: }
16913: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 16914: if ($bcc{$type} ne '') {
1.286 raeburn 16915: my $bcctext;
16916: if (@text) {
1.289 raeburn 16917: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 16918: } else {
16919: $bcctext = '(Bcc)';
16920: }
16921: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
16922: } elsif (!@text) {
16923: $resulttext .= &mt('No one');
16924: }
1.289 raeburn 16925: if ($includestr{$type} ne '') {
1.286 raeburn 16926: if ($includeloc{$type} eq 'b') {
16927: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
16928: } elsif ($includeloc{$type} eq 's') {
16929: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
16930: }
1.134 raeburn 16931: }
1.286 raeburn 16932: } elsif (!@text) {
16933: $resulttext .= &mt('No recipients');
1.134 raeburn 16934: }
16935: $resulttext .= '</li>';
1.28 raeburn 16936: }
16937: }
1.315 raeburn 16938: if (ref($changes{'overrides'}) eq 'ARRAY') {
16939: my @deletions;
16940: foreach my $type (@{$changes{'overrides'}}) {
16941: if ($usertypeshash{$type}) {
16942: if (grep(/^\Q$type\E/,@overrides)) {
16943: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
16944: $usertypeshash{$type}).'<ul><li>';
16945: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
16946: my @text;
16947: foreach my $item (@contacts) {
16948: if ($newsetting{'override_'.$type}{$item}) {
16949: push(@text,$short_titles->{$item});
16950: }
16951: }
16952: if ($newsetting{'override_'.$type}{'others'} ne '') {
16953: push(@text,$newsetting{'override_'.$type}{'others'});
16954: }
16955:
16956: if (@text) {
16957: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
16958: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
16959: }
16960: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
16961: my $bcctext;
16962: if (@text) {
16963: $bcctext = ' '.&mt('with Bcc to');
16964: } else {
16965: $bcctext = '(Bcc)';
16966: }
16967: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
16968: } elsif (!@text) {
16969: $resulttext .= &mt('Helpdesk e-mail sent to no one');
16970: }
16971: $resulttext .= '</li>';
16972: if ($newsetting{'override_'.$type}{'include'} ne '') {
16973: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
16974: if ($loc eq 'b') {
16975: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
16976: } elsif ($loc eq 's') {
16977: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
16978: }
16979: }
16980: }
16981: $resulttext .= '</li></ul></li>';
16982: } else {
16983: push(@deletions,$usertypeshash{$type});
16984: }
16985: }
16986: }
16987: if (@deletions) {
16988: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
16989: join(', ',@deletions)).'</li>';
16990: }
16991: }
1.203 raeburn 16992: my @offon = ('off','on');
1.340 raeburn 16993: my $corelink = &core_link_msu();
1.203 raeburn 16994: if ($changes{'reporterrors'}) {
16995: $resulttext .= '<li>'.
16996: &mt('E-mail error reports to [_1] set to "'.
16997: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 16998: $corelink).
1.203 raeburn 16999: '</li>';
17000: }
17001: if ($changes{'reportupdates'}) {
17002: $resulttext .= '<li>'.
17003: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17004: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17005: $corelink).
1.203 raeburn 17006: '</li>';
17007: }
1.340 raeburn 17008: if ($changes{'reportstatus'}) {
17009: $resulttext .= '<li>'.
17010: &mt('E-mail status if errors above threshold to [_1] set to "'.
17011: $offon[$env{'form.reportstatus'}].'".',
17012: $corelink).
17013: '</li>';
17014: }
17015: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17016: $resulttext .= '<li>'.
17017: &mt('Nightly status check e-mail settings').':<ul>';
17018: my (%defval,%use_def,%shown);
17019: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17020: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17021: $defval{'weights'} =
1.341 raeburn 17022: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17023: $defval{'excluded'} = &mt('None');
17024: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17025: foreach my $item ('threshold','sysmail','weights','excluded') {
17026: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17027: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17028: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17029: } elsif ($item eq 'weights') {
17030: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17031: foreach my $type ('E','W','N','U') {
1.340 raeburn 17032: $shown{$item} .= $lonstatus_names->{$type}.'=';
17033: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17034: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17035: } else {
17036: $shown{$item} .= $lonstatus_defs->{$type};
17037: }
17038: $shown{$item} .= ', ';
17039: }
17040: $shown{$item} =~ s/, $//;
17041: } else {
17042: $shown{$item} = $defval{$item};
17043: }
17044: } elsif ($item eq 'excluded') {
17045: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17046: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17047: } else {
17048: $shown{$item} = $defval{$item};
17049: }
17050: }
17051: } else {
17052: $shown{$item} = $defval{$item};
17053: }
17054: }
17055: } else {
17056: foreach my $item ('threshold','weights','excluded','sysmail') {
17057: $shown{$item} = $defval{$item};
17058: }
17059: }
17060: foreach my $item ('threshold','weights','excluded','sysmail') {
17061: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17062: $shown{$item}).'</li>';
17063: }
17064: $resulttext .= '</ul></li>';
17065: }
1.286 raeburn 17066: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17067: my (@optional,@required,@unused,$maxsizechg);
17068: foreach my $field (@{$changes{'helpform'}}) {
17069: if ($field eq 'maxsize') {
17070: $maxsizechg = 1;
17071: next;
17072: }
17073: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17074: push(@optional,$field);
1.286 raeburn 17075: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17076: push(@unused,$field);
17077: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17078: push(@required,$field);
1.286 raeburn 17079: }
17080: }
17081: if (@optional) {
17082: $resulttext .= '<li>'.
17083: &mt('Help form fields changed to "Optional": [_1].',
17084: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17085: '</li>';
17086: }
17087: if (@required) {
17088: $resulttext .= '<li>'.
17089: &mt('Help form fields changed to "Required": [_1].',
17090: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17091: '</li>';
17092: }
17093: if (@unused) {
17094: $resulttext .= '<li>'.
17095: &mt('Help form fields changed to "Not shown": [_1].',
17096: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17097: '</li>';
17098: }
17099: if ($maxsizechg) {
17100: $resulttext .= '<li>'.
17101: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17102: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17103: '</li>';
17104: }
17105: }
1.28 raeburn 17106: $resulttext .= '</ul>';
17107: } else {
1.288 raeburn 17108: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17109: }
17110: } else {
17111: $resulttext = '<span class="LC_error">'.
17112: &mt('An error occurred: [_1].',$putresult).'</span>';
17113: }
17114: return $resulttext;
17115: }
17116:
1.357 raeburn 17117: sub modify_privacy {
17118: my ($dom,%domconfig) = @_;
17119: my ($resulttext,%current,%changes);
17120: if (ref($domconfig{'privacy'}) eq 'HASH') {
17121: %current = %{$domconfig{'privacy'}};
17122: }
17123: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17124: my @items = ('domain','author','course','community');
17125: my %names = &Apache::lonlocal::texthash (
17126: domain => 'Assigned domain role(s)',
17127: author => 'Assigned co-author role(s)',
17128: course => 'Assigned course role(s)',
1.416 raeburn 17129: community => 'Assigned community role(s)',
1.357 raeburn 17130: );
17131: my %roles = &Apache::lonlocal::texthash (
17132: domain => 'Domain role',
17133: author => 'Co-author role',
17134: course => 'Course role',
17135: community => 'Community role',
17136: );
17137: my %titles = &Apache::lonlocal::texthash (
17138: approval => 'Approval for role in different domain',
17139: othdom => 'User information available in other domain',
17140: priv => 'Information viewable by privileged user in same domain',
17141: unpriv => 'Information viewable by unprivileged user in same domain',
17142: instdom => 'Other domain shares institution/provider',
17143: extdom => 'Other domain has different institution/provider',
17144: none => 'Not allowed',
17145: user => 'User authorizes',
17146: domain => 'Domain Coordinator authorizes',
17147: auto => 'Unrestricted',
1.418 raeburn 17148: notify => 'Notify when role needs authorization',
1.357 raeburn 17149: );
17150: my %fieldnames = &Apache::lonlocal::texthash (
17151: id => 'Student/Employee ID',
17152: permanentemail => 'E-mail address',
17153: lastname => 'Last Name',
17154: firstname => 'First Name',
17155: middlename => 'Middle Name',
17156: generation => 'Generation',
17157: );
17158: my ($othertitle,$usertypes,$types) =
17159: &Apache::loncommon::sorted_inst_types($dom);
17160: my (%by_ip,%by_location,@intdoms,@instdoms);
17161: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17162:
17163: my %privacyhash = (
17164: 'approval' => {
17165: instdom => {},
17166: extdom => {},
17167: },
17168: 'othdom' => {},
17169: 'priv' => {},
17170: 'unpriv' => {},
17171: );
17172: foreach my $item (@items) {
17173: if (@instdoms > 1) {
1.416 raeburn 17174: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17175: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17176: }
17177: if (ref($current{'approval'}) eq 'HASH') {
17178: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17179: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17180: $changes{'approval'} = 1;
17181: }
17182: }
17183: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17184: $changes{'approval'} = 1;
17185: }
17186: }
17187: if (keys(%by_location) > 0) {
17188: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17189: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17190: }
17191: if (ref($current{'approval'}) eq 'HASH') {
17192: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17193: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17194: $changes{'approval'} = 1;
17195: }
17196: }
17197: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17198: $changes{'approval'} = 1;
17199: }
17200: }
17201: foreach my $status ('priv','unpriv') {
17202: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17203: my @newvalues;
17204: foreach my $field (@possibles) {
17205: if (grep(/^\Q$field\E$/,@fields)) {
17206: $privacyhash{$status}{$item}{$field} = 1;
17207: push(@newvalues,$field);
17208: }
17209: }
17210: @newvalues = sort(@newvalues);
17211: if (ref($current{$status}) eq 'HASH') {
17212: if (ref($current{$status}{$item}) eq 'HASH') {
17213: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17214: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17215: if (@diffs > 0) {
17216: $changes{$status} = 1;
17217: }
17218: }
17219: } else {
17220: my @stdfields;
17221: foreach my $field (@fields) {
17222: if ($field eq 'id') {
17223: next if ($status eq 'unpriv');
17224: next if (($status eq 'priv') && ($item eq 'community'));
17225: }
17226: push(@stdfields,$field);
17227: }
17228: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17229: if (@diffs > 0) {
17230: $changes{$status} = 1;
17231: }
17232: }
17233: }
17234: }
17235: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17236: my @statuses;
17237: if (ref($types) eq 'ARRAY') {
17238: @statuses = @{$types};
17239: }
17240: foreach my $type (@statuses,'default') {
17241: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17242: my @newvalues;
17243: foreach my $field (sort(@possfields)) {
17244: if (grep(/^\Q$field\E$/,@fields)) {
17245: $privacyhash{'othdom'}{$type}{$field} = 1;
17246: push(@newvalues,$field);
17247: }
17248: }
17249: @newvalues = sort(@newvalues);
17250: if (ref($current{'othdom'}) eq 'HASH') {
17251: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17252: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17253: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17254: if (@diffs > 0) {
17255: $changes{'othdom'} = 1;
17256: }
17257: }
17258: } else {
17259: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17260: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17261: if (@diffs > 0) {
17262: $changes{'othdom'} = 1;
17263: }
17264: }
17265: }
1.417 raeburn 17266: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17267: my %notify;
17268: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17269: if (exists($domcoords{$possdc})) {
17270: $notify{$possdc} = 1;
17271: }
17272: }
17273: my $notify = join(',',sort(keys(%notify)));
17274: if ($current{'notify'} ne $notify) {
17275: $changes{'notify'} = 1;
17276: }
17277: $privacyhash{'notify'} = $notify;
1.357 raeburn 17278: }
17279: my %confighash = (
17280: privacy => \%privacyhash,
17281: );
17282: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17283: if ($putresult eq 'ok') {
17284: if (keys(%changes) > 0) {
17285: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17286: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17287: if ($changes{$key}) {
17288: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17289: if ($key eq 'approval') {
17290: if (keys(%{$privacyhash{$key}{instdom}})) {
17291: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17292: foreach my $item (@items) {
17293: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17294: }
17295: $resulttext .= '</ul></li>';
17296: }
17297: if (keys(%{$privacyhash{$key}{extdom}})) {
17298: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17299: foreach my $item (@items) {
17300: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17301: }
17302: $resulttext .= '</ul></li>';
17303: }
1.417 raeburn 17304: } elsif ($key eq 'notify') {
17305: if ($privacyhash{$key}) {
17306: foreach my $dc (split(/,/,$privacyhash{$key})) {
17307: my ($dcname,$dcdom) = split(/:/,$dc);
17308: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17309: }
17310: } else {
17311: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17312: }
1.357 raeburn 17313: } elsif ($key eq 'othdom') {
17314: my @statuses;
17315: if (ref($types) eq 'ARRAY') {
17316: @statuses = @{$types};
17317: }
17318: if (ref($privacyhash{$key}) eq 'HASH') {
17319: foreach my $status (@statuses,'default') {
17320: if ($status eq 'default') {
17321: $resulttext .= '<li>'.$othertitle.': ';
17322: } elsif (ref($usertypes) eq 'HASH') {
17323: $resulttext .= '<li>'.$usertypes->{$status}.': ';
17324: } else {
17325: next;
17326: }
17327: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
17328: if (keys(%{$privacyhash{$key}{$status}})) {
17329: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
17330: } else {
17331: $resulttext .= &mt('none');
17332: }
17333: }
17334: $resulttext .= '</li>';
17335: }
17336: }
17337: } else {
17338: foreach my $item (@items) {
17339: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
17340: $resulttext .= '<li>'.$names{$item}.': ';
17341: if (keys(%{$privacyhash{$key}{$item}})) {
17342: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
17343: } else {
17344: $resulttext .= &mt('none');
17345: }
17346: $resulttext .= '</li>';
17347: }
17348: }
17349: }
17350: $resulttext .= '</ul></li>';
17351: }
17352: }
1.421 raeburn 17353: $resulttext .= '</ul>';
1.357 raeburn 17354: } else {
17355: $resulttext = &mt('No changes made to user information settings');
17356: }
17357: } else {
17358: $resulttext = '<span class="LC_error">'.
17359: &mt('An error occurred: [_1]',$putresult).'</span>';
17360: }
17361: return $resulttext;
17362: }
17363:
1.354 raeburn 17364: sub modify_passwords {
17365: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 17366: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
17367: $updatedefaults,$updateconf);
1.354 raeburn 17368: my $customfn = 'resetpw.html';
17369: if (ref($domconfig{'passwords'}) eq 'HASH') {
17370: %current = %{$domconfig{'passwords'}};
17371: }
17372: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
17373: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17374: if (ref($types) eq 'ARRAY') {
17375: @oktypes = @{$types};
17376: }
17377: push(@oktypes,'default');
17378:
17379: my %titles = &Apache::lonlocal::texthash (
17380: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
17381: intauth_check => 'Check bcrypt cost if authenticated',
17382: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
17383: permanent => 'Permanent e-mail address',
17384: critical => 'Critical notification address',
17385: notify => 'Notification address',
17386: min => 'Minimum password length',
17387: max => 'Maximum password length',
17388: chars => 'Required characters',
17389: expire => 'Password expiration (days)',
1.356 raeburn 17390: numsaved => 'Number of previous passwords to save',
1.354 raeburn 17391: reset => 'Resetting Forgotten Password',
17392: intauth => 'Encryption of Stored Passwords (Internal Auth)',
17393: rules => 'Rules for LON-CAPA Passwords',
17394: crsownerchg => 'Course Owner Changing Student Passwords',
17395: username => 'Username',
17396: email => 'E-mail address',
17397: );
17398:
17399: #
17400: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
17401: #
17402: my (%curr_defaults,%save_defaults);
17403: if (ref($domconfig{'defaults'}) eq 'HASH') {
17404: foreach my $key (keys(%{$domconfig{'defaults'}})) {
17405: if ($key =~ /^intauth_(cost|check|switch)$/) {
17406: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
17407: } else {
17408: $save_defaults{$key} = $domconfig{'defaults'}{$key};
17409: }
17410: }
17411: }
17412: my %staticdefaults = (
17413: 'resetlink' => 2,
17414: 'resetcase' => \@oktypes,
17415: 'resetprelink' => 'both',
17416: 'resetemail' => ['critical','notify','permanent'],
17417: 'intauth_cost' => 10,
17418: 'intauth_check' => 0,
17419: 'intauth_switch' => 0,
17420: );
1.365 raeburn 17421: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 17422: foreach my $type (@oktypes) {
17423: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
17424: }
17425: my $linklife = $env{'form.passwords_link'};
17426: $linklife =~ s/^\s+|\s+$//g;
17427: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
17428: $newvalues{'resetlink'} = $linklife;
17429: if ($current{'resetlink'}) {
17430: if ($current{'resetlink'} ne $linklife) {
17431: $changes{'reset'} = 1;
17432: }
1.368 raeburn 17433: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17434: if ($staticdefaults{'resetlink'} ne $linklife) {
17435: $changes{'reset'} = 1;
17436: }
17437: }
17438: } elsif ($current{'resetlink'}) {
17439: $changes{'reset'} = 1;
17440: }
17441: my @casesens;
17442: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
17443: foreach my $case (sort(@posscase)) {
17444: if (grep(/^\Q$case\E$/,@oktypes)) {
17445: push(@casesens,$case);
17446: }
17447: }
17448: $newvalues{'resetcase'} = \@casesens;
17449: if (ref($current{'resetcase'}) eq 'ARRAY') {
17450: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
17451: if (@diffs > 0) {
17452: $changes{'reset'} = 1;
17453: }
1.368 raeburn 17454: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17455: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
17456: if (@diffs > 0) {
17457: $changes{'reset'} = 1;
17458: }
17459: }
17460: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
17461: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
17462: if (exists($current{'resetprelink'})) {
17463: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
17464: $changes{'reset'} = 1;
17465: }
1.368 raeburn 17466: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17467: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
17468: $changes{'reset'} = 1;
17469: }
17470: }
17471: } elsif ($current{'resetprelink'}) {
17472: $changes{'reset'} = 1;
17473: }
17474: foreach my $type (@oktypes) {
17475: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
17476: my @postlink;
17477: foreach my $item (sort(@possplink)) {
17478: if ($item =~ /^(email|username)$/) {
17479: push(@postlink,$item);
17480: }
17481: }
17482: $newvalues{'resetpostlink'}{$type} = \@postlink;
17483: unless ($changes{'reset'}) {
17484: if (ref($current{'resetpostlink'}) eq 'HASH') {
17485: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
17486: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
17487: if (@diffs > 0) {
17488: $changes{'reset'} = 1;
17489: }
17490: } else {
17491: $changes{'reset'} = 1;
17492: }
1.368 raeburn 17493: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17494: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
17495: if (@diffs > 0) {
17496: $changes{'reset'} = 1;
17497: }
17498: }
17499: }
17500: }
17501: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
17502: my @resetemail;
17503: foreach my $item (sort(@possemailsrc)) {
17504: if ($item =~ /^(permanent|critical|notify)$/) {
17505: push(@resetemail,$item);
17506: }
17507: }
17508: $newvalues{'resetemail'} = \@resetemail;
17509: unless ($changes{'reset'}) {
17510: if (ref($current{'resetemail'}) eq 'ARRAY') {
17511: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
17512: if (@diffs > 0) {
17513: $changes{'reset'} = 1;
17514: }
1.368 raeburn 17515: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 17516: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
17517: if (@diffs > 0) {
17518: $changes{'reset'} = 1;
17519: }
17520: }
17521: }
17522: if ($env{'form.passwords_stdtext'} == 0) {
17523: $newvalues{'resetremove'} = 1;
17524: unless ($current{'resetremove'}) {
17525: $changes{'reset'} = 1;
17526: }
17527: } elsif ($current{'resetremove'}) {
17528: $changes{'reset'} = 1;
17529: }
17530: if ($env{'form.passwords_customfile.filename'} ne '') {
17531: my $servadm = $r->dir_config('lonAdmEMail');
17532: my ($configuserok,$author_ok,$switchserver) =
17533: &config_check($dom,$confname,$servadm);
17534: my $error;
17535: if ($configuserok eq 'ok') {
17536: if ($switchserver) {
17537: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
17538: } else {
17539: if ($author_ok eq 'ok') {
1.421 raeburn 17540: my $modified = [];
1.354 raeburn 17541: my ($result,$customurl) =
1.421 raeburn 17542: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
17543: $confname,'customtext/resetpw','','',$customfn,
17544: $modified);
1.354 raeburn 17545: if ($result eq 'ok') {
17546: $newvalues{'resetcustom'} = $customurl;
17547: $changes{'reset'} = 1;
1.421 raeburn 17548: &update_modify_urls($r,$modified);
1.354 raeburn 17549: } else {
17550: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
17551: }
17552: } else {
17553: $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);
17554: }
17555: }
17556: } else {
17557: $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);
17558: }
17559: if ($error) {
17560: &Apache::lonnet::logthis($error);
17561: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17562: }
17563: } elsif ($current{'resetcustom'}) {
17564: if ($env{'form.passwords_custom_del'}) {
17565: $changes{'reset'} = 1;
17566: } else {
17567: $newvalues{'resetcustom'} = $current{'resetcustom'};
17568: }
17569: }
17570: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
17571: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
17572: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
17573: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
17574: $changes{'intauth'} = 1;
17575: }
17576: } else {
17577: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
17578: }
17579: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
17580: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
17581: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
17582: $changes{'intauth'} = 1;
17583: }
17584: } else {
17585: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17586: }
17587: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
17588: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
17589: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
17590: $changes{'intauth'} = 1;
17591: }
17592: } else {
17593: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
17594: }
17595: foreach my $item ('cost','check','switch') {
17596: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
17597: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
17598: $updatedefaults = 1;
17599: }
17600: }
1.405 raeburn 17601: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 17602: my %crsownerchg = (
17603: by => [],
17604: for => [],
17605: );
17606: foreach my $item ('by','for') {
17607: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
17608: foreach my $type (sort(@posstypes)) {
17609: if (grep(/^\Q$type\E$/,@oktypes)) {
17610: push(@{$crsownerchg{$item}},$type);
17611: }
17612: }
17613: }
17614: $newvalues{'crsownerchg'} = \%crsownerchg;
17615: if (ref($current{'crsownerchg'}) eq 'HASH') {
17616: foreach my $item ('by','for') {
17617: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
17618: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
17619: if (@diffs > 0) {
17620: $changes{'crsownerchg'} = 1;
17621: last;
17622: }
17623: }
17624: }
1.368 raeburn 17625: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 17626: foreach my $item ('by','for') {
17627: if (@{$crsownerchg{$item}} > 0) {
17628: $changes{'crsownerchg'} = 1;
17629: last;
17630: }
1.354 raeburn 17631: }
17632: }
17633:
17634: my %confighash = (
17635: defaults => \%save_defaults,
17636: passwords => \%newvalues,
17637: );
17638: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
17639:
17640: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17641: if ($putresult eq 'ok') {
17642: if (keys(%changes) > 0) {
17643: $resulttext = &mt('Changes made: ').'<ul>';
17644: foreach my $key ('reset','intauth','rules','crsownerchg') {
17645: if ($changes{$key}) {
1.355 raeburn 17646: unless ($key eq 'intauth') {
17647: $updateconf = 1;
17648: }
1.354 raeburn 17649: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17650: if ($key eq 'reset') {
17651: if ($confighash{'passwords'}{'captcha'} eq 'original') {
17652: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
17653: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
17654: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 17655: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
17656: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
17657: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
17658: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
17659: }
1.354 raeburn 17660: } else {
17661: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
17662: }
17663: if ($confighash{'passwords'}{'resetlink'}) {
17664: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
17665: } else {
17666: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
17667: &mt('Will default to 2 hours').'</li>';
17668: }
17669: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
17670: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
17671: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
17672: } else {
17673: my $casesens;
17674: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
17675: if ($type eq 'default') {
17676: $casesens .= $othertitle.', ';
17677: } elsif ($usertypes->{$type} ne '') {
17678: $casesens .= $usertypes->{$type}.', ';
17679: }
17680: }
17681: $casesens =~ s/\Q, \E$//;
17682: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
17683: }
17684: } else {
17685: $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>';
17686: }
17687: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
17688: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
17689: } else {
17690: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
17691: }
17692: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
17693: my $output;
17694: if (ref($types) eq 'ARRAY') {
17695: foreach my $type (@{$types}) {
17696: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
17697: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
17698: $output .= $usertypes->{$type}.' -- '.&mt('none');
17699: } else {
17700: $output .= $usertypes->{$type}.' -- '.
17701: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
17702: }
17703: }
17704: }
17705: }
17706: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
17707: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
17708: $output .= $othertitle.' -- '.&mt('none');
17709: } else {
17710: $output .= $othertitle.' -- '.
17711: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
17712: }
17713: }
17714: if ($output) {
17715: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
17716: } else {
17717: $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>';
17718: }
17719: } else {
17720: $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>';
17721: }
17722: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
17723: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
17724: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
17725: } else {
17726: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
17727: }
17728: } else {
1.379 raeburn 17729: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.354 raeburn 17730: }
17731: if ($confighash{'passwords'}{'resetremove'}) {
17732: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
17733: } else {
17734: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
17735: }
17736: if ($confighash{'passwords'}{'resetcustom'}) {
17737: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 17738: &mt('custom text'),600,500,undef,undef,
17739: undef,undef,'background-color:#ffffff');
17740: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 17741: } else {
17742: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
17743: }
17744: } elsif ($key eq 'intauth') {
17745: foreach my $item ('cost','switch','check') {
17746: my $value = $save_defaults{$key.'_'.$item};
17747: if ($item eq 'switch') {
17748: my %optiondesc = &Apache::lonlocal::texthash (
17749: 0 => 'No',
17750: 1 => 'Yes',
17751: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
17752: );
17753: if ($value =~ /^(0|1|2)$/) {
17754: $value = $optiondesc{$value};
17755: } else {
17756: $value = &mt('none -- defaults to No');
17757: }
17758: } elsif ($item eq 'check') {
17759: my %optiondesc = &Apache::lonlocal::texthash (
17760: 0 => 'No',
17761: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
17762: 2 => 'Yes, disallow login if stored cost is less than domain default',
17763: );
17764: if ($value =~ /^(0|1|2)$/) {
17765: $value = $optiondesc{$value};
17766: } else {
17767: $value = &mt('none -- defaults to No');
17768: }
17769: }
17770: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
17771: }
17772: } elsif ($key eq 'rules') {
1.356 raeburn 17773: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 17774: if ($confighash{'passwords'}{$rule} eq '') {
17775: if ($rule eq 'min') {
1.356 raeburn 17776: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 17777: ' '.&mt('Default of [_1] will be used',
17778: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 17779: } else {
17780: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 17781: }
17782: } else {
17783: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
17784: }
17785: }
1.370 raeburn 17786: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
17787: if (@{$confighash{'passwords'}{'chars'}} > 0) {
17788: my %rulenames = &Apache::lonlocal::texthash(
17789: uc => 'At least one upper case letter',
17790: lc => 'At least one lower case letter',
17791: num => 'At least one number',
17792: spec => 'At least one non-alphanumeric',
17793: );
17794: my $needed = '<ul><li>'.
17795: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
17796: '</li></ul>';
17797: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
17798: } else {
17799: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17800: }
17801: } else {
17802: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
17803: }
1.354 raeburn 17804: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 17805: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
17806: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
17807: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
17808: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
17809: } else {
17810: my %crsownerstr;
17811: foreach my $item ('by','for') {
17812: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
17813: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
17814: if ($type eq 'default') {
17815: $crsownerstr{$item} .= $othertitle.', ';
17816: } elsif ($usertypes->{$type} ne '') {
17817: $crsownerstr{$item} .= $usertypes->{$type}.', ';
17818: }
17819: }
17820: $crsownerstr{$item} =~ s/\Q, \E$//;
17821: }
17822: }
17823: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
17824: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
17825: }
1.354 raeburn 17826: } else {
1.359 raeburn 17827: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 17828: }
17829: }
17830: $resulttext .= '</ul></li>';
17831: }
17832: }
17833: $resulttext .= '</ul>';
17834: } else {
17835: $resulttext = &mt('No changes made to password settings');
17836: }
1.355 raeburn 17837: my $cachetime = 24*60*60;
1.354 raeburn 17838: if ($updatedefaults) {
17839: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17840: if (ref($lastactref) eq 'HASH') {
17841: $lastactref->{'domdefaults'} = 1;
17842: }
17843: }
1.355 raeburn 17844: if ($updateconf) {
17845: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
17846: if (ref($lastactref) eq 'HASH') {
17847: $lastactref->{'passwdconf'} = 1;
17848: }
17849: }
1.354 raeburn 17850: } else {
17851: $resulttext = '<span class="LC_error">'.
17852: &mt('An error occurred: [_1]',$putresult).'</span>';
17853: }
17854: if ($errors) {
17855: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17856: $errors.'</ul></p>';
17857: }
17858: return $resulttext;
17859: }
17860:
1.405 raeburn 17861: sub password_rule_changes {
17862: my ($prefix,$newvalues,$current,$changes) = @_;
17863: return unless ((ref($newvalues) eq 'HASH') &&
17864: (ref($current) eq 'HASH') &&
17865: (ref($changes) eq 'HASH'));
17866: my (@rules,%staticdefaults);
17867: if ($prefix eq 'passwords') {
17868: @rules = ('min','max','expire','numsaved');
1.421 raeburn 17869: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 17870: @rules = ('min','max');
17871: }
17872: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
17873: foreach my $rule (@rules) {
17874: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
17875: my $ruleok;
17876: if ($rule eq 'expire') {
17877: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
17878: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
17879: $ruleok = 1;
17880: }
17881: } elsif ($rule eq 'min') {
17882: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
17883: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
17884: $ruleok = 1;
17885: }
17886: }
17887: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
17888: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
17889: $ruleok = 1;
17890: }
17891: if ($ruleok) {
17892: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
17893: if (exists($current->{$rule})) {
17894: if ($newvalues->{$rule} ne $current->{$rule}) {
17895: $changes->{'rules'} = 1;
17896: }
17897: } elsif ($rule eq 'min') {
17898: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
17899: $changes->{'rules'} = 1;
17900: }
17901: } else {
17902: $changes->{'rules'} = 1;
17903: }
17904: } elsif (exists($current->{$rule})) {
17905: $changes->{'rules'} = 1;
17906: }
17907: }
17908: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
17909: my @chars;
17910: foreach my $item (sort(@posschars)) {
17911: if ($item =~ /^(uc|lc|num|spec)$/) {
17912: push(@chars,$item);
17913: }
17914: }
17915: $newvalues->{'chars'} = \@chars;
17916: unless ($changes->{'rules'}) {
17917: if (ref($current->{'chars'}) eq 'ARRAY') {
17918: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
17919: if (@diffs > 0) {
17920: $changes->{'rules'} = 1;
17921: }
17922: } else {
17923: if (@chars > 0) {
17924: $changes->{'rules'} = 1;
17925: }
17926: }
17927: }
17928: return;
17929: }
17930:
1.28 raeburn 17931: sub modify_usercreation {
1.27 raeburn 17932: my ($dom,%domconfig) = @_;
1.224 raeburn 17933: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 17934: my $warningmsg;
1.27 raeburn 17935: if (ref($domconfig{'usercreation'}) eq 'HASH') {
17936: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 17937: if ($key eq 'cancreate') {
17938: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
17939: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 17940: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
17941: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17942: } else {
1.224 raeburn 17943: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
17944: }
17945: }
17946: }
17947: } elsif ($key eq 'email_rule') {
17948: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
17949: } else {
17950: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
17951: }
1.27 raeburn 17952: }
17953: }
17954: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 17955: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 17956: my @contexts = ('author','course','requestcrs');
1.34 raeburn 17957: foreach my $item(@contexts) {
1.224 raeburn 17958: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 17959: }
1.34 raeburn 17960: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17961: foreach my $item (@contexts) {
1.224 raeburn 17962: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
17963: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 17964: }
1.27 raeburn 17965: }
1.34 raeburn 17966: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
17967: foreach my $item (@contexts) {
1.43 raeburn 17968: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 17969: if ($cancreate{$item} ne 'any') {
17970: push(@{$changes{'cancreate'}},$item);
17971: }
17972: } else {
17973: if ($cancreate{$item} ne 'none') {
17974: push(@{$changes{'cancreate'}},$item);
17975: }
1.27 raeburn 17976: }
17977: }
17978: } else {
1.43 raeburn 17979: foreach my $item (@contexts) {
1.34 raeburn 17980: push(@{$changes{'cancreate'}},$item);
17981: }
1.27 raeburn 17982: }
1.34 raeburn 17983:
1.27 raeburn 17984: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
17985: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
17986: if (!grep(/^\Q$type\E$/,@username_rule)) {
17987: push(@{$changes{'username_rule'}},$type);
17988: }
17989: }
17990: foreach my $type (@username_rule) {
17991: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
17992: push(@{$changes{'username_rule'}},$type);
17993: }
17994: }
17995: } else {
17996: push(@{$changes{'username_rule'}},@username_rule);
17997: }
17998:
1.32 raeburn 17999: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18000: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18001: if (!grep(/^\Q$type\E$/,@id_rule)) {
18002: push(@{$changes{'id_rule'}},$type);
18003: }
18004: }
18005: foreach my $type (@id_rule) {
18006: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18007: push(@{$changes{'id_rule'}},$type);
18008: }
18009: }
18010: } else {
18011: push(@{$changes{'id_rule'}},@id_rule);
18012: }
18013:
1.43 raeburn 18014: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18015: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18016: my %authhash;
1.43 raeburn 18017: foreach my $item (@authen_contexts) {
1.28 raeburn 18018: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18019: foreach my $auth (@authtypes) {
18020: if (grep(/^\Q$auth\E$/,@authallowed)) {
18021: $authhash{$item}{$auth} = 1;
18022: } else {
18023: $authhash{$item}{$auth} = 0;
18024: }
18025: }
18026: }
18027: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18028: foreach my $item (@authen_contexts) {
1.28 raeburn 18029: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18030: foreach my $auth (@authtypes) {
18031: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18032: push(@{$changes{'authtypes'}},$item);
18033: last;
18034: }
18035: }
18036: }
18037: }
18038: } else {
1.43 raeburn 18039: foreach my $item (@authen_contexts) {
1.28 raeburn 18040: push(@{$changes{'authtypes'}},$item);
18041: }
18042: }
18043:
1.224 raeburn 18044: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18045: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18046: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18047: $save_usercreate{'id_rule'} = \@id_rule;
18048: $save_usercreate{'username_rule'} = \@username_rule,
18049: $save_usercreate{'authtypes'} = \%authhash;
18050:
1.27 raeburn 18051: my %usercreation_hash = (
1.224 raeburn 18052: usercreation => \%save_usercreate,
18053: );
1.27 raeburn 18054:
18055: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18056: $dom);
1.50 raeburn 18057:
1.224 raeburn 18058: if ($putresult eq 'ok') {
18059: if (keys(%changes) > 0) {
18060: $resulttext = &mt('Changes made:').'<ul>';
18061: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18062: my %lt = &usercreation_types();
18063: foreach my $type (@{$changes{'cancreate'}}) {
18064: my $chgtext = $lt{$type}.', ';
18065: if ($cancreate{$type} eq 'none') {
18066: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18067: } elsif ($cancreate{$type} eq 'any') {
18068: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18069: } elsif ($cancreate{$type} eq 'official') {
18070: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18071: } elsif ($cancreate{$type} eq 'unofficial') {
18072: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18073: }
18074: $resulttext .= '<li>'.$chgtext.'</li>';
18075: }
18076: }
18077: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18078: my ($rules,$ruleorder) =
18079: &Apache::lonnet::inst_userrules($dom,'username');
18080: my $chgtext = '<ul>';
18081: foreach my $type (@username_rule) {
18082: if (ref($rules->{$type}) eq 'HASH') {
18083: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18084: }
18085: }
18086: $chgtext .= '</ul>';
18087: if (@username_rule > 0) {
18088: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18089: } else {
18090: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18091: }
18092: }
18093: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18094: my ($idrules,$idruleorder) =
18095: &Apache::lonnet::inst_userrules($dom,'id');
18096: my $chgtext = '<ul>';
18097: foreach my $type (@id_rule) {
18098: if (ref($idrules->{$type}) eq 'HASH') {
18099: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18100: }
18101: }
18102: $chgtext .= '</ul>';
18103: if (@id_rule > 0) {
18104: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18105: } else {
18106: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18107: }
18108: }
18109: my %authname = &authtype_names();
18110: my %context_title = &context_names();
18111: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18112: my $chgtext = '<ul>';
18113: foreach my $type (@{$changes{'authtypes'}}) {
18114: my @allowed;
18115: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18116: foreach my $auth (@authtypes) {
18117: if ($authhash{$type}{$auth}) {
18118: push(@allowed,$authname{$auth});
18119: }
18120: }
18121: if (@allowed > 0) {
18122: $chgtext .= join(', ',@allowed).'</li>';
18123: } else {
18124: $chgtext .= &mt('none').'</li>';
18125: }
18126: }
18127: $chgtext .= '</ul>';
18128: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18129: $resulttext .= '</li>';
18130: }
18131: $resulttext .= '</ul>';
18132: } else {
18133: $resulttext = &mt('No changes made to user creation settings');
18134: }
18135: } else {
18136: $resulttext = '<span class="LC_error">'.
18137: &mt('An error occurred: [_1]',$putresult).'</span>';
18138: }
18139: if ($warningmsg ne '') {
18140: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18141: }
18142: return $resulttext;
18143: }
18144:
18145: sub modify_selfcreation {
1.305 raeburn 18146: my ($dom,$lastactref,%domconfig) = @_;
18147: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18148: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18149: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18150: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18151: if (ref($typesref) eq 'ARRAY') {
18152: @types = @{$typesref};
18153: }
18154: if (ref($usertypesref) eq 'HASH') {
18155: %usertypes = %{$usertypesref};
1.228 raeburn 18156: }
1.303 raeburn 18157: $usertypes{'default'} = $othertitle;
1.224 raeburn 18158: #
18159: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18160: #
18161: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18162: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18163: if ($key eq 'cancreate') {
18164: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18165: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18166: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18167: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18168: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18169: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18170: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18171: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18172: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18173: } else {
18174: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18175: }
18176: }
18177: }
18178: } elsif ($key eq 'email_rule') {
18179: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18180: } else {
18181: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18182: }
18183: }
18184: }
18185: #
18186: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18187: #
18188: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18189: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18190: if ($key eq 'selfcreate') {
18191: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18192: } else {
18193: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18194: }
18195: }
18196: }
1.305 raeburn 18197: #
18198: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18199: #
18200: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18201: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18202: if ($key eq 'inststatusguest') {
18203: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18204: } else {
18205: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18206: }
18207: }
18208: }
1.224 raeburn 18209:
18210: my @contexts = ('selfcreate');
18211: @{$cancreate{'selfcreate'}} = ();
18212: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18213: if (@types) {
18214: @{$cancreate{'statustocreate'}} = ();
18215: }
1.236 raeburn 18216: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18217: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18218: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18219: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18220: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18221: my %selfcreatetypes = (
18222: sso => 'users authenticated by institutional single sign on',
18223: login => 'users authenticated by institutional log-in',
1.303 raeburn 18224: email => 'users verified by e-mail',
1.50 raeburn 18225: );
1.224 raeburn 18226: #
18227: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18228: # is permitted.
18229: #
1.305 raeburn 18230: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18231:
1.305 raeburn 18232: my (@statuses,%email_rule);
1.228 raeburn 18233: foreach my $item ('login','sso','email') {
1.224 raeburn 18234: if ($item eq 'email') {
1.236 raeburn 18235: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18236: if (@types) {
18237: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18238: foreach my $status (@poss_statuses) {
18239: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18240: push(@statuses,$status);
18241: }
18242: }
18243: $save_inststatus{'inststatusguest'} = \@statuses;
18244: } else {
18245: push(@statuses,'default');
18246: }
18247: if (@statuses) {
18248: my %curr_rule;
18249: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18250: foreach my $type (@statuses) {
18251: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18252: }
1.305 raeburn 18253: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18254: foreach my $type (@statuses) {
18255: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18256: }
18257: }
18258: push(@{$cancreate{'selfcreate'}},'email');
18259: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18260: my %curremaildom;
18261: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18262: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18263: }
18264: foreach my $type (@statuses) {
18265: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18266: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18267: }
18268: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18269: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18270: }
18271: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18272: #
18273: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18274: #
18275: my $chosen = $1;
18276: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18277: my $emaildom;
18278: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
18279: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
18280: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18281: if (ref($curremaildom{$type}) eq 'HASH') {
18282: if (exists($curremaildom{$type}{$chosen})) {
18283: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18284: push(@{$changes{'cancreate'}},'emaildomain');
18285: }
18286: } elsif ($emaildom ne '') {
18287: push(@{$changes{'cancreate'}},'emaildomain');
18288: }
18289: } elsif ($emaildom ne '') {
18290: push(@{$changes{'cancreate'}},'emaildomain');
18291: }
18292: }
18293: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18294: } elsif ($chosen eq 'custom') {
18295: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
18296: $email_rule{$type} = [];
18297: if (ref($emailrules) eq 'HASH') {
18298: foreach my $rule (@possemail_rules) {
18299: if (exists($emailrules->{$rule})) {
18300: push(@{$email_rule{$type}},$rule);
18301: }
18302: }
18303: }
18304: if (@{$email_rule{$type}}) {
18305: $cancreate{'emailoptions'}{$type} = 'custom';
18306: if (ref($curr_rule{$type}) eq 'ARRAY') {
18307: if (@{$curr_rule{$type}} > 0) {
18308: foreach my $rule (@{$curr_rule{$type}}) {
18309: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
18310: push(@{$changes{'email_rule'}},$type);
18311: }
18312: }
18313: }
18314: foreach my $type (@{$email_rule{$type}}) {
18315: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
18316: push(@{$changes{'email_rule'}},$type);
18317: }
18318: }
18319: } else {
18320: push(@{$changes{'email_rule'}},$type);
18321: }
18322: }
18323: } else {
18324: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
18325: }
18326: }
18327: }
18328: if (@types) {
18329: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18330: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
18331: if (@changed) {
18332: push(@{$changes{'inststatus'}},'inststatusguest');
18333: }
18334: } else {
18335: push(@{$changes{'inststatus'}},'inststatusguest');
18336: }
18337: }
18338: } else {
18339: delete($env{'form.cancreate_email'});
18340: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18341: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18342: push(@{$changes{'inststatus'}},'inststatusguest');
18343: }
18344: }
18345: }
18346: } else {
18347: $save_inststatus{'inststatusguest'} = [];
18348: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
18349: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
18350: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 18351: }
18352: }
1.224 raeburn 18353: }
18354: } else {
18355: if ($env{'form.cancreate_'.$item}) {
18356: push(@{$cancreate{'selfcreate'}},$item);
18357: }
18358: }
18359: }
1.305 raeburn 18360: my (%userinfo,%savecaptcha);
1.224 raeburn 18361: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
18362: #
1.228 raeburn 18363: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
18364: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 18365: #
1.236 raeburn 18366:
1.244 raeburn 18367: if ($env{'form.cancreate_email'}) {
1.228 raeburn 18368: push(@contexts,'emailusername');
1.305 raeburn 18369: if (@statuses) {
18370: foreach my $type (@statuses) {
1.228 raeburn 18371: if (ref($infofields) eq 'ARRAY') {
18372: foreach my $field (@{$infofields}) {
18373: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
18374: $cancreate{'emailusername'}{$type}{$field} = $1;
18375: }
18376: }
1.224 raeburn 18377: }
18378: }
18379: }
18380: #
18381: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 18382: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 18383: #
18384:
18385: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
18386: @approvalnotify = sort(@approvalnotify);
18387: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
18388: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18389: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
18390: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
18391: push(@{$changes{'cancreate'}},'notify');
18392: }
18393: } else {
18394: if ($cancreate{'notify'}{'approval'}) {
18395: push(@{$changes{'cancreate'}},'notify');
18396: }
18397: }
18398: } elsif ($cancreate{'notify'}{'approval'}) {
18399: push(@{$changes{'cancreate'}},'notify');
18400: }
18401:
18402: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
18403: }
18404: #
1.236 raeburn 18405: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 18406: # institutional log-in.
18407: #
18408: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
18409: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
18410: ($domdefaults{'auth_def'} eq 'localauth'))) {
18411: $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.').' '.
18412: &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.');
18413: }
18414: }
18415: my @fields = ('lastname','firstname','middlename','generation',
18416: 'permanentemail','id');
1.240 raeburn 18417: my @shibfields = (@fields,'inststatus');
1.224 raeburn 18418: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18419: #
18420: # Where usernames may created for institutional log-in and/or institutional single sign on:
18421: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
18422: # may self-create accounts
18423: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
18424: # which the user may supply, if institutional data is unavailable.
18425: #
18426: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 18427: if (@types) {
1.305 raeburn 18428: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
18429: push(@contexts,'statustocreate');
1.303 raeburn 18430: foreach my $type (@types) {
1.224 raeburn 18431: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
18432: foreach my $field (@fields) {
18433: if (grep(/^\Q$field\E$/,@modifiable)) {
18434: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
18435: } else {
18436: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
18437: }
18438: }
18439: }
18440: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 18441: foreach my $type (@types) {
1.224 raeburn 18442: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
18443: foreach my $field (@fields) {
18444: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
18445: $curr_usermodify{'selfcreate'}{$type}{$field}) {
18446: push(@{$changes{'selfcreate'}},$type);
18447: last;
18448: }
18449: }
18450: }
18451: }
18452: } else {
1.303 raeburn 18453: foreach my $type (@types) {
1.224 raeburn 18454: push(@{$changes{'selfcreate'}},$type);
18455: }
18456: }
18457: }
1.240 raeburn 18458: foreach my $field (@shibfields) {
18459: if ($env{'form.shibenv_'.$field} ne '') {
18460: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
18461: }
18462: }
18463: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18464: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
18465: foreach my $field (@shibfields) {
18466: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
18467: push(@{$changes{'cancreate'}},'shibenv');
18468: }
18469: }
18470: } else {
18471: foreach my $field (@shibfields) {
18472: if ($env{'form.shibenv_'.$field}) {
18473: push(@{$changes{'cancreate'}},'shibenv');
18474: last;
18475: }
18476: }
18477: }
18478: }
1.224 raeburn 18479: }
18480: foreach my $item (@contexts) {
18481: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
18482: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
18483: if (ref($cancreate{$item}) eq 'ARRAY') {
18484: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
18485: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18486: push(@{$changes{'cancreate'}},$item);
18487: }
18488: }
18489: }
18490: }
18491: if (ref($cancreate{$item}) eq 'ARRAY') {
18492: foreach my $type (@{$cancreate{$item}}) {
18493: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
18494: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18495: push(@{$changes{'cancreate'}},$item);
18496: }
18497: }
18498: }
18499: }
18500: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
18501: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 18502: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
18503: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18504: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
18505: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18506: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18507: push(@{$changes{'cancreate'}},$item);
18508: }
18509: }
18510: }
1.305 raeburn 18511: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18512: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18513: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18514: push(@{$changes{'cancreate'}},$item);
18515: }
1.224 raeburn 18516: }
18517: }
18518: }
1.305 raeburn 18519: foreach my $type (keys(%{$cancreate{$item}})) {
18520: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18521: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18522: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
18523: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 18524: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18525: push(@{$changes{'cancreate'}},$item);
18526: }
18527: }
18528: } else {
18529: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18530: push(@{$changes{'cancreate'}},$item);
18531: }
18532: }
18533: }
1.305 raeburn 18534: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18535: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 18536: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18537: push(@{$changes{'cancreate'}},$item);
18538: }
1.224 raeburn 18539: }
18540: }
18541: }
18542: }
18543: } elsif ($curr_usercreation{'cancreate'}{$item}) {
18544: if (ref($cancreate{$item}) eq 'ARRAY') {
18545: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
18546: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18547: push(@{$changes{'cancreate'}},$item);
18548: }
18549: }
1.305 raeburn 18550: }
18551: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
18552: if (ref($cancreate{$item}) eq 'HASH') {
18553: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18554: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 18555: }
18556: }
18557: } elsif ($item eq 'emailusername') {
1.228 raeburn 18558: if (ref($cancreate{$item}) eq 'HASH') {
18559: foreach my $type (keys(%{$cancreate{$item}})) {
18560: if (ref($cancreate{$item}{$type}) eq 'HASH') {
18561: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
18562: if ($cancreate{$item}{$type}{$field}) {
18563: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
18564: push(@{$changes{'cancreate'}},$item);
18565: }
18566: last;
18567: }
18568: }
18569: }
18570: }
1.224 raeburn 18571: }
18572: }
18573: }
18574: #
18575: # Populate %save_usercreate hash with updates to self-creation configuration.
18576: #
18577: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
18578: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 18579: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 18580: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
18581: if (ref($cancreate{'notify'}) eq 'HASH') {
18582: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
18583: }
1.236 raeburn 18584: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
18585: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
18586: }
1.303 raeburn 18587: if (ref($cancreate{'emailverified'}) eq 'HASH') {
18588: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
18589: }
1.305 raeburn 18590: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
18591: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
18592: }
1.303 raeburn 18593: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
18594: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
18595: }
1.224 raeburn 18596: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18597: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
18598: }
1.240 raeburn 18599: if (ref($cancreate{'shibenv'}) eq 'HASH') {
18600: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
18601: }
1.224 raeburn 18602: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 18603: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 18604:
18605: my %userconfig_hash = (
18606: usercreation => \%save_usercreate,
18607: usermodification => \%save_usermodify,
1.305 raeburn 18608: inststatus => \%save_inststatus,
1.224 raeburn 18609: );
1.305 raeburn 18610:
1.224 raeburn 18611: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
18612: $dom);
18613: #
1.305 raeburn 18614: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 18615: #
1.27 raeburn 18616: if ($putresult eq 'ok') {
18617: if (keys(%changes) > 0) {
18618: $resulttext = &mt('Changes made:').'<ul>';
18619: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 18620: my %lt = &selfcreation_types();
1.34 raeburn 18621: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 18622: my $chgtext = '';
1.45 raeburn 18623: if ($type eq 'selfcreate') {
1.50 raeburn 18624: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 18625: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 18626: } else {
1.224 raeburn 18627: $chgtext .= &mt('Self-creation of a new account is permitted for:').
18628: '<ul>';
1.50 raeburn 18629: foreach my $case (@{$cancreate{$type}}) {
18630: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
18631: }
18632: $chgtext .= '</ul>';
1.100 raeburn 18633: if (ref($cancreate{$type}) eq 'ARRAY') {
18634: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
18635: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
18636: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 18637: $chgtext .= '<span class="LC_warning">'.
18638: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
18639: '</span><br />';
18640: }
18641: }
18642: }
18643: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 18644: if (!@statuses) {
18645: $chgtext .= '<span class="LC_warning">'.
18646: &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.").
18647: '</span><br />';
1.303 raeburn 18648:
1.100 raeburn 18649: }
18650: }
18651: }
1.43 raeburn 18652: }
1.240 raeburn 18653: } elsif ($type eq 'shibenv') {
18654: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 18655: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 18656: } else {
18657: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
18658: '<ul>';
18659: foreach my $field (@shibfields) {
18660: next if ($cancreate{$type}{$field} eq '');
18661: if ($field eq 'inststatus') {
18662: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
18663: } else {
18664: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
18665: }
18666: }
18667: $chgtext .= '</ul>';
1.303 raeburn 18668: }
1.93 raeburn 18669: } elsif ($type eq 'statustocreate') {
1.96 raeburn 18670: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
18671: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
18672: if (@{$cancreate{'selfcreate'}} > 0) {
18673: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 18674: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 18675: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 18676: $chgtext .= '<br />'.
18677: '<span class="LC_warning">'.
18678: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
18679: '</span>';
18680: }
1.303 raeburn 18681: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 18682: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 18683: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
18684: } else {
18685: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
18686: }
18687: $chgtext .= '<ul>';
18688: foreach my $case (@{$cancreate{$type}}) {
18689: if ($case eq 'default') {
18690: $chgtext .= '<li>'.$othertitle.'</li>';
18691: } else {
1.303 raeburn 18692: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 18693: }
18694: }
1.100 raeburn 18695: $chgtext .= '</ul>';
18696: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 18697: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 18698: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
18699: '</span>';
1.100 raeburn 18700: }
18701: }
18702: } else {
18703: if (@{$cancreate{$type}} == 0) {
18704: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
18705: } else {
18706: $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 18707: }
18708: }
1.303 raeburn 18709: $chgtext .= '<br />';
1.93 raeburn 18710: }
1.236 raeburn 18711: } elsif ($type eq 'selfcreateprocessing') {
18712: my %choices = &Apache::lonlocal::texthash (
18713: automatic => 'Automatic approval',
18714: approval => 'Queued for approval',
18715: );
1.305 raeburn 18716: if (@types) {
18717: if (@statuses) {
1.303 raeburn 18718: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 18719: '<ul>';
1.305 raeburn 18720: foreach my $status (@statuses) {
18721: if ($status eq 'default') {
18722: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18723: } else {
1.305 raeburn 18724: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 18725: }
18726: }
18727: $chgtext .= '</ul>';
18728: }
18729: } else {
18730: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
18731: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
18732: }
18733: } elsif ($type eq 'emailverified') {
18734: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 18735: all => 'Same as e-mail',
18736: first => 'Omit @domain',
18737: free => 'Free to choose',
1.303 raeburn 18738: );
1.305 raeburn 18739: if (@types) {
18740: if (@statuses) {
1.303 raeburn 18741: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
18742: '<ul>';
1.305 raeburn 18743: foreach my $status (@statuses) {
1.362 raeburn 18744: if ($status eq 'default') {
1.305 raeburn 18745: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18746: } else {
1.305 raeburn 18747: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 18748: }
18749: }
18750: $chgtext .= '</ul>';
18751: }
18752: } else {
1.305 raeburn 18753: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 18754: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 18755: }
1.305 raeburn 18756: } elsif ($type eq 'emailoptions') {
18757: my %options = &Apache::lonlocal::texthash (
18758: any => 'Any e-mail',
18759: inst => 'Institutional only',
18760: noninst => 'Non-institutional only',
18761: custom => 'Custom restrictions',
18762: );
18763: if (@types) {
18764: if (@statuses) {
18765: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
18766: '<ul>';
18767: foreach my $status (@statuses) {
18768: if ($type eq 'default') {
18769: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
18770: } else {
18771: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 18772: }
18773: }
1.305 raeburn 18774: $chgtext .= '</ul>';
18775: }
18776: } else {
18777: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
18778: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
18779: } else {
18780: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
18781: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 18782: }
1.305 raeburn 18783: }
18784: } elsif ($type eq 'emaildomain') {
18785: my $output;
18786: if (@statuses) {
18787: foreach my $type (@statuses) {
18788: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
18789: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
18790: if ($type eq 'default') {
18791: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18792: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18793: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18794: } else {
18795: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
18796: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
18797: }
1.303 raeburn 18798: } else {
1.305 raeburn 18799: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18800: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
18801: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18802: } else {
18803: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 18804: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 18805: }
1.303 raeburn 18806: }
1.305 raeburn 18807: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
18808: if ($type eq 'default') {
18809: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18810: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18811: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
18812: } else {
18813: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
18814: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
18815: }
1.303 raeburn 18816: } else {
1.305 raeburn 18817: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
18818: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
18819: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
18820: } else {
18821: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 18822: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 18823: }
1.303 raeburn 18824: }
18825: }
18826: }
18827: }
1.305 raeburn 18828: }
18829: if ($output ne '') {
18830: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
18831: '<ul>'.$output.'</ul>';
1.236 raeburn 18832: }
1.165 raeburn 18833: } elsif ($type eq 'captcha') {
1.224 raeburn 18834: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 18835: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
18836: } else {
18837: my %captchas = &captcha_phrases();
1.224 raeburn 18838: if ($captchas{$savecaptcha{$type}}) {
18839: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 18840: } else {
1.210 raeburn 18841: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 18842: }
18843: }
18844: } elsif ($type eq 'recaptchakeys') {
18845: my ($privkey,$pubkey);
1.224 raeburn 18846: if (ref($savecaptcha{$type}) eq 'HASH') {
18847: $pubkey = $savecaptcha{$type}{'public'};
18848: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 18849: }
18850: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
18851: if (!$pubkey) {
18852: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
18853: } else {
18854: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
18855: }
18856: if (!$privkey) {
18857: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
18858: } else {
18859: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
18860: }
18861: $chgtext .= '</ul>';
1.269 raeburn 18862: } elsif ($type eq 'recaptchaversion') {
18863: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 18864: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 18865: }
1.224 raeburn 18866: } elsif ($type eq 'emailusername') {
18867: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 18868: if (@statuses) {
18869: foreach my $type (@statuses) {
1.228 raeburn 18870: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
18871: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 18872: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 18873: '<ul>';
18874: foreach my $field (@{$infofields}) {
18875: if ($cancreate{'emailusername'}{$type}{$field}) {
18876: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
18877: }
18878: }
1.245 raeburn 18879: $chgtext .= '</ul>';
18880: } else {
1.303 raeburn 18881: $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.228 raeburn 18882: }
18883: } else {
1.303 raeburn 18884: $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.224 raeburn 18885: }
18886: }
18887: }
18888: }
18889: } elsif ($type eq 'notify') {
1.303 raeburn 18890: my $numapprove = 0;
1.224 raeburn 18891: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18892: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
18893: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 18894: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
18895: $numapprove ++;
1.224 raeburn 18896: }
18897: }
1.43 raeburn 18898: }
1.303 raeburn 18899: unless ($numapprove) {
18900: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
18901: }
1.34 raeburn 18902: }
1.224 raeburn 18903: if ($chgtext) {
18904: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 18905: }
18906: }
18907: }
1.305 raeburn 18908: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 18909: my ($emailrules,$emailruleorder) =
18910: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 18911: foreach my $type (@{$changes{'email_rule'}}) {
18912: if (ref($email_rule{$type}) eq 'ARRAY') {
18913: my $chgtext = '<ul>';
18914: foreach my $rule (@{$email_rule{$type}}) {
18915: if (ref($emailrules->{$rule}) eq 'HASH') {
18916: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
18917: }
18918: }
18919: $chgtext .= '</ul>';
1.310 raeburn 18920: my $typename;
1.305 raeburn 18921: if (@types) {
18922: if ($type eq 'default') {
18923: $typename = $othertitle;
18924: } else {
18925: $typename = $usertypes{$type};
18926: }
18927: $chgtext .= &mt('(Affiliation: [_1])',$typename);
18928: }
18929: if (@{$email_rule{$type}} > 0) {
18930: $resulttext .= '<li>'.
18931: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
18932: $usertypes{$type}).
18933: $chgtext.
18934: '</li>';
18935: } else {
18936: $resulttext .= '<li>'.
1.310 raeburn 18937: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
1.305 raeburn 18938: '</li>'.
1.310 raeburn 18939: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 18940: }
1.43 raeburn 18941: }
18942: }
1.305 raeburn 18943: }
18944: if (ref($changes{'inststatus'}) eq 'ARRAY') {
18945: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
18946: if (@{$save_inststatus{'inststatusguest'}} > 0) {
18947: my $chgtext = '<ul>';
18948: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
18949: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
18950: }
18951: $chgtext .= '</ul>';
18952: $resulttext .= '<li>'.
18953: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
18954: $chgtext.
18955: '</li>';
18956: } else {
18957: $resulttext .= '<li>'.
18958: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
18959: '</li>';
18960: }
1.43 raeburn 18961: }
18962: }
1.224 raeburn 18963: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
18964: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
18965: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
18966: foreach my $type (@{$changes{'selfcreate'}}) {
18967: my $typename = $type;
1.303 raeburn 18968: if (keys(%usertypes) > 0) {
18969: if ($usertypes{$type} ne '') {
18970: $typename = $usertypes{$type};
1.224 raeburn 18971: }
18972: }
18973: my @modifiable;
18974: $resulttext .= '<li>'.
18975: &mt('Self-creation of account by users with status: [_1]',
18976: '<span class="LC_cusr_emph">'.$typename.'</span>').
18977: ' - '.&mt('modifiable fields (if institutional data blank): ');
18978: foreach my $field (@fields) {
18979: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
18980: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 18981: }
18982: }
1.224 raeburn 18983: if (@modifiable > 0) {
18984: $resulttext .= join(', ',@modifiable);
1.43 raeburn 18985: } else {
1.224 raeburn 18986: $resulttext .= &mt('none');
1.43 raeburn 18987: }
1.224 raeburn 18988: $resulttext .= '</li>';
1.28 raeburn 18989: }
1.224 raeburn 18990: $resulttext .= '</ul></li>';
1.28 raeburn 18991: }
1.27 raeburn 18992: $resulttext .= '</ul>';
1.305 raeburn 18993: my $cachetime = 24*60*60;
18994: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
18995: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18996: if (ref($lastactref) eq 'HASH') {
18997: $lastactref->{'domdefaults'} = 1;
18998: }
1.27 raeburn 18999: } else {
1.224 raeburn 19000: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19001: }
19002: } else {
19003: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19004: &mt('An error occurred: [_1]',$putresult).'</span>';
19005: }
1.43 raeburn 19006: if ($warningmsg ne '') {
19007: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19008: }
1.23 raeburn 19009: return $resulttext;
19010: }
19011:
1.165 raeburn 19012: sub process_captcha {
1.369 raeburn 19013: my ($container,$changes,$newsettings,$currsettings) = @_;
19014: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19015: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19016: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19017: $newsettings->{'captcha'} = 'original';
19018: }
1.369 raeburn 19019: my %current;
19020: if (ref($currsettings) eq 'HASH') {
19021: %current = %{$currsettings};
19022: }
19023: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19024: if ($container eq 'cancreate') {
1.169 raeburn 19025: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19026: push(@{$changes->{'cancreate'}},'captcha');
19027: } elsif (!defined($changes->{'cancreate'})) {
19028: $changes->{'cancreate'} = ['captcha'];
19029: }
1.368 raeburn 19030: } elsif ($container eq 'passwords') {
19031: $changes->{'reset'} = 1;
1.169 raeburn 19032: } else {
19033: $changes->{'captcha'} = 1;
1.165 raeburn 19034: }
19035: }
1.269 raeburn 19036: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19037: if ($newsettings->{'captcha'} eq 'recaptcha') {
19038: $newpub = $env{'form.'.$container.'_recaptchapub'};
19039: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19040: $newpub =~ s/[^\w\-]//g;
19041: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19042: $newsettings->{'recaptchakeys'} = {
19043: public => $newpub,
19044: private => $newpriv,
19045: };
1.269 raeburn 19046: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19047: $newversion =~ s/\D//g;
19048: if ($newversion ne '2') {
19049: $newversion = 1;
19050: }
19051: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19052: }
1.369 raeburn 19053: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19054: $currpub = $current{'recaptchakeys'}{'public'};
19055: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19056: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19057: $newsettings->{'recaptchakeys'} = {
19058: public => '',
19059: private => '',
19060: }
19061: }
1.165 raeburn 19062: }
1.369 raeburn 19063: if ($current{'captcha'} eq 'recaptcha') {
19064: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19065: if ($currversion ne '2') {
19066: $currversion = 1;
19067: }
19068: }
19069: if ($currversion ne $newversion) {
19070: if ($container eq 'cancreate') {
19071: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19072: push(@{$changes->{'cancreate'}},'recaptchaversion');
19073: } elsif (!defined($changes->{'cancreate'})) {
19074: $changes->{'cancreate'} = ['recaptchaversion'];
19075: }
1.368 raeburn 19076: } elsif ($container eq 'passwords') {
19077: $changes->{'reset'} = 1;
1.269 raeburn 19078: } else {
19079: $changes->{'recaptchaversion'} = 1;
19080: }
19081: }
1.165 raeburn 19082: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19083: if ($container eq 'cancreate') {
19084: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19085: push(@{$changes->{'cancreate'}},'recaptchakeys');
19086: } elsif (!defined($changes->{'cancreate'})) {
19087: $changes->{'cancreate'} = ['recaptchakeys'];
19088: }
1.368 raeburn 19089: } elsif ($container eq 'passwords') {
19090: $changes->{'reset'} = 1;
1.169 raeburn 19091: } else {
1.210 raeburn 19092: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19093: }
19094: }
19095: return;
19096: }
19097:
1.33 raeburn 19098: sub modify_usermodification {
19099: my ($dom,%domconfig) = @_;
1.224 raeburn 19100: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19101: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19102: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19103: if ($key eq 'selfcreate') {
19104: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19105: } else {
19106: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19107: }
1.33 raeburn 19108: }
19109: }
1.224 raeburn 19110: my @contexts = ('author','course');
1.33 raeburn 19111: my %context_title = (
19112: author => 'In author context',
19113: course => 'In course context',
19114: );
19115: my @fields = ('lastname','firstname','middlename','generation',
19116: 'permanentemail','id');
19117: my %roles = (
19118: author => ['ca','aa'],
19119: course => ['st','ep','ta','in','cr'],
19120: );
19121: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19122: foreach my $context (@contexts) {
19123: foreach my $role (@{$roles{$context}}) {
19124: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19125: foreach my $item (@fields) {
19126: if (grep(/^\Q$item\E$/,@modifiable)) {
19127: $modifyhash{$context}{$role}{$item} = 1;
19128: } else {
19129: $modifyhash{$context}{$role}{$item} = 0;
19130: }
19131: }
19132: }
19133: if (ref($curr_usermodification{$context}) eq 'HASH') {
19134: foreach my $role (@{$roles{$context}}) {
19135: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19136: foreach my $field (@fields) {
19137: if ($modifyhash{$context}{$role}{$field} ne
19138: $curr_usermodification{$context}{$role}{$field}) {
19139: push(@{$changes{$context}},$role);
19140: last;
19141: }
19142: }
19143: }
19144: }
19145: } else {
19146: foreach my $context (@contexts) {
19147: foreach my $role (@{$roles{$context}}) {
19148: push(@{$changes{$context}},$role);
19149: }
19150: }
19151: }
19152: }
19153: my %usermodification_hash = (
19154: usermodification => \%modifyhash,
19155: );
19156: my $putresult = &Apache::lonnet::put_dom('configuration',
19157: \%usermodification_hash,$dom);
19158: if ($putresult eq 'ok') {
19159: if (keys(%changes) > 0) {
19160: $resulttext = &mt('Changes made: ').'<ul>';
19161: foreach my $context (@contexts) {
19162: if (ref($changes{$context}) eq 'ARRAY') {
19163: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19164: if (ref($changes{$context}) eq 'ARRAY') {
19165: foreach my $role (@{$changes{$context}}) {
19166: my $rolename;
1.224 raeburn 19167: if ($role eq 'cr') {
19168: $rolename = &mt('Custom');
1.33 raeburn 19169: } else {
1.224 raeburn 19170: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19171: }
19172: my @modifiable;
1.224 raeburn 19173: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19174: foreach my $field (@fields) {
19175: if ($modifyhash{$context}{$role}{$field}) {
19176: push(@modifiable,$fieldtitles{$field});
19177: }
19178: }
19179: if (@modifiable > 0) {
19180: $resulttext .= join(', ',@modifiable);
19181: } else {
19182: $resulttext .= &mt('none');
19183: }
19184: $resulttext .= '</li>';
19185: }
19186: $resulttext .= '</ul></li>';
19187: }
19188: }
19189: }
19190: $resulttext .= '</ul>';
19191: } else {
19192: $resulttext = &mt('No changes made to user modification settings');
19193: }
19194: } else {
19195: $resulttext = '<span class="LC_error">'.
19196: &mt('An error occurred: [_1]',$putresult).'</span>';
19197: }
19198: return $resulttext;
19199: }
19200:
1.43 raeburn 19201: sub modify_defaults {
1.212 raeburn 19202: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19203: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19204: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19205: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19206: 'portal_def');
1.325 raeburn 19207: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19208: foreach my $item (@items) {
19209: $newvalues{$item} = $env{'form.'.$item};
19210: if ($item eq 'auth_def') {
19211: if ($newvalues{$item} ne '') {
19212: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19213: push(@errors,$item);
19214: }
19215: }
19216: } elsif ($item eq 'lang_def') {
19217: if ($newvalues{$item} ne '') {
19218: if ($newvalues{$item} =~ /^(\w+)/) {
19219: my $langcode = $1;
1.103 raeburn 19220: if ($langcode ne 'x_chef') {
19221: if (code2language($langcode) eq '') {
19222: push(@errors,$item);
19223: }
1.43 raeburn 19224: }
19225: } else {
19226: push(@errors,$item);
19227: }
19228: }
1.54 raeburn 19229: } elsif ($item eq 'timezone_def') {
19230: if ($newvalues{$item} ne '') {
1.62 raeburn 19231: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19232: push(@errors,$item);
19233: }
19234: }
1.68 raeburn 19235: } elsif ($item eq 'datelocale_def') {
19236: if ($newvalues{$item} ne '') {
19237: my @datelocale_ids = DateTime::Locale->ids();
19238: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19239: push(@errors,$item);
19240: }
19241: }
1.141 raeburn 19242: } elsif ($item eq 'portal_def') {
19243: if ($newvalues{$item} ne '') {
1.414 raeburn 19244: if ($newvalues{$item} =~ /^https?\:\/\/(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\-]*[A-Za-z0-9])\/?$/) {
19245: foreach my $field ('email','web') {
19246: if ($env{'form.'.$item.'_'.$field}) {
19247: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19248: }
19249: }
19250: } else {
1.141 raeburn 19251: push(@errors,$item);
19252: }
19253: }
1.43 raeburn 19254: }
19255: if (grep(/^\Q$item\E$/,@errors)) {
19256: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19257: if ($item eq 'portal_def') {
19258: if ($domdefaults{$item}) {
19259: foreach my $field ('email','web') {
19260: if (exists($domdefaults{$item.'_'.$field})) {
19261: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19262: }
19263: }
19264: }
19265: }
1.43 raeburn 19266: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19267: $changes{$item} = 1;
19268: }
1.414 raeburn 19269: if ($item eq 'portal_def') {
19270: unless (grep(/^\Q$item\E$/,@errors)) {
19271: if ($newvalues{$item} eq '') {
19272: foreach my $field ('email','web') {
19273: if (exists($domdefaults{$item.'_'.$field})) {
19274: delete($domdefaults{$item.'_'.$field});
19275: }
19276: }
19277: } else {
19278: unless ($changes{$item}) {
19279: foreach my $field ('email','web') {
19280: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19281: $changes{$item} = 1;
19282: last;
19283: }
19284: }
19285: }
19286: foreach my $field ('email','web') {
19287: if ($newvalues{$item.'_'.$field}) {
19288: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19289: } elsif (exists($domdefaults{$item.'_'.$field})) {
19290: delete($domdefaults{$item.'_'.$field});
19291: }
19292: }
19293: }
19294: }
19295: }
1.72 raeburn 19296: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 19297: }
1.354 raeburn 19298: my %staticdefaults = (
19299: 'intauth_cost' => 10,
19300: 'intauth_check' => 0,
19301: 'intauth_switch' => 0,
19302: );
19303: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
19304: if (exists($domdefaults{$item})) {
19305: $newvalues{$item} = $domdefaults{$item};
19306: } else {
19307: $newvalues{$item} = $staticdefaults{$item};
19308: }
19309: }
1.409 raeburn 19310: my ($unamemaprules,$ruleorder);
19311: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
19312: if (@possunamemaprules) {
19313: ($unamemaprules,$ruleorder) =
19314: &Apache::lonnet::inst_userrules($dom,'unamemap');
19315: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
19316: if (@{$ruleorder} > 0) {
19317: my %possrules;
19318: map { $possrules{$_} = 1; } @possunamemaprules;
19319: foreach my $rule (@{$ruleorder}) {
19320: if ($possrules{$rule}) {
19321: push(@{$newvalues{'unamemap_rule'}},$rule);
19322: }
19323: }
19324: }
19325: }
19326: }
19327: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
19328: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19329: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
19330: $newvalues{'unamemap_rule'});
19331: if (@rulediffs) {
19332: $changes{'unamemap_rule'} = 1;
19333: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19334: }
19335: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
19336: $changes{'unamemap_rule'} = 1;
19337: delete($domdefaults{'unamemap_rule'});
19338: }
19339: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19340: if (@{$newvalues{'unamemap_rule'}} > 0) {
19341: $changes{'unamemap_rule'} = 1;
19342: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
19343: }
19344: }
1.43 raeburn 19345: my %defaults_hash = (
1.72 raeburn 19346: defaults => \%newvalues,
19347: );
1.43 raeburn 19348: my $title = &defaults_titles();
1.236 raeburn 19349:
19350: my $currinststatus;
19351: if (ref($domconfig{'inststatus'}) eq 'HASH') {
19352: $currinststatus = $domconfig{'inststatus'};
19353: } else {
19354: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
19355: $currinststatus = {
19356: inststatustypes => $usertypes,
19357: inststatusorder => $types,
19358: inststatusguest => [],
19359: };
19360: }
19361: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
19362: my @allpos;
19363: my %alltypes;
1.305 raeburn 19364: my @inststatusguest;
19365: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
19366: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
19367: unless (grep(/^\Q$type\E$/,@todelete)) {
19368: push(@inststatusguest,$type);
19369: }
19370: }
19371: }
19372: my ($currtitles,$currorder);
1.236 raeburn 19373: if (ref($currinststatus) eq 'HASH') {
19374: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
19375: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
19376: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
19377: if ($currinststatus->{inststatustypes}->{$type} ne '') {
19378: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
19379: }
19380: }
19381: unless (grep(/^\Q$type\E$/,@todelete)) {
19382: my $position = $env{'form.inststatus_pos_'.$type};
19383: $position =~ s/\D+//g;
19384: $allpos[$position] = $type;
19385: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
19386: $alltypes{$type} =~ s/`//g;
19387: }
19388: }
19389: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
19390: $currtitles =~ s/,$//;
19391: }
19392: }
19393: if ($env{'form.addinststatus'}) {
19394: my $newtype = $env{'form.addinststatus'};
19395: $newtype =~ s/\W//g;
19396: unless (exists($alltypes{$newtype})) {
19397: $alltypes{$newtype} = $env{'form.addinststatus_title'};
19398: $alltypes{$newtype} =~ s/`//g;
19399: my $position = $env{'form.addinststatus_pos'};
19400: $position =~ s/\D+//g;
19401: if ($position ne '') {
19402: $allpos[$position] = $newtype;
19403: }
19404: }
19405: }
1.305 raeburn 19406: my @orderedstatus;
1.236 raeburn 19407: foreach my $type (@allpos) {
19408: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
19409: push(@orderedstatus,$type);
19410: }
19411: }
19412: foreach my $type (keys(%alltypes)) {
19413: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
19414: delete($alltypes{$type});
19415: }
19416: }
19417: $defaults_hash{'inststatus'} = {
19418: inststatustypes => \%alltypes,
19419: inststatusorder => \@orderedstatus,
1.305 raeburn 19420: inststatusguest => \@inststatusguest,
1.236 raeburn 19421: };
19422: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
19423: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
19424: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
19425: }
19426: }
19427: if ($currorder ne join(',',@orderedstatus)) {
19428: $changes{'inststatus'}{'inststatusorder'} = 1;
19429: }
19430: my $newtitles;
19431: foreach my $item (@orderedstatus) {
19432: $newtitles .= $alltypes{$item}.',';
19433: }
19434: $newtitles =~ s/,$//;
19435: if ($currtitles ne $newtitles) {
19436: $changes{'inststatus'}{'inststatustypes'} = 1;
19437: }
1.43 raeburn 19438: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
19439: $dom);
19440: if ($putresult eq 'ok') {
19441: if (keys(%changes) > 0) {
19442: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 19443: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 19444: 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";
19445: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 19446: if ($item eq 'inststatus') {
19447: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 19448: if (@orderedstatus) {
1.236 raeburn 19449: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
19450: foreach my $type (@orderedstatus) {
19451: $resulttext .= $alltypes{$type}.', ';
19452: }
19453: $resulttext =~ s/, $//;
19454: $resulttext .= '</li>';
1.305 raeburn 19455: } else {
19456: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 19457: }
19458: }
1.409 raeburn 19459: } elsif ($item eq 'unamemap_rule') {
19460: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
19461: my @rulenames;
19462: if (ref($unamemaprules) eq 'HASH') {
19463: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
19464: if (ref($unamemaprules->{$rule}) eq 'HASH') {
19465: push(@rulenames,$unamemaprules->{$rule}->{'name'});
19466: }
19467: }
19468: }
19469: if (@rulenames) {
19470: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
19471: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
19472: '</li>';
19473: } else {
19474: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
19475: }
19476: } else {
19477: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
19478: }
1.236 raeburn 19479: } else {
19480: my $value = $env{'form.'.$item};
19481: if ($value eq '') {
19482: $value = &mt('none');
19483: } elsif ($item eq 'auth_def') {
19484: my %authnames = &authtype_names();
19485: my %shortauth = (
19486: internal => 'int',
19487: krb4 => 'krb4',
19488: krb5 => 'krb5',
19489: localauth => 'loc',
1.325 raeburn 19490: lti => 'lti',
1.236 raeburn 19491: );
19492: $value = $authnames{$shortauth{$value}};
19493: }
19494: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 19495: $mailmsgtext .= "$title->{$item} set to $value\n";
19496: if ($item eq 'portal_def') {
19497: if ($env{'form.'.$item} ne '') {
19498: foreach my $field ('email','web') {
19499: $value = $env{'form.'.$item.'_'.$field};
19500: if ($value) {
19501: $value = &mt('Yes');
19502: } else {
19503: $value = &mt('No');
19504: }
19505: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
19506: }
19507: }
19508: }
1.43 raeburn 19509: }
19510: }
19511: $resulttext .= '</ul>';
19512: $mailmsgtext .= "\n";
19513: my $cachetime = 24*60*60;
1.72 raeburn 19514: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 19515: if (ref($lastactref) eq 'HASH') {
19516: $lastactref->{'domdefaults'} = 1;
19517: }
1.68 raeburn 19518: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 19519: my $notify = 1;
19520: if (ref($domconfig{'contacts'}) eq 'HASH') {
19521: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
19522: $notify = 0;
19523: }
19524: }
19525: if ($notify) {
19526: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
19527: "LON-CAPA Domain Settings Change - $dom",
19528: $mailmsgtext);
19529: }
1.54 raeburn 19530: }
1.43 raeburn 19531: } else {
1.54 raeburn 19532: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 19533: }
19534: } else {
19535: $resulttext = '<span class="LC_error">'.
19536: &mt('An error occurred: [_1]',$putresult).'</span>';
19537: }
19538: if (@errors > 0) {
19539: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
19540: foreach my $item (@errors) {
19541: $resulttext .= ' "'.$title->{$item}.'",';
19542: }
19543: $resulttext =~ s/,$//;
19544: }
19545: return $resulttext;
19546: }
19547:
1.46 raeburn 19548: sub modify_scantron {
1.205 raeburn 19549: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 19550: my ($resulttext,%confhash,%changes,$errors);
19551: my $custom = 'custom.tab';
19552: my $default = 'default.tab';
19553: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 19554: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 19555: &config_check($dom,$confname,$servadm);
19556: if ($env{'form.scantronformat.filename'} ne '') {
19557: my $error;
19558: if ($configuserok eq 'ok') {
19559: if ($switchserver) {
1.130 raeburn 19560: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 19561: } else {
19562: if ($author_ok eq 'ok') {
1.421 raeburn 19563: my $modified = [];
1.46 raeburn 19564: my ($result,$scantronurl) =
1.421 raeburn 19565: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
19566: $confname,'scantron','','',$custom,
19567: $modified);
1.46 raeburn 19568: if ($result eq 'ok') {
19569: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 19570: $changes{'scantronformat'} = 1;
1.421 raeburn 19571: &update_modify_urls($r,$modified);
1.46 raeburn 19572: } else {
19573: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
19574: }
19575: } else {
19576: $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);
19577: }
19578: }
19579: } else {
19580: $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);
19581: }
19582: if ($error) {
19583: &Apache::lonnet::logthis($error);
19584: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
19585: }
19586: }
1.48 raeburn 19587: if (ref($domconfig{'scantron'}) eq 'HASH') {
19588: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
19589: if ($env{'form.scantronformat_del'}) {
19590: $confhash{'scantron'}{'scantronformat'} = '';
19591: $changes{'scantronformat'} = 1;
1.347 raeburn 19592: } else {
19593: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 19594: }
19595: }
19596: }
1.347 raeburn 19597: my @options = ('hdr','pad','rem');
1.346 raeburn 19598: my @fields = &scantroncsv_fields();
19599: my %titles = &scantronconfig_titles();
1.347 raeburn 19600: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 19601: my ($newdat,$currdat,%newcol,%currcol);
19602: if (grep(/^dat$/,@formats)) {
19603: $confhash{'scantron'}{config}{dat} = 1;
19604: $newdat = 1;
19605: } else {
19606: $newdat = 0;
19607: }
19608: if (grep(/^csv$/,@formats)) {
19609: my %bynum;
19610: foreach my $field (@fields) {
19611: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
19612: my $posscol = $1;
19613: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 19614: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 19615: $bynum{$posscol} = $field;
19616: $newcol{$field} = $posscol;
19617: }
19618: }
19619: }
1.347 raeburn 19620: if (keys(%newcol)) {
19621: foreach my $option (@options) {
19622: if ($env{'form.scantroncsv_'.$option}) {
19623: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
19624: }
19625: }
19626: }
1.346 raeburn 19627: }
19628: $currdat = 1;
19629: if (ref($domconfig{'scantron'}) eq 'HASH') {
19630: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 19631: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 19632: $currdat = 0;
19633: }
19634: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19635: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19636: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
19637: }
1.346 raeburn 19638: }
19639: }
19640: }
19641: if ($currdat != $newdat) {
19642: $changes{'config'} = 1;
19643: } else {
19644: foreach my $field (@fields) {
19645: if ($currcol{$field} ne '') {
19646: if ($currcol{$field} ne $newcol{$field}) {
19647: $changes{'config'} = 1;
19648: last;
1.347 raeburn 19649: }
1.346 raeburn 19650: } elsif ($newcol{$field} ne '') {
19651: $changes{'config'} = 1;
19652: last;
19653: }
19654: }
19655: }
1.46 raeburn 19656: if (keys(%confhash) > 0) {
19657: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
19658: $dom);
19659: if ($putresult eq 'ok') {
19660: if (keys(%changes) > 0) {
1.48 raeburn 19661: if (ref($confhash{'scantron'}) eq 'HASH') {
19662: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 19663: if ($changes{'scantronformat'}) {
19664: if ($confhash{'scantron'}{'scantronformat'} eq '') {
19665: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
19666: } else {
19667: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
19668: }
19669: }
1.347 raeburn 19670: if ($changes{'config'}) {
1.346 raeburn 19671: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
19672: if ($confhash{'scantron'}{'config'}{'dat'}) {
19673: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
19674: }
19675: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 19676: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
19677: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
19678: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
19679: foreach my $field (@fields) {
19680: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
19681: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
19682: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
19683: }
19684: }
19685: $resulttext .= '</ul></li>';
19686: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
19687: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
19688: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
19689: foreach my $option (@options) {
19690: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
19691: $resulttext .= '<li>'.$titles{$option}.'</li>';
19692: }
19693: }
19694: $resulttext .= '</ul></li>';
19695: }
1.346 raeburn 19696: }
19697: }
19698: }
19699: }
19700: } else {
19701: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
19702: }
1.46 raeburn 19703: }
1.48 raeburn 19704: $resulttext .= '</ul>';
19705: } else {
1.130 raeburn 19706: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 19707: }
19708: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 19709: if (ref($lastactref) eq 'HASH') {
19710: $lastactref->{'domainconfig'} = 1;
19711: }
1.46 raeburn 19712: } else {
1.346 raeburn 19713: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 19714: }
19715: } else {
19716: $resulttext = '<span class="LC_error">'.
19717: &mt('An error occurred: [_1]',$putresult).'</span>';
19718: }
19719: } else {
1.130 raeburn 19720: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 19721: }
19722: if ($errors) {
1.353 raeburn 19723: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
19724: $errors.'</ul></p>';
1.46 raeburn 19725: }
19726: return $resulttext;
19727: }
19728:
1.48 raeburn 19729: sub modify_coursecategories {
1.239 raeburn 19730: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 19731: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
19732: $cathash);
1.48 raeburn 19733: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 19734: my @catitems = ('unauth','auth');
19735: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 19736: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 19737: $cathash = $domconfig{'coursecategories'}{'cats'};
19738: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
19739: $changes{'togglecats'} = 1;
19740: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
19741: }
19742: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
19743: $changes{'categorize'} = 1;
19744: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
19745: }
1.120 raeburn 19746: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
19747: $changes{'togglecatscomm'} = 1;
19748: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
19749: }
19750: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
19751: $changes{'categorizecomm'} = 1;
19752: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 19753:
19754: }
19755: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
19756: $changes{'togglecatsplace'} = 1;
19757: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
19758: }
19759: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
19760: $changes{'categorizeplace'} = 1;
19761: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 19762: }
1.238 raeburn 19763: foreach my $item (@catitems) {
19764: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19765: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
19766: $changes{$item} = 1;
19767: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19768: }
19769: }
19770: }
1.57 raeburn 19771: } else {
19772: $changes{'togglecats'} = 1;
19773: $changes{'categorize'} = 1;
1.124 raeburn 19774: $changes{'togglecatscomm'} = 1;
19775: $changes{'categorizecomm'} = 1;
1.272 raeburn 19776: $changes{'togglecatsplace'} = 1;
19777: $changes{'categorizeplace'} = 1;
1.87 raeburn 19778: $domconfig{'coursecategories'} = {
19779: togglecats => $env{'form.togglecats'},
19780: categorize => $env{'form.categorize'},
1.124 raeburn 19781: togglecatscomm => $env{'form.togglecatscomm'},
19782: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 19783: togglecatsplace => $env{'form.togglecatsplace'},
19784: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 19785: };
1.238 raeburn 19786: foreach my $item (@catitems) {
19787: if ($env{'form.coursecat_'.$item} ne 'std') {
19788: $changes{$item} = 1;
19789: }
19790: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
19791: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
19792: }
19793: }
1.57 raeburn 19794: }
19795: if (ref($cathash) eq 'HASH') {
19796: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 19797: push (@deletecategory,'instcode::0');
19798: }
1.120 raeburn 19799: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
19800: push(@deletecategory,'communities::0');
19801: }
1.272 raeburn 19802: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
19803: push(@deletecategory,'placement::0');
19804: }
1.48 raeburn 19805: }
1.57 raeburn 19806: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
19807: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19808: if (@deletecategory > 0) {
19809: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 19810: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 19811: foreach my $item (@deletecategory) {
1.57 raeburn 19812: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
19813: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 19814: $deletions{$item} = 1;
1.57 raeburn 19815: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 19816: }
19817: }
19818: }
1.57 raeburn 19819: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 19820: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 19821: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 19822: $reorderings{$item} = 1;
1.57 raeburn 19823: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 19824: }
19825: if ($env{'form.addcategory_name_'.$item} ne '') {
19826: my $newcat = $env{'form.addcategory_name_'.$item};
19827: my $newdepth = $depth+1;
19828: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19829: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 19830: $adds{$newitem} = 1;
19831: }
19832: if ($env{'form.subcat_'.$item} ne '') {
19833: my $newcat = $env{'form.subcat_'.$item};
19834: my $newdepth = $depth+1;
19835: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 19836: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 19837: $adds{$newitem} = 1;
19838: }
19839: }
19840: }
19841: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 19842: if (ref($cathash) eq 'HASH') {
1.48 raeburn 19843: my $newitem = 'instcode::0';
1.57 raeburn 19844: if ($cathash->{$newitem} eq '') {
19845: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19846: $adds{$newitem} = 1;
19847: }
19848: } else {
19849: my $newitem = 'instcode::0';
1.57 raeburn 19850: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 19851: $adds{$newitem} = 1;
19852: }
19853: }
1.120 raeburn 19854: if ($env{'form.communities'} eq '1') {
19855: if (ref($cathash) eq 'HASH') {
19856: my $newitem = 'communities::0';
19857: if ($cathash->{$newitem} eq '') {
19858: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19859: $adds{$newitem} = 1;
19860: }
19861: } else {
19862: my $newitem = 'communities::0';
19863: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
19864: $adds{$newitem} = 1;
19865: }
19866: }
1.272 raeburn 19867: if ($env{'form.placement'} eq '1') {
19868: if (ref($cathash) eq 'HASH') {
19869: my $newitem = 'placement::0';
19870: if ($cathash->{$newitem} eq '') {
19871: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19872: $adds{$newitem} = 1;
19873: }
19874: } else {
19875: my $newitem = 'placement::0';
19876: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
19877: $adds{$newitem} = 1;
19878: }
19879: }
1.48 raeburn 19880: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 19881: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 19882: ($env{'form.addcategory_name'} ne 'communities') &&
19883: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 19884: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
19885: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
19886: $adds{$newitem} = 1;
19887: }
1.48 raeburn 19888: }
1.57 raeburn 19889: my $putresult;
1.48 raeburn 19890: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19891: if (keys(%deletions) > 0) {
19892: foreach my $key (keys(%deletions)) {
19893: if ($predelallitems{$key} ne '') {
19894: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
19895: }
19896: }
19897: }
19898: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 19899: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 19900: if (ref($chkcats[0]) eq 'ARRAY') {
19901: my $depth = 0;
19902: my $chg = 0;
19903: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
19904: my $name = $chkcats[0][$i];
19905: my $item;
19906: if ($name eq '') {
19907: $chg ++;
19908: } else {
19909: $item = &escape($name).'::0';
19910: if ($chg) {
1.57 raeburn 19911: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 19912: }
19913: $depth ++;
1.57 raeburn 19914: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 19915: $depth --;
19916: }
19917: }
19918: }
1.57 raeburn 19919: }
19920: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19921: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 19922: if ($putresult eq 'ok') {
1.57 raeburn 19923: my %title = (
1.120 raeburn 19924: togglecats => 'Show/Hide a course in catalog',
19925: categorize => 'Assign a category to a course',
19926: togglecatscomm => 'Show/Hide a community in catalog',
19927: categorizecomm => 'Assign a category to a community',
1.57 raeburn 19928: );
19929: my %level = (
1.120 raeburn 19930: dom => 'set in Domain ("Modify Course/Community")',
19931: crs => 'set in Course ("Course Configuration")',
19932: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 19933: none => 'No catalog',
19934: std => 'Standard catalog',
19935: domonly => 'Domain-only catalog',
19936: codesrch => 'Code search form',
1.57 raeburn 19937: );
1.48 raeburn 19938: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 19939: if ($changes{'togglecats'}) {
19940: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
19941: }
19942: if ($changes{'categorize'}) {
19943: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 19944: }
1.120 raeburn 19945: if ($changes{'togglecatscomm'}) {
19946: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
19947: }
19948: if ($changes{'categorizecomm'}) {
19949: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
19950: }
1.238 raeburn 19951: if ($changes{'unauth'}) {
19952: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
19953: }
19954: if ($changes{'auth'}) {
19955: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
19956: }
1.57 raeburn 19957: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
19958: my $cathash;
19959: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
19960: $cathash = $domconfig{'coursecategories'}{'cats'};
19961: } else {
19962: $cathash = {};
19963: }
19964: my (@cats,@trails,%allitems);
19965: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
19966: if (keys(%deletions) > 0) {
19967: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
19968: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
19969: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
19970: }
19971: $resulttext .= '</ul></li>';
19972: }
19973: if (keys(%reorderings) > 0) {
19974: my %sort_by_trail;
19975: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
19976: foreach my $key (keys(%reorderings)) {
19977: if ($allitems{$key} ne '') {
19978: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19979: }
1.48 raeburn 19980: }
1.57 raeburn 19981: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19982: $resulttext .= '<li>'.$trails[$trail].'</li>';
19983: }
19984: $resulttext .= '</ul></li>';
1.48 raeburn 19985: }
1.57 raeburn 19986: if (keys(%adds) > 0) {
19987: my %sort_by_trail;
19988: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
19989: foreach my $key (keys(%adds)) {
19990: if ($allitems{$key} ne '') {
19991: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
19992: }
19993: }
19994: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
19995: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 19996: }
1.57 raeburn 19997: $resulttext .= '</ul></li>';
1.48 raeburn 19998: }
1.364 raeburn 19999: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20000: if (ref($lastactref) eq 'HASH') {
20001: $lastactref->{'cats'} = 1;
20002: }
1.48 raeburn 20003: }
20004: $resulttext .= '</ul>';
1.239 raeburn 20005: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20006: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20007: if ($changes{'auth'}) {
20008: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20009: }
20010: if ($changes{'unauth'}) {
20011: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20012: }
20013: my $cachetime = 24*60*60;
20014: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20015: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20016: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20017: }
20018: }
1.48 raeburn 20019: } else {
20020: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20021: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20022: }
20023: } else {
1.120 raeburn 20024: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20025: }
20026: return $resulttext;
20027: }
20028:
1.69 raeburn 20029: sub modify_serverstatuses {
20030: my ($dom,%domconfig) = @_;
20031: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20032: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20033: %currserverstatus = %{$domconfig{'serverstatuses'}};
20034: }
20035: my @pages = &serverstatus_pages();
20036: foreach my $type (@pages) {
20037: $newserverstatus{$type}{'namedusers'} = '';
20038: $newserverstatus{$type}{'machines'} = '';
20039: if (defined($env{'form.'.$type.'_namedusers'})) {
20040: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20041: my @okusers;
20042: foreach my $user (@users) {
20043: my ($uname,$udom) = split(/:/,$user);
20044: if (($udom =~ /^$match_domain$/) &&
20045: (&Apache::lonnet::domain($udom)) &&
20046: ($uname =~ /^$match_username$/)) {
20047: if (!grep(/^\Q$user\E/,@okusers)) {
20048: push(@okusers,$user);
20049: }
20050: }
20051: }
20052: if (@okusers > 0) {
20053: @okusers = sort(@okusers);
20054: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20055: }
20056: }
20057: if (defined($env{'form.'.$type.'_machines'})) {
20058: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20059: my @okmachines;
20060: foreach my $ip (@machines) {
20061: my @parts = split(/\./,$ip);
20062: next if (@parts < 4);
20063: my $badip = 0;
20064: for (my $i=0; $i<4; $i++) {
20065: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20066: $badip = 1;
20067: last;
20068: }
20069: }
20070: if (!$badip) {
20071: push(@okmachines,$ip);
20072: }
20073: }
20074: @okmachines = sort(@okmachines);
20075: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20076: }
20077: }
20078: my %serverstatushash = (
20079: serverstatuses => \%newserverstatus,
20080: );
20081: foreach my $type (@pages) {
1.83 raeburn 20082: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20083: my (@current,@new);
1.83 raeburn 20084: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20085: if ($currserverstatus{$type}{$setting} ne '') {
20086: @current = split(/,/,$currserverstatus{$type}{$setting});
20087: }
20088: }
20089: if ($newserverstatus{$type}{$setting} ne '') {
20090: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20091: }
20092: if (@current > 0) {
20093: if (@new > 0) {
20094: foreach my $item (@current) {
20095: if (!grep(/^\Q$item\E$/,@new)) {
20096: $changes{$type}{$setting} = 1;
1.82 raeburn 20097: last;
20098: }
20099: }
1.84 raeburn 20100: foreach my $item (@new) {
20101: if (!grep(/^\Q$item\E$/,@current)) {
20102: $changes{$type}{$setting} = 1;
20103: last;
1.82 raeburn 20104: }
20105: }
20106: } else {
1.83 raeburn 20107: $changes{$type}{$setting} = 1;
1.69 raeburn 20108: }
1.83 raeburn 20109: } elsif (@new > 0) {
20110: $changes{$type}{$setting} = 1;
1.69 raeburn 20111: }
20112: }
20113: }
20114: if (keys(%changes) > 0) {
1.81 raeburn 20115: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20116: my $putresult = &Apache::lonnet::put_dom('configuration',
20117: \%serverstatushash,$dom);
20118: if ($putresult eq 'ok') {
20119: $resulttext .= &mt('Changes made:').'<ul>';
20120: foreach my $type (@pages) {
1.84 raeburn 20121: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20122: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20123: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20124: if ($newserverstatus{$type}{'namedusers'} eq '') {
20125: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20126: } else {
20127: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20128: }
1.84 raeburn 20129: }
20130: if ($changes{$type}{'machines'}) {
1.69 raeburn 20131: if ($newserverstatus{$type}{'machines'} eq '') {
20132: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20133: } else {
20134: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20135: }
20136:
20137: }
20138: $resulttext .= '</ul></li>';
20139: }
20140: }
20141: $resulttext .= '</ul>';
20142: } else {
20143: $resulttext = '<span class="LC_error">'.
20144: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20145:
20146: }
20147: } else {
20148: $resulttext = &mt('No changes made to access to server status pages');
20149: }
20150: return $resulttext;
20151: }
20152:
1.118 jms 20153: sub modify_helpsettings {
1.285 raeburn 20154: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20155: my ($resulttext,$errors,%changes,%helphash);
20156: my %defaultchecked = ('submitbugs' => 'on');
20157: my @offon = ('off','on');
1.118 jms 20158: my @toggles = ('submitbugs');
1.285 raeburn 20159: my %current = ('submitbugs' => '',
20160: 'adhoc' => {},
20161: );
1.118 jms 20162: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20163: %current = %{$domconfig{'helpsettings'}};
20164: }
1.285 raeburn 20165: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20166: foreach my $item (@toggles) {
20167: if ($defaultchecked{$item} eq 'on') {
20168: if ($current{$item} eq '') {
20169: if ($env{'form.'.$item} eq '0') {
20170: $changes{$item} = 1;
20171: }
20172: } elsif ($current{$item} ne $env{'form.'.$item}) {
20173: $changes{$item} = 1;
20174: }
20175: } elsif ($defaultchecked{$item} eq 'off') {
20176: if ($current{$item} eq '') {
20177: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20178: $changes{$item} = 1;
20179: }
1.282 raeburn 20180: } elsif ($current{$item} ne $env{'form.'.$item}) {
20181: $changes{$item} = 1;
20182: }
20183: }
20184: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20185: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20186: }
20187: }
1.285 raeburn 20188: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20189: my $confname = $dom.'-domainconfig';
20190: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20191: my (@allpos,%newsettings,%changedprivs,$newrole);
20192: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20193: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20194: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20195: my %lt = &Apache::lonlocal::texthash(
20196: s => 'system',
20197: d => 'domain',
20198: order => 'Display order',
20199: access => 'Role usage',
1.291 raeburn 20200: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20201: dh => 'All with domain helpdesk role',
20202: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20203: none => 'None',
20204: status => 'Determined based on institutional status',
20205: inc => 'Include all, but exclude specific personnel',
20206: exc => 'Exclude all, but include specific personnel',
20207: );
20208: for (my $num=0; $num<=$maxnum; $num++) {
20209: my ($prefix,$identifier,$rolename,%curr);
20210: if ($num == $maxnum) {
20211: next unless ($env{'form.newcusthelp'} == $maxnum);
20212: $identifier = 'custhelp'.$num;
20213: $prefix = 'helproles_'.$num;
20214: $rolename = $env{'form.custhelpname'.$num};
20215: $rolename=~s/[^A-Za-z0-9]//gs;
20216: next if ($rolename eq '');
20217: next if (exists($existing{'rolesdef_'.$rolename}));
20218: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20219: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20220: $newprivs{'c'},$confname,$dom);
20221: if ($result ne 'ok') {
20222: $errors .= '<li><span class="LC_error">'.
20223: &mt('An error occurred storing the new custom role: [_1]',
20224: $result).'</span></li>';
20225: next;
20226: } else {
20227: $changedprivs{$rolename} = \%newprivs;
20228: $newrole = $rolename;
20229: }
20230: } else {
20231: $prefix = 'helproles_'.$num;
20232: $rolename = $env{'form.'.$prefix};
20233: next if ($rolename eq '');
20234: next unless (exists($existing{'rolesdef_'.$rolename}));
20235: $identifier = 'custhelp'.$num;
20236: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20237: my %currprivs;
1.289 raeburn 20238: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20239: split(/\_/,$existing{'rolesdef_'.$rolename});
20240: foreach my $level ('c','d','s') {
20241: if ($newprivs{$level} ne $currprivs{$level}) {
20242: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20243: $newprivs{'c'},$confname,$dom);
20244: if ($result ne 'ok') {
20245: $errors .= '<li><span class="LC_error">'.
20246: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20247: $rolename,$result).'</span></li>';
20248: } else {
20249: $changedprivs{$rolename} = \%newprivs;
20250: }
20251: last;
20252: }
20253: }
20254: if (ref($current{'adhoc'}) eq 'HASH') {
20255: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20256: %curr = %{$current{'adhoc'}{$rolename}};
20257: }
20258: }
20259: }
20260: my $newpos = $env{'form.'.$prefix.'_pos'};
20261: $newpos =~ s/\D+//g;
20262: $allpos[$newpos] = $rolename;
20263: my $newdesc = $env{'form.'.$prefix.'_desc'};
20264: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20265: if ($curr{'desc'}) {
20266: if ($curr{'desc'} ne $newdesc) {
20267: $changes{'customrole'}{$rolename}{'desc'} = 1;
20268: $newsettings{$rolename}{'desc'} = $newdesc;
20269: }
20270: } elsif ($newdesc ne '') {
20271: $changes{'customrole'}{$rolename}{'desc'} = 1;
20272: $newsettings{$rolename}{'desc'} = $newdesc;
20273: }
20274: my $access = $env{'form.'.$prefix.'_access'};
20275: if (grep(/^\Q$access\E$/,@accesstypes)) {
20276: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20277: if ($access eq 'status') {
20278: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20279: if (scalar(@statuses) == 0) {
1.289 raeburn 20280: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20281: } else {
20282: my (@shownstatus,$numtypes);
20283: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20284: if (ref($types) eq 'ARRAY') {
20285: $numtypes = scalar(@{$types});
20286: foreach my $type (sort(@statuses)) {
20287: if ($type eq 'default') {
20288: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20289: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20290: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20291: push(@shownstatus,$usertypes->{$type});
20292: }
20293: }
20294: }
20295: if (grep(/^default$/,@statuses)) {
20296: push(@shownstatus,$othertitle);
20297: }
20298: if (scalar(@shownstatus) == 1+$numtypes) {
20299: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
20300: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
20301: } else {
20302: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
20303: if (ref($curr{'status'}) eq 'ARRAY') {
20304: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20305: if (@diffs) {
20306: $changes{'customrole'}{$rolename}{$access} = 1;
20307: }
20308: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20309: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 20310: }
1.166 raeburn 20311: }
20312: }
1.285 raeburn 20313: } elsif (($access eq 'inc') || ($access eq 'exc')) {
20314: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
20315: my @newspecstaff;
20316: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20317: foreach my $person (sort(@personnel)) {
20318: if ($domhelpdesk{$person}) {
20319: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
20320: }
20321: }
20322: if (ref($curr{$access}) eq 'ARRAY') {
20323: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
20324: if (@diffs) {
20325: $changes{'customrole'}{$rolename}{$access} = 1;
20326: }
20327: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20328: $changes{'customrole'}{$rolename}{$access} = 1;
20329: }
20330: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
20331: my ($uname,$udom) = split(/:/,$person);
20332: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
20333: }
20334: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 20335: }
1.285 raeburn 20336: } else {
20337: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
20338: }
20339: unless ($curr{'access'} eq $access) {
20340: $changes{'customrole'}{$rolename}{'access'} = 1;
20341: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 20342: }
20343: }
1.285 raeburn 20344: if (@allpos > 0) {
20345: my $idx = 0;
20346: foreach my $rolename (@allpos) {
20347: if ($rolename ne '') {
20348: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
20349: if (ref($current{'adhoc'}) eq 'HASH') {
20350: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20351: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
20352: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 20353: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 20354: }
20355: }
1.282 raeburn 20356: }
1.285 raeburn 20357: $idx ++;
1.166 raeburn 20358: }
20359: }
1.118 jms 20360: }
1.123 jms 20361: my $putresult;
20362: if (keys(%changes) > 0) {
1.166 raeburn 20363: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 20364: if ($putresult eq 'ok') {
1.285 raeburn 20365: if (ref($helphash{'helpsettings'}) eq 'HASH') {
20366: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
20367: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
20368: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
20369: }
20370: }
20371: my $cachetime = 24*60*60;
20372: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20373: if (ref($lastactref) eq 'HASH') {
20374: $lastactref->{'domdefaults'} = 1;
20375: }
20376: } else {
20377: $errors .= '<li><span class="LC_error">'.
20378: &mt('An error occurred storing the settings: [_1]',
20379: $putresult).'</span></li>';
20380: }
20381: }
20382: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
20383: $resulttext = &mt('Changes made:').'<ul>';
20384: my (%shownprivs,@levelorder);
20385: @levelorder = ('c','d','s');
20386: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 20387: foreach my $item (sort(keys(%changes))) {
20388: if ($item eq 'submitbugs') {
20389: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
20390: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
20391: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 20392: } elsif ($item eq 'customrole') {
20393: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 20394: my @keyorder = ('order','desc','access','status','exc','inc');
20395: my %keytext = &Apache::lonlocal::texthash(
20396: order => 'Order',
20397: desc => 'Role description',
20398: access => 'Role usage',
1.300 droeschl 20399: status => 'Allowed institutional types',
1.285 raeburn 20400: exc => 'Allowed personnel',
20401: inc => 'Disallowed personnel',
20402: );
1.282 raeburn 20403: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 20404: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
20405: if ($role eq $newrole) {
20406: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
20407: $role).'<ul>';
20408: } else {
20409: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20410: $role).'<ul>';
20411: }
20412: foreach my $key (@keyorder) {
20413: if ($changes{'customrole'}{$role}{$key}) {
20414: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
20415: $keytext{$key},$newsettings{$role}{$key}).
20416: '</li>';
20417: }
20418: }
20419: if (ref($changedprivs{$role}) eq 'HASH') {
20420: $shownprivs{$role} = 1;
20421: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
20422: foreach my $level (@levelorder) {
20423: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20424: next if ($item eq '');
20425: my ($priv) = split(/\&/,$item,2);
20426: if (&Apache::lonnet::plaintext($priv)) {
20427: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20428: unless ($level eq 'c') {
20429: $resulttext .= ' ('.$lt{$level}.')';
20430: }
20431: $resulttext .= '</li>';
20432: }
20433: }
20434: }
20435: $resulttext .= '</ul>';
20436: }
20437: $resulttext .= '</ul></li>';
20438: }
20439: }
20440: }
20441: }
20442: }
20443: }
20444: if (keys(%changedprivs)) {
20445: foreach my $role (sort(keys(%changedprivs))) {
20446: unless ($shownprivs{$role}) {
20447: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
20448: $role).'<ul>'.
20449: '<li>'.&mt('Privileges set to :').'<ul>';
20450: foreach my $level (@levelorder) {
20451: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
20452: next if ($item eq '');
20453: my ($priv) = split(/\&/,$item,2);
20454: if (&Apache::lonnet::plaintext($priv)) {
20455: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
20456: unless ($level eq 'c') {
20457: $resulttext .= ' ('.$lt{$level}.')';
20458: }
20459: $resulttext .= '</li>';
20460: }
1.282 raeburn 20461: }
20462: }
1.285 raeburn 20463: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 20464: }
20465: }
20466: }
1.285 raeburn 20467: $resulttext .= '</ul>';
20468: } else {
20469: $resulttext = &mt('No changes made to help settings');
1.118 jms 20470: }
20471: if ($errors) {
1.168 raeburn 20472: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 20473: $errors.'</ul>';
1.118 jms 20474: }
20475: return $resulttext;
20476: }
20477:
1.121 raeburn 20478: sub modify_coursedefaults {
1.212 raeburn 20479: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 20480: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 20481: my %defaultchecked = (
20482: 'canuse_pdfforms' => 'off',
20483: 'uselcmath' => 'on',
1.398 raeburn 20484: 'usejsme' => 'on',
20485: 'inline_chem' => 'on',
1.404 raeburn 20486: 'ltiauth' => 'off',
1.257 raeburn 20487: );
1.404 raeburn 20488: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 20489: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 20490: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
20491: 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
20492: 'mysqltables_textbook','mysqltables_placement');
1.271 raeburn 20493: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 20494: my %staticdefaults = (
20495: anonsurvey_threshold => 10,
20496: uploadquota => 500,
1.257 raeburn 20497: postsubmit => 60,
1.276 raeburn 20498: mysqltables => 172800,
1.422 raeburn 20499: domexttool => 1,
1.198 raeburn 20500: );
1.314 raeburn 20501: my %texoptions = (
20502: MathJax => 'MathJax',
20503: mimetex => &mt('Convert to Images'),
20504: tth => &mt('TeX to HTML'),
20505: );
1.121 raeburn 20506: $defaultshash{'coursedefaults'} = {};
20507:
20508: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
20509: if ($domconfig{'coursedefaults'} eq '') {
20510: $domconfig{'coursedefaults'} = {};
20511: }
20512: }
20513:
20514: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
20515: foreach my $item (@toggles) {
20516: if ($defaultchecked{$item} eq 'on') {
20517: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20518: ($env{'form.'.$item} eq '0')) {
20519: $changes{$item} = 1;
1.192 raeburn 20520: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 20521: $changes{$item} = 1;
20522: }
20523: } elsif ($defaultchecked{$item} eq 'off') {
20524: if (($domconfig{'coursedefaults'}{$item} eq '') &&
20525: ($env{'form.'.$item} eq '1')) {
20526: $changes{$item} = 1;
20527: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
20528: $changes{$item} = 1;
20529: }
20530: }
20531: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
20532: }
1.198 raeburn 20533: foreach my $item (@numbers) {
20534: my ($currdef,$newdef);
1.208 raeburn 20535: $newdef = $env{'form.'.$item};
1.198 raeburn 20536: if ($item eq 'anonsurvey_threshold') {
20537: $currdef = $domconfig{'coursedefaults'}{$item};
20538: $newdef =~ s/\D//g;
20539: if ($newdef eq '' || $newdef < 1) {
20540: $newdef = 1;
20541: }
20542: $defaultshash{'coursedefaults'}{$item} = $newdef;
20543: } else {
1.276 raeburn 20544: my ($setting,$type) = ($item =~ /^(uploadquota|mysqltables)_(\w+)$/);
20545: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
20546: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 20547: }
20548: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 20549: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 20550: }
20551: if ($currdef ne $newdef) {
20552: if ($item eq 'anonsurvey_threshold') {
20553: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
20554: $changes{$item} = 1;
20555: }
1.276 raeburn 20556: } elsif ($item =~ /^(uploadquota|mysqltables)_/) {
1.289 raeburn 20557: my $setting = $1;
1.276 raeburn 20558: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
20559: $changes{$setting} = 1;
1.198 raeburn 20560: }
20561: }
1.139 raeburn 20562: }
20563: }
1.314 raeburn 20564: my $texengine;
20565: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
20566: $texengine = $env{'form.texengine'};
1.349 raeburn 20567: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
20568: if ($currdef eq '') {
20569: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 20570: $changes{'texengine'} = 1;
20571: }
1.349 raeburn 20572: } elsif ($currdef ne $texengine) {
1.314 raeburn 20573: $changes{'texengine'} = 1;
20574: }
20575: }
20576: if ($texengine ne '') {
20577: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
20578: }
1.264 raeburn 20579: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
20580: my @currclonecode;
20581: if (ref($currclone) eq 'HASH') {
20582: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
20583: @currclonecode = @{$currclone->{'instcode'}};
20584: }
20585: }
20586: my $newclone;
1.289 raeburn 20587: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 20588: $newclone = $env{'form.canclone'};
20589: }
20590: if ($newclone eq 'instcode') {
20591: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
20592: my (%codedefaults,@code_order,@clonecode);
20593: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
20594: \@code_order);
20595: foreach my $item (@code_order) {
20596: if (grep(/^\Q$item\E$/,@newcodes)) {
20597: push(@clonecode,$item);
20598: }
20599: }
20600: if (@clonecode) {
20601: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
20602: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
20603: if (@diffs) {
20604: $changes{'canclone'} = 1;
20605: }
20606: } else {
20607: $newclone eq '';
20608: }
20609: } elsif ($newclone ne '') {
1.289 raeburn 20610: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
20611: }
1.264 raeburn 20612: if ($newclone ne $currclone) {
20613: $changes{'canclone'} = 1;
20614: }
1.257 raeburn 20615: my %credits;
20616: foreach my $type (@types) {
20617: unless ($type eq 'community') {
20618: $credits{$type} = $env{'form.'.$type.'_credits'};
20619: $credits{$type} =~ s/[^\d.]+//g;
20620: }
20621: }
20622: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
20623: ($env{'form.coursecredits'} eq '1')) {
20624: $changes{'coursecredits'} = 1;
20625: foreach my $type (keys(%credits)) {
20626: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20627: }
20628: } else {
1.289 raeburn 20629: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 20630: foreach my $type (@types) {
20631: unless ($type eq 'community') {
1.289 raeburn 20632: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 20633: $changes{'coursecredits'} = 1;
20634: }
20635: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
20636: }
20637: }
20638: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20639: foreach my $type (@types) {
20640: unless ($type eq 'community') {
20641: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
20642: $changes{'coursecredits'} = 1;
20643: last;
20644: }
20645: }
20646: }
20647: }
20648: }
20649: if ($env{'form.postsubmit'} eq '1') {
20650: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
20651: my %currtimeout;
20652: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20653: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
20654: $changes{'postsubmit'} = 1;
20655: }
20656: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20657: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
20658: }
20659: } else {
20660: $changes{'postsubmit'} = 1;
20661: }
20662: foreach my $type (@types) {
20663: my $timeout = $env{'form.'.$type.'_timeout'};
20664: $timeout =~ s/\D//g;
20665: if ($timeout == $staticdefaults{'postsubmit'}) {
20666: $timeout = '';
20667: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
20668: $timeout = '0';
20669: }
20670: unless ($timeout eq '') {
20671: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
20672: }
20673: if (exists($currtimeout{$type})) {
20674: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 20675: $changes{'postsubmit'} = 1;
1.257 raeburn 20676: }
20677: } elsif ($timeout ne '') {
20678: $changes{'postsubmit'} = 1;
20679: }
20680: }
20681: } else {
20682: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
20683: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20684: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
20685: $changes{'postsubmit'} = 1;
20686: }
20687: } else {
20688: $changes{'postsubmit'} = 1;
20689: }
1.192 raeburn 20690: }
1.422 raeburn 20691: my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
20692: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
20693: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
20694: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
20695: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
20696: } else {
20697: foreach my $type (@types) {
20698: if ($staticdefaults{'domexttool'}) {
20699: $olddomexttool{$type} = 1;
20700: } else {
20701: $olddomexttool{$type} = 0;
20702: }
20703: }
20704: }
20705: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
20706: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
20707: } else {
20708: foreach my $type (@types) {
20709: if ($staticdefaults{'exttool'}) {
20710: $oldexttool{$type} = 1;
20711: } else {
20712: $oldexttool{$type} = 0;
20713: }
20714: }
20715: }
20716: foreach my $type (@types) {
20717: unless ($newdomexttool{$type}) {
20718: $newdomexttool{$type} = 0;
20719: }
20720: unless ($newexttool{$type}) {
20721: $newexttool{$type} = 0;
20722: }
20723: if ($newdomexttool{$type} != $olddomexttool{$type}) {
20724: $changes{'domexttool'} = 1;
20725: }
20726: if ($newexttool{$type} != $oldexttool{$type}) {
20727: $changes{'exttool'} = 1;
20728: }
20729: }
20730: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
20731: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.121 raeburn 20732: }
20733: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20734: $dom);
20735: if ($putresult eq 'ok') {
20736: if (keys(%changes) > 0) {
1.213 raeburn 20737: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 20738: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 20739: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 20740: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 20741: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
20742: ($changes{'exttool'}) ) {
20743: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
20744: 'ltiauth') {
1.257 raeburn 20745: if ($changes{$item}) {
20746: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
20747: }
1.289 raeburn 20748: }
1.192 raeburn 20749: if ($changes{'coursecredits'}) {
20750: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 20751: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
20752: $domdefaults{$type.'credits'} =
20753: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
20754: }
20755: }
20756: }
20757: if ($changes{'postsubmit'}) {
20758: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
20759: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
20760: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20761: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
20762: $domdefaults{$type.'postsubtimeout'} =
20763: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20764: }
20765: }
1.192 raeburn 20766: }
20767: }
1.198 raeburn 20768: if ($changes{'uploadquota'}) {
20769: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20770: foreach my $type (@types) {
20771: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
20772: }
20773: }
20774: }
1.264 raeburn 20775: if ($changes{'canclone'}) {
20776: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20777: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20778: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
20779: if (@clonecodes) {
20780: $domdefaults{'canclone'} = join('+',@clonecodes);
20781: }
20782: }
20783: } else {
20784: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
20785: }
20786: }
1.422 raeburn 20787: if ($changes{'domexttool'}) {
20788: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
20789: foreach my $type (@types) {
20790: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
20791: }
20792: }
20793: }
20794: if ($changes{'exttool'}) {
20795: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
20796: foreach my $type (@types) {
20797: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
20798: }
20799: }
20800: }
1.121 raeburn 20801: my $cachetime = 24*60*60;
20802: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20803: if (ref($lastactref) eq 'HASH') {
20804: $lastactref->{'domdefaults'} = 1;
20805: }
1.121 raeburn 20806: }
20807: $resulttext = &mt('Changes made:').'<ul>';
20808: foreach my $item (sort(keys(%changes))) {
20809: if ($item eq 'canuse_pdfforms') {
20810: if ($env{'form.'.$item} eq '1') {
20811: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
20812: } else {
20813: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
20814: }
1.257 raeburn 20815: } elsif ($item eq 'uselcmath') {
20816: if ($env{'form.'.$item} eq '1') {
20817: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
20818: } else {
20819: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
20820: }
20821: } elsif ($item eq 'usejsme') {
20822: if ($env{'form.'.$item} eq '1') {
20823: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
20824: } else {
1.289 raeburn 20825: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 20826: }
1.398 raeburn 20827: } elsif ($item eq 'inline_chem') {
20828: if ($env{'form.'.$item} eq '1') {
20829: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
20830: } else {
20831: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
20832: }
1.314 raeburn 20833: } elsif ($item eq 'texengine') {
20834: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
20835: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
20836: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
20837: }
1.139 raeburn 20838: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 20839: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 20840: } elsif ($item eq 'uploadquota') {
20841: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
20842: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
20843: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
20844: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 20845: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 20846: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 20847: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
20848: '</ul>'.
20849: '</li>';
20850: } else {
20851: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
20852: }
1.276 raeburn 20853: } elsif ($item eq 'mysqltables') {
20854: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
20855: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
20856: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
20857: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
20858: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
20859: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
20860: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
20861: '</ul>'.
20862: '</li>';
20863: } else {
20864: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
20865: }
1.257 raeburn 20866: } elsif ($item eq 'postsubmit') {
20867: if ($domdefaults{'postsubmit'} eq 'off') {
20868: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
20869: } else {
20870: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 20871: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 20872: $resulttext .= &mt('durations:').'<ul>';
20873: foreach my $type (@types) {
20874: $resulttext .= '<li>';
20875: my $timeout;
20876: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
20877: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
20878: }
20879: my $display;
20880: if ($timeout eq '0') {
20881: $display = &mt('unlimited');
20882: } elsif ($timeout eq '') {
20883: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
20884: } else {
20885: $display = &mt('[quant,_1,second]',$timeout);
20886: }
20887: if ($type eq 'community') {
20888: $resulttext .= &mt('Communities');
20889: } elsif ($type eq 'official') {
20890: $resulttext .= &mt('Official courses');
20891: } elsif ($type eq 'unofficial') {
20892: $resulttext .= &mt('Unofficial courses');
20893: } elsif ($type eq 'textbook') {
20894: $resulttext .= &mt('Textbook courses');
1.271 raeburn 20895: } elsif ($type eq 'placement') {
20896: $resulttext .= &mt('Placement tests');
1.257 raeburn 20897: }
20898: $resulttext .= ' -- '.$display.'</li>';
20899: }
20900: $resulttext .= '</ul>';
20901: }
1.289 raeburn 20902: $resulttext .= '</li>';
1.257 raeburn 20903: }
1.192 raeburn 20904: } elsif ($item eq 'coursecredits') {
20905: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
20906: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 20907: ($domdefaults{'unofficialcredits'} eq '') &&
20908: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 20909: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20910: } else {
20911: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
20912: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
20913: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 20914: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 20915: '</ul>'.
20916: '</li>';
20917: }
20918: } else {
20919: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
20920: }
1.264 raeburn 20921: } elsif ($item eq 'canclone') {
20922: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
20923: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
20924: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
20925: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
20926: }
20927: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
20928: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
20929: } else {
1.289 raeburn 20930: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 20931: }
1.404 raeburn 20932: } elsif ($item eq 'ltiauth') {
20933: if ($env{'form.'.$item} eq '1') {
20934: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
20935: } else {
20936: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
20937: }
1.422 raeburn 20938: } elsif ($item eq 'domexttool') {
20939: my @noyes = (&mt('no'),&mt('yes'));
20940: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
20941: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
20942: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
20943: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
20944: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
20945: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
20946: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
20947: '</ul>'.
20948: '</li>';
20949: } else {
20950: $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
20951: }
20952: } elsif ($item eq 'exttool') {
20953: my @noyes = (&mt('no'),&mt('yes'));
20954: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
20955: $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
20956: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
20957: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
20958: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
20959: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
20960: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
20961: '</ul>'.
20962: '</li>';
20963: } else {
20964: $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
20965: }
1.140 raeburn 20966: }
1.121 raeburn 20967: }
20968: $resulttext .= '</ul>';
20969: } else {
20970: $resulttext = &mt('No changes made to course defaults');
20971: }
20972: } else {
20973: $resulttext = '<span class="LC_error">'.
20974: &mt('An error occurred: [_1]',$putresult).'</span>';
20975: }
20976: return $resulttext;
20977: }
20978:
1.231 raeburn 20979: sub modify_selfenrollment {
20980: my ($dom,$lastactref,%domconfig) = @_;
20981: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 20982: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 20983: my %titles = &tool_titles();
1.232 raeburn 20984: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
20985: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 20986: $ordered{'default'} = ['types','registered','approval','limit'];
20987:
20988: my (%roles,%shown,%toplevel);
20989: $roles{'0'} = &Apache::lonnet::plaintext('dc');
20990:
20991: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
20992: if ($domconfig{'selfenrollment'} eq '') {
20993: $domconfig{'selfenrollment'} = {};
20994: }
20995: }
20996: %toplevel = (
20997: admin => 'Configuration Rights',
20998: default => 'Default settings',
20999: validation => 'Validation of self-enrollment requests',
21000: );
1.233 raeburn 21001: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21002:
21003: if (ref($ordered{'admin'}) eq 'ARRAY') {
21004: foreach my $item (@{$ordered{'admin'}}) {
21005: foreach my $type (@types) {
21006: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21007: $selfenrollhash{'admin'}{$type}{$item} = 1;
21008: } else {
21009: $selfenrollhash{'admin'}{$type}{$item} = 0;
21010: }
21011: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21012: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21013: if ($selfenrollhash{'admin'}{$type}{$item} ne
21014: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21015: push(@{$changes{'admin'}{$type}},$item);
21016: }
21017: } else {
21018: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21019: push(@{$changes{'admin'}{$type}},$item);
21020: }
21021: }
21022: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21023: push(@{$changes{'admin'}{$type}},$item);
21024: }
21025: }
21026: }
21027: }
21028:
21029: foreach my $item (@{$ordered{'default'}}) {
21030: foreach my $type (@types) {
21031: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21032: if ($item eq 'types') {
21033: unless (($value eq 'all') || ($value eq 'dom')) {
21034: $value = '';
21035: }
21036: } elsif ($item eq 'registered') {
21037: unless ($value eq '1') {
21038: $value = 0;
21039: }
21040: } elsif ($item eq 'approval') {
21041: unless ($value =~ /^[012]$/) {
21042: $value = 0;
21043: }
21044: } else {
21045: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21046: $value = 'none';
21047: }
21048: }
21049: $selfenrollhash{'default'}{$type}{$item} = $value;
21050: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21051: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21052: if ($selfenrollhash{'default'}{$type}{$item} ne
21053: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21054: push(@{$changes{'default'}{$type}},$item);
21055: }
21056: } else {
21057: push(@{$changes{'default'}{$type}},$item);
21058: }
21059: } else {
21060: push(@{$changes{'default'}{$type}},$item);
21061: }
21062: if ($item eq 'limit') {
21063: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21064: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21065: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21066: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21067: }
21068: } else {
21069: $selfenrollhash{'default'}{$type}{'cap'} = '';
21070: }
21071: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21072: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21073: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21074: push(@{$changes{'default'}{$type}},'cap');
21075: }
21076: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21077: push(@{$changes{'default'}{$type}},'cap');
21078: }
21079: }
21080: }
21081: }
21082:
21083: foreach my $item (@{$itemsref}) {
21084: if ($item eq 'fields') {
21085: my @changed;
21086: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21087: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21088: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21089: }
21090: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21091: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21092: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21093: $domconfig{'selfenrollment'}{'validation'}{$item});
21094: } else {
21095: @changed = @{$selfenrollhash{'validation'}{$item}};
21096: }
21097: } else {
21098: @changed = @{$selfenrollhash{'validation'}{$item}};
21099: }
21100: if (@changed) {
21101: if ($selfenrollhash{'validation'}{$item}) {
21102: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21103: } else {
21104: $changes{'validation'}{$item} = &mt('None');
21105: }
21106: }
21107: } else {
21108: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21109: if ($item eq 'markup') {
21110: if ($env{'form.selfenroll_validation_'.$item}) {
21111: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21112: }
21113: }
21114: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21115: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21116: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21117: }
21118: }
21119: }
21120: }
21121:
21122: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21123: $dom);
21124: if ($putresult eq 'ok') {
21125: if (keys(%changes) > 0) {
21126: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21127: $resulttext = &mt('Changes made:').'<ul>';
21128: foreach my $key ('admin','default','validation') {
21129: if (ref($changes{$key}) eq 'HASH') {
21130: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21131: if ($key eq 'validation') {
21132: foreach my $item (@{$itemsref}) {
21133: if (exists($changes{$key}{$item})) {
21134: if ($item eq 'markup') {
21135: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21136: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21137: } else {
21138: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21139: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21140: }
21141: }
21142: }
21143: } else {
21144: foreach my $type (@types) {
21145: if ($type eq 'community') {
21146: $roles{'1'} = &mt('Community personnel');
21147: } else {
21148: $roles{'1'} = &mt('Course personnel');
21149: }
21150: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21151: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21152: if ($key eq 'admin') {
21153: my @mgrdc = ();
21154: if (ref($ordered{$key}) eq 'ARRAY') {
21155: foreach my $item (@{$ordered{'admin'}}) {
21156: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21157: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21158: push(@mgrdc,$item);
21159: }
21160: }
21161: }
21162: if (@mgrdc) {
21163: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21164: } else {
21165: delete($domdefaults{$type.'selfenrolladmdc'});
21166: }
21167: }
21168: } else {
21169: if (ref($ordered{$key}) eq 'ARRAY') {
21170: foreach my $item (@{$ordered{$key}}) {
21171: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21172: $domdefaults{$type.'selfenroll'.$item} =
21173: $selfenrollhash{$key}{$type}{$item};
21174: }
21175: }
21176: }
21177: }
21178: }
1.231 raeburn 21179: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21180: foreach my $item (@{$ordered{$key}}) {
21181: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21182: $resulttext .= '<li>';
21183: if ($key eq 'admin') {
21184: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21185: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21186: } else {
21187: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21188: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21189: }
21190: $resulttext .= '</li>';
21191: }
21192: }
21193: $resulttext .= '</ul></li>';
21194: }
21195: }
21196: $resulttext .= '</ul></li>';
21197: }
21198: }
1.305 raeburn 21199: }
21200: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21201: my $cachetime = 24*60*60;
21202: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21203: if (ref($lastactref) eq 'HASH') {
21204: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21205: }
1.231 raeburn 21206: }
21207: $resulttext .= '</ul>';
21208: } else {
21209: $resulttext = &mt('No changes made to self-enrollment settings');
21210: }
21211: } else {
21212: $resulttext = '<span class="LC_error">'.
21213: &mt('An error occurred: [_1]',$putresult).'</span>';
21214: }
21215: return $resulttext;
21216: }
21217:
1.373 raeburn 21218: sub modify_wafproxy {
21219: my ($dom,$action,$lastactref,%domconfig) = @_;
21220: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21221: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21222: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21223: foreach my $server (sort(keys(%servers))) {
21224: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21225: if ($serverhome eq $server) {
21226: my $serverdom = &Apache::lonnet::host_domain($server);
21227: if ($serverdom eq $dom) {
21228: $canset{$server} = 1;
21229: }
21230: }
21231: }
1.381 raeburn 21232: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21233: %{$values{$dom}} = ();
21234: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21235: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21236: }
1.388 raeburn 21237: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21238: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21239: }
1.382 raeburn 21240: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 21241: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
21242: }
21243: }
1.373 raeburn 21244: my $output;
21245: if (keys(%canset)) {
21246: %{$wafproxy{'alias'}} = ();
1.388 raeburn 21247: %{$wafproxy{'saml'}} = ();
1.373 raeburn 21248: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 21249: if ($env{'form.wafproxy_'.$dom}) {
21250: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
21251: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
21252: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
21253: $changes{'alias'} = 1;
21254: }
1.388 raeburn 21255: if ($env{'form.wafproxy_alias_saml_'.$key}) {
21256: $wafproxy{'saml'}{$key} = 1;
21257: }
21258: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
21259: $changes{'saml'} = 1;
21260: }
1.381 raeburn 21261: } else {
21262: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 21263: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 21264: if ($curralias{$key}) {
21265: $changes{'alias'} = 1;
21266: }
1.388 raeburn 21267: if ($currsaml{$key}) {
21268: $changes{'saml'} = 1;
21269: }
1.373 raeburn 21270: }
21271: if ($wafproxy{'alias'}{$key} eq '') {
21272: if ($curralias{$key}) {
21273: $expirecache{$key} = 1;
21274: }
21275: delete($wafproxy{'alias'}{$key});
21276: }
1.388 raeburn 21277: if ($wafproxy{'saml'}{$key} eq '') {
21278: if ($currsaml{$key}) {
21279: $expiresaml{$key} = 1;
21280: }
21281: delete($wafproxy{'saml'}{$key});
21282: }
1.373 raeburn 21283: }
21284: unless (keys(%{$wafproxy{'alias'}})) {
21285: delete($wafproxy{'alias'});
21286: }
1.388 raeburn 21287: unless (keys(%{$wafproxy{'saml'}})) {
21288: delete($wafproxy{'saml'});
21289: }
21290: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 21291: my %warn = (
21292: trusted => 'trusted IP range(s)',
1.381 raeburn 21293: vpnint => 'internal IP range(s) for VPN sessions(s)',
21294: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 21295: );
1.382 raeburn 21296: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21297: my $possible = $env{'form.wafproxy_'.$item};
21298: $possible =~ s/^\s+|\s+$//g;
21299: if ($possible ne '') {
1.381 raeburn 21300: if ($item eq 'remoteip') {
21301: if ($possible =~ /^[mhn]$/) {
21302: $wafproxy{$item} = $possible;
21303: }
21304: } elsif ($item eq 'ipheader') {
21305: if ($wafproxy{'remoteip'} eq 'h') {
21306: $wafproxy{$item} = $possible;
21307: }
1.382 raeburn 21308: } elsif ($item eq 'sslopt') {
21309: if ($possible =~ /^0|1$/) {
21310: $wafproxy{$item} = $possible;
21311: }
1.373 raeburn 21312: } else {
21313: my (@ok,$count);
1.381 raeburn 21314: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
21315: unless ($env{'form.wafproxy_vpnaccess'}) {
21316: $possible = '';
21317: }
21318: } elsif ($item eq 'trusted') {
21319: unless ($wafproxy{'remoteip'} eq 'h') {
21320: $possible = '';
21321: }
21322: }
21323: unless ($possible eq '') {
21324: $possible =~ s/[\r\n]+/\s/g;
21325: $possible =~ s/\s*-\s*/-/g;
21326: $possible =~ s/\s+/,/g;
1.393 raeburn 21327: $possible =~ s/,+/,/g;
1.381 raeburn 21328: }
1.373 raeburn 21329: $count = 0;
1.381 raeburn 21330: if ($possible ne '') {
1.373 raeburn 21331: foreach my $poss (split(/\,/,$possible)) {
21332: $count ++;
1.393 raeburn 21333: $poss = &validate_ip_pattern($poss);
21334: if ($poss ne '') {
1.373 raeburn 21335: push(@ok,$poss);
21336: }
21337: }
21338: my $diff = $count - scalar(@ok);
21339: if ($diff) {
21340: push(@warnings,'<li>'.
21341: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
21342: $diff,$warn{$item}).
21343: '</li>');
21344: }
1.393 raeburn 21345: if (@ok) {
21346: my @cidr_list;
21347: foreach my $item (@ok) {
21348: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
21349: }
21350: $wafproxy{$item} = join(',',@cidr_list);
21351: }
1.373 raeburn 21352: }
21353: }
1.381 raeburn 21354: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 21355: $changes{$item} = 1;
21356: }
1.381 raeburn 21357: } elsif ($currvalue{$item}) {
21358: $changes{$item} = 1;
21359: }
21360: }
21361: } else {
21362: if (keys(%curralias)) {
21363: $changes{'alias'} = 1;
1.388 raeburn 21364: }
21365: if (keys(%currsaml)) {
21366: $changes{'saml'} = 1;
1.381 raeburn 21367: }
21368: if (keys(%currvalue)) {
21369: foreach my $key (keys(%currvalue)) {
21370: $changes{$key} = 1;
1.373 raeburn 21371: }
21372: }
21373: }
21374: if (keys(%changes)) {
21375: my %defaultshash = (
21376: wafproxy => \%wafproxy,
21377: );
21378: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21379: $dom);
21380: if ($putresult eq 'ok') {
21381: my $cachetime = 24*60*60;
21382: my (%domdefaults,$updatedomdefs);
1.382 raeburn 21383: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21384: if ($changes{$item}) {
21385: unless ($updatedomdefs) {
21386: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
21387: $updatedomdefs = 1;
21388: }
21389: if ($wafproxy{$item}) {
21390: $domdefaults{'waf_'.$item} = $wafproxy{$item};
21391: } elsif (exists($domdefaults{'waf_'.$item})) {
21392: delete($domdefaults{'waf_'.$item});
21393: }
21394: }
21395: }
21396: if ($updatedomdefs) {
21397: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21398: if (ref($lastactref) eq 'HASH') {
21399: $lastactref->{'domdefaults'} = 1;
21400: }
21401: }
21402: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
21403: my %updates = %expirecache;
21404: foreach my $key (keys(%expirecache)) {
21405: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
21406: }
21407: if (ref($wafproxy{'alias'}) eq 'HASH') {
21408: my $cachetime = 24*60*60;
21409: foreach my $key (keys(%{$wafproxy{'alias'}})) {
21410: $updates{$key} = 1;
21411: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
21412: $cachetime);
21413: }
21414: }
21415: if (ref($lastactref) eq 'HASH') {
21416: $lastactref->{'proxyalias'} = \%updates;
21417: }
21418: }
1.388 raeburn 21419: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
21420: my %samlupdates = %expiresaml;
21421: foreach my $key (keys(%expiresaml)) {
21422: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
21423: }
21424: if (ref($wafproxy{'saml'}) eq 'HASH') {
21425: my $cachetime = 24*60*60;
21426: foreach my $key (keys(%{$wafproxy{'saml'}})) {
21427: $samlupdates{$key} = 1;
21428: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
21429: $cachetime);
21430: }
21431: }
21432: if (ref($lastactref) eq 'HASH') {
21433: $lastactref->{'proxysaml'} = \%samlupdates;
21434: }
21435: }
1.373 raeburn 21436: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 21437: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 21438: if ($changes{$item}) {
21439: if ($item eq 'alias') {
21440: my $numaliased = 0;
21441: if (ref($wafproxy{'alias'}) eq 'HASH') {
21442: my $shown;
21443: if (keys(%{$wafproxy{'alias'}})) {
21444: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
21445: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
21446: &Apache::lonnet::hostname($server),
21447: $wafproxy{'alias'}{$server}).'</li>';
21448: $numaliased ++;
21449: }
21450: if ($numaliased) {
21451: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
21452: '<ul>'.$shown.'</ul>').'</li>';
21453: }
21454: }
21455: }
21456: unless ($numaliased) {
21457: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
21458: }
1.388 raeburn 21459: } elsif ($item eq 'saml') {
21460: my $shown;
21461: if (ref($wafproxy{'saml'}) eq 'HASH') {
21462: if (keys(%{$wafproxy{'saml'}})) {
21463: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
21464: }
21465: }
21466: if ($shown) {
1.396 raeburn 21467: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 21468: $shown).'</li>';
21469: } else {
1.396 raeburn 21470: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 21471: }
1.373 raeburn 21472: } else {
1.381 raeburn 21473: if ($item eq 'remoteip') {
21474: my %ip_methods = &remoteip_methods();
21475: if ($wafproxy{$item} =~ /^[mh]$/) {
21476: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
21477: $ip_methods{$wafproxy{$item}}).'</li>';
21478: } else {
21479: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
21480: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
21481: '</li>';
21482: } else {
21483: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
21484: }
21485: }
21486: } elsif ($item eq 'ipheader') {
1.373 raeburn 21487: if ($wafproxy{$item}) {
1.381 raeburn 21488: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 21489: $wafproxy{$item}).'</li>';
21490: } else {
1.381 raeburn 21491: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 21492: }
21493: } elsif ($item eq 'trusted') {
21494: if ($wafproxy{$item}) {
1.381 raeburn 21495: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 21496: $wafproxy{$item}).'</li>';
21497: } else {
21498: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
21499: }
1.381 raeburn 21500: } elsif ($item eq 'vpnint') {
21501: if ($wafproxy{$item}) {
21502: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
21503: $wafproxy{$item}).'</li>';
21504: } else {
21505: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
21506: }
21507: } elsif ($item eq 'vpnext') {
1.373 raeburn 21508: if ($wafproxy{$item}) {
1.381 raeburn 21509: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 21510: $wafproxy{$item}).'</li>';
21511: } else {
1.381 raeburn 21512: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 21513: }
1.382 raeburn 21514: } elsif ($item eq 'sslopt') {
21515: if ($wafproxy{$item}) {
21516: $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>';
21517: } else {
21518: $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>';
21519: }
1.373 raeburn 21520: }
21521: }
21522: }
21523: }
1.420 raeburn 21524: $output .= '</ul>';
1.373 raeburn 21525: } else {
21526: $output = '<span class="LC_error">'.
21527: &mt('An error occurred: [_1]',$putresult).'</span>';
21528: }
21529: } elsif (keys(%canset)) {
21530: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
21531: }
21532: if (@warnings) {
21533: $output .= '<br />'.&mt('Warnings:').'<ul>'.
21534: join("\n",@warnings).'</ul>';
21535: }
21536: return $output;
21537: }
21538:
21539: sub validate_ip_pattern {
21540: my ($pattern) = @_;
21541: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
21542: my ($start,$end) = ($1,$2);
21543: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 21544: if (($start !~ m{/}) && ($end !~ m{/})) {
21545: return $start.'-'.$end;
21546: }
21547: }
21548: } elsif ($pattern ne '') {
21549: $pattern = &Net::CIDR::cidrvalidate($pattern);
21550: if ($pattern ne '') {
21551: return $pattern;
1.373 raeburn 21552: }
21553: }
1.393 raeburn 21554: return;
1.373 raeburn 21555: }
21556:
1.137 raeburn 21557: sub modify_usersessions {
1.212 raeburn 21558: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 21559: my @hostingtypes = ('version','excludedomain','includedomain');
21560: my @offloadtypes = ('primary','default');
21561: my %types = (
21562: remote => \@hostingtypes,
21563: hosted => \@hostingtypes,
21564: spares => \@offloadtypes,
21565: );
21566: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 21567: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 21568: my (%by_ip,%by_location,@intdoms,@instdoms);
21569: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 21570: my @locations = sort(keys(%by_location));
1.137 raeburn 21571: my (%defaultshash,%changes);
21572: foreach my $prefix (@prefixes) {
21573: $defaultshash{'usersessions'}{$prefix} = {};
21574: }
1.212 raeburn 21575: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 21576: my $resulttext;
1.138 raeburn 21577: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 21578: foreach my $prefix (@prefixes) {
1.145 raeburn 21579: next if ($prefix eq 'spares');
21580: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 21581: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21582: if ($type eq 'version') {
21583: my $value = $env{'form.'.$prefix.'_'.$type};
21584: my $okvalue;
21585: if ($value ne '') {
21586: if (grep(/^\Q$value\E$/,@lcversions)) {
21587: $okvalue = $value;
21588: }
21589: }
21590: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21591: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21592: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
21593: if ($inuse == 0) {
21594: $changes{$prefix}{$type} = 1;
21595: } else {
21596: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
21597: $changes{$prefix}{$type} = 1;
21598: }
21599: if ($okvalue ne '') {
21600: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21601: }
21602: }
21603: } else {
21604: if (($inuse == 1) && ($okvalue ne '')) {
21605: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21606: $changes{$prefix}{$type} = 1;
21607: }
21608: }
21609: } else {
21610: if (($inuse == 1) && ($okvalue ne '')) {
21611: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21612: $changes{$prefix}{$type} = 1;
21613: }
21614: }
21615: } else {
21616: if (($inuse == 1) && ($okvalue ne '')) {
21617: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
21618: $changes{$prefix}{$type} = 1;
21619: }
21620: }
21621: } else {
21622: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21623: my @okvals;
21624: foreach my $val (@vals) {
1.138 raeburn 21625: if ($val =~ /:/) {
21626: my @items = split(/:/,$val);
21627: foreach my $item (@items) {
21628: if (ref($by_location{$item}) eq 'ARRAY') {
21629: push(@okvals,$item);
21630: }
21631: }
21632: } else {
21633: if (ref($by_location{$val}) eq 'ARRAY') {
21634: push(@okvals,$val);
21635: }
1.137 raeburn 21636: }
21637: }
21638: @okvals = sort(@okvals);
21639: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21640: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
21641: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21642: if ($inuse == 0) {
21643: $changes{$prefix}{$type} = 1;
21644: } else {
21645: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21646: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
21647: if (@changed > 0) {
21648: $changes{$prefix}{$type} = 1;
21649: }
21650: }
21651: } else {
21652: if ($inuse == 1) {
21653: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21654: $changes{$prefix}{$type} = 1;
21655: }
21656: }
21657: } else {
21658: if ($inuse == 1) {
21659: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21660: $changes{$prefix}{$type} = 1;
21661: }
21662: }
21663: } else {
21664: if ($inuse == 1) {
21665: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
21666: $changes{$prefix}{$type} = 1;
21667: }
21668: }
21669: }
21670: }
21671: }
1.145 raeburn 21672:
21673: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 21674: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 21675: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
21676: my $savespares;
21677:
21678: foreach my $lonhost (sort(keys(%servers))) {
21679: my $serverhomeID =
21680: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 21681: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 21682: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
21683: my %spareschg;
21684: foreach my $type (@{$types{'spares'}}) {
21685: my @okspares;
21686: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
21687: foreach my $server (@checked) {
1.152 raeburn 21688: if (&Apache::lonnet::hostname($server) ne '') {
21689: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
21690: unless (grep(/^\Q$server\E$/,@okspares)) {
21691: push(@okspares,$server);
21692: }
1.145 raeburn 21693: }
21694: }
21695: }
21696: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
21697: my $newspare;
1.152 raeburn 21698: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
21699: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 21700: $newspare = $new;
21701: }
21702: }
1.152 raeburn 21703: my @spares;
21704: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
21705: @spares = sort(@okspares,$newspare);
21706: } else {
21707: @spares = sort(@okspares);
21708: }
21709: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 21710: if (ref($spareid{$lonhost}) eq 'HASH') {
21711: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 21712: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 21713: if (@diffs > 0) {
21714: $spareschg{$type} = 1;
21715: }
21716: }
21717: }
21718: }
21719: if (keys(%spareschg) > 0) {
21720: $changes{'spares'}{$lonhost} = \%spareschg;
21721: }
21722: }
1.261 raeburn 21723: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 21724: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 21725: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
21726: my @okoffload;
21727: if (@offloadnow) {
21728: foreach my $server (@offloadnow) {
21729: if (&Apache::lonnet::hostname($server) ne '') {
21730: unless (grep(/^\Q$server\E$/,@okoffload)) {
21731: push(@okoffload,$server);
21732: }
21733: }
21734: }
21735: if (@okoffload) {
21736: foreach my $lonhost (@okoffload) {
21737: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
21738: }
21739: }
21740: }
1.371 raeburn 21741: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
21742: my @okoffloadoth;
21743: if (@offloadoth) {
21744: foreach my $server (@offloadoth) {
21745: if (&Apache::lonnet::hostname($server) ne '') {
21746: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
21747: push(@okoffloadoth,$server);
21748: }
21749: }
21750: }
21751: if (@okoffloadoth) {
21752: foreach my $lonhost (@okoffloadoth) {
21753: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
21754: }
21755: }
21756: }
1.145 raeburn 21757: if (ref($domconfig{'usersessions'}) eq 'HASH') {
21758: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
21759: if (ref($changes{'spares'}) eq 'HASH') {
21760: if (keys(%{$changes{'spares'}}) > 0) {
21761: $savespares = 1;
21762: }
21763: }
21764: } else {
21765: $savespares = 1;
21766: }
1.371 raeburn 21767: foreach my $offload ('offloadnow','offloadoth') {
21768: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
21769: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
21770: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
21771: $changes{$offload} = 1;
21772: last;
21773: }
1.261 raeburn 21774: }
1.371 raeburn 21775: unless ($changes{$offload}) {
21776: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
21777: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
21778: $changes{$offload} = 1;
21779: last;
21780: }
1.261 raeburn 21781: }
21782: }
1.371 raeburn 21783: } else {
21784: if (($offload eq 'offloadnow') && (@okoffload)) {
21785: $changes{'offloadnow'} = 1;
21786: }
21787: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
21788: $changes{'offloadoth'} = 1;
21789: }
21790: }
21791: }
21792: } else {
21793: if (@okoffload) {
1.261 raeburn 21794: $changes{'offloadnow'} = 1;
21795: }
1.371 raeburn 21796: if (@okoffloadoth) {
21797: $changes{'offloadoth'} = 1;
21798: }
1.145 raeburn 21799: }
1.147 raeburn 21800: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
21801: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 21802: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21803: $dom);
21804: if ($putresult eq 'ok') {
21805: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21806: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
21807: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
21808: }
21809: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
21810: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
21811: }
1.261 raeburn 21812: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21813: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
21814: }
1.371 raeburn 21815: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21816: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
21817: }
1.137 raeburn 21818: }
21819: my $cachetime = 24*60*60;
21820: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 21821: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 21822: if (ref($lastactref) eq 'HASH') {
21823: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 21824: $lastactref->{'usersessions'} = 1;
1.212 raeburn 21825: }
1.147 raeburn 21826: if (keys(%changes) > 0) {
21827: my %lt = &usersession_titles();
21828: $resulttext = &mt('Changes made:').'<ul>';
21829: foreach my $prefix (@prefixes) {
21830: if (ref($changes{$prefix}) eq 'HASH') {
21831: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
21832: if ($prefix eq 'spares') {
21833: if (ref($changes{$prefix}) eq 'HASH') {
21834: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
21835: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 21836: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 21837: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
21838: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 21839: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
21840: foreach my $type (@{$types{$prefix}}) {
21841: if ($changes{$prefix}{$lonhost}{$type}) {
21842: my $offloadto = &mt('None');
21843: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
21844: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
21845: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
21846: }
1.145 raeburn 21847: }
1.147 raeburn 21848: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 21849: }
1.137 raeburn 21850: }
21851: }
1.147 raeburn 21852: $resulttext .= '</li>';
1.137 raeburn 21853: }
21854: }
1.147 raeburn 21855: } else {
21856: foreach my $type (@{$types{$prefix}}) {
21857: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 21858: my ($newvalue,$notinuse);
1.147 raeburn 21859: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
21860: if (ref($defaultshash{'usersessions'}{$prefix})) {
21861: if ($type eq 'version') {
21862: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 21863: } else {
21864: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
21865: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
21866: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
21867: }
21868: } else {
21869: $notinuse = 1;
1.147 raeburn 21870: }
1.145 raeburn 21871: }
21872: }
21873: }
1.147 raeburn 21874: if ($newvalue eq '') {
21875: if ($type eq 'version') {
21876: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 21877: } elsif ($notinuse) {
21878: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 21879: } else {
21880: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
21881: }
1.145 raeburn 21882: } else {
1.147 raeburn 21883: if ($type eq 'version') {
1.344 raeburn 21884: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 21885: }
21886: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 21887: }
1.137 raeburn 21888: }
21889: }
21890: }
1.147 raeburn 21891: $resulttext .= '</ul>';
1.137 raeburn 21892: }
21893: }
1.261 raeburn 21894: if ($changes{'offloadnow'}) {
21895: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
21896: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 21897: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 21898: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
21899: $resulttext .= '<li>'.$lonhost.'</li>';
21900: }
21901: $resulttext .= '</ul>';
21902: } else {
1.371 raeburn 21903: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
21904: }
21905: } else {
21906: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
21907: }
21908: }
21909: if ($changes{'offloadoth'}) {
21910: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
21911: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
21912: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
21913: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
21914: $resulttext .= '<li>'.$lonhost.'</li>';
21915: }
21916: $resulttext .= '</ul>';
21917: } else {
21918: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 21919: }
21920: } else {
1.371 raeburn 21921: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 21922: }
21923: }
1.147 raeburn 21924: $resulttext .= '</ul>';
21925: } else {
21926: $resulttext = $nochgmsg;
1.137 raeburn 21927: }
21928: } else {
21929: $resulttext = '<span class="LC_error">'.
21930: &mt('An error occurred: [_1]',$putresult).'</span>';
21931: }
21932: } else {
1.147 raeburn 21933: $resulttext = $nochgmsg;
1.137 raeburn 21934: }
21935: return $resulttext;
21936: }
21937:
1.275 raeburn 21938: sub modify_ssl {
21939: my ($dom,$lastactref,%domconfig) = @_;
21940: my (%by_ip,%by_location,@intdoms,@instdoms);
21941: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
21942: my @locations = sort(keys(%by_location));
21943: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21944: my (%defaultshash,%changes);
21945: my $action = 'ssl';
1.293 raeburn 21946: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 21947: foreach my $prefix (@prefixes) {
21948: $defaultshash{$action}{$prefix} = {};
21949: }
21950: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21951: my $resulttext;
21952: my %iphost = &Apache::lonnet::get_iphost();
21953: my @reptypes = ('certreq','nocertreq');
21954: my @connecttypes = ('dom','intdom','other');
21955: my %types = (
1.293 raeburn 21956: connto => \@connecttypes,
21957: connfrom => \@connecttypes,
21958: replication => \@reptypes,
1.275 raeburn 21959: );
21960: foreach my $prefix (sort(keys(%types))) {
21961: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 21962: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 21963: my $value = 'yes';
21964: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
21965: $value = $env{'form.'.$prefix.'_'.$type};
21966: }
1.335 raeburn 21967: if (ref($domconfig{$action}) eq 'HASH') {
21968: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
21969: if ($domconfig{$action}{$prefix}{$type} ne '') {
21970: if ($value ne $domconfig{$action}{$prefix}{$type}) {
21971: $changes{$prefix}{$type} = 1;
21972: }
21973: $defaultshash{$action}{$prefix}{$type} = $value;
21974: } else {
21975: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 21976: $changes{$prefix}{$type} = 1;
21977: }
21978: } else {
21979: $defaultshash{$action}{$prefix}{$type} = $value;
21980: $changes{$prefix}{$type} = 1;
21981: }
21982: } else {
21983: $defaultshash{$action}{$prefix}{$type} = $value;
21984: $changes{$prefix}{$type} = 1;
21985: }
21986: if (($type eq 'dom') && (keys(%servers) == 1)) {
21987: delete($changes{$prefix}{$type});
21988: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
21989: delete($changes{$prefix}{$type});
21990: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
21991: delete($changes{$prefix}{$type});
21992: }
21993: } elsif ($prefix eq 'replication') {
21994: if (@locations > 0) {
21995: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
21996: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
21997: my @okvals;
21998: foreach my $val (@vals) {
21999: if ($val =~ /:/) {
22000: my @items = split(/:/,$val);
22001: foreach my $item (@items) {
22002: if (ref($by_location{$item}) eq 'ARRAY') {
22003: push(@okvals,$item);
22004: }
22005: }
22006: } else {
22007: if (ref($by_location{$val}) eq 'ARRAY') {
22008: push(@okvals,$val);
22009: }
22010: }
22011: }
22012: @okvals = sort(@okvals);
22013: if (ref($domconfig{$action}) eq 'HASH') {
22014: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22015: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22016: if ($inuse == 0) {
22017: $changes{$prefix}{$type} = 1;
22018: } else {
22019: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22020: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22021: if (@changed > 0) {
22022: $changes{$prefix}{$type} = 1;
22023: }
22024: }
22025: } else {
22026: if ($inuse == 1) {
22027: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22028: $changes{$prefix}{$type} = 1;
22029: }
22030: }
22031: } else {
22032: if ($inuse == 1) {
22033: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22034: $changes{$prefix}{$type} = 1;
22035: }
22036: }
22037: } else {
22038: if ($inuse == 1) {
22039: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22040: $changes{$prefix}{$type} = 1;
22041: }
22042: }
22043: }
22044: }
22045: }
22046: }
1.336 raeburn 22047: if (keys(%changes)) {
22048: foreach my $prefix (keys(%changes)) {
22049: if (ref($changes{$prefix}) eq 'HASH') {
22050: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22051: delete($changes{$prefix});
22052: }
22053: } else {
22054: delete($changes{$prefix});
22055: }
22056: }
22057: }
1.275 raeburn 22058: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22059: if (keys(%changes) > 0) {
22060: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22061: $dom);
22062: if ($putresult eq 'ok') {
22063: if (ref($defaultshash{$action}) eq 'HASH') {
22064: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22065: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22066: }
1.293 raeburn 22067: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22068: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22069: }
22070: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22071: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22072: }
22073: }
22074: my $cachetime = 24*60*60;
22075: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22076: if (ref($lastactref) eq 'HASH') {
22077: $lastactref->{'domdefaults'} = 1;
22078: }
22079: if (keys(%changes) > 0) {
22080: my %titles = &ssl_titles();
22081: $resulttext = &mt('Changes made:').'<ul>';
22082: foreach my $prefix (@prefixes) {
22083: if (ref($changes{$prefix}) eq 'HASH') {
22084: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22085: foreach my $type (@{$types{$prefix}}) {
22086: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22087: my ($newvalue,$notinuse);
1.275 raeburn 22088: if (ref($defaultshash{$action}) eq 'HASH') {
22089: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22090: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22091: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22092: } else {
22093: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22094: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22095: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22096: }
22097: } else {
22098: $notinuse = 1;
1.275 raeburn 22099: }
22100: }
22101: }
1.344 raeburn 22102: if ($notinuse) {
22103: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22104: } elsif ($newvalue eq '') {
1.275 raeburn 22105: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22106: } else {
22107: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22108: }
22109: }
22110: }
22111: }
22112: $resulttext .= '</ul>';
22113: }
22114: }
22115: } else {
22116: $resulttext = $nochgmsg;
22117: }
22118: } else {
22119: $resulttext = '<span class="LC_error">'.
22120: &mt('An error occurred: [_1]',$putresult).'</span>';
22121: }
22122: } else {
22123: $resulttext = $nochgmsg;
22124: }
22125: return $resulttext;
22126: }
22127:
1.279 raeburn 22128: sub modify_trust {
22129: my ($dom,$lastactref,%domconfig) = @_;
22130: my (%by_ip,%by_location,@intdoms,@instdoms);
22131: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22132: my @locations = sort(keys(%by_location));
22133: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22134: my @types = ('exc','inc');
22135: my (%defaultshash,%changes);
22136: foreach my $prefix (@prefixes) {
22137: $defaultshash{'trust'}{$prefix} = {};
22138: }
22139: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22140: my $resulttext;
22141: foreach my $prefix (@prefixes) {
22142: foreach my $type (@types) {
22143: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22144: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22145: my @okvals;
22146: foreach my $val (@vals) {
22147: if ($val =~ /:/) {
22148: my @items = split(/:/,$val);
22149: foreach my $item (@items) {
22150: if (ref($by_location{$item}) eq 'ARRAY') {
22151: push(@okvals,$item);
22152: }
22153: }
22154: } else {
22155: if (ref($by_location{$val}) eq 'ARRAY') {
22156: push(@okvals,$val);
22157: }
22158: }
22159: }
22160: @okvals = sort(@okvals);
22161: if (ref($domconfig{'trust'}) eq 'HASH') {
22162: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22163: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22164: if ($inuse == 0) {
22165: $changes{$prefix}{$type} = 1;
22166: } else {
22167: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22168: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22169: if (@changed > 0) {
22170: $changes{$prefix}{$type} = 1;
22171: }
22172: }
22173: } else {
22174: if ($inuse == 1) {
22175: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22176: $changes{$prefix}{$type} = 1;
22177: }
22178: }
22179: } else {
22180: if ($inuse == 1) {
22181: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22182: $changes{$prefix}{$type} = 1;
22183: }
22184: }
22185: } else {
22186: if ($inuse == 1) {
22187: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22188: $changes{$prefix}{$type} = 1;
22189: }
22190: }
22191: }
22192: }
22193: my $nochgmsg = &mt('No changes made to trust settings.');
22194: if (keys(%changes) > 0) {
22195: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22196: $dom);
22197: if ($putresult eq 'ok') {
22198: if (ref($defaultshash{'trust'}) eq 'HASH') {
22199: foreach my $prefix (@prefixes) {
22200: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22201: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22202: }
22203: }
22204: }
22205: my $cachetime = 24*60*60;
22206: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22207: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22208: if (ref($lastactref) eq 'HASH') {
22209: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22210: $lastactref->{'trust'} = 1;
1.279 raeburn 22211: }
22212: if (keys(%changes) > 0) {
22213: my %lt = &trust_titles();
22214: $resulttext = &mt('Changes made:').'<ul>';
22215: foreach my $prefix (@prefixes) {
22216: if (ref($changes{$prefix}) eq 'HASH') {
22217: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22218: foreach my $type (@types) {
22219: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22220: my ($newvalue,$notinuse);
1.279 raeburn 22221: if (ref($defaultshash{'trust'}) eq 'HASH') {
22222: if (ref($defaultshash{'trust'}{$prefix})) {
22223: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22224: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22225: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22226: }
1.344 raeburn 22227: } else {
22228: $notinuse = 1;
1.279 raeburn 22229: }
22230: }
22231: }
1.344 raeburn 22232: if ($notinuse) {
22233: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22234: } elsif ($newvalue eq '') {
1.279 raeburn 22235: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22236: } else {
22237: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22238: }
22239: }
22240: }
22241: $resulttext .= '</ul>';
22242: }
22243: }
22244: $resulttext .= '</ul>';
22245: } else {
22246: $resulttext = $nochgmsg;
22247: }
22248: } else {
22249: $resulttext = '<span class="LC_error">'.
22250: &mt('An error occurred: [_1]',$putresult).'</span>';
22251: }
22252: } else {
22253: $resulttext = $nochgmsg;
22254: }
22255: return $resulttext;
22256: }
22257:
1.150 raeburn 22258: sub modify_loadbalancing {
22259: my ($dom,%domconfig) = @_;
22260: my $primary_id = &Apache::lonnet::domain($dom,'primary');
22261: my $intdom = &Apache::lonnet::internet_dom($primary_id);
22262: my ($othertitle,$usertypes,$types) =
22263: &Apache::loncommon::sorted_inst_types($dom);
22264: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 22265: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 22266: my @sparestypes = ('primary','default');
22267: my %typetitles = &sparestype_titles();
22268: my $resulttext;
1.342 raeburn 22269: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22270: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22271: %existing = %{$domconfig{'loadbalancing'}};
22272: }
22273: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 22274: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 22275: my ($saveloadbalancing,%defaultshash,%changes);
22276: my ($alltypes,$othertypes,$titles) =
22277: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
22278: my %ruletitles = &offloadtype_text();
22279: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
22280: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
22281: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
22282: if ($balancer eq '') {
22283: next;
22284: }
1.210 raeburn 22285: if (!exists($servers{$balancer})) {
1.171 raeburn 22286: if (exists($currbalancer{$balancer})) {
22287: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 22288: }
1.171 raeburn 22289: next;
22290: }
22291: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
22292: push(@{$changes{'delete'}},$balancer);
22293: next;
22294: }
22295: if (!exists($currbalancer{$balancer})) {
22296: push(@{$changes{'add'}},$balancer);
22297: }
22298: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
22299: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
22300: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
22301: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
22302: $saveloadbalancing = 1;
22303: }
22304: foreach my $sparetype (@sparestypes) {
22305: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
22306: my @offloadto;
22307: foreach my $target (@targets) {
22308: if (($servers{$target}) && ($target ne $balancer)) {
22309: if ($sparetype eq 'default') {
22310: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
22311: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 22312: }
22313: }
1.171 raeburn 22314: unless(grep(/^\Q$target\E$/,@offloadto)) {
22315: push(@offloadto,$target);
22316: }
1.150 raeburn 22317: }
22318: }
1.284 raeburn 22319: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
22320: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
22321: push(@offloadto,$balancer);
22322: }
22323: }
22324: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 22325: }
1.342 raeburn 22326: if ($env{'form.loadbalancing_cookie_'.$i}) {
22327: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
22328: if (exists($currbalancer{$balancer})) {
22329: unless ($currcookies{$balancer}) {
22330: $changes{'curr'}{$balancer}{'cookie'} = 1;
22331: }
22332: }
22333: } elsif (exists($currbalancer{$balancer})) {
22334: if ($currcookies{$balancer}) {
22335: $changes{'curr'}{$balancer}{'cookie'} = 1;
22336: }
22337: }
1.171 raeburn 22338: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 22339: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22340: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
22341: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 22342: if (@targetdiffs > 0) {
1.171 raeburn 22343: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22344: }
1.171 raeburn 22345: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22346: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22347: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 22348: }
22349: }
22350: }
22351: } else {
1.171 raeburn 22352: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 22353: foreach my $sparetype (@sparestypes) {
1.171 raeburn 22354: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22355: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22356: $changes{'curr'}{$balancer}{'targets'} = 1;
22357: }
1.150 raeburn 22358: }
22359: }
1.210 raeburn 22360: }
1.150 raeburn 22361: }
22362: my $ishomedom;
1.171 raeburn 22363: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
22364: $ishomedom = 1;
1.150 raeburn 22365: }
22366: if (ref($alltypes) eq 'ARRAY') {
22367: foreach my $type (@{$alltypes}) {
22368: my $rule;
1.210 raeburn 22369: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 22370: (!$ishomedom)) {
1.171 raeburn 22371: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
22372: }
22373: if ($rule eq 'specific') {
1.255 raeburn 22374: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 22375: if (exists($servers{$specifiedhost})) {
1.255 raeburn 22376: $rule = $specifiedhost;
22377: }
1.150 raeburn 22378: }
1.171 raeburn 22379: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
22380: if (ref($currrules{$balancer}) eq 'HASH') {
22381: if ($rule ne $currrules{$balancer}{$type}) {
22382: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22383: }
22384: } elsif ($rule ne '') {
1.171 raeburn 22385: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 22386: }
22387: }
22388: }
1.171 raeburn 22389: }
22390: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
22391: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
22392: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
22393: $defaultshash{'loadbalancing'} = {};
22394: }
22395: my $putresult = &Apache::lonnet::put_dom('configuration',
22396: \%defaultshash,$dom);
22397: if ($putresult eq 'ok') {
22398: if (keys(%changes) > 0) {
1.252 raeburn 22399: my %toupdate;
1.171 raeburn 22400: if (ref($changes{'delete'}) eq 'ARRAY') {
22401: foreach my $balancer (sort(@{$changes{'delete'}})) {
22402: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 22403: $toupdate{$balancer} = 1;
1.150 raeburn 22404: }
1.171 raeburn 22405: }
22406: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 22407: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 22408: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 22409: $toupdate{$balancer} = 1;
1.171 raeburn 22410: }
22411: }
22412: if (ref($changes{'curr'}) eq 'HASH') {
22413: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 22414: $toupdate{$balancer} = 1;
1.171 raeburn 22415: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
22416: if ($changes{'curr'}{$balancer}{'targets'}) {
22417: my %offloadstr;
22418: foreach my $sparetype (@sparestypes) {
22419: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22420: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
22421: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22422: }
22423: }
1.150 raeburn 22424: }
1.171 raeburn 22425: if (keys(%offloadstr) == 0) {
22426: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 22427: } else {
1.171 raeburn 22428: my $showoffload;
22429: foreach my $sparetype (@sparestypes) {
22430: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
22431: if (defined($offloadstr{$sparetype})) {
22432: $showoffload .= $offloadstr{$sparetype};
22433: } else {
22434: $showoffload .= &mt('None');
22435: }
22436: $showoffload .= (' 'x3);
22437: }
22438: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 22439: }
22440: }
22441: }
1.171 raeburn 22442: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
22443: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
22444: foreach my $type (@{$alltypes}) {
22445: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
22446: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22447: my $balancetext;
22448: if ($rule eq '') {
22449: $balancetext = $ruletitles{'default'};
1.209 raeburn 22450: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 22451: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 22452: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 22453: foreach my $sparetype (@sparestypes) {
22454: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
22455: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
22456: }
22457: }
1.253 raeburn 22458: foreach my $item (@{$alltypes}) {
22459: next if ($item =~ /^_LC_ipchange/);
22460: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
22461: if ($hasrule eq 'homeserver') {
22462: map { $toupdate{$_} = 1; } (keys(%libraryservers));
22463: } else {
22464: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
22465: if ($servers{$hasrule}) {
22466: $toupdate{$hasrule} = 1;
22467: }
22468: }
22469: }
22470: }
1.254 raeburn 22471: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
22472: $balancetext = $ruletitles{$rule};
22473: } else {
22474: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
22475: $balancetext = $ruletitles{'particular'}.' '.$receiver;
22476: if ($receiver) {
22477: $toupdate{$receiver};
22478: }
22479: }
22480: } else {
22481: $balancetext = $ruletitles{$rule};
1.252 raeburn 22482: }
1.171 raeburn 22483: } else {
22484: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
22485: }
1.210 raeburn 22486: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 22487: }
22488: }
22489: }
22490: }
1.342 raeburn 22491: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 22492: if ($currcookies{$balancer}) {
22493: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
22494: $balancer).'</li>';
22495: } else {
22496: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
22497: $balancer).'</li>';
22498: }
1.342 raeburn 22499: }
1.375 raeburn 22500: }
22501: }
22502: if (keys(%toupdate)) {
22503: my %thismachine;
22504: my $updatedhere;
22505: my $cachetime = 60*60*24;
22506: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
22507: foreach my $lonhost (keys(%toupdate)) {
22508: if ($thismachine{$lonhost}) {
22509: unless ($updatedhere) {
22510: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
22511: $defaultshash{'loadbalancing'},
22512: $cachetime);
22513: $updatedhere = 1;
1.252 raeburn 22514: }
1.375 raeburn 22515: } else {
22516: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
22517: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 22518: }
1.150 raeburn 22519: }
1.171 raeburn 22520: }
22521: if ($resulttext ne '') {
22522: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 22523: } else {
22524: $resulttext = $nochgmsg;
22525: }
22526: } else {
1.171 raeburn 22527: $resulttext = $nochgmsg;
1.150 raeburn 22528: }
22529: } else {
1.171 raeburn 22530: $resulttext = '<span class="LC_error">'.
22531: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 22532: }
22533: } else {
1.171 raeburn 22534: $resulttext = $nochgmsg;
1.150 raeburn 22535: }
22536: return $resulttext;
22537: }
22538:
1.48 raeburn 22539: sub recurse_check {
22540: my ($chkcats,$categories,$depth,$name) = @_;
22541: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
22542: my $chg = 0;
22543: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
22544: my $category = $chkcats->[$depth]{$name}[$j];
22545: my $item;
22546: if ($category eq '') {
22547: $chg ++;
22548: } else {
22549: my $deeper = $depth + 1;
22550: $item = &escape($category).':'.&escape($name).':'.$depth;
22551: if ($chg) {
22552: $categories->{$item} -= $chg;
22553: }
22554: &recurse_check($chkcats,$categories,$deeper,$category);
22555: $deeper --;
22556: }
22557: }
22558: }
22559: return;
22560: }
22561:
22562: sub recurse_cat_deletes {
22563: my ($item,$coursecategories,$deletions) = @_;
22564: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
22565: my $subdepth = $depth + 1;
22566: if (ref($coursecategories) eq 'HASH') {
22567: foreach my $subitem (keys(%{$coursecategories})) {
22568: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
22569: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
22570: delete($coursecategories->{$subitem});
22571: $deletions->{$subitem} = 1;
22572: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 22573: }
1.48 raeburn 22574: }
22575: }
22576: return;
22577: }
22578:
1.125 raeburn 22579: sub active_dc_picker {
1.191 raeburn 22580: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 22581: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 22582: my @domcoord = keys(%domcoords);
22583: if (keys(%currhash)) {
22584: foreach my $dc (keys(%currhash)) {
22585: unless (exists($domcoords{$dc})) {
22586: push(@domcoord,$dc);
22587: }
22588: }
22589: }
22590: @domcoord = sort(@domcoord);
1.210 raeburn 22591: my $numdcs = scalar(@domcoord);
1.191 raeburn 22592: my $rows = 0;
22593: my $table;
1.125 raeburn 22594: if ($numdcs > 1) {
1.191 raeburn 22595: $table = '<table>';
22596: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 22597: my $rem = $i%($numinrow);
22598: if ($rem == 0) {
22599: if ($i > 0) {
1.191 raeburn 22600: $table .= '</tr>';
1.125 raeburn 22601: }
1.191 raeburn 22602: $table .= '<tr>';
22603: $rows ++;
1.125 raeburn 22604: }
1.191 raeburn 22605: my $check = '';
22606: if ($inputtype eq 'radio') {
22607: if (keys(%currhash) == 0) {
22608: if (!$i) {
22609: $check = ' checked="checked"';
22610: }
22611: } elsif (exists($currhash{$domcoord[$i]})) {
22612: $check = ' checked="checked"';
22613: }
22614: } else {
22615: if (exists($currhash{$domcoord[$i]})) {
22616: $check = ' checked="checked"';
1.125 raeburn 22617: }
22618: }
1.191 raeburn 22619: if ($i == @domcoord - 1) {
1.125 raeburn 22620: my $colsleft = $numinrow - $rem;
22621: if ($colsleft > 1) {
1.191 raeburn 22622: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 22623: } else {
1.191 raeburn 22624: $table .= '<td class="LC_left_item">';
1.125 raeburn 22625: }
22626: } else {
1.191 raeburn 22627: $table .= '<td class="LC_left_item">';
22628: }
22629: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
22630: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
22631: $table .= '<span class="LC_nobreak"><label>'.
22632: '<input type="'.$inputtype.'" name="'.$name.'"'.
22633: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
22634: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 22635: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 22636: }
1.219 raeburn 22637: $table .= '</label></span></td>';
1.191 raeburn 22638: }
22639: $table .= '</tr></table>';
22640: } elsif ($numdcs == 1) {
1.219 raeburn 22641: my ($dcname,$dcdom) = split(':',$domcoord[0]);
22642: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 22643: if ($inputtype eq 'radio') {
1.247 raeburn 22644: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 22645: if ($user ne $dcname.':'.$dcdom) {
22646: $table .= ' ('.$dcname.':'.$dcdom.')';
22647: }
1.191 raeburn 22648: } else {
22649: my $check;
22650: if (exists($currhash{$domcoord[0]})) {
22651: $check = ' checked="checked"';
1.125 raeburn 22652: }
1.247 raeburn 22653: $table = '<span class="LC_nobreak"><label>'.
22654: '<input type="checkbox" name="'.$name.'" '.
22655: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 22656: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 22657: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 22658: }
1.220 raeburn 22659: $table .= '</label></span>';
1.191 raeburn 22660: $rows ++;
1.125 raeburn 22661: }
22662: }
1.191 raeburn 22663: return ($numdcs,$table,$rows);
1.125 raeburn 22664: }
22665:
1.137 raeburn 22666: sub usersession_titles {
22667: return &Apache::lonlocal::texthash(
22668: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
22669: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 22670: spares => 'Servers offloaded to, when busy',
1.137 raeburn 22671: version => 'LON-CAPA version requirement',
1.138 raeburn 22672: excludedomain => 'Allow all, but exclude specific domains',
22673: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 22674: primary => 'Primary (checked first)',
1.154 raeburn 22675: default => 'Default',
1.137 raeburn 22676: );
22677: }
22678:
1.152 raeburn 22679: sub id_for_thisdom {
22680: my (%servers) = @_;
22681: my %altids;
22682: foreach my $server (keys(%servers)) {
22683: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22684: if ($serverhome ne $server) {
22685: $altids{$serverhome} = $server;
22686: }
22687: }
22688: return %altids;
22689: }
22690:
1.150 raeburn 22691: sub count_servers {
22692: my ($currbalancer,%servers) = @_;
22693: my (@spares,$numspares);
22694: foreach my $lonhost (sort(keys(%servers))) {
22695: next if ($currbalancer eq $lonhost);
22696: push(@spares,$lonhost);
22697: }
22698: if ($currbalancer) {
22699: $numspares = scalar(@spares);
22700: } else {
22701: $numspares = scalar(@spares) - 1;
22702: }
22703: return ($numspares,@spares);
22704: }
22705:
22706: sub lonbalance_targets_js {
1.171 raeburn 22707: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 22708: my $select = &mt('Select');
22709: my ($alltargets,$allishome,$allinsttypes,@alltypes);
22710: if (ref($servers) eq 'HASH') {
22711: $alltargets = join("','",sort(keys(%{$servers})));
22712: my @homedoms;
22713: foreach my $server (sort(keys(%{$servers}))) {
22714: if (&Apache::lonnet::host_domain($server) eq $dom) {
22715: push(@homedoms,'1');
22716: } else {
22717: push(@homedoms,'0');
22718: }
22719: }
22720: $allishome = join("','",@homedoms);
22721: }
22722: if (ref($types) eq 'ARRAY') {
22723: if (@{$types} > 0) {
22724: @alltypes = @{$types};
22725: }
22726: }
22727: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
22728: $allinsttypes = join("','",@alltypes);
1.342 raeburn 22729: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 22730: if (ref($settings) eq 'HASH') {
22731: %existing = %{$settings};
22732: }
22733: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 22734: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 22735: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 22736: return <<"END";
22737:
22738: <script type="text/javascript">
22739: // <![CDATA[
22740:
1.171 raeburn 22741: currBalancers = new Array('$balancers');
22742:
22743: function toggleTargets(balnum) {
22744: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22745: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
22746: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
22747: var prevbalancer = prevhostitem.value;
22748: var baltotal = document.getElementById('loadbalancing_total').value;
22749: prevhostitem.value = balancer;
22750: if (prevbalancer != '') {
22751: var prevIdx = currBalancers.indexOf(prevbalancer);
22752: if (prevIdx != -1) {
22753: currBalancers.splice(prevIdx,1);
22754: }
22755: }
1.150 raeburn 22756: if (balancer == '') {
1.171 raeburn 22757: hideSpares(balnum);
1.150 raeburn 22758: } else {
1.171 raeburn 22759: var currIdx = currBalancers.indexOf(balancer);
22760: if (currIdx == -1) {
22761: currBalancers.push(balancer);
22762: }
1.150 raeburn 22763: var homedoms = new Array('$allishome');
1.171 raeburn 22764: var ishomedom = homedoms[lonhostitem.selectedIndex];
22765: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 22766: }
1.171 raeburn 22767: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 22768: return;
22769: }
22770:
1.171 raeburn 22771: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 22772: var alltargets = new Array('$alltargets');
22773: var insttypes = new Array('$allinsttypes');
1.151 raeburn 22774: var offloadtypes = new Array('primary','default');
22775:
1.171 raeburn 22776: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
22777: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 22778:
1.151 raeburn 22779: for (var i=0; i<offloadtypes.length; i++) {
22780: var count = 0;
22781: for (var j=0; j<alltargets.length; j++) {
22782: if (alltargets[j] != balancer) {
1.171 raeburn 22783: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
22784: item.value = alltargets[j];
22785: item.style.textAlign='left';
22786: item.style.textFace='normal';
22787: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
22788: if (currBalancers.indexOf(alltargets[j]) == -1) {
22789: item.disabled = '';
22790: } else {
22791: item.disabled = 'disabled';
22792: item.checked = false;
22793: }
1.151 raeburn 22794: count ++;
22795: }
1.150 raeburn 22796: }
22797: }
1.151 raeburn 22798: for (var k=0; k<insttypes.length; k++) {
22799: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 22800: if (ishomedom == 1) {
1.171 raeburn 22801: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22802: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22803: } else {
1.171 raeburn 22804: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22805: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 22806: }
22807: } else {
1.171 raeburn 22808: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
22809: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 22810: }
1.151 raeburn 22811: if ((insttypes[k] != '_LC_external') &&
22812: ((insttypes[k] != '_LC_internetdom') ||
22813: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 22814: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
22815: item.options.length = 0;
22816: item.options[0] = new Option("","",true,true);
1.210 raeburn 22817: var idx = 0;
1.151 raeburn 22818: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 22819: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
22820: idx ++;
22821: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 22822: }
22823: }
22824: }
22825: }
22826: return;
22827: }
22828:
1.171 raeburn 22829: function hideSpares(balnum) {
1.150 raeburn 22830: var alltargets = new Array('$alltargets');
22831: var insttypes = new Array('$allinsttypes');
22832: var offloadtypes = new Array('primary','default');
22833:
1.171 raeburn 22834: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
22835: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 22836:
22837: var total = alltargets.length - 1;
22838: for (var i=0; i<offloadtypes; i++) {
22839: for (var j=0; j<total; j++) {
1.171 raeburn 22840: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
22841: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
22842: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 22843: }
1.150 raeburn 22844: }
22845: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 22846: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
22847: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 22848: if (insttypes[k] != '_LC_external') {
1.171 raeburn 22849: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
22850: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 22851: }
22852: }
22853: return;
22854: }
22855:
1.171 raeburn 22856: function checkOffloads(item,balnum,type) {
1.150 raeburn 22857: var alltargets = new Array('$alltargets');
22858: var offloadtypes = new Array('primary','default');
22859: if (item.checked) {
22860: var total = alltargets.length - 1;
22861: var other;
22862: if (type == offloadtypes[0]) {
1.151 raeburn 22863: other = offloadtypes[1];
1.150 raeburn 22864: } else {
1.151 raeburn 22865: other = offloadtypes[0];
1.150 raeburn 22866: }
22867: for (var i=0; i<total; i++) {
1.171 raeburn 22868: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 22869: if (server == item.value) {
1.171 raeburn 22870: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
22871: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 22872: }
22873: }
22874: }
22875: }
22876: return;
22877: }
22878:
1.171 raeburn 22879: function singleServerToggle(balnum,type) {
22880: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 22881: if (offloadtoSelIdx == 0) {
1.171 raeburn 22882: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
22883: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22884:
22885: } else {
1.171 raeburn 22886: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
22887: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 22888: }
22889: return;
22890: }
22891:
1.171 raeburn 22892: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 22893: if (type == '_LC_external') {
1.171 raeburn 22894: return;
1.150 raeburn 22895: }
1.171 raeburn 22896: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 22897: for (var i=0; i<typesRules.length; i++) {
22898: if (formname.elements[typesRules[i]].checked) {
22899: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 22900: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
22901: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 22902: } else {
1.171 raeburn 22903: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
22904: }
22905: }
22906: }
22907: return;
22908: }
22909:
22910: function balancerDeleteChange(balnum) {
22911: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
22912: var baltotal = document.getElementById('loadbalancing_total').value;
22913: var addtarget;
22914: var removetarget;
22915: var action = 'delete';
22916: if (document.getElementById('loadbalancing_delete_'+balnum)) {
22917: var lonhost = hostitem.value;
22918: var currIdx = currBalancers.indexOf(lonhost);
22919: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
22920: if (currIdx != -1) {
22921: currBalancers.splice(currIdx,1);
22922: }
22923: addtarget = lonhost;
22924: } else {
22925: if (currIdx == -1) {
22926: currBalancers.push(lonhost);
22927: }
22928: removetarget = lonhost;
22929: action = 'undelete';
22930: }
22931: balancerChange(balnum,baltotal,action,addtarget,removetarget);
22932: }
22933: return;
22934: }
22935:
22936: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
22937: if (baltotal > 1) {
22938: var offloadtypes = new Array('primary','default');
22939: var alltargets = new Array('$alltargets');
22940: var insttypes = new Array('$allinsttypes');
22941: for (var i=0; i<baltotal; i++) {
22942: if (i != balnum) {
22943: for (var j=0; j<offloadtypes.length; j++) {
22944: var total = alltargets.length - 1;
22945: for (var k=0; k<total; k++) {
22946: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
22947: var server = serveritem.value;
22948: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22949: if (server == addtarget) {
22950: serveritem.disabled = '';
22951: }
22952: }
22953: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22954: if (server == removetarget) {
22955: serveritem.disabled = 'disabled';
22956: serveritem.checked = false;
22957: }
22958: }
22959: }
22960: }
22961: for (var j=0; j<insttypes.length; j++) {
22962: if (insttypes[j] != '_LC_external') {
22963: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
22964: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
22965: var currSel = singleserver.selectedIndex;
22966: var currVal = singleserver.options[currSel].value;
22967: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
22968: var numoptions = singleserver.options.length;
22969: var needsnew = 1;
22970: for (var k=0; k<numoptions; k++) {
22971: if (singleserver.options[k] == addtarget) {
22972: needsnew = 0;
22973: break;
22974: }
22975: }
22976: if (needsnew == 1) {
22977: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
22978: }
22979: }
22980: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
22981: singleserver.options.length = 0;
22982: if ((currVal) && (currVal != removetarget)) {
22983: singleserver.options[0] = new Option("","",false,false);
22984: } else {
22985: singleserver.options[0] = new Option("","",true,true);
22986: }
22987: var idx = 0;
22988: for (var m=0; m<alltargets.length; m++) {
22989: if (currBalancers.indexOf(alltargets[m]) == -1) {
22990: idx ++;
22991: if (currVal == alltargets[m]) {
22992: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
22993: } else {
22994: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
22995: }
22996: }
22997: }
22998: }
22999: }
23000: }
23001: }
1.150 raeburn 23002: }
23003: }
23004: }
23005: return;
23006: }
23007:
1.152 raeburn 23008: // ]]>
23009: </script>
23010:
23011: END
23012: }
23013:
1.372 raeburn 23014:
1.152 raeburn 23015: sub new_spares_js {
23016: my @sparestypes = ('primary','default');
23017: my $types = join("','",@sparestypes);
23018: my $select = &mt('Select');
23019: return <<"END";
23020:
23021: <script type="text/javascript">
23022: // <![CDATA[
23023:
23024: function updateNewSpares(formname,lonhost) {
23025: var types = new Array('$types');
23026: var include = new Array();
23027: var exclude = new Array();
23028: for (var i=0; i<types.length; i++) {
23029: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23030: for (var j=0; j<spareboxes.length; j++) {
23031: if (formname.elements[spareboxes[j]].checked) {
23032: exclude.push(formname.elements[spareboxes[j]].value);
23033: } else {
23034: include.push(formname.elements[spareboxes[j]].value);
23035: }
23036: }
23037: }
23038: for (var i=0; i<types.length; i++) {
23039: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23040: var selIdx = newSpare.selectedIndex;
23041: var currnew = newSpare.options[selIdx].value;
23042: var okSpares = new Array();
23043: for (var j=0; j<newSpare.options.length; j++) {
23044: var possible = newSpare.options[j].value;
23045: if (possible != '') {
23046: if (exclude.indexOf(possible) == -1) {
23047: okSpares.push(possible);
23048: } else {
23049: if (currnew == possible) {
23050: selIdx = 0;
23051: }
23052: }
23053: }
23054: }
23055: for (var k=0; k<include.length; k++) {
23056: if (okSpares.indexOf(include[k]) == -1) {
23057: okSpares.push(include[k]);
23058: }
23059: }
23060: okSpares.sort();
23061: newSpare.options.length = 0;
23062: if (selIdx == 0) {
23063: newSpare.options[0] = new Option("$select","",true,true);
23064: } else {
23065: newSpare.options[0] = new Option("$select","",false,false);
23066: }
23067: for (var m=0; m<okSpares.length; m++) {
23068: var idx = m+1;
23069: var selThis = 0;
23070: if (selIdx != 0) {
23071: if (okSpares[m] == currnew) {
23072: selThis = 1;
23073: }
23074: }
23075: if (selThis == 1) {
23076: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23077: } else {
23078: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23079: }
23080: }
23081: }
23082: return;
23083: }
23084:
23085: function checkNewSpares(lonhost,type) {
23086: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23087: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23088: if (chosen != '') {
1.152 raeburn 23089: var othertype;
23090: var othernewSpare;
23091: if (type == 'primary') {
23092: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23093: }
23094: if (type == 'default') {
23095: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23096: }
23097: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23098: othernewSpare.selectedIndex = 0;
23099: }
23100: }
23101: return;
23102: }
23103:
23104: // ]]>
23105: </script>
23106:
23107: END
23108:
23109: }
23110:
23111: sub common_domprefs_js {
23112: return <<"END";
23113:
23114: <script type="text/javascript">
23115: // <![CDATA[
23116:
1.150 raeburn 23117: function getIndicesByName(formname,item) {
1.152 raeburn 23118: var group = new Array();
1.150 raeburn 23119: for (var i=0;i<formname.elements.length;i++) {
23120: if (formname.elements[i].name == item) {
1.152 raeburn 23121: group.push(formname.elements[i].id);
1.150 raeburn 23122: }
23123: }
1.152 raeburn 23124: return group;
1.150 raeburn 23125: }
23126:
23127: // ]]>
23128: </script>
23129:
23130: END
1.152 raeburn 23131:
1.150 raeburn 23132: }
23133:
1.165 raeburn 23134: sub recaptcha_js {
23135: my %lt = &captcha_phrases();
23136: return <<"END";
23137:
23138: <script type="text/javascript">
23139: // <![CDATA[
23140:
23141: function updateCaptcha(caller,context) {
23142: var privitem;
23143: var pubitem;
23144: var privtext;
23145: var pubtext;
1.269 raeburn 23146: var versionitem;
23147: var versiontext;
1.165 raeburn 23148: if (document.getElementById(context+'_recaptchapub')) {
23149: pubitem = document.getElementById(context+'_recaptchapub');
23150: } else {
23151: return;
23152: }
23153: if (document.getElementById(context+'_recaptchapriv')) {
23154: privitem = document.getElementById(context+'_recaptchapriv');
23155: } else {
23156: return;
23157: }
23158: if (document.getElementById(context+'_recaptchapubtxt')) {
23159: pubtext = document.getElementById(context+'_recaptchapubtxt');
23160: } else {
23161: return;
23162: }
23163: if (document.getElementById(context+'_recaptchaprivtxt')) {
23164: privtext = document.getElementById(context+'_recaptchaprivtxt');
23165: } else {
23166: return;
23167: }
1.269 raeburn 23168: if (document.getElementById(context+'_recaptchaversion')) {
23169: versionitem = document.getElementById(context+'_recaptchaversion');
23170: } else {
23171: return;
23172: }
23173: if (document.getElementById(context+'_recaptchavertxt')) {
23174: versiontext = document.getElementById(context+'_recaptchavertxt');
23175: } else {
23176: return;
23177: }
1.165 raeburn 23178: if (caller.checked) {
23179: if (caller.value == 'recaptcha') {
23180: pubitem.type = 'text';
23181: privitem.type = 'text';
23182: pubitem.size = '40';
23183: privitem.size = '40';
23184: pubtext.innerHTML = "$lt{'pub'}";
23185: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23186: versionitem.type = 'text';
23187: versionitem.size = '3';
1.289 raeburn 23188: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23189: } else {
23190: pubitem.type = 'hidden';
23191: privitem.type = 'hidden';
1.269 raeburn 23192: versionitem.type = 'hidden';
1.165 raeburn 23193: pubtext.innerHTML = '';
23194: privtext.innerHTML = '';
1.269 raeburn 23195: versiontext.innerHTML = '';
1.165 raeburn 23196: }
23197: }
23198: return;
23199: }
23200:
23201: // ]]>
23202: </script>
23203:
23204: END
23205:
23206: }
23207:
1.236 raeburn 23208: sub toggle_display_js {
1.192 raeburn 23209: return <<"END";
23210:
23211: <script type="text/javascript">
23212: // <![CDATA[
23213:
1.236 raeburn 23214: function toggleDisplay(domForm,caller) {
23215: if (document.getElementById(caller)) {
23216: var divitem = document.getElementById(caller);
23217: var optionsElement = domForm.coursecredits;
1.264 raeburn 23218: var checkval = 1;
23219: var dispval = 'block';
1.303 raeburn 23220: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23221: if (caller == 'emailoptions') {
1.372 raeburn 23222: optionsElement = domForm.cancreate_email;
1.236 raeburn 23223: }
1.257 raeburn 23224: if (caller == 'studentsubmission') {
23225: optionsElement = domForm.postsubmit;
23226: }
1.264 raeburn 23227: if (caller == 'cloneinstcode') {
23228: optionsElement = domForm.canclone;
23229: checkval = 'instcode';
23230: }
1.303 raeburn 23231: if (selfcreateRegExp.test(caller)) {
23232: optionsElement = domForm.elements[caller];
23233: checkval = 'other';
23234: dispval = 'inline'
23235: }
1.236 raeburn 23236: if (optionsElement.length) {
1.192 raeburn 23237: var currval;
1.236 raeburn 23238: for (var i=0; i<optionsElement.length; i++) {
23239: if (optionsElement[i].checked) {
23240: currval = optionsElement[i].value;
1.192 raeburn 23241: }
23242: }
1.264 raeburn 23243: if (currval == checkval) {
23244: divitem.style.display = dispval;
1.192 raeburn 23245: } else {
1.236 raeburn 23246: divitem.style.display = 'none';
1.192 raeburn 23247: }
23248: }
23249: }
23250: return;
23251: }
23252:
23253: // ]]>
23254: </script>
23255:
23256: END
23257:
23258: }
23259:
1.165 raeburn 23260: sub captcha_phrases {
23261: return &Apache::lonlocal::texthash (
23262: priv => 'Private key',
23263: pub => 'Public key',
23264: original => 'original (CAPTCHA)',
23265: recaptcha => 'successor (ReCAPTCHA)',
23266: notused => 'unused',
1.289 raeburn 23267: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 23268: );
23269: }
23270:
1.205 raeburn 23271: sub devalidate_remote_domconfs {
1.212 raeburn 23272: my ($dom,$cachekeys) = @_;
23273: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 23274: my %servers = &Apache::lonnet::internet_dom_servers($dom);
23275: my %thismachine;
23276: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 23277: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 23278: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 23279: 'ipaccess','trust');
1.386 raeburn 23280: my %cache_by_lonhost;
23281: if (exists($cachekeys->{'samllanding'})) {
23282: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
23283: my %landing = %{$cachekeys->{'samllanding'}};
23284: my %domservers = &Apache::lonnet::get_servers($dom);
23285: if (keys(%domservers)) {
23286: foreach my $server (keys(%domservers)) {
23287: my @cached;
23288: next if ($thismachine{$server});
23289: if ($landing{$server}) {
23290: push(@cached,&escape('samllanding').':'.&escape($server));
23291: }
23292: if (@cached) {
23293: $cache_by_lonhost{$server} = \@cached;
23294: }
23295: }
23296: }
23297: }
23298: }
1.260 raeburn 23299: if (keys(%servers)) {
1.205 raeburn 23300: foreach my $server (keys(%servers)) {
23301: next if ($thismachine{$server});
1.212 raeburn 23302: my @cached;
23303: foreach my $name (@posscached) {
23304: if ($cachekeys->{$name}) {
1.388 raeburn 23305: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 23306: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 23307: foreach my $key (keys(%{$cachekeys->{$name}})) {
23308: push(@cached,&escape($name).':'.&escape($key));
23309: }
23310: }
23311: } else {
23312: push(@cached,&escape($name).':'.&escape($dom));
23313: }
1.212 raeburn 23314: }
23315: }
1.386 raeburn 23316: if ((exists($cache_by_lonhost{$server})) &&
23317: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
23318: push(@cached,@{$cache_by_lonhost{$server}});
23319: }
1.212 raeburn 23320: if (@cached) {
23321: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
23322: }
1.205 raeburn 23323: }
23324: }
23325: return;
23326: }
23327:
1.3 raeburn 23328: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>