Annotation of loncom/interface/domainprefs.pm, revision 1.435
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.435 ! raeburn 4: # $Id: domainprefs.pm,v 1.434 2024/02/24 23:41:44 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.429 raeburn 98: used by course owners to request creation of a course.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.325 raeburn 106: (official, unofficial, community, textbook, placement, and lti).
1.425 raeburn 107: In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.232 raeburn 167: use Apache::lonuserutils();
1.235 raeburn 168: use Apache::loncoursequeueadmin();
1.419 raeburn 169: use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.275 raeburn 173: use LONCAPA::SSL;
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.267 raeburn 178: use Time::HiRes qw( sleep );
1.373 raeburn 179: use Net::CIDR;
1.424 raeburn 180: use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
221: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 222: 'coursedefaults','usersessions','loadbalancing',
1.267 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.421 raeburn 224: 'ltitools','toolsec','ssl','trust','lti','ltisec',
1.429 raeburn 225: 'privacy','passwords','proctoring','wafproxy',
226: 'ipaccess','authordefaults'],$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.425 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.429 raeburn 308: 'authordefaults','ltitools','proctoring','selfenrollment',
309: 'usersessions','ssl','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.429 raeburn 385: { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 386: help => 'Domain_Configuration_Quotas',
1.77 raeburn 387: header => [{col1 => 'User affiliation',
1.72 raeburn 388: col2 => 'Available tools',
1.435 ! raeburn 389: col3 => 'Portfolio quota (MB)',}],
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.427 raeburn 571: {text => 'Role assignments and user privacy',
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.425 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.425 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'},
1.425 raeburn 670: {col1 => 'Rules for shared secrets',
1.405 raeburn 671: col2 => 'Settings'},
1.434 raeburn 672: {col1 => 'Link Protectors in Courses',
673: col2 => 'Values'},
1.406 raeburn 674: {col1 => 'Link Protectors',
1.405 raeburn 675: col2 => 'Settings'},
676: {col1 => 'Consumers',
677: col2 => 'Settings'},],
1.320 raeburn 678: print => \&print_lti,
679: modify => \&modify_lti,
680: },
1.425 raeburn 681: 'ipaccess' =>
1.394 raeburn 682: {text => 'IP-based access control',
683: help => 'Domain_Configuration_IP_Access',
684: header => [{col1 => 'Setting',
685: col2 => 'Value'},],
686: print => \&print_ipaccess,
687: modify => \&modify_ipaccess,
688: },
1.429 raeburn 689: 'authordefaults' =>
690: {text => 'Authoring Space defaults',
691: help => 'Domain_Configuration_Author_Defaults',
692: header => [{col1 => 'Defaults which can be overridden by Author',
693: col2 => 'Settings',},
694: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
695: col2 => 'Settings',},],
696: print => \&print_authordefaults,
697: modify => \&modify_authordefaults,
698: },
1.3 raeburn 699: );
1.110 raeburn 700: if (keys(%servers) > 1) {
701: $prefs{'login'} = { text => 'Log-in page options',
702: help => 'Domain_Configuration_Login_Page',
703: header => [{col1 => 'Log-in Service',
704: col2 => 'Server Setting',},
705: {col1 => 'Log-in Page Items',
1.405 raeburn 706: col2 => 'Settings'},
1.168 raeburn 707: {col1 => 'Log-in Help',
1.256 raeburn 708: col2 => 'Value'},
709: {col1 => 'Custom HTML in document head',
1.386 raeburn 710: col2 => 'Value'},
711: {col1 => 'SSO',
712: col2 => 'Dual login: SSO and non-SSO options'},
713: ],
1.230 raeburn 714: print => \&print_login,
715: modify => \&modify_login,
1.110 raeburn 716: };
717: }
1.174 foxr 718:
1.6 raeburn 719: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 720: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 721: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 722: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 723: text=>"Settings to display/modify"});
1.9 raeburn 724: my $confname = $dom.'-domainconfig';
1.174 foxr 725:
1.3 raeburn 726: if ($phase eq 'process') {
1.212 raeburn 727: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
728: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 729: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 730: $r->rflush();
1.212 raeburn 731: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 732: }
1.30 raeburn 733: } elsif ($phase eq 'display') {
1.192 raeburn 734: my $js = &recaptcha_js().
1.236 raeburn 735: &toggle_display_js();
1.171 raeburn 736: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 737: my ($othertitle,$usertypes,$types) =
738: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 739: $js .= &lonbalance_targets_js($dom,$types,\%servers,
740: $domconfig{'loadbalancing'}).
1.170 raeburn 741: &new_spares_js().
742: &common_domprefs_js().
743: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 744: }
1.216 raeburn 745: if (grep(/^requestcourses$/,@actions)) {
746: my $javascript_validations;
747: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
748: $js .= <<END;
749: <script type="text/javascript">
750: $javascript_validations
751: </script>
752: $coursebrowserjs
753: END
1.394 raeburn 754: } elsif (grep(/^ipaccess$/,@actions)) {
755: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 756: }
1.305 raeburn 757: if (grep(/^selfcreation$/,@actions)) {
758: $js .= &selfcreate_javascript();
759: }
1.286 raeburn 760: if (grep(/^contacts$/,@actions)) {
761: $js .= &contacts_javascript();
762: }
1.346 raeburn 763: if (grep(/^scantron$/,@actions)) {
764: $js .= &scantron_javascript();
765: }
1.150 raeburn 766: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 767: } else {
1.180 raeburn 768: # check if domconfig user exists for the domain.
769: my $servadm = $r->dir_config('lonAdmEMail');
770: my ($configuserok,$author_ok,$switchserver) =
771: &config_check($dom,$confname,$servadm);
772: unless ($configuserok eq 'ok') {
1.181 raeburn 773: &Apache::lonconfigsettings::print_header($r,$phase,$context);
774: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 775: $confname).
1.181 raeburn 776: '<br />'
777: );
1.180 raeburn 778: if ($switchserver) {
1.181 raeburn 779: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
780: '<br />'.
781: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
782: '<br />'.
783: &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).
784: '<br />'.
785: &mt('To do that now, use the following link: [_1]',$switchserver)
786: );
787: } else {
788: $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.').
789: '<br />'.
790: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
791: );
1.180 raeburn 792: }
793: $r->print(&Apache::loncommon::end_page());
794: return OK;
795: }
1.21 raeburn 796: if (keys(%domconfig) == 0) {
797: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 798: my @ids=&Apache::lonnet::current_machine_ids();
799: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 800: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 801: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 802: my $custom_img_count = 0;
803: foreach my $img (@loginimages) {
804: if ($designhash{$dom.'.login.'.$img} ne '') {
805: $custom_img_count ++;
806: }
807: }
808: foreach my $role (@roles) {
809: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
810: $custom_img_count ++;
811: }
812: }
813: if ($custom_img_count > 0) {
1.94 raeburn 814: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 815: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 816: $r->print(
817: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
818: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
819: &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 />'.
820: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
821: if ($switch_server) {
1.30 raeburn 822: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 823: }
1.91 raeburn 824: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 825: return OK;
826: }
827: }
828: }
1.91 raeburn 829: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 830: }
831: return OK;
832: }
833:
834: sub process_changes {
1.205 raeburn 835: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 836: my %domconfig;
837: if (ref($values) eq 'HASH') {
838: %domconfig = %{$values};
839: }
1.3 raeburn 840: my $output;
841: if ($action eq 'login') {
1.205 raeburn 842: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 843: } elsif ($action eq 'rolecolors') {
1.9 raeburn 844: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 845: $lastactref,%domconfig);
1.3 raeburn 846: } elsif ($action eq 'quotas') {
1.216 raeburn 847: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'autoenroll') {
1.205 raeburn 849: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 850: } elsif ($action eq 'autoupdate') {
851: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 852: } elsif ($action eq 'autocreate') {
853: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 854: } elsif ($action eq 'directorysrch') {
1.295 raeburn 855: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 856: } elsif ($action eq 'usercreation') {
1.28 raeburn 857: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 858: } elsif ($action eq 'selfcreation') {
1.305 raeburn 859: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 860: } elsif ($action eq 'usermodification') {
861: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 862: } elsif ($action eq 'contacts') {
1.205 raeburn 863: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 864: } elsif ($action eq 'defaults') {
1.212 raeburn 865: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 866: } elsif ($action eq 'scantron') {
1.205 raeburn 867: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 868: } elsif ($action eq 'coursecategories') {
1.239 raeburn 869: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 870: } elsif ($action eq 'serverstatuses') {
871: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 872: } elsif ($action eq 'requestcourses') {
1.216 raeburn 873: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 874: } elsif ($action eq 'requestauthor') {
1.216 raeburn 875: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 876: } elsif ($action eq 'helpsettings') {
1.285 raeburn 877: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 878: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 879: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 880: } elsif ($action eq 'selfenrollment') {
881: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 882: } elsif ($action eq 'usersessions') {
1.212 raeburn 883: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 884: } elsif ($action eq 'loadbalancing') {
885: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 886: } elsif ($action eq 'ltitools') {
887: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 888: } elsif ($action eq 'proctoring') {
889: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 890: } elsif ($action eq 'ssl') {
891: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 892: } elsif ($action eq 'trust') {
893: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 894: } elsif ($action eq 'lti') {
895: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 896: } elsif ($action eq 'privacy') {
1.427 raeburn 897: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 898: } elsif ($action eq 'passwords') {
899: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 900: } elsif ($action eq 'wafproxy') {
901: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 902: } elsif ($action eq 'ipaccess') {
903: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 904: } elsif ($action eq 'authordefaults') {
905: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 906: }
907: return $output;
908: }
909:
910: sub print_config_box {
1.9 raeburn 911: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 912: my $rowtotal = 0;
1.49 raeburn 913: my $output;
914: if ($action eq 'coursecategories') {
915: $output = &coursecategories_javascript($settings);
1.236 raeburn 916: } elsif ($action eq 'defaults') {
917: $output = &defaults_javascript($settings);
1.354 raeburn 918: } elsif ($action eq 'passwords') {
1.405 raeburn 919: $output = &passwords_javascript($action);
1.282 raeburn 920: } elsif ($action eq 'helpsettings') {
921: my (%privs,%levelscurrent);
922: my %full=();
923: my %levels=(
924: course => {},
925: domain => {},
926: system => {},
927: );
928: my $context = 'domain';
929: my $crstype = 'Course';
930: my $formname = 'display';
931: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
932: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
933: $output =
1.425 raeburn 934: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 935: \@templateroles);
1.334 raeburn 936: } elsif ($action eq 'ltitools') {
1.421 raeburn 937: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 938: } elsif ($action eq 'lti') {
1.421 raeburn 939: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 940: <i_javascript($dom,$settings);
1.372 raeburn 941: } elsif ($action eq 'proctoring') {
942: $output .= &proctoring_javascript($settings);
1.381 raeburn 943: } elsif ($action eq 'wafproxy') {
944: $output .= &wafproxy_javascript($dom);
1.385 raeburn 945: } elsif ($action eq 'autoupdate') {
946: $output .= &autoupdate_javascript();
1.399 raeburn 947: } elsif ($action eq 'autoenroll') {
948: $output .= &autoenroll_javascript();
1.386 raeburn 949: } elsif ($action eq 'login') {
950: $output .= &saml_javascript();
1.394 raeburn 951: } elsif ($action eq 'ipaccess') {
952: $output .= &ipaccess_javascript($settings);
1.429 raeburn 953: } elsif ($action eq 'authordefaults') {
954: $output .= &authordefaults_javascript();
1.91 raeburn 955: }
1.236 raeburn 956: $output .=
1.30 raeburn 957: '<table class="LC_nested_outer">
1.3 raeburn 958: <tr>
1.306 raeburn 959: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 960: &mt($item->{text}).' '.
961: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
962: '</tr>';
1.30 raeburn 963: $rowtotal ++;
1.110 raeburn 964: my $numheaders = 1;
965: if (ref($item->{'header'}) eq 'ARRAY') {
966: $numheaders = scalar(@{$item->{'header'}});
967: }
968: if ($numheaders > 1) {
1.64 raeburn 969: my $colspan = '';
1.145 raeburn 970: my $rightcolspan = '';
1.369 raeburn 971: my $leftnobr = '';
1.238 raeburn 972: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 973: ($action eq 'directorysrch') ||
1.386 raeburn 974: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 975: $colspan = ' colspan="2"';
976: }
1.145 raeburn 977: if ($action eq 'usersessions') {
978: $rightcolspan = ' colspan="3"';
979: }
1.369 raeburn 980: if ($action eq 'passwords') {
981: $leftnobr = ' LC_nobreak';
982: }
1.30 raeburn 983: $output .= '
1.3 raeburn 984: <tr>
985: <td>
986: <table class="LC_nested">
987: <tr class="LC_info_row">
1.369 raeburn 988: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 989: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 990: </tr>';
1.69 raeburn 991: $rowtotal ++;
1.230 raeburn 992: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 993: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 994: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 995: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 996: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 997: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 998: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 999: } elsif ($action eq 'passwords') {
1000: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 1001: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1002: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1003: } elsif ($action eq 'scantron') {
1004: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1005: } elsif ($action eq 'login') {
1.386 raeburn 1006: if ($numheaders == 5) {
1.168 raeburn 1007: $colspan = ' colspan="2"';
1008: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1009: } else {
1010: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1011: }
1.230 raeburn 1012: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1013: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1014: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1015: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1016: }
1.30 raeburn 1017: $output .= '
1.6 raeburn 1018: </table>
1019: </td>
1020: </tr>
1021: <tr>
1022: <td>
1023: <table class="LC_nested">
1024: <tr class="LC_info_row">
1.230 raeburn 1025: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1026: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1027: </tr>';
1028: $rowtotal ++;
1.230 raeburn 1029: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1030: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1031: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1032: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1033: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1034: ($action eq 'ltitools')) {
1.238 raeburn 1035: if ($action eq 'coursecategories') {
1036: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1037: $colspan = ' colspan="2"';
1.279 raeburn 1038: } elsif ($action eq 'trust') {
1039: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1040: } elsif ($action eq 'passwords') {
1041: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1042: } elsif ($action eq 'lti') {
1043: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1044: </table>
1045: </td>
1046: </tr>
1047: <tr>
1048: <td>
1049: <table class="LC_nested">
1050: <tr class="LC_info_row">
1051: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1052: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1053: </tr>'."\n".
1054: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1055: } else {
1056: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1057: }
1.279 raeburn 1058: if ($action eq 'trust') {
1059: $output .= '
1060: </table>
1061: </td>
1062: </tr>';
1063: my @trusthdrs = qw(2 3 4 5 6 7);
1064: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1065: for (my $i=0; $i<@trusthdrs; $i++) {
1066: $output .= '
1067: <tr>
1068: <td>
1069: <table class="LC_nested">
1070: <tr class="LC_info_row">
1071: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1072: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1073: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1074: </table>
1075: </td>
1076: </tr>';
1077: }
1078: $output .= '
1079: <tr>
1080: <td>
1081: <table class="LC_nested">
1082: <tr class="LC_info_row">
1083: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1084: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1085: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1086: } else {
1.434 raeburn 1087: my $hdridx = 2;
1088: if ($action eq 'lti') {
1089: $hdridx = 3;
1090: }
1.279 raeburn 1091: $output .= '
1.63 raeburn 1092: </table>
1093: </td>
1094: </tr>
1095: <tr>
1096: <td>
1097: <table class="LC_nested">
1098: <tr class="LC_info_row">
1.434 raeburn 1099: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1100: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1101: </tr>'."\n";
1.279 raeburn 1102: if ($action eq 'coursecategories') {
1103: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1104: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1105: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1106: if ($action eq 'passwords') {
1107: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1108: } else {
1109: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1110: }
1.434 raeburn 1111: $hdridx ++;
1.354 raeburn 1112: $output .= '
1.340 raeburn 1113: </tr>
1114: </table>
1115: </td>
1116: </tr>
1117: <tr>
1118: <td>
1119: <table class="LC_nested">
1120: <tr class="LC_info_row">
1.434 raeburn 1121: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1122: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1123: if ($action eq 'passwords') {
1124: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1125: } else {
1126: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1127: }
1128: $output .= '
1.340 raeburn 1129: </table>
1130: </td>
1131: </tr>
1132: <tr>';
1.279 raeburn 1133: } else {
1134: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1135: }
1.238 raeburn 1136: }
1.63 raeburn 1137: $rowtotal ++;
1.236 raeburn 1138: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.409 raeburn 1139: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.429 raeburn 1140: ($action eq 'wafproxy') || ($action eq 'authordefaults')) {
1.230 raeburn 1141: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1142: } elsif ($action eq 'scantron') {
1143: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1144: } elsif ($action eq 'ssl') {
1145: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1146: </table>
1147: </td>
1148: </tr>
1149: <tr>
1150: <td>
1151: <table class="LC_nested">
1152: <tr class="LC_info_row">
1153: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1154: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1155: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1156: </table>
1157: </td>
1158: </tr>
1159: <tr>
1160: <td>
1161: <table class="LC_nested">
1162: <tr class="LC_info_row">
1163: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1164: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1165: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1166: } elsif ($action eq 'login') {
1.386 raeburn 1167: if ($numheaders == 5) {
1.168 raeburn 1168: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1169: </table>
1170: </td>
1171: </tr>
1172: <tr>
1173: <td>
1174: <table class="LC_nested">
1175: <tr class="LC_info_row">
1176: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1177: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1178: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1179: $rowtotal ++;
1180: } else {
1181: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1182: }
1.256 raeburn 1183: $output .= '
1184: </table>
1185: </td>
1186: </tr>
1187: <tr>
1188: <td>
1189: <table class="LC_nested">
1190: <tr class="LC_info_row">';
1.386 raeburn 1191: if ($numheaders == 5) {
1.256 raeburn 1192: $output .= '
1193: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1194: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1195: </tr>';
1196: } else {
1197: $output .= '
1198: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1199: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1200: </tr>';
1201: }
1202: $rowtotal ++;
1.386 raeburn 1203: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1204: </table>
1205: </td>
1206: </tr>
1207: <tr>
1208: <td>
1209: <table class="LC_nested">
1210: <tr class="LC_info_row">';
1211: if ($numheaders == 5) {
1212: $output .= '
1213: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1214: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1215: </tr>';
1216: } else {
1217: $output .= '
1218: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1219: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1220: </tr>';
1221: }
1222: $rowtotal ++;
1223: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1224: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1225: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1226: $rowtotal ++;
1227: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1228: </table>
1229: </td>
1230: </tr>
1231: <tr>
1232: <td>
1233: <table class="LC_nested">
1234: <tr class="LC_info_row">
1235: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1236: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1237: &textbookcourses_javascript($settings).
1238: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1239: </table>
1240: </td>
1241: </tr>
1242: <tr>
1243: <td>
1244: <table class="LC_nested">
1245: <tr class="LC_info_row">
1246: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1247: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1248: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1249: </table>
1250: </td>
1251: </tr>
1252: <tr>
1253: <td>
1254: <table class="LC_nested">
1255: <tr class="LC_info_row">
1.306 raeburn 1256: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1257: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1258: </tr>'.
1259: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1260: } elsif ($action eq 'requestauthor') {
1261: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1262: $rowtotal ++;
1.122 jms 1263: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1264: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1265: </table>
1266: </td>
1267: </tr>
1268: <tr>
1269: <td>
1270: <table class="LC_nested">
1271: <tr class="LC_info_row">
1.306 raeburn 1272: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1273: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1274: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1275: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1276: </tr>'.
1.30 raeburn 1277: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1278: </table>
1279: </td>
1280: </tr>
1281: <tr>
1282: <td>
1283: <table class="LC_nested">
1284: <tr class="LC_info_row">
1.59 bisitz 1285: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1286: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1287: </tr>'.
1.30 raeburn 1288: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1289: $rowtotal += 2;
1.6 raeburn 1290: }
1.3 raeburn 1291: } else {
1.30 raeburn 1292: $output .= '
1.3 raeburn 1293: <tr>
1294: <td>
1295: <table class="LC_nested">
1.30 raeburn 1296: <tr class="LC_info_row">';
1.277 raeburn 1297: if ($action eq 'login') {
1.30 raeburn 1298: $output .= '
1.59 bisitz 1299: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1300: } elsif ($action eq 'serverstatuses') {
1301: $output .= '
1.306 raeburn 1302: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1303: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1304:
1.6 raeburn 1305: } else {
1.30 raeburn 1306: $output .= '
1.306 raeburn 1307: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1308: }
1.72 raeburn 1309: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1310: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1311: &mt($item->{'header'}->[0]->{'col2'});
1312: if ($action eq 'serverstatuses') {
1313: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1314: }
1.69 raeburn 1315: } else {
1.306 raeburn 1316: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1317: &mt($item->{'header'}->[0]->{'col2'});
1318: }
1319: $output .= '</td>';
1320: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1321: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1322: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1323: &mt($item->{'header'}->[0]->{'col3'});
1324: } else {
1.306 raeburn 1325: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1326: &mt($item->{'header'}->[0]->{'col3'});
1327: }
1.69 raeburn 1328: if ($action eq 'serverstatuses') {
1329: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1330: }
1331: $output .= '</td>';
1.6 raeburn 1332: }
1.150 raeburn 1333: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1334: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1335: &mt($item->{'header'}->[0]->{'col4'});
1336: }
1.69 raeburn 1337: $output .= '</tr>';
1.48 raeburn 1338: $rowtotal ++;
1.168 raeburn 1339: if ($action eq 'quotas') {
1.86 raeburn 1340: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1341: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1342: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1343: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1344: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1345: }
1.3 raeburn 1346: }
1.30 raeburn 1347: $output .= '
1.3 raeburn 1348: </table>
1349: </td>
1350: </tr>
1.30 raeburn 1351: </table><br />';
1352: return ($output,$rowtotal);
1.1 raeburn 1353: }
1354:
1.3 raeburn 1355: sub print_login {
1.168 raeburn 1356: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1357: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1358: my %choices = &login_choices();
1.386 raeburn 1359: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1360: %lt = &login_file_options();
1361: $switchserver = &check_switchserver($dom,$confname);
1362: }
1.168 raeburn 1363: if ($caller eq 'service') {
1.149 raeburn 1364: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1365: my $choice = $choices{'disallowlogin'};
1366: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1367: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1368: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1369: '<th>'.$choices{'server'}.'</th>'.
1370: '<th>'.$choices{'serverpath'}.'</th>'.
1371: '<th>'.$choices{'custompath'}.'</th>'.
1372: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1373: my %disallowed;
1374: if (ref($settings) eq 'HASH') {
1375: if (ref($settings->{'loginvia'}) eq 'HASH') {
1376: %disallowed = %{$settings->{'loginvia'}};
1377: }
1378: }
1379: foreach my $lonhost (sort(keys(%servers))) {
1380: my $direct = 'selected="selected"';
1.128 raeburn 1381: if (ref($disallowed{$lonhost}) eq 'HASH') {
1382: if ($disallowed{$lonhost}{'server'} ne '') {
1383: $direct = '';
1384: }
1.110 raeburn 1385: }
1.115 raeburn 1386: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1387: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1388: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1389: '</option>';
1.184 raeburn 1390: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1391: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1392: my $selected = '';
1.128 raeburn 1393: if (ref($disallowed{$lonhost}) eq 'HASH') {
1394: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1395: $selected = 'selected="selected"';
1396: }
1.110 raeburn 1397: }
1398: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1399: $servers{$hostid}.'</option>';
1400: }
1.128 raeburn 1401: $datatable .= '</select></td>'.
1402: '<td><select name="'.$lonhost.'_serverpath">';
1403: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1404: my $pathname = $path;
1405: if ($path eq 'custom') {
1406: $pathname = &mt('Custom Path').' ->';
1407: }
1408: my $selected = '';
1409: if (ref($disallowed{$lonhost}) eq 'HASH') {
1410: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1411: $selected = 'selected="selected"';
1412: }
1413: } elsif ($path eq '') {
1414: $selected = 'selected="selected"';
1415: }
1416: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1417: }
1418: $datatable .= '</select></td>';
1419: my ($custom,$exempt);
1420: if (ref($disallowed{$lonhost}) eq 'HASH') {
1421: $custom = $disallowed{$lonhost}{'custompath'};
1422: $exempt = $disallowed{$lonhost}{'exempt'};
1423: }
1424: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1425: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1426: '</tr>';
1.110 raeburn 1427: }
1428: $datatable .= '</table></td></tr>';
1429: return $datatable;
1.168 raeburn 1430: } elsif ($caller eq 'page') {
1431: my %defaultchecked = (
1432: 'coursecatalog' => 'on',
1.188 raeburn 1433: 'helpdesk' => 'on',
1.168 raeburn 1434: 'adminmail' => 'off',
1435: 'newuser' => 'off',
1436: );
1.188 raeburn 1437: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1438: my (%checkedon,%checkedoff);
1.42 raeburn 1439: foreach my $item (@toggles) {
1.168 raeburn 1440: if ($defaultchecked{$item} eq 'on') {
1441: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1442: $checkedoff{$item} = ' ';
1.168 raeburn 1443: } elsif ($defaultchecked{$item} eq 'off') {
1444: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1445: $checkedon{$item} = ' ';
1446: }
1.1 raeburn 1447: }
1.168 raeburn 1448: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1449: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1450: my @logintext = ('textcol','bgcol');
1451: my @bgs = ('pgbg','mainbg','sidebg');
1452: my @links = ('link','alink','vlink');
1453: my %designhash = &Apache::loncommon::get_domainconf($dom);
1454: my %defaultdesign = %Apache::loncommon::defaultdesign;
1455: my (%is_custom,%designs);
1456: my %defaults = (
1457: font => $defaultdesign{'login.font'},
1458: );
1.6 raeburn 1459: foreach my $item (@images) {
1.168 raeburn 1460: $defaults{$item} = $defaultdesign{'login.'.$item};
1461: $defaults{'showlogo'}{$item} = 1;
1462: }
1463: foreach my $item (@bgs) {
1464: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1465: }
1.41 raeburn 1466: foreach my $item (@logintext) {
1.168 raeburn 1467: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1468: }
1.168 raeburn 1469: foreach my $item (@links) {
1470: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1471: }
1.168 raeburn 1472: if (ref($settings) eq 'HASH') {
1473: foreach my $item (@toggles) {
1474: if ($settings->{$item} eq '1') {
1475: $checkedon{$item} = ' checked="checked" ';
1476: $checkedoff{$item} = ' ';
1477: } elsif ($settings->{$item} eq '0') {
1478: $checkedoff{$item} = ' checked="checked" ';
1479: $checkedon{$item} = ' ';
1480: }
1481: }
1482: foreach my $item (@images) {
1483: if (defined($settings->{$item})) {
1484: $designs{$item} = $settings->{$item};
1485: $is_custom{$item} = 1;
1486: }
1487: if (defined($settings->{'showlogo'}{$item})) {
1488: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1489: }
1490: }
1.402 raeburn 1491: foreach my $item (@alttext) {
1492: if (ref($settings->{'alttext'}) eq 'HASH') {
1493: if ($settings->{'alttext'}->{$item} ne '') {
1494: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1495: }
1496: }
1497: }
1.168 raeburn 1498: foreach my $item (@logintext) {
1499: if ($settings->{$item} ne '') {
1500: $designs{'logintext'}{$item} = $settings->{$item};
1501: $is_custom{$item} = 1;
1502: }
1503: }
1504: if ($settings->{'font'} ne '') {
1505: $designs{'font'} = $settings->{'font'};
1506: $is_custom{'font'} = 1;
1507: }
1508: foreach my $item (@bgs) {
1509: if ($settings->{$item} ne '') {
1510: $designs{'bgs'}{$item} = $settings->{$item};
1511: $is_custom{$item} = 1;
1512: }
1513: }
1514: foreach my $item (@links) {
1515: if ($settings->{$item} ne '') {
1516: $designs{'links'}{$item} = $settings->{$item};
1517: $is_custom{$item} = 1;
1518: }
1519: }
1520: } else {
1521: if ($designhash{$dom.'.login.font'} ne '') {
1522: $designs{'font'} = $designhash{$dom.'.login.font'};
1523: $is_custom{'font'} = 1;
1524: }
1525: foreach my $item (@images) {
1526: if ($designhash{$dom.'.login.'.$item} ne '') {
1527: $designs{$item} = $designhash{$dom.'.login.'.$item};
1528: $is_custom{$item} = 1;
1529: }
1530: }
1531: foreach my $item (@bgs) {
1532: if ($designhash{$dom.'.login.'.$item} ne '') {
1533: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1534: $is_custom{$item} = 1;
1535: }
1.6 raeburn 1536: }
1.168 raeburn 1537: foreach my $item (@links) {
1538: if ($designhash{$dom.'.login.'.$item} ne '') {
1539: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1540: $is_custom{$item} = 1;
1541: }
1.6 raeburn 1542: }
1543: }
1.168 raeburn 1544: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1545: logo => 'Institution Logo',
1546: domlogo => 'Domain Logo',
1547: login => 'Login box');
1548: my $itemcount = 1;
1549: foreach my $item (@toggles) {
1550: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1551: $datatable .=
1552: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1553: '</td><td>'.
1554: '<span class="LC_nobreak"><label><input type="radio" name="'.
1555: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1556: '</label> <label><input type="radio" name="'.$item.'"'.
1557: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1558: '</tr>';
1559: $itemcount ++;
1.6 raeburn 1560: }
1.168 raeburn 1561: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1562: $datatable .= '</tr></table></td></tr>';
1563: } elsif ($caller eq 'help') {
1.386 raeburn 1564: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1565: my $itemcount = 1;
1566: $defaulturl = '/adm/loginproblems.html';
1567: $defaulttype = 'default';
1568: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1569: my @currlangs;
1570: if (ref($settings) eq 'HASH') {
1571: if (ref($settings->{'helpurl'}) eq 'HASH') {
1572: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1573: next if ($settings->{'helpurl'}{$key} eq '');
1574: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1575: $type{$key} = 'custom';
1576: unless ($key eq 'nolang') {
1577: push(@currlangs,$key);
1578: }
1579: }
1580: } elsif ($settings->{'helpurl'} ne '') {
1581: $type{'nolang'} = 'custom';
1582: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1583: }
1584: }
1.168 raeburn 1585: foreach my $lang ('nolang',sort(@currlangs)) {
1586: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1587: $datatable .= '<tr'.$css_class.'>';
1588: if ($url{$lang} eq '') {
1589: $url{$lang} = $defaulturl;
1590: }
1591: if ($type{$lang} eq '') {
1592: $type{$lang} = $defaulttype;
1593: }
1594: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1595: if ($lang eq 'nolang') {
1596: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1597: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1598: } else {
1599: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1600: $langchoices{$lang},
1601: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1602: }
1603: $datatable .= '</span></td>'."\n".
1604: '<td class="LC_left_item">';
1605: if ($type{$lang} eq 'custom') {
1606: $datatable .= '<span class="LC_nobreak"><label>'.
1607: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1608: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1609: } else {
1610: $datatable .= $lt{'upl'};
1611: }
1612: $datatable .='<br />';
1613: if ($switchserver) {
1614: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1615: } else {
1616: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1617: }
1.168 raeburn 1618: $datatable .= '</td></tr>';
1619: $itemcount ++;
1.6 raeburn 1620: }
1.168 raeburn 1621: my @addlangs;
1622: foreach my $lang (sort(keys(%langchoices))) {
1623: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1624: push(@addlangs,$lang);
1625: }
1626: if (@addlangs > 0) {
1627: my %toadd;
1628: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1629: $toadd{''} = &mt('Select');
1630: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1631: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1632: &mt('Add log-in help page for a specific language:').' '.
1633: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1634: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1635: if ($switchserver) {
1636: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1637: } else {
1638: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1639: }
1.168 raeburn 1640: $datatable .= '</td></tr>';
1.169 raeburn 1641: $itemcount ++;
1.6 raeburn 1642: }
1.169 raeburn 1643: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1644: } elsif ($caller eq 'headtag') {
1645: my %domservers = &Apache::lonnet::get_servers($dom);
1646: my $choice = $choices{'headtag'};
1647: $css_class = ' class="LC_odd_row"';
1648: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1649: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1650: '<th>'.$choices{'current'}.'</th>'.
1651: '<th>'.$choices{'action'}.'</th>'.
1652: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1653: my (%currurls,%currexempt);
1654: if (ref($settings) eq 'HASH') {
1655: if (ref($settings->{'headtag'}) eq 'HASH') {
1656: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1657: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1658: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1659: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1660: }
1661: }
1662: }
1663: }
1664: foreach my $lonhost (sort(keys(%domservers))) {
1665: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1666: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1667: if ($currurls{$lonhost}) {
1668: $datatable .= '<td class="LC_right_item"><a href="'.
1669: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1670: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1671: '">'.$lt{'curr'}.'</a></td>'.
1672: '<td><span class="LC_nobreak"><label>'.
1673: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1674: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1675: } else {
1676: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1677: }
1678: $datatable .='<br />';
1679: if ($switchserver) {
1680: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1681: } else {
1682: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1683: }
1.330 raeburn 1684: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1685: }
1686: $datatable .= '</table></td></tr>';
1.386 raeburn 1687: } elsif ($caller eq 'saml') {
1688: my %domservers = &Apache::lonnet::get_servers($dom);
1689: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1690: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1691: '<th>'.$choices{'samllanding'}.'</th>'.
1692: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1693: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1694: foreach my $lonhost (keys(%domservers)) {
1695: $samlurl{$lonhost} = '/adm/sso';
1696: $styleon{$lonhost} = 'display:none';
1697: $styleoff{$lonhost} = '';
1698: }
1.411 raeburn 1699: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1700: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1701: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1702: $saml{$lonhost} = 1;
1703: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1704: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1705: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1706: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1707: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1708: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1709: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1710: $styleon{$lonhost} = '';
1711: $styleoff{$lonhost} = 'display:none';
1712: } else {
1713: $styleon{$lonhost} = 'display:none';
1714: $styleoff{$lonhost} = '';
1715: }
1716: }
1717: }
1718: my $itemcount = 1;
1719: foreach my $lonhost (sort(keys(%domservers))) {
1720: my $samlon = ' ';
1721: my $samloff = ' checked="checked" ';
1722: if ($saml{$lonhost}) {
1723: $samlon = $samloff;
1724: $samloff = ' ';
1725: }
1.412 raeburn 1726: my $samlwinon = '';
1727: my $samlwinoff = ' checked="checked"';
1728: if ($samlwindow{$lonhost}) {
1729: $samlwinon = $samlwinoff;
1730: $samlwinoff = '';
1731: }
1.386 raeburn 1732: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1733: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1734: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1735: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1736: &mt('No').'</label>'.(' 'x2).
1737: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1738: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1739: &mt('Yes').'</label></span></td>'.
1740: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1741: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1742: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1743: '<th>'.&mt('Alt Text').'</th></tr>'.
1744: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1745: $samltext{$lonhost}.'" /></td><td>';
1746: if ($samlimg{$lonhost}) {
1747: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1748: '<span class="LC_nobreak"><label>'.
1749: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1750: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1751: } else {
1752: $datatable .= $lt{'upl'};
1753: }
1754: $datatable .='<br />';
1755: if ($switchserver) {
1756: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1757: } else {
1758: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1759: }
1760: $datatable .= '</td>'.
1.412 raeburn 1761: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1762: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1763: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1764: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1765: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1766: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1767: '<tr'.$css_class.'>'.
1768: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1769: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1770: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1771: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1772: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1773: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1774: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1775: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1776: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1777: '</table></td>'.
1778: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1779: $itemcount ++;
1780: }
1781: $datatable .= '</table></td></tr>';
1.1 raeburn 1782: }
1.6 raeburn 1783: return $datatable;
1784: }
1785:
1786: sub login_choices {
1787: my %choices =
1788: &Apache::lonlocal::texthash (
1.116 bisitz 1789: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1790: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1791: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1792: disallowlogin => "Login page requests redirected",
1793: hostid => "Server",
1.128 raeburn 1794: server => "Redirect to:",
1795: serverpath => "Path",
1796: custompath => "Custom",
1797: exempt => "Exempt IP(s)",
1.110 raeburn 1798: directlogin => "No redirect",
1799: newuser => "Link to create a user account",
1800: img => "Header",
1801: logo => "Main Logo",
1802: domlogo => "Domain Logo",
1803: login => "Log-in Header",
1804: textcol => "Text color",
1805: bgcol => "Box color",
1806: bgs => "Background colors",
1807: links => "Link colors",
1808: font => "Font color",
1809: pgbg => "Header",
1810: mainbg => "Page",
1811: sidebg => "Login box",
1812: link => "Link",
1813: alink => "Active link",
1814: vlink => "Visited link",
1.256 raeburn 1815: headtag => "Custom markup",
1816: action => "Action",
1817: current => "Current",
1.386 raeburn 1818: samllanding => "Dual login?",
1819: samloptions => "Options",
1.402 raeburn 1820: alttext => "Alt text",
1.6 raeburn 1821: );
1822: return %choices;
1823: }
1824:
1.386 raeburn 1825: sub login_file_options {
1826: return &Apache::lonlocal::texthash(
1827: del => 'Delete?',
1828: rep => 'Replace:',
1829: upl => 'Upload:',
1830: curr => 'View contents',
1831: default => 'Default',
1832: custom => 'Custom',
1833: none => 'None',
1834: );
1835: }
1836:
1.394 raeburn 1837: sub print_ipaccess {
1838: my ($dom,$settings,$rowtotal) = @_;
1839: my $css_class;
1840: my $itemcount = 0;
1841: my $datatable;
1842: my %ordered;
1843: if (ref($settings) eq 'HASH') {
1844: foreach my $item (keys(%{$settings})) {
1845: if (ref($settings->{$item}) eq 'HASH') {
1846: my $num = $settings->{$item}{'order'};
1847: if ($num eq '') {
1848: $num = scalar(keys(%{$settings}));
1849: }
1850: $ordered{$num} = $item;
1851: }
1852: }
1853: }
1854: my $maxnum = scalar(keys(%ordered));
1855: if (keys(%ordered)) {
1856: my @items = sort { $a <=> $b } keys(%ordered);
1857: for (my $i=0; $i<@items; $i++) {
1858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1859: my $item = $ordered{$items[$i]};
1860: my ($name,$ipranges,%commblocks,%courses);
1861: if (ref($settings->{$item}) eq 'HASH') {
1862: $name = $settings->{$item}->{'name'};
1863: $ipranges = $settings->{$item}->{'ip'};
1864: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1865: %commblocks = %{$settings->{$item}->{'commblocks'}};
1866: }
1867: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1868: %courses = %{$settings->{$item}->{'courses'}};
1869: }
1870: }
1871: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1872: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1873: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1874: for (my $k=0; $k<=$maxnum; $k++) {
1875: my $vpos = $k+1;
1876: my $selstr;
1877: if ($k == $i) {
1878: $selstr = ' selected="selected" ';
1879: }
1880: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1881: }
1882: $datatable .= '</select>'.(' 'x2).
1883: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1884: &mt('Delete?').'</label></span></td>'.
1885: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1886: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1887: '</td></tr>';
1888: $itemcount ++;
1889: }
1890: }
1891: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1892: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1893: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1894: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1895: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1896: for (my $k=0; $k<$maxnum+1; $k++) {
1897: my $vpos = $k+1;
1898: my $selstr;
1899: if ($k == $maxnum) {
1900: $selstr = ' selected="selected" ';
1901: }
1902: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1903: }
1904: $datatable .= '</select> '."\n".
1905: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1906: '<td colspan="2">'.
1907: &ipaccess_options('add',$itemcount,$dom).
1908: '</td>'."\n".
1909: '</tr>'."\n";
1910: $$rowtotal ++;
1911: return $datatable;
1912: }
1913:
1914: sub ipaccess_options {
1915: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1916: my (%currblocks,%currcourses,$output);
1917: if (ref($blocksref) eq 'HASH') {
1918: %currblocks = %{$blocksref};
1919: }
1920: if (ref($coursesref) eq 'HASH') {
1921: %currcourses = %{$coursesref};
1922: }
1923: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1924: '<span class="LC_nobreak">'.&mt('Name').': '.
1925: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1926: '</span></fieldset>'.
1927: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1928: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1929: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1930: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1931: $ipranges.'</textarea></fieldset>'.
1932: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1933: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1934: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1935: '<table>';
1936: foreach my $cid (sort(keys(%currcourses))) {
1937: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1938: $output .= '<tr><td><span class="LC_nobreak">'.
1939: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1940: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1941: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1942: }
1943: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1944: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1945: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1946: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1947: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1948: '</span></td></tr></table>'."\n".
1949: '</fieldset>';
1950: return $output;
1951: }
1952:
1953: sub blocker_checkboxes {
1954: my ($num,$blocks) = @_;
1955: my ($typeorder,$types) = &commblocktype_text();
1956: my $numinrow = 6;
1957: my $output = '<table>';
1958: for (my $i=0; $i<@{$typeorder}; $i++) {
1959: my $block = $typeorder->[$i];
1960: my $blockstatus;
1961: if (ref($blocks) eq 'HASH') {
1962: if ($blocks->{$block} eq 'on') {
1963: $blockstatus = 'checked="checked"';
1964: }
1965: }
1966: my $rem = $i%($numinrow);
1967: if ($rem == 0) {
1968: if ($i > 0) {
1969: $output .= '</tr>';
1970: }
1971: $output .= '<tr>';
1972: }
1973: if ($i == scalar(@{$typeorder})-1) {
1974: my $colsleft = $numinrow-$rem;
1975: if ($colsleft > 1) {
1976: $output .= '<td colspan="'.$colsleft.'">';
1977: } else {
1978: $output .= '<td>';
1979: }
1980: } else {
1981: $output .= '<td>';
1982: }
1983: my $item = 'ipaccess_block_'.$num;
1984: if ($blockstatus) {
1985: $blockstatus = ' '.$blockstatus;
1986: }
1987: $output .= '<span class="LC_nobreak"><label>'."\n".
1988: '<input type="checkbox" name="'.$item.'"'.
1989: $blockstatus.' value="'.$block.'"'.' />'.
1990: $types->{$block}.'</label></span>'."\n".
1991: '<br /></td>';
1992: }
1993: $output .= '</tr></table>';
1994: return $output;
1995: }
1996:
1997: sub commblocktype_text {
1998: my %types = &Apache::lonlocal::texthash(
1999: 'com' => 'Messaging',
2000: 'chat' => 'Chat Room',
2001: 'boards' => 'Discussion',
2002: 'port' => 'Portfolio',
2003: 'groups' => 'Groups',
2004: 'blogs' => 'Blogs',
2005: 'about' => 'User Information',
2006: 'printout' => 'Printouts',
2007: 'passwd' => 'Change Password',
2008: 'grades' => 'Gradebook',
1.397 raeburn 2009: 'search' => 'Course search',
2010: 'wishlist' => 'Stored links',
2011: 'annotate' => 'Annotations',
1.394 raeburn 2012: );
1.397 raeburn 2013: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 2014: return ($typeorder,\%types);
2015: }
2016:
1.6 raeburn 2017: sub print_rolecolors {
1.30 raeburn 2018: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2019: my %choices = &color_font_choices();
2020: my @bgs = ('pgbg','tabbg','sidebg');
2021: my @links = ('link','alink','vlink');
2022: my @images = ('img');
2023: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2024: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2025: my %defaultdesign = %Apache::loncommon::defaultdesign;
2026: my (%is_custom,%designs);
1.200 raeburn 2027: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2028: if (ref($settings) eq 'HASH') {
2029: if (ref($settings->{$role}) eq 'HASH') {
2030: if ($settings->{$role}->{'img'} ne '') {
2031: $designs{'img'} = $settings->{$role}->{'img'};
2032: $is_custom{'img'} = 1;
2033: }
2034: if ($settings->{$role}->{'font'} ne '') {
2035: $designs{'font'} = $settings->{$role}->{'font'};
2036: $is_custom{'font'} = 1;
2037: }
1.97 tempelho 2038: if ($settings->{$role}->{'fontmenu'} ne '') {
2039: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2040: $is_custom{'fontmenu'} = 1;
2041: }
1.6 raeburn 2042: foreach my $item (@bgs) {
2043: if ($settings->{$role}->{$item} ne '') {
2044: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2045: $is_custom{$item} = 1;
2046: }
2047: }
2048: foreach my $item (@links) {
2049: if ($settings->{$role}->{$item} ne '') {
2050: $designs{'links'}{$item} = $settings->{$role}->{$item};
2051: $is_custom{$item} = 1;
2052: }
2053: }
2054: }
2055: } else {
2056: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2057: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2058: $is_custom{'img'} = 1;
2059: }
1.97 tempelho 2060: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2061: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2062: $is_custom{'fontmenu'} = 1;
2063: }
1.6 raeburn 2064: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2065: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2066: $is_custom{'font'} = 1;
2067: }
2068: foreach my $item (@bgs) {
2069: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2070: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2071: $is_custom{$item} = 1;
2072:
2073: }
2074: }
2075: foreach my $item (@links) {
2076: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2077: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2078: $is_custom{$item} = 1;
2079: }
2080: }
2081: }
2082: my $itemcount = 1;
1.30 raeburn 2083: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2084: $datatable .= '</tr></table></td></tr>';
2085: return $datatable;
2086: }
2087:
1.200 raeburn 2088: sub role_defaults {
2089: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2090: my %defaults;
2091: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2092: return %defaults;
2093: }
2094: my %defaultdesign = %Apache::loncommon::defaultdesign;
2095: if ($role eq 'login') {
2096: %defaults = (
2097: font => $defaultdesign{$role.'.font'},
2098: );
2099: if (ref($logintext) eq 'ARRAY') {
2100: foreach my $item (@{$logintext}) {
2101: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2102: }
2103: }
2104: foreach my $item (@{$images}) {
2105: $defaults{'showlogo'}{$item} = 1;
2106: }
2107: } else {
2108: %defaults = (
2109: img => $defaultdesign{$role.'.img'},
2110: font => $defaultdesign{$role.'.font'},
2111: fontmenu => $defaultdesign{$role.'.fontmenu'},
2112: );
2113: }
2114: foreach my $item (@{$bgs}) {
2115: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2116: }
2117: foreach my $item (@{$links}) {
2118: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2119: }
2120: foreach my $item (@{$images}) {
2121: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2122: }
2123: return %defaults;
2124: }
2125:
1.6 raeburn 2126: sub display_color_options {
1.9 raeburn 2127: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2128: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2129: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2130: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2131: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2132: '<td>'.$choices->{'font'}.'</td>';
2133: if (!$is_custom->{'font'}) {
1.329 raeburn 2134: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2135: } else {
2136: $datatable .= '<td> </td>';
2137: }
1.174 foxr 2138: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2139:
1.8 raeburn 2140: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2141: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2142: ' value="'.$current_color.'" /> '.
1.329 raeburn 2143: ' </span></td></tr>';
1.107 raeburn 2144: unless ($role eq 'login') {
2145: $datatable .= '<tr'.$css_class.'>'.
2146: '<td>'.$choices->{'fontmenu'}.'</td>';
2147: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2148: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2149: } else {
2150: $datatable .= '<td> </td>';
2151: }
1.202 raeburn 2152: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2153: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2154: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2155: '<input class="colorchooser" type="text" size="10" name="'
2156: .$role.'_fontmenu"'.
2157: ' value="'.$current_color.'" /> '.
1.329 raeburn 2158: ' </span></td></tr>';
1.97 tempelho 2159: }
1.9 raeburn 2160: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2161: foreach my $img (@{$images}) {
1.18 albertel 2162: $itemcount ++;
1.6 raeburn 2163: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2164: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2165: '<td>'.$choices->{$img};
1.402 raeburn 2166: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2167: if ($role eq 'login') {
2168: if ($img eq 'login') {
2169: $login_hdr_pick =
1.135 bisitz 2170: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2171: $logincolors =
2172: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2173: $designs,$defaults);
1.402 raeburn 2174: } else {
2175: if ($img ne 'domlogo') {
2176: $datatable.= &logo_display_options($img,$defaults,$designs);
2177: }
2178: if (ref($designs->{'alttext'}) eq 'HASH') {
2179: $alttext = $designs->{'alttext'}{$img};
2180: }
1.70 raeburn 2181: }
2182: }
2183: $datatable .= '</td>';
1.6 raeburn 2184: if ($designs->{$img} ne '') {
2185: $imgfile = $designs->{$img};
1.18 albertel 2186: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2187: } else {
2188: $imgfile = $defaults->{$img};
2189: }
2190: if ($imgfile) {
1.9 raeburn 2191: my ($showfile,$fullsize);
2192: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2193: my $urldir = $1;
2194: my $filename = $2;
2195: my @info = &Apache::lonnet::stat_file($designs->{$img});
2196: if (@info) {
2197: my $thumbfile = 'tn-'.$filename;
2198: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2199: if (@thumb) {
2200: $showfile = $urldir.'/'.$thumbfile;
2201: } else {
2202: $showfile = $imgfile;
2203: }
2204: } else {
2205: $showfile = '';
2206: }
2207: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2208: $showfile = $imgfile;
1.6 raeburn 2209: my $imgdir = $1;
2210: my $filename = $2;
1.159 raeburn 2211: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2212: $showfile = "/$imgdir/tn-".$filename;
2213: } else {
1.159 raeburn 2214: my $input = $londocroot.$imgfile;
2215: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2216: if (!-e $output) {
1.9 raeburn 2217: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2218: my ($fullwidth,$fullheight) = &check_dimensions($input);
2219: if ($fullwidth ne '' && $fullheight ne '') {
2220: if ($fullwidth > $width && $fullheight > $height) {
2221: my $size = $width.'x'.$height;
1.316 raeburn 2222: my @args = ('convert','-sample',$size,$input,$output);
2223: system({$args[0]} @args);
1.159 raeburn 2224: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2225: }
2226: }
1.6 raeburn 2227: }
2228: }
1.16 raeburn 2229: }
1.6 raeburn 2230: if ($showfile) {
1.40 raeburn 2231: if ($showfile =~ m{^/(adm|res)/}) {
2232: if ($showfile =~ m{^/res/}) {
2233: my $local_showfile =
2234: &Apache::lonnet::filelocation('',$showfile);
2235: &Apache::lonnet::repcopy($local_showfile);
2236: }
2237: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2238: }
2239: if ($imgfile) {
2240: if ($imgfile =~ m{^/(adm|res)/}) {
2241: if ($imgfile =~ m{^/res/}) {
2242: my $local_imgfile =
2243: &Apache::lonnet::filelocation('',$imgfile);
2244: &Apache::lonnet::repcopy($local_imgfile);
2245: }
2246: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2247: } else {
2248: $fullsize = $imgfile;
2249: }
2250: }
1.41 raeburn 2251: $datatable .= '<td>';
2252: if ($img eq 'login') {
1.135 bisitz 2253: $datatable .= $login_hdr_pick;
2254: }
1.41 raeburn 2255: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2256: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2257: } else {
1.201 raeburn 2258: $datatable .= '<td> </td><td class="LC_left_item">'.
2259: &mt('Upload:').'<br />';
1.6 raeburn 2260: }
2261: } else {
1.201 raeburn 2262: $datatable .= '<td> </td><td class="LC_left_item">'.
2263: &mt('Upload:').'<br />';
1.6 raeburn 2264: }
1.9 raeburn 2265: if ($switchserver) {
2266: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2267: } else {
1.135 bisitz 2268: if ($img ne 'login') { # suppress file selection for Log-in header
2269: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2270: }
1.9 raeburn 2271: }
1.402 raeburn 2272: if (($role eq 'login') && ($img ne 'login')) {
2273: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2274: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2275: '</label></span>';
2276: }
1.9 raeburn 2277: $datatable .= '</td></tr>';
1.6 raeburn 2278: }
2279: $itemcount ++;
2280: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2281: $datatable .= '<tr'.$css_class.'>'.
2282: '<td>'.$choices->{'bgs'}.'</td>';
2283: my $bgs_def;
2284: foreach my $item (@{$bgs}) {
2285: if (!$is_custom->{$item}) {
1.329 raeburn 2286: $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 2287: }
2288: }
2289: if ($bgs_def) {
1.8 raeburn 2290: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2291: } else {
2292: $datatable .= '<td> </td>';
2293: }
2294: $datatable .= '<td class="LC_right_item">'.
2295: '<table border="0"><tr>';
1.174 foxr 2296:
1.6 raeburn 2297: foreach my $item (@{$bgs}) {
1.306 raeburn 2298: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2299: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2300: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2301: $datatable .= ' ';
1.6 raeburn 2302: }
1.174 foxr 2303: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2304: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2305: }
2306: $datatable .= '</tr></table></td></tr>';
2307: $itemcount ++;
2308: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2309: $datatable .= '<tr'.$css_class.'>'.
2310: '<td>'.$choices->{'links'}.'</td>';
2311: my $links_def;
2312: foreach my $item (@{$links}) {
2313: if (!$is_custom->{$item}) {
1.329 raeburn 2314: $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 2315: }
2316: }
2317: if ($links_def) {
1.8 raeburn 2318: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2319: } else {
2320: $datatable .= '<td> </td>';
2321: }
2322: $datatable .= '<td class="LC_right_item">'.
2323: '<table border="0"><tr>';
2324: foreach my $item (@{$links}) {
1.234 raeburn 2325: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2326: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2327: if ($designs->{'links'}{$item}) {
1.174 foxr 2328: $datatable.=' ';
1.6 raeburn 2329: }
1.174 foxr 2330: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2331: '" /></td>';
2332: }
1.30 raeburn 2333: $$rowtotal += $itemcount;
1.3 raeburn 2334: return $datatable;
2335: }
2336:
1.70 raeburn 2337: sub logo_display_options {
2338: my ($img,$defaults,$designs) = @_;
2339: my $checkedon;
2340: if (ref($defaults) eq 'HASH') {
2341: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2342: if ($defaults->{'showlogo'}{$img}) {
2343: $checkedon = 'checked="checked" ';
2344: }
2345: }
2346: }
2347: if (ref($designs) eq 'HASH') {
2348: if (ref($designs->{'showlogo'}) eq 'HASH') {
2349: if (defined($designs->{'showlogo'}{$img})) {
2350: if ($designs->{'showlogo'}{$img} == 0) {
2351: $checkedon = '';
2352: } elsif ($designs->{'showlogo'}{$img} == 1) {
2353: $checkedon = 'checked="checked" ';
2354: }
2355: }
2356: }
2357: }
2358: return '<br /><label> <input type="checkbox" name="'.
2359: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2360: &mt('show').'</label>'."\n";
2361: }
2362:
1.41 raeburn 2363: sub login_header_options {
1.135 bisitz 2364: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2365: my $output = '';
1.41 raeburn 2366: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2367: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2368: if (!$is_custom->{'textcol'}) {
2369: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2370: ' ';
2371: }
2372: if (!$is_custom->{'bgcol'}) {
2373: $output .= $choices->{'bgcol'}.': '.
2374: '<span id="css_'.$role.'_font" style="background-color: '.
2375: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2376: }
2377: $output .= '<br />';
2378: }
2379: $output .='<br />';
2380: return $output;
2381: }
2382:
2383: sub login_text_colors {
1.201 raeburn 2384: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2385: my $color_menu = '<table border="0"><tr>';
2386: foreach my $item (@{$logintext}) {
1.306 raeburn 2387: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2388: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2389: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2390: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2391: }
2392: $color_menu .= '</tr></table><br />';
2393: return $color_menu;
2394: }
2395:
2396: sub image_changes {
2397: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2398: my $output;
1.135 bisitz 2399: if ($img eq 'login') {
1.331 raeburn 2400: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2401: } elsif (!$is_custom) {
1.70 raeburn 2402: if ($img ne 'domlogo') {
1.331 raeburn 2403: $output = &mt('Default image:').'<br />';
1.41 raeburn 2404: } else {
1.331 raeburn 2405: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2406: }
2407: }
1.331 raeburn 2408: if ($img ne 'login') {
1.135 bisitz 2409: if ($img_import) {
2410: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2411: }
2412: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2413: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2414: if ($is_custom) {
2415: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2416: '<input type="checkbox" name="'.
2417: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2418: '</label> '.&mt('Replace:').'</span><br />';
2419: } else {
1.306 raeburn 2420: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2421: }
1.41 raeburn 2422: }
2423: return $output;
2424: }
2425:
1.3 raeburn 2426: sub print_quotas {
1.86 raeburn 2427: my ($dom,$settings,$rowtotal,$action) = @_;
2428: my $context;
2429: if ($action eq 'quotas') {
2430: $context = 'tools';
2431: } else {
2432: $context = $action;
2433: }
1.429 raeburn 2434: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2435: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2436: my $typecount = 0;
1.101 raeburn 2437: my ($css_class,%titles);
1.86 raeburn 2438: if ($context eq 'requestcourses') {
1.325 raeburn 2439: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2440: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2441: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2442: %titles = &courserequest_titles();
1.163 raeburn 2443: } elsif ($context eq 'requestauthor') {
2444: @usertools = ('author');
2445: @options = ('norequest','approval','automatic');
1.210 raeburn 2446: %titles = &authorrequest_titles();
1.86 raeburn 2447: } else {
1.430 raeburn 2448: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2449: %titles = &tool_titles();
1.86 raeburn 2450: }
1.26 raeburn 2451: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2452: foreach my $type (@{$types}) {
1.429 raeburn 2453: my $currdefquota;
1.163 raeburn 2454: unless (($context eq 'requestcourses') ||
2455: ($context eq 'requestauthor')) {
1.86 raeburn 2456: if (ref($settings) eq 'HASH') {
2457: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2458: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2459: } else {
2460: $currdefquota = $settings->{$type};
2461: }
1.78 raeburn 2462: }
1.72 raeburn 2463: }
1.3 raeburn 2464: if (defined($usertypes->{$type})) {
2465: $typecount ++;
2466: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2467: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2468: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2469: '<td class="LC_left_item">';
1.101 raeburn 2470: if ($context eq 'requestcourses') {
2471: $datatable .= '<table><tr>';
2472: }
2473: my %cell;
1.72 raeburn 2474: foreach my $item (@usertools) {
1.101 raeburn 2475: if ($context eq 'requestcourses') {
2476: my ($curroption,$currlimit);
2477: if (ref($settings) eq 'HASH') {
2478: if (ref($settings->{$item}) eq 'HASH') {
2479: $curroption = $settings->{$item}->{$type};
2480: if ($curroption =~ /^autolimit=(\d*)$/) {
2481: $currlimit = $1;
2482: }
2483: }
2484: }
2485: if (!$curroption) {
2486: $curroption = 'norequest';
2487: }
2488: $datatable .= '<th>'.$titles{$item}.'</th>';
2489: foreach my $option (@options) {
2490: my $val = $option;
2491: if ($option eq 'norequest') {
2492: $val = 0;
2493: }
2494: if ($option eq 'validate') {
2495: my $canvalidate = 0;
2496: if (ref($validations{$item}) eq 'HASH') {
2497: if ($validations{$item}{$type}) {
2498: $canvalidate = 1;
2499: }
2500: }
2501: next if (!$canvalidate);
2502: }
2503: my $checked = '';
2504: if ($option eq $curroption) {
2505: $checked = ' checked="checked"';
2506: } elsif ($option eq 'autolimit') {
2507: if ($curroption =~ /^autolimit/) {
2508: $checked = ' checked="checked"';
2509: }
2510: }
2511: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2512: '<input type="radio" name="crsreq_'.$item.
2513: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2514: $titles{$option}.'</label>';
1.101 raeburn 2515: if ($option eq 'autolimit') {
1.127 raeburn 2516: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2517: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2518: 'value="'.$currlimit.'" />';
1.101 raeburn 2519: }
1.127 raeburn 2520: $cell{$item} .= '</span> ';
1.103 raeburn 2521: if ($option eq 'autolimit') {
1.127 raeburn 2522: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2523: }
1.101 raeburn 2524: }
1.163 raeburn 2525: } elsif ($context eq 'requestauthor') {
2526: my $curroption;
2527: if (ref($settings) eq 'HASH') {
2528: $curroption = $settings->{$type};
2529: }
2530: if (!$curroption) {
2531: $curroption = 'norequest';
2532: }
2533: foreach my $option (@options) {
2534: my $val = $option;
2535: if ($option eq 'norequest') {
2536: $val = 0;
2537: }
2538: my $checked = '';
2539: if ($option eq $curroption) {
2540: $checked = ' checked="checked"';
2541: }
2542: $datatable .= '<span class="LC_nobreak"><label>'.
2543: '<input type="radio" name="authorreq_'.$type.
2544: '" value="'.$val.'"'.$checked.' />'.
2545: $titles{$option}.'</label></span> ';
2546: }
1.101 raeburn 2547: } else {
2548: my $checked = 'checked="checked" ';
1.413 raeburn 2549: if ($item eq 'timezone') {
2550: $checked = '';
2551: }
1.101 raeburn 2552: if (ref($settings) eq 'HASH') {
2553: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2554: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2555: $checked = '';
2556: } elsif ($settings->{$item}->{$type} == 1) {
2557: $checked = 'checked="checked" ';
2558: }
1.78 raeburn 2559: }
1.72 raeburn 2560: }
1.101 raeburn 2561: $datatable .= '<span class="LC_nobreak"><label>'.
2562: '<input type="checkbox" name="'.$context.'_'.$item.
2563: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2564: '</label></span> ';
1.72 raeburn 2565: }
1.101 raeburn 2566: }
2567: if ($context eq 'requestcourses') {
2568: $datatable .= '</tr><tr>';
2569: foreach my $item (@usertools) {
1.106 raeburn 2570: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2571: }
2572: $datatable .= '</tr></table>';
1.72 raeburn 2573: }
1.86 raeburn 2574: $datatable .= '</td>';
1.163 raeburn 2575: unless (($context eq 'requestcourses') ||
2576: ($context eq 'requestauthor')) {
1.86 raeburn 2577: $datatable .=
1.197 raeburn 2578: '<td class="LC_right_item">'.
1.429 raeburn 2579: '<span class="LC_nobreak">'.
1.3 raeburn 2580: '<input type="text" name="quota_'.$type.
1.72 raeburn 2581: '" value="'.$currdefquota.
1.197 raeburn 2582: '" size="5" /></span></td>';
1.86 raeburn 2583: }
2584: $datatable .= '</tr>';
1.3 raeburn 2585: }
2586: }
2587: }
1.163 raeburn 2588: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2589: $defaultquota = '20';
2590: if (ref($settings) eq 'HASH') {
2591: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2592: $defaultquota = $settings->{'defaultquota'}->{'default'};
2593: } elsif (defined($settings->{'default'})) {
2594: $defaultquota = $settings->{'default'};
2595: }
1.3 raeburn 2596: }
2597: }
2598: $typecount ++;
2599: $css_class = $typecount%2?' class="LC_odd_row"':'';
2600: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2601: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2602: '<td class="LC_left_item">';
1.101 raeburn 2603: if ($context eq 'requestcourses') {
2604: $datatable .= '<table><tr>';
2605: }
2606: my %defcell;
1.72 raeburn 2607: foreach my $item (@usertools) {
1.101 raeburn 2608: if ($context eq 'requestcourses') {
2609: my ($curroption,$currlimit);
2610: if (ref($settings) eq 'HASH') {
2611: if (ref($settings->{$item}) eq 'HASH') {
2612: $curroption = $settings->{$item}->{'default'};
2613: if ($curroption =~ /^autolimit=(\d*)$/) {
2614: $currlimit = $1;
2615: }
2616: }
2617: }
2618: if (!$curroption) {
2619: $curroption = 'norequest';
2620: }
2621: $datatable .= '<th>'.$titles{$item}.'</th>';
2622: foreach my $option (@options) {
2623: my $val = $option;
2624: if ($option eq 'norequest') {
2625: $val = 0;
2626: }
2627: if ($option eq 'validate') {
2628: my $canvalidate = 0;
2629: if (ref($validations{$item}) eq 'HASH') {
2630: if ($validations{$item}{'default'}) {
2631: $canvalidate = 1;
2632: }
2633: }
2634: next if (!$canvalidate);
2635: }
2636: my $checked = '';
2637: if ($option eq $curroption) {
2638: $checked = ' checked="checked"';
2639: } elsif ($option eq 'autolimit') {
2640: if ($curroption =~ /^autolimit/) {
2641: $checked = ' checked="checked"';
2642: }
2643: }
2644: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2645: '<input type="radio" name="crsreq_'.$item.
2646: '_default" value="'.$val.'"'.$checked.' />'.
2647: $titles{$option}.'</label>';
2648: if ($option eq 'autolimit') {
1.127 raeburn 2649: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2650: $item.'_limit_default" size="1" '.
2651: 'value="'.$currlimit.'" />';
2652: }
1.127 raeburn 2653: $defcell{$item} .= '</span> ';
1.104 raeburn 2654: if ($option eq 'autolimit') {
1.127 raeburn 2655: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2656: }
1.101 raeburn 2657: }
1.163 raeburn 2658: } elsif ($context eq 'requestauthor') {
2659: my $curroption;
2660: if (ref($settings) eq 'HASH') {
1.172 raeburn 2661: $curroption = $settings->{'default'};
1.163 raeburn 2662: }
2663: if (!$curroption) {
2664: $curroption = 'norequest';
2665: }
2666: foreach my $option (@options) {
2667: my $val = $option;
2668: if ($option eq 'norequest') {
2669: $val = 0;
2670: }
2671: my $checked = '';
2672: if ($option eq $curroption) {
2673: $checked = ' checked="checked"';
2674: }
2675: $datatable .= '<span class="LC_nobreak"><label>'.
2676: '<input type="radio" name="authorreq_default"'.
2677: ' value="'.$val.'"'.$checked.' />'.
2678: $titles{$option}.'</label></span> ';
2679: }
1.101 raeburn 2680: } else {
2681: my $checked = 'checked="checked" ';
2682: if (ref($settings) eq 'HASH') {
2683: if (ref($settings->{$item}) eq 'HASH') {
2684: if ($settings->{$item}->{'default'} == 0) {
2685: $checked = '';
2686: } elsif ($settings->{$item}->{'default'} == 1) {
2687: $checked = 'checked="checked" ';
2688: }
1.78 raeburn 2689: }
1.72 raeburn 2690: }
1.101 raeburn 2691: $datatable .= '<span class="LC_nobreak"><label>'.
2692: '<input type="checkbox" name="'.$context.'_'.$item.
2693: '" value="default" '.$checked.'/>'.$titles{$item}.
2694: '</label></span> ';
2695: }
2696: }
2697: if ($context eq 'requestcourses') {
2698: $datatable .= '</tr><tr>';
2699: foreach my $item (@usertools) {
1.106 raeburn 2700: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2701: }
1.101 raeburn 2702: $datatable .= '</tr></table>';
1.72 raeburn 2703: }
1.86 raeburn 2704: $datatable .= '</td>';
1.163 raeburn 2705: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2706: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2707: '<span class="LC_nobreak">'.
1.86 raeburn 2708: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2709: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2710: }
2711: $datatable .= '</tr>';
1.72 raeburn 2712: $typecount ++;
2713: $css_class = $typecount%2?' class="LC_odd_row"':'';
2714: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2715: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2716: if ($context eq 'requestcourses') {
1.109 raeburn 2717: $datatable .= &mt('(overrides affiliation, if set)').
2718: '</td>'.
2719: '<td class="LC_left_item">'.
2720: '<table><tr>';
1.101 raeburn 2721: } else {
1.109 raeburn 2722: $datatable .= &mt('(overrides affiliation, if checked)').
2723: '</td>'.
2724: '<td class="LC_left_item" colspan="2">'.
2725: '<br />';
1.101 raeburn 2726: }
2727: my %advcell;
1.72 raeburn 2728: foreach my $item (@usertools) {
1.101 raeburn 2729: if ($context eq 'requestcourses') {
2730: my ($curroption,$currlimit);
2731: if (ref($settings) eq 'HASH') {
2732: if (ref($settings->{$item}) eq 'HASH') {
2733: $curroption = $settings->{$item}->{'_LC_adv'};
2734: if ($curroption =~ /^autolimit=(\d*)$/) {
2735: $currlimit = $1;
2736: }
2737: }
2738: }
2739: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2740: my $checked = '';
2741: if ($curroption eq '') {
2742: $checked = ' checked="checked"';
2743: }
2744: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2745: '<input type="radio" name="crsreq_'.$item.
2746: '__LC_adv" value=""'.$checked.' />'.
2747: &mt('No override set').'</label></span> ';
1.101 raeburn 2748: foreach my $option (@options) {
2749: my $val = $option;
2750: if ($option eq 'norequest') {
2751: $val = 0;
2752: }
2753: if ($option eq 'validate') {
2754: my $canvalidate = 0;
2755: if (ref($validations{$item}) eq 'HASH') {
2756: if ($validations{$item}{'_LC_adv'}) {
2757: $canvalidate = 1;
2758: }
2759: }
2760: next if (!$canvalidate);
2761: }
2762: my $checked = '';
1.104 raeburn 2763: if ($val eq $curroption) {
1.101 raeburn 2764: $checked = ' checked="checked"';
2765: } elsif ($option eq 'autolimit') {
2766: if ($curroption =~ /^autolimit/) {
2767: $checked = ' checked="checked"';
2768: }
2769: }
2770: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2771: '<input type="radio" name="crsreq_'.$item.
2772: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2773: $titles{$option}.'</label>';
2774: if ($option eq 'autolimit') {
1.127 raeburn 2775: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2776: $item.'_limit__LC_adv" size="1" '.
2777: 'value="'.$currlimit.'" />';
2778: }
1.127 raeburn 2779: $advcell{$item} .= '</span> ';
1.104 raeburn 2780: if ($option eq 'autolimit') {
1.127 raeburn 2781: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2782: }
1.101 raeburn 2783: }
1.163 raeburn 2784: } elsif ($context eq 'requestauthor') {
2785: my $curroption;
2786: if (ref($settings) eq 'HASH') {
2787: $curroption = $settings->{'_LC_adv'};
2788: }
2789: my $checked = '';
2790: if ($curroption eq '') {
2791: $checked = ' checked="checked"';
2792: }
2793: $datatable .= '<span class="LC_nobreak"><label>'.
2794: '<input type="radio" name="authorreq__LC_adv"'.
2795: ' value=""'.$checked.' />'.
2796: &mt('No override set').'</label></span> ';
2797: foreach my $option (@options) {
2798: my $val = $option;
2799: if ($option eq 'norequest') {
2800: $val = 0;
2801: }
2802: my $checked = '';
2803: if ($val eq $curroption) {
2804: $checked = ' checked="checked"';
2805: }
2806: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2807: '<input type="radio" name="authorreq__LC_adv"'.
2808: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2809: $titles{$option}.'</label></span> ';
2810: }
1.101 raeburn 2811: } else {
2812: my $checked = 'checked="checked" ';
2813: if (ref($settings) eq 'HASH') {
2814: if (ref($settings->{$item}) eq 'HASH') {
2815: if ($settings->{$item}->{'_LC_adv'} == 0) {
2816: $checked = '';
2817: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2818: $checked = 'checked="checked" ';
2819: }
1.79 raeburn 2820: }
1.72 raeburn 2821: }
1.101 raeburn 2822: $datatable .= '<span class="LC_nobreak"><label>'.
2823: '<input type="checkbox" name="'.$context.'_'.$item.
2824: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2825: '</label></span> ';
2826: }
2827: }
2828: if ($context eq 'requestcourses') {
2829: $datatable .= '</tr><tr>';
2830: foreach my $item (@usertools) {
1.106 raeburn 2831: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2832: }
1.101 raeburn 2833: $datatable .= '</tr></table>';
1.72 raeburn 2834: }
1.98 raeburn 2835: $datatable .= '</td></tr>';
1.30 raeburn 2836: $$rowtotal += $typecount;
1.3 raeburn 2837: return $datatable;
2838: }
2839:
1.163 raeburn 2840: sub print_requestmail {
1.305 raeburn 2841: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2842: my ($now,$datatable,%currapp);
1.102 raeburn 2843: $now = time;
2844: if (ref($settings) eq 'HASH') {
2845: if (ref($settings->{'notify'}) eq 'HASH') {
2846: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2847: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2848: }
2849: }
2850: }
1.191 raeburn 2851: my $numinrow = 2;
1.224 raeburn 2852: my $css_class;
1.305 raeburn 2853: if ($$rowtotal%2) {
2854: $css_class = 'LC_odd_row';
2855: }
2856: if ($customcss) {
2857: $css_class .= " $customcss";
2858: }
2859: $css_class =~ s/^\s+//;
2860: if ($css_class) {
2861: $css_class = ' class="'.$css_class.'"';
2862: }
2863: if ($rowstyle) {
2864: $css_class .= ' style="'.$rowstyle.'"';
2865: }
1.163 raeburn 2866: my $text;
2867: if ($action eq 'requestcourses') {
2868: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2869: } elsif ($action eq 'requestauthor') {
2870: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2871: } else {
1.224 raeburn 2872: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2873: }
1.224 raeburn 2874: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2875: ' <td>'.$text.'</td>'.
1.102 raeburn 2876: ' <td class="LC_left_item">';
1.191 raeburn 2877: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2878: $action.'notifyapproval',%currapp);
1.191 raeburn 2879: if ($numdc > 0) {
2880: $datatable .= $table;
1.102 raeburn 2881: } else {
2882: $datatable .= &mt('There are no active Domain Coordinators');
2883: }
2884: $datatable .='</td></tr>';
2885: return $datatable;
2886: }
2887:
1.216 raeburn 2888: sub print_studentcode {
2889: my ($settings,$rowtotal) = @_;
2890: my $rownum = 0;
1.218 raeburn 2891: my ($output,%current);
1.325 raeburn 2892: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2893: if (ref($settings) eq 'HASH') {
2894: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2895: foreach my $type (@crstypes) {
2896: $current{$type} = $settings->{'uniquecode'}{$type};
2897: }
1.218 raeburn 2898: }
2899: }
2900: $output .= '<tr>'.
2901: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2902: '<td class="LC_left_item">';
2903: foreach my $type (@crstypes) {
2904: my $check = ' ';
2905: if ($current{$type}) {
2906: $check = ' checked="checked" ';
2907: }
2908: $output .= '<span class="LC_nobreak"><label>'.
2909: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2910: &mt($type).'</label></span>'.(' 'x2).' ';
2911: }
2912: $output .= '</td></tr>';
2913: $$rowtotal ++;
2914: return $output;
1.216 raeburn 2915: }
2916:
2917: sub print_textbookcourses {
1.242 raeburn 2918: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2919: my $rownum = 0;
2920: my $css_class;
2921: my $itemcount = 1;
2922: my $maxnum = 0;
2923: my $bookshash;
2924: if (ref($settings) eq 'HASH') {
1.242 raeburn 2925: $bookshash = $settings->{$type};
1.216 raeburn 2926: }
2927: my %ordered;
2928: if (ref($bookshash) eq 'HASH') {
2929: foreach my $item (keys(%{$bookshash})) {
2930: if (ref($bookshash->{$item}) eq 'HASH') {
2931: my $num = $bookshash->{$item}{'order'};
2932: $ordered{$num} = $item;
2933: }
2934: }
2935: }
2936: my $confname = $dom.'-domainconfig';
2937: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2938: my $maxnum = scalar(keys(%ordered));
2939: my $datatable;
1.216 raeburn 2940: if (keys(%ordered)) {
2941: my @items = sort { $a <=> $b } keys(%ordered);
2942: for (my $i=0; $i<@items; $i++) {
2943: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2944: my $key = $ordered{$items[$i]};
2945: my %coursehash=&Apache::lonnet::coursedescription($key);
2946: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2947: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2948: if (ref($bookshash->{$key}) eq 'HASH') {
2949: $subject = $bookshash->{$key}->{'subject'};
2950: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2951: if ($type eq 'textbooks') {
1.243 raeburn 2952: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2953: $author = $bookshash->{$key}->{'author'};
2954: $image = $bookshash->{$key}->{'image'};
2955: if ($image ne '') {
2956: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2957: my $imagethumb = "$path/tn-".$imagefile;
2958: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2959: }
1.216 raeburn 2960: }
2961: }
1.242 raeburn 2962: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2963: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2964: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2965: for (my $k=0; $k<=$maxnum; $k++) {
2966: my $vpos = $k+1;
2967: my $selstr;
2968: if ($k == $i) {
2969: $selstr = ' selected="selected" ';
2970: }
2971: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2972: }
2973: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2974: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2975: &mt('Delete?').'</label></span></td>'.
2976: '<td colspan="2">'.
1.242 raeburn 2977: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2978: (' 'x2).
1.242 raeburn 2979: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2980: if ($type eq 'textbooks') {
2981: $datatable .= (' 'x2).
1.243 raeburn 2982: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2983: (' 'x2).
1.242 raeburn 2984: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2985: (' 'x2).
2986: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2987: if ($image) {
1.267 raeburn 2988: $datatable .= $imgsrc.
1.242 raeburn 2989: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2990: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2991: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2992: }
2993: if ($switchserver) {
2994: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2995: } else {
2996: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2997: }
1.216 raeburn 2998: }
1.242 raeburn 2999: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 3000: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
3001: $coursetitle.'</span></td></tr>'."\n";
3002: $itemcount ++;
3003: }
3004: }
3005: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 3006: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3007: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3008: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3009: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3010: for (my $k=0; $k<$maxnum+1; $k++) {
3011: my $vpos = $k+1;
3012: my $selstr;
3013: if ($k == $maxnum) {
3014: $selstr = ' selected="selected" ';
3015: }
3016: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3017: }
3018: $datatable .= '</select> '."\n".
1.334 raeburn 3019: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3020: '<td colspan="2">'.
1.242 raeburn 3021: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3022: (' 'x2).
1.242 raeburn 3023: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3024: (' 'x2);
3025: if ($type eq 'textbooks') {
1.243 raeburn 3026: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3027: (' 'x2).
3028: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3029: (' 'x2).
3030: '<span class="LC_nobreak">'.&mt('Image:').' ';
3031: if ($switchserver) {
3032: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3033: } else {
3034: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3035: }
1.334 raeburn 3036: $datatable .= '</span>'."\n";
1.216 raeburn 3037: }
1.334 raeburn 3038: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3039: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3040: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3041: &Apache::loncommon::selectcourse_link
1.334 raeburn 3042: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3043: '</span></td>'."\n".
3044: '</tr>'."\n";
3045: $itemcount ++;
3046: return $datatable;
3047: }
3048:
1.217 raeburn 3049: sub textbookcourses_javascript {
1.242 raeburn 3050: my ($settings) = @_;
3051: return unless(ref($settings) eq 'HASH');
3052: my (%ordered,%total,%jstext);
3053: foreach my $type ('textbooks','templates') {
3054: $total{$type} = 0;
3055: if (ref($settings->{$type}) eq 'HASH') {
3056: foreach my $item (keys(%{$settings->{$type}})) {
3057: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3058: my $num = $settings->{$type}->{$item}{'order'};
3059: $ordered{$type}{$num} = $item;
3060: }
3061: }
3062: $total{$type} = scalar(keys(%{$settings->{$type}}));
3063: }
3064: my @jsarray = ();
3065: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3066: push(@jsarray,$ordered{$type}{$item});
3067: }
3068: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3069: }
3070: return <<"ENDSCRIPT";
3071: <script type="text/javascript">
3072: // <![CDATA[
1.242 raeburn 3073: function reorderBooks(form,item,caller) {
1.217 raeburn 3074: var changedVal;
1.242 raeburn 3075: $jstext{'textbooks'};
3076: $jstext{'templates'};
3077: var newpos;
3078: var maxh;
3079: if (caller == 'textbooks') {
3080: newpos = 'textbooks_addbook_pos';
3081: maxh = 1 + $total{'textbooks'};
3082: } else {
3083: newpos = 'templates_addbook_pos';
3084: maxh = 1 + $total{'templates'};
3085: }
1.217 raeburn 3086: var current = new Array;
3087: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3088: if (item == newpos) {
3089: changedVal = newitemVal;
3090: } else {
3091: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3092: current[newitemVal] = newpos;
3093: }
1.242 raeburn 3094: if (caller == 'textbooks') {
3095: for (var i=0; i<textbooks.length; i++) {
3096: var elementName = 'textbooks_'+textbooks[i];
3097: if (elementName != item) {
3098: if (form.elements[elementName]) {
3099: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3100: current[currVal] = elementName;
3101: }
3102: }
3103: }
3104: }
3105: if (caller == 'templates') {
3106: for (var i=0; i<templates.length; i++) {
3107: var elementName = 'templates_'+templates[i];
3108: if (elementName != item) {
3109: if (form.elements[elementName]) {
3110: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3111: current[currVal] = elementName;
3112: }
1.217 raeburn 3113: }
3114: }
3115: }
3116: var oldVal;
3117: for (var j=0; j<maxh; j++) {
3118: if (current[j] == undefined) {
3119: oldVal = j;
3120: }
3121: }
3122: if (oldVal < changedVal) {
3123: for (var k=oldVal+1; k<=changedVal ; k++) {
3124: var elementName = current[k];
3125: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3126: }
3127: } else {
3128: for (var k=changedVal; k<oldVal; k++) {
3129: var elementName = current[k];
3130: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3131: }
3132: }
3133: return;
3134: }
3135:
3136: // ]]>
3137: </script>
3138:
3139: ENDSCRIPT
3140: }
3141:
1.267 raeburn 3142: sub ltitools_javascript {
3143: my ($settings) = @_;
1.319 raeburn 3144: my $togglejs = <itools_toggle_js();
3145: unless (ref($settings) eq 'HASH') {
3146: return $togglejs;
3147: }
1.267 raeburn 3148: my (%ordered,$total,%jstext);
3149: $total = 0;
3150: foreach my $item (keys(%{$settings})) {
3151: if (ref($settings->{$item}) eq 'HASH') {
3152: my $num = $settings->{$item}{'order'};
3153: $ordered{$num} = $item;
3154: }
3155: }
3156: $total = scalar(keys(%{$settings}));
3157: my @jsarray = ();
3158: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3159: push(@jsarray,$ordered{$item});
3160: }
3161: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3162: return <<"ENDSCRIPT";
3163: <script type="text/javascript">
3164: // <![CDATA[
1.319 raeburn 3165: function reorderLTITools(form,item) {
1.267 raeburn 3166: var changedVal;
3167: $jstext
3168: var newpos = 'ltitools_add_pos';
3169: var maxh = 1 + $total;
3170: var current = new Array;
3171: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3172: if (item == newpos) {
3173: changedVal = newitemVal;
3174: } else {
3175: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3176: current[newitemVal] = newpos;
3177: }
3178: for (var i=0; i<ltitools.length; i++) {
3179: var elementName = 'ltitools_'+ltitools[i];
3180: if (elementName != item) {
3181: if (form.elements[elementName]) {
3182: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3183: current[currVal] = elementName;
3184: }
3185: }
3186: }
3187: var oldVal;
3188: for (var j=0; j<maxh; j++) {
3189: if (current[j] == undefined) {
3190: oldVal = j;
3191: }
3192: }
3193: if (oldVal < changedVal) {
3194: for (var k=oldVal+1; k<=changedVal ; k++) {
3195: var elementName = current[k];
3196: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3197: }
3198: } else {
3199: for (var k=changedVal; k<oldVal; k++) {
3200: var elementName = current[k];
3201: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3202: }
3203: }
3204: return;
3205: }
3206:
3207: // ]]>
3208: </script>
3209:
1.319 raeburn 3210: $togglejs
3211:
3212: ENDSCRIPT
3213: }
3214:
3215: sub ltitools_toggle_js {
3216: return <<"ENDSCRIPT";
3217: <script type="text/javascript">
3218: // <![CDATA[
3219:
3220: function toggleLTITools(form,setting,item) {
3221: var radioname = '';
3222: var divid = '';
3223: if ((setting == 'passback') || (setting == 'roster')) {
3224: radioname = 'ltitools_'+setting+'_'+item;
3225: divid = 'ltitools_'+setting+'time_'+item;
3226: var num = form.elements[radioname].length;
3227: if (num) {
3228: var setvis = '';
3229: for (var i=0; i<num; i++) {
3230: if (form.elements[radioname][i].checked) {
3231: if (form.elements[radioname][i].value == '1') {
3232: if (document.getElementById(divid)) {
3233: document.getElementById(divid).style.display = 'inline-block';
3234: }
3235: setvis = 1;
3236: }
3237: break;
3238: }
3239: }
3240: }
3241: if (!setvis) {
3242: if (document.getElementById(divid)) {
3243: document.getElementById(divid).style.display = 'none';
3244: }
3245: }
3246: }
1.324 raeburn 3247: if (setting == 'user') {
3248: divid = 'ltitools_'+setting+'_div_'+item;
3249: var checkid = 'ltitools_'+setting+'_field_'+item;
3250: if (document.getElementById(divid)) {
3251: if (document.getElementById(checkid)) {
3252: if (document.getElementById(checkid).checked) {
3253: document.getElementById(divid).style.display = 'inline-block';
3254: } else {
3255: document.getElementById(divid).style.display = 'none';
3256: }
3257: }
3258: }
3259: }
1.319 raeburn 3260: return;
3261: }
3262: // ]]>
3263: </script>
3264:
1.267 raeburn 3265: ENDSCRIPT
3266: }
3267:
1.381 raeburn 3268: sub wafproxy_javascript {
3269: my ($dom) = @_;
3270: return <<"ENDSCRIPT";
3271: <script type="text/javascript">
3272: // <![CDATA[
3273: function updateWAF() {
3274: if (document.getElementById('wafproxy_remoteip')) {
3275: var wafremote = 0;
3276: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3277: wafremote = 1;
3278: }
3279: var fields = new Array('header','trust');
3280: for (var i=0; i<fields.length; i++) {
3281: if (document.getElementById('wafproxy_'+fields[i])) {
3282: if (wafremote == 1) {
3283: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3284: }
3285: else {
3286: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3287: }
3288: }
3289: }
3290: if (document.getElementById('wafproxyranges_$dom')) {
3291: if (wafremote == 1) {
3292: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3293: } else {
3294: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3295: if (document.display.wafproxy_vpnaccess[i].checked) {
3296: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3297: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3298: }
3299: }
3300: }
3301: }
3302: }
3303: }
3304: return;
3305: }
3306:
3307: function checkWAF() {
3308: if (document.getElementById('wafproxy_remoteip')) {
3309: var wafvpn = 0;
3310: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3311: if (document.display.wafproxy_vpnaccess[i].checked) {
3312: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3313: wafvpn = 1;
3314: }
3315: break;
3316: }
3317: }
3318: var vpn = new Array('vpnint','vpnext');
3319: for (var i=0; i<vpn.length; i++) {
3320: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3321: if (wafvpn == 1) {
3322: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3323: }
3324: else {
3325: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3326: }
3327: }
3328: }
3329: if (document.getElementById('wafproxyranges_$dom')) {
3330: if (wafvpn == 1) {
3331: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3332: }
3333: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3334: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3335: }
3336: }
3337: }
3338: return;
3339: }
3340:
3341: function toggleWAF() {
3342: if (document.getElementById('wafproxy_table')) {
3343: var wafproxy = 0;
3344: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3345: if (document.display.wafproxy_${dom}[i].checked) {
3346: if (document.display.wafproxy_${dom}[i].value == 1) {
3347: wafproxy = 1;
3348: break;
3349: }
3350: }
3351: }
3352: if (wafproxy == 1) {
3353: document.getElementById('wafproxy_table').style.display='inline';
3354: }
3355: else {
3356: document.getElementById('wafproxy_table').style.display='none';
3357: }
3358: if (document.getElementById('wafproxyrow_${dom}')) {
3359: if (wafproxy == 1) {
3360: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3361: }
3362: else {
3363: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3364: }
3365: }
3366: if (document.getElementById('nowafproxyrow_$dom')) {
3367: if (wafproxy == 1) {
3368: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3369: }
3370: else {
3371: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3372: }
3373: }
3374: }
3375: return;
3376: }
3377: // ]]>
3378: </script>
3379:
3380: ENDSCRIPT
3381: }
3382:
1.372 raeburn 3383: sub proctoring_javascript {
3384: my ($settings) = @_;
3385: my (%ordered,$total,%jstext);
3386: $total = 0;
3387: if (ref($settings) eq 'HASH') {
3388: foreach my $item (keys(%{$settings})) {
3389: if (ref($settings->{$item}) eq 'HASH') {
3390: my $num = $settings->{$item}{'order'};
3391: $ordered{$num} = $item;
3392: }
3393: }
3394: $total = scalar(keys(%{$settings}));
3395: } else {
3396: %ordered = (
3397: 0 => 'proctorio',
3398: 1 => 'examity',
3399: );
3400: $total = 2;
3401: }
3402: my @jsarray = ();
3403: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3404: push(@jsarray,$ordered{$item});
3405: }
3406: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3407: return <<"ENDSCRIPT";
3408: <script type="text/javascript">
3409: // <![CDATA[
3410: function reorderProctoring(form,item) {
3411: var changedVal;
3412: $jstext
3413: var maxh = $total;
3414: var current = new Array;
3415: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3416: for (var i=0; i<proctors.length; i++) {
3417: var elementName = 'proctoring_pos_'+proctors[i];
3418: if (elementName != item) {
3419: if (form.elements[elementName]) {
3420: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3421: current[currVal] = elementName;
3422: }
3423: }
3424: }
3425: var oldVal;
3426: for (var j=0; j<maxh; j++) {
3427: if (current[j] == undefined) {
3428: oldVal = j;
3429: }
3430: }
3431: if (oldVal < changedVal) {
3432: for (var k=oldVal+1; k<=changedVal ; k++) {
3433: var elementName = current[k];
3434: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3435: }
3436: } else {
3437: for (var k=changedVal; k<oldVal; k++) {
3438: var elementName = current[k];
3439: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3440: }
3441: }
3442: return;
3443: }
3444:
3445: function toggleProctoring(form,item) {
3446: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3447: if (fieldsets.length) {
3448: var radioname = 'proctoring_available_'+item;
3449: var num = form.elements[radioname].length;
3450: if (num) {
3451: var setvis = '';
3452: for (var i=0; i<num; i++) {
3453: if (form.elements[radioname][i].checked) {
3454: if (form.elements[radioname][i].value == '1') {
3455: setvis = 1;
3456: break;
3457: }
3458: }
3459: }
3460: for (var j=0; j<fieldsets.length; j++) {
3461: if (setvis) {
3462: fieldsets[j].style.display = 'block';
3463: } else {
3464: fieldsets[j].style.display = 'none';
3465: }
3466: }
3467: }
3468: }
3469: return;
3470: }
3471:
3472: // ]]>
3473: </script>
3474:
3475: ENDSCRIPT
3476: }
3477:
3478:
1.320 raeburn 3479: sub lti_javascript {
1.405 raeburn 3480: my ($dom,$settings) = @_;
3481: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3482: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3483: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3484: return $togglejs.'
3485: <script type="text/javascript">
3486: // <![CDATA[
3487:
3488: '.$linkprot_js.'
3489:
3490: // ]]>
3491: </script>
3492: ';
1.320 raeburn 3493: }
3494: my (%ordered,$total,%jstext);
1.390 raeburn 3495: $total = scalar(keys(%{$settings}));
1.320 raeburn 3496: foreach my $item (keys(%{$settings})) {
3497: if (ref($settings->{$item}) eq 'HASH') {
3498: my $num = $settings->{$item}{'order'};
1.390 raeburn 3499: if ($num eq '') {
3500: $num = $total - 1;
3501: }
1.320 raeburn 3502: $ordered{$num} = $item;
3503: }
3504: }
3505: my @jsarray = ();
3506: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3507: push(@jsarray,$ordered{$item});
3508: }
3509: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3510: return <<"ENDSCRIPT";
3511: <script type="text/javascript">
3512: // <![CDATA[
3513: function reorderLTI(form,item) {
3514: var changedVal;
3515: $jstext
3516: var newpos = 'lti_pos_add';
3517: var maxh = 1 + $total;
3518: var current = new Array;
3519: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3520: if (item == newpos) {
3521: changedVal = newitemVal;
3522: } else {
3523: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3524: current[newitemVal] = newpos;
3525: }
3526: for (var i=0; i<lti.length; i++) {
3527: var elementName = 'lti_pos_'+lti[i];
3528: if (elementName != item) {
3529: if (form.elements[elementName]) {
3530: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3531: current[currVal] = elementName;
3532: }
3533: }
3534: }
3535: var oldVal;
3536: for (var j=0; j<maxh; j++) {
3537: if (current[j] == undefined) {
3538: oldVal = j;
3539: }
3540: }
3541: if (oldVal < changedVal) {
3542: for (var k=oldVal+1; k<=changedVal ; k++) {
3543: var elementName = current[k];
3544: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3545: }
3546: } else {
3547: for (var k=changedVal; k<oldVal; k++) {
3548: var elementName = current[k];
3549: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3550: }
3551: }
3552: return;
3553: }
1.406 raeburn 3554:
3555: $linkprot_js
3556:
1.320 raeburn 3557: // ]]>
3558: </script>
3559:
3560: $togglejs
3561:
3562: ENDSCRIPT
3563: }
3564:
3565: sub lti_toggle_js {
1.405 raeburn 3566: my ($dom) = @_;
1.325 raeburn 3567: my %lcauthparmtext = &Apache::lonlocal::texthash (
3568: localauth => 'Local auth argument',
3569: krb => 'Kerberos domain',
3570: );
1.391 raeburn 3571: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3572: &js_escape(\$crsincalert);
1.405 raeburn 3573: my %servers = &Apache::lonnet::get_servers($dom,'library');
3574: my $primary = &Apache::lonnet::domain($dom,'primary');
3575: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3576: return <<"ENDSCRIPT";
3577: <script type="text/javascript">
3578: // <![CDATA[
3579:
3580: function toggleLTI(form,setting,item) {
1.391 raeburn 3581: if ((setting == 'requser') || (setting == 'crsinc')) {
3582: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3583: var setvis = '';
3584: var radioname = 'lti_requser_'+item;
3585: var num = form.elements[radioname].length;
3586: if (num) {
3587: for (var i=0; i<num; i++) {
3588: if (form.elements[radioname][i].checked) {
3589: if (form.elements[radioname][i].value == '1') {
3590: setvis = 1;
3591: break;
3592: }
3593: }
3594: }
3595: }
3596: if (usrfieldsets.length) {
3597: for (var j=0; j<usrfieldsets.length; j++) {
3598: if (setvis) {
3599: usrfieldsets[j].style.display = 'block';
3600: } else {
3601: usrfieldsets[j].style.display = 'none';
3602: }
3603: }
3604: }
3605: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3606: if (crsfieldsets.length) {
3607: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3608: var num = form.elements[radioname].length;
3609: if (num) {
1.391 raeburn 3610: var crsvis = '';
1.345 raeburn 3611: for (var i=0; i<num; i++) {
3612: if (form.elements[radioname][i].checked) {
3613: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3614: if (setvis == '') {
3615: if (setting == 'crsinc'){
3616: alert("$crsincalert");
3617: form.elements[radioname][0].checked = true;
3618: }
3619: } else {
3620: crsvis = 1;
3621: }
3622: break;
1.345 raeburn 3623: }
3624: }
3625: }
1.391 raeburn 3626: setvis = crsvis;
3627: }
3628: for (var j=0; j<crsfieldsets.length; j++) {
3629: if (setvis) {
3630: crsfieldsets[j].style.display = 'block';
3631: } else {
3632: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3633: }
3634: }
3635: }
1.363 raeburn 3636: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3637: var radioname = '';
3638: var divid = '';
3639: if (setting == 'user') {
3640: radioname = 'lti_mapuser_'+item;
3641: divid = 'lti_userfield_'+item;
1.343 raeburn 3642: } else if (setting == 'crs') {
1.320 raeburn 3643: radioname = 'lti_mapcrs_'+item;
3644: divid = 'lti_crsfield_'+item;
1.363 raeburn 3645: } else if (setting == 'callback') {
3646: radioname = 'lti_callback_'+item;
3647: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3648: } else {
1.351 raeburn 3649: radioname = 'lti_passback_'+item;
1.337 raeburn 3650: divid = 'lti_passback_'+item;
1.320 raeburn 3651: }
3652: var num = form.elements[radioname].length;
3653: if (num) {
3654: var setvis = '';
3655: for (var i=0; i<num; i++) {
3656: if (form.elements[radioname][i].checked) {
1.363 raeburn 3657: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3658: if (form.elements[radioname][i].value == '1') {
3659: if (document.getElementById(divid)) {
3660: document.getElementById(divid).style.display = 'inline-block';
3661: }
3662: setvis = 1;
3663: break;
3664: }
3665: } else {
3666: if (form.elements[radioname][i].value == 'other') {
3667: if (document.getElementById(divid)) {
3668: document.getElementById(divid).style.display = 'inline-block';
3669: }
3670: setvis = 1;
3671: break;
1.320 raeburn 3672: }
3673: }
1.425 raeburn 3674: }
1.320 raeburn 3675: }
3676: if (!setvis) {
3677: if (document.getElementById(divid)) {
3678: document.getElementById(divid).style.display = 'none';
3679: }
3680: }
3681: }
3682: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3683: var numsec = form.elements['lti_crssec_'+item].length;
3684: if (numsec) {
3685: var setvis = '';
3686: for (var i=0; i<numsec; i++) {
3687: if (form.elements['lti_crssec_'+item][i].checked) {
3688: if (form.elements['lti_crssec_'+item][i].value == '1') {
3689: if (document.getElementById('lti_crssecfield_'+item)) {
3690: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3691: setvis = 1;
3692: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3693: if (numsrcsec) {
3694: var setsrcvis = '';
3695: for (var j=0; j<numsrcsec; j++) {
3696: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3697: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3698: if (document.getElementById('lti_secsrcfield_'+item)) {
3699: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3700: setsrcvis = 1;
3701: }
3702: }
3703: }
3704: }
3705: if (!setsrcvis) {
3706: if (document.getElementById('lti_secsrcfield_'+item)) {
3707: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3708: }
3709: }
3710: }
3711: }
3712: }
3713: }
3714: }
3715: if (!setvis) {
3716: if (document.getElementById('lti_crssecfield_'+item)) {
3717: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3718: }
3719: if (document.getElementById('lti_secsrcfield_'+item)) {
3720: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3721: }
3722: }
3723: }
1.325 raeburn 3724: } else if (setting == 'lcauth') {
3725: var numauth = form.elements['lti_lcauth_'+item].length;
3726: if (numauth) {
3727: for (var i=0; i<numauth; i++) {
3728: if (form.elements['lti_lcauth_'+item][i].checked) {
3729: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3730: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3731: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3732: } else {
3733: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3734: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3735: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3736: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3737: } else {
3738: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3739: }
3740: }
3741: }
3742: }
3743: }
3744: }
3745: }
1.326 raeburn 3746: } else if (setting == 'lcmenu') {
3747: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3748: var divid = 'lti_menufield_'+item;
3749: var setvis = '';
3750: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3751: var radioname = menus[i];
1.326 raeburn 3752: var num = form.elements[radioname].length;
3753: if (num) {
3754: for (var j=0; j<num; j++) {
3755: if (form.elements[radioname][j].checked) {
3756: if (form.elements[radioname][j].value == '1') {
3757: if (document.getElementById(divid)) {
3758: document.getElementById(divid).style.display = 'inline-block';
3759: }
3760: setvis = 1;
3761: break;
3762: }
3763: }
3764: }
3765: }
3766: if (setvis == 1) {
3767: break;
3768: }
3769: }
3770: if (!setvis) {
3771: if (document.getElementById(divid)) {
3772: document.getElementById(divid).style.display = 'none';
3773: }
3774: }
1.320 raeburn 3775: }
3776: return;
3777: }
1.405 raeburn 3778:
1.320 raeburn 3779: // ]]>
3780: </script>
3781:
3782: ENDSCRIPT
3783: }
3784:
1.385 raeburn 3785: sub autoupdate_javascript {
3786: return <<"ENDSCRIPT";
3787: <script type="text/javascript">
3788: // <![CDATA[
3789: function toggleLastActiveDays(form) {
3790: var radioname = 'lastactive';
3791: var divid = 'lastactive_div';
3792: var num = form.elements[radioname].length;
3793: if (num) {
3794: var setvis = '';
3795: for (var i=0; i<num; i++) {
3796: if (form.elements[radioname][i].checked) {
3797: if (form.elements[radioname][i].value == '1') {
3798: if (document.getElementById(divid)) {
3799: document.getElementById(divid).style.display = 'inline-block';
3800: }
3801: setvis = 1;
3802: }
3803: break;
3804: }
3805: }
3806: if (!setvis) {
3807: if (document.getElementById(divid)) {
3808: document.getElementById(divid).style.display = 'none';
3809: }
3810: }
3811: }
3812: return;
3813: }
3814: // ]]>
3815: </script>
3816:
3817: ENDSCRIPT
3818: }
3819:
1.399 raeburn 3820: sub autoenroll_javascript {
3821: return <<"ENDSCRIPT";
3822: <script type="text/javascript">
3823: // <![CDATA[
3824: function toggleFailsafe(form) {
3825: var radioname = 'autoenroll_failsafe';
3826: var divid = 'autoenroll_failsafe_div';
3827: var num = form.elements[radioname].length;
3828: if (num) {
3829: var setvis = '';
3830: for (var i=0; i<num; i++) {
3831: if (form.elements[radioname][i].checked) {
3832: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3833: if (document.getElementById(divid)) {
3834: document.getElementById(divid).style.display = 'inline-block';
3835: }
3836: setvis = 1;
3837: }
3838: break;
3839: }
3840: }
3841: if (!setvis) {
3842: if (document.getElementById(divid)) {
3843: document.getElementById(divid).style.display = 'none';
3844: }
3845: }
3846: }
3847: return;
3848: }
3849: // ]]>
3850: </script>
3851:
3852: ENDSCRIPT
3853: }
3854:
1.386 raeburn 3855: sub saml_javascript {
3856: return <<"ENDSCRIPT";
3857: <script type="text/javascript">
3858: // <![CDATA[
1.425 raeburn 3859: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3860: var radioname = 'saml_'+hostid;
3861: var tablecellon = 'samloptionson_'+hostid;
3862: var tablecelloff = 'samloptionsoff_'+hostid;
3863: var num = form.elements[radioname].length;
3864: if (num) {
1.425 raeburn 3865: var setvis = '';
1.386 raeburn 3866: for (var i=0; i<num; i++) {
3867: if (form.elements[radioname][i].checked) {
1.425 raeburn 3868: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3869: if (document.getElementById(tablecellon)) {
3870: document.getElementById(tablecellon).style.display='';
3871: }
3872: if (document.getElementById(tablecelloff)) {
3873: document.getElementById(tablecelloff).style.display='none';
3874: }
3875: setvis = 1;
3876: }
3877: break;
3878: }
3879: }
3880: if (!setvis) {
3881: if (document.getElementById(tablecellon)) {
3882: document.getElementById(tablecellon).style.display='none';
3883: }
3884: if (document.getElementById(tablecelloff)) {
3885: document.getElementById(tablecelloff).style.display='';
3886: }
3887: }
3888: }
3889: return;
3890: }
3891: // ]]>
3892: </script>
3893:
3894: ENDSCRIPT
3895: }
3896:
1.394 raeburn 3897: sub ipaccess_javascript {
3898: my ($settings) = @_;
3899: my (%ordered,$total,%jstext);
3900: $total = 0;
3901: if (ref($settings) eq 'HASH') {
3902: foreach my $item (keys(%{$settings})) {
3903: if (ref($settings->{$item}) eq 'HASH') {
3904: my $num = $settings->{$item}{'order'};
3905: $ordered{$num} = $item;
3906: }
3907: }
3908: $total = scalar(keys(%{$settings}));
3909: }
3910: my @jsarray = ();
3911: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3912: push(@jsarray,$ordered{$item});
3913: }
3914: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3915: return <<"ENDSCRIPT";
3916: <script type="text/javascript">
3917: // <![CDATA[
3918: function reorderIPaccess(form,item) {
3919: var changedVal;
3920: $jstext
3921: var newpos = 'ipaccess_pos_add';
3922: var maxh = 1 + $total;
3923: var current = new Array;
3924: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3925: if (item == newpos) {
3926: changedVal = newitemVal;
3927: } else {
3928: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3929: current[newitemVal] = newpos;
3930: }
3931: for (var i=0; i<ipaccess.length; i++) {
3932: var elementName = 'ipaccess_pos_'+ipaccess[i];
3933: if (elementName != item) {
3934: if (form.elements[elementName]) {
3935: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3936: current[currVal] = elementName;
3937: }
3938: }
3939: }
3940: var oldVal;
3941: for (var j=0; j<maxh; j++) {
3942: if (current[j] == undefined) {
3943: oldVal = j;
3944: }
3945: }
3946: if (oldVal < changedVal) {
3947: for (var k=oldVal+1; k<=changedVal ; k++) {
3948: var elementName = current[k];
3949: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3950: }
3951: } else {
3952: for (var k=changedVal; k<oldVal; k++) {
3953: var elementName = current[k];
3954: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3955: }
3956: }
3957: return;
3958: }
3959: // ]]>
3960: </script>
3961:
3962: ENDSCRIPT
3963: }
3964:
1.429 raeburn 3965: sub authordefaults_javascript {
3966: my %alert = &Apache::lonlocal::texthash (
3967: reqd => 'Warning: at least one editor needs to be available.',
3968: rest => 'Unchecking this editor disallowed while others unchecked.',
3969: );
3970: &js_escape(\%alert);
3971: return <<"ENDSCRIPT";
3972: <script type="text/javascript">
3973: // <![CDATA[
3974:
3975: function checkEditors(form,checkbox,current) {
3976: if (form.elements[checkbox].length != undefined) {
3977: var count = 0;
3978: for (var i=0; i<form.elements[checkbox].length; i++) {
3979: if (form.elements[checkbox][i].checked) {
3980: count ++;
3981: }
3982: }
3983: if (count == 0) {
3984: if (current.type =='radio') {
3985: current.checked = true;
3986: alert('$alert{reqd}\\n$alert{rest}');
3987: }
3988: }
3989: }
3990: return;
3991: }
3992: // ]]>
3993: </script>
3994:
3995: ENDSCRIPT
3996: }
3997:
1.3 raeburn 3998: sub print_autoenroll {
1.30 raeburn 3999: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 4000: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 4001: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
4002: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
4003: $failsafesty = 'none';
4004: %failsafechecked = (
4005: off => ' checked="checked"',
4006: );
1.3 raeburn 4007: if (ref($settings) eq 'HASH') {
4008: if (exists($settings->{'run'})) {
4009: if ($settings->{'run'} eq '0') {
4010: $runoff = ' checked="checked" ';
4011: $runon = ' ';
4012: } else {
4013: $runon = ' checked="checked" ';
4014: $runoff = ' ';
4015: }
4016: } else {
4017: if ($autorun) {
4018: $runon = ' checked="checked" ';
4019: $runoff = ' ';
4020: } else {
4021: $runoff = ' checked="checked" ';
4022: $runon = ' ';
4023: }
4024: }
1.129 raeburn 4025: if (exists($settings->{'co-owners'})) {
4026: if ($settings->{'co-owners'} eq '0') {
4027: $coownersoff = ' checked="checked" ';
4028: $coownerson = ' ';
4029: } else {
4030: $coownerson = ' checked="checked" ';
4031: $coownersoff = ' ';
4032: }
4033: } else {
4034: $coownersoff = ' checked="checked" ';
4035: $coownerson = ' ';
4036: }
1.3 raeburn 4037: if (exists($settings->{'sender_domain'})) {
4038: $defdom = $settings->{'sender_domain'};
4039: }
1.399 raeburn 4040: if (exists($settings->{'failsafe'})) {
4041: $failsafe = $settings->{'failsafe'};
4042: if ($failsafe eq 'zero') {
1.400 raeburn 4043: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4044: $failsafechecked{'off'} = '';
4045: $failsafesty = 'inline-block';
4046: } elsif ($failsafe eq 'any') {
4047: $failsafechecked{'any'} = ' checked="checked"';
4048: $failsafechecked{'off'} = '';
4049: }
4050: $autofailsafe = $settings->{'autofailsafe'};
4051: } elsif (exists($settings->{'autofailsafe'})) {
4052: $autofailsafe = $settings->{'autofailsafe'};
4053: if ($autofailsafe ne '') {
4054: $failsafechecked{'zero'} = ' checked="checked"';
4055: $failsafe = 'zero';
1.400 raeburn 4056: $failsafechecked{'off'} = '';
1.399 raeburn 4057: }
1.274 raeburn 4058: }
1.14 raeburn 4059: } else {
4060: if ($autorun) {
4061: $runon = ' checked="checked" ';
4062: $runoff = ' ';
4063: } else {
4064: $runoff = ' checked="checked" ';
4065: $runon = ' ';
4066: }
1.3 raeburn 4067: }
4068: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4069: my $notif_sender;
4070: if (ref($settings) eq 'HASH') {
4071: $notif_sender = $settings->{'sender_uname'};
4072: }
1.3 raeburn 4073: my $datatable='<tr class="LC_odd_row">'.
4074: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4075: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4076: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4077: $runon.' value="1" />'.&mt('Yes').'</label> '.
4078: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4079: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4080: '</tr><tr>'.
4081: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4082: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4083: &mt('username').': '.
4084: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4085: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4086: ': '.$domform.'</span></td></tr>'.
4087: '<tr class="LC_odd_row">'.
4088: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4089: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4090: '<input type="radio" name="autoassign_coowners"'.
4091: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4092: '<label><input type="radio" name="autoassign_coowners"'.
4093: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4094: '</tr><tr>'.
4095: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4096: '<td class="LC_left_item"><span class="LC_nobreak">'.
4097: '<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> '.
4098: '<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 />'.
4099: '<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 4100: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4101: '<span class="LC_nobreak">'.
4102: &mt('Threshold for number of students in section to drop: [_1]',
4103: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4104: '</span></div></td></tr>';
1.274 raeburn 4105: $$rowtotal += 4;
1.3 raeburn 4106: return $datatable;
4107: }
4108:
4109: sub print_autoupdate {
1.30 raeburn 4110: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4111: my ($enable,$datatable);
1.3 raeburn 4112: if ($position eq 'top') {
1.385 raeburn 4113: my %choices = &Apache::lonlocal::texthash (
4114: run => 'Auto-update active?',
4115: classlists => 'Update information in classlists?',
4116: unexpired => 'Skip updates for users without active or future roles?',
4117: lastactive => 'Skip updates for inactive users?',
4118: );
4119: my $itemcount = 0;
1.3 raeburn 4120: my $updateon = ' ';
4121: my $updateoff = ' checked="checked" ';
4122: if (ref($settings) eq 'HASH') {
4123: if ($settings->{'run'} eq '1') {
4124: $updateon = $updateoff;
4125: $updateoff = ' ';
4126: }
4127: }
1.385 raeburn 4128: $enable = '<tr class="LC_odd_row">'.
4129: '<td>'.$choices{'run'}.'</td>'.
4130: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4131: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4132: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4133: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4134: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4135: '</tr>';
1.385 raeburn 4136: my @toggles = ('classlists','unexpired');
4137: my %defaultchecked = ('classlists' => 'off',
4138: 'unexpired' => 'off'
4139: );
4140: $$rowtotal ++;
4141: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4142: \%choices,$itemcount,'','','left','no');
4143: $datatable = $enable.$datatable;
4144: $$rowtotal += $itemcount;
4145: my $lastactiveon = ' ';
4146: my $lastactiveoff = ' checked="checked" ';
4147: my $lastactivestyle = 'none';
4148: my $lastactivedays;
4149: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4150: if (ref($settings) eq 'HASH') {
4151: if ($settings->{'lastactive'} =~ /^\d+$/) {
4152: $lastactiveon = $lastactiveoff;
4153: $lastactiveoff = ' ';
4154: $lastactivestyle = 'inline-block';
4155: $lastactivedays = $settings->{'lastactive'};
4156: }
4157: }
4158: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4159: $datatable .= '<tr'.$css_class.'>'.
4160: '<td>'.$choices{'lastactive'}.'</td>'.
4161: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4162: '<input type="radio" name="lastactive"'.
4163: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4164: ' <label>'.
4165: '<input type="radio" name="lastactive"'.
4166: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4167: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4168: ': '.&mt('inactive = no activity in last [_1] days',
4169: '<input type="text" size="5" name="lastactivedays" value="'.
4170: $lastactivedays.'" />').
4171: '</span></td>'.
4172: '</tr>';
4173: $$rowtotal ++;
1.131 raeburn 4174: } elsif ($position eq 'middle') {
4175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4176: my $numinrow = 3;
4177: my $locknamesettings;
4178: $datatable .= &insttypes_row($settings,$types,$usertypes,
4179: $dom,$numinrow,$othertitle,
1.305 raeburn 4180: 'lockablenames',$rowtotal);
1.131 raeburn 4181: $$rowtotal ++;
1.3 raeburn 4182: } else {
1.44 raeburn 4183: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4184: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4185: 'permanentemail','id');
1.33 raeburn 4186: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4187: my $numrows = 0;
1.26 raeburn 4188: if (ref($types) eq 'ARRAY') {
4189: if (@{$types} > 0) {
4190: $datatable =
4191: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4192: \@fields,$types,\$numrows);
1.30 raeburn 4193: $$rowtotal += @{$types};
1.26 raeburn 4194: }
1.3 raeburn 4195: }
4196: $datatable .=
4197: &usertype_update_row($settings,{'default' => $othertitle},
4198: \%fieldtitles,\@fields,['default'],
4199: \$numrows);
1.30 raeburn 4200: $$rowtotal ++;
1.3 raeburn 4201: }
4202: return $datatable;
4203: }
4204:
1.125 raeburn 4205: sub print_autocreate {
4206: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4207: my (%createon,%createoff,%currhash);
1.125 raeburn 4208: my @types = ('xml','req');
4209: if (ref($settings) eq 'HASH') {
4210: foreach my $item (@types) {
4211: $createoff{$item} = ' checked="checked" ';
4212: $createon{$item} = ' ';
4213: if (exists($settings->{$item})) {
4214: if ($settings->{$item}) {
4215: $createon{$item} = ' checked="checked" ';
4216: $createoff{$item} = ' ';
4217: }
4218: }
4219: }
1.210 raeburn 4220: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4221: $currhash{$settings->{'xmldc'}} = 1;
4222: }
1.125 raeburn 4223: } else {
4224: foreach my $item (@types) {
4225: $createoff{$item} = ' checked="checked" ';
4226: $createon{$item} = ' ';
4227: }
4228: }
4229: $$rowtotal += 2;
1.191 raeburn 4230: my $numinrow = 2;
1.125 raeburn 4231: my $datatable='<tr class="LC_odd_row">'.
4232: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4234: '<input type="radio" name="autocreate_xml"'.
4235: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4236: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4237: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4238: '</td></tr><tr>'.
4239: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4240: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4241: '<input type="radio" name="autocreate_req"'.
4242: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4243: '<label><input type="radio" name="autocreate_req"'.
4244: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4245: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4246: 'autocreate_xmldc',%currhash);
1.247 raeburn 4247: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4248: if ($numdc > 1) {
1.247 raeburn 4249: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4250: '</td><td class="LC_left_item">';
1.125 raeburn 4251: } else {
1.247 raeburn 4252: $datatable .= &mt('Course creation processed as:').
4253: '</td><td class="LC_right_item">';
1.125 raeburn 4254: }
1.247 raeburn 4255: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4256: $$rowtotal += $rows;
1.125 raeburn 4257: return $datatable;
4258: }
4259:
1.23 raeburn 4260: sub print_directorysrch {
1.277 raeburn 4261: my ($position,$dom,$settings,$rowtotal) = @_;
4262: my $datatable;
4263: if ($position eq 'top') {
4264: my $instsrchon = ' ';
4265: my $instsrchoff = ' checked="checked" ';
4266: my ($exacton,$containson,$beginson);
4267: my $instlocalon = ' ';
4268: my $instlocaloff = ' checked="checked" ';
4269: if (ref($settings) eq 'HASH') {
4270: if ($settings->{'available'} eq '1') {
4271: $instsrchon = $instsrchoff;
4272: $instsrchoff = ' ';
4273: }
4274: if ($settings->{'localonly'} eq '1') {
4275: $instlocalon = $instlocaloff;
4276: $instlocaloff = ' ';
4277: }
4278: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4279: foreach my $type (@{$settings->{'searchtypes'}}) {
4280: if ($type eq 'exact') {
4281: $exacton = ' checked="checked" ';
4282: } elsif ($type eq 'contains') {
4283: $containson = ' checked="checked" ';
4284: } elsif ($type eq 'begins') {
4285: $beginson = ' checked="checked" ';
4286: }
4287: }
4288: } else {
4289: if ($settings->{'searchtypes'} eq 'exact') {
4290: $exacton = ' checked="checked" ';
4291: } elsif ($settings->{'searchtypes'} eq 'contains') {
4292: $containson = ' checked="checked" ';
4293: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4294: $exacton = ' checked="checked" ';
4295: $containson = ' checked="checked" ';
4296: }
4297: }
1.277 raeburn 4298: }
4299: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4300: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4301:
4302: my $numinrow = 4;
4303: my $cansrchrow = 0;
4304: $datatable='<tr class="LC_odd_row">'.
4305: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4306: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4307: '<input type="radio" name="dirsrch_available"'.
4308: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4309: '<label><input type="radio" name="dirsrch_available"'.
4310: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4311: '</tr><tr>'.
4312: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4313: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4314: '<input type="radio" name="dirsrch_instlocalonly"'.
4315: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4316: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4317: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4318: '</tr>';
4319: $$rowtotal += 2;
4320: if (ref($usertypes) eq 'HASH') {
4321: if (keys(%{$usertypes}) > 0) {
4322: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4323: $numinrow,$othertitle,'cansearch',
4324: $rowtotal);
1.277 raeburn 4325: $cansrchrow = 1;
1.25 raeburn 4326: }
1.23 raeburn 4327: }
1.277 raeburn 4328: if ($cansrchrow) {
4329: $$rowtotal ++;
4330: $datatable .= '<tr>';
4331: } else {
4332: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4333: }
1.277 raeburn 4334: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4335: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4336: foreach my $title (@{$titleorder}) {
4337: if (defined($searchtitles->{$title})) {
4338: my $check = ' ';
4339: if (ref($settings) eq 'HASH') {
4340: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4341: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4342: $check = ' checked="checked" ';
4343: }
1.39 raeburn 4344: }
1.25 raeburn 4345: }
1.277 raeburn 4346: $datatable .= '<td class="LC_left_item">'.
4347: '<span class="LC_nobreak"><label>'.
4348: '<input type="checkbox" name="searchby" '.
4349: 'value="'.$title.'"'.$check.'/>'.
4350: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4351: }
4352: }
1.277 raeburn 4353: $datatable .= '</tr></table></td></tr>';
4354: $$rowtotal ++;
4355: if ($cansrchrow) {
4356: $datatable .= '<tr class="LC_odd_row">';
4357: } else {
4358: $datatable .= '<tr>';
4359: }
4360: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4361: '<td class="LC_left_item" colspan="2">'.
4362: '<span class="LC_nobreak"><label>'.
4363: '<input type="checkbox" name="searchtypes" '.
4364: $exacton.' value="exact" />'.&mt('Exact match').
4365: '</label> '.
4366: '<label><input type="checkbox" name="searchtypes" '.
4367: $beginson.' value="begins" />'.&mt('Begins with').
4368: '</label> '.
4369: '<label><input type="checkbox" name="searchtypes" '.
4370: $containson.' value="contains" />'.&mt('Contains').
4371: '</label></span></td></tr>';
4372: $$rowtotal ++;
1.26 raeburn 4373: } else {
1.277 raeburn 4374: my $domsrchon = ' checked="checked" ';
4375: my $domsrchoff = ' ';
4376: my $domlocalon = ' ';
4377: my $domlocaloff = ' checked="checked" ';
4378: if (ref($settings) eq 'HASH') {
4379: if ($settings->{'lclocalonly'} eq '1') {
4380: $domlocalon = $domlocaloff;
4381: $domlocaloff = ' ';
4382: }
4383: if ($settings->{'lcavailable'} eq '0') {
4384: $domsrchoff = $domsrchon;
4385: $domsrchon = ' ';
4386: }
4387: }
4388: $datatable='<tr class="LC_odd_row">'.
4389: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4390: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4391: '<input type="radio" name="dirsrch_domavailable"'.
4392: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4393: '<label><input type="radio" name="dirsrch_domavailable"'.
4394: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4395: '</tr><tr>'.
4396: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4397: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4398: '<input type="radio" name="dirsrch_domlocalonly"'.
4399: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4400: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4401: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4402: '</tr>';
4403: $$rowtotal += 2;
1.26 raeburn 4404: }
1.25 raeburn 4405: return $datatable;
4406: }
4407:
1.28 raeburn 4408: sub print_contacts {
1.286 raeburn 4409: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4410: my $datatable;
4411: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4412: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4413: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4414: if ($position eq 'top') {
4415: if (ref($settings) eq 'HASH') {
4416: foreach my $item (@contacts) {
4417: if (exists($settings->{$item})) {
4418: $to{$item} = $settings->{$item};
4419: }
4420: }
4421: }
4422: } elsif ($position eq 'middle') {
4423: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4424: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4425: foreach my $type (@mailings) {
4426: $otheremails{$type} = '';
4427: }
1.340 raeburn 4428: } elsif ($position eq 'lower') {
4429: if (ref($settings) eq 'HASH') {
4430: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4431: %lonstatus = %{$settings->{'lonstatus'}};
4432: }
4433: }
1.286 raeburn 4434: } else {
4435: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4436: foreach my $type (@mailings) {
4437: $otheremails{$type} = '';
4438: }
1.286 raeburn 4439: $bccemails{'helpdeskmail'} = '';
4440: $bccemails{'otherdomsmail'} = '';
4441: $includestr{'helpdeskmail'} = '';
4442: $includestr{'otherdomsmail'} = '';
4443: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4444: }
1.28 raeburn 4445: if (ref($settings) eq 'HASH') {
1.340 raeburn 4446: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4447: foreach my $type (@mailings) {
4448: if (exists($settings->{$type})) {
4449: if (ref($settings->{$type}) eq 'HASH') {
4450: foreach my $item (@contacts) {
4451: if ($settings->{$type}{$item}) {
4452: $checked{$type}{$item} = ' checked="checked" ';
4453: }
4454: }
4455: $otheremails{$type} = $settings->{$type}{'others'};
4456: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4457: $bccemails{$type} = $settings->{$type}{'bcc'};
4458: if ($settings->{$type}{'include'} ne '') {
4459: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4460: $includestr{$type} = &unescape($includestr{$type});
4461: }
4462: }
4463: }
4464: } elsif ($type eq 'lonstatusmail') {
4465: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4466: }
1.28 raeburn 4467: }
4468: }
1.286 raeburn 4469: if ($position eq 'bottom') {
4470: foreach my $type (@mailings) {
4471: $bccemails{$type} = $settings->{$type}{'bcc'};
4472: if ($settings->{$type}{'include'} ne '') {
4473: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4474: $includestr{$type} = &unescape($includestr{$type});
4475: }
4476: }
4477: if (ref($settings->{'helpform'}) eq 'HASH') {
4478: if (ref($fields) eq 'ARRAY') {
4479: foreach my $field (@{$fields}) {
4480: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4481: }
1.286 raeburn 4482: }
4483: if (exists($settings->{'helpform'}{'maxsize'})) {
4484: $maxsize = $settings->{'helpform'}{'maxsize'};
4485: } else {
1.289 raeburn 4486: $maxsize = '1.0';
1.286 raeburn 4487: }
4488: } else {
4489: if (ref($fields) eq 'ARRAY') {
4490: foreach my $field (@{$fields}) {
4491: $currfield{$field} = 'yes';
1.134 raeburn 4492: }
1.28 raeburn 4493: }
1.286 raeburn 4494: $maxsize = '1.0';
1.28 raeburn 4495: }
4496: }
4497: } else {
1.286 raeburn 4498: if ($position eq 'top') {
4499: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4500: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4501: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4502: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4503: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4504: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4505: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4506: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4507: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4508: } elsif ($position eq 'bottom') {
4509: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4510: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4511: if (ref($fields) eq 'ARRAY') {
4512: foreach my $field (@{$fields}) {
4513: $currfield{$field} = 'yes';
4514: }
4515: }
4516: $maxsize = '1.0';
4517: }
1.28 raeburn 4518: }
4519: my ($titles,$short_titles) = &contact_titles();
4520: my $rownum = 0;
4521: my $css_class;
1.286 raeburn 4522: if ($position eq 'top') {
4523: foreach my $item (@contacts) {
4524: $css_class = $rownum%2?' class="LC_odd_row"':'';
4525: $datatable .= '<tr'.$css_class.'>'.
4526: '<td><span class="LC_nobreak">'.$titles->{$item}.
4527: '</span></td><td class="LC_right_item">'.
4528: '<input type="text" name="'.$item.'" value="'.
4529: $to{$item}.'" /></td></tr>';
4530: $rownum ++;
4531: }
1.315 raeburn 4532: } elsif ($position eq 'bottom') {
4533: $css_class = $rownum%2?' class="LC_odd_row"':'';
4534: $datatable .= '<tr'.$css_class.'>'.
4535: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4536: &mt('(e-mail, subject, and description always shown)').
4537: '</td><td class="LC_left_item">';
4538: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4539: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4540: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4541: foreach my $field (@{$fields}) {
4542: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4543: if (($field eq 'screenshot') || ($field eq 'cc')) {
4544: $datatable .= ' '.&mt('(logged-in users)');
4545: }
4546: $datatable .='</td><td>';
4547: my $clickaction;
4548: if ($field eq 'screenshot') {
4549: $clickaction = ' onclick="screenshotSize(this);"';
4550: }
4551: if (ref($possoptions->{$field}) eq 'ARRAY') {
4552: foreach my $option (@{$possoptions->{$field}}) {
4553: my $checked;
4554: if ($currfield{$field} eq $option) {
4555: $checked = ' checked="checked"';
4556: }
4557: $datatable .= '<span class="LC_nobreak"><label>'.
4558: '<input type="radio" name="helpform_'.$field.'" '.
4559: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4560: '</label></span>'.(' 'x2);
4561: }
4562: }
4563: if ($field eq 'screenshot') {
4564: my $display;
4565: if ($currfield{$field} eq 'no') {
4566: $display = ' style="display:none"';
4567: }
1.334 raeburn 4568: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4569: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4570: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4571: }
4572: $datatable .= '</td></tr>';
4573: }
4574: $datatable .= '</table>';
4575: }
4576: $datatable .= '</td></tr>'."\n";
4577: $rownum ++;
4578: }
1.340 raeburn 4579: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4580: foreach my $type (@mailings) {
4581: $css_class = $rownum%2?' class="LC_odd_row"':'';
4582: $datatable .= '<tr'.$css_class.'>'.
4583: '<td><span class="LC_nobreak">'.
4584: $titles->{$type}.': </span></td>'.
4585: '<td class="LC_left_item">';
4586: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4587: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4588: }
4589: $datatable .= '<span class="LC_nobreak">';
4590: foreach my $item (@contacts) {
4591: $datatable .= '<label>'.
4592: '<input type="checkbox" name="'.$type.'"'.
4593: $checked{$type}{$item}.
4594: ' value="'.$item.'" />'.$short_titles->{$item}.
4595: '</label> ';
4596: }
4597: $datatable .= '</span><br />'.&mt('Others').': '.
4598: '<input type="text" name="'.$type.'_others" '.
4599: 'value="'.$otheremails{$type}.'" />';
4600: my %locchecked;
4601: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4602: foreach my $loc ('s','b') {
4603: if ($includeloc{$type} eq $loc) {
4604: $locchecked{$loc} = ' checked="checked"';
4605: last;
4606: }
4607: }
4608: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4609: '<input type="text" name="'.$type.'_bcc" '.
4610: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4611: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4612: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4613: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4614: '<span class="LC_nobreak">'.&mt('Location:').' '.
4615: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4616: (' 'x2).
4617: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4618: '</span></fieldset>';
4619: }
4620: $datatable .= '</td></tr>'."\n";
4621: $rownum ++;
4622: }
1.28 raeburn 4623: }
1.286 raeburn 4624: if ($position eq 'middle') {
4625: my %choices;
1.340 raeburn 4626: my $corelink = &core_link_msu();
4627: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4628: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4629: $corelink);
4630: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4631: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4632: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4633: 'reportupdates' => 'on',
4634: 'reportstatus' => 'on');
1.286 raeburn 4635: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4636: \%choices,$rownum);
4637: $datatable .= $reports;
1.340 raeburn 4638: } elsif ($position eq 'lower') {
1.378 raeburn 4639: my (%current,%excluded,%weights);
1.340 raeburn 4640: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4641: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4642: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4643: } else {
1.378 raeburn 4644: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4645: }
4646: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4647: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4648: } else {
1.378 raeburn 4649: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4650: }
4651: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4652: foreach my $type ('E','W','N','U') {
1.340 raeburn 4653: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4654: $weights{$type} = $lonstatus{'weights'}{$type};
4655: } else {
4656: $weights{$type} = $defaults->{$type};
4657: }
4658: }
4659: } else {
1.341 raeburn 4660: foreach my $type ('E','W','N','U') {
1.340 raeburn 4661: $weights{$type} = $defaults->{$type};
4662: }
4663: }
4664: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4665: if (@{$lonstatus{'excluded'}} > 0) {
4666: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4667: }
4668: }
1.425 raeburn 4669: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4670: $css_class = $rownum%2?' class="LC_odd_row"':'';
4671: $datatable .= '<tr'.$css_class.'>'.
4672: '<td class="LC_left_item"><span class="LC_nobreak">'.
4673: $titles->{$item}.
4674: '</span></td><td class="LC_left_item">'.
4675: '<input type="text" name="'.$item.'" value="'.
4676: $current{$item}.'" size="5" /></td></tr>';
4677: $rownum ++;
4678: }
1.340 raeburn 4679: $css_class = $rownum%2?' class="LC_odd_row"':'';
4680: $datatable .= '<tr'.$css_class.'>'.
4681: '<td class="LC_left_item">'.
4682: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4683: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4684: foreach my $type ('E','W','N','U') {
1.340 raeburn 4685: $datatable .= '<td>'.$names->{$type}.'<br />'.
4686: '<input type="text" name="errorweights_'.$type.'" value="'.
4687: $weights{$type}.'" size="5" /></td>';
4688: }
4689: $datatable .= '</tr></table></tr>';
4690: $rownum ++;
4691: $css_class = $rownum%2?' class="LC_odd_row"':'';
4692: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4693: $titles->{'errorexcluded'}.'</td>'.
4694: '<td class="LC_left_item"><table>';
4695: my $numinrow = 4;
4696: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4697: for (my $i=0; $i<@ids; $i++) {
4698: my $rem = $i%($numinrow);
4699: if ($rem == 0) {
4700: if ($i > 0) {
4701: $datatable .= '</tr>';
4702: }
4703: $datatable .= '<tr>';
4704: }
4705: my $check;
4706: if ($excluded{$ids[$i]}) {
4707: $check = ' checked="checked" ';
4708: }
4709: $datatable .= '<td class="LC_left_item">'.
4710: '<span class="LC_nobreak"><label>'.
4711: '<input type="checkbox" name="errorexcluded" '.
4712: 'value="'.$ids[$i].'"'.$check.' />'.
4713: $ids[$i].'</label></span></td>';
4714: }
4715: my $colsleft = $numinrow - @ids%($numinrow);
4716: if ($colsleft > 1 ) {
4717: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4718: ' </td>';
4719: } elsif ($colsleft == 1) {
4720: $datatable .= '<td class="LC_left_item"> </td>';
4721: }
4722: $datatable .= '</tr></table></td></tr>';
4723: $rownum ++;
1.286 raeburn 4724: } elsif ($position eq 'bottom') {
1.315 raeburn 4725: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4726: my (@posstypes,%usertypeshash);
4727: if (ref($types) eq 'ARRAY') {
4728: @posstypes = @{$types};
4729: }
4730: if (@posstypes) {
4731: if (ref($usertypes) eq 'HASH') {
4732: %usertypeshash = %{$usertypes};
4733: }
4734: my @overridden;
4735: my $numinrow = 4;
4736: if (ref($settings) eq 'HASH') {
4737: if (ref($settings->{'overrides'}) eq 'HASH') {
4738: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4739: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4740: push(@overridden,$key);
4741: foreach my $item (@contacts) {
4742: if ($settings->{'overrides'}{$key}{$item}) {
4743: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4744: }
4745: }
4746: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4747: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4748: $includeloc{'override_'.$key} = '';
4749: $includestr{'override_'.$key} = '';
4750: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4751: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4752: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4753: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4754: }
1.286 raeburn 4755: }
4756: }
4757: }
1.315 raeburn 4758: }
4759: my $customclass = 'LC_helpdesk_override';
4760: my $optionsprefix = 'LC_options_helpdesk_';
4761:
4762: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4763: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4764: $numinrow,$othertitle,'overrides',
4765: \$rownum,$onclicktypes,$customclass);
4766: $rownum ++;
4767: $usertypeshash{'default'} = $othertitle;
4768: foreach my $status (@posstypes) {
4769: my $css_class;
4770: if ($rownum%2) {
4771: $css_class = 'LC_odd_row ';
4772: }
4773: $css_class .= $customclass;
4774: my $rowid = $optionsprefix.$status;
4775: my $hidden = 1;
4776: my $currstyle = 'display:none';
4777: if (grep(/^\Q$status\E$/,@overridden)) {
4778: $currstyle = 'display:table-row';
4779: $hidden = 0;
4780: }
4781: my $key = 'override_'.$status;
4782: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4783: $includeloc{$key},$includestr{$key},$status,$rowid,
4784: $usertypeshash{$status},$css_class,$currstyle,
4785: \@contacts,$short_titles);
4786: unless ($hidden) {
4787: $rownum ++;
1.286 raeburn 4788: }
4789: }
1.134 raeburn 4790: }
1.28 raeburn 4791: }
1.30 raeburn 4792: $$rowtotal += $rownum;
1.28 raeburn 4793: return $datatable;
4794: }
4795:
1.340 raeburn 4796: sub core_link_msu {
4797: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4798: &mt('LON-CAPA core group - MSU'),600,500);
4799: }
4800:
1.315 raeburn 4801: sub overridden_helpdesk {
4802: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4803: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4804: my $class = 'LC_left_item';
4805: if ($css_class) {
4806: $css_class = ' class="'.$css_class.'"';
4807: }
4808: if ($rowid) {
4809: $rowid = ' id="'.$rowid.'"';
4810: }
4811: if ($rowstyle) {
4812: $rowstyle = ' style="'.$rowstyle.'"';
4813: }
4814: my ($output,$description);
4815: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4816: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4817: "<td>$description</td>\n".
4818: '<td class="'.$class.'" colspan="2">'.
4819: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4820: '<span class="LC_nobreak">';
4821: if (ref($contacts) eq 'ARRAY') {
4822: foreach my $item (@{$contacts}) {
4823: my $check;
4824: if (ref($checked) eq 'HASH') {
4825: $check = $checked->{$item};
4826: }
4827: my $title;
4828: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4829: $title = $short_titles->{$item};
1.315 raeburn 4830: }
4831: $output .= '<label>'.
4832: '<input type="checkbox" name="override_'.$type.'"'.$check.
4833: ' value="'.$item.'" />'.$title.'</label> ';
4834: }
4835: }
4836: $output .= '</span><br />'.&mt('Others').': '.
4837: '<input type="text" name="override_'.$type.'_others" '.
4838: 'value="'.$otheremails.'" />';
4839: my %locchecked;
4840: foreach my $loc ('s','b') {
4841: if ($includeloc eq $loc) {
4842: $locchecked{$loc} = ' checked="checked"';
4843: last;
4844: }
4845: }
4846: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4847: '<input type="text" name="override_'.$type.'_bcc" '.
4848: 'value="'.$bccemails.'" /></fieldset>'.
4849: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4850: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4851: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4852: '<span class="LC_nobreak">'.&mt('Location:').' '.
4853: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4854: (' 'x2).
4855: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4856: '</span></fieldset>'.
4857: '</td></tr>'."\n";
4858: return $output;
4859: }
4860:
1.286 raeburn 4861: sub contacts_javascript {
4862: return <<"ENDSCRIPT";
4863:
4864: <script type="text/javascript">
4865: // <![CDATA[
4866:
4867: function screenshotSize(field) {
4868: if (document.getElementById('help_screenshotsize')) {
4869: if (field.value == 'no') {
1.289 raeburn 4870: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4871: } else {
4872: document.getElementById('help_screenshotsize').style.display="";
4873: }
4874: }
4875: return;
4876: }
4877:
1.315 raeburn 4878: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4879: if (form.elements[checkbox].length != undefined) {
4880: var count = 0;
4881: if (docount) {
4882: for (var i=0; i<form.elements[checkbox].length; i++) {
4883: if (form.elements[checkbox][i].checked) {
4884: count ++;
4885: }
4886: }
4887: }
4888: for (var i=0; i<form.elements[checkbox].length; i++) {
4889: var type = form.elements[checkbox][i].value;
4890: if (document.getElementById(prefix+type)) {
4891: if (form.elements[checkbox][i].checked) {
4892: document.getElementById(prefix+type).style.display = 'table-row';
4893: if (count % 2 == 1) {
4894: document.getElementById(prefix+type).className = target+' LC_odd_row';
4895: } else {
4896: document.getElementById(prefix+type).className = target;
4897: }
4898: count ++;
4899: } else {
4900: document.getElementById(prefix+type).style.display = 'none';
4901: }
4902: }
4903: }
4904: }
4905: return;
4906: }
4907:
1.286 raeburn 4908: // ]]>
4909: </script>
4910:
4911: ENDSCRIPT
4912: }
4913:
1.118 jms 4914: sub print_helpsettings {
1.282 raeburn 4915: my ($position,$dom,$settings,$rowtotal) = @_;
4916: my $confname = $dom.'-domainconfig';
1.285 raeburn 4917: my $formname = 'display';
1.168 raeburn 4918: my ($datatable,$itemcount);
1.282 raeburn 4919: if ($position eq 'top') {
4920: $itemcount = 1;
4921: my (%choices,%defaultchecked,@toggles);
4922: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4923: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4924: &mt('LON-CAPA bug tracker'),600,500));
4925: %defaultchecked = ('submitbugs' => 'on');
4926: @toggles = ('submitbugs');
4927: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4928: \%choices,$itemcount);
4929: $$rowtotal ++;
4930: } else {
4931: my $css_class;
4932: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4933: my (%customroles,%ordered,%current);
1.301 raeburn 4934: if (ref($settings) eq 'HASH') {
4935: if (ref($settings->{'adhoc'}) eq 'HASH') {
4936: %current = %{$settings->{'adhoc'}};
4937: }
1.285 raeburn 4938: }
4939: my $count = 0;
4940: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4941: if ($key=~/^rolesdef\_(\w+)$/) {
4942: my $rolename = $1;
1.285 raeburn 4943: my (%privs,$order);
1.282 raeburn 4944: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4945: $customroles{$rolename} = \%privs;
1.285 raeburn 4946: if (ref($current{$rolename}) eq 'HASH') {
4947: $order = $current{$rolename}{'order'};
4948: }
4949: if ($order eq '') {
4950: $order = $count;
4951: }
4952: $ordered{$order} = $rolename;
4953: $count++;
4954: }
4955: }
4956: my $maxnum = scalar(keys(%ordered));
4957: my @roles_by_num = ();
4958: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4959: push(@roles_by_num,$item);
4960: }
4961: my $context = 'domprefs';
4962: my $crstype = 'Course';
4963: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4964: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4965: my ($numstatustypes,@jsarray);
4966: if (ref($types) eq 'ARRAY') {
4967: if (@{$types} > 0) {
4968: $numstatustypes = scalar(@{$types});
4969: push(@accesstypes,'status');
4970: @jsarray = ('bystatus');
1.282 raeburn 4971: }
4972: }
1.290 raeburn 4973: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4974: if (keys(%domhelpdesk)) {
4975: push(@accesstypes,('inc','exc'));
4976: push(@jsarray,('notinc','notexc'));
4977: }
4978: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4979: my $context = 'domprefs';
4980: my $crstype = 'Course';
1.285 raeburn 4981: my $prefix = 'helproles_';
4982: my $add_class = 'LC_hidden';
4983: foreach my $num (@roles_by_num) {
4984: my $role = $ordered{$num};
4985: my ($desc,$access,@statuses);
4986: if (ref($current{$role}) eq 'HASH') {
4987: $desc = $current{$role}{'desc'};
4988: $access = $current{$role}{'access'};
4989: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4990: @statuses = @{$current{$role}{'insttypes'}};
4991: }
4992: }
4993: if ($desc eq '') {
4994: $desc = $role;
4995: }
4996: my $identifier = 'custhelp'.$num;
1.282 raeburn 4997: my %full=();
4998: my %levels= (
4999: course => {},
5000: domain => {},
5001: system => {},
5002: );
5003: my %levelscurrent=(
5004: course => {},
5005: domain => {},
5006: system => {},
5007: );
5008: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5009: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5011: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5012: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5013: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5014: for (my $k=0; $k<=$maxnum; $k++) {
5015: my $vpos = $k+1;
5016: my $selstr;
5017: if ($k == $num) {
5018: $selstr = ' selected="selected" ';
5019: }
5020: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5021: }
5022: $datatable .= '</select>'.(' 'x2).
5023: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5024: '</td>'.
5025: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5026: &mt('Name shown to users:').
5027: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5028: '</fieldset>'.
5029: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5030: $othertitle,$usertypes,$types,\%domhelpdesk).
5031: '<fieldset>'.
5032: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5033: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5034: \%levelscurrent,$identifier,
5035: 'LC_hidden',$prefix.$num.'_privs').
5036: '</fieldset></td>';
1.282 raeburn 5037: $itemcount ++;
5038: }
5039: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5040: my $newcust = 'custhelp'.$count;
5041: my (%privs,%levelscurrent);
5042: my %full=();
5043: my %levels= (
5044: course => {},
5045: domain => {},
5046: system => {},
5047: );
5048: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5049: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5050: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5051: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5052: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5053: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5054: for (my $k=0; $k<$maxnum+1; $k++) {
5055: my $vpos = $k+1;
5056: my $selstr;
5057: if ($k == $maxnum) {
5058: $selstr = ' selected="selected" ';
5059: }
5060: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5061: }
5062: $datatable .= '</select> '."\n".
1.282 raeburn 5063: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5064: '</label></span></td>'.
1.285 raeburn 5065: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5066: '<span class="LC_nobreak">'.
5067: &mt('Internal name:').
5068: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5069: '</span>'.(' 'x4).
5070: '<span class="LC_nobreak">'.
5071: &mt('Name shown to users:').
5072: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5073: '</span></fieldset>'.
5074: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5075: $usertypes,$types,\%domhelpdesk).
5076: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5077: &Apache::lonuserutils::custom_role_header($context,$crstype,
5078: \@templateroles,$newcust).
5079: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5080: \%levelscurrent,$newcust).
1.334 raeburn 5081: '</fieldset>'.
5082: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5083: '</td></tr>';
1.282 raeburn 5084: $count ++;
5085: $$rowtotal += $count;
5086: }
1.166 raeburn 5087: return $datatable;
1.121 raeburn 5088: }
5089:
1.285 raeburn 5090: sub adhocbutton {
5091: my ($prefix,$num,$field,$visibility) = @_;
5092: my %lt = &Apache::lonlocal::texthash(
5093: show => 'Show details',
5094: hide => 'Hide details',
5095: );
5096: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5097: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5098: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5099: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5100: }
5101:
5102: sub helpsettings_javascript {
5103: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5104: return unless(ref($roles_by_num) eq 'ARRAY');
5105: my %html_js_lt = &Apache::lonlocal::texthash(
5106: show => 'Show details',
5107: hide => 'Hide details',
5108: );
5109: &html_escape(\%html_js_lt);
5110: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5111: return <<"ENDSCRIPT";
5112: <script type="text/javascript">
5113: // <![CDATA[
5114:
5115: function reorderHelpRoles(form,item) {
5116: var changedVal;
5117: $jstext
5118: var newpos = 'helproles_${total}_pos';
5119: var maxh = 1 + $total;
5120: var current = new Array();
5121: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5122: if (item == newpos) {
5123: changedVal = newitemVal;
5124: } else {
5125: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5126: current[newitemVal] = newpos;
5127: }
5128: for (var i=0; i<helproles.length; i++) {
5129: var elementName = 'helproles_'+helproles[i]+'_pos';
5130: if (elementName != item) {
5131: if (form.elements[elementName]) {
5132: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5133: current[currVal] = elementName;
5134: }
5135: }
5136: }
5137: var oldVal;
5138: for (var j=0; j<maxh; j++) {
5139: if (current[j] == undefined) {
5140: oldVal = j;
5141: }
5142: }
5143: if (oldVal < changedVal) {
5144: for (var k=oldVal+1; k<=changedVal ; k++) {
5145: var elementName = current[k];
5146: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5147: }
5148: } else {
5149: for (var k=changedVal; k<oldVal; k++) {
5150: var elementName = current[k];
5151: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5152: }
5153: }
5154: return;
5155: }
5156:
5157: function helpdeskAccess(num) {
5158: var curraccess = null;
5159: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5160: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5161: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5162: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5163: }
5164: }
5165: }
5166: var shown = Array();
5167: var hidden = Array();
5168: if (curraccess == 'none') {
5169: hidden = Array('$hiddenstr');
5170: } else {
5171: if (curraccess == 'status') {
5172: shown = Array('bystatus');
5173: hidden = Array('notinc','notexc');
5174: } else {
5175: if (curraccess == 'exc') {
5176: shown = Array('notexc');
5177: hidden = Array('notinc','bystatus');
5178: }
5179: if (curraccess == 'inc') {
5180: shown = Array('notinc');
5181: hidden = Array('notexc','bystatus');
5182: }
1.293 raeburn 5183: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5184: hidden = Array('notinc','notexc','bystatus');
5185: }
5186: }
5187: }
5188: if (hidden.length > 0) {
5189: for (var i=0; i<hidden.length; i++) {
5190: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5191: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5192: }
5193: }
5194: }
5195: if (shown.length > 0) {
5196: for (var i=0; i<shown.length; i++) {
5197: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5198: if (shown[i] == 'privs') {
5199: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5200: } else {
5201: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5202: }
5203: }
5204: }
5205: }
5206: return;
5207: }
5208:
5209: function toggleHelpdeskItem(num,field) {
5210: if (document.getElementById('helproles_'+num+'_'+field)) {
5211: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5212: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5213: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5214: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5215: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5216: }
5217: } else {
5218: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5219: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5220: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5221: }
5222: }
5223: }
5224: return;
5225: }
5226:
5227: // ]]>
5228: </script>
5229:
5230: ENDSCRIPT
5231: }
5232:
5233: sub helpdeskroles_access {
5234: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5235: $usertypes,$types,$domhelpdesk) = @_;
5236: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5237: my %lt = &Apache::lonlocal::texthash(
5238: 'rou' => 'Role usage',
5239: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5240: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5241: 'dh' => 'All with domain helpdesk role',
5242: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5243: 'none' => 'None',
5244: 'status' => 'Determined based on institutional status',
5245: 'inc' => 'Include all, but exclude specific personnel',
5246: 'exc' => 'Exclude all, but include specific personnel',
5247: );
5248: my %usecheck = (
5249: all => ' checked="checked"',
5250: );
5251: my %displaydiv = (
5252: status => 'none',
5253: inc => 'none',
5254: exc => 'none',
5255: priv => 'block',
5256: );
5257: my $output;
5258: if (ref($current) eq 'HASH') {
5259: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5260: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5261: $usecheck{$current->{access}} = $usecheck{'all'};
5262: delete($usecheck{'all'});
5263: if ($current->{access} =~ /^(status|inc|exc)$/) {
5264: my $access = $1;
5265: $displaydiv{$access} = 'inline';
5266: } elsif ($current->{access} eq 'none') {
5267: $displaydiv{'priv'} = 'none';
5268: }
5269: }
5270: }
5271: }
5272: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5273: '<p>'.$lt{'whi'}.'</p>';
5274: foreach my $access (@{$accesstypes}) {
5275: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5276: ' onclick="helpdeskAccess('."'$num'".');" />'.
5277: $lt{$access}.'</label>';
5278: if ($access eq 'status') {
5279: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5280: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5281: $othertitle,$usertypes,$types).
5282: '</div>';
5283: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5284: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5285: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5286: '</div>';
5287: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5288: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5289: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5290: '</div>';
5291: }
5292: $output .= '</p>';
5293: }
5294: $output .= '</fieldset>';
5295: return $output;
5296: }
5297:
1.121 raeburn 5298: sub radiobutton_prefs {
1.192 raeburn 5299: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5300: $additional,$align,$firstval) = @_;
1.121 raeburn 5301: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5302: (ref($choices) eq 'HASH'));
5303:
1.170 raeburn 5304: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5305:
5306: foreach my $item (@{$toggles}) {
5307: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5308: $checkedon{$item} = ' checked="checked" ';
5309: $checkedoff{$item} = ' ';
1.121 raeburn 5310: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5311: $checkedoff{$item} = ' checked="checked" ';
5312: $checkedon{$item} = ' ';
5313: }
5314: }
5315: if (ref($settings) eq 'HASH') {
1.121 raeburn 5316: foreach my $item (@{$toggles}) {
1.118 jms 5317: if ($settings->{$item} eq '1') {
5318: $checkedon{$item} = ' checked="checked" ';
5319: $checkedoff{$item} = ' ';
5320: } elsif ($settings->{$item} eq '0') {
5321: $checkedoff{$item} = ' checked="checked" ';
5322: $checkedon{$item} = ' ';
5323: }
5324: }
1.121 raeburn 5325: }
1.192 raeburn 5326: if ($onclick) {
5327: $onclick = ' onclick="'.$onclick.'"';
5328: }
1.121 raeburn 5329: foreach my $item (@{$toggles}) {
1.118 jms 5330: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5331: $datatable .=
1.306 raeburn 5332: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5333: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5334: '</span></td>';
5335: if ($align eq 'left') {
5336: $datatable .= '<td class="LC_left_item">';
5337: } else {
5338: $datatable .= '<td class="LC_right_item">';
5339: }
1.385 raeburn 5340: $datatable .= '<span class="LC_nobreak">';
5341: if ($firstval eq 'no') {
5342: $datatable .=
5343: '<label><input type="radio" name="'.
5344: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5345: '</label> <label><input type="radio" name="'.$item.'" '.
5346: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5347: } else {
5348: $datatable .=
5349: '<label><input type="radio" name="'.
5350: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5351: '</label> <label><input type="radio" name="'.$item.'" '.
5352: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5353: }
5354: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5355: $itemcount ++;
1.121 raeburn 5356: }
5357: return ($datatable,$itemcount);
5358: }
5359:
1.267 raeburn 5360: sub print_ltitools {
1.421 raeburn 5361: my ($position,$dom,$settings,$rowtotal) = @_;
5362: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5363: if (ref($settings) eq 'HASH') {
1.421 raeburn 5364: if ($position eq 'top') {
5365: if (exists($settings->{'encrypt'})) {
5366: if (ref($settings->{'encrypt'}) eq 'HASH') {
5367: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5368: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5369: }
5370: }
1.267 raeburn 5371: }
1.421 raeburn 5372: if (exists($settings->{'private'})) {
5373: if (ref($settings->{'private'}) eq 'HASH') {
5374: if (ref($settings->{'private'}) eq 'HASH') {
5375: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5376: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5377: }
5378: }
5379: }
5380: }
1.421 raeburn 5381: } elsif ($position eq 'middle') {
5382: if (exists($settings->{'rules'})) {
5383: if (ref($settings->{'rules'}) eq 'HASH') {
5384: %rules = %{$settings->{'rules'}};
1.273 raeburn 5385: }
5386: }
1.421 raeburn 5387: } else {
5388: foreach my $key ('encrypt','private','rules') {
5389: if (exists($settings->{$key})) {
5390: delete($settings->{$key});
1.267 raeburn 5391: }
5392: }
5393: }
5394: }
1.421 raeburn 5395: my $datatable;
5396: my $itemcount = 1;
5397: if ($position eq 'top') {
5398: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5399: } elsif ($position eq 'middle') {
5400: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5401: $$rowtotal += $itemcount;
5402: } else {
5403: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5404: }
5405: return $datatable;
5406: }
5407:
5408: sub ltitools_names {
5409: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5410: 'title' => 'Title',
5411: 'version' => 'Version',
5412: 'msgtype' => 'Message Type',
1.323 raeburn 5413: 'sigmethod' => 'Signature Method',
1.296 raeburn 5414: 'url' => 'URL',
5415: 'key' => 'Key',
1.322 raeburn 5416: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5417: 'secret' => 'Secret',
1.425 raeburn 5418: 'icon' => 'Icon',
1.324 raeburn 5419: 'user' => 'User',
1.296 raeburn 5420: 'fullname' => 'Full Name',
5421: 'firstname' => 'First Name',
5422: 'lastname' => 'Last Name',
5423: 'email' => 'E-mail',
5424: 'roles' => 'Role',
1.298 raeburn 5425: 'window' => 'Window',
5426: 'tab' => 'Tab',
1.296 raeburn 5427: 'iframe' => 'iFrame',
5428: 'height' => 'Height',
5429: 'width' => 'Width',
5430: 'linktext' => 'Default Link Text',
5431: 'explanation' => 'Default Explanation',
5432: 'passback' => 'Tool can return grades:',
5433: 'roster' => 'Tool can retrieve roster:',
5434: 'crstarget' => 'Display target',
5435: 'crslabel' => 'Course label',
1.425 raeburn 5436: 'crstitle' => 'Course title',
1.296 raeburn 5437: 'crslinktext' => 'Link Text',
5438: 'crsexplanation' => 'Explanation',
1.318 raeburn 5439: 'crsappend' => 'Provider URL',
1.267 raeburn 5440: );
5441: return %lt;
5442: }
5443:
1.421 raeburn 5444: sub secrets_form {
5445: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5446: my @ids=&Apache::lonnet::current_machine_ids();
5447: my %servers = &Apache::lonnet::get_servers($dom,'library');
5448: my $primary = &Apache::lonnet::domain($dom,'primary');
5449: my ($css_class,$extra,$numshown,$itemcount,$output);
5450: $itemcount = 0;
5451: foreach my $hostid (sort(keys(%servers))) {
5452: my ($showextra,$divsty,$switch);
5453: if ($hostid eq $primary) {
5454: if ($context eq 'ltisec') {
5455: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5456: $showextra = 1;
5457: }
5458: if ($encrypt->{'ltisec_crslinkprot'}) {
5459: $showextra = 1;
5460: }
5461: } else {
5462: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5463: $showextra = 1;
5464: }
5465: }
5466: unless (grep(/^\Q$hostid\E$/,@ids)) {
5467: $switch = 1;
5468: }
5469: if ($showextra) {
5470: $numshown ++;
5471: $divsty = 'display:inline-block';
5472: } else {
5473: $divsty = 'display:none';
5474: }
5475: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5476: '<legend>'.$hostid.'</legend>';
5477: if ($switch) {
5478: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5479: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5480: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5481: if (exists($privkeys->{$hostid})) {
5482: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5483: '<span class="LC_nobreak">'.
5484: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5485: '<span class="LC_nobreak">'.&mt('Change?').
5486: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5487: (' 'x2).
5488: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5489: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5490: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5491: '</span></div>';
5492: } else {
5493: $extra .= '<span class="LC_nobreak">'.
5494: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5495: '</span>'."\n";
5496: }
5497: } elsif (exists($privkeys->{$hostid})) {
5498: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5499: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5500: '<span class="LC_nobreak">'.&mt('Change?').
5501: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5502: (' 'x2).
5503: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5504: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5505: '<span class="LC_nobreak">'.&mt('New Key').':'.
5506: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5507: '<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>'.
5508: '</span></div>';
5509: } else {
5510: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5511: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5512: '<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>';
5513: }
5514: $extra .= '</fieldset>';
5515: }
5516: }
5517: my (%choices,@toggles,%defaultchecked);
5518: if ($context eq 'ltisec') {
5519: %choices = &Apache::lonlocal::texthash (
5520: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5521: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5522: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5523: );
5524: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5525: %defaultchecked = (
5526: 'ltisec_crslinkprot' => 'off',
5527: 'ltisec_domlinkprot' => 'off',
5528: 'ltisec_consumers' => 'off',
5529: );
5530: } else {
5531: %choices = &Apache::lonlocal::texthash (
5532: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5533: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5534: );
5535: @toggles = qw(toolsec_crs toolsec_dom);
5536: %defaultchecked = (
5537: 'toolsec_crs' => 'off',
5538: 'toolsec_dom' => 'off',
5539: );
5540: }
5541: my ($onclick,$itemcount);
5542: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5543: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5544: \%choices,$itemcount,$onclick,'','left','no');
5545:
5546: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5547: my $noprivkeysty = 'display:inline-block';
5548: if ($numshown) {
5549: $noprivkeysty = 'display:none';
5550: }
5551: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5552: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5553: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5554: $extra.
5555: '</td></tr>';
5556: $itemcount ++;
5557: $$rowtotal += $itemcount;
5558: return $output;
5559: }
5560:
1.372 raeburn 5561: sub print_proctoring {
5562: my ($dom,$settings,$rowtotal) = @_;
5563: my $itemcount = 1;
5564: my (%ordered,%providernames,%current,%currentdef);
5565: my $confname = $dom.'-domainconfig';
5566: my $switchserver = &check_switchserver($dom,$confname);
5567: if (ref($settings) eq 'HASH') {
5568: foreach my $item (keys(%{$settings})) {
5569: if (ref($settings->{$item}) eq 'HASH') {
5570: my $num = $settings->{$item}{'order'};
5571: $ordered{$num} = $item;
5572: }
5573: }
5574: } else {
5575: %ordered = (
5576: 1 => 'proctorio',
5577: 2 => 'examity',
5578: );
5579: }
5580: %providernames = &proctoring_providernames();
5581: my $maxnum = scalar(keys(%ordered));
5582: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5583: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5584: if (ref($requref) eq 'HASH') {
5585: %requserfields = %{$requref};
5586: }
5587: if (ref($opturef) eq 'HASH') {
5588: %optuserfields = %{$opturef};
5589: }
5590: if (ref($defref) eq 'HASH') {
5591: %defaults = %{$defref};
5592: }
5593: if (ref($extref) eq 'HASH') {
5594: %extended = %{$extref};
5595: }
5596: if (ref($crsref) eq 'HASH') {
5597: %crsconf = %{$crsref};
5598: }
5599: if (ref($rolesref) eq 'ARRAY') {
5600: @courseroles = @{$rolesref};
5601: }
5602: if (ref($ltiref) eq 'ARRAY') {
5603: @ltiroles = @{$ltiref};
5604: }
5605: my $datatable;
5606: my $css_class;
5607: if (keys(%ordered)) {
5608: my @items = sort { $a <=> $b } keys(%ordered);
5609: for (my $i=0; $i<@items; $i++) {
5610: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5611: my $provider = $ordered{$items[$i]};
5612: my $optionsty = 'none';
5613: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5614: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5615: if (ref($settings) eq 'HASH') {
5616: if (ref($settings->{$provider}) eq 'HASH') {
5617: %current = %{$settings->{$provider}};
5618: if ($current{'available'}) {
5619: $optionsty = 'block';
5620: $available = 1;
5621: }
5622: if ($current{'lifetime'} =~ /^\d+$/) {
5623: $lifetime = $current{'lifetime'};
5624: }
5625: if ($current{'version'} =~ /^\d+\.\d+$/) {
5626: $version = $current{'version'};
5627: }
5628: if ($current{'image'} ne '') {
5629: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5630: }
5631: if (ref($current{'fields'}) eq 'ARRAY') {
5632: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5633: }
5634: $userincdom = $current{'incdom'};
5635: if (ref($current{'roles'}) eq 'HASH') {
5636: %rolemaps = %{$current{'roles'}};
5637: $checkedfields{'roles'} = 1;
5638: }
5639: if (ref($current{'defaults'}) eq 'ARRAY') {
5640: foreach my $val (@{$current{'defaults'}}) {
5641: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5642: $inuse{$val} = 1;
5643: } else {
5644: foreach my $poss (keys(%{$extended{$provider}})) {
5645: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5646: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5647: $inuse{$poss} = $val;
5648: last;
5649: }
5650: }
5651: }
5652: }
5653: }
5654: } elsif (ref($current{'defaults'}) eq 'HASH') {
5655: foreach my $key (keys(%{$current{'defaults'}})) {
5656: my $currval = $current{'defaults'}{$key};
5657: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5658: $inuse{$key} = 1;
5659: } else {
5660: my $match;
5661: foreach my $poss (keys(%{$extended{$provider}})) {
5662: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5663: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5664: $inuse{$poss} = $key;
5665: last;
5666: }
5667: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5668: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5669: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5670: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5671: $currentdef{$inner} = $currval;
5672: $match = 1;
5673: last;
5674: }
5675: } elsif ($inner eq $key) {
5676: $currentdef{$key} = $currval;
5677: $match = 1;
5678: last;
5679: }
5680: }
5681: }
5682: last if ($match);
5683: }
5684: }
5685: }
5686: }
5687: if (ref($current{'crsconf'}) eq 'ARRAY') {
5688: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5689: }
5690: }
5691: }
5692: my %lt = &proctoring_titles($provider);
5693: my %fieldtitles = &proctoring_fieldtitles($provider);
5694: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5695: my %checkedavailable = (
5696: yes => '',
5697: no => ' checked="checked"',
5698: );
5699: if ($available) {
5700: $checkedavailable{'yes'} = $checkedavailable{'no'};
5701: $checkedavailable{'no'} = '';
5702: }
5703: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5704: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5705: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5706: for (my $k=0; $k<$maxnum; $k++) {
5707: my $vpos = $k+1;
5708: my $selstr;
5709: if ($k == $i) {
5710: $selstr = ' selected="selected" ';
5711: }
5712: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5713: }
5714: if ($version eq '') {
5715: if ($provider eq 'proctorio') {
5716: $version = '1.0';
5717: } elsif ($provider eq 'examity') {
5718: $version = '1.1';
5719: }
5720: }
5721: if ($lifetime eq '') {
5722: $lifetime = '300';
5723: }
5724: $datatable .=
5725: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5726: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5727: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5728: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5729: '</td>'.
5730: '<td colspan="2">'.
5731: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5732: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5733: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5734: (' 'x2).
5735: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5736: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5737: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5738: (' 'x2).
5739: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5740: '<br />'.
5741: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5742: '<br />'.
5743: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5744: (' 'x2).
5745: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5746: '<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";
5747: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5748: if ($imgsrc) {
5749: $datatable .= $imgsrc.
5750: '<label><input type="checkbox" name="proctoring_image_del"'.
5751: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5752: '<span class="LC_nobreak"> '.&mt('Replace:');
5753: }
5754: $datatable .= ' ';
5755: if ($switchserver) {
5756: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5757: } else {
5758: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5759: }
5760: unless ($imgsrc) {
5761: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5762: }
5763: $datatable .= '</fieldset>'."\n";
5764: if (ref($requserfields{$provider}) eq 'ARRAY') {
5765: if (@{$requserfields{$provider}} > 0) {
5766: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5767: foreach my $field (@{$requserfields{$provider}}) {
5768: $datatable .= '<span class="LC_nobreak">'.
5769: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5770: $lt{$field}.'</label>';
5771: if ($field eq 'user') {
5772: my $seluserdom = '';
5773: my $unseluserdom = ' selected="selected"';
5774: if ($userincdom) {
5775: $seluserdom = $unseluserdom;
5776: $unseluserdom = '';
5777: }
5778: $datatable .= ': '.
5779: '<select name="proctoring_userincdom_'.$provider.'">'.
5780: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5781: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5782: '</select> ';
5783: } else {
5784: $datatable .= ' ';
5785: if ($field eq 'roles') {
5786: $showroles = 1;
5787: }
5788: }
5789: $datatable .= '</span> ';
5790: }
5791: }
5792: $datatable .= '</fieldset>'."\n";
5793: }
5794: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5795: if (@{$optuserfields{$provider}} > 0) {
5796: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5797: foreach my $field (@{$optuserfields{$provider}}) {
5798: my $checked;
5799: if ($checkedfields{$field}) {
5800: $checked = ' checked="checked"';
5801: }
5802: $datatable .= '<span class="LC_nobreak">'.
5803: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5804: }
5805: $datatable .= '</fieldset>'."\n";
5806: }
5807: }
5808: if (ref($defaults{$provider}) eq 'ARRAY') {
5809: if (@{$defaults{$provider}}) {
5810: my (%options,@selectboxes);
5811: if (ref($extended{$provider}) eq 'HASH') {
5812: %options = %{$extended{$provider}};
5813: }
5814: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5815: my ($rem,$numinrow,$dropdowns);
5816: if ($provider eq 'proctorio') {
5817: $datatable .= '<table>';
5818: $numinrow = 4;
5819: }
5820: my $i = 0;
5821: foreach my $field (@{$defaults{$provider}}) {
5822: my $checked;
5823: if ($inuse{$field}) {
5824: $checked = ' checked="checked"';
5825: }
5826: if ($provider eq 'examity') {
5827: if ($field eq 'display') {
5828: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5829: foreach my $option ('iframe','tab','window') {
5830: my $checkdisp;
5831: if ($currentdef{'target'} eq $option) {
5832: $checkdisp = ' checked="checked"';
5833: }
5834: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5835: $fieldtitles{$option}.'</label>'.(' 'x2);
5836: }
5837: $datatable .= (' 'x4);
5838: foreach my $dimen ('width','height') {
5839: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5840: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5841: 'value="'.$currentdef{$dimen}.'" /></label>'.
5842: (' 'x2);
5843: }
5844: $datatable .= '</span><br />'.
5845: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5846: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5847: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5848: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5849: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5850: $currentdef{'explanation'}.
5851: '</textarea></div><div style=""></div><br />';
5852: }
5853: } else {
5854: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5855: my ($output,$selnone);
5856: unless ($checked) {
5857: $selnone = ' selected="selected"';
5858: }
5859: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5860: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5861: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5862: foreach my $option (@{$options{$field}}) {
5863: my $sel;
5864: if ($inuse{$field} eq $option) {
5865: $sel = ' selected="selected"';
5866: }
5867: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5868: }
5869: $output .= '</select></span>';
5870: push(@selectboxes,$output);
5871: } else {
5872: $rem = $i%($numinrow);
5873: if ($rem == 0) {
5874: if ($i > 0) {
5875: $datatable .= '</tr>';
5876: }
5877: $datatable .= '<tr>';
5878: }
5879: $datatable .= '<td class="LC_left_item">'.
5880: '<span class="LC_nobreak">'.
5881: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5882: $fieldtitles{$field}.'</label></span></td>';
5883: $i++;
5884: }
5885: }
5886: }
5887: if ($provider eq 'proctorio') {
5888: if ($numinrow) {
5889: $rem = $i%$numinrow;
5890: }
5891: my $colsleft = $numinrow - $rem;
5892: if ($colsleft > 1) {
5893: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5894: } else {
5895: $datatable .= '<td class="LC_left_item">';
5896: }
5897: $datatable .= ' '.
5898: '</td></tr></table>';
5899: if (@selectboxes) {
5900: $datatable .= '<hr /><table>';
5901: $numinrow = 2;
5902: for (my $i=0; $i<@selectboxes; $i++) {
5903: $rem = $i%($numinrow);
5904: if ($rem == 0) {
5905: if ($i > 0) {
5906: $datatable .= '</tr>';
5907: }
5908: $datatable .= '<tr>';
5909: }
5910: $datatable .= '<td class="LC_left_item">'.
5911: $selectboxes[$i].'</td>';
5912: }
5913: if ($numinrow) {
5914: $rem = $i%$numinrow;
5915: }
5916: $colsleft = $numinrow - $rem;
5917: if ($colsleft > 1) {
5918: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5919: } else {
5920: $datatable .= '<td class="LC_left_item">';
5921: }
5922: $datatable .= ' '.
5923: '</td></tr></table>';
5924: }
5925: }
5926: $datatable .= '</fieldset>';
5927: }
5928: if (ref($crsconf{$provider}) eq 'ARRAY') {
5929: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5930: '<legend>'.&mt('Configurable in course').'</legend>';
5931: my ($rem,$numinrow);
5932: if ($provider eq 'proctorio') {
5933: $datatable .= '<table>';
5934: $numinrow = 4;
5935: }
5936: my $i = 0;
5937: foreach my $item (@{$crsconf{$provider}}) {
5938: my $name;
5939: if ($provider eq 'examity') {
5940: $name = $lt{'crs'.$item};
5941: } elsif ($provider eq 'proctorio') {
5942: $name = $fieldtitles{$item};
5943: $rem = $i%($numinrow);
5944: if ($rem == 0) {
5945: if ($i > 0) {
5946: $datatable .= '</tr>';
5947: }
5948: $datatable .= '<tr>';
5949: }
5950: $datatable .= '<td class="LC_left_item>';
5951: }
5952: my $checked;
5953: if ($crsconfig{$item}) {
5954: $checked = ' checked="checked"';
5955: }
5956: $datatable .= '<span class="LC_nobreak"><label>'.
5957: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5958: $name.'</label></span>';
5959: if ($provider eq 'examity') {
5960: $datatable .= ' ';
5961: }
5962: $datatable .= "\n";
5963: $i++;
5964: }
5965: if ($provider eq 'proctorio') {
5966: if ($numinrow) {
5967: $rem = $i%$numinrow;
5968: }
5969: my $colsleft = $numinrow - $rem;
5970: if ($colsleft > 1) {
5971: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5972: } else {
5973: $datatable .= '<td class="LC_left_item">';
5974: }
5975: $datatable .= ' '.
5976: '</td></tr></table>';
5977: }
5978: $datatable .= '</fieldset>';
5979: }
5980: if ($showroles) {
5981: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5982: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5983: foreach my $role (@courseroles) {
5984: my ($selected,$selectnone);
5985: if (!$rolemaps{$role}) {
5986: $selectnone = ' selected="selected"';
5987: }
5988: $datatable .= '<td style="text-align: center">'.
5989: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5990: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5991: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5992: foreach my $ltirole (@ltiroles) {
5993: unless ($selectnone) {
5994: if ($rolemaps{$role} eq $ltirole) {
5995: $selected = ' selected="selected"';
5996: } else {
5997: $selected = '';
5998: }
5999: }
6000: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6001: }
6002: $datatable .= '</select></td>';
6003: }
6004: $datatable .= '</tr></table></fieldset>'.
6005: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6006: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6007: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6008: '<tr><td></td><td>lms</td>'.
6009: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6010: ' value="Loncapa" disabled="disabled"/></td></tr>';
6011: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6012: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6013: my %custom = %{$settings->{$provider}->{'custom'}};
6014: if (keys(%custom) > 0) {
6015: foreach my $key (sort(keys(%custom))) {
6016: next if ($key eq 'lms');
6017: $datatable .= '<tr><td><span class="LC_nobreak">'.
6018: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6019: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6020: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6021: ' value="'.$custom{$key}.'" /></td></tr>';
6022: }
6023: }
6024: }
6025: $datatable .= '<tr><td><span class="LC_nobreak">'.
6026: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6027: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6028: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6029: '</table></fieldset></td></tr>'."\n";
6030: }
6031: $datatable .= '</td></tr>';
6032: }
6033: $itemcount ++;
6034: }
6035: }
6036: return $datatable;
6037: }
6038:
6039: sub proctoring_data {
6040: my $requserfields = {
6041: proctorio => ['user'],
6042: examity => ['roles','user'],
6043: };
6044: my $optuserfields = {
6045: proctorio => ['fullname'],
6046: examity => ['fullname','firstname','lastname','email'],
6047: };
6048: my $defaults = {
6049: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6050: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6051: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6052: 'closetabs','onescreen','print','downloads','cache','rightclick',
6053: 'reentry','calculator','whiteboard'],
6054: examity => ['display'],
6055: };
6056: my $extended = {
6057: proctorio => {
6058: verifyid => ['verifyidauto','verifyidlive'],
6059: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6060: tabslinks => ['notabs','linksonly'],
6061: reentry => ['noreentry','agentreentry'],
6062: calculator => ['calculatorbasic','calculatorsci'],
6063: },
6064: examity => {
6065: display => {
6066: target => ['iframe','tab','window'],
6067: width => '',
6068: height => '',
6069: linktext => '',
6070: explanation => '',
6071: },
6072: },
6073: };
6074: my $crsconf = {
6075: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6076: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6077: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6078: 'closetabs','onescreen','print','downloads','cache','rightclick',
6079: 'reentry','calculator','whiteboard'],
6080: examity => ['label','title','target','linktext','explanation','append'],
6081: };
6082: my $courseroles = ['cc','in','ta','ep','st'];
6083: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6084: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6085: }
6086:
6087: sub proctoring_titles {
6088: my ($item) = @_;
6089: my (%common_lt,%custom_lt);
6090: %common_lt = &Apache::lonlocal::texthash (
6091: 'avai' => 'Available?',
6092: 'base' => 'Basic Settings',
6093: 'requ' => 'User data required to be sent on launch',
6094: 'optu' => 'User data optionally sent on launch',
6095: 'udsl' => 'User data sent on launch',
6096: 'defa' => 'Defaults for items configurable in course',
6097: 'sigmethod' => 'Signature Method',
6098: 'key' => 'Key',
6099: 'lifetime' => 'Nonce lifetime (s)',
6100: 'secret' => 'Secret',
6101: 'icon' => 'Icon',
6102: 'fullname' => 'Full Name',
6103: 'visible' => 'Visible input',
6104: 'username' => 'username',
6105: 'user' => 'User',
6106: );
6107: if ($item eq 'proctorio') {
6108: %custom_lt = &Apache::lonlocal::texthash (
6109: 'version' => 'OAuth version',
6110: 'url' => 'API URL',
6111: 'uname:dom' => 'username-domain',
6112: );
6113: } elsif ($item eq 'examity') {
6114: %custom_lt = &Apache::lonlocal::texthash (
6115: 'version' => 'LTI Version',
6116: 'url' => 'URL',
6117: 'uname:dom' => 'username:domain',
6118: 'msgtype' => 'Message Type',
6119: 'firstname' => 'First Name',
6120: 'lastname' => 'Last Name',
6121: 'email' => 'E-mail',
6122: 'roles' => 'Role',
6123: 'crstarget' => 'Display target',
6124: 'crslabel' => 'Course label',
6125: 'crstitle' => 'Course title',
6126: 'crslinktext' => 'Link Text',
6127: 'crsexplanation' => 'Explanation',
6128: 'crsappend' => 'Provider URL',
6129: );
6130: }
6131: my %lt = (%common_lt,%custom_lt);
6132: return %lt;
6133: }
6134:
6135: sub proctoring_fieldtitles {
6136: my ($item) = @_;
6137: if ($item eq 'proctorio') {
6138: return &Apache::lonlocal::texthash (
6139: 'recordvideo' => 'Record video',
6140: 'recordaudio' => 'Record audio',
6141: 'recordscreen' => 'Record screen',
6142: 'recordwebtraffic' => 'Record web traffic',
6143: 'recordroomstart' => 'Record room scan',
6144: 'verifyvideo' => 'Verify webcam',
6145: 'verifyaudio' => 'Verify microphone',
6146: 'verifydesktop' => 'Verify desktop recording',
6147: 'verifyid' => 'Photo ID verification',
6148: 'verifysignature' => 'Require signature',
6149: 'fullscreen' => 'Fullscreen',
6150: 'clipboard' => 'Disable copy/paste',
6151: 'tabslinks' => 'New tabs/windows',
6152: 'closetabs' => 'Close other tabs',
6153: 'onescreen' => 'Limit to single screen',
6154: 'print' => 'Disable Printing',
6155: 'downloads' => 'Disable Downloads',
6156: 'cache' => 'Empty cache after exam',
6157: 'rightclick' => 'Disable right click',
6158: 'reentry' => 'Re-entry to exam',
6159: 'calculator' => 'Onscreen calculator',
6160: 'whiteboard' => 'Onscreen whiteboard',
6161: 'verifyidauto' => 'Automated verification',
6162: 'verifyidlive' => 'Live agent verification',
6163: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6164: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6165: 'fullscreensever' => 'Forced, navigation away ends exam',
6166: 'notabs' => 'Disaallowed',
6167: 'linksonly' => 'Allowed from links in exam',
6168: 'noreentry' => 'Disallowed',
6169: 'agentreentry' => 'Agent required for re-entry',
6170: 'calculatorbasic' => 'Basic',
6171: 'calculatorsci' => 'Scientific',
6172: );
6173: } elsif ($item eq 'examity') {
6174: return &Apache::lonlocal::texthash (
6175: 'target' => 'Display target',
6176: 'window' => 'Window',
6177: 'tab' => 'Tab',
6178: 'iframe' => 'iFrame',
6179: 'height' => 'Height (pixels)',
6180: 'width' => 'Width (pixels)',
6181: 'linktext' => 'Default Link Text',
6182: 'explanation' => 'Default Explanation',
6183: 'append' => 'Provider URL',
6184: );
6185: }
6186: }
6187:
6188: sub proctoring_providernames {
6189: return (
6190: proctorio => 'Proctorio',
6191: examity => 'Examity',
6192: );
6193: }
6194:
1.320 raeburn 6195: sub print_lti {
1.405 raeburn 6196: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6197: my $itemcount = 1;
1.405 raeburn 6198: my ($datatable,$css_class);
1.434 raeburn 6199: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6200: if (ref($settings) eq 'HASH') {
1.405 raeburn 6201: if ($position eq 'top') {
6202: if (exists($settings->{'encrypt'})) {
6203: if (ref($settings->{'encrypt'}) eq 'HASH') {
6204: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6205: if ($key eq 'consumers') {
6206: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6207: } else {
6208: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6209: }
6210: }
6211: }
6212: }
6213: if (exists($settings->{'private'})) {
6214: if (ref($settings->{'private'}) eq 'HASH') {
6215: if (ref($settings->{'private'}) eq 'HASH') {
6216: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6217: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6218: }
6219: }
6220: }
6221: }
1.434 raeburn 6222: } elsif ($position eq 'upper') {
1.405 raeburn 6223: if (exists($settings->{'rules'})) {
6224: if (ref($settings->{'rules'}) eq 'HASH') {
6225: %rules = %{$settings->{'rules'}};
6226: }
6227: }
1.434 raeburn 6228: } elsif ($position eq 'middle') {
6229: if (exists($settings->{'suggested'})) {
6230: if (ref($settings->{'suggested'}) eq 'HASH') {
6231: %suggestions = %{$settings->{'suggested'}};
6232: }
6233: }
1.405 raeburn 6234: } elsif ($position eq 'lower') {
6235: if (exists($settings->{'linkprot'})) {
6236: if (ref($settings->{'linkprot'}) eq 'HASH') {
6237: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6238: if ($linkprot{'lock'}) {
6239: delete($linkprot{'lock'});
6240: }
1.405 raeburn 6241: }
6242: }
6243: } else {
1.434 raeburn 6244: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6245: if (exists($settings->{$key})) {
6246: delete($settings->{$key});
1.390 raeburn 6247: }
1.320 raeburn 6248: }
6249: }
6250: }
1.405 raeburn 6251: if ($position eq 'top') {
1.421 raeburn 6252: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6253: } elsif ($position eq 'upper') {
6254: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6255: $$rowtotal += $itemcount;
1.421 raeburn 6256: } elsif ($position eq 'middle') {
1.434 raeburn 6257: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6258: $$rowtotal += $itemcount;
6259: } elsif ($position eq 'lower') {
1.434 raeburn 6260: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6261: } else {
1.424 raeburn 6262: my ($switchserver,$switchmessage);
6263: $switchserver = &check_switchserver($dom);
6264: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6265: my $maxnum = 0;
6266: my %ordered;
6267: if (ref($settings) eq 'HASH') {
6268: foreach my $item (keys(%{$settings})) {
6269: if (ref($settings->{$item}) eq 'HASH') {
6270: my $num = $settings->{$item}{'order'};
6271: if ($num eq '') {
6272: $num = scalar(keys(%{$settings}));
6273: }
6274: $ordered{$num} = $item;
1.405 raeburn 6275: }
1.352 raeburn 6276: }
1.405 raeburn 6277: }
6278: $maxnum = scalar(keys(%ordered));
6279: my %lt = <i_names();
6280: if (keys(%ordered)) {
6281: my @items = sort { $a <=> $b } keys(%ordered);
6282: for (my $i=0; $i<@items; $i++) {
6283: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6284: my $item = $ordered{$items[$i]};
1.424 raeburn 6285: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6286: if (ref($settings->{$item}) eq 'HASH') {
6287: $key = $settings->{$item}->{'key'};
1.424 raeburn 6288: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6289: $lifetime = $settings->{$item}->{'lifetime'};
6290: $consumer = $settings->{$item}->{'consumer'};
6291: $requser = $settings->{$item}->{'requser'};
6292: $crsinc = $settings->{$item}->{'crsinc'};
6293: $current = $settings->{$item};
6294: }
6295: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6296: my %checkedrequser = (
6297: yes => ' checked="checked"',
6298: no => '',
6299: );
6300: if (!$requser) {
6301: $checkedrequser{'no'} = $checkedrequser{'yes'};
6302: $checkedrequser{'yes'} = '';
6303: }
6304: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6305: my %checkedcrsinc = (
1.391 raeburn 6306: yes => ' checked="checked"',
6307: no => '',
1.405 raeburn 6308: );
6309: if (!$crsinc) {
6310: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6311: $checkedcrsinc{'yes'} = '';
6312: }
6313: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6314: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6315: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6316: for (my $k=0; $k<=$maxnum; $k++) {
6317: my $vpos = $k+1;
6318: my $selstr;
6319: if ($k == $i) {
6320: $selstr = ' selected="selected" ';
6321: }
6322: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6323: }
1.405 raeburn 6324: $datatable .= '</select>'.(' 'x2).
6325: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6326: &mt('Delete?').'</label></span></td>'.
6327: '<td colspan="2">'.
6328: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6329: '<span class="LC_nobreak">'.$lt{'consumer'}.
6330: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6331: (' 'x2).
6332: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6333: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6334: (' 'x2).
6335: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6336: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6337: if ($key ne '') {
6338: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6339: if ($switchserver) {
6340: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6341: } else {
6342: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6343: }
6344: $datatable .= '</span> '.(' 'x2);
6345: } elsif (!$switchserver) {
6346: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6347: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6348: '</span> '.(' 'x2);
6349: }
6350: if ($switchserver) {
6351: if ($usable ne '') {
6352: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6353: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6354: '<span class="LC_nobreak">'.&mt('Change secret?').
6355: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6356: (' 'x2).
6357: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6358: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6359: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6360: '</div>';
6361: } elsif ($key eq '') {
6362: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6363: } else {
6364: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6365: }
6366: } else {
6367: if ($usable ne '') {
6368: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6369: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6370: '<span class="LC_nobreak">'.&mt('Change?').
6371: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6372: (' 'x2).
6373: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6374: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6375: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6376: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6377: '<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>';
6378: } else {
6379: $datatable .=
6380: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6381: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6382: '<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>';
6383: }
6384: }
1.425 raeburn 6385: $datatable .= '<br /><br />'.
1.405 raeburn 6386: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6387: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6388: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6389: '<br /><br />'.
6390: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6391: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6392: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6393: (' 'x4).
6394: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6395: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6396: $itemcount ++;
1.320 raeburn 6397: }
6398: }
1.405 raeburn 6399: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6400: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6401: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6402: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6403: '<select name="lti_pos_add"'.$chgstr.'>';
6404: for (my $k=0; $k<$maxnum+1; $k++) {
6405: my $vpos = $k+1;
6406: my $selstr;
6407: if ($k == $maxnum) {
6408: $selstr = ' selected="selected" ';
6409: }
6410: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6411: }
1.405 raeburn 6412: $datatable .= '</select> '."\n".
6413: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6414: '<td colspan="2">'.
6415: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6416: '<span class="LC_nobreak">'.$lt{'consumer'}.
6417: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6418: (' 'x2).
6419: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6420: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6421: (' 'x2).
1.424 raeburn 6422: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6423: if ($switchserver) {
6424: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6425: } else {
6426: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6427: (' 'x2).
6428: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6429: '<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";
6430: }
6431: $datatable .= '<br /><br />'.
1.405 raeburn 6432: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6433: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6434: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6435: '<br /><br />'.
6436: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6437: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6438: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6439: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6440: '</td>'."\n".
6441: '</tr>'."\n";
6442: $itemcount ++;
1.320 raeburn 6443: }
1.405 raeburn 6444: $$rowtotal += $itemcount;
6445: return $datatable;
1.320 raeburn 6446: }
6447:
6448: sub lti_names {
6449: my %lt = &Apache::lonlocal::texthash(
6450: 'version' => 'LTI Version',
6451: 'url' => 'URL',
6452: 'key' => 'Key',
1.322 raeburn 6453: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6454: 'consumer' => 'Consumer',
1.320 raeburn 6455: 'secret' => 'Secret',
1.345 raeburn 6456: 'requser' => "User's identity sent",
1.391 raeburn 6457: 'crsinc' => "Course's identity sent",
1.320 raeburn 6458: 'email' => 'Email address',
6459: 'sourcedid' => 'User ID',
6460: 'other' => 'Other',
6461: 'passback' => 'Can return grades to Consumer:',
6462: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6463: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6464: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6465: );
6466: return %lt;
6467: }
6468:
6469: sub lti_options {
1.325 raeburn 6470: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6471: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6472: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6473: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6474: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6475: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6476: $checked{'mapcrstype'} = {};
6477: $checked{'makeuser'} = {};
6478: $checked{'selfenroll'} = {};
6479: $checked{'crssec'} = {};
6480: $checked{'crssecsrc'} = {};
1.325 raeburn 6481: $checked{'lcauth'} = {};
1.326 raeburn 6482: $checked{'menuitem'} = {};
1.325 raeburn 6483: if ($num eq 'add') {
6484: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6485: }
1.320 raeburn 6486: my $userfieldsty = 'none';
6487: my $crsfieldsty = 'none';
6488: my $crssecfieldsty = 'none';
6489: my $secsrcfieldsty = 'none';
1.363 raeburn 6490: my $callbacksty = 'none';
1.337 raeburn 6491: my $passbacksty = 'none';
1.345 raeburn 6492: my $optionsty = 'block';
1.391 raeburn 6493: my $crssty = 'block';
1.325 raeburn 6494: my $lcauthparm;
6495: my $lcauthparmstyle = 'display:none';
6496: my $lcauthparmtext;
1.326 raeburn 6497: my $menusty;
1.325 raeburn 6498: my $numinrow = 4;
1.326 raeburn 6499: my %menutitles = <imenu_titles();
1.320 raeburn 6500:
6501: if (ref($current) eq 'HASH') {
1.345 raeburn 6502: if (!$current->{'requser'}) {
6503: $optionsty = 'none';
1.391 raeburn 6504: $crssty = 'none';
6505: } elsif (!$current->{'crsinc'}) {
6506: $crssty = 'none';
1.345 raeburn 6507: }
1.320 raeburn 6508: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6509: $checked{'mapuser'}{'sourcedid'} = '';
6510: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6511: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6512: } else {
6513: $checked{'mapuser'}{'other'} = ' checked="checked"';
6514: $userfield = $current->{'mapuser'};
6515: $userfieldsty = 'inline-block';
6516: }
6517: }
6518: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6519: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6520: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6521: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6522: } else {
6523: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6524: $cidfield = $current->{'mapcrs'};
6525: $crsfieldsty = 'inline-block';
6526: }
6527: }
6528: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6529: foreach my $type (@{$current->{'mapcrstype'}}) {
6530: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6531: }
6532: }
1.392 raeburn 6533: if (!$current->{'storecrs'}) {
6534: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6535: $checked{'storecrs'}{'Y'} = '';
6536: }
1.345 raeburn 6537: if ($current->{'makecrs'}) {
1.320 raeburn 6538: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6539: }
1.320 raeburn 6540: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6541: foreach my $role (@{$current->{'makeuser'}}) {
6542: $checked{'makeuser'}{$role} = ' checked="checked"';
6543: }
6544: }
1.325 raeburn 6545: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6546: $checked{'lcauth'}{$1} = ' checked="checked"';
6547: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6548: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6549: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6550: if ($current->{'lcauth'} eq 'localauth') {
6551: $lcauthparmtext = &mt('Local auth argument');
6552: } else {
6553: $lcauthparmtext = &mt('Kerberos domain');
6554: }
6555: }
6556: }
1.320 raeburn 6557: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6558: foreach my $role (@{$current->{'selfenroll'}}) {
6559: $checked{'selfenroll'}{$role} = ' checked="checked"';
6560: }
6561: }
6562: if (ref($current->{'maproles'}) eq 'HASH') {
6563: %rolemaps = %{$current->{'maproles'}};
6564: }
6565: if ($current->{'section'} ne '') {
1.425 raeburn 6566: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6567: $crssecfieldsty = 'inline-block';
6568: if ($current->{'section'} eq 'course_section_sourcedid') {
6569: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6570: } else {
6571: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6572: $crssecsrc = $current->{'section'};
6573: $secsrcfieldsty = 'inline-block';
6574: }
6575: } else {
6576: $checked{'crssec'}{'N'} = ' checked="checked"';
6577: }
1.363 raeburn 6578: if ($current->{'callback'} ne '') {
6579: $callback = $current->{'callback'};
6580: $checked{'callback'}{'Y'} = ' checked="checked"';
6581: $callbacksty = 'inline-block';
6582: } else {
6583: $checked{'callback'}{'N'} = ' checked="checked"';
6584: }
1.326 raeburn 6585: if ($current->{'topmenu'}) {
6586: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6587: } else {
6588: $checked{'topmenu'}{'N'} = ' checked="checked"';
6589: }
6590: if ($current->{'inlinemenu'}) {
6591: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6592: } else {
6593: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6594: }
6595: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6596: $menusty = 'inline-block';
6597: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6598: foreach my $item (@{$current->{'lcmenu'}}) {
6599: if (exists($menutitles{$item})) {
6600: $checked{'menuitem'}{$item} = ' checked="checked"';
6601: }
6602: }
6603: }
6604: } else {
6605: $menusty = 'none';
6606: }
1.320 raeburn 6607: } else {
6608: $checked{'makecrs'}{'N'} = ' checked="checked"';
6609: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6610: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6611: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6612: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6613: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6614: $menusty = 'inline-block';
1.320 raeburn 6615: }
1.325 raeburn 6616: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6617: my %coursetypetitles = &Apache::lonlocal::texthash (
6618: official => 'Official',
6619: unofficial => 'Unofficial',
6620: community => 'Community',
6621: textbook => 'Textbook',
6622: placement => 'Placement Test',
1.325 raeburn 6623: lti => 'LTI Provider',
1.320 raeburn 6624: );
1.325 raeburn 6625: my @authtypes = ('internal','krb4','krb5','localauth');
6626: my %shortauth = (
6627: internal => 'int',
6628: krb4 => 'krb4',
6629: krb5 => 'krb5',
6630: localauth => 'loc'
6631: );
6632: my %authnames = &authtype_names();
1.320 raeburn 6633: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6634: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6635: my @courseroles = ('cc','in','ta','ep','st');
6636: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6637: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6638: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6639: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6640: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6641: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6642: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6643: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6644: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6645: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6646: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6647: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6648: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6649: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6650: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6651: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6652: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6653: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6654: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6655: foreach my $option ('sourcedid','email','other') {
6656: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6657: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6658: ($option eq 'other' ? '' : (' 'x2) );
6659: }
6660: $output .= '</span></div>'.
6661: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6662: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6663: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6664: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6665: foreach my $ltirole (@ltiroles) {
6666: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6667: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6668: }
6669: $output .= '</fieldset>'.
1.391 raeburn 6670: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6671: '<table>'.
6672: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6673: '</table>'.
6674: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6675: '<td class="LC_left_item">';
6676: foreach my $auth ('lti',@authtypes) {
6677: my $authtext;
6678: if ($auth eq 'lti') {
6679: $authtext = &mt('None');
6680: } else {
6681: $authtext = $authnames{$shortauth{$auth}};
6682: }
6683: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6684: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6685: $authtext.'</label></span> ';
6686: }
6687: $output .= '</td></tr>'.
6688: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6689: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6690: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6691: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6692: '</table></fieldset>'.
1.391 raeburn 6693: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6694: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6695: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6696: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6697: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6698: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6699: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6700: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6701: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6702: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6703: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6704: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6705: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6706: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6707: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6708: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6709: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6710: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6711: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6712: (' 'x2);
6713: }
6714: $output .= '</span></div></fieldset>'.
6715: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6716: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6717: &mt('Unique course identifier').': ';
6718: foreach my $option ('course_offering_sourcedid','context_id','other') {
6719: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6720: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6721: ($option eq 'other' ? '' : (' 'x2) );
6722: }
1.334 raeburn 6723: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6724: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6725: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6726: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6727: foreach my $type (@coursetypes) {
6728: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6729: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6730: (' 'x2);
6731: }
1.392 raeburn 6732: $output .= '</span><br /><br />'.
6733: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6734: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6735: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6736: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6737: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6738: '</fieldset>'.
1.391 raeburn 6739: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6740: foreach my $ltirole (@lticourseroles) {
6741: my ($selected,$selectnone);
6742: if ($rolemaps{$ltirole} eq '') {
6743: $selectnone = ' selected="selected"';
6744: }
6745: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6746: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6747: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6748: foreach my $role (@courseroles) {
6749: unless ($selectnone) {
6750: if ($rolemaps{$ltirole} eq $role) {
6751: $selected = ' selected="selected"';
6752: } else {
6753: $selected = '';
6754: }
6755: }
6756: $output .= '<option value="'.$role.'"'.$selected.'>'.
6757: &Apache::lonnet::plaintext($role,'Course').
6758: '</option>';
6759: }
6760: $output .= '</select></td>';
6761: }
6762: $output .= '</tr></table></fieldset>'.
6763: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6764: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6765: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6766: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6767: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6768: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6769: '</fieldset>'.
1.391 raeburn 6770: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6771: foreach my $lticrsrole (@lticourseroles) {
6772: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6773: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6774: }
6775: $output .= '</fieldset>'.
1.391 raeburn 6776: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6777: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6778: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6779: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6780: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6781: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6782: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6783: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6784: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6785: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6786: &mt('Standard field').'</label>'.(' 'x2).
6787: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6788: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6789: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6790: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6791: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6792: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6793: foreach my $extra ('roster','passback') {
1.320 raeburn 6794: my $checkedon = '';
6795: my $checkedoff = ' checked="checked"';
1.337 raeburn 6796: if ($extra eq 'passback') {
6797: $pb1p1chk = ' checked="checked"';
6798: $pb1p0chk = '';
1.425 raeburn 6799: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6800: } else {
1.425 raeburn 6801: $onclickpb = '';
1.337 raeburn 6802: }
1.320 raeburn 6803: if (ref($current) eq 'HASH') {
6804: if (($current->{$extra})) {
6805: $checkedon = $checkedoff;
6806: $checkedoff = '';
1.337 raeburn 6807: if ($extra eq 'passback') {
6808: $passbacksty = 'inline-block';
6809: }
6810: if ($current->{'passbackformat'} eq '1.0') {
6811: $pb1p0chk = ' checked="checked"';
6812: $pb1p1chk = '';
6813: }
1.320 raeburn 6814: }
6815: }
6816: $output .= $lt{$extra}.' '.
1.337 raeburn 6817: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6818: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6819: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6820: &mt('Yes').'</label><br />';
6821: }
1.337 raeburn 6822: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6823: '<span class="LC_nobreak">'.&mt('Grade format').
6824: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6825: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6826: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6827: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6828: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6829: $output .= '</span></div></fieldset>';
1.320 raeburn 6830: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6831: #
6832: # $output .= '</fieldset>'.
6833: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6834: return $output;
6835: }
6836:
1.326 raeburn 6837: sub ltimenu_titles {
6838: return &Apache::lonlocal::texthash(
6839: fullname => 'Full name',
6840: coursetitle => 'Course title',
6841: role => 'Role',
6842: logout => 'Logout',
6843: grades => 'Grades',
6844: );
6845: }
6846:
1.434 raeburn 6847: sub linkprot_suggestions {
6848: my ($suggested,$itemcount) = @_;
6849: my $count = 0;
6850: my $next = 1;
6851: my %lt = &Apache::lonlocal::texthash(
6852: 'name' => 'Suggested Launcher',
6853: 'info' => 'Recommendations',
6854: );
6855: my ($datatable,$css_class,$dest);
6856: if (ref($suggested) eq 'HASH') {
6857: my @current = sort { $a <=> $b } keys(%{$suggested});
6858: $next += $current[-1];
6859: for (my $i=0; $i<@current; $i++) {
6860: my $num = $current[$i];
6861: my %values;
6862: if (ref($suggested->{$num}) eq 'HASH') {
6863: %values = %{$suggested->{$num}};
6864: } else {
6865: next;
6866: }
6867: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6868: $datatable .=
6869: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6870: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6871: &mt('Delete?').'</label></span></td><td>'."\n".
6872: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6873: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6874: '</fieldset></div>'.
6875: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6876: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6877: '</fieldset></div>'.
6878: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6879: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6880: $$itemcount ++;
6881: }
6882: }
6883: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6884: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6885: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6886: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6887: '<td>'."\n".
6888: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6889: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6890: '</fieldset></div>'.
6891: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6892: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6893: '</fieldset></div>'.
6894: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6895: '</td></tr>'."\n";
6896: return $datatable;
6897: }
6898:
1.121 raeburn 6899: sub print_coursedefaults {
1.139 raeburn 6900: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6901: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6902: my $itemcount = 1;
1.192 raeburn 6903: my %choices = &Apache::lonlocal::texthash (
6904: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6905: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6906: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6907: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6908: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6909: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6910: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6911: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6912: texengine => 'Default method to display mathematics',
1.257 raeburn 6913: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6914: canclone => "People who may clone a course (besides course's owner and coordinators)",
6915: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6916: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6917: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6918: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6919: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.192 raeburn 6920: );
1.198 raeburn 6921: my %staticdefaults = (
6922: anonsurvey_threshold => 10,
6923: uploadquota => 500,
1.428 raeburn 6924: coursequota => 20,
1.257 raeburn 6925: postsubmit => 60,
1.276 raeburn 6926: mysqltables => 172800,
1.422 raeburn 6927: domexttool => 1,
6928: exttool => 0,
1.432 raeburn 6929: crsauthor => 1,
1.198 raeburn 6930: );
1.139 raeburn 6931: if ($position eq 'top') {
1.257 raeburn 6932: %defaultchecked = (
6933: 'canuse_pdfforms' => 'off',
6934: 'uselcmath' => 'on',
6935: 'usejsme' => 'on',
1.398 raeburn 6936: 'inline_chem' => 'on',
1.289 raeburn 6937: 'canclone' => 'none',
1.257 raeburn 6938: );
1.398 raeburn 6939: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6940: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6941: if (ref($settings) eq 'HASH') {
6942: if ($settings->{'texengine'}) {
6943: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6944: $deftex = $settings->{'texengine'};
6945: }
6946: }
6947: }
6948: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6949: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6950: '<span class="LC_nobreak">'.$choices{'texengine'}.
6951: '</span></td><td class="LC_right_item">'.
6952: '<select name="texengine">'."\n";
6953: my %texoptions = (
6954: MathJax => 'MathJax',
6955: mimetex => &mt('Convert to Images'),
6956: tth => &mt('TeX to HTML'),
6957: );
6958: foreach my $renderer ('MathJax','mimetex','tth') {
6959: my $selected = '';
6960: if ($renderer eq $deftex) {
6961: $selected = ' selected="selected"';
6962: }
6963: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6964: }
6965: $mathdisp .= '</select></td></tr>'."\n";
6966: $itemcount ++;
1.139 raeburn 6967: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6968: \%choices,$itemcount);
1.314 raeburn 6969: $datatable = $mathdisp.$datatable;
1.264 raeburn 6970: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6971: $datatable .=
1.306 raeburn 6972: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6973: '<span class="LC_nobreak">'.$choices{'canclone'}.
6974: '</span></td><td class="LC_left_item">';
6975: my $currcanclone = 'none';
6976: my $onclick;
6977: my @cloneoptions = ('none','domain');
1.380 raeburn 6978: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6979: none => 'No additional course requesters',
6980: domain => "Any course requester in course's domain",
6981: instcode => 'Course requests for official courses ...',
6982: );
6983: my (%codedefaults,@code_order,@posscodes);
6984: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6985: \@code_order) eq 'ok') {
6986: if (@code_order > 0) {
6987: push(@cloneoptions,'instcode');
6988: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6989: }
6990: }
6991: if (ref($settings) eq 'HASH') {
6992: if ($settings->{'canclone'}) {
6993: if (ref($settings->{'canclone'}) eq 'HASH') {
6994: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6995: if (@code_order > 0) {
6996: $currcanclone = 'instcode';
6997: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6998: }
6999: }
7000: } elsif ($settings->{'canclone'} eq 'domain') {
7001: $currcanclone = $settings->{'canclone'};
7002: }
7003: }
1.289 raeburn 7004: }
1.264 raeburn 7005: foreach my $option (@cloneoptions) {
7006: my ($checked,$additional);
7007: if ($currcanclone eq $option) {
7008: $checked = ' checked="checked"';
7009: }
7010: if ($option eq 'instcode') {
7011: if (@code_order) {
7012: my $show = 'none';
7013: if ($checked) {
7014: $show = 'block';
7015: }
1.317 raeburn 7016: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7017: &mt('Institutional codes for new and cloned course have identical:').
7018: '<br />';
7019: foreach my $item (@code_order) {
7020: my $codechk;
7021: if ($checked) {
7022: if (grep(/^\Q$item\E$/,@posscodes)) {
7023: $codechk = ' checked="checked"';
7024: }
7025: }
7026: $additional .= '<label>'.
7027: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7028: $item.'</label>';
7029: }
7030: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7031: }
7032: }
7033: $datatable .=
7034: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7035: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7036: '</label> '.$additional.'</span><br />';
7037: }
7038: $datatable .= '</td>'.
7039: '</tr>';
7040: $itemcount ++;
1.139 raeburn 7041: } else {
7042: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7043: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7044: %deftimeout,%currmysql);
1.192 raeburn 7045: my $currusecredits = 0;
1.257 raeburn 7046: my $postsubmitclient = 1;
1.405 raeburn 7047: my $ltiauth = 0;
1.422 raeburn 7048: my %domexttool;
7049: my %exttool;
1.432 raeburn 7050: my %crsauthor;
1.271 raeburn 7051: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7052: if (ref($settings) eq 'HASH') {
1.404 raeburn 7053: if ($settings->{'ltiauth'}) {
7054: $ltiauth = 1;
1.405 raeburn 7055: }
1.422 raeburn 7056: if (ref($settings->{'domexttool'}) eq 'HASH') {
7057: foreach my $type (@types) {
7058: if ($settings->{'domexttool'}->{$type}) {
7059: $domexttool{$type} = ' checked="checked"';
7060: }
7061: }
7062: } else {
7063: foreach my $type (@types) {
7064: if ($staticdefaults{'domexttool'}) {
7065: $domexttool{$type} = ' checked="checked"';
7066: }
7067: }
7068: }
7069: if (ref($settings->{'exttool'}) eq 'HASH') {
7070: foreach my $type (@types) {
7071: if ($settings->{'exttool'}->{$type}) {
7072: $exttool{$type} = ' checked="checked"';
7073: }
7074: }
7075: }
1.432 raeburn 7076: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7077: foreach my $type (@types) {
7078: if ($settings->{'crsauthor'}->{$type}) {
7079: $crsauthor{$type} = ' checked="checked"';
7080: }
7081: }
7082: } else {
7083: foreach my $type (@types) {
7084: if ($staticdefaults{'crsauthor'}) {
7085: $crsauthor{$type} = ' checked="checked"';
7086: }
7087: }
7088: }
1.139 raeburn 7089: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7090: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7091: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7092: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7093: }
7094: }
1.428 raeburn 7095: if (ref($settings->{'coursequota'}) eq 'HASH') {
7096: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7097: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7098: }
7099: }
1.192 raeburn 7100: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7101: foreach my $type (@types) {
7102: next if ($type eq 'community');
7103: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7104: if ($defcredits{$type} ne '') {
7105: $currusecredits = 1;
7106: }
7107: }
7108: }
7109: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7110: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7111: $postsubmitclient = 0;
7112: foreach my $type (@types) {
7113: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7114: }
7115: } else {
7116: foreach my $type (@types) {
7117: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7118: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7119: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7120: } else {
7121: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7122: }
7123: } else {
7124: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7125: }
7126: }
7127: }
7128: } else {
7129: foreach my $type (@types) {
7130: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7131: }
7132: }
1.276 raeburn 7133: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7134: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7135: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7136: }
7137: } else {
7138: foreach my $type (@types) {
7139: $currmysql{$type} = $staticdefaults{'mysqltables'};
7140: }
7141: }
1.258 raeburn 7142: } else {
7143: foreach my $type (@types) {
7144: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7145: if ($staticdefaults{'domexttool'}) {
7146: $domexttool{$type} = ' checked="checked"';
7147: }
1.432 raeburn 7148: if ($staticdefaults{'crsauthor'}) {
7149: $crsauthor{$type} = ' checked="checked"';
7150: }
1.258 raeburn 7151: }
1.139 raeburn 7152: }
7153: if (!$currdefresponder) {
1.198 raeburn 7154: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7155: } elsif ($currdefresponder < 1) {
7156: $currdefresponder = 1;
7157: }
1.198 raeburn 7158: foreach my $type (@types) {
7159: if ($curruploadquota{$type} eq '') {
7160: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7161: }
1.428 raeburn 7162: if ($currcoursequota{$type} eq '') {
7163: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7164: }
1.198 raeburn 7165: }
1.139 raeburn 7166: $datatable .=
1.192 raeburn 7167: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7168: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7169: '</span></td>'.
7170: '<td class="LC_right_item"><span class="LC_nobreak">'.
7171: '<input type="text" name="anonsurvey_threshold"'.
7172: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7173: '</td></tr>'."\n";
7174: $itemcount ++;
7175: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7176: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7177: $choices{'uploadquota'}.
7178: '</span></td>'.
1.306 raeburn 7179: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7180: '<table><tr>';
1.198 raeburn 7181: foreach my $type (@types) {
1.306 raeburn 7182: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7183: '<input type="text" name="uploadquota_'.$type.'"'.
7184: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7185: }
7186: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7187: $itemcount ++;
1.428 raeburn 7188: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7189: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7190: $choices{'coursequota'}.
7191: '</span></td>'.
7192: '<td style="text-align: right" class="LC_right_item">'.
7193: '<table><tr>';
7194: foreach my $type (@types) {
7195: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7196: '<input type="text" name="coursequota_'.$type.'"'.
7197: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7198: }
7199: $datatable .= '</tr></table></td></tr>'."\n";
7200: $itemcount ++;
1.236 raeburn 7201: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7202: my $display = 'none';
1.192 raeburn 7203: if ($currusecredits) {
7204: $display = 'block';
7205: }
7206: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7207: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7208: foreach my $type (@types) {
7209: next if ($type eq 'community');
1.306 raeburn 7210: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7211: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7212: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7213: }
7214: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7215: %defaultchecked = ('coursecredits' => 'off');
7216: @toggles = ('coursecredits');
7217: my $current = {
7218: 'coursecredits' => $currusecredits,
7219: };
7220: (my $table,$itemcount) =
7221: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7222: \%choices,$itemcount,$onclick,$additional,'left');
7223: $datatable .= $table;
7224: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7225: my $display = 'none';
7226: if ($postsubmitclient) {
7227: $display = 'block';
7228: }
7229: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7230: &mt('Number of seconds submit is disabled').'<br />'.
7231: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7232: '<table><tr>';
1.257 raeburn 7233: foreach my $type (@types) {
1.306 raeburn 7234: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7235: '<input type="text" name="'.$type.'_timeout" value="'.
7236: $deftimeout{$type}.'" size="5" /></td>';
7237: }
7238: $additional .= '</tr></table></div>'."\n";
7239: %defaultchecked = ('postsubmit' => 'on');
7240: @toggles = ('postsubmit');
1.280 raeburn 7241: $current = {
7242: 'postsubmit' => $postsubmitclient,
7243: };
1.257 raeburn 7244: ($table,$itemcount) =
7245: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7246: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7247: $datatable .= $table;
1.276 raeburn 7248: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7249: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7250: $choices{'mysqltables'}.
7251: '</span></td>'.
1.306 raeburn 7252: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7253: '<table><tr>';
7254: foreach my $type (@types) {
1.306 raeburn 7255: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7256: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7257: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7258: }
7259: $datatable .= '</tr></table></td></tr>'."\n";
7260: $itemcount ++;
1.404 raeburn 7261: %defaultchecked = ('ltiauth' => 'off');
7262: @toggles = ('ltiauth');
7263: $current = {
7264: 'ltiauth' => $ltiauth,
7265: };
7266: ($table,$itemcount) =
7267: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7268: \%choices,$itemcount,undef,undef,'left');
7269: $datatable .= $table;
1.422 raeburn 7270: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7271: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7272: $choices{'domexttool'}.
7273: '</span></td>'.
7274: '<td style="text-align: right" class="LC_right_item">'.
7275: '<table><tr>';
7276: foreach my $type (@types) {
7277: $datatable .= '<td style="text-align: left">'.
7278: '<span class="LC_nobreak">'.
7279: '<input type="checkbox" name="domexttool"'.
7280: ' value="'.$type.'"'.$domexttool{$type}.' />'.
7281: &mt($type).'</span></td>'."\n";
7282: }
7283: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7284: $itemcount ++;
1.422 raeburn 7285: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7286: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7287: $choices{'exttool'}.
7288: '</span></td>'.
7289: '<td style="text-align: right" class="LC_right_item">'.
7290: '<table><tr>';
7291: foreach my $type (@types) {
7292: $datatable .= '<td style="text-align: left">'.
7293: '<span class="LC_nobreak">'.
7294: '<input type="checkbox" name="exttool"'.
7295: ' value="'.$type.'"'.$exttool{$type}.' />'.
7296: &mt($type).'</span></td>'."\n";
7297: }
7298: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7299: $itemcount ++;
7300: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7301: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7302: $choices{'crsauthor'}.
7303: '</span></td>'.
7304: '<td style="text-align: right" class="LC_right_item">'.
7305: '<table><tr>';
7306: foreach my $type (@types) {
7307: $datatable .= '<td style="text-align: left">'.
7308: '<span class="LC_nobreak">'.
7309: '<input type="checkbox" name="crsauthor"'.
7310: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
7311: &mt($type).'</span></td>'."\n";
7312: }
7313: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7314: }
1.192 raeburn 7315: $$rowtotal += $itemcount;
1.121 raeburn 7316: return $datatable;
1.118 jms 7317: }
7318:
1.429 raeburn 7319: sub print_authordefaults {
7320: my ($position,$dom,$settings,$rowtotal) = @_;
7321: my ($css_class,$datatable,%checkedon,%checkedoff);
7322: my $itemcount = 1;
7323: my %titles = &authordefaults_titles();
7324: if ($position eq 'top') {
7325: my %defaultchecked = (
7326: 'nocodemirror' => 'off',
7327: 'domcoordacc' => 'on',
7328: );
7329: my @toggles = ('nocodemirror','domcoordacc');
7330: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7331: \%titles,$itemcount);
7332: my %staticdefaults = (
7333: 'copyright' => 'default',
7334: 'sourceavail' => 'closed',
7335: );
7336: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7337: my %currrights;
7338: foreach my $item ('copyright','sourceavail') {
7339: $currrights{$item} = $staticdefaults{$item};
7340: if (ref($settings) eq 'HASH') {
7341: if (exists($settings->{$item})) {
7342: $currrights{$item} = $settings->{$item};
7343: }
7344: }
7345: }
7346: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7347: '<span class="LC_nobreak">'.$titles{'copyright'}.
7348: '</span></td><td class="LC_right_item">'.
7349: &selectbox('copyright',$currrights{'copyright'},'',
7350: \&Apache::loncommon::copyrightdescription,
7351: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7352: '</td></tr>'."\n";
7353: $itemcount ++;
7354: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7355: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7356: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7357: '</span></td><td class="LC_right_item">'.
7358: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7359: \&Apache::loncommon::source_copyrightdescription,
7360: (&Apache::loncommon::source_copyrightids)).
7361: '</td></tr>'."\n";
7362: } else {
7363: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7364: my $curreditors;
7365: my %staticdefaults = (
7366: editors => ['edit','xml'],
7367: authorquota => 500,
7368: webdav => 0,
7369: );
7370: my $curreditors = $staticdefaults{'editors'};
7371: if ((ref($settings) eq 'HASH') &&
7372: (ref($settings->{'editors'}) eq 'ARRAY')) {
7373: $curreditors = $settings->{'editors'};
7374: } else {
7375: $curreditors = $staticdefaults{'editors'};
7376: }
7377: my @editors = ('edit','xml','daxe');
7378: $datatable = '<tr'.$css_class.'>'."\n".
7379: '<td>'.$titles{'editors'}.'</td>'."\n".
7380: '<td class="LC_left_item">'."\n".
7381: '<span class="LC_nobreak">';
7382: foreach my $editor (@editors) {
7383: my $checked;
7384: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7385: $checked = ' checked="checked"';
7386: }
7387: $datatable .= '<label>'.
7388: '<input type="checkbox" name="author_editors" '.
7389: $checked.' value="'.$editor.'" '.
7390: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7391: $titles{$editor}.'</label> ';
7392: }
7393: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7394: $itemcount ++;
7395: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7396: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7397: my @insttypes;
7398: if (ref($types) eq 'ARRAY') {
7399: @insttypes = @{$types};
7400: }
7401: my $typecount = 0;
7402: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7403: my @items = ('webdav','authorquota');
7404: my %quotas;
7405: if (ref($domconf{'quotas'}) eq 'HASH') {
7406: %quotas = %{$domconf{'quotas'}};
7407: foreach my $item (@items) {
7408: if (ref($quotas{$item}) eq 'HASH') {
7409: foreach my $type (@insttypes,'default') {
7410: if ($item eq 'authorquota') {
7411: if ($quotas{$item}{$type} !~ /^\d+$/) {
7412: $quotas{$item}{$type} = $staticdefaults{$item};
7413: }
7414: } elsif ($item eq 'webdav') {
7415: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7416: $quotas{$item}{$type} = $staticdefaults{$item};
7417: }
7418: }
7419: }
7420: } else {
7421: foreach my $type (@insttypes,'default') {
7422: $quotas{$item}{$type} = $staticdefaults{$item};
7423: }
7424: }
7425: }
7426: } else {
7427: foreach my $item (@items) {
7428: foreach my $type (@insttypes,'default') {
7429: $quotas{$item}{$type} = $staticdefaults{$item};
7430: }
7431: }
7432: }
7433: if (ref($usertypes) eq 'HASH') {
7434: my $numinrow = 4;
7435: my $onclick = '';
7436: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7437: $numinrow,$othertitle,'authorquota',
7438: \$itemcount,$onclick);
7439: $itemcount ++;
7440: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7441: $numinrow,$othertitle,'webdav',
7442: \$itemcount);
7443: $itemcount ++;
7444: }
7445: my $checkedno = ' checked="checked"';
7446: my ($checkedon,$checkedoff);
7447: if (ref($quotas{'webdav'}) eq 'HASH') {
7448: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
7449: if ($quotas{'webdav'}{'_LC_adv'}) {
7450: $checkedon = $checkedno;
7451: } else {
7452: $checkedoff = $checkedno;
7453: }
7454: undef($checkedno);
7455: }
7456: }
7457: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7458: $datatable .= '<tr'.$css_class.'>'.
7459: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7460: $titles{'webdav_LC_adv_over'}.
7461: '</td>'.
7462: '<td class="LC_left_item">';
7463: foreach my $option ('none','off','on') {
7464: my ($text,$val,$checked);
7465: if ($option eq 'none') {
7466: $text = $titles{'none'};
7467: $val = '';
7468: $checked = $checkedno;
7469: } elsif ($option eq 'off') {
7470: $text = $titles{'overoff'};
7471: $val = 0;
7472: $checked = $checkedoff;
7473: } elsif ($option eq 'on') {
7474: $text = $titles{'overon'};
7475: $val = 1;
7476: $checked = $checkedon;
7477: }
7478: $datatable .= '<span class="LC_nobreak"><label>'.
7479: '<input type="radio" name="webdav_LC_adv"'.
7480: ' value="'.$val.'"'.$checked.' />'.
7481: $text.'</label></span> ';
7482: }
7483: $datatable .= '</td></tr>';
7484: $itemcount ++;
7485: }
7486: $$rowtotal += $itemcount;
7487: return $datatable;
7488: }
7489:
7490: sub authordefaults_titles {
7491: return &Apache::lonlocal::texthash(
7492: copyright => 'Copyright/Distribution',
7493: sourceavail => ' Source Available',
7494: editors => 'Available Editors',
7495: webdav => 'WebDAV',
7496: authorquota => 'Authoring Space quotas (MB)',
7497: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
7498: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7499: edit => 'Standard editor (Edit)',
7500: xml => 'Text editor (EditXML)',
7501: daxe => 'Daxe editor (Daxe)',
7502: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7503: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7504: none => 'No override set',
7505: overon => 'Override -- webDAV on',
7506: overoff => 'Override -- webDAV off',
7507: );
7508: }
7509:
7510: sub selectbox {
7511: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7512: my $selout = '<select name="'.$name.'">';
7513: foreach my $id (@idlist) {
7514: $selout.='<option value="'.$id.'"';
7515: if ($id eq $value) {
7516: $selout.=' selected="selected"';
7517: }
7518: if ($readonly) {
7519: $selout .= ' disabled="disabled"';
7520: }
7521: $selout.='>'.&{$functionref}($id).'</option>';
7522: }
7523: $selout.='</select>';
7524: return $selout;
7525: }
7526:
1.231 raeburn 7527: sub print_selfenrollment {
7528: my ($position,$dom,$settings,$rowtotal) = @_;
7529: my ($css_class,$datatable);
7530: my $itemcount = 1;
1.271 raeburn 7531: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7532: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7533: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7534: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7535: my @rows;
7536: my $key;
7537: if ($position eq 'top') {
7538: $key = 'admin';
7539: if (ref($rowsref) eq 'ARRAY') {
7540: @rows = @{$rowsref};
7541: }
7542: } elsif ($position eq 'middle') {
7543: $key = 'default';
7544: @rows = ('types','registered','approval','limit');
7545: }
7546: foreach my $row (@rows) {
7547: if (defined($titlesref->{$row})) {
7548: $itemcount ++;
7549: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7550: $datatable .= '<tr'.$css_class.'>'.
7551: '<td>'.$titlesref->{$row}.'</td>'.
7552: '<td class="LC_left_item">'.
7553: '<table><tr>';
7554: my (%current,%currentcap);
7555: if (ref($settings) eq 'HASH') {
7556: if (ref($settings->{$key}) eq 'HASH') {
7557: foreach my $type (@types) {
7558: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7559: $current{$type} = $settings->{$key}->{$type}->{$row};
7560: }
7561: if (($row eq 'limit') && ($key eq 'default')) {
7562: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7563: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7564: }
7565: }
7566: }
7567: }
7568: }
7569: my %roles = (
7570: '0' => &Apache::lonnet::plaintext('dc'),
7571: );
7572:
7573: foreach my $type (@types) {
7574: unless (($row eq 'registered') && ($key eq 'default')) {
7575: $datatable .= '<th>'.&mt($type).'</th>';
7576: }
7577: }
7578: unless (($row eq 'registered') && ($key eq 'default')) {
7579: $datatable .= '</tr><tr>';
7580: }
7581: foreach my $type (@types) {
7582: if ($type eq 'community') {
7583: $roles{'1'} = &mt('Community personnel');
7584: } else {
7585: $roles{'1'} = &mt('Course personnel');
7586: }
7587: $datatable .= '<td style="vertical-align: top">';
7588: if ($position eq 'top') {
7589: my %checked;
7590: if ($current{$type} eq '0') {
7591: $checked{'0'} = ' checked="checked"';
7592: } else {
7593: $checked{'1'} = ' checked="checked"';
7594: }
7595: foreach my $role ('1','0') {
7596: $datatable .= '<span class="LC_nobreak"><label>'.
7597: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7598: 'value="'.$role.'"'.$checked{$role}.' />'.
7599: $roles{$role}.'</label></span> ';
7600: }
7601: } else {
7602: if ($row eq 'types') {
7603: my %checked;
7604: if ($current{$type} =~ /^(all|dom)$/) {
7605: $checked{$1} = ' checked="checked"';
7606: } else {
7607: $checked{''} = ' checked="checked"';
7608: }
7609: foreach my $val ('','dom','all') {
7610: $datatable .= '<span class="LC_nobreak"><label>'.
7611: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7612: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7613: }
7614: } elsif ($row eq 'registered') {
7615: my %checked;
7616: if ($current{$type} eq '1') {
7617: $checked{'1'} = ' checked="checked"';
7618: } else {
7619: $checked{'0'} = ' checked="checked"';
7620: }
7621: foreach my $val ('0','1') {
7622: $datatable .= '<span class="LC_nobreak"><label>'.
7623: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7624: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7625: }
7626: } elsif ($row eq 'approval') {
7627: my %checked;
7628: if ($current{$type} =~ /^([12])$/) {
7629: $checked{$1} = ' checked="checked"';
7630: } else {
7631: $checked{'0'} = ' checked="checked"';
7632: }
7633: for my $val (0..2) {
7634: $datatable .= '<span class="LC_nobreak"><label>'.
7635: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7636: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7637: }
7638: } elsif ($row eq 'limit') {
7639: my %checked;
7640: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7641: $checked{$1} = ' checked="checked"';
7642: } else {
7643: $checked{'none'} = ' checked="checked"';
7644: }
7645: my $cap;
7646: if ($currentcap{$type} =~ /^\d+$/) {
7647: $cap = $currentcap{$type};
7648: }
7649: foreach my $val ('none','allstudents','selfenrolled') {
7650: $datatable .= '<span class="LC_nobreak"><label>'.
7651: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7652: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7653: }
7654: $datatable .= '<br />'.
7655: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7656: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7657: '</span>';
7658: }
7659: }
7660: $datatable .= '</td>';
7661: }
7662: $datatable .= '</tr>';
7663: }
7664: $datatable .= '</table></td></tr>';
7665: }
7666: } elsif ($position eq 'bottom') {
1.235 raeburn 7667: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7668: }
7669: $$rowtotal += $itemcount;
7670: return $datatable;
7671: }
7672:
7673: sub print_validation_rows {
7674: my ($caller,$dom,$settings,$rowtotal) = @_;
7675: my ($itemsref,$namesref,$fieldsref);
7676: if ($caller eq 'selfenroll') {
7677: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7678: } elsif ($caller eq 'requestcourses') {
7679: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7680: }
7681: my %currvalidation;
7682: if (ref($settings) eq 'HASH') {
7683: if (ref($settings->{'validation'}) eq 'HASH') {
7684: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7685: }
1.235 raeburn 7686: }
7687: my $datatable;
7688: my $itemcount = 0;
7689: foreach my $item (@{$itemsref}) {
7690: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7691: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7692: $namesref->{$item}.
7693: '</span></td>'.
7694: '<td class="LC_left_item">';
7695: if (($item eq 'url') || ($item eq 'button')) {
7696: $datatable .= '<span class="LC_nobreak">'.
7697: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7698: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7699: } elsif ($item eq 'fields') {
7700: my @currfields;
7701: if (ref($currvalidation{$item}) eq 'ARRAY') {
7702: @currfields = @{$currvalidation{$item}};
7703: }
7704: foreach my $field (@{$fieldsref}) {
7705: my $check = '';
7706: if (grep(/^\Q$field\E$/,@currfields)) {
7707: $check = ' checked="checked"';
7708: }
7709: $datatable .= '<span class="LC_nobreak"><label>'.
7710: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7711: ' value="'.$field.'"'.$check.' />'.$field.
7712: '</label></span> ';
7713: }
7714: } elsif ($item eq 'markup') {
1.334 raeburn 7715: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7716: $currvalidation{$item}.
1.231 raeburn 7717: '</textarea>';
1.235 raeburn 7718: }
7719: $datatable .= '</td></tr>'."\n";
7720: if (ref($rowtotal)) {
1.231 raeburn 7721: $itemcount ++;
7722: }
7723: }
1.235 raeburn 7724: if ($caller eq 'requestcourses') {
7725: my %currhash;
1.248 raeburn 7726: if (ref($settings) eq 'HASH') {
7727: if (ref($settings->{'validation'}) eq 'HASH') {
7728: if ($settings->{'validation'}{'dc'} ne '') {
7729: $currhash{$settings->{'validation'}{'dc'}} = 1;
7730: }
1.235 raeburn 7731: }
7732: }
7733: my $numinrow = 2;
7734: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7735: 'validationdc',%currhash);
1.247 raeburn 7736: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7737: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7738: if ($numdc > 1) {
1.247 raeburn 7739: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7740: } else {
1.247 raeburn 7741: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7742: }
1.247 raeburn 7743: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7744: $itemcount ++;
7745: }
7746: if (ref($rowtotal)) {
7747: $$rowtotal += $itemcount;
7748: }
1.231 raeburn 7749: return $datatable;
7750: }
7751:
1.357 raeburn 7752: sub print_privacy {
7753: my ($position,$dom,$settings,$rowtotal) = @_;
7754: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7755: my $itemcount = 0;
1.417 raeburn 7756: if ($position eq 'top') {
7757: $numinrow = 2;
7758: } else {
1.357 raeburn 7759: @items = ('domain','author','course','community');
7760: %names = &Apache::lonlocal::texthash (
7761: domain => 'Assigned domain role(s)',
7762: author => 'Assigned co-author role(s)',
7763: course => 'Assigned course role(s)',
1.416 raeburn 7764: community => 'Assigned community role(s)',
1.357 raeburn 7765: );
7766: $numinrow = 4;
7767: ($othertitle,$usertypes,$types) =
7768: &Apache::loncommon::sorted_inst_types($dom);
7769: }
7770: if (($position eq 'top') || ($position eq 'middle')) {
7771: my (%by_ip,%by_location,@intdoms,@instdoms);
7772: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7773: if ($position eq 'top') {
7774: my %curr;
7775: my @options = ('none','user','domain','auto');
7776: my %titles = &Apache::lonlocal::texthash (
7777: none => 'Not allowed',
7778: user => 'User authorizes',
7779: domain => 'DC authorizes',
7780: auto => 'Unrestricted',
7781: instdom => 'Other domain shares institution/provider',
7782: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7783: notify => 'Notify when role needs authorization',
1.357 raeburn 7784: );
7785: my %names = &Apache::lonlocal::texthash (
7786: domain => 'Domain role',
7787: author => 'Co-author role',
7788: course => 'Course role',
7789: community => 'Community role',
7790: );
7791: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7792: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7793: foreach my $domtype ('instdom','extdom') {
7794: my (%checked,$skip);
7795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7796: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7797: '<td class="LC_left_item">';
7798: if ($domtype eq 'instdom') {
7799: unless (@instdoms > 1) {
7800: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7801: $skip = 1;
7802: }
7803: } elsif ($domtype eq 'extdom') {
7804: if (keys(%by_location) == 0) {
7805: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7806: $skip = 1;
7807: }
7808: }
7809: unless ($skip) {
7810: foreach my $roletype ('domain','author','course','community') {
7811: $checked{'auto'} = ' checked="checked"';
7812: if (ref($settings) eq 'HASH') {
7813: if (ref($settings->{approval}) eq 'HASH') {
7814: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7815: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7816: $checked{$1} = ' checked="checked"';
7817: $checked{'auto'} = '';
7818: }
7819: }
7820: }
7821: }
7822: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7823: foreach my $option (@options) {
7824: $datatable .= '<span class="LC_nobreak"><label>'.
7825: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7826: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7827: '</label></span> ';
7828: }
7829: $datatable .= '</fieldset>';
7830: }
7831: }
7832: $datatable .= '</td></tr>';
7833: $itemcount ++;
7834: }
1.417 raeburn 7835: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7836: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7837: '<td class="LC_left_item">';
7838: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7839: my %curr;
7840: if (ref($settings) eq 'HASH') {
7841: if ($settings->{'notify'} ne '') {
7842: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7843: }
7844: }
7845: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7846: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7847: 'privacy_notify',%curr);
7848: if ($numdc > 0) {
7849: $datatable .= $table;
7850: } else {
7851: $datatable .= &mt('There are no active Domain Coordinators');
7852: }
7853: } else {
7854: $datatable .= &mt('Nothing to set here, as there are no other domains');
7855: }
7856: $datatable .='</td></tr>';
1.357 raeburn 7857: } elsif ($position eq 'middle') {
7858: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7859: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7860: foreach my $item (@{$types}) {
7861: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7862: $numinrow,$itemcount,'','','','','',
7863: '',$usertypes->{$item});
7864: $itemcount ++;
7865: }
7866: }
7867: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7868: $numinrow,$itemcount,'','','','','',
7869: '',$othertitle);
7870: $itemcount ++;
7871: } else {
1.360 raeburn 7872: my (@insttypes,%insttitles);
7873: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7874: @insttypes = @{$types};
7875: %insttitles = %{$usertypes};
7876: }
7877: foreach my $item (@insttypes,'default') {
7878: my $title;
7879: if ($item eq 'default') {
7880: $title = $othertitle;
7881: } else {
7882: $title = $insttitles{$item};
7883: }
7884: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7885: $datatable .= '<tr'.$css_class.'>'.
7886: '<td class="LC_left_item">'.$title.'</td>'.
7887: '<td class="LC_left_item">'.
7888: &mt('Nothing to set here, as there are no other domains').
7889: '</td></tr>';
7890: $itemcount ++;
7891: }
1.357 raeburn 7892: }
7893: }
7894: } else {
7895: my $prefix;
7896: if ($position eq 'lower') {
7897: $prefix = 'priv';
7898: } else {
7899: $prefix = 'unpriv';
7900: }
7901: foreach my $item (@items) {
7902: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7903: $numinrow,$itemcount,'','','','','',
7904: '',$names{$item});
7905: $itemcount ++;
7906: }
7907: }
7908: if (ref($rowtotal)) {
7909: $$rowtotal += $itemcount;
7910: }
7911: return $datatable;
7912: }
7913:
1.354 raeburn 7914: sub print_passwords {
7915: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7916: my ($datatable,$css_class);
7917: my $itemcount = 0;
7918: my %titles = &Apache::lonlocal::texthash (
7919: captcha => '"Forgot Password" CAPTCHA validation',
7920: link => 'Reset link expiration (hours)',
7921: case => 'Case-sensitive usernames/e-mail',
7922: prelink => 'Information required (form 1)',
7923: postlink => 'Information required (form 2)',
7924: emailsrc => 'LON-CAPA e-mail address type(s)',
7925: customtext => 'Domain specific text (HTML)',
7926: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7927: intauth_check => 'Check bcrypt cost if authenticated',
7928: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7929: permanent => 'Permanent e-mail address',
7930: critical => 'Critical notification address',
7931: notify => 'Notification address',
7932: min => 'Minimum password length',
7933: max => 'Maximum password length',
7934: chars => 'Required characters',
7935: expire => 'Password expiration (days)',
1.356 raeburn 7936: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7937: );
7938: if ($position eq 'top') {
7939: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7940: my $shownlinklife = 2;
7941: my $prelink = 'both';
7942: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7943: if (ref($settings) eq 'HASH') {
7944: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7945: $shownlinklife = $settings->{resetlink};
7946: }
7947: if (ref($settings->{resetcase}) eq 'ARRAY') {
7948: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7949: }
7950: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7951: $prelink = $settings->{resetprelink};
7952: }
7953: if (ref($settings->{resetpostlink}) eq 'HASH') {
7954: %postlink = %{$settings->{resetpostlink}};
7955: }
7956: if (ref($settings->{resetemail}) eq 'ARRAY') {
7957: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
7958: }
7959: if ($settings->{resetremove}) {
7960: $nostdtext = 1;
7961: }
7962: if ($settings->{resetcustom}) {
7963: $customurl = $settings->{resetcustom};
7964: }
7965: } else {
7966: if (ref($types) eq 'ARRAY') {
7967: foreach my $item (@{$types}) {
7968: $casesens{$item} = 1;
7969: $postlink{$item} = ['username','email'];
7970: }
7971: }
7972: $casesens{'default'} = 1;
7973: $postlink{'default'} = ['username','email'];
7974: $prelink = 'both';
7975: %emailsrc = (
7976: permanent => 1,
7977: critical => 1,
7978: notify => 1,
7979: );
7980: }
7981: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
7982: $itemcount ++;
7983: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7984: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
7985: '<td class="LC_left_item">'.
7986: '<input type="textbox" value="'.$shownlinklife.'" '.
7987: 'name="passwords_link" size="3" /></td></tr>';
7988: $itemcount ++;
7989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7990: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
7991: '<td class="LC_left_item">';
7992: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7993: foreach my $item (@{$types}) {
7994: my $checkedcase;
7995: if ($casesens{$item}) {
7996: $checkedcase = ' checked="checked"';
7997: }
7998: $datatable .= '<span class="LC_nobreak"><label>'.
7999: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8000: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8001: '</span> ';
1.354 raeburn 8002: }
8003: }
8004: my $checkedcase;
8005: if ($casesens{'default'}) {
8006: $checkedcase = ' checked="checked"';
8007: }
8008: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8009: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8010: $othertitle.'</label></span></td>';
8011: $itemcount ++;
8012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8013: my %checkedpre = (
8014: both => ' checked="checked"',
8015: either => '',
8016: );
8017: if ($prelink eq 'either') {
8018: $checkedpre{either} = ' checked="checked"';
8019: $checkedpre{both} = '';
8020: }
8021: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8022: '<td class="LC_left_item"><span class="LC_nobreak">'.
8023: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8024: &mt('Both username and e-mail address').'</label></span> '.
8025: '<span class="LC_nobreak"><label>'.
8026: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8027: &mt('Either username or e-mail address').'</label></span></td></tr>';
8028: $itemcount ++;
8029: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8030: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8031: '<td class="LC_left_item">';
8032: my %postlinked;
8033: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8034: foreach my $item (@{$types}) {
8035: undef(%postlinked);
8036: $datatable .= '<fieldset style="display: inline-block;">'.
8037: '<legend>'.$usertypes->{$item}.'</legend>';
8038: if (ref($postlink{$item}) eq 'ARRAY') {
8039: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8040: }
8041: foreach my $field ('email','username') {
8042: my $checked;
8043: if ($postlinked{$field}) {
8044: $checked = ' checked="checked"';
8045: }
8046: $datatable .= '<span class="LC_nobreak"><label>'.
8047: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8048: $field.'"'.$checked.' />'.$field.'</label>'.
8049: '<span> ';
8050: }
8051: $datatable .= '</fieldset>';
8052: }
8053: }
8054: if (ref($postlink{'default'}) eq 'ARRAY') {
8055: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8056: }
8057: $datatable .= '<fieldset style="display: inline-block;">'.
8058: '<legend>'.$othertitle.'</legend>';
8059: foreach my $field ('email','username') {
8060: my $checked;
8061: if ($postlinked{$field}) {
8062: $checked = ' checked="checked"';
8063: }
8064: $datatable .= '<span class="LC_nobreak"><label>'.
8065: '<input type="checkbox" name="passwords_postlink_default" value="'.
8066: $field.'"'.$checked.' />'.$field.'</label>'.
8067: '<span> ';
8068: }
8069: $datatable .= '</fieldset></td></tr>';
8070: $itemcount ++;
8071: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8072: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8073: '<td class="LC_left_item">';
8074: foreach my $type ('permanent','critical','notify') {
8075: my $checkedemail;
8076: if ($emailsrc{$type}) {
8077: $checkedemail = ' checked="checked"';
8078: }
8079: $datatable .= '<span class="LC_nobreak"><label>'.
8080: '<input type="checkbox" name="passwords_emailsrc" value="'.
8081: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8082: '<span> ';
8083: }
8084: $datatable .= '</td></tr>';
8085: $itemcount ++;
8086: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8087: my $switchserver = &check_switchserver($dom,$confname);
8088: my ($showstd,$noshowstd);
8089: if ($nostdtext) {
8090: $noshowstd = ' checked="checked"';
8091: } else {
8092: $showstd = ' checked="checked"';
8093: }
8094: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8095: '<td class="LC_left_item"><span class="LC_nobreak">'.
8096: &mt('Retain standard text:').
8097: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8098: &mt('Yes').'</label>'.' '.
8099: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8100: &mt('No').'</label></span><br />'.
8101: '<span class="LC_fontsize_small">'.
8102: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8103: &mt('Include custom text:');
8104: if ($customurl) {
1.369 raeburn 8105: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8106: undef,undef,undef,undef,'background-color:#ffffff');
8107: $datatable .= '<span class="LC_nobreak"> '.$link.
8108: '<label><input type="checkbox" name="passwords_custom_del"'.
8109: ' value="1" />'.&mt('Delete?').'</label></span>'.
8110: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8111: }
8112: if ($switchserver) {
8113: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8114: } else {
8115: $datatable .='<span class="LC_nobreak"> '.
8116: '<input type="file" name="passwords_customfile" /></span>';
8117: }
8118: $datatable .= '</td></tr>';
8119: } elsif ($position eq 'middle') {
8120: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8121: my @items = ('intauth_cost','intauth_check','intauth_switch');
8122: my %defaults;
8123: if (ref($domconf{'defaults'}) eq 'HASH') {
8124: %defaults = %{$domconf{'defaults'}};
8125: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8126: $defaults{'intauth_cost'} = 10;
8127: }
8128: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8129: $defaults{'intauth_check'} = 0;
8130: }
8131: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8132: $defaults{'intauth_switch'} = 0;
8133: }
8134: } else {
8135: %defaults = (
8136: 'intauth_cost' => 10,
8137: 'intauth_check' => 0,
8138: 'intauth_switch' => 0,
8139: );
8140: }
8141: foreach my $item (@items) {
8142: if ($itemcount%2) {
8143: $css_class = '';
8144: } else {
8145: $css_class = ' class="LC_odd_row" ';
8146: }
8147: $datatable .= '<tr'.$css_class.'>'.
8148: '<td><span class="LC_nobreak">'.$titles{$item}.
8149: '</span></td><td class="LC_left_item" colspan="3">';
8150: if ($item eq 'intauth_switch') {
8151: my @options = (0,1,2);
8152: my %optiondesc = &Apache::lonlocal::texthash (
8153: 0 => 'No',
8154: 1 => 'Yes',
8155: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8156: );
8157: $datatable .= '<table width="100%">';
8158: foreach my $option (@options) {
8159: my $checked = ' ';
8160: if ($defaults{$item} eq $option) {
8161: $checked = ' checked="checked"';
8162: }
8163: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8164: '<label><input type="radio" name="'.$item.
8165: '" value="'.$option.'"'.$checked.' />'.
8166: $optiondesc{$option}.'</label></span></td></tr>';
8167: }
8168: $datatable .= '</table>';
8169: } elsif ($item eq 'intauth_check') {
8170: my @options = (0,1,2);
8171: my %optiondesc = &Apache::lonlocal::texthash (
8172: 0 => 'No',
8173: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8174: 2 => 'Yes, disallow login if stored cost is less than domain default',
8175: );
8176: $datatable .= '<table width="100%">';
8177: foreach my $option (@options) {
8178: my $checked = ' ';
8179: my $onclick;
8180: if ($defaults{$item} eq $option) {
8181: $checked = ' checked="checked"';
8182: }
8183: if ($option == 2) {
8184: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8185: }
8186: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8187: '<label><input type="radio" name="'.$item.
8188: '" value="'.$option.'"'.$checked.$onclick.' />'.
8189: $optiondesc{$option}.'</label></span></td></tr>';
8190: }
8191: $datatable .= '</table>';
8192: } else {
8193: $datatable .= '<input type="text" name="'.$item.'" value="'.
8194: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8195: }
8196: $datatable .= '</td></tr>';
8197: $itemcount ++;
8198: }
8199: } elsif ($position eq 'lower') {
1.405 raeburn 8200: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8201: } else {
1.359 raeburn 8202: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8203: my %ownerchg = (
8204: by => {},
8205: for => {},
8206: );
8207: my %ownertitles = &Apache::lonlocal::texthash (
8208: by => 'Course owner status(es) allowed',
8209: for => 'Student status(es) allowed',
8210: );
1.354 raeburn 8211: if (ref($settings) eq 'HASH') {
1.359 raeburn 8212: if (ref($settings->{crsownerchg}) eq 'HASH') {
8213: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8214: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8215: }
8216: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8217: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8218: }
1.354 raeburn 8219: }
8220: }
8221: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8222: $datatable .= '<tr '.$css_class.'>'.
8223: '<td>'.
8224: &mt('Requirements').'<ul>'.
1.359 raeburn 8225: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8226: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8227: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8228: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8229: '</ul>'.
8230: '</td>'.
1.359 raeburn 8231: '<td class="LC_left_item">';
8232: foreach my $item ('by','for') {
8233: $datatable .= '<fieldset style="display: inline-block;">'.
8234: '<legend>'.$ownertitles{$item}.'</legend>';
8235: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8236: foreach my $type (@{$types}) {
8237: my $checked;
8238: if ($ownerchg{$item}{$type}) {
8239: $checked = ' checked="checked"';
8240: }
8241: $datatable .= '<span class="LC_nobreak"><label>'.
8242: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8243: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8244: '</span> ';
1.359 raeburn 8245: }
8246: }
8247: my $checked;
8248: if ($ownerchg{$item}{'default'}) {
8249: $checked = ' checked="checked"';
8250: }
8251: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8252: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8253: $othertitle.'</label></span></fieldset>';
8254: }
8255: $datatable .= '</td></tr>';
1.354 raeburn 8256: }
8257: return $datatable;
8258: }
8259:
1.405 raeburn 8260: sub password_rules {
8261: my ($prefix,$itemcountref,$settings) = @_;
8262: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8263: my %titles;
8264: if ($prefix eq 'passwords') {
8265: %titles = &Apache::lonlocal::texthash (
8266: min => 'Minimum password length',
8267: max => 'Maximum password length',
8268: chars => 'Required characters',
8269: );
1.421 raeburn 8270: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8271: %titles = &Apache::lonlocal::texthash (
8272: min => 'Minimum secret length',
8273: max => 'Maximum secret length',
8274: chars => 'Required characters',
8275: );
8276: }
8277: $min = $Apache::lonnet::passwdmin;
8278: my $datatable;
8279: my $itemcount;
8280: if (ref($itemcountref)) {
8281: $itemcount = $$itemcountref;
8282: }
8283: if (ref($settings) eq 'HASH') {
8284: if ($settings->{min}) {
8285: $min = $settings->{min};
8286: }
8287: if ($settings->{max}) {
8288: $max = $settings->{max};
8289: }
8290: if (ref($settings->{chars}) eq 'ARRAY') {
8291: map { $chars{$_} = 1; } (@{$settings->{chars}});
8292: }
1.425 raeburn 8293: if ($prefix eq 'passwords') {
1.405 raeburn 8294: if ($settings->{expire}) {
8295: $expire = $settings->{expire};
8296: }
8297: if ($settings->{numsaved}) {
8298: $numsaved = $settings->{numsaved};
8299: }
8300: }
8301: }
8302: my %rulenames = &Apache::lonlocal::texthash(
8303: uc => 'At least one upper case letter',
8304: lc => 'At least one lower case letter',
8305: num => 'At least one number',
8306: spec => 'At least one non-alphanumeric',
8307: );
8308: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8309: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8310: '<td class="LC_left_item"><span class="LC_nobreak">'.
8311: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8312: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8313: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8314: '</span></td></tr>';
8315: $itemcount ++;
8316: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8317: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8318: '<td class="LC_left_item"><span class="LC_nobreak">'.
8319: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8320: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8321: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8322: '</span></td></tr>';
8323: $itemcount ++;
8324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8325: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8326: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8327: '</span></td>';
8328: my $numinrow = 2;
8329: my @possrules = ('uc','lc','num','spec');
8330: $datatable .= '<td class="LC_left_item"><table>';
8331: for (my $i=0; $i<@possrules; $i++) {
8332: my ($rem,$checked);
8333: if ($chars{$possrules[$i]}) {
8334: $checked = ' checked="checked"';
8335: }
8336: $rem = $i%($numinrow);
8337: if ($rem == 0) {
8338: if ($i > 0) {
8339: $datatable .= '</tr>';
8340: }
8341: $datatable .= '<tr>';
8342: }
8343: $datatable .= '<td><span class="LC_nobreak"><label>'.
8344: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8345: $rulenames{$possrules[$i]}.'</label></span></td>';
8346: }
8347: my $rem = @possrules%($numinrow);
8348: my $colsleft = $numinrow - $rem;
8349: if ($colsleft > 1 ) {
8350: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8351: ' </td>';
8352: } elsif ($colsleft == 1) {
8353: $datatable .= '<td class="LC_left_item"> </td>';
8354: }
8355: $datatable .='</table></td></tr>';
8356: $itemcount ++;
8357: if ($prefix eq 'passwords') {
8358: $titles{'expire'} = &mt('Password expiration (days)');
8359: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8360: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8361: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8362: '<td class="LC_left_item"><span class="LC_nobreak">'.
8363: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8364: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8365: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8366: '</span></td></tr>';
8367: $itemcount ++;
8368: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8369: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8370: '<td class="LC_left_item"><span class="LC_nobreak">'.
8371: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8372: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8373: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8374: '</span></td></tr>';
8375: $itemcount ++;
8376: }
8377: if (ref($itemcountref)) {
8378: $$itemcountref += $itemcount;
8379: }
8380: return $datatable;
8381: }
8382:
1.373 raeburn 8383: sub print_wafproxy {
8384: my ($position,$dom,$settings,$rowtotal) = @_;
8385: my $css_class;
8386: my $itemcount = 0;
8387: my $datatable;
8388: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8389: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8390: my %lt = &wafproxy_titles();
1.373 raeburn 8391: foreach my $server (sort(keys(%servers))) {
8392: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8393: next if ($serverhome eq '');
1.373 raeburn 8394: my $serverdom;
8395: if ($serverhome ne $server) {
8396: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8397: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8398: $othercontrol{$server} = $serverdom;
8399: }
1.373 raeburn 8400: } else {
8401: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8402: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8403: if ($serverdom ne $dom) {
8404: $othercontrol{$server} = $serverdom;
8405: } else {
8406: $setdom = 1;
8407: if (ref($settings) eq 'HASH') {
8408: if (ref($settings->{'alias'}) eq 'HASH') {
8409: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8410: if ($aliases{$dom} ne '') {
8411: $showdom = 1;
8412: }
1.373 raeburn 8413: }
1.388 raeburn 8414: if (ref($settings->{'saml'}) eq 'HASH') {
8415: $saml{$dom} = $settings->{'saml'};
8416: }
1.373 raeburn 8417: }
8418: }
8419: }
8420: }
1.381 raeburn 8421: if ($setdom) {
8422: %{$values{$dom}} = ();
8423: if (ref($settings) eq 'HASH') {
8424: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8425: $values{$dom}{$item} = $settings->{$item};
8426: }
8427: }
8428: }
1.373 raeburn 8429: if (keys(%othercontrol)) {
8430: %otherdoms = reverse(%othercontrol);
8431: foreach my $domain (keys(%otherdoms)) {
8432: %{$values{$domain}} = ();
8433: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8434: if (ref($config{'wafproxy'}) eq 'HASH') {
8435: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8436: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8437: $saml{$domain} = $config{'wafproxy'}{'saml'};
8438: }
1.383 raeburn 8439: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8440: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8441: }
8442: }
8443: }
8444: }
8445: if ($position eq 'top') {
8446: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8447: my %aliasinfo;
1.373 raeburn 8448: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8449: $itemcount ++;
8450: my $dom_in_effect;
8451: my $aliasrows = '<tr>'.
1.383 raeburn 8452: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8453: &mt('Hostname').': '.
8454: '<span class="LC_nobreak LC_cusr_emph">'.
8455: &Apache::lonnet::hostname($server).
8456: '</span></td><td> </td>';
1.373 raeburn 8457: if ($othercontrol{$server}) {
1.381 raeburn 8458: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8459: my ($current,$forsaml);
1.383 raeburn 8460: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8461: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8462: }
1.388 raeburn 8463: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8464: if ($saml{$dom_in_effect}{$server}) {
8465: $forsaml = 1;
8466: }
8467: }
1.383 raeburn 8468: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8469: &mt('Alias').': ';
1.373 raeburn 8470: if ($current) {
1.381 raeburn 8471: $aliasrows .= $current;
1.388 raeburn 8472: if ($forsaml) {
1.396 raeburn 8473: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8474: }
1.373 raeburn 8475: } else {
1.383 raeburn 8476: $aliasrows .= &mt('None');
1.373 raeburn 8477: }
1.383 raeburn 8478: $aliasrows .= ' <span class="LC_small">('.
8479: &mt('controlled by domain: [_1]',
8480: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8481: } else {
1.381 raeburn 8482: $dom_in_effect = $dom;
1.388 raeburn 8483: my ($current,$samlon,$samloff);
8484: $samloff = ' checked="checked"';
1.373 raeburn 8485: if (ref($aliases{$dom}) eq 'HASH') {
8486: if ($aliases{$dom}{$server}) {
8487: $current = $aliases{$dom}{$server};
8488: }
8489: }
1.388 raeburn 8490: if (ref($saml{$dom}) eq 'HASH') {
8491: if ($saml{$dom}{$server}) {
8492: $samlon = $samloff;
8493: undef($samloff);
8494: }
8495: }
1.383 raeburn 8496: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8497: &mt('Alias').': '.
1.381 raeburn 8498: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8499: 'value="'.$current.'" size="30" />'.
8500: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8501: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8502: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8503: &mt('No').'</label> <label>'.
1.388 raeburn 8504: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8505: &mt('Yes').'</label></span>'.
1.425 raeburn 8506: '</td>';
1.381 raeburn 8507: }
8508: $aliasrows .= '</tr>';
8509: $aliasinfo{$dom_in_effect} .= $aliasrows;
8510: }
8511: if ($aliasinfo{$dom}) {
8512: my ($onclick,$wafon,$wafoff,$showtable);
8513: $onclick = ' onclick="javascript:toggleWAF();"';
8514: $wafoff = ' checked="checked"';
8515: $showtable = ' style="display:none";';
8516: if ($showdom) {
8517: $wafon = $wafoff;
8518: $wafoff = '';
8519: $showtable = ' style="display:inline;"';
8520: }
8521: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8522: $datatable = '<tr'.$css_class.'>'.
8523: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8524: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8525: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8526: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8527: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8528: &mt('No').'</label></span></td>'.
8529: '<td class="LC_left_item">'.
8530: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8531: '</table></td></tr>';
8532: $itemcount++;
8533: }
1.383 raeburn 8534: if (keys(%otherdoms)) {
8535: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8536: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8537: $datatable .= '<tr'.$css_class.'>'.
8538: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8539: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8540: '</table></td></tr>';
1.381 raeburn 8541: $itemcount++;
1.373 raeburn 8542: }
8543: }
8544: } else {
1.383 raeburn 8545: my %ip_methods = &remoteip_methods();
1.373 raeburn 8546: if ($setdom) {
8547: $itemcount ++;
8548: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8549: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8550: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8551: $wafstyle = ' style="display:none;"';
8552: $nowafstyle = ' style="display:table-row;"';
8553: $currwafdisplay = ' style="display: none"';
8554: $wafrangestyle = ' style="display: none"';
8555: $curr_remotip = 'n';
1.382 raeburn 8556: $ssltossl = ' checked="checked"';
1.381 raeburn 8557: if ($showdom) {
8558: $wafstyle = ' style="display:table-row;"';
8559: $nowafstyle = ' style="display:none;"';
8560: if (keys(%{$values{$dom}})) {
8561: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8562: $curr_remotip = $values{$dom}{remoteip};
8563: }
8564: if ($curr_remotip eq 'h') {
8565: $currwafdisplay = ' style="display:table-row"';
8566: $wafrangestyle = ' style="display:inline-block;"';
8567: }
1.382 raeburn 8568: if ($values{$dom}{'sslopt'}) {
8569: $alltossl = ' checked="checked"';
8570: $ssltossl = '';
8571: }
1.381 raeburn 8572: }
8573: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8574: $vpndircheck = ' checked="checked"';
8575: $currwafvpn = ' style="display:table-row;"';
8576: $wafrangestyle = ' style="display:inline-block;"';
8577: } else {
8578: $vpnaliascheck = ' checked="checked"';
8579: $currwafvpn = ' style="display:none;"';
8580: }
8581: }
8582: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8583: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8584: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8585: '</tr>'.
8586: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8587: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8588: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8589: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8590: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8591: '<td class="LC_left_item"><table>'.
8592: '<tr>'.
8593: '<td valign="top">'.$lt{'remoteip'}.': '.
8594: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8595: foreach my $option ('m','h','n') {
8596: my $sel;
8597: if ($option eq $curr_remotip) {
8598: $sel = ' selected="selected"';
8599: }
8600: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8601: $ip_methods{$option}.'</option>';
8602: }
8603: $datatable .= '</select></td></tr>'."\n".
8604: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8605: $lt{'ipheader'}.': '.
8606: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8607: 'name="wafproxy_ipheader" />'.
8608: '</td></tr>'."\n".
8609: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8610: $lt{'trusted'}.':<br />'.
1.381 raeburn 8611: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8612: $values{$dom}{'trusted'}.'</textarea>'.
8613: '</td></tr>'."\n".
8614: '<tr><td><hr /></td></tr>'."\n".
8615: '<tr>'.
8616: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8617: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8618: $lt{'vpndirect'}.'</label>'.(' 'x2).
8619: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8620: $lt{'vpnaliased'}.'</label></span></td></tr>';
8621: foreach my $item ('vpnint','vpnext') {
8622: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8623: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8624: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8625: $values{$dom}{$item}.'</textarea>'.
8626: '</td></tr>'."\n";
1.373 raeburn 8627: }
1.382 raeburn 8628: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8629: '<tr>'.
8630: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8631: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8632: $lt{'alltossl'}.'</label>'.(' 'x2).
8633: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8634: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8635: '</table></td></tr>';
1.373 raeburn 8636: }
8637: if (keys(%otherdoms)) {
8638: foreach my $domain (sort(keys(%otherdoms))) {
8639: $itemcount ++;
8640: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8641: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8642: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8643: '<td class="LC_left_item"><table>';
1.382 raeburn 8644: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8645: my $showval = &mt('None');
1.382 raeburn 8646: if ($item eq 'ssl') {
8647: $showval = $lt{'ssltossl'};
8648: }
1.373 raeburn 8649: if ($values{$domain}{$item}) {
1.381 raeburn 8650: $showval = $values{$domain}{$item};
1.382 raeburn 8651: if ($item eq 'ssl') {
8652: $showval = $lt{'alltossl'};
1.383 raeburn 8653: } elsif ($item eq 'remoteip') {
8654: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8655: }
1.373 raeburn 8656: }
8657: $datatable .= '<tr>'.
8658: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8659: }
1.381 raeburn 8660: $datatable .= '</table></td></tr>';
1.373 raeburn 8661: }
8662: }
8663: }
8664: $$rowtotal += $itemcount;
8665: return $datatable;
8666: }
8667:
8668: sub wafproxy_titles {
8669: return &Apache::lonlocal::texthash(
1.381 raeburn 8670: remoteip => "Method for determining user's IP",
8671: ipheader => 'Request header containing remote IP',
8672: trusted => 'Trusted IP range(s)',
8673: vpnaccess => 'Access from institutional VPN',
8674: vpndirect => 'via regular hostname (no WAF)',
8675: vpnaliased => 'via aliased hostname (WAF)',
8676: vpnint => 'Internal IP Range(s) for VPN sessions',
8677: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8678: sslopt => 'Forwarding http/https',
1.381 raeburn 8679: alltossl => 'WAF forwards both http and https requests to https',
8680: ssltossl => 'WAF forwards http requests to http and https to https',
8681: );
8682: }
8683:
8684: sub remoteip_methods {
8685: return &Apache::lonlocal::texthash(
8686: m => 'Use Apache mod_remoteip',
8687: h => 'Use headers parsed by LON-CAPA',
8688: n => 'Not in use',
1.373 raeburn 8689: );
8690: }
8691:
1.137 raeburn 8692: sub print_usersessions {
8693: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8694: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8695: my (%by_ip,%by_location,@intdoms,@instdoms);
8696: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8697:
8698: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8699: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8700: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8701: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8702: if ($position eq 'top') {
1.152 raeburn 8703: if (keys(%serverhomes) > 1) {
1.145 raeburn 8704: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8705: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8706: if (ref($settings) eq 'HASH') {
8707: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8708: $curroffloadnow = $settings->{'offloadnow'};
8709: }
1.371 raeburn 8710: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8711: $curroffloadoth = $settings->{'offloadoth'};
8712: }
1.261 raeburn 8713: }
1.371 raeburn 8714: my $other_insts = scalar(keys(%by_location));
8715: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8716: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8717: } else {
1.140 raeburn 8718: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8719: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8720: '</td></tr>';
1.140 raeburn 8721: }
1.137 raeburn 8722: } else {
1.279 raeburn 8723: my %titles = &usersession_titles();
8724: my ($prefix,@types);
8725: if ($position eq 'bottom') {
8726: $prefix = 'remote';
8727: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8728: } else {
1.279 raeburn 8729: $prefix = 'hosted';
8730: @types = ('excludedomain','includedomain');
8731: }
8732: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8733: }
8734: $$rowtotal += $itemcount;
8735: return $datatable;
8736: }
8737:
8738: sub rules_by_location {
8739: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8740: my ($datatable,$itemcount,$css_class);
8741: if (keys(%{$by_location}) == 0) {
8742: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8743: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8744: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8745: '</td></tr>';
8746: $itemcount = 1;
8747: } else {
8748: $itemcount = 0;
8749: my $numinrow = 5;
8750: my (%current,%checkedon,%checkedoff);
8751: my @locations = sort(keys(%{$by_location}));
8752: foreach my $type (@{$types}) {
8753: $checkedon{$type} = '';
8754: $checkedoff{$type} = ' checked="checked"';
8755: }
8756: if (ref($settings) eq 'HASH') {
8757: if (ref($settings->{$prefix}) eq 'HASH') {
8758: foreach my $key (keys(%{$settings->{$prefix}})) {
8759: $current{$key} = $settings->{$prefix}{$key};
8760: if ($key eq 'version') {
8761: if ($current{$key} ne '') {
1.145 raeburn 8762: $checkedon{$key} = ' checked="checked"';
8763: $checkedoff{$key} = '';
8764: }
1.279 raeburn 8765: } elsif (ref($current{$key}) eq 'ARRAY') {
8766: $checkedon{$key} = ' checked="checked"';
8767: $checkedoff{$key} = '';
1.137 raeburn 8768: }
8769: }
8770: }
1.279 raeburn 8771: }
8772: foreach my $type (@{$types}) {
8773: next if ($type ne 'version' && !@locations);
8774: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8775: $datatable .= '<tr'.$css_class.'>
8776: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8777: <span class="LC_nobreak">
8778: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8779: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8780: if ($type eq 'version') {
8781: my @lcversions = &Apache::lonnet::all_loncaparevs();
8782: my $selector = '<select name="'.$prefix.'_version">';
8783: foreach my $version (@lcversions) {
8784: my $selected = '';
8785: if ($current{'version'} eq $version) {
8786: $selected = ' selected="selected"';
1.145 raeburn 8787: }
1.279 raeburn 8788: $selector .= ' <option value="'.$version.'"'.
8789: $selected.'>'.$version.'</option>';
8790: }
8791: $selector .= '</select> ';
8792: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8793: } else {
8794: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8795: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8796: ' />'.(' 'x2).
8797: '<input type="button" value="'.&mt('uncheck all').'" '.
8798: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8799: "\n".
8800: '</div><div><table>';
8801: my $rem;
8802: for (my $i=0; $i<@locations; $i++) {
8803: my ($showloc,$value,$checkedtype);
8804: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8805: my $ip = $by_location->{$locations[$i]}->[0];
8806: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8807: $value = join(':',@{$by_ip->{$ip}});
8808: $showloc = join(', ',@{$by_ip->{$ip}});
8809: if (ref($current{$type}) eq 'ARRAY') {
8810: foreach my $loc (@{$by_ip->{$ip}}) {
8811: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8812: $checkedtype = ' checked="checked"';
8813: last;
1.145 raeburn 8814: }
1.138 raeburn 8815: }
8816: }
8817: }
1.137 raeburn 8818: }
1.279 raeburn 8819: $rem = $i%($numinrow);
8820: if ($rem == 0) {
8821: if ($i > 0) {
8822: $datatable .= '</tr>';
8823: }
8824: $datatable .= '<tr>';
8825: }
8826: $datatable .= '<td class="LC_left_item">'.
8827: '<span class="LC_nobreak"><label>'.
8828: '<input type="checkbox" name="'.$prefix.'_'.$type.
8829: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8830: '</label></span></td>';
8831: }
8832: $rem = @locations%($numinrow);
8833: my $colsleft = $numinrow - $rem;
8834: if ($colsleft > 1 ) {
8835: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8836: ' </td>';
8837: } elsif ($colsleft == 1) {
8838: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8839: }
1.279 raeburn 8840: $datatable .= '</tr></table>';
1.137 raeburn 8841: }
1.279 raeburn 8842: $datatable .= '</td></tr>';
8843: $itemcount ++;
1.137 raeburn 8844: }
8845: }
1.279 raeburn 8846: return ($datatable,$itemcount);
1.137 raeburn 8847: }
8848:
1.275 raeburn 8849: sub print_ssl {
8850: my ($position,$dom,$settings,$rowtotal) = @_;
8851: my ($css_class,$datatable);
8852: my $itemcount = 1;
8853: if ($position eq 'top') {
1.281 raeburn 8854: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8855: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8856: my $same_institution;
8857: if ($intdom ne '') {
8858: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8859: if (ref($internet_names) eq 'ARRAY') {
8860: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8861: $same_institution = 1;
8862: }
8863: }
8864: }
1.275 raeburn 8865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8866: $datatable = '<tr'.$css_class.'><td colspan="2">';
8867: if ($same_institution) {
8868: my %domservers = &Apache::lonnet::get_servers($dom);
8869: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8870: } else {
8871: $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.");
8872: }
8873: $datatable .= '</td></tr>';
1.275 raeburn 8874: $itemcount ++;
8875: } else {
8876: my %titles = &ssl_titles();
8877: my (%by_ip,%by_location,@intdoms,@instdoms);
8878: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8879: my @alldoms = &Apache::lonnet::all_domains();
8880: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8881: my @domservers = &Apache::lonnet::get_servers($dom);
8882: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8883: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8884: if (($position eq 'connto') || ($position eq 'connfrom')) {
8885: my $legacy;
8886: unless (ref($settings) eq 'HASH') {
8887: my $name;
8888: if ($position eq 'connto') {
8889: $name = 'loncAllowInsecure';
8890: } else {
8891: $name = 'londAllowInsecure';
8892: }
8893: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8894: my @ids=&Apache::lonnet::current_machine_ids();
8895: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8896: my %what = (
8897: $name => 1,
8898: );
8899: my ($result,$returnhash) =
8900: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8901: if ($result eq 'ok') {
8902: if (ref($returnhash) eq 'HASH') {
8903: $legacy = $returnhash->{$name};
8904: }
8905: }
8906: } else {
8907: $legacy = $Apache::lonnet::perlvar{$name};
8908: }
8909: }
1.275 raeburn 8910: foreach my $type ('dom','intdom','other') {
8911: my %checked;
8912: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8913: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8914: '<td class="LC_right_item">';
8915: my $skip;
8916: if ($type eq 'dom') {
8917: unless (keys(%servers) > 1) {
8918: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8919: $skip = 1;
8920: }
8921: }
8922: if ($type eq 'intdom') {
8923: unless (@instdoms > 1) {
8924: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8925: $skip = 1;
8926: }
8927: } elsif ($type eq 'other') {
8928: if (keys(%by_location) == 0) {
8929: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8930: $skip = 1;
8931: }
8932: }
8933: unless ($skip) {
8934: $checked{'yes'} = ' checked="checked"';
8935: if (ref($settings) eq 'HASH') {
1.293 raeburn 8936: if (ref($settings->{$position}) eq 'HASH') {
8937: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8938: $checked{$1} = $checked{'yes'};
8939: delete($checked{'yes'});
8940: }
8941: }
1.293 raeburn 8942: } else {
8943: if ($legacy == 0) {
8944: $checked{'req'} = $checked{'yes'};
8945: delete($checked{'yes'});
8946: }
1.275 raeburn 8947: }
8948: foreach my $option ('no','yes','req') {
8949: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8950: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8951: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8952: '</label></span>'.(' 'x2);
8953: }
8954: }
8955: $datatable .= '</td></tr>';
8956: $itemcount ++;
8957: }
8958: } else {
8959: my $prefix = 'replication';
8960: my @types = ('certreq','nocertreq');
1.279 raeburn 8961: if (keys(%by_location) == 0) {
8962: $datatable .= '<tr'.$css_class.'><td>'.
8963: &mt('Nothing to set here, as there are no other institutions').
8964: '</td></tr>';
8965: $itemcount ++;
1.275 raeburn 8966: } else {
1.279 raeburn 8967: ($datatable,$itemcount) =
8968: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 8969: }
8970: }
8971: }
8972: $$rowtotal += $itemcount;
8973: return $datatable;
8974: }
8975:
8976: sub ssl_titles {
8977: return &Apache::lonlocal::texthash (
8978: dom => 'LON-CAPA servers/VMs from same domain',
8979: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
8980: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 8981: connto => 'Connections to other servers',
8982: connfrom => 'Connections from other servers',
1.275 raeburn 8983: replication => 'Replicating content to other institutions',
8984: certreq => 'Client certificate required, but specific domains exempt',
8985: nocertreq => 'No client certificate required, except for specific domains',
8986: no => 'SSL not used',
8987: yes => 'SSL Optional (used if available)',
8988: req => 'SSL Required',
8989: );
1.279 raeburn 8990: }
8991:
8992: sub print_trust {
8993: my ($prefix,$dom,$settings,$rowtotal) = @_;
8994: my ($css_class,$datatable,%checked,%choices);
8995: my (%by_ip,%by_location,@intdoms,@instdoms);
8996: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8997: my $itemcount = 1;
8998: my %titles = &trust_titles();
8999: my @types = ('exc','inc');
9000: if ($prefix eq 'top') {
9001: $prefix = 'content';
9002: } elsif ($prefix eq 'bottom') {
9003: $prefix = 'msg';
9004: }
9005: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9006: $$rowtotal += $itemcount;
9007: return $datatable;
9008: }
9009:
9010: sub trust_titles {
9011: return &Apache::lonlocal::texthash(
9012: content => "Access to this domain's content by others",
9013: shared => "Access to other domain's content by this domain",
9014: enroll => "Enrollment in this domain's courses by others",
9015: othcoau => "Co-author roles in this domain for others",
9016: coaurem => "Co-author roles for this domain's users elsewhere",
9017: domroles => "Domain roles in this domain assignable to others",
9018: catalog => "Course Catalog for this domain displayed elsewhere",
9019: reqcrs => "Requests for creation of courses in this domain by others",
9020: msg => "Users in other domains can send messages to this domain",
9021: exc => "Allow all, but exclude specific domains",
9022: inc => "Deny all, but include specific domains",
9023: );
1.275 raeburn 9024: }
9025:
1.138 raeburn 9026: sub build_location_hashes {
1.275 raeburn 9027: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9028: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9029: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9030: my %iphost = &Apache::lonnet::get_iphost();
9031: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9032: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9033: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9034: foreach my $id (@{$iphost{$primary_ip}}) {
9035: my $intdom = &Apache::lonnet::internet_dom($id);
9036: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9037: push(@{$intdoms},$intdom);
9038: }
9039: }
9040: }
9041: foreach my $ip (keys(%iphost)) {
9042: if (ref($iphost{$ip}) eq 'ARRAY') {
9043: foreach my $id (@{$iphost{$ip}}) {
9044: my $location = &Apache::lonnet::internet_dom($id);
9045: if ($location) {
1.275 raeburn 9046: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9047: my $dom = &Apache::lonnet::host_domain($id);
9048: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9049: push(@{$instdoms},$dom);
9050: }
9051: next;
9052: }
1.138 raeburn 9053: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9054: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9055: push(@{$by_ip->{$ip}},$location);
9056: }
9057: } else {
9058: $by_ip->{$ip} = [$location];
9059: }
9060: }
9061: }
9062: }
9063: }
9064: foreach my $ip (sort(keys(%{$by_ip}))) {
9065: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9066: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9067: my $first = $by_ip->{$ip}->[0];
9068: if (ref($by_location->{$first}) eq 'ARRAY') {
9069: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9070: push(@{$by_location->{$first}},$ip);
9071: }
9072: } else {
9073: $by_location->{$first} = [$ip];
9074: }
9075: }
9076: }
9077: return;
9078: }
9079:
1.145 raeburn 9080: sub current_offloads_to {
9081: my ($dom,$settings,$servers) = @_;
9082: my (%spareid,%otherdomconfigs);
1.152 raeburn 9083: if (ref($servers) eq 'HASH') {
1.145 raeburn 9084: foreach my $lonhost (sort(keys(%{$servers}))) {
9085: my $gotspares;
1.152 raeburn 9086: if (ref($settings) eq 'HASH') {
9087: if (ref($settings->{'spares'}) eq 'HASH') {
9088: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9089: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9090: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9091: $gotspares = 1;
9092: }
1.145 raeburn 9093: }
9094: }
9095: unless ($gotspares) {
9096: my $gotspares;
9097: my $serverhomeID =
9098: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9099: my $serverhomedom =
9100: &Apache::lonnet::host_domain($serverhomeID);
9101: if ($serverhomedom ne $dom) {
9102: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9103: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9104: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9105: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9106: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9107: $gotspares = 1;
9108: }
9109: }
9110: } else {
9111: $otherdomconfigs{$serverhomedom} =
9112: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9113: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9114: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9115: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9116: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9117: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9118: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9119: $gotspares = 1;
9120: }
9121: }
9122: }
9123: }
9124: }
9125: }
9126: }
9127: unless ($gotspares) {
9128: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9129: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9130: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9131: } else {
9132: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9133: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9134: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9135: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9136: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9137: } else {
1.150 raeburn 9138: my %what = (
9139: spareid => 1,
9140: );
9141: my ($result,$returnhash) =
9142: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9143: if ($result eq 'ok') {
9144: if (ref($returnhash) eq 'HASH') {
9145: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9146: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9147: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9148: }
9149: }
1.145 raeburn 9150: }
9151: }
9152: }
9153: }
9154: }
9155: }
9156: return %spareid;
9157: }
9158:
9159: sub spares_row {
1.371 raeburn 9160: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9161: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9162: my $css_class;
9163: my $numinrow = 4;
9164: my $itemcount = 1;
9165: my $datatable;
1.152 raeburn 9166: my %typetitles = &sparestype_titles();
9167: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9168: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9169: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9170: my ($othercontrol,$serverdom);
9171: if ($serverhome ne $server) {
9172: $serverdom = &Apache::lonnet::host_domain($serverhome);
9173: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9174: } else {
9175: $serverdom = &Apache::lonnet::host_domain($server);
9176: if ($serverdom ne $dom) {
9177: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9178: }
9179: }
9180: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9181: my ($checkednow,$checkedoth);
1.261 raeburn 9182: if (ref($curroffloadnow) eq 'HASH') {
9183: if ($curroffloadnow->{$server}) {
9184: $checkednow = ' checked="checked"';
9185: }
9186: }
1.371 raeburn 9187: if (ref($curroffloadoth) eq 'HASH') {
9188: if ($curroffloadoth->{$server}) {
9189: $checkedoth = ' checked="checked"';
9190: }
9191: }
1.145 raeburn 9192: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9193: $datatable .= '<tr'.$css_class.'>
9194: <td rowspan="2">
1.183 bisitz 9195: <span class="LC_nobreak">'.
9196: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9197: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9198: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9199: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9200: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9201: "\n";
1.371 raeburn 9202: if ($other_insts) {
9203: $datatable .= '<br />'.
9204: '<span class="LC_nobreak">'."\n".
9205: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9206: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9207: "\n";
9208: }
1.145 raeburn 9209: my (%current,%canselect);
1.152 raeburn 9210: my @choices =
9211: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9212: foreach my $type ('primary','default') {
9213: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9214: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9215: my @spares = @{$spareid->{$server}{$type}};
9216: if (@spares > 0) {
1.152 raeburn 9217: if ($othercontrol) {
9218: $current{$type} = join(', ',@spares);
9219: } else {
9220: $current{$type} .= '<table>';
9221: my $numspares = scalar(@spares);
9222: for (my $i=0; $i<@spares; $i++) {
9223: my $rem = $i%($numinrow);
9224: if ($rem == 0) {
9225: if ($i > 0) {
9226: $current{$type} .= '</tr>';
9227: }
9228: $current{$type} .= '<tr>';
1.145 raeburn 9229: }
1.152 raeburn 9230: $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'".');" /> '.
9231: $spareid->{$server}{$type}[$i].
9232: '</label></td>'."\n";
9233: }
9234: my $rem = @spares%($numinrow);
9235: my $colsleft = $numinrow - $rem;
9236: if ($colsleft > 1 ) {
9237: $current{$type} .= '<td colspan="'.$colsleft.
9238: '" class="LC_left_item">'.
9239: ' </td>';
9240: } elsif ($colsleft == 1) {
9241: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9242: }
1.152 raeburn 9243: $current{$type} .= '</tr></table>';
1.150 raeburn 9244: }
1.145 raeburn 9245: }
9246: }
9247: if ($current{$type} eq '') {
9248: $current{$type} = &mt('None specified');
9249: }
1.152 raeburn 9250: if ($othercontrol) {
9251: if ($type eq 'primary') {
9252: $canselect{$type} = $othercontrol;
9253: }
9254: } else {
9255: $canselect{$type} =
9256: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9257: '<select name="newspare_'.$type.'_'.$server.'" '.
9258: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9259: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9260: if (@choices > 0) {
9261: foreach my $lonhost (@choices) {
9262: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9263: }
9264: }
9265: $canselect{$type} .= '</select>'."\n";
9266: }
9267: } else {
9268: $current{$type} = &mt('Could not be determined');
9269: if ($type eq 'primary') {
9270: $canselect{$type} = $othercontrol;
9271: }
1.145 raeburn 9272: }
1.152 raeburn 9273: if ($type eq 'default') {
9274: $datatable .= '<tr'.$css_class.'>';
9275: }
9276: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9277: '<td>'.$current{$type}.'</td>'."\n".
9278: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9279: }
9280: $itemcount ++;
9281: }
9282: }
9283: $$rowtotal += $itemcount;
9284: return $datatable;
9285: }
9286:
1.152 raeburn 9287: sub possible_newspares {
9288: my ($server,$currspares,$serverhomes,$altids) = @_;
9289: my $serverhostname = &Apache::lonnet::hostname($server);
9290: my %excluded;
9291: if ($serverhostname ne '') {
9292: %excluded = (
9293: $serverhostname => 1,
9294: );
9295: }
9296: if (ref($currspares) eq 'HASH') {
9297: foreach my $type (keys(%{$currspares})) {
9298: if (ref($currspares->{$type}) eq 'ARRAY') {
9299: if (@{$currspares->{$type}} > 0) {
9300: foreach my $curr (@{$currspares->{$type}}) {
9301: my $hostname = &Apache::lonnet::hostname($curr);
9302: $excluded{$hostname} = 1;
9303: }
9304: }
9305: }
9306: }
9307: }
9308: my @choices;
9309: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9310: if (keys(%{$serverhomes}) > 1) {
9311: foreach my $name (sort(keys(%{$serverhomes}))) {
9312: unless ($excluded{$name}) {
9313: if (exists($altids->{$serverhomes->{$name}})) {
9314: push(@choices,$altids->{$serverhomes->{$name}});
9315: } else {
9316: push(@choices,$serverhomes->{$name});
1.145 raeburn 9317: }
9318: }
9319: }
9320: }
9321: }
1.152 raeburn 9322: return sort(@choices);
1.145 raeburn 9323: }
9324:
1.150 raeburn 9325: sub print_loadbalancing {
9326: my ($dom,$settings,$rowtotal) = @_;
9327: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9328: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9329: my $numinrow = 1;
9330: my $datatable;
9331: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9332: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9333: if (ref($settings) eq 'HASH') {
9334: %existing = %{$settings};
9335: }
9336: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9337: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9338: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9339: } else {
9340: return;
9341: }
9342: my ($othertitle,$usertypes,$types) =
9343: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9344: my $rownum = 8;
1.150 raeburn 9345: if (ref($types) eq 'ARRAY') {
9346: $rownum += scalar(@{$types});
9347: }
1.171 raeburn 9348: my @css_class = ('LC_odd_row','LC_even_row');
9349: my $balnum = 0;
9350: my $islast;
9351: my (@toshow,$disabledtext);
9352: if (keys(%currbalancer) > 0) {
9353: @toshow = sort(keys(%currbalancer));
9354: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9355: push(@toshow,'');
9356: }
9357: } else {
9358: @toshow = ('');
9359: $disabledtext = &mt('No existing load balancer');
9360: }
9361: foreach my $lonhost (@toshow) {
9362: if ($balnum == scalar(@toshow)-1) {
9363: $islast = 1;
9364: } else {
9365: $islast = 0;
9366: }
9367: my $cssidx = $balnum%2;
9368: my $targets_div_style = 'display: none';
9369: my $disabled_div_style = 'display: block';
9370: my $homedom_div_style = 'display: none';
9371: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9372: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9373: '<p>';
9374: if ($lonhost eq '') {
1.210 raeburn 9375: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9376: if (keys(%currbalancer) > 0) {
9377: $datatable .= &mt('Add balancer:');
9378: } else {
9379: $datatable .= &mt('Enable balancer:');
9380: }
9381: $datatable .= ' '.
9382: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9383: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9384: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9385: '<option value="" selected="selected">'.&mt('None').
9386: '</option>'."\n";
9387: foreach my $server (sort(keys(%servers))) {
9388: next if ($currbalancer{$server});
9389: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9390: }
1.210 raeburn 9391: $datatable .=
1.171 raeburn 9392: '</select>'."\n".
9393: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9394: } else {
9395: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9396: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9397: &mt('Stop balancing').'</label>'.
9398: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9399: $targets_div_style = 'display: block';
9400: $disabled_div_style = 'display: none';
9401: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9402: $homedom_div_style = 'display: block';
9403: }
9404: }
1.306 raeburn 9405: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9406: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9407: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9408: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9409: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9410: my @sparestypes = ('primary','default');
9411: my %typetitles = &sparestype_titles();
1.284 raeburn 9412: my %hostherechecked = (
9413: no => ' checked="checked"',
9414: );
1.342 raeburn 9415: my %balcookiechecked = (
1.425 raeburn 9416: no => ' checked="checked"',
1.342 raeburn 9417: );
1.171 raeburn 9418: foreach my $sparetype (@sparestypes) {
9419: my $targettable;
9420: for (my $i=0; $i<$numspares; $i++) {
9421: my $checked;
9422: if (ref($currtargets{$lonhost}) eq 'HASH') {
9423: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9424: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9425: $checked = ' checked="checked"';
9426: }
9427: }
9428: }
9429: my ($chkboxval,$disabled);
9430: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9431: $chkboxval = $spares[$i];
9432: }
9433: if (exists($currbalancer{$spares[$i]})) {
9434: $disabled = ' disabled="disabled"';
9435: }
1.210 raeburn 9436: $targettable .=
1.253 raeburn 9437: '<td><span class="LC_nobreak"><label>'.
9438: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9439: $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 9440: '</span></label></span></td>';
1.171 raeburn 9441: my $rem = $i%($numinrow);
9442: if ($rem == 0) {
9443: if (($i > 0) && ($i < $numspares-1)) {
9444: $targettable .= '</tr>';
9445: }
9446: if ($i < $numspares-1) {
9447: $targettable .= '<tr>';
1.150 raeburn 9448: }
9449: }
9450: }
1.171 raeburn 9451: if ($targettable ne '') {
9452: my $rem = $numspares%($numinrow);
9453: my $colsleft = $numinrow - $rem;
9454: if ($colsleft > 1 ) {
9455: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9456: ' </td>';
9457: } elsif ($colsleft == 1) {
9458: $targettable .= '<td class="LC_left_item"> </td>';
9459: }
9460: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9461: '<table><tr>'.$targettable.'</tr></table><br />';
9462: }
1.284 raeburn 9463: $hostherechecked{$sparetype} = '';
9464: if (ref($currtargets{$lonhost}) eq 'HASH') {
9465: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9466: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9467: $hostherechecked{$sparetype} = ' checked="checked"';
9468: $hostherechecked{'no'} = '';
9469: }
9470: }
9471: }
9472: }
1.342 raeburn 9473: if ($currcookies{$lonhost}) {
9474: %balcookiechecked = (
9475: yes => ' checked="checked"',
9476: );
9477: }
1.284 raeburn 9478: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9479: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9480: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9481: foreach my $sparetype (@sparestypes) {
9482: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9483: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9484: '</i></label><br />';
1.171 raeburn 9485: }
1.342 raeburn 9486: $datatable .= &mt('Use balancer cookie').'<br />'.
9487: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9488: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9489: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9490: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9491: '</div></td></tr>'.
1.171 raeburn 9492: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9493: $othertitle,$usertypes,$types,\%servers,
9494: \%currbalancer,$lonhost,
9495: $targets_div_style,$homedom_div_style,
9496: $css_class[$cssidx],$balnum,$islast);
9497: $$rowtotal += $rownum;
9498: $balnum ++;
9499: }
9500: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9501: return $datatable;
9502: }
9503:
9504: sub get_loadbalancers_config {
1.342 raeburn 9505: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9506: return unless ((ref($servers) eq 'HASH') &&
9507: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9508: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9509: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9510: if (keys(%{$existing}) > 0) {
9511: my $oldlonhost;
9512: foreach my $key (sort(keys(%{$existing}))) {
9513: if ($key eq 'lonhost') {
9514: $oldlonhost = $existing->{'lonhost'};
9515: $currbalancer->{$oldlonhost} = 1;
9516: } elsif ($key eq 'targets') {
9517: if ($oldlonhost) {
9518: $currtargets->{$oldlonhost} = $existing->{'targets'};
9519: }
9520: } elsif ($key eq 'rules') {
9521: if ($oldlonhost) {
9522: $currrules->{$oldlonhost} = $existing->{'rules'};
9523: }
9524: } elsif (ref($existing->{$key}) eq 'HASH') {
9525: $currbalancer->{$key} = 1;
9526: $currtargets->{$key} = $existing->{$key}{'targets'};
9527: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9528: if ($existing->{$key}{'cookie'}) {
9529: $currcookies->{$key} = 1;
9530: }
1.150 raeburn 9531: }
9532: }
1.171 raeburn 9533: } else {
9534: my ($balancerref,$targetsref) =
9535: &Apache::lonnet::get_lonbalancer_config($servers);
9536: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9537: foreach my $server (sort(keys(%{$balancerref}))) {
9538: $currbalancer->{$server} = 1;
9539: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9540: }
9541: }
9542: }
1.171 raeburn 9543: return;
1.150 raeburn 9544: }
9545:
9546: sub loadbalancing_rules {
9547: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9548: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9549: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9550: my $output;
1.171 raeburn 9551: my $num = 0;
1.210 raeburn 9552: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9553: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9554: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9555: foreach my $type (@{$alltypes}) {
1.171 raeburn 9556: $num ++;
1.150 raeburn 9557: my $current;
9558: if (ref($currrules) eq 'HASH') {
9559: $current = $currrules->{$type};
9560: }
1.253 raeburn 9561: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9562: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9563: $current = '';
9564: }
9565: }
9566: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9567: $servers,$currbalancer,$lonhost,$dom,
9568: $targets_div_style,$homedom_div_style,
9569: $css_class,$balnum,$num,$islast);
1.150 raeburn 9570: }
9571: }
9572: return $output;
9573: }
9574:
9575: sub loadbalancing_titles {
9576: my ($dom,$intdom,$usertypes,$types) = @_;
9577: my %othertypes = (
9578: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9579: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9580: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9581: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9582: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9583: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9584: );
1.209 raeburn 9585: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9586: my @available;
1.150 raeburn 9587: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9588: @available = @{$types};
1.150 raeburn 9589: }
1.302 raeburn 9590: unless (grep(/^default$/,@available)) {
9591: push(@available,'default');
9592: }
9593: unshift(@alltypes,@available);
1.150 raeburn 9594: my %titles;
9595: foreach my $type (@alltypes) {
9596: if ($type =~ /^_LC_/) {
9597: $titles{$type} = $othertypes{$type};
9598: } elsif ($type eq 'default') {
9599: $titles{$type} = &mt('All users from [_1]',$dom);
9600: if (ref($types) eq 'ARRAY') {
9601: if (@{$types} > 0) {
9602: $titles{$type} = &mt('Other users from [_1]',$dom);
9603: }
9604: }
9605: } elsif (ref($usertypes) eq 'HASH') {
9606: $titles{$type} = $usertypes->{$type};
9607: }
9608: }
9609: return (\@alltypes,\%othertypes,\%titles);
9610: }
9611:
9612: sub loadbalance_rule_row {
1.171 raeburn 9613: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9614: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9615: my @rulenames;
1.150 raeburn 9616: my %ruletitles = &offloadtype_text();
1.209 raeburn 9617: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9618: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9619: } else {
1.209 raeburn 9620: @rulenames = ('default','homeserver');
9621: if ($type eq '_LC_external') {
9622: push(@rulenames,'externalbalancer');
9623: } else {
9624: push(@rulenames,'specific');
9625: }
9626: push(@rulenames,'none');
1.150 raeburn 9627: }
9628: my $style = $targets_div_style;
1.253 raeburn 9629: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9630: $style = $homedom_div_style;
9631: }
1.171 raeburn 9632: my $space;
9633: if ($islast && $num == 1) {
1.317 raeburn 9634: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9635: }
1.210 raeburn 9636: my $output =
1.306 raeburn 9637: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9638: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9639: '<td valaign="top">'.$space.
9640: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9641: for (my $i=0; $i<@rulenames; $i++) {
9642: my $rule = $rulenames[$i];
9643: my ($checked,$extra);
9644: if ($rulenames[$i] eq 'default') {
9645: $rule = '';
9646: }
9647: if ($rulenames[$i] eq 'specific') {
9648: if (ref($servers) eq 'HASH') {
9649: my $default;
9650: if (($current ne '') && (exists($servers->{$current}))) {
9651: $checked = ' checked="checked"';
9652: }
9653: unless ($checked) {
9654: $default = ' selected="selected"';
9655: }
1.210 raeburn 9656: $extra =
1.171 raeburn 9657: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9658: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9659: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9660: '<option value=""'.$default.'></option>'."\n";
9661: foreach my $server (sort(keys(%{$servers}))) {
9662: if (ref($currbalancer) eq 'HASH') {
9663: next if (exists($currbalancer->{$server}));
9664: }
1.150 raeburn 9665: my $selected;
1.171 raeburn 9666: if ($server eq $current) {
1.150 raeburn 9667: $selected = ' selected="selected"';
9668: }
1.171 raeburn 9669: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9670: }
9671: $extra .= '</select>';
9672: }
9673: } elsif ($rule eq $current) {
9674: $checked = ' checked="checked"';
9675: }
9676: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9677: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9678: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9679: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9680: ')"'.$checked.' /> ';
9681: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9682: $output .= $ruletitles{'particular'};
9683: } else {
9684: $output .= $ruletitles{$rulenames[$i]};
9685: }
9686: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9687: }
9688: $output .= '</div></td></tr>'."\n";
9689: return $output;
9690: }
9691:
9692: sub offloadtype_text {
9693: my %ruletitles = &Apache::lonlocal::texthash (
9694: 'default' => 'Offloads to default destinations',
9695: 'homeserver' => "Offloads to user's home server",
9696: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9697: 'specific' => 'Offloads to specific server',
1.161 raeburn 9698: 'none' => 'No offload',
1.209 raeburn 9699: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9700: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9701: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9702: );
9703: return %ruletitles;
9704: }
9705:
9706: sub sparestype_titles {
9707: my %typestitles = &Apache::lonlocal::texthash (
9708: 'primary' => 'primary',
9709: 'default' => 'default',
9710: );
9711: return %typestitles;
9712: }
9713:
1.28 raeburn 9714: sub contact_titles {
9715: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9716: 'supportemail' => 'Support E-mail address',
9717: 'adminemail' => 'Default Server Admin E-mail address',
9718: 'errormail' => 'Error reports to be e-mailed to',
9719: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9720: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9721: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9722: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9723: 'requestsmail' => 'E-mail from course requests requiring approval',
9724: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9725: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9726: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9727: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9728: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9729: 'errorweights' => 'Weights used to compute error count',
9730: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9731: );
9732: my %short_titles = &Apache::lonlocal::texthash (
9733: adminemail => 'Admin E-mail address',
9734: supportemail => 'Support E-mail',
9735: );
9736: return (\%titles,\%short_titles);
9737: }
9738:
1.286 raeburn 9739: sub helpform_fields {
9740: my %titles = &Apache::lonlocal::texthash (
9741: 'username' => 'Name',
9742: 'user' => 'Username/domain',
9743: 'phone' => 'Phone',
9744: 'cc' => 'Cc e-mail',
9745: 'course' => 'Course Details',
9746: 'section' => 'Sections',
1.289 raeburn 9747: 'screenshot' => 'File upload',
1.286 raeburn 9748: );
9749: my @fields = ('username','phone','user','course','section','cc','screenshot');
9750: my %possoptions = (
9751: username => ['yes','no','req'],
1.289 raeburn 9752: phone => ['yes','no','req'],
1.286 raeburn 9753: user => ['yes','no'],
1.289 raeburn 9754: cc => ['yes','no'],
1.286 raeburn 9755: course => ['yes','no'],
9756: section => ['yes','no'],
9757: screenshot => ['yes','no'],
9758: );
9759: my %fieldoptions = &Apache::lonlocal::texthash (
9760: 'yes' => 'Optional',
9761: 'req' => 'Required',
9762: 'no' => "Not shown",
9763: );
9764: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9765: }
9766:
1.72 raeburn 9767: sub tool_titles {
9768: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9769: aboutme => 'Personal web page',
1.86 raeburn 9770: blog => 'Blog',
9771: portfolio => 'Portfolio',
1.430 raeburn 9772: portaccess => 'Share portfolio files',
1.413 raeburn 9773: timezone => 'Can set time zone',
1.88 bisitz 9774: official => 'Official courses (with institutional codes)',
9775: unofficial => 'Unofficial courses',
1.98 raeburn 9776: community => 'Communities',
1.216 raeburn 9777: textbook => 'Textbook courses',
1.271 raeburn 9778: placement => 'Placement tests',
1.86 raeburn 9779: );
1.72 raeburn 9780: return %titles;
9781: }
9782:
1.101 raeburn 9783: sub courserequest_titles {
9784: my %titles = &Apache::lonlocal::texthash (
9785: official => 'Official',
9786: unofficial => 'Unofficial',
9787: community => 'Communities',
1.216 raeburn 9788: textbook => 'Textbook',
1.271 raeburn 9789: placement => 'Placement tests',
1.325 raeburn 9790: lti => 'LTI Provider',
1.101 raeburn 9791: norequest => 'Not allowed',
1.325 raeburn 9792: approval => 'Approval by DC',
1.101 raeburn 9793: validate => 'With validation',
9794: autolimit => 'Numerical limit',
1.103 raeburn 9795: unlimited => '(blank for unlimited)',
1.101 raeburn 9796: );
9797: return %titles;
9798: }
9799:
1.163 raeburn 9800: sub authorrequest_titles {
9801: my %titles = &Apache::lonlocal::texthash (
9802: norequest => 'Not allowed',
9803: approval => 'Approval by Dom. Coord.',
9804: automatic => 'Automatic approval',
9805: );
9806: return %titles;
1.210 raeburn 9807: }
1.163 raeburn 9808:
1.101 raeburn 9809: sub courserequest_conditions {
9810: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9811: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9812: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9813: );
9814: return %conditions;
9815: }
9816:
9817:
1.27 raeburn 9818: sub print_usercreation {
1.30 raeburn 9819: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9820: my $numinrow = 4;
1.28 raeburn 9821: my $datatable;
9822: if ($position eq 'top') {
1.30 raeburn 9823: $$rowtotal ++;
1.34 raeburn 9824: my $rowcount = 0;
1.32 raeburn 9825: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9826: if (ref($rules) eq 'HASH') {
9827: if (keys(%{$rules}) > 0) {
1.32 raeburn 9828: $datatable .= &user_formats_row('username',$settings,$rules,
9829: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9830: $$rowtotal ++;
1.32 raeburn 9831: $rowcount ++;
9832: }
9833: }
9834: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9835: if (ref($idrules) eq 'HASH') {
9836: if (keys(%{$idrules}) > 0) {
9837: $datatable .= &user_formats_row('id',$settings,$idrules,
9838: $idruleorder,$numinrow,$rowcount);
9839: $$rowtotal ++;
9840: $rowcount ++;
1.28 raeburn 9841: }
9842: }
1.39 raeburn 9843: if ($rowcount == 0) {
9844: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9845: $$rowtotal ++;
9846: $rowcount ++;
9847: }
1.34 raeburn 9848: } elsif ($position eq 'middle') {
1.224 raeburn 9849: my @creators = ('author','course','requestcrs');
1.37 raeburn 9850: my ($rules,$ruleorder) =
9851: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9852: my %lt = &usercreation_types();
9853: my %checked;
9854: if (ref($settings) eq 'HASH') {
9855: if (ref($settings->{'cancreate'}) eq 'HASH') {
9856: foreach my $item (@creators) {
9857: $checked{$item} = $settings->{'cancreate'}{$item};
9858: }
9859: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9860: foreach my $item (@creators) {
9861: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9862: $checked{$item} = 'none';
9863: }
9864: }
9865: }
9866: }
9867: my $rownum = 0;
9868: foreach my $item (@creators) {
9869: $rownum ++;
1.224 raeburn 9870: if ($checked{$item} eq '') {
9871: $checked{$item} = 'any';
1.34 raeburn 9872: }
9873: my $css_class;
9874: if ($rownum%2) {
9875: $css_class = '';
9876: } else {
9877: $css_class = ' class="LC_odd_row" ';
9878: }
9879: $datatable .= '<tr'.$css_class.'>'.
9880: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9881: '</span></td><td style="text-align: right">';
1.224 raeburn 9882: my @options = ('any');
9883: if (ref($rules) eq 'HASH') {
9884: if (keys(%{$rules}) > 0) {
9885: push(@options,('official','unofficial'));
1.37 raeburn 9886: }
9887: }
1.224 raeburn 9888: push(@options,'none');
1.37 raeburn 9889: foreach my $option (@options) {
1.50 raeburn 9890: my $type = 'radio';
1.34 raeburn 9891: my $check = ' ';
1.224 raeburn 9892: if ($checked{$item} eq $option) {
9893: $check = ' checked="checked" ';
1.34 raeburn 9894: }
9895: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9896: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9897: $item.'" value="'.$option.'"'.$check.'/> '.
9898: $lt{$option}.'</label> </span>';
9899: }
9900: $datatable .= '</td></tr>';
9901: }
1.28 raeburn 9902: } else {
9903: my @contexts = ('author','course','domain');
1.325 raeburn 9904: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9905: my %checked;
9906: if (ref($settings) eq 'HASH') {
9907: if (ref($settings->{'authtypes'}) eq 'HASH') {
9908: foreach my $item (@contexts) {
9909: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9910: foreach my $auth (@authtypes) {
9911: if ($settings->{'authtypes'}{$item}{$auth}) {
9912: $checked{$item}{$auth} = ' checked="checked" ';
9913: }
9914: }
9915: }
9916: }
1.27 raeburn 9917: }
1.35 raeburn 9918: } else {
9919: foreach my $item (@contexts) {
1.36 raeburn 9920: foreach my $auth (@authtypes) {
1.35 raeburn 9921: $checked{$item}{$auth} = ' checked="checked" ';
9922: }
9923: }
1.27 raeburn 9924: }
1.28 raeburn 9925: my %title = &context_names();
9926: my %authname = &authtype_names();
9927: my $rownum = 0;
9928: my $css_class;
9929: foreach my $item (@contexts) {
9930: if ($rownum%2) {
9931: $css_class = '';
9932: } else {
9933: $css_class = ' class="LC_odd_row" ';
9934: }
1.30 raeburn 9935: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9936: '<td>'.$title{$item}.
9937: '</td><td class="LC_left_item">'.
9938: '<span class="LC_nobreak">';
9939: foreach my $auth (@authtypes) {
9940: $datatable .= '<label>'.
9941: '<input type="checkbox" name="'.$item.'_auth" '.
9942: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9943: $authname{$auth}.'</label> ';
9944: }
9945: $datatable .= '</span></td></tr>';
9946: $rownum ++;
1.27 raeburn 9947: }
1.30 raeburn 9948: $$rowtotal += $rownum;
1.27 raeburn 9949: }
9950: return $datatable;
9951: }
9952:
1.224 raeburn 9953: sub print_selfcreation {
9954: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 9955: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
9956: $emaildomain,$datatable);
1.224 raeburn 9957: if (ref($settings) eq 'HASH') {
9958: if (ref($settings->{'cancreate'}) eq 'HASH') {
9959: $createsettings = $settings->{'cancreate'};
1.236 raeburn 9960: if (ref($createsettings) eq 'HASH') {
9961: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
9962: @selfcreate = @{$createsettings->{'selfcreate'}};
9963: } elsif ($createsettings->{'selfcreate'} ne '') {
9964: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
9965: @selfcreate = ('email','login','sso');
9966: } elsif ($createsettings->{'selfcreate'} ne 'none') {
9967: @selfcreate = ($createsettings->{'selfcreate'});
9968: }
9969: }
9970: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
9971: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 9972: }
1.305 raeburn 9973: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
9974: $emailoptions = $createsettings->{'emailoptions'};
9975: }
1.303 raeburn 9976: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
9977: $emailverified = $createsettings->{'emailverified'};
9978: }
9979: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
9980: $emaildomain = $createsettings->{'emaildomain'};
9981: }
1.224 raeburn 9982: }
9983: }
9984: }
9985: my %radiohash;
9986: my $numinrow = 4;
9987: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 9988: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 9989: if ($position eq 'top') {
9990: my %choices = &Apache::lonlocal::texthash (
9991: cancreate_login => 'Institutional Login',
9992: cancreate_sso => 'Institutional Single Sign On',
9993: );
9994: my @toggles = sort(keys(%choices));
9995: my %defaultchecked = (
9996: 'cancreate_login' => 'off',
9997: 'cancreate_sso' => 'off',
9998: );
1.228 raeburn 9999: my ($onclick,$itemcount);
1.224 raeburn 10000: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10001: \%choices,$itemcount,$onclick);
1.228 raeburn 10002: $$rowtotal += $itemcount;
1.425 raeburn 10003:
1.224 raeburn 10004: if (ref($usertypes) eq 'HASH') {
10005: if (keys(%{$usertypes}) > 0) {
10006: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10007: $dom,$numinrow,$othertitle,
1.305 raeburn 10008: 'statustocreate',$rowtotal);
1.224 raeburn 10009: $$rowtotal ++;
10010: }
10011: }
1.240 raeburn 10012: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10013: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10014: $fieldtitles{'inststatus'} = &mt('Institutional status');
10015: my $rem;
10016: my $numperrow = 2;
10017: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10018: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10019: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10020: '<td class="LC_left_item">'."\n".
1.334 raeburn 10021: '<table>'."\n";
1.240 raeburn 10022: for (my $i=0; $i<@fields; $i++) {
10023: $rem = $i%($numperrow);
10024: if ($rem == 0) {
10025: if ($i > 0) {
10026: $datatable .= '</tr>';
10027: }
10028: $datatable .= '<tr>';
10029: }
10030: my $currval;
1.248 raeburn 10031: if (ref($createsettings) eq 'HASH') {
10032: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10033: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10034: }
1.240 raeburn 10035: }
10036: $datatable .= '<td class="LC_left_item">'.
10037: '<span class="LC_nobreak">'.
10038: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10039: 'value="'.$currval.'" size="10" /> '.
10040: $fieldtitles{$fields[$i]}.'</span></td>';
10041: }
10042: my $colsleft = $numperrow - $rem;
10043: if ($colsleft > 1 ) {
10044: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10045: ' </td>';
10046: } elsif ($colsleft == 1) {
10047: $datatable .= '<td class="LC_left_item"> </td>';
10048: }
10049: $datatable .= '</tr></table></td></tr>';
10050: $$rowtotal ++;
1.224 raeburn 10051: } elsif ($position eq 'middle') {
10052: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10053: my @posstypes;
1.224 raeburn 10054: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10055: @posstypes = @{$types};
10056: }
10057: unless (grep(/^default$/,@posstypes)) {
10058: push(@posstypes,'default');
10059: }
10060: my %usertypeshash;
10061: if (ref($usertypes) eq 'HASH') {
10062: %usertypeshash = %{$usertypes};
10063: }
10064: $usertypeshash{'default'} = $othertitle;
10065: foreach my $status (@posstypes) {
10066: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10067: $numinrow,$$rowtotal,\%usertypeshash);
10068: $$rowtotal ++;
1.224 raeburn 10069: }
10070: } else {
1.236 raeburn 10071: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10072: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10073: );
10074: my @toggles = sort(keys(%choices));
10075: my %defaultchecked = (
10076: 'cancreate_email' => 'off',
10077: );
1.305 raeburn 10078: my $customclass = 'LC_selfcreate_email';
10079: my $classprefix = 'LC_canmodify_emailusername_';
10080: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10081: my $display = 'none';
1.305 raeburn 10082: my $rowstyle = 'display:none';
1.236 raeburn 10083: if (grep(/^\Qemail\E$/,@selfcreate)) {
10084: $display = 'block';
1.305 raeburn 10085: $rowstyle = 'display:table-row';
1.236 raeburn 10086: }
1.305 raeburn 10087: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10088: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10089: \%choices,$$rowtotal,$onclick);
10090: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10091: $rowstyle);
10092: $$rowtotal ++;
10093: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10094: $rowstyle);
10095: $$rowtotal ++;
10096: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10097: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10098: my ($emailrules,$emailruleorder) =
10099: &Apache::lonnet::inst_userrules($dom,'email');
10100: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10101: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10102: if (ref($types) eq 'ARRAY') {
10103: @posstypes = @{$types};
10104: }
10105: if (@posstypes) {
10106: unless (grep(/^default$/,@posstypes)) {
10107: push(@posstypes,'default');
1.302 raeburn 10108: }
10109: if (ref($usertypes) eq 'HASH') {
10110: %usertypeshash = %{$usertypes};
10111: }
1.305 raeburn 10112: my $currassign;
10113: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10114: $currassign = {
10115: selfassign => $domdefaults{'inststatusguest'},
10116: };
10117: @ordered = @{$domdefaults{'inststatusguest'}};
10118: } else {
10119: $currassign = { selfassign => [] };
10120: }
10121: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10122: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10123: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10124: $numinrow,$othertitle,'selfassign',
10125: $rowtotal,$onclicktypes,$customclass,
10126: $rowstyle);
10127: $$rowtotal ++;
1.302 raeburn 10128: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10129: foreach my $status (@posstypes) {
10130: my $css_class;
10131: if ($$rowtotal%2) {
10132: $css_class = 'LC_odd_row ';
10133: }
10134: $css_class .= $customclass;
10135: my $rowid = $optionsprefix.$status;
10136: my $hidden = 1;
10137: my $currstyle = 'display:none';
10138: if (grep(/^\Q$status\E$/,@ordered)) {
10139: $currstyle = $rowstyle;
1.425 raeburn 10140: $hidden = 0;
1.305 raeburn 10141: }
10142: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10143: $emailrules,$emailruleorder,$settings,$status,$rowid,
10144: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10145: unless ($hidden) {
10146: $$rowtotal ++;
10147: }
1.224 raeburn 10148: }
1.302 raeburn 10149: } else {
1.305 raeburn 10150: my $css_class;
10151: if ($$rowtotal%2) {
10152: $css_class = 'LC_odd_row ';
10153: }
10154: $css_class .= $customclass;
1.302 raeburn 10155: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10156: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10157: $emailrules,$emailruleorder,$settings,'default','',
10158: $othertitle,$css_class,$rowstyle,$intdom);
10159: $$rowtotal ++;
1.224 raeburn 10160: }
10161: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10162: $numinrow = 1;
1.305 raeburn 10163: if (@posstypes) {
10164: foreach my $status (@posstypes) {
10165: my $rowid = $classprefix.$status;
10166: my $datarowstyle = 'display:none';
1.425 raeburn 10167: if (grep(/^\Q$status\E$/,@ordered)) {
10168: $datarowstyle = $rowstyle;
1.305 raeburn 10169: }
10170: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10171: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10172: $infotitles,$rowid,$customclass,$datarowstyle);
10173: unless ($datarowstyle eq 'display:none') {
10174: $$rowtotal ++;
10175: }
1.224 raeburn 10176: }
1.305 raeburn 10177: } else {
10178: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10179: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10180: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10181: }
10182: }
10183: return $datatable;
10184: }
10185:
1.305 raeburn 10186: sub selfcreate_javascript {
10187: return <<"ENDSCRIPT";
10188:
10189: <script type="text/javascript">
10190: // <![CDATA[
10191:
10192: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10193: var x = document.getElementsByClassName(target);
10194: var insttypes = 0;
10195: var insttypeRegExp = new RegExp(prefix);
10196: if ((x.length != undefined) && (x.length > 0)) {
10197: if (form.elements[radio].length != undefined) {
10198: for (var i=0; i<form.elements[radio].length; i++) {
10199: if (form.elements[radio][i].checked) {
10200: if (form.elements[radio][i].value == 1) {
10201: for (var j=0; j<x.length; j++) {
10202: if (x[j].id == 'undefined') {
10203: x[j].style.display = 'table-row';
10204: } else if (insttypeRegExp.test(x[j].id)) {
10205: insttypes ++;
10206: } else {
10207: x[j].style.display = 'table-row';
10208: }
10209: }
10210: } else {
10211: for (var j=0; j<x.length; j++) {
10212: x[j].style.display = 'none';
10213: }
1.236 raeburn 10214: }
1.305 raeburn 10215: break;
10216: }
10217: }
10218: if (insttypes > 0) {
10219: toggleDataRow(form,checkbox,target,altprefix);
10220: toggleDataRow(form,checkbox,target,prefix,1);
10221: }
10222: }
10223: }
10224: return;
10225: }
10226:
10227: function toggleDataRow(form,checkbox,target,prefix,docount) {
10228: if (form.elements[checkbox].length != undefined) {
10229: var count = 0;
10230: if (docount) {
10231: for (var i=0; i<form.elements[checkbox].length; i++) {
10232: if (form.elements[checkbox][i].checked) {
10233: count ++;
1.236 raeburn 10234: }
1.305 raeburn 10235: }
10236: }
10237: for (var i=0; i<form.elements[checkbox].length; i++) {
10238: var type = form.elements[checkbox][i].value;
10239: if (document.getElementById(prefix+type)) {
10240: if (form.elements[checkbox][i].checked) {
10241: document.getElementById(prefix+type).style.display = 'table-row';
10242: if (count % 2 == 1) {
10243: document.getElementById(prefix+type).className = target+' LC_odd_row';
10244: } else {
10245: document.getElementById(prefix+type).className = target;
1.236 raeburn 10246: }
1.305 raeburn 10247: count ++;
1.236 raeburn 10248: } else {
1.305 raeburn 10249: document.getElementById(prefix+type).style.display = 'none';
10250: }
10251: }
10252: }
10253: }
10254: return;
10255: }
10256:
10257: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10258: var caller = radio+'_'+status;
10259: if (form.elements[caller].length != undefined) {
10260: for (var i=0; i<form.elements[caller].length; i++) {
10261: if (form.elements[caller][i].checked) {
10262: if (document.getElementById(altprefix+'_inst_'+status)) {
10263: var curr = form.elements[caller][i].value;
10264: if (prefix) {
10265: document.getElementById(prefix+'_'+status).style.display = 'none';
10266: }
10267: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10268: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10269: if (curr == 'custom') {
1.425 raeburn 10270: if (prefix) {
1.305 raeburn 10271: document.getElementById(prefix+'_'+status).style.display = 'inline';
10272: }
10273: } else if (curr == 'inst') {
10274: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10275: } else if (curr == 'noninst') {
10276: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10277: }
1.305 raeburn 10278: break;
1.236 raeburn 10279: }
10280: }
10281: }
10282: }
10283: }
10284:
1.305 raeburn 10285: // ]]>
10286: </script>
10287:
10288: ENDSCRIPT
10289: }
10290:
10291: sub noninst_users {
10292: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10293: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10294: my $class = 'LC_left_item';
10295: if ($css_class) {
1.425 raeburn 10296: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10297: }
10298: if ($rowid) {
10299: $rowid = ' id="'.$rowid.'"';
10300: }
10301: if ($rowstyle) {
10302: $rowstyle = ' style="'.$rowstyle.'"';
10303: }
10304: my ($output,$description);
10305: if ($type eq 'default') {
10306: $description = &mt('Requests for: [_1]',$typetitle);
10307: } else {
10308: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10309: }
10310: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10311: "<td>$description</td>\n".
1.305 raeburn 10312: '<td class="'.$class.'" colspan="2">'.
10313: '<table><tr>';
1.425 raeburn 10314: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10315: approve => 'Processing',
10316: email => 'E-mail',
10317: username => 'Username',
10318: );
10319: foreach my $item ('approve','email','username') {
10320: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10321: }
1.305 raeburn 10322: $output .= '</tr><tr>';
10323: foreach my $item ('approve','email','username') {
1.306 raeburn 10324: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10325: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10326: if ($item eq 'approve') {
10327: %choices = &Apache::lonlocal::texthash (
10328: automatic => 'Automatically approved',
10329: approval => 'Queued for approval',
10330: );
10331: @options = ('automatic','approval');
10332: $hashref = $processing;
10333: $defoption = 'automatic';
10334: $name = 'cancreate_emailprocess_'.$type;
10335: } elsif ($item eq 'email') {
10336: %choices = &Apache::lonlocal::texthash (
10337: any => 'Any e-mail',
10338: inst => 'Institutional only',
10339: noninst => 'Non-institutional only',
10340: custom => 'Custom restrictions',
10341: );
10342: @options = ('any','inst','noninst');
10343: my $showcustom;
10344: if (ref($emailrules) eq 'HASH') {
10345: if (keys(%{$emailrules}) > 0) {
10346: push(@options,'custom');
10347: $showcustom = 'cancreate_emailrule';
10348: if (ref($settings) eq 'HASH') {
10349: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10350: foreach my $rule (@{$settings->{'email_rule'}}) {
10351: if (exists($emailrules->{$rule})) {
10352: $hascustom ++;
10353: }
10354: }
10355: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10356: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10357: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10358: if (exists($emailrules->{$rule})) {
10359: $hascustom ++;
10360: }
10361: }
10362: }
10363: }
10364: }
10365: }
10366: }
10367: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10368: "'cancreate_emaildomain','$type'".');"';
10369: $hashref = $emailoptions;
10370: $defoption = 'any';
10371: $name = 'cancreate_emailoptions_'.$type;
10372: } elsif ($item eq 'username') {
10373: %choices = &Apache::lonlocal::texthash (
10374: all => 'Same as e-mail',
10375: first => 'Omit @domain',
10376: free => 'Free to choose',
10377: );
10378: @options = ('all','first','free');
10379: $hashref = $emailverified;
10380: $defoption = 'all';
10381: $name = 'cancreate_usernameoptions_'.$type;
10382: }
10383: foreach my $option (@options) {
10384: my $checked;
10385: if (ref($hashref) eq 'HASH') {
10386: if ($type eq '') {
10387: if (!exists($hashref->{'default'})) {
10388: if ($option eq $defoption) {
10389: $checked = ' checked="checked"';
10390: }
10391: } else {
10392: if ($hashref->{'default'} eq $option) {
10393: $checked = ' checked="checked"';
10394: }
1.303 raeburn 10395: }
10396: } else {
1.305 raeburn 10397: if (!exists($hashref->{$type})) {
10398: if ($option eq $defoption) {
10399: $checked = ' checked="checked"';
10400: }
10401: } else {
10402: if ($hashref->{$type} eq $option) {
10403: $checked = ' checked="checked"';
10404: }
1.303 raeburn 10405: }
10406: }
1.305 raeburn 10407: } elsif (($item eq 'email') && ($hascustom)) {
10408: if ($option eq 'custom') {
10409: $checked = ' checked="checked"';
10410: }
10411: } elsif ($option eq $defoption) {
10412: $checked = ' checked="checked"';
10413: }
10414: $output .= '<span class="LC_nobreak"><label>'.
10415: '<input type="radio" name="'.$name.'"'.
10416: $checked.' value="'.$option.'"'.$onclick.' />'.
10417: $choices{$option}.'</label></span><br />';
10418: if ($item eq 'email') {
10419: if ($option eq 'custom') {
10420: my $id = 'cancreate_emailrule_'.$type;
10421: my $display = 'none';
10422: if ($checked) {
10423: $display = 'inline';
1.303 raeburn 10424: }
1.305 raeburn 10425: my $numinrow = 2;
10426: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10427: '<legend>'.&mt('Disallow').'</legend><table>'.
10428: &user_formats_row('email',$settings,$emailrules,
10429: $emailruleorder,$numinrow,'',$type);
10430: '</table></fieldset>';
10431: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10432: my %text = &Apache::lonlocal::texthash (
10433: inst => 'must end:',
10434: noninst => 'cannot end:',
10435: );
10436: my $value;
10437: if (ref($emaildomain) eq 'HASH') {
10438: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10439: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10440: }
10441: }
1.305 raeburn 10442: if ($value eq '') {
10443: $value = '@'.$intdom;
10444: }
10445: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10446: my $display = 'none';
10447: if ($checked) {
10448: $display = 'inline';
10449: }
10450: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10451: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10452: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10453: '</div>';
1.303 raeburn 10454: }
10455: }
10456: }
1.305 raeburn 10457: $output .= '</td>'."\n";
1.303 raeburn 10458: }
1.305 raeburn 10459: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10460: return $output;
10461: }
10462:
1.165 raeburn 10463: sub captcha_choice {
1.305 raeburn 10464: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10465: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10466: $vertext,$currver);
1.165 raeburn 10467: my %lt = &captcha_phrases();
10468: $keyentry = 'hidden';
1.354 raeburn 10469: my $colspan=2;
1.165 raeburn 10470: if ($context eq 'cancreate') {
1.224 raeburn 10471: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10472: } elsif ($context eq 'login') {
10473: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10474: } elsif ($context eq 'passwords') {
10475: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10476: $colspan=1;
1.165 raeburn 10477: }
10478: if (ref($settings) eq 'HASH') {
10479: if ($settings->{'captcha'}) {
10480: $checked{$settings->{'captcha'}} = ' checked="checked"';
10481: } else {
10482: $checked{'original'} = ' checked="checked"';
10483: }
10484: if ($settings->{'captcha'} eq 'recaptcha') {
10485: $pubtext = $lt{'pub'};
10486: $privtext = $lt{'priv'};
10487: $keyentry = 'text';
1.269 raeburn 10488: $vertext = $lt{'ver'};
10489: $currver = $settings->{'recaptchaversion'};
10490: if ($currver ne '2') {
10491: $currver = 1;
10492: }
1.165 raeburn 10493: }
10494: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10495: $currpub = $settings->{'recaptchakeys'}{'public'};
10496: $currpriv = $settings->{'recaptchakeys'}{'private'};
10497: }
10498: } else {
10499: $checked{'original'} = ' checked="checked"';
10500: }
1.305 raeburn 10501: my $css_class;
10502: if ($itemcount%2) {
10503: $css_class = 'LC_odd_row';
10504: }
10505: if ($customcss) {
10506: $css_class .= " $customcss";
10507: }
10508: $css_class =~ s/^\s+//;
10509: if ($css_class) {
10510: $css_class = ' class="'.$css_class.'"';
10511: }
10512: if ($rowstyle) {
10513: $css_class .= ' style="'.$rowstyle.'"';
10514: }
1.169 raeburn 10515: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10516: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10517: '<table><tr><td>'."\n";
10518: foreach my $option ('original','recaptcha','notused') {
10519: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10520: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10521: $lt{$option}.'</label></span>';
10522: unless ($option eq 'notused') {
10523: $output .= (' 'x2)."\n";
10524: }
10525: }
10526: #
10527: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10528: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10529: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10530: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10531: #
1.165 raeburn 10532: $output .= '</td></tr>'."\n".
1.305 raeburn 10533: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10534: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10535: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10536: $currpub.'" size="40" /></span><br />'."\n".
10537: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10538: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10539: $currpriv.'" size="40" /></span><br />'.
10540: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10541: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10542: $currver.'" size="3" /></span><br />'.
10543: '</td></tr></table>'."\n".
1.165 raeburn 10544: '</td></tr>';
10545: return $output;
10546: }
10547:
1.32 raeburn 10548: sub user_formats_row {
1.305 raeburn 10549: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10550: my $output;
10551: my %text = (
10552: 'username' => 'new usernames',
10553: 'id' => 'IDs',
10554: );
1.409 raeburn 10555: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10556: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10557: $output = '<tr '.$css_class.'>'.
10558: '<td><span class="LC_nobreak">'.
10559: &mt("Format rules to check for $text{$type}: ").
10560: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10561: }
1.27 raeburn 10562: my $rem;
10563: if (ref($ruleorder) eq 'ARRAY') {
10564: for (my $i=0; $i<@{$ruleorder}; $i++) {
10565: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10566: my $rem = $i%($numinrow);
10567: if ($rem == 0) {
10568: if ($i > 0) {
10569: $output .= '</tr>';
10570: }
10571: $output .= '<tr>';
10572: }
10573: my $check = ' ';
1.39 raeburn 10574: if (ref($settings) eq 'HASH') {
10575: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10576: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10577: $check = ' checked="checked" ';
10578: }
1.305 raeburn 10579: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10580: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10581: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10582: $check = ' checked="checked" ';
10583: }
10584: }
1.27 raeburn 10585: }
10586: }
1.305 raeburn 10587: my $name = $type.'_rule';
10588: if ($type eq 'email') {
10589: $name .= '_'.$status;
10590: }
1.27 raeburn 10591: $output .= '<td class="LC_left_item">'.
10592: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10593: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10594: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10595: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10596: }
10597: }
10598: $rem = @{$ruleorder}%($numinrow);
10599: }
1.305 raeburn 10600: my $colsleft;
10601: if ($rem) {
10602: $colsleft = $numinrow - $rem;
10603: }
1.27 raeburn 10604: if ($colsleft > 1 ) {
10605: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10606: ' </td>';
10607: } elsif ($colsleft == 1) {
10608: $output .= '<td class="LC_left_item"> </td>';
10609: }
1.409 raeburn 10610: $output .= '</tr>';
10611: unless (($type eq 'email') || ($type eq 'unamemap')) {
10612: $output .= '</table></td></tr>';
1.305 raeburn 10613: }
1.27 raeburn 10614: return $output;
10615: }
10616:
1.34 raeburn 10617: sub usercreation_types {
10618: my %lt = &Apache::lonlocal::texthash (
10619: author => 'When adding a co-author',
10620: course => 'When adding a user to a course',
1.100 raeburn 10621: requestcrs => 'When requesting a course',
1.34 raeburn 10622: any => 'Any',
10623: official => 'Institutional only ',
10624: unofficial => 'Non-institutional only',
10625: none => 'None',
10626: );
10627: return %lt;
1.48 raeburn 10628: }
1.34 raeburn 10629:
1.224 raeburn 10630: sub selfcreation_types {
10631: my %lt = &Apache::lonlocal::texthash (
10632: selfcreate => 'User creates own account',
10633: any => 'Any',
10634: official => 'Institutional only ',
10635: unofficial => 'Non-institutional only',
10636: email => 'E-mail address',
10637: login => 'Institutional Login',
10638: sso => 'SSO',
10639: );
10640: }
10641:
1.28 raeburn 10642: sub authtype_names {
10643: my %lt = &Apache::lonlocal::texthash(
10644: int => 'Internal',
10645: krb4 => 'Kerberos 4',
10646: krb5 => 'Kerberos 5',
10647: loc => 'Local',
1.325 raeburn 10648: lti => 'LTI',
1.28 raeburn 10649: );
10650: return %lt;
10651: }
10652:
10653: sub context_names {
10654: my %context_title = &Apache::lonlocal::texthash(
10655: author => 'Creating users when an Author',
10656: course => 'Creating users when in a course',
10657: domain => 'Creating users when a Domain Coordinator',
10658: );
10659: return %context_title;
10660: }
10661:
1.33 raeburn 10662: sub print_usermodification {
10663: my ($position,$dom,$settings,$rowtotal) = @_;
10664: my $numinrow = 4;
10665: my ($context,$datatable,$rowcount);
10666: if ($position eq 'top') {
10667: $rowcount = 0;
10668: $context = 'author';
10669: foreach my $role ('ca','aa') {
10670: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10671: $numinrow,$rowcount);
10672: $$rowtotal ++;
10673: $rowcount ++;
10674: }
1.230 raeburn 10675: } elsif ($position eq 'bottom') {
1.33 raeburn 10676: $context = 'course';
10677: $rowcount = 0;
10678: foreach my $role ('st','ep','ta','in','cr') {
10679: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10680: $numinrow,$rowcount);
10681: $$rowtotal ++;
10682: $rowcount ++;
10683: }
10684: }
10685: return $datatable;
10686: }
10687:
1.43 raeburn 10688: sub print_defaults {
1.236 raeburn 10689: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10690: my $rownum = 0;
1.294 raeburn 10691: my ($datatable,$css_class,$titles);
10692: unless ($position eq 'bottom') {
10693: $titles = &defaults_titles($dom);
10694: }
1.236 raeburn 10695: if ($position eq 'top') {
10696: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10697: 'datelocale_def','portal_def');
10698: my %defaults;
10699: if (ref($settings) eq 'HASH') {
10700: %defaults = %{$settings};
1.43 raeburn 10701: } else {
1.236 raeburn 10702: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10703: foreach my $item (@items) {
10704: $defaults{$item} = $domdefaults{$item};
10705: }
1.43 raeburn 10706: }
1.236 raeburn 10707: foreach my $item (@items) {
10708: if ($rownum%2) {
10709: $css_class = '';
10710: } else {
10711: $css_class = ' class="LC_odd_row" ';
10712: }
10713: $datatable .= '<tr'.$css_class.'>'.
10714: '<td><span class="LC_nobreak">'.$titles->{$item}.
10715: '</span></td><td class="LC_right_item" colspan="3">';
10716: if ($item eq 'auth_def') {
1.325 raeburn 10717: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10718: my %shortauth = (
10719: internal => 'int',
10720: krb4 => 'krb4',
10721: krb5 => 'krb5',
1.325 raeburn 10722: localauth => 'loc',
10723: lti => 'lti',
1.236 raeburn 10724: );
10725: my %authnames = &authtype_names();
10726: foreach my $auth (@authtypes) {
10727: my $checked = ' ';
10728: if ($defaults{$item} eq $auth) {
10729: $checked = ' checked="checked" ';
10730: }
10731: $datatable .= '<label><input type="radio" name="'.$item.
10732: '" value="'.$auth.'"'.$checked.'/>'.
10733: $authnames{$shortauth{$auth}}.'</label> ';
10734: }
10735: } elsif ($item eq 'timezone_def') {
10736: my $includeempty = 1;
10737: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10738: } elsif ($item eq 'datelocale_def') {
10739: my $includeempty = 1;
10740: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10741: } elsif ($item eq 'lang_def') {
1.263 raeburn 10742: my $includeempty = 1;
10743: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10744: } elsif ($item eq 'portal_def') {
10745: $datatable .= '<input type="text" name="'.$item.'" value="'.
10746: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10747: my $portalsty = 'none';
10748: if ($defaults{$item}) {
10749: $portalsty = 'block';
10750: }
10751: foreach my $field ('email','web') {
10752: my $checkedoff = ' checked="checked"';
10753: my $checkedon;
10754: if ($defaults{$item.'_'.$field}) {
10755: $checkedon = $checkedoff;
10756: $checkedoff = '';
1.425 raeburn 10757: }
1.414 raeburn 10758: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10759: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10760: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10761: (' 'x2).
10762: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10763: '</div>';
10764: }
1.236 raeburn 10765: } else {
1.414 raeburn 10766: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10767: }
1.236 raeburn 10768: $datatable .= '</td></tr>';
10769: $rownum ++;
10770: }
1.409 raeburn 10771: } elsif ($position eq 'middle') {
1.294 raeburn 10772: my %defaults;
10773: if (ref($settings) eq 'HASH') {
1.354 raeburn 10774: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10775: my $maxnum = @{$settings->{'inststatusorder'}};
10776: for (my $i=0; $i<$maxnum; $i++) {
10777: $css_class = $rownum%2?' class="LC_odd_row"':'';
10778: my $item = $settings->{'inststatusorder'}->[$i];
10779: my $title = $settings->{'inststatustypes'}->{$item};
10780: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10781: $datatable .= '<tr'.$css_class.'>'.
10782: '<td><span class="LC_nobreak">'.
10783: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10784: for (my $k=0; $k<=$maxnum; $k++) {
10785: my $vpos = $k+1;
10786: my $selstr;
10787: if ($k == $i) {
10788: $selstr = ' selected="selected" ';
10789: }
10790: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10791: }
10792: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10793: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10794: &mt('delete').'</span></td>'.
1.380 raeburn 10795: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10796: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10797: '</span></td></tr>';
10798: }
10799: $css_class = $rownum%2?' class="LC_odd_row"':'';
10800: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10801: $datatable .= '<tr '.$css_class.'>'.
10802: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10803: for (my $k=0; $k<=$maxnum; $k++) {
10804: my $vpos = $k+1;
10805: my $selstr;
10806: if ($k == $maxnum) {
10807: $selstr = ' selected="selected" ';
10808: }
10809: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10810: }
10811: $datatable .= '</select> '.&mt('Internal ID:').
10812: '<input type="text" size="10" name="addinststatus" value="" />'.
10813: ' '.&mt('(new)').
10814: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10815: &mt('Name displayed').':'.
1.354 raeburn 10816: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10817: '</tr>'."\n";
10818: $rownum ++;
1.294 raeburn 10819: }
1.354 raeburn 10820: }
1.409 raeburn 10821: } else {
10822: my ($unamemaprules,$ruleorder) =
10823: &Apache::lonnet::inst_userrules($dom,'unamemap');
10824: $css_class = $rownum%2?' class="LC_odd_row"':'';
10825: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10826: my $numinrow = 2;
10827: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10828: &user_formats_row('unamemap',$settings,$unamemaprules,
10829: $ruleorder,$numinrow).
10830: '</table></td></tr>';
10831: }
10832: if ($datatable eq '') {
10833: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10834: &mt('No rules set for domain in customized localenroll.pm').
10835: '</td></tr>';
10836: }
1.354 raeburn 10837: }
10838: $$rowtotal += $rownum;
1.43 raeburn 10839: return $datatable;
10840: }
10841:
1.168 raeburn 10842: sub get_languages_hash {
10843: my %langchoices;
10844: foreach my $id (&Apache::loncommon::languageids()) {
10845: my $code = &Apache::loncommon::supportedlanguagecode($id);
10846: if ($code ne '') {
10847: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10848: }
10849: }
10850: return %langchoices;
10851: }
10852:
1.43 raeburn 10853: sub defaults_titles {
1.141 raeburn 10854: my ($dom) = @_;
1.43 raeburn 10855: my %titles = &Apache::lonlocal::texthash (
10856: 'auth_def' => 'Default authentication type',
10857: 'auth_arg_def' => 'Default authentication argument',
10858: 'lang_def' => 'Default language',
1.54 raeburn 10859: 'timezone_def' => 'Default timezone',
1.68 raeburn 10860: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10861: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10862: 'email' => 'Email links use portal URL',
10863: 'web' => 'Public web links use portal URL',
1.294 raeburn 10864: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10865: 'intauth_check' => 'Check bcrypt cost if authenticated',
10866: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10867: );
1.141 raeburn 10868: if ($dom) {
10869: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10870: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10871: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10872: $protocol = 'http' if ($protocol ne 'https');
10873: if ($uint_dom) {
10874: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10875: $uint_dom);
10876: }
10877: }
1.43 raeburn 10878: return (\%titles);
10879: }
10880:
1.346 raeburn 10881: sub print_scantron {
10882: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10883: if ($position eq 'top') {
10884: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10885: } else {
10886: return &print_scantronconfig($dom,$settings,\$rowtotal);
10887: }
10888: }
10889:
10890: sub scantron_javascript {
10891: return <<"ENDSCRIPT";
10892:
10893: <script type="text/javascript">
10894: // <![CDATA[
10895:
10896: function toggleScantron(form) {
1.347 raeburn 10897: var csvfieldset = new Array();
1.346 raeburn 10898: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10899: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10900: }
10901: if (document.getElementById('scantroncsv_options')) {
10902: csvfieldset.push(document.getElementById('scantroncsv_options'));
10903: }
10904: if (csvfieldset.length) {
1.346 raeburn 10905: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10906: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10907: if (scantroncsv.checked) {
1.347 raeburn 10908: for (var i=0; i<csvfieldset.length; i++) {
10909: csvfieldset[i].style.display = 'block';
10910: }
1.346 raeburn 10911: } else {
1.347 raeburn 10912: for (var i=0; i<csvfieldset.length; i++) {
10913: csvfieldset[i].style.display = 'none';
10914: }
1.346 raeburn 10915: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10916: if (csvselects.length) {
10917: for (var j=0; j<csvselects.length; j++) {
10918: csvselects[j].selectedIndex = 0;
10919: }
10920: }
10921: }
10922: }
10923: }
10924: return;
10925: }
10926: // ]]>
10927: </script>
10928:
10929: ENDSCRIPT
10930:
10931: }
10932:
1.46 raeburn 10933: sub print_scantronformat {
10934: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10935: my $itemcount = 1;
1.60 raeburn 10936: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10937: %confhash);
1.46 raeburn 10938: my $switchserver = &check_switchserver($dom,$confname);
10939: my %lt = &Apache::lonlocal::texthash (
1.95 www 10940: default => 'Default bubblesheet format file error',
10941: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10942: );
10943: my %scantronfiles = (
10944: default => 'default.tab',
10945: custom => 'custom.tab',
10946: );
10947: foreach my $key (keys(%scantronfiles)) {
10948: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
10949: .$scantronfiles{$key};
10950: }
10951: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
10952: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
10953: if (!$switchserver) {
10954: my $servadm = $r->dir_config('lonAdmEMail');
10955: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
10956: if ($configuserok eq 'ok') {
10957: if ($author_ok eq 'ok') {
10958: my %legacyfile = (
1.346 raeburn 10959: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
10960: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 10961: );
10962: my %md5chk;
10963: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 10964: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
10965: chomp($md5chk{$type});
1.46 raeburn 10966: }
10967: if ($md5chk{'default'} ne $md5chk{'custom'}) {
10968: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 10969: ($scantronurls{$type},my $error) =
1.46 raeburn 10970: &legacy_scantronformat($r,$dom,$confname,
10971: $type,$legacyfile{$type},
10972: $scantronurls{$type},
10973: $scantronfiles{$type});
1.60 raeburn 10974: if ($error ne '') {
10975: $error{$type} = $error;
10976: }
10977: }
10978: if (keys(%error) == 0) {
10979: $is_custom = 1;
1.346 raeburn 10980: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 10981: $scantronurls{'custom'};
1.346 raeburn 10982: my $putresult =
1.60 raeburn 10983: &Apache::lonnet::put_dom('configuration',
10984: \%confhash,$dom);
10985: if ($putresult ne 'ok') {
1.346 raeburn 10986: $error{'custom'} =
1.60 raeburn 10987: '<span class="LC_error">'.
10988: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
10989: }
1.46 raeburn 10990: }
10991: } else {
1.60 raeburn 10992: ($scantronurls{'default'},my $error) =
1.46 raeburn 10993: &legacy_scantronformat($r,$dom,$confname,
10994: 'default',$legacyfile{'default'},
10995: $scantronurls{'default'},
10996: $scantronfiles{'default'});
1.60 raeburn 10997: if ($error eq '') {
10998: $confhash{'scantron'}{'scantronformat'} = '';
10999: my $putresult =
11000: &Apache::lonnet::put_dom('configuration',
11001: \%confhash,$dom);
11002: if ($putresult ne 'ok') {
11003: $error{'default'} =
11004: '<span class="LC_error">'.
11005: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11006: }
11007: } else {
11008: $error{'default'} = $error;
11009: }
1.46 raeburn 11010: }
11011: }
11012: }
11013: } else {
1.95 www 11014: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11015: }
11016: }
11017: if (ref($settings) eq 'HASH') {
11018: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11019: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11020: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11021: $scantronurl = '';
11022: } else {
11023: $scantronurl = $settings->{'scantronformat'};
11024: }
11025: $is_custom = 1;
11026: } else {
11027: $scantronurl = $scantronurls{'default'};
11028: }
11029: } else {
1.60 raeburn 11030: if ($is_custom) {
11031: $scantronurl = $scantronurls{'custom'};
11032: } else {
11033: $scantronurl = $scantronurls{'default'};
11034: }
1.46 raeburn 11035: }
11036: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11037: $datatable .= '<tr'.$css_class.'>';
11038: if (!$is_custom) {
1.65 raeburn 11039: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11040: '<span class="LC_nobreak">';
1.46 raeburn 11041: if ($scantronurl) {
1.199 raeburn 11042: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11043: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11044: } else {
11045: $datatable = &mt('File unavailable for display');
11046: }
1.65 raeburn 11047: $datatable .= '</span></td>';
1.60 raeburn 11048: if (keys(%error) == 0) {
1.306 raeburn 11049: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11050: if (!$switchserver) {
11051: $datatable .= &mt('Upload:').'<br />';
11052: }
11053: } else {
11054: my $errorstr;
11055: foreach my $key (sort(keys(%error))) {
11056: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11057: }
11058: $datatable .= '<td>'.$errorstr;
11059: }
1.46 raeburn 11060: } else {
11061: if (keys(%error) > 0) {
11062: my $errorstr;
11063: foreach my $key (sort(keys(%error))) {
11064: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11065: }
1.60 raeburn 11066: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11067: } elsif ($scantronurl) {
1.199 raeburn 11068: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11069: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11070: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11071: $link.
11072: '<label><input type="checkbox" name="scantronformat_del"'.
11073: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11074: '<td><span class="LC_nobreak"> '.
11075: &mt('Replace:').'</span><br />';
1.46 raeburn 11076: }
11077: }
11078: if (keys(%error) == 0) {
11079: if ($switchserver) {
11080: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11081: } else {
1.65 raeburn 11082: $datatable .='<span class="LC_nobreak"> '.
11083: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11084: }
11085: }
11086: $datatable .= '</td></tr>';
11087: $$rowtotal ++;
11088: return $datatable;
11089: }
11090:
11091: sub legacy_scantronformat {
11092: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11093: my ($url,$error);
11094: my @statinfo = &Apache::lonnet::stat_file($newurl);
11095: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11096: my $modified = [];
1.46 raeburn 11097: (my $result,$url) =
1.421 raeburn 11098: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11099: 'scantron','','',$newfile,$modified);
11100: if ($result eq 'ok') {
11101: &update_modify_urls($r,$modified);
11102: } else {
1.130 raeburn 11103: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11104: }
11105: }
11106: return ($url,$error);
11107: }
1.43 raeburn 11108:
1.346 raeburn 11109: sub print_scantronconfig {
11110: my ($dom,$settings,$rowtotal) = @_;
11111: my $itemcount = 2;
11112: my $is_checked = ' checked="checked"';
1.347 raeburn 11113: my %optionson = (
11114: hdr => ' checked="checked"',
11115: pad => ' checked="checked"',
11116: rem => ' checked="checked"',
11117: );
11118: my %optionsoff = (
11119: hdr => '',
11120: pad => '',
11121: rem => '',
11122: );
1.346 raeburn 11123: my $currcsvsty = 'none';
1.347 raeburn 11124: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11125: my @fields = &scantroncsv_fields();
11126: my %titles = &scantronconfig_titles();
11127: if (ref($settings) eq 'HASH') {
11128: if (ref($settings->{config}) eq 'HASH') {
11129: if ($settings->{config}->{dat}) {
11130: $checked{'dat'} = $is_checked;
11131: }
11132: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11133: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11134: %csvfields = %{$settings->{config}->{csv}->{fields}};
11135: if (keys(%csvfields) > 0) {
11136: $checked{'csv'} = $is_checked;
11137: $currcsvsty = 'block';
11138: }
11139: }
11140: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11141: %csvoptions = %{$settings->{config}->{csv}->{options}};
11142: foreach my $option (keys(%optionson)) {
11143: unless ($csvoptions{$option}) {
11144: $optionsoff{$option} = $optionson{$option};
11145: $optionson{$option} = '';
11146: }
11147: }
1.346 raeburn 11148: }
11149: }
11150: } else {
11151: $checked{'dat'} = $is_checked;
11152: }
11153: } else {
11154: $checked{'dat'} = $is_checked;
11155: }
11156: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11157: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11158: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11159: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11160: foreach my $item ('dat','csv') {
11161: my $id;
11162: if ($item eq 'csv') {
11163: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11164: }
1.346 raeburn 11165: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11166: $titles{$item}.'</label>'.(' 'x3);
11167: if ($item eq 'csv') {
11168: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11169: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11170: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11171: foreach my $col (@fields) {
11172: my $selnone;
11173: if ($csvfields{$col} eq '') {
11174: $selnone = ' selected="selected"';
11175: }
11176: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11177: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11178: '<option value=""'.$selnone.'></option>';
11179: for (my $i=0; $i<20; $i++) {
11180: my $shown = $i+1;
11181: my $sel;
11182: unless ($selnone) {
11183: if (exists($csvfields{$col})) {
11184: if ($csvfields{$col} == $i) {
11185: $sel = ' selected="selected"';
11186: }
11187: }
11188: }
11189: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11190: }
11191: $datatable .= '</select></td></tr>';
11192: }
1.347 raeburn 11193: $datatable .= '</table></fieldset>'.
11194: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11195: '<legend>'.&mt('CSV Options').'</legend>';
11196: foreach my $option ('hdr','pad','rem') {
11197: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11198: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11199: &mt('Yes').'</label>'.(' 'x2)."\n".
11200: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11201: }
11202: $datatable .= '</fieldset>';
1.346 raeburn 11203: $itemcount ++;
11204: }
11205: }
11206: $datatable .= '</td></tr>';
11207: $$rowtotal ++;
11208: return $datatable;
11209: }
11210:
11211: sub scantronconfig_titles {
11212: return &Apache::lonlocal::texthash(
11213: dat => 'Standard format (.dat)',
11214: csv => 'Comma separated values (.csv)',
1.347 raeburn 11215: hdr => 'Remove first line in file (contains column titles)',
11216: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11217: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11218: CODE => 'CODE',
11219: ID => 'Student ID',
11220: PaperID => 'Paper ID',
11221: FirstName => 'First Name',
11222: LastName => 'Last Name',
11223: FirstQuestion => 'First Question Response',
11224: Section => 'Section',
11225: );
11226: }
11227:
11228: sub scantroncsv_fields {
11229: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11230: }
11231:
1.49 raeburn 11232: sub print_coursecategories {
1.57 raeburn 11233: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11234: my $datatable;
11235: if ($position eq 'top') {
1.238 raeburn 11236: my (%checked);
11237: my @catitems = ('unauth','auth');
11238: my @cattypes = ('std','domonly','codesrch','none');
11239: $checked{'unauth'} = 'std';
11240: $checked{'auth'} = 'std';
11241: if (ref($settings) eq 'HASH') {
11242: foreach my $type (@cattypes) {
11243: if ($type eq $settings->{'unauth'}) {
11244: $checked{'unauth'} = $type;
11245: }
11246: if ($type eq $settings->{'auth'}) {
11247: $checked{'auth'} = $type;
11248: }
11249: }
11250: }
11251: my %lt = &Apache::lonlocal::texthash (
11252: unauth => 'Catalog type for unauthenticated users',
11253: auth => 'Catalog type for authenticated users',
11254: none => 'No catalog',
11255: std => 'Standard catalog',
11256: domonly => 'Domain-only catalog',
11257: codesrch => "Code search form",
11258: );
11259: my $itemcount = 0;
11260: foreach my $item (@catitems) {
11261: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11262: $datatable .= '<tr '.$css_class.'>'.
11263: '<td>'.$lt{$item}.'</td>'.
11264: '<td class="LC_right_item"><span class="LC_nobreak">';
11265: foreach my $type (@cattypes) {
11266: my $ischecked;
11267: if ($checked{$item} eq $type) {
11268: $ischecked=' checked="checked"';
11269: }
11270: $datatable .= '<label>'.
11271: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11272: ' />'.$lt{$type}.'</label> ';
11273: }
1.327 raeburn 11274: $datatable .= '</span></td></tr>';
1.238 raeburn 11275: $itemcount ++;
11276: }
11277: $$rowtotal += $itemcount;
11278: } elsif ($position eq 'middle') {
1.57 raeburn 11279: my $toggle_cats_crs = ' ';
11280: my $toggle_cats_dom = ' checked="checked" ';
11281: my $can_cat_crs = ' ';
11282: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11283: my $toggle_catscomm_comm = ' ';
11284: my $toggle_catscomm_dom = ' checked="checked" ';
11285: my $can_catcomm_comm = ' ';
11286: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11287: my $toggle_catsplace_place = ' ';
11288: my $toggle_catsplace_dom = ' checked="checked" ';
11289: my $can_catplace_place = ' ';
11290: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11291:
1.57 raeburn 11292: if (ref($settings) eq 'HASH') {
11293: if ($settings->{'togglecats'} eq 'crs') {
11294: $toggle_cats_crs = $toggle_cats_dom;
11295: $toggle_cats_dom = ' ';
11296: }
11297: if ($settings->{'categorize'} eq 'crs') {
11298: $can_cat_crs = $can_cat_dom;
11299: $can_cat_dom = ' ';
11300: }
1.120 raeburn 11301: if ($settings->{'togglecatscomm'} eq 'comm') {
11302: $toggle_catscomm_comm = $toggle_catscomm_dom;
11303: $toggle_catscomm_dom = ' ';
11304: }
11305: if ($settings->{'categorizecomm'} eq 'comm') {
11306: $can_catcomm_comm = $can_catcomm_dom;
11307: $can_catcomm_dom = ' ';
11308: }
1.272 raeburn 11309: if ($settings->{'togglecatsplace'} eq 'place') {
11310: $toggle_catsplace_place = $toggle_catsplace_dom;
11311: $toggle_catsplace_dom = ' ';
11312: }
11313: if ($settings->{'categorizeplace'} eq 'place') {
11314: $can_catplace_place = $can_catplace_dom;
11315: $can_catplace_dom = ' ';
11316: }
1.57 raeburn 11317: }
11318: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11319: togglecats => 'Show/Hide a course in catalog',
11320: togglecatscomm => 'Show/Hide a community in catalog',
11321: togglecatsplace => 'Show/Hide a placement test in catalog',
11322: categorize => 'Assign a category to a course',
11323: categorizecomm => 'Assign a category to a community',
11324: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11325: );
11326: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11327: dom => 'Set in Domain',
11328: crs => 'Set in Course',
11329: comm => 'Set in Community',
11330: place => 'Set in Placement Test',
1.57 raeburn 11331: );
11332: $datatable = '<tr class="LC_odd_row">'.
11333: '<td>'.$title{'togglecats'}.'</td>'.
11334: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11335: '<input type="radio" name="togglecats"'.
11336: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11337: '<label><input type="radio" name="togglecats"'.
11338: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11339: '</tr><tr>'.
11340: '<td>'.$title{'categorize'}.'</td>'.
11341: '<td class="LC_right_item"><span class="LC_nobreak">'.
11342: '<label><input type="radio" name="categorize"'.
11343: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11344: '<label><input type="radio" name="categorize"'.
11345: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11346: '</tr><tr class="LC_odd_row">'.
11347: '<td>'.$title{'togglecatscomm'}.'</td>'.
11348: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11349: '<input type="radio" name="togglecatscomm"'.
11350: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11351: '<label><input type="radio" name="togglecatscomm"'.
11352: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11353: '</tr><tr>'.
11354: '<td>'.$title{'categorizecomm'}.'</td>'.
11355: '<td class="LC_right_item"><span class="LC_nobreak">'.
11356: '<label><input type="radio" name="categorizecomm"'.
11357: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11358: '<label><input type="radio" name="categorizecomm"'.
11359: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11360: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11361: '<td>'.$title{'togglecatsplace'}.'</td>'.
11362: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11363: '<input type="radio" name="togglecatsplace"'.
11364: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11365: '<label><input type="radio" name="togglecatscomm"'.
11366: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11367: '</tr><tr>'.
11368: '<td>'.$title{'categorizeplace'}.'</td>'.
11369: '<td class="LC_right_item"><span class="LC_nobreak">'.
11370: '<label><input type="radio" name="categorizeplace"'.
11371: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11372: '<label><input type="radio" name="categorizeplace"'.
11373: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11374: '</tr>';
1.272 raeburn 11375: $$rowtotal += 6;
1.57 raeburn 11376: } else {
11377: my $css_class;
11378: my $itemcount = 1;
11379: my $cathash;
11380: if (ref($settings) eq 'HASH') {
11381: $cathash = $settings->{'cats'};
11382: }
11383: if (ref($cathash) eq 'HASH') {
11384: my (@cats,@trails,%allitems,%idx,@jsarray);
11385: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11386: \%allitems,\%idx,\@jsarray);
11387: my $maxdepth = scalar(@cats);
11388: my $colattrib = '';
11389: if ($maxdepth > 2) {
11390: $colattrib = ' colspan="2" ';
11391: }
11392: my @path;
11393: if (@cats > 0) {
11394: if (ref($cats[0]) eq 'ARRAY') {
11395: my $numtop = @{$cats[0]};
11396: my $maxnum = $numtop;
1.120 raeburn 11397: my %default_names = (
11398: instcode => &mt('Official courses'),
11399: communities => &mt('Communities'),
1.272 raeburn 11400: placement => &mt('Placement Tests'),
1.120 raeburn 11401: );
11402:
11403: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11404: ($cathash->{'instcode::0'} eq '') ||
11405: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11406: ($cathash->{'communities::0'} eq '') ||
11407: (!grep(/^placement$/,@{$cats[0]})) ||
11408: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11409: $maxnum ++;
11410: }
11411: my $lastidx;
11412: for (my $i=0; $i<$numtop; $i++) {
11413: my $parent = $cats[0][$i];
11414: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11415: my $item = &escape($parent).'::0';
11416: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11417: $lastidx = $idx{$item};
11418: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11419: .'<select name="'.$item.'"'.$chgstr.'>';
11420: for (my $k=0; $k<=$maxnum; $k++) {
11421: my $vpos = $k+1;
11422: my $selstr;
11423: if ($k == $i) {
11424: $selstr = ' selected="selected" ';
11425: }
11426: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11427: }
1.214 raeburn 11428: $datatable .= '</select></span></td><td>';
1.272 raeburn 11429: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11430: $datatable .= '<span class="LC_nobreak">'
11431: .$default_names{$parent}.'</span>';
11432: if ($parent eq 'instcode') {
11433: $datatable .= '<br /><span class="LC_nobreak">('
11434: .&mt('with institutional codes')
11435: .')</span></td><td'.$colattrib.'>';
11436: } else {
11437: $datatable .= '<table><tr><td>';
11438: }
11439: $datatable .= '<span class="LC_nobreak">'
11440: .'<label><input type="radio" name="'
11441: .$parent.'" value="1" checked="checked" />'
11442: .&mt('Display').'</label>';
11443: if ($parent eq 'instcode') {
11444: $datatable .= ' ';
11445: } else {
11446: $datatable .= '</span></td></tr><tr><td>'
11447: .'<span class="LC_nobreak">';
11448: }
11449: $datatable .= '<label><input type="radio" name="'
11450: .$parent.'" value="0" />'
11451: .&mt('Do not display').'</label></span>';
1.272 raeburn 11452: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11453: $datatable .= '</td></tr></table>';
11454: }
11455: $datatable .= '</td>';
1.57 raeburn 11456: } else {
11457: $datatable .= $parent
1.214 raeburn 11458: .' <span class="LC_nobreak"><label>'
11459: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11460: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11461: }
11462: my $depth = 1;
11463: push(@path,$parent);
11464: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11465: pop(@path);
11466: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11467: $itemcount ++;
11468: }
1.48 raeburn 11469: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11470: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11471: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11472: for (my $k=0; $k<=$maxnum; $k++) {
11473: my $vpos = $k+1;
11474: my $selstr;
1.57 raeburn 11475: if ($k == $numtop) {
1.48 raeburn 11476: $selstr = ' selected="selected" ';
11477: }
11478: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11479: }
1.59 bisitz 11480: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11481: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11482: .'</tr>'."\n";
1.48 raeburn 11483: $itemcount ++;
1.272 raeburn 11484: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11485: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11486: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11487: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11488: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11489: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11490: for (my $k=0; $k<=$maxnum; $k++) {
11491: my $vpos = $k+1;
11492: my $selstr;
11493: if ($k == $maxnum) {
11494: $selstr = ' selected="selected" ';
11495: }
11496: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11497: }
1.120 raeburn 11498: $datatable .= '</select></span></td>'.
11499: '<td><span class="LC_nobreak">'.
11500: $default_names{$default}.'</span>';
11501: if ($default eq 'instcode') {
11502: $datatable .= '<br /><span class="LC_nobreak">('
11503: .&mt('with institutional codes').')</span>';
11504: }
11505: $datatable .= '</td>'
11506: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11507: .&mt('Display').'</label> '
11508: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11509: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11510: }
11511: }
11512: }
1.57 raeburn 11513: } else {
11514: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11515: }
11516: } else {
1.327 raeburn 11517: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11518: .&initialize_categories($itemcount);
1.48 raeburn 11519: }
1.57 raeburn 11520: $$rowtotal += $itemcount;
1.48 raeburn 11521: }
11522: return $datatable;
11523: }
11524:
1.69 raeburn 11525: sub print_serverstatuses {
11526: my ($dom,$settings,$rowtotal) = @_;
11527: my $datatable;
11528: my @pages = &serverstatus_pages();
11529: my (%namedaccess,%machineaccess);
11530: foreach my $type (@pages) {
11531: $namedaccess{$type} = '';
11532: $machineaccess{$type}= '';
11533: }
11534: if (ref($settings) eq 'HASH') {
11535: foreach my $type (@pages) {
11536: if (exists($settings->{$type})) {
11537: if (ref($settings->{$type}) eq 'HASH') {
11538: foreach my $key (keys(%{$settings->{$type}})) {
11539: if ($key eq 'namedusers') {
11540: $namedaccess{$type} = $settings->{$type}->{$key};
11541: } elsif ($key eq 'machines') {
11542: $machineaccess{$type} = $settings->{$type}->{$key};
11543: }
11544: }
11545: }
11546: }
11547: }
11548: }
1.81 raeburn 11549: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11550: my $rownum = 0;
11551: my $css_class;
11552: foreach my $type (@pages) {
11553: $rownum ++;
11554: $css_class = $rownum%2?' class="LC_odd_row"':'';
11555: $datatable .= '<tr'.$css_class.'>'.
11556: '<td><span class="LC_nobreak">'.
11557: $titles->{$type}.'</span></td>'.
11558: '<td class="LC_left_item">'.
11559: '<input type="text" name="'.$type.'_namedusers" '.
11560: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11561: '<td class="LC_right_item">'.
11562: '<span class="LC_nobreak">'.
11563: '<input type="text" name="'.$type.'_machines" '.
11564: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11565: '</span></td></tr>'."\n";
1.69 raeburn 11566: }
11567: $$rowtotal += $rownum;
11568: return $datatable;
11569: }
11570:
11571: sub serverstatus_pages {
11572: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11573: 'checksums','clusterstatus','certstatus','metadata_keywords',
11574: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11575: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11576: }
11577:
1.236 raeburn 11578: sub defaults_javascript {
11579: my ($settings) = @_;
1.354 raeburn 11580: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11581: my $portal_js = <<"ENDPORTAL";
11582:
11583: function portalExtras(caller) {
11584: var x = caller.value;
11585: var y = new Array('email','web');
1.425 raeburn 11586: for (var i=0; i<y.length; i++) {
1.414 raeburn 11587: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11588: var z = document.getElementById('portal_def_'+y[i]+'_div');
11589: if (x.length > 0) {
11590: z.style.display = 'block';
11591: } else {
11592: z.style.display = 'none';
11593: }
11594: }
11595: }
11596: }
11597: ENDPORTAL
1.236 raeburn 11598: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11599: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11600: if ($maxnum eq '') {
11601: $maxnum = 0;
11602: }
11603: $maxnum ++;
1.249 raeburn 11604: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11605: return <<"ENDSCRIPT";
11606: <script type="text/javascript">
11607: // <![CDATA[
11608: function reorderTypes(form,caller) {
11609: var changedVal;
11610: $jstext
11611: var newpos = 'addinststatus_pos';
11612: var current = new Array;
11613: var maxh = $maxnum;
11614: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11615: var oldVal;
11616: if (caller == newpos) {
11617: changedVal = newitemVal;
11618: } else {
11619: var curritem = 'inststatus_pos_'+caller;
11620: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11621: current[newitemVal] = newpos;
11622: }
11623: for (var i=0; i<inststatuses.length; i++) {
11624: if (inststatuses[i] != caller) {
11625: var elementName = 'inststatus_pos_'+inststatuses[i];
11626: if (form.elements[elementName]) {
11627: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11628: current[currVal] = elementName;
11629: }
11630: }
11631: }
11632: for (var j=0; j<maxh; j++) {
11633: if (current[j] == undefined) {
11634: oldVal = j;
11635: }
11636: }
11637: if (oldVal < changedVal) {
11638: for (var k=oldVal+1; k<=changedVal ; k++) {
11639: var elementName = current[k];
11640: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11641: }
11642: } else {
11643: for (var k=changedVal; k<oldVal; k++) {
11644: var elementName = current[k];
11645: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11646: }
11647: }
11648: return;
11649: }
11650:
1.414 raeburn 11651: $portal_js
11652:
11653: // ]]>
11654: </script>
11655:
11656: ENDSCRIPT
11657: } else {
11658: return <<"ENDSCRIPT";
11659: <script type="text/javascript">
11660: // <![CDATA[
11661: $portal_js
1.236 raeburn 11662: // ]]>
11663: </script>
11664:
11665: ENDSCRIPT
11666: }
1.354 raeburn 11667: return;
11668: }
11669:
11670: sub passwords_javascript {
1.405 raeburn 11671: my ($prefix) = @_;
11672: my %intalert;
11673: if ($prefix eq 'passwords') {
11674: %intalert = &Apache::lonlocal::texthash (
11675: 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.',
11676: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11677: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11678: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11679: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11680: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11681: );
1.421 raeburn 11682: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11683: %intalert = &Apache::lonlocal::texthash (
11684: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11685: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11686: );
11687: }
1.365 raeburn 11688: &js_escape(\%intalert);
11689: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11690: my $intauthjs;
1.405 raeburn 11691: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11692:
11693: function warnIntAuth(field) {
11694: if (field.name == 'intauth_check') {
11695: if (field.value == '2') {
1.365 raeburn 11696: alert('$intalert{authcheck}');
1.354 raeburn 11697: }
11698: }
11699: if (field.name == 'intauth_cost') {
11700: field.value.replace(/\s/g,'');
11701: if (field.value != '') {
11702: var regexdigit=/^\\d+\$/;
11703: if (!regexdigit.test(field.value)) {
1.365 raeburn 11704: alert('$intalert{authcost}');
11705: }
11706: }
11707: }
11708: return;
11709: }
11710:
1.405 raeburn 11711: ENDSCRIPT
11712:
11713: }
11714:
11715: $intauthjs .= <<"ENDSCRIPT";
11716:
11717: function warnInt$prefix(field) {
1.365 raeburn 11718: field.value.replace(/^\s+/,'');
11719: field.value.replace(/\s+\$/,'');
11720: var regexdigit=/^\\d+\$/;
1.408 raeburn 11721: if (field.name == '${prefix}_min') {
1.365 raeburn 11722: if (field.value == '') {
11723: alert('$intalert{passmin}');
11724: field.value = '$defmin';
11725: } else {
11726: if (!regexdigit.test(field.value)) {
11727: alert('$intalert{passmin}');
11728: field.value = '$defmin';
11729: }
1.366 raeburn 11730: var minval = parseInt(field.value,10);
1.365 raeburn 11731: if (minval < $defmin) {
11732: alert('$intalert{passmin}');
11733: field.value = '$defmin';
11734: }
11735: }
11736: } else {
11737: if (field.value == '0') {
11738: field.value = '';
11739: }
11740: if (field.value != '') {
1.408 raeburn 11741: if (field.name == '${prefix}_expire') {
1.365 raeburn 11742: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11743: if (!regexpposnum.test(field.value)) {
11744: alert('$intalert{passexp}');
11745: field.value = '';
11746: } else {
11747: var expval = parseFloat(field.value);
11748: if (expval == 0) {
11749: alert('$intalert{passexp}');
11750: field.value = '';
11751: }
11752: }
11753: } else {
11754: if (!regexdigit.test(field.value)) {
1.408 raeburn 11755: if (field.name == '${prefix}_max') {
1.365 raeburn 11756: alert('$intalert{passmax}');
11757: } else {
1.408 raeburn 11758: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11759: alert('$intalert{passnum}');
11760: }
11761: }
1.370 raeburn 11762: field.value = '';
1.365 raeburn 11763: }
1.354 raeburn 11764: }
11765: }
11766: }
11767: return;
11768: }
11769:
11770: ENDSCRIPT
11771: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11772: }
11773:
1.49 raeburn 11774: sub coursecategories_javascript {
11775: my ($settings) = @_;
1.57 raeburn 11776: my ($output,$jstext,$cathash);
1.49 raeburn 11777: if (ref($settings) eq 'HASH') {
1.57 raeburn 11778: $cathash = $settings->{'cats'};
11779: }
11780: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11781: my (@cats,@jsarray,%idx);
1.57 raeburn 11782: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11783: if (@jsarray > 0) {
11784: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11785: for (my $i=0; $i<@jsarray; $i++) {
11786: if (ref($jsarray[$i]) eq 'ARRAY') {
11787: my $catstr = join('","',@{$jsarray[$i]});
11788: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11789: }
11790: }
11791: }
11792: } else {
11793: $jstext = ' var categories = Array(1);'."\n".
11794: ' categories[0] = Array("instcode_pos");'."\n";
11795: }
1.237 bisitz 11796: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11797: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11798: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11799: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11800: &js_escape(\$instcode_reserved);
11801: &js_escape(\$communities_reserved);
1.272 raeburn 11802: &js_escape(\$placement_reserved);
1.265 damieng 11803: &js_escape(\$choose_again);
1.49 raeburn 11804: $output = <<"ENDSCRIPT";
11805: <script type="text/javascript">
1.109 raeburn 11806: // <![CDATA[
1.49 raeburn 11807: function reorderCats(form,parent,item,idx) {
11808: var changedVal;
11809: $jstext
11810: var newpos = 'addcategory_pos';
11811: if (parent == '') {
11812: var has_instcode = 0;
11813: var maxtop = categories[idx].length;
11814: for (var j=0; j<maxtop; j++) {
11815: if (categories[idx][j] == 'instcode::0') {
11816: has_instcode == 1;
11817: }
11818: }
11819: if (has_instcode == 0) {
11820: categories[idx][maxtop] = 'instcode_pos';
11821: }
11822: } else {
11823: newpos += '_'+parent;
11824: }
11825: var maxh = 1 + categories[idx].length;
11826: var current = new Array;
11827: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11828: if (item == newpos) {
11829: changedVal = newitemVal;
11830: } else {
11831: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11832: current[newitemVal] = newpos;
11833: }
11834: for (var i=0; i<categories[idx].length; i++) {
11835: var elementName = categories[idx][i];
11836: if (elementName != item) {
11837: if (form.elements[elementName]) {
11838: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11839: current[currVal] = elementName;
11840: }
11841: }
11842: }
11843: var oldVal;
11844: for (var j=0; j<maxh; j++) {
11845: if (current[j] == undefined) {
11846: oldVal = j;
11847: }
11848: }
11849: if (oldVal < changedVal) {
11850: for (var k=oldVal+1; k<=changedVal ; k++) {
11851: var elementName = current[k];
11852: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11853: }
11854: } else {
11855: for (var k=changedVal; k<oldVal; k++) {
11856: var elementName = current[k];
11857: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11858: }
11859: }
11860: return;
11861: }
1.120 raeburn 11862:
11863: function categoryCheck(form) {
11864: if (form.elements['addcategory_name'].value == 'instcode') {
11865: alert('$instcode_reserved\\n$choose_again');
11866: return false;
11867: }
11868: if (form.elements['addcategory_name'].value == 'communities') {
11869: alert('$communities_reserved\\n$choose_again');
11870: return false;
11871: }
1.272 raeburn 11872: if (form.elements['addcategory_name'].value == 'placement') {
11873: alert('$placement_reserved\\n$choose_again');
11874: return false;
11875: }
1.120 raeburn 11876: return true;
11877: }
11878:
1.109 raeburn 11879: // ]]>
1.49 raeburn 11880: </script>
11881:
11882: ENDSCRIPT
11883: return $output;
11884: }
11885:
1.48 raeburn 11886: sub initialize_categories {
11887: my ($itemcount) = @_;
1.120 raeburn 11888: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11889: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11890: instcode => 'Official courses (with institutional codes)',
11891: communities => 'Communities',
1.272 raeburn 11892: placement => 'Placement Tests',
1.120 raeburn 11893: );
1.328 raeburn 11894: my %selnum = (
11895: instcode => '0',
11896: communities => '1',
11897: placement => '2',
11898: );
11899: my %selected;
1.272 raeburn 11900: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11901: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11902: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11903: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11904: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11905: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11906: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11907: .'<option value="0"'.$selected{'0'}.'>1</option>'
11908: .'<option value="1"'.$selected{'1'}.'>2</option>'
11909: .'<option value="2"'.$selected{'2'}.'>3</option>'
11910: .'<option value="3">4</option></select> '
1.120 raeburn 11911: .$default_names{$default}
11912: .'</span></td><td><span class="LC_nobreak">'
11913: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11914: .&mt('Display').'</label> <label>'
11915: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11916: .'</label></span></td></tr>';
1.120 raeburn 11917: $itemcount ++;
11918: }
1.48 raeburn 11919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11920: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11921: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11922: .'<select name="addcategory_pos"'.$chgstr.'>'
11923: .'<option value="0">1</option>'
11924: .'<option value="1">2</option>'
1.328 raeburn 11925: .'<option value="2">3</option>'
11926: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11927: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11928: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11929: .'</td></tr>';
1.48 raeburn 11930: return $datatable;
11931: }
11932:
11933: sub build_category_rows {
1.49 raeburn 11934: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11935: my ($text,$name,$item,$chgstr);
1.48 raeburn 11936: if (ref($cats) eq 'ARRAY') {
11937: my $maxdepth = scalar(@{$cats});
11938: if (ref($cats->[$depth]) eq 'HASH') {
11939: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11940: my $numchildren = @{$cats->[$depth]{$parent}};
11941: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11942: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11943: my ($idxnum,$parent_name,$parent_item);
11944: my $higher = $depth - 1;
11945: if ($higher == 0) {
11946: $parent_name = &escape($parent).'::'.$higher;
11947: } else {
11948: if (ref($path) eq 'ARRAY') {
11949: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
11950: }
11951: }
11952: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 11953: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 11954: if ($j < $numchildren) {
1.48 raeburn 11955: $name = $cats->[$depth]{$parent}[$j];
11956: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 11957: $idxnum = $idx->{$item};
11958: } else {
11959: $name = $parent_name;
11960: $item = $parent_item;
1.48 raeburn 11961: }
1.49 raeburn 11962: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
11963: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 11964: for (my $i=0; $i<=$numchildren; $i++) {
11965: my $vpos = $i+1;
11966: my $selstr;
11967: if ($j == $i) {
11968: $selstr = ' selected="selected" ';
11969: }
11970: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
11971: }
11972: $text .= '</select> ';
11973: if ($j < $numchildren) {
11974: my $deeper = $depth+1;
11975: $text .= $name.' '
11976: .'<label><input type="checkbox" name="deletecategory" value="'
11977: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
11978: if(ref($path) eq 'ARRAY') {
11979: push(@{$path},$name);
1.49 raeburn 11980: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 11981: pop(@{$path});
11982: }
11983: } else {
1.330 raeburn 11984: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 11985: if ($j == $numchildren) {
11986: $text .= $name;
11987: } else {
11988: $text .= $item;
11989: }
11990: $text .= '" value="" />';
11991: }
11992: $text .= '</td></tr>';
11993: }
11994: $text .= '</table></td>';
11995: } else {
11996: my $higher = $depth-1;
11997: if ($higher == 0) {
11998: $name = &escape($parent).'::'.$higher;
11999: } else {
12000: if (ref($path) eq 'ARRAY') {
12001: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12002: }
12003: }
12004: my $colspan;
12005: if ($parent ne 'instcode') {
12006: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12007: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12008: }
12009: }
12010: }
12011: }
12012: return $text;
12013: }
12014:
1.33 raeburn 12015: sub modifiable_userdata_row {
1.305 raeburn 12016: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12017: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12018: my ($role,$rolename,$statustype);
12019: $role = $item;
1.224 raeburn 12020: if ($context eq 'cancreate') {
1.305 raeburn 12021: if ($item =~ /^(emailusername)_(.+)$/) {
12022: $role = $1;
12023: $statustype = $2;
1.228 raeburn 12024: if (ref($usertypes) eq 'HASH') {
12025: if ($usertypes->{$statustype}) {
12026: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12027: } else {
12028: $rolename = &mt('Data provided by user');
12029: }
12030: }
1.224 raeburn 12031: }
12032: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12033: if (ref($usertypes) eq 'HASH') {
12034: $rolename = $usertypes->{$role};
12035: } else {
12036: $rolename = $role;
12037: }
1.325 raeburn 12038: } elsif ($context eq 'lti') {
12039: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12040: } elsif ($context eq 'privacy') {
12041: $rolename = $itemdesc;
1.33 raeburn 12042: } else {
1.63 raeburn 12043: if ($role eq 'cr') {
12044: $rolename = &mt('Custom role');
12045: } else {
12046: $rolename = &Apache::lonnet::plaintext($role);
12047: }
1.33 raeburn 12048: }
1.224 raeburn 12049: my (@fields,%fieldtitles);
12050: if (ref($fieldsref) eq 'ARRAY') {
12051: @fields = @{$fieldsref};
12052: } else {
12053: @fields = ('lastname','firstname','middlename','generation',
12054: 'permanentemail','id');
12055: }
12056: if ((ref($titlesref) eq 'HASH')) {
12057: %fieldtitles = %{$titlesref};
12058: } else {
12059: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12060: }
1.33 raeburn 12061: my $output;
1.305 raeburn 12062: my $css_class;
12063: if ($rowcount%2) {
12064: $css_class = 'LC_odd_row';
12065: }
12066: if ($customcss) {
12067: $css_class .= " $customcss";
12068: }
12069: $css_class =~ s/^\s+//;
12070: if ($css_class) {
12071: $css_class = ' class="'.$css_class.'"';
12072: }
12073: if ($rowstyle) {
12074: $css_class .= ' style="'.$rowstyle.'"';
12075: }
12076: if ($rowid) {
12077: $rowid = ' id="'.$rowid.'"';
12078: }
12079: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12080: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12081: '<td class="LC_left_item" colspan="2"><table>';
12082: my $rem;
12083: my %checks;
12084: if (ref($settings) eq 'HASH') {
1.325 raeburn 12085: my $hashref;
12086: if ($context eq 'lti') {
12087: if (ref($settings) eq 'HASH') {
12088: $hashref = $settings->{'instdata'};
12089: }
1.357 raeburn 12090: } elsif ($context eq 'privacy') {
12091: my ($key,$inner) = split(/_/,$role);
12092: if (ref($settings) eq 'HASH') {
12093: if (ref($settings->{$key}) eq 'HASH') {
12094: $hashref = $settings->{$key}->{$inner};
12095: }
12096: }
1.325 raeburn 12097: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12098: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12099: $hashref = $settings->{'lti_instdata'};
12100: }
12101: if ($role eq 'emailusername') {
12102: if ($statustype) {
12103: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12104: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12105: }
1.325 raeburn 12106: }
12107: }
12108: }
1.425 raeburn 12109: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12110: foreach my $field (@fields) {
12111: if ($hashref->{$field}) {
12112: if ($role eq 'emailusername') {
12113: $checks{$field} = $hashref->{$field};
12114: } else {
12115: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12116: }
12117: }
12118: }
12119: }
12120: }
1.305 raeburn 12121: my $total = scalar(@fields);
12122: for (my $i=0; $i<$total; $i++) {
12123: $rem = $i%($numinrow);
1.33 raeburn 12124: if ($rem == 0) {
12125: if ($i > 0) {
12126: $output .= '</tr>';
12127: }
12128: $output .= '<tr>';
12129: }
12130: my $check = ' ';
1.228 raeburn 12131: unless ($role eq 'emailusername') {
12132: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12133: $check = $checks{$fields[$i]};
1.357 raeburn 12134: } elsif ($context eq 'privacy') {
12135: if ($role =~ /^priv_(domain|course)$/) {
12136: if (ref($settings) ne 'HASH') {
12137: $check = ' checked="checked" ';
12138: }
12139: } elsif ($role =~ /^priv_(author|community)$/) {
12140: if (ref($settings) ne 'HASH') {
12141: unless ($fields[$i] eq 'id') {
12142: $check = ' checked="checked" ';
12143: }
12144: }
12145: } elsif ($role =~ /^(unpriv|othdom)_/) {
12146: if (ref($settings) ne 'HASH') {
12147: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12148: $check = ' checked="checked" ';
12149: }
12150: }
12151: }
1.325 raeburn 12152: } elsif ($context ne 'lti') {
1.228 raeburn 12153: if ($role eq 'st') {
12154: if (ref($settings) ne 'HASH') {
12155: $check = ' checked="checked" ';
12156: }
1.33 raeburn 12157: }
12158: }
12159: }
12160: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12161: '<span class="LC_nobreak">';
1.325 raeburn 12162: my $prefix = 'canmodify';
1.228 raeburn 12163: if ($role eq 'emailusername') {
12164: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12165: $checks{$fields[$i]} = 'omit';
12166: }
12167: foreach my $option ('required','optional','omit') {
12168: my $checked='';
12169: if ($checks{$fields[$i]} eq $option) {
12170: $checked='checked="checked" ';
12171: }
12172: $output .= '<label>'.
1.325 raeburn 12173: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12174: &mt($option).'</label>'.(' ' x2);
12175: }
12176: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12177: } else {
1.325 raeburn 12178: if ($context eq 'lti') {
12179: $prefix = 'lti';
1.357 raeburn 12180: } elsif ($context eq 'privacy') {
12181: $prefix = 'privacy';
1.325 raeburn 12182: }
1.228 raeburn 12183: $output .= '<label>'.
1.325 raeburn 12184: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12185: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12186: '</label>';
12187: }
12188: $output .= '</span></td>';
1.33 raeburn 12189: }
1.305 raeburn 12190: $rem = $total%$numinrow;
12191: my $colsleft;
12192: if ($rem) {
12193: $colsleft = $numinrow - $rem;
12194: }
12195: if ($colsleft > 1) {
1.33 raeburn 12196: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12197: ' </td>';
12198: } elsif ($colsleft == 1) {
12199: $output .= '<td class="LC_left_item"> </td>';
12200: }
12201: $output .= '</tr></table></td></tr>';
12202: return $output;
12203: }
1.28 raeburn 12204:
1.93 raeburn 12205: sub insttypes_row {
1.305 raeburn 12206: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12207: $customcss,$rowstyle) = @_;
1.93 raeburn 12208: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12209: cansearch => 'Users allowed to search',
1.93 raeburn 12210: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12211: lockablenames => 'User preference to lock name',
12212: selfassign => 'Self-reportable affiliations',
12213: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12214: webdav => 'WebDAV access available',
12215: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12216: );
1.429 raeburn 12217: my ($showdom,$defaultquota);
1.93 raeburn 12218: if ($context eq 'cansearch') {
12219: $showdom = ' ('.$dom.')';
1.429 raeburn 12220: } elsif ($context eq 'authorquota') {
12221: $defaultquota = 500;
1.93 raeburn 12222: }
1.165 raeburn 12223: my $class = 'LC_left_item';
12224: if ($context eq 'statustocreate') {
12225: $class = 'LC_right_item';
12226: }
1.305 raeburn 12227: my $css_class;
12228: if ($$rowtotal%2) {
12229: $css_class = 'LC_odd_row';
12230: }
12231: if ($customcss) {
12232: $css_class .= ' '.$customcss;
12233: }
12234: $css_class =~ s/^\s+//;
12235: if ($css_class) {
12236: $css_class = ' class="'.$css_class.'"';
12237: }
12238: if ($rowstyle) {
12239: $css_class .= ' style="'.$rowstyle.'"';
12240: }
12241: if ($onclick) {
12242: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12243: }
12244: my $output = '<tr'.$css_class.'>'.
12245: '<td>'.$lt{$context}.$showdom.
12246: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12247: my $rem;
12248: if (ref($types) eq 'ARRAY') {
12249: for (my $i=0; $i<@{$types}; $i++) {
12250: if (defined($usertypes->{$types->[$i]})) {
12251: my $rem = $i%($numinrow);
12252: if ($rem == 0) {
12253: if ($i > 0) {
12254: $output .= '</tr>';
12255: }
12256: $output .= '<tr>';
1.23 raeburn 12257: }
1.429 raeburn 12258: if ($context eq 'authorquota') {
12259: my $currquota;
12260: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12261: $currquota = $settings->{$context}->{$types->[$i]};
12262: } else {
12263: $currquota = $defaultquota;
12264: }
12265: $output .= '<td class="LC_left_item">'."\n".
12266: '<label><span class="LC_nobreak">'."\n".
12267: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12268: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12269: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12270: '</label></td>';
12271: } else {
12272: my $check = ' ';
12273: if (ref($settings) eq 'HASH') {
12274: if (ref($settings->{$context}) eq 'ARRAY') {
12275: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12276: $check = ' checked="checked" ';
12277: }
12278: } elsif (ref($settings->{$context}) eq 'HASH') {
12279: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12280: $check = ' checked="checked" ';
12281: } elsif ($context eq 'webdav') {
12282: if ($settings->{$context}->{$types->[$i]}) {
12283: $check = ' checked="checked" ';
12284: }
12285: }
12286: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12287: $check = ' checked="checked" ';
12288: }
1.26 raeburn 12289: }
1.429 raeburn 12290: $output .= '<td class="LC_left_item">'.
12291: '<span class="LC_nobreak"><label>'.
12292: '<input type="checkbox" name="'.$context.'" '.
12293: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12294: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12295: }
12296: }
12297: }
1.26 raeburn 12298: $rem = @{$types}%($numinrow);
1.23 raeburn 12299: }
12300: my $colsleft = $numinrow - $rem;
1.315 raeburn 12301: if ($context eq 'overrides') {
12302: if ($colsleft > 1) {
12303: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12304: } else {
12305: $output .= '<td class="LC_left_item">';
12306: }
1.425 raeburn 12307: $output .= ' ';
1.23 raeburn 12308: } else {
1.334 raeburn 12309: if ($rem == 0) {
1.315 raeburn 12310: $output .= '<tr>';
12311: }
12312: if ($colsleft > 1) {
12313: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12314: } else {
12315: $output .= '<td class="LC_left_item">';
12316: }
1.429 raeburn 12317: if ($context eq 'authorquota') {
12318: my $currquota = 500;
12319: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12320: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12321: $currquota = $settings->{$context}{'default'};
12322: }
12323: }
12324: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12325: '<input type="text" name="'.$context.'_default" '.
12326: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12327: '</label>';
12328: } else {
12329: my $defcheck = ' ';
12330: if (ref($settings) eq 'HASH') {
12331: if (ref($settings->{$context}) eq 'ARRAY') {
12332: if (grep(/^default$/,@{$settings->{$context}})) {
12333: $defcheck = ' checked="checked" ';
12334: }
12335: } elsif (ref($settings->{$context}) eq 'HASH') {
12336: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12337: $defcheck = ' checked="checked" ';
12338: } elsif ($context eq 'webdav') {
12339: if ($settings->{$context}->{'default'}) {
12340: $defcheck = ' checked="checked" ';
12341: }
12342: }
12343: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12344: $defcheck = ' checked="checked" ';
12345: }
1.99 raeburn 12346: }
1.429 raeburn 12347: $output .= '<span class="LC_nobreak"><label>'.
12348: '<input type="checkbox" name="'.$context.'" '.
12349: 'value="default"'.$defcheck.$onclick.'/>'.
12350: $othertitle.'</label></span>';
1.26 raeburn 12351: }
1.23 raeburn 12352: }
1.315 raeburn 12353: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12354: return $output;
1.23 raeburn 12355: }
12356:
12357: sub sorted_searchtitles {
12358: my %searchtitles = &Apache::lonlocal::texthash(
12359: 'uname' => 'username',
12360: 'lastname' => 'last name',
12361: 'lastfirst' => 'last name, first name',
12362: );
12363: my @titleorder = ('uname','lastname','lastfirst');
12364: return (\%searchtitles,\@titleorder);
12365: }
12366:
1.25 raeburn 12367: sub sorted_searchtypes {
12368: my %srchtypes_desc = (
12369: exact => 'is exact match',
12370: contains => 'contains ..',
12371: begins => 'begins with ..',
12372: );
12373: my @srchtypeorder = ('exact','begins','contains');
12374: return (\%srchtypes_desc,\@srchtypeorder);
12375: }
12376:
1.3 raeburn 12377: sub usertype_update_row {
12378: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12379: my $datatable;
12380: my $numinrow = 4;
12381: foreach my $type (@{$types}) {
12382: if (defined($usertypes->{$type})) {
12383: $$rownums ++;
12384: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12385: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12386: '</td><td class="LC_left_item"><table>';
12387: for (my $i=0; $i<@{$fields}; $i++) {
12388: my $rem = $i%($numinrow);
12389: if ($rem == 0) {
12390: if ($i > 0) {
12391: $datatable .= '</tr>';
12392: }
12393: $datatable .= '<tr>';
12394: }
12395: my $check = ' ';
1.39 raeburn 12396: if (ref($settings) eq 'HASH') {
12397: if (ref($settings->{'fields'}) eq 'HASH') {
12398: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12399: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12400: $check = ' checked="checked" ';
12401: }
1.3 raeburn 12402: }
12403: }
12404: }
12405:
12406: if ($i == @{$fields}-1) {
12407: my $colsleft = $numinrow - $rem;
12408: if ($colsleft > 1) {
12409: $datatable .= '<td colspan="'.$colsleft.'">';
12410: } else {
12411: $datatable .= '<td>';
12412: }
12413: } else {
12414: $datatable .= '<td>';
12415: }
1.8 raeburn 12416: $datatable .= '<span class="LC_nobreak"><label>'.
12417: '<input type="checkbox" name="updateable_'.$type.
12418: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12419: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12420: }
12421: $datatable .= '</tr></table></td></tr>';
12422: }
12423: }
12424: return $datatable;
1.1 raeburn 12425: }
12426:
12427: sub modify_login {
1.205 raeburn 12428: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12429: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12430: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12431: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12432: %title = ( coursecatalog => 'Display course catalog',
12433: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12434: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12435: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12436: loginheader => 'Log-in box header',
12437: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12438: @offon = ('off','on');
1.112 raeburn 12439: if (ref($domconfig{login}) eq 'HASH') {
12440: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12441: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12442: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12443: }
12444: }
1.386 raeburn 12445: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12446: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12447: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12448: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12449: $saml{$lonhost} = 1;
12450: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12451: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12452: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12453: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12454: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12455: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12456: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12457: }
12458: }
12459: }
1.112 raeburn 12460: }
1.9 raeburn 12461: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12462: \%domconfig,\%loginhash);
1.188 raeburn 12463: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12464: foreach my $item (@toggles) {
12465: $loginhash{login}{$item} = $env{'form.'.$item};
12466: }
1.41 raeburn 12467: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12468: if (ref($colchanges{'login'}) eq 'HASH') {
12469: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12470: \%loginhash);
12471: }
1.110 raeburn 12472:
1.149 raeburn 12473: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12474: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12475: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12476: if (keys(%servers) > 1) {
12477: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12478: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12479: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12480: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12481: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12482: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12483: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12484: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12485: $changes{'loginvia'}{$lonhost} = 1;
12486: } else {
12487: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12488: $changes{'loginvia'}{$lonhost} = 1;
12489: }
12490: } else {
12491: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12492: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12493: $changes{'loginvia'}{$lonhost} = 1;
12494: }
12495: }
12496: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12497: foreach my $item (@loginvia_attribs) {
12498: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12499: }
12500: } else {
12501: foreach my $item (@loginvia_attribs) {
12502: my $new = $env{'form.'.$lonhost.'_'.$item};
12503: if (($item eq 'serverpath') && ($new eq 'custom')) {
12504: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12505: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12506: $new = '/';
12507: }
12508: }
12509: if (($item eq 'custompath') &&
12510: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12511: $new = '';
12512: }
12513: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12514: $changes{'loginvia'}{$lonhost} = 1;
12515: }
12516: if ($item eq 'exempt') {
1.256 raeburn 12517: $new = &check_exempt_addresses($new);
1.128 raeburn 12518: }
12519: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12520: }
12521: }
1.112 raeburn 12522: } else {
1.128 raeburn 12523: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12524: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12525: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12526: foreach my $item (@loginvia_attribs) {
12527: my $new = $env{'form.'.$lonhost.'_'.$item};
12528: if (($item eq 'serverpath') && ($new eq 'custom')) {
12529: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12530: $new = '/';
12531: }
12532: }
12533: if (($item eq 'custompath') &&
12534: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12535: $new = '';
12536: }
12537: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12538: }
1.110 raeburn 12539: }
12540: }
12541: }
12542: }
1.119 raeburn 12543:
1.168 raeburn 12544: my $servadm = $r->dir_config('lonAdmEMail');
12545: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12546: if (ref($domconfig{'login'}) eq 'HASH') {
12547: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12548: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12549: if ($lang eq 'nolang') {
12550: push(@currlangs,$lang);
12551: } elsif (defined($langchoices{$lang})) {
12552: push(@currlangs,$lang);
12553: } else {
12554: next;
12555: }
12556: }
12557: }
12558: }
12559: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12560: if (@currlangs > 0) {
12561: foreach my $lang (@currlangs) {
12562: if (grep(/^\Q$lang\E$/,@delurls)) {
12563: $changes{'helpurl'}{$lang} = 1;
12564: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12565: $changes{'helpurl'}{$lang} = 1;
12566: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12567: push(@newlangs,$lang);
12568: } else {
12569: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12570: }
12571: }
12572: }
12573: unless (grep(/^nolang$/,@currlangs)) {
12574: if ($env{'form.loginhelpurl_nolang.filename'}) {
12575: $changes{'helpurl'}{'nolang'} = 1;
12576: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12577: push(@newlangs,'nolang');
12578: }
12579: }
12580: if ($env{'form.loginhelpurl_add_lang'}) {
12581: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12582: ($env{'form.loginhelpurl_add_file.filename'})) {
12583: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12584: $addedfile = $env{'form.loginhelpurl_add_lang'};
12585: }
12586: }
12587: if ((@newlangs > 0) || ($addedfile)) {
12588: my $error;
12589: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12590: if ($configuserok eq 'ok') {
12591: if ($switchserver) {
12592: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12593: } elsif ($author_ok eq 'ok') {
12594: my @allnew = @newlangs;
12595: if ($addedfile ne '') {
12596: push(@allnew,$addedfile);
12597: }
1.421 raeburn 12598: my $modified = [];
1.168 raeburn 12599: foreach my $lang (@allnew) {
12600: my $formelem = 'loginhelpurl_'.$lang;
12601: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12602: $formelem = 'loginhelpurl_add_file';
12603: }
1.425 raeburn 12604: (my $result,$newurl{$lang}) =
1.421 raeburn 12605: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12606: "help/$lang",'','',$newfile{$lang},
12607: $modified);
1.168 raeburn 12608: if ($result eq 'ok') {
12609: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12610: $changes{'helpurl'}{$lang} = 1;
12611: } else {
12612: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12613: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12614: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12615: (!grep(/^\Q$lang\E$/,@delurls))) {
12616: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12617: }
12618: }
12619: }
1.421 raeburn 12620: &update_modify_urls($r,$modified);
1.168 raeburn 12621: } else {
12622: $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);
12623: }
12624: } else {
12625: $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);
12626: }
12627: if ($error) {
12628: &Apache::lonnet::logthis($error);
12629: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12630: }
12631: }
1.256 raeburn 12632:
12633: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12634: if (ref($domconfig{'login'}) eq 'HASH') {
12635: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12636: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12637: if ($domservers{$lonhost}) {
12638: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12639: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12640: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12641: }
12642: }
12643: }
12644: }
12645: }
12646: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12647: foreach my $lonhost (sort(keys(%domservers))) {
12648: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12649: $changes{'headtag'}{$lonhost} = 1;
12650: } else {
12651: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12652: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12653: }
12654: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12655: push(@newhosts,$lonhost);
12656: } elsif ($currheadtagurls{$lonhost}) {
12657: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12658: if ($currexempt{$lonhost}) {
1.289 raeburn 12659: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12660: $changes{'headtag'}{$lonhost} = 1;
12661: }
12662: } elsif ($possexempt{$lonhost}) {
12663: $changes{'headtag'}{$lonhost} = 1;
12664: }
12665: if ($possexempt{$lonhost}) {
12666: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12667: }
12668: }
12669: }
12670: }
12671: if (@newhosts) {
12672: my $error;
12673: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12674: if ($configuserok eq 'ok') {
12675: if ($switchserver) {
12676: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12677: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12678: my $modified = [];
1.256 raeburn 12679: foreach my $lonhost (@newhosts) {
12680: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12681: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12682: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12683: "login/headtag/$lonhost",'','',
12684: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12685: $modified);
1.256 raeburn 12686: if ($result eq 'ok') {
12687: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12688: $changes{'headtag'}{$lonhost} = 1;
12689: if ($possexempt{$lonhost}) {
12690: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12691: }
12692: } else {
12693: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12694: $newheadtagurls{$lonhost},$result);
12695: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12696: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12697: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12698: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12699: }
12700: }
12701: }
1.421 raeburn 12702: &update_modify_urls($r,$modified);
1.256 raeburn 12703: } else {
12704: $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);
12705: }
12706: } else {
12707: $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);
12708: }
12709: if ($error) {
12710: &Apache::lonnet::logthis($error);
12711: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12712: }
12713: }
1.386 raeburn 12714: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12715: my @newsamlimgs;
12716: foreach my $lonhost (keys(%domservers)) {
12717: if ($env{'form.saml_'.$lonhost}) {
12718: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12719: push(@newsamlimgs,$lonhost);
12720: }
1.412 raeburn 12721: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12722: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12723: }
12724: if ($saml{$lonhost}) {
1.412 raeburn 12725: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12726: $env{'form.saml_window_'.$lonhost} = '';
12727: }
1.386 raeburn 12728: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12729: #FIXME Need to obsolete published image
12730: delete($currsaml{$lonhost}{'img'});
12731: $changes{'saml'}{$lonhost} = 1;
12732: }
12733: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12734: $changes{'saml'}{$lonhost} = 1;
12735: }
12736: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12737: $changes{'saml'}{$lonhost} = 1;
12738: }
12739: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12740: $changes{'saml'}{$lonhost} = 1;
12741: }
12742: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12743: $changes{'saml'}{$lonhost} = 1;
12744: }
1.412 raeburn 12745: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12746: $changes{'saml'}{$lonhost} = 1;
12747: }
1.386 raeburn 12748: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12749: $changes{'saml'}{$lonhost} = 1;
12750: }
12751: } else {
12752: $changes{'saml'}{$lonhost} = 1;
12753: }
1.412 raeburn 12754: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12755: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12756: }
12757: } else {
1.425 raeburn 12758: if ($saml{$lonhost}) {
1.389 raeburn 12759: $changes{'saml'}{$lonhost} = 1;
12760: delete($currsaml{$lonhost});
12761: }
1.386 raeburn 12762: }
12763: }
12764: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12765: unless (exists($domservers{$posshost})) {
12766: delete($currsaml{$posshost});
1.386 raeburn 12767: }
12768: }
12769: %{$loginhash{'login'}{'saml'}} = %currsaml;
12770: if (@newsamlimgs) {
12771: my $error;
12772: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12773: if ($configuserok eq 'ok') {
12774: if ($switchserver) {
12775: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12776: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12777: my $modified = [];
1.386 raeburn 12778: foreach my $lonhost (@newsamlimgs) {
12779: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12780: my ($result,$imgurl) =
1.421 raeburn 12781: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12782: "login/saml/$lonhost",'','',
12783: $env{'form.saml_img_'.$lonhost.'.filename'},
12784: $modified);
1.386 raeburn 12785: if ($result eq 'ok') {
12786: $currsaml{$lonhost}{'img'} = $imgurl;
12787: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12788: $changes{'saml'}{$lonhost} = 1;
12789: } else {
12790: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12791: $lonhost,$result);
12792: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12793: }
12794: }
1.421 raeburn 12795: &update_modify_urls($r,$modified);
1.386 raeburn 12796: } else {
12797: $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);
12798: }
12799: } else {
12800: $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);
12801: }
12802: if ($error) {
12803: &Apache::lonnet::logthis($error);
12804: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12805: }
12806: }
1.169 raeburn 12807: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12808:
12809: my $defaulthelpfile = '/adm/loginproblems.html';
12810: my $defaulttext = &mt('Default in use');
12811:
1.1 raeburn 12812: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12813: $dom);
12814: if ($putresult eq 'ok') {
1.188 raeburn 12815: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12816: my %defaultchecked = (
12817: 'coursecatalog' => 'on',
1.188 raeburn 12818: 'helpdesk' => 'on',
1.42 raeburn 12819: 'adminmail' => 'off',
1.43 raeburn 12820: 'newuser' => 'off',
1.42 raeburn 12821: );
1.55 raeburn 12822: if (ref($domconfig{'login'}) eq 'HASH') {
12823: foreach my $item (@toggles) {
12824: if ($defaultchecked{$item} eq 'on') {
12825: if (($domconfig{'login'}{$item} eq '0') &&
12826: ($env{'form.'.$item} eq '1')) {
12827: $changes{$item} = 1;
12828: } elsif (($domconfig{'login'}{$item} eq '' ||
12829: $domconfig{'login'}{$item} eq '1') &&
12830: ($env{'form.'.$item} eq '0')) {
12831: $changes{$item} = 1;
12832: }
12833: } elsif ($defaultchecked{$item} eq 'off') {
12834: if (($domconfig{'login'}{$item} eq '1') &&
12835: ($env{'form.'.$item} eq '0')) {
12836: $changes{$item} = 1;
12837: } elsif (($domconfig{'login'}{$item} eq '' ||
12838: $domconfig{'login'}{$item} eq '0') &&
12839: ($env{'form.'.$item} eq '1')) {
12840: $changes{$item} = 1;
12841: }
1.42 raeburn 12842: }
12843: }
1.41 raeburn 12844: }
1.6 raeburn 12845: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12846: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12847: if (exists($changes{'saml'})) {
12848: my $hostid_in_use;
12849: my @hosts = &Apache::lonnet::current_machine_ids();
12850: if (@hosts > 1) {
12851: foreach my $hostid (@hosts) {
12852: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12853: $hostid_in_use = $hostid;
12854: last;
12855: }
12856: }
12857: } else {
12858: $hostid_in_use = $r->dir_config('lonHostID');
12859: }
12860: if (($hostid_in_use) &&
12861: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12862: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12863: }
12864: if (ref($lastactref) eq 'HASH') {
12865: if (ref($changes{'saml'}) eq 'HASH') {
12866: my %updates;
12867: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12868: $lastactref->{'samllanding'} = \%updates;
12869: }
12870: }
12871: }
1.212 raeburn 12872: if (ref($lastactref) eq 'HASH') {
12873: $lastactref->{'domainconfig'} = 1;
12874: }
1.1 raeburn 12875: $resulttext = &mt('Changes made:').'<ul>';
12876: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12877: if ($item eq 'loginvia') {
1.112 raeburn 12878: if (ref($changes{$item}) eq 'HASH') {
12879: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12880: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12881: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12882: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12883: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12884: $protocol = 'http' if ($protocol ne 'https');
12885: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12886:
12887: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12888: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12889: } else {
12890: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12891: }
12892: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12893: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12894: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12895: }
12896: $resulttext .= '</li>';
12897: } else {
12898: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12899: }
1.112 raeburn 12900: } else {
1.128 raeburn 12901: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12902: }
12903: }
1.128 raeburn 12904: $resulttext .= '</ul></li>';
1.112 raeburn 12905: }
1.168 raeburn 12906: } elsif ($item eq 'helpurl') {
12907: if (ref($changes{$item}) eq 'HASH') {
12908: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12909: if (grep(/^\Q$lang\E$/,@delurls)) {
12910: my ($chg,$link);
12911: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12912: if ($lang eq 'nolang') {
12913: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12914: } else {
12915: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12916: }
12917: $resulttext .= '<li>'.$chg.'</li>';
12918: } else {
12919: my $chg;
12920: if ($lang eq 'nolang') {
12921: $chg = &mt('custom log-in help file for no preferred language');
12922: } else {
12923: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12924: }
12925: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12926: $loginhash{'login'}{'helpurl'}{$lang}.
12927: '?inhibitmenu=yes',$chg,600,500).
12928: '</li>';
12929: }
12930: }
12931: }
1.256 raeburn 12932: } elsif ($item eq 'headtag') {
12933: if (ref($changes{$item}) eq 'HASH') {
12934: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12935: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12936: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12937: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12938: $resulttext .= '<li><a href="'.
12939: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12940: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12941: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12942: if ($possexempt{$lonhost}) {
12943: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
12944: } else {
12945: $resulttext .= &mt('included for any client IP');
12946: }
12947: $resulttext .= '</li>';
12948: }
12949: }
12950: }
1.386 raeburn 12951: } elsif ($item eq 'saml') {
12952: if (ref($changes{$item}) eq 'HASH') {
12953: my %notlt = (
12954: text => 'Text for log-in by SSO',
12955: img => 'SSO button image',
12956: alt => 'Alt text for button image',
12957: url => 'SSO URL',
12958: title => 'Tooltip for SSO link',
1.412 raeburn 12959: window => 'Pop-up window if iframe',
1.386 raeburn 12960: notsso => 'Text for non-SSO log-in',
12961: );
12962: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12963: if (ref($currsaml{$lonhost}) eq 'HASH') {
12964: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
12965: '<ul>';
1.412 raeburn 12966: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 12967: if ($currsaml{$lonhost}{$key} eq '') {
12968: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
12969: } else {
12970: my $value = "'$currsaml{$lonhost}{$key}'";
12971: if ($key eq 'img') {
12972: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 12973: } elsif ($key eq 'window') {
12974: $value = 'On';
1.386 raeburn 12975: }
12976: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
12977: $value).'</li>';
12978: }
12979: }
12980: $resulttext .= '</ul></li>';
12981: } else {
12982: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
12983: }
12984: }
12985: }
1.169 raeburn 12986: } elsif ($item eq 'captcha') {
12987: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 12988: my $chgtxt;
1.169 raeburn 12989: if ($loginhash{'login'}{$item} eq 'notused') {
12990: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
12991: } else {
12992: my %captchas = &captcha_phrases();
12993: if ($captchas{$loginhash{'login'}{$item}}) {
12994: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
12995: } else {
12996: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
12997: }
12998: }
12999: $resulttext .= '<li>'.$chgtxt.'</li>';
13000: }
13001: } elsif ($item eq 'recaptchakeys') {
13002: if (ref($loginhash{'login'}) eq 'HASH') {
13003: my ($privkey,$pubkey);
13004: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13005: $pubkey = $loginhash{'login'}{$item}{'public'};
13006: $privkey = $loginhash{'login'}{$item}{'private'};
13007: }
13008: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13009: if (!$pubkey) {
13010: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13011: } else {
13012: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13013: }
13014: if (!$privkey) {
13015: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13016: } else {
1.251 raeburn 13017: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13018: }
13019: $chgtxt .= '</ul>';
13020: $resulttext .= '<li>'.$chgtxt.'</li>';
13021: }
1.269 raeburn 13022: } elsif ($item eq 'recaptchaversion') {
13023: if (ref($loginhash{'login'}) eq 'HASH') {
13024: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13025: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13026: '</li>';
13027: }
13028: }
1.41 raeburn 13029: } else {
13030: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13031: }
1.1 raeburn 13032: }
1.6 raeburn 13033: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13034: } else {
13035: $resulttext = &mt('No changes made to log-in page settings');
13036: }
13037: } else {
1.11 albertel 13038: $resulttext = '<span class="LC_error">'.
13039: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13040: }
1.6 raeburn 13041: if ($errors) {
1.9 raeburn 13042: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13043: $errors.'</ul>';
13044: }
13045: return $resulttext;
13046: }
13047:
1.256 raeburn 13048: sub check_exempt_addresses {
13049: my ($iplist) = @_;
13050: $iplist =~ s/^\s+//;
13051: $iplist =~ s/\s+$//;
13052: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13053: my (@okips,$new);
13054: foreach my $ip (@poss_ips) {
13055: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13056: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13057: push(@okips,$ip);
13058: }
13059: }
13060: }
13061: if (@okips > 0) {
13062: $new = join(',',@okips);
13063: } else {
13064: $new = '';
13065: }
13066: return $new;
13067: }
13068:
1.6 raeburn 13069: sub color_font_choices {
13070: my %choices =
13071: &Apache::lonlocal::texthash (
13072: img => "Header",
13073: bgs => "Background colors",
13074: links => "Link colors",
1.55 raeburn 13075: images => "Images",
1.6 raeburn 13076: font => "Font color",
1.201 raeburn 13077: fontmenu => "Font menu",
1.76 raeburn 13078: pgbg => "Page",
1.6 raeburn 13079: tabbg => "Header",
13080: sidebg => "Border",
13081: link => "Link",
13082: alink => "Active link",
13083: vlink => "Visited link",
13084: );
13085: return %choices;
13086: }
13087:
1.394 raeburn 13088: sub modify_ipaccess {
13089: my ($dom,$lastactref,%domconfig) = @_;
13090: my (@allpos,%changes,%confhash,$errors,$resulttext);
13091: my (@items,%deletions,%itemids,@warnings);
13092: my ($typeorder,$types) = &commblocktype_text();
13093: if ($env{'form.ipaccess_add'}) {
13094: my $name = $env{'form.ipaccess_name_add'};
13095: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13096: if ($newid) {
13097: $itemids{'add'} = $newid;
13098: push(@items,'add');
13099: $changes{$newid} = 1;
13100: } else {
13101: $error = &mt('Failed to acquire unique ID for new IP access control item');
13102: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13103: }
13104: }
13105: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13106: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13107: if (@todelete) {
13108: map { $deletions{$_} = 1; } @todelete;
13109: }
13110: my $maxnum = $env{'form.ipaccess_maxnum'};
13111: for (my $i=0; $i<$maxnum; $i++) {
13112: my $itemid = $env{'form.ipaccess_id_'.$i};
13113: $itemid =~ s/\D+//g;
13114: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13115: if ($deletions{$itemid}) {
13116: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13117: } else {
13118: push(@items,$i);
13119: $itemids{$i} = $itemid;
13120: }
13121: }
13122: }
13123: }
13124: foreach my $idx (@items) {
13125: my $itemid = $itemids{$idx};
13126: next unless ($itemid);
13127: my %current;
13128: unless ($idx eq 'add') {
13129: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13130: %current = %{$domconfig{'ipaccess'}{$itemid}};
13131: }
13132: }
13133: my $position = $env{'form.ipaccess_pos_'.$itemid};
13134: $position =~ s/\D+//g;
13135: if ($position ne '') {
13136: $allpos[$position] = $itemid;
13137: }
13138: my $name = $env{'form.ipaccess_name_'.$idx};
13139: $name =~ s/^\s+|\s+$//g;
13140: $confhash{$itemid}{'name'} = $name;
13141: my $possrange = $env{'form.ipaccess_range_'.$idx};
13142: $possrange =~ s/^\s+|\s+$//g;
13143: unless ($possrange eq '') {
13144: $possrange =~ s/[\r\n]+/\s/g;
13145: $possrange =~ s/\s*-\s*/-/g;
13146: $possrange =~ s/\s+/,/g;
13147: $possrange =~ s/,+/,/g;
13148: if ($possrange ne '') {
13149: my (@ok,$count);
1.425 raeburn 13150: $count = 0;
1.394 raeburn 13151: foreach my $poss (split(/\,/,$possrange)) {
13152: $count ++;
13153: $poss = &validate_ip_pattern($poss);
13154: if ($poss ne '') {
13155: push(@ok,$poss);
13156: }
13157: }
13158: my $diff = $count - scalar(@ok);
13159: if ($diff) {
13160: $errors .= '<li><span class="LC_error">'.
13161: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13162: $diff,$name).
13163: '</span></li>';
13164: }
13165: if (@ok) {
13166: my @cidr_list;
13167: foreach my $item (@ok) {
13168: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13169: }
13170: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13171: }
13172: }
13173: }
13174: foreach my $field ('name','ip') {
13175: unless (($idx eq 'add') || ($changes{$itemid})) {
13176: if ($current{$field} ne $confhash{$itemid}{$field}) {
13177: $changes{$itemid} = 1;
13178: last;
13179: }
13180: }
13181: }
13182: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13183:
1.394 raeburn 13184: my %commblocks;
1.425 raeburn 13185: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13186: foreach my $type (@{$typeorder}) {
13187: if ($commblocks{$type}) {
13188: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13189: }
13190: unless (($idx eq 'add') || ($changes{$itemid})) {
13191: if (ref($current{'commblocks'}) eq 'HASH') {
13192: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13193: $changes{$itemid} = 1;
13194: }
13195: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13196: $changes{$itemid} = 1;
13197: }
13198: }
13199: }
13200: $confhash{$itemid}{'courses'} = {};
13201: my %crsdeletions;
13202: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13203: if (@delcrs) {
13204: map { $crsdeletions{$_} = 1; } @delcrs;
13205: }
13206: if (ref($current{'courses'}) eq 'HASH') {
13207: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13208: if ($crsdeletions{$cid}) {
13209: $changes{$itemid} = 1;
13210: } else {
13211: $confhash{$itemid}{'courses'}{$cid} = 1;
13212: }
13213: }
13214: }
13215: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13216: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13217: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13218: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13219: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13220: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13221: $errors .= '<li><span class="LC_error">'.
13222: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13223: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13224: '</span></li>';
13225: } else {
13226: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13227: $changes{$itemid} = 1;
13228: }
13229: }
13230: }
13231: if (@allpos > 0) {
13232: my $idx = 0;
13233: foreach my $itemid (@allpos) {
13234: if ($itemid ne '') {
13235: $confhash{$itemid}{'order'} = $idx;
13236: unless ($changes{$itemid}) {
13237: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13238: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13239: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13240: $changes{$itemid} = 1;
13241: }
13242: }
13243: }
13244: }
13245: $idx ++;
13246: }
13247: }
13248: }
13249: if (keys(%changes)) {
13250: my %defaultshash = (
13251: ipaccess => \%confhash,
13252: );
13253: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13254: $dom);
13255: if ($putresult eq 'ok') {
13256: my $cachetime = 1800;
13257: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13258: if (ref($lastactref) eq 'HASH') {
13259: $lastactref->{'ipaccess'} = 1;
13260: }
13261: $resulttext = &mt('Changes made:').'<ul>';
13262: my %bynum;
13263: foreach my $itemid (sort(keys(%changes))) {
13264: if (ref($confhash{$itemid}) eq 'HASH') {
13265: my $position = $confhash{$itemid}{'order'};
13266: if ($position =~ /^\d+$/) {
13267: $bynum{$position} = $itemid;
13268: }
13269: }
13270: }
13271: if (keys(%deletions)) {
13272: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13273: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13274: }
13275: }
13276: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13277: my $itemid = $bynum{$pos};
13278: if (ref($confhash{$itemid}) eq 'HASH') {
13279: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13280: my $position = $pos + 1;
13281: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13282: if ($confhash{$itemid}{'ip'} eq '') {
13283: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13284: } else {
13285: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13286: }
13287: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13288: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13289: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13290: '</li>';
13291: } else {
13292: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13293: }
13294: if (keys(%{$confhash{$itemid}{'courses'}})) {
13295: my @courses;
13296: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13297: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13298: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13299: }
13300: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13301: join('</li><li>',@courses).'</li></ul>';
13302: } else {
13303: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13304: }
1.395 raeburn 13305: $resulttext .= '</ul></li>';
1.394 raeburn 13306: }
13307: }
1.395 raeburn 13308: $resulttext .= '</ul>';
1.394 raeburn 13309: } else {
13310: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13311: }
13312: } else {
13313: $resulttext = &mt('No changes made');
13314: }
13315: if ($errors) {
13316: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13317: $errors.'</ul></p>';
13318: }
13319: return $resulttext;
13320: }
13321:
13322: sub get_ipaccess_id {
13323: my ($domain,$location) = @_;
13324: # get lock on ipaccess db
13325: my $lockhash = {
13326: lock => $env{'user.name'}.
13327: ':'.$env{'user.domain'},
13328: };
13329: my $tries = 0;
13330: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13331: my ($id,$error);
13332:
13333: while (($gotlock ne 'ok') && ($tries<10)) {
13334: $tries ++;
13335: sleep (0.1);
13336: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13337: }
13338: if ($gotlock eq 'ok') {
13339: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13340: if ($currids{'lock'}) {
13341: delete($currids{'lock'});
13342: if (keys(%currids)) {
13343: my @curr = sort { $a <=> $b } keys(%currids);
13344: if ($curr[-1] =~ /^\d+$/) {
13345: $id = 1 + $curr[-1];
13346: }
13347: } else {
13348: $id = 1;
13349: }
13350: if ($id) {
13351: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13352: $error = 'nostore';
13353: }
13354: } else {
13355: $error = 'nonumber';
13356: }
13357: }
13358: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13359: } else {
13360: $error = 'nolock';
13361: }
13362: return ($id,$error);
13363: }
13364:
1.429 raeburn 13365: sub modify_authordefaults {
13366: my ($dom,$lastactref,%domconfig) = @_;
13367: #
13368: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13369: #
13370: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13371: if (ref($domconfig{'quotas'}) eq 'HASH') {
13372: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13373: if ($key =~ /^webdav|authorquota$/) {
13374: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13375: } else {
13376: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13377: }
13378: }
13379: }
13380: my %staticdefaults = (
13381: 'copyright' => 'default',
13382: 'sourceavail' => 'closed',
13383: 'nocodemirror' => 'off',
13384: 'domcoordacc' => 'on',
13385: 'editors' => ['edit','xml'].
13386: 'authorquota' => 500,
13387: 'webdav' => 0,
13388: );
13389: my %titles = &authordefaults_titles();
13390: foreach my $item ('nocodemirror','domcoordacc') {
13391: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13392: $confhash{$item} = $env{'form.'.$item};
13393: }
13394: }
13395: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13396: $confhash{'copyright'} = $1;
13397: }
13398: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13399: $confhash{'sourceavail'} = $1;
13400: }
13401: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13402: my @okeditors = ('edit','xml','daxe');
13403: my @editors;
13404: foreach my $item (@posseditors) {
13405: if (grep(/^\Q$item\E$/,@okeditors)) {
13406: push(@editors,$item);
13407: }
13408: }
13409: $confhash{'editors'} = \@editors;
13410:
13411: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13412: my @insttypes;
13413: if (ref($types) eq 'ARRAY') {
13414: @insttypes = @{$types};
13415: }
13416: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13417: my %webdav;
13418: map { $webdav{$_} = 1; } @webdavon;
13419: foreach my $type (@insttypes,'default') {
13420: my $possquota = $env{'form.authorquota_'.$type};
13421: if ($possquota =~ /^\d+$/) {
13422: $save_quotas{'authorquota'}{$type} = $possquota;
13423: }
13424: if ($webdav{$type}) {
13425: $save_quotas{'webdav'}{$type} = 1;
13426: } else {
13427: $save_quotas{'webdav'}{$type} = 0;
13428: }
13429: }
13430: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13431: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13432: }
13433: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
13434: foreach my $item ('nocodemirror','domcoordacc','copyright','sourceavail') {
13435: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13436: $changes{$item} = 1;
13437: }
13438: }
13439: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
13440: my @diffs =
13441: &Apache::loncommon::compare_arrays($confhash{'editors'},
13442: $domconfig{'authordefaults'}{'editors'});
13443: unless (@diffs == 0) {
13444: $changes{'editors'} = 1;
13445: }
13446: } else {
13447: my @diffs =
13448: &Apache::loncommon::compare_arrays($confhash{'editors'},
13449: $staticdefaults{'editors'});
13450: unless (@diffs == 0) {
13451: $changes{'editors'} = 1;
13452: }
13453: }
13454: } else {
13455: my @offon = ('off','on');
13456: foreach my $item ('nocodemirror','domcoordacc') {
13457: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
13458: $changes{$item} = 1;
13459: }
13460: }
13461: foreach my $item ('copyright','sourceavail') {
13462: if ($confhash{$item} ne $staticdefaults{$item}) {
13463: $changes{$item} = 1;
13464: }
13465: }
13466: }
13467: foreach my $key ('authorquota','webdav') {
13468: if (ref($curr_quotas{$key}) eq 'HASH') {
13469: foreach my $type (@insttypes,'default') {
13470: if (exists($save_quotas{$key}{$type})) {
13471: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13472: $changes{$key}{$type} = 1;
13473: }
13474: } elsif (exists($curr_quotas{$key}{$type})) {
13475: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13476: } else {
13477: $save_quotas{$key}{$type} = $staticdefaults{$key};
13478: }
13479: }
13480: } else {
13481: foreach my $type (@insttypes,'default') {
13482: if (exists($save_quotas{$key}{$type})) {
13483: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13484: $changes{$key}{$type} = 1;
13485: }
13486: } else {
13487: $save_quotas{$key}{$type} = $staticdefaults{$key};
13488: }
13489: }
13490: }
13491: }
13492: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13493: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13494: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
13495: $changes{'webdav_LC_adv'} = 1;
13496: }
13497: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13498: $changes{'webdav_LC_adv'} = 1;
13499: }
13500: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13501: $changes{'webdav_LC_adv'} = 1;
13502: }
13503: my %confighash = (
13504: quotas => \%save_quotas,
13505: authordefaults => \%confhash,
13506: );
13507: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13508: $dom);
13509: my $resulttext;
13510: if ($putresult eq 'ok') {
13511: if (keys(%changes)) {
1.431 raeburn 13512: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13513: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
13514: ($changes{'webdav_LC_adv'})) {
13515: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13516: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13517: }
13518: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13519: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13520: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13521: }
13522: }
13523: $resulttext = &mt('Changes made:').'<ul>';
13524: my $authoroverride;
13525: foreach my $key ('nocodemirror','domcoordacc','copyright','sourceavail') {
13526: if (exists($changes{$key})) {
1.431 raeburn 13527: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13528: my $shown;
13529: unless ($authoroverride) {
13530: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13531: $authoroverride = 1;
13532: }
13533: if (($key eq 'nocodemirror') || ($key eq 'domcoordacc')) {
13534: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13535: } elsif ($key eq 'copyright') {
13536: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13537: } elsif ($key eq 'sourceavail') {
13538: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13539: }
13540: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13541: }
13542: }
13543: if ($authoroverride) {
13544: $resulttext .= '</ul></li>';
13545: }
13546: my $domcoordoverride;
13547: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv') {
13548: if (exists($changes{$key})) {
13549: my $shown;
13550: unless ($domcoordoverride) {
13551: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13552: $domcoordoverride = 1;
13553: }
13554: if ($key eq 'editors') {
1.431 raeburn 13555: if (ref($confhash{'editors'}) eq 'ARRAY') {
13556: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13557: if (@{$confhash{'editors'}}) {
13558: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13559: } else {
13560: $shown = &mt('None');
13561: }
1.429 raeburn 13562: }
13563: } elsif ($key eq 'authorquota') {
13564: foreach my $type (@insttypes) {
13565: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13566: }
13567: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13568: } elsif ($key eq 'webdav') {
13569: foreach my $type (@insttypes) {
13570: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13571: }
13572: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13573: } elsif ($key eq 'webdav_LC_adv') {
13574: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13575: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13576: } else {
13577: $shown = $titles{'none'};
13578: }
13579: }
13580: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
13581: }
13582: }
13583: if ($domcoordoverride) {
13584: $resulttext .= '</ul></li>';
13585: }
1.431 raeburn 13586: my $cachetime = 24*60*60;
13587: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13588: if (ref($lastactref) eq 'HASH') {
13589: $lastactref->{'domdefaults'} = 1;
13590: }
1.429 raeburn 13591: } else {
13592: $resulttext = &mt('No changes made to Authoring Space defaults');
13593: }
13594: }
13595: return $resulttext;
13596: }
13597:
1.6 raeburn 13598: sub modify_rolecolors {
1.205 raeburn 13599: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13600: my ($resulttext,%rolehash);
13601: $rolehash{'rolecolors'} = {};
1.55 raeburn 13602: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13603: if ($domconfig{'rolecolors'} eq '') {
13604: $domconfig{'rolecolors'} = {};
13605: }
13606: }
1.9 raeburn 13607: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13608: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13609: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13610: $dom);
13611: if ($putresult eq 'ok') {
13612: if (keys(%changes) > 0) {
1.41 raeburn 13613: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13614: if (ref($lastactref) eq 'HASH') {
13615: $lastactref->{'domainconfig'} = 1;
13616: }
1.6 raeburn 13617: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13618: $rolehash{'rolecolors'});
13619: } else {
13620: $resulttext = &mt('No changes made to default color schemes');
13621: }
13622: } else {
1.11 albertel 13623: $resulttext = '<span class="LC_error">'.
13624: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13625: }
13626: if ($errors) {
13627: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13628: $errors.'</ul>';
13629: }
13630: return $resulttext;
13631: }
13632:
13633: sub modify_colors {
1.9 raeburn 13634: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13635: my (%changes,%choices);
1.51 raeburn 13636: my @bgs;
1.6 raeburn 13637: my @links = ('link','alink','vlink');
1.41 raeburn 13638: my @logintext;
1.6 raeburn 13639: my @images;
13640: my $servadm = $r->dir_config('lonAdmEMail');
13641: my $errors;
1.200 raeburn 13642: my %defaults;
1.6 raeburn 13643: foreach my $role (@{$roles}) {
13644: if ($role eq 'login') {
1.12 raeburn 13645: %choices = &login_choices();
1.41 raeburn 13646: @logintext = ('textcol','bgcol');
1.12 raeburn 13647: } else {
13648: %choices = &color_font_choices();
13649: }
13650: if ($role eq 'login') {
1.41 raeburn 13651: @images = ('img','logo','domlogo','login');
1.51 raeburn 13652: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13653: } else {
13654: @images = ('img');
1.200 raeburn 13655: @bgs = ('pgbg','tabbg','sidebg');
13656: }
13657: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13658: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13659: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13660: }
13661: if ($role eq 'login') {
13662: foreach my $item (@logintext) {
1.234 raeburn 13663: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13664: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13665: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13666: }
13667: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13668: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13669: }
13670: }
13671: } else {
1.234 raeburn 13672: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13673: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13674: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13675: }
13676: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13677: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13678: }
1.6 raeburn 13679: }
1.200 raeburn 13680: foreach my $item (@bgs) {
1.234 raeburn 13681: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13682: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13683: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13684: }
13685: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13686: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13687: }
13688: }
13689: foreach my $item (@links) {
1.234 raeburn 13690: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13691: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13692: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13693: }
13694: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13695: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13696: }
1.6 raeburn 13697: }
1.46 raeburn 13698: my ($configuserok,$author_ok,$switchserver) =
13699: &config_check($dom,$confname,$servadm);
1.9 raeburn 13700: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13701: if (ref($domconfig->{$role}) ne 'HASH') {
13702: $domconfig->{$role} = {};
13703: }
1.8 raeburn 13704: foreach my $img (@images) {
1.402 raeburn 13705: if ($role eq 'login') {
13706: if (($img eq 'img') || ($img eq 'logo')) {
13707: if (defined($env{'form.login_showlogo_'.$img})) {
13708: $confhash->{$role}{'showlogo'}{$img} = 1;
13709: } else {
13710: $confhash->{$role}{'showlogo'}{$img} = 0;
13711: }
13712: }
13713: if ($env{'form.login_alt_'.$img} ne '') {
13714: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13715: }
1.402 raeburn 13716: }
1.18 albertel 13717: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13718: && !defined($domconfig->{$role}{$img})
13719: && !$env{'form.'.$role.'_del_'.$img}
13720: && $env{'form.'.$role.'_import_'.$img}) {
13721: # import the old configured image from the .tab setting
13722: # if they haven't provided a new one
13723: $domconfig->{$role}{$img} =
13724: $env{'form.'.$role.'_import_'.$img};
13725: }
1.6 raeburn 13726: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13727: my $error;
1.6 raeburn 13728: if ($configuserok eq 'ok') {
1.9 raeburn 13729: if ($switchserver) {
1.12 raeburn 13730: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13731: } else {
13732: if ($author_ok eq 'ok') {
1.421 raeburn 13733: my $modified = [];
1.9 raeburn 13734: my ($result,$logourl) =
1.421 raeburn 13735: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13736: $dom,$confname,$img,$width,$height,
13737: '',$modified);
1.9 raeburn 13738: if ($result eq 'ok') {
13739: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13740: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13741: &update_modify_urls($r,$modified);
1.9 raeburn 13742: } else {
1.12 raeburn 13743: $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 13744: }
13745: } else {
1.46 raeburn 13746: $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 13747: }
13748: }
13749: } else {
1.46 raeburn 13750: $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 13751: }
13752: if ($error) {
1.8 raeburn 13753: &Apache::lonnet::logthis($error);
1.11 albertel 13754: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13755: }
13756: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13757: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13758: my $error;
13759: if ($configuserok eq 'ok') {
13760: # is confname an author?
13761: if ($switchserver eq '') {
13762: if ($author_ok eq 'ok') {
1.421 raeburn 13763: my $modified = [];
1.9 raeburn 13764: my ($result,$logourl) =
1.421 raeburn 13765: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13766: $dom,$confname,$img,$width,$height,
13767: '',$modified);
1.9 raeburn 13768: if ($result eq 'ok') {
13769: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13770: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13771: &update_modify_urls($r,$modified);
1.9 raeburn 13772: }
13773: }
13774: }
13775: }
1.6 raeburn 13776: }
13777: }
13778: }
13779: if (ref($domconfig) eq 'HASH') {
13780: if (ref($domconfig->{$role}) eq 'HASH') {
13781: foreach my $img (@images) {
13782: if ($domconfig->{$role}{$img} ne '') {
13783: if ($env{'form.'.$role.'_del_'.$img}) {
13784: $confhash->{$role}{$img} = '';
1.12 raeburn 13785: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13786: } else {
1.9 raeburn 13787: if ($confhash->{$role}{$img} eq '') {
13788: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13789: }
1.6 raeburn 13790: }
13791: } else {
13792: if ($env{'form.'.$role.'_del_'.$img}) {
13793: $confhash->{$role}{$img} = '';
1.12 raeburn 13794: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13795: }
13796: }
1.402 raeburn 13797: if ($role eq 'login') {
13798: if (($img eq 'logo') || ($img eq 'img')) {
13799: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13800: if ($confhash->{$role}{'showlogo'}{$img} ne
13801: $domconfig->{$role}{'showlogo'}{$img}) {
13802: $changes{$role}{'showlogo'}{$img} = 1;
13803: }
13804: } else {
13805: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13806: $changes{$role}{'showlogo'}{$img} = 1;
13807: }
1.70 raeburn 13808: }
1.402 raeburn 13809: }
13810: if ($img ne 'login') {
13811: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13812: if ($confhash->{$role}{'alttext'}{$img} ne
13813: $domconfig->{$role}{'alttext'}{$img}) {
13814: $changes{$role}{'alttext'}{$img} = 1;
13815: }
13816: } else {
13817: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13818: $changes{$role}{'alttext'}{$img} = 1;
13819: }
1.70 raeburn 13820: }
13821: }
13822: }
13823: }
1.6 raeburn 13824: if ($domconfig->{$role}{'font'} ne '') {
13825: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13826: $changes{$role}{'font'} = 1;
13827: }
13828: } else {
13829: if ($confhash->{$role}{'font'}) {
13830: $changes{$role}{'font'} = 1;
13831: }
13832: }
1.107 raeburn 13833: if ($role ne 'login') {
13834: if ($domconfig->{$role}{'fontmenu'} ne '') {
13835: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13836: $changes{$role}{'fontmenu'} = 1;
13837: }
13838: } else {
13839: if ($confhash->{$role}{'fontmenu'}) {
13840: $changes{$role}{'fontmenu'} = 1;
13841: }
1.97 tempelho 13842: }
13843: }
1.6 raeburn 13844: foreach my $item (@bgs) {
13845: if ($domconfig->{$role}{$item} ne '') {
13846: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13847: $changes{$role}{'bgs'}{$item} = 1;
13848: }
13849: } else {
13850: if ($confhash->{$role}{$item}) {
13851: $changes{$role}{'bgs'}{$item} = 1;
13852: }
13853: }
13854: }
13855: foreach my $item (@links) {
13856: if ($domconfig->{$role}{$item} ne '') {
13857: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13858: $changes{$role}{'links'}{$item} = 1;
13859: }
13860: } else {
13861: if ($confhash->{$role}{$item}) {
13862: $changes{$role}{'links'}{$item} = 1;
13863: }
13864: }
13865: }
1.41 raeburn 13866: foreach my $item (@logintext) {
13867: if ($domconfig->{$role}{$item} ne '') {
13868: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13869: $changes{$role}{'logintext'}{$item} = 1;
13870: }
13871: } else {
13872: if ($confhash->{$role}{$item}) {
13873: $changes{$role}{'logintext'}{$item} = 1;
13874: }
13875: }
13876: }
1.6 raeburn 13877: } else {
13878: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13879: \@logintext,$confhash,\%changes);
1.6 raeburn 13880: }
13881: } else {
13882: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13883: \@logintext,$confhash,\%changes);
1.6 raeburn 13884: }
13885: }
13886: return ($errors,%changes);
13887: }
13888:
1.46 raeburn 13889: sub config_check {
13890: my ($dom,$confname,$servadm) = @_;
13891: my ($configuserok,$author_ok,$switchserver,%currroles);
13892: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13893: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13894: $confname,$servadm);
13895: if ($configuserok eq 'ok') {
13896: $switchserver = &check_switchserver($dom,$confname);
13897: if ($switchserver eq '') {
13898: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13899: }
13900: }
13901: return ($configuserok,$author_ok,$switchserver);
13902: }
13903:
1.6 raeburn 13904: sub default_change_checker {
1.41 raeburn 13905: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13906: foreach my $item (@{$links}) {
13907: if ($confhash->{$role}{$item}) {
13908: $changes->{$role}{'links'}{$item} = 1;
13909: }
13910: }
13911: foreach my $item (@{$bgs}) {
13912: if ($confhash->{$role}{$item}) {
13913: $changes->{$role}{'bgs'}{$item} = 1;
13914: }
13915: }
1.41 raeburn 13916: foreach my $item (@{$logintext}) {
13917: if ($confhash->{$role}{$item}) {
13918: $changes->{$role}{'logintext'}{$item} = 1;
13919: }
13920: }
1.6 raeburn 13921: foreach my $img (@{$images}) {
13922: if ($env{'form.'.$role.'_del_'.$img}) {
13923: $confhash->{$role}{$img} = '';
1.12 raeburn 13924: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13925: }
1.70 raeburn 13926: if ($role eq 'login') {
13927: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13928: $changes->{$role}{'showlogo'}{$img} = 1;
13929: }
1.402 raeburn 13930: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
13931: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13932: $changes->{$role}{'alttext'}{$img} = 1;
13933: }
13934: }
1.70 raeburn 13935: }
1.6 raeburn 13936: }
13937: if ($confhash->{$role}{'font'}) {
13938: $changes->{$role}{'font'} = 1;
13939: }
1.48 raeburn 13940: }
1.6 raeburn 13941:
13942: sub display_colorchgs {
13943: my ($dom,$changes,$roles,$confhash) = @_;
13944: my (%choices,$resulttext);
13945: if (!grep(/^login$/,@{$roles})) {
13946: $resulttext = &mt('Changes made:').'<br />';
13947: }
13948: foreach my $role (@{$roles}) {
13949: if ($role eq 'login') {
13950: %choices = &login_choices();
13951: } else {
13952: %choices = &color_font_choices();
13953: }
13954: if (ref($changes->{$role}) eq 'HASH') {
13955: if ($role ne 'login') {
13956: $resulttext .= '<h4>'.&mt($role).'</h4>';
13957: }
13958: foreach my $key (sort(keys(%{$changes->{$role}}))) {
13959: if ($role ne 'login') {
13960: $resulttext .= '<ul>';
13961: }
13962: if (ref($changes->{$role}{$key}) eq 'HASH') {
13963: if ($role ne 'login') {
13964: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
13965: }
13966: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 13967: if (($role eq 'login') && ($key eq 'showlogo')) {
13968: if ($confhash->{$role}{$key}{$item}) {
13969: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
13970: } else {
13971: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
13972: }
1.402 raeburn 13973: } elsif (($role eq 'login') && ($key eq 'alttext')) {
13974: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 13975: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 13976: $confhash->{$role}{$key}{$item}).'</li>';
13977: } else {
13978: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
13979: }
1.70 raeburn 13980: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 13981: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
13982: } else {
1.12 raeburn 13983: my $newitem = $confhash->{$role}{$item};
13984: if ($key eq 'images') {
1.306 raeburn 13985: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 13986: }
13987: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 13988: }
13989: }
13990: if ($role ne 'login') {
13991: $resulttext .= '</ul></li>';
13992: }
13993: } else {
13994: if ($confhash->{$role}{$key} eq '') {
13995: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
13996: } else {
13997: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
13998: }
13999: }
14000: if ($role ne 'login') {
14001: $resulttext .= '</ul>';
14002: }
14003: }
14004: }
14005: }
1.3 raeburn 14006: return $resulttext;
1.1 raeburn 14007: }
14008:
1.9 raeburn 14009: sub thumb_dimensions {
14010: return ('200','50');
14011: }
14012:
1.16 raeburn 14013: sub check_dimensions {
14014: my ($inputfile) = @_;
14015: my ($fullwidth,$fullheight);
14016: if ($inputfile =~ m|^[/\w.\-]+$|) {
14017: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14018: my $imageinfo = <PIPE>;
14019: if (!close(PIPE)) {
14020: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14021: }
14022: chomp($imageinfo);
14023: my ($fullsize) =
1.21 raeburn 14024: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14025: if ($fullsize) {
14026: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14027: }
14028: }
14029: }
14030: return ($fullwidth,$fullheight);
14031: }
14032:
1.9 raeburn 14033: sub check_configuser {
14034: my ($uhome,$dom,$confname,$servadm) = @_;
14035: my ($configuserok,%currroles);
14036: if ($uhome eq 'no_host') {
14037: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14038: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14039: $configuserok =
14040: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14041: $configpass,'','','','','',undef,$servadm);
14042: } else {
14043: $configuserok = 'ok';
14044: %currroles =
14045: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14046: }
14047: return ($configuserok,%currroles);
14048: }
14049:
14050: sub check_authorstatus {
14051: my ($dom,$confname,%currroles) = @_;
14052: my $author_ok;
1.40 raeburn 14053: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14054: my $start = time;
14055: my $end = 0;
14056: $author_ok =
14057: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14058: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14059: } else {
14060: $author_ok = 'ok';
14061: }
14062: return $author_ok;
14063: }
14064:
1.421 raeburn 14065: sub update_modify_urls {
14066: my ($r,$modified) = @_;
14067: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14068: push(@{$modified_urls},$modified);
14069: unless ($registered_cleanup) {
14070: my $handlers = $r->get_handlers('PerlCleanupHandler');
14071: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14072: $registered_cleanup=1;
1.9 raeburn 14073: }
14074: }
1.155 raeburn 14075: }
14076:
14077: sub notifysubscribed {
14078: foreach my $targetsource (@{$modified_urls}){
14079: next unless (ref($targetsource) eq 'ARRAY');
14080: my ($target,$source)=@{$targetsource};
14081: if ($source ne '') {
1.316 raeburn 14082: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14083: print $logfh "\nCleanup phase: Notifications\n";
14084: my @subscribed=&subscribed_hosts($target);
14085: foreach my $subhost (@subscribed) {
14086: print $logfh "\nNotifying host ".$subhost.':';
14087: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14088: print $logfh $reply;
14089: }
14090: my @subscribedmeta=&subscribed_hosts("$target.meta");
14091: foreach my $subhost (@subscribedmeta) {
14092: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14093: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14094: $subhost);
14095: print $logfh $reply;
14096: }
14097: print $logfh "\n============ Done ============\n";
1.160 raeburn 14098: close($logfh);
1.155 raeburn 14099: }
14100: }
14101: }
14102: return OK;
14103: }
14104:
14105: sub subscribed_hosts {
14106: my ($target) = @_;
14107: my @subscribed;
1.316 raeburn 14108: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14109: while (my $subline=<$fh>) {
14110: if ($subline =~ /^($match_lonid):/) {
14111: my $host = $1;
14112: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14113: unless (grep(/^\Q$host\E$/,@subscribed)) {
14114: push(@subscribed,$host);
14115: }
14116: }
14117: }
14118: }
14119: }
14120: return @subscribed;
1.9 raeburn 14121: }
14122:
14123: sub check_switchserver {
14124: my ($dom,$confname) = @_;
1.424 raeburn 14125: my ($allowed,$switchserver,$home);
14126: if ($confname eq '') {
1.9 raeburn 14127: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14128: } else {
14129: $home = &Apache::lonnet::homeserver($confname,$dom);
14130: if ($home eq 'no_host') {
14131: $home = &Apache::lonnet::domain($dom,'primary');
14132: }
1.9 raeburn 14133: }
14134: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14135: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14136: if (!$allowed) {
1.426 raeburn 14137: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14138: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14139: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14140: }
14141: return $switchserver;
14142: }
14143:
1.1 raeburn 14144: sub modify_quotas {
1.216 raeburn 14145: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14146: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14147: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14148: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14149: $validationfieldsref);
1.86 raeburn 14150: if ($action eq 'quotas') {
1.429 raeburn 14151: $context = 'tools';
1.163 raeburn 14152: } else {
1.86 raeburn 14153: $context = $action;
14154: }
14155: if ($context eq 'requestcourses') {
1.325 raeburn 14156: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14157: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14158: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14159: %titles = &courserequest_titles();
14160: $toolregexp = join('|',@usertools);
14161: %conditions = &courserequest_conditions();
1.216 raeburn 14162: $confname = $dom.'-domainconfig';
14163: my $servadm = $r->dir_config('lonAdmEMail');
14164: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14165: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14166: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14167: } elsif ($context eq 'requestauthor') {
14168: @usertools = ('author');
14169: %titles = &authorrequest_titles();
1.86 raeburn 14170: } else {
1.430 raeburn 14171: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14172: %titles = &tool_titles();
1.86 raeburn 14173: }
1.212 raeburn 14174: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14175: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14176: foreach my $key (keys(%env)) {
1.101 raeburn 14177: if ($context eq 'requestcourses') {
14178: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14179: my $item = $1;
14180: my $type = $2;
14181: if ($type =~ /^limit_(.+)/) {
14182: $limithash{$item}{$1} = $env{$key};
14183: } else {
14184: $confhash{$item}{$type} = $env{$key};
14185: }
14186: }
1.163 raeburn 14187: } elsif ($context eq 'requestauthor') {
14188: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14189: $confhash{$1} = $env{$key};
14190: }
1.101 raeburn 14191: } else {
1.86 raeburn 14192: if ($key =~ /^form\.quota_(.+)$/) {
14193: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14194: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14195: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14196: }
1.72 raeburn 14197: }
14198: }
1.163 raeburn 14199: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14200: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14201: @approvalnotify = sort(@approvalnotify);
14202: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14203: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14204: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14205: foreach my $type (@hasuniquecode) {
14206: if (grep(/^\Q$type\E$/,@crstypes)) {
14207: $confhash{'uniquecode'}{$type} = 1;
14208: }
1.216 raeburn 14209: }
1.242 raeburn 14210: my (%newbook,%allpos);
1.216 raeburn 14211: if ($context eq 'requestcourses') {
1.242 raeburn 14212: foreach my $type ('textbooks','templates') {
14213: @{$allpos{$type}} = ();
14214: my $invalid;
14215: if ($type eq 'textbooks') {
14216: $invalid = &mt('Invalid LON-CAPA course for textbook');
14217: } else {
14218: $invalid = &mt('Invalid LON-CAPA course for template');
14219: }
14220: if ($env{'form.'.$type.'_addbook'}) {
14221: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14222: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14223: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14224: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14225: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14226: } else {
14227: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14228: my $position = $env{'form.'.$type.'_addbook_pos'};
14229: $position =~ s/\D+//g;
14230: if ($position ne '') {
14231: $allpos{$type}[$position] = $newbook{$type};
14232: }
1.216 raeburn 14233: }
1.242 raeburn 14234: } else {
14235: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14236: }
14237: }
1.242 raeburn 14238: }
1.216 raeburn 14239: }
1.102 raeburn 14240: if (ref($domconfig{$action}) eq 'HASH') {
14241: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14242: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14243: $changes{'notify'}{'approval'} = 1;
14244: }
14245: } else {
1.144 raeburn 14246: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14247: $changes{'notify'}{'approval'} = 1;
14248: }
14249: }
1.218 raeburn 14250: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14251: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14252: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14253: unless ($confhash{'uniquecode'}{$crstype}) {
14254: $changes{'uniquecode'} = 1;
14255: }
14256: }
14257: unless ($changes{'uniquecode'}) {
14258: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14259: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14260: $changes{'uniquecode'} = 1;
14261: }
14262: }
14263: }
14264: } else {
14265: $changes{'uniquecode'} = 1;
14266: }
14267: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14268: $changes{'uniquecode'} = 1;
1.216 raeburn 14269: }
14270: if ($context eq 'requestcourses') {
1.242 raeburn 14271: foreach my $type ('textbooks','templates') {
14272: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14273: my %deletions;
14274: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14275: if (@todelete) {
14276: map { $deletions{$_} = 1; } @todelete;
14277: }
14278: my %imgdeletions;
14279: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14280: if (@todeleteimages) {
14281: map { $imgdeletions{$_} = 1; } @todeleteimages;
14282: }
14283: my $maxnum = $env{'form.'.$type.'_maxnum'};
14284: for (my $i=0; $i<=$maxnum; $i++) {
14285: my $itemid = $env{'form.'.$type.'_id_'.$i};
14286: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14287: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14288: if ($deletions{$key}) {
14289: if ($domconfig{$action}{$type}{$key}{'image'}) {
14290: #FIXME need to obsolete item in RES space
14291: }
14292: next;
14293: } else {
14294: my $newpos = $env{'form.'.$itemid};
14295: $newpos =~ s/\D+//g;
1.243 raeburn 14296: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14297: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14298: ($type eq 'templates'));
1.242 raeburn 14299: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14300: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14301: $changes{$type}{$key} = 1;
14302: }
14303: }
14304: $allpos{$type}[$newpos] = $key;
14305: }
14306: if ($imgdeletions{$key}) {
14307: $changes{$type}{$key} = 1;
1.216 raeburn 14308: #FIXME need to obsolete item in RES space
1.242 raeburn 14309: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14310: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14311: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14312: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14313: } else {
14314: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14315: $cdom,$cnum,$type,$configuserok,
14316: $switchserver,$author_ok);
14317: if ($imgurl) {
14318: $confhash{$type}{$key}{'image'} = $imgurl;
14319: $changes{$type}{$key} = 1;
14320: }
14321: if ($error) {
14322: &Apache::lonnet::logthis($error);
14323: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14324: }
14325: }
1.242 raeburn 14326: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14327: $confhash{$type}{$key}{'image'} =
14328: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14329: }
14330: }
14331: }
14332: }
14333: }
14334: }
1.102 raeburn 14335: } else {
1.144 raeburn 14336: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14337: $changes{'notify'}{'approval'} = 1;
14338: }
1.218 raeburn 14339: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14340: $changes{'uniquecode'} = 1;
14341: }
14342: }
14343: if ($context eq 'requestcourses') {
1.242 raeburn 14344: foreach my $type ('textbooks','templates') {
14345: if ($newbook{$type}) {
14346: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14347: foreach my $item ('subject','title','publisher','author') {
14348: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14349: ($type eq 'template'));
1.242 raeburn 14350: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14351: if ($env{'form.'.$type.'_addbook_'.$item}) {
14352: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14353: }
14354: }
14355: if ($type eq 'textbooks') {
14356: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14357: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14358: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14359: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14360: } else {
14361: my ($imageurl,$error) =
14362: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14363: $configuserok,$switchserver,$author_ok);
14364: if ($imageurl) {
14365: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14366: }
14367: if ($error) {
14368: &Apache::lonnet::logthis($error);
14369: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14370: }
1.242 raeburn 14371: }
14372: }
1.216 raeburn 14373: }
14374: }
1.242 raeburn 14375: if (@{$allpos{$type}} > 0) {
14376: my $idx = 0;
14377: foreach my $item (@{$allpos{$type}}) {
14378: if ($item ne '') {
14379: $confhash{$type}{$item}{'order'} = $idx;
14380: if (ref($domconfig{$action}) eq 'HASH') {
14381: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14382: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14383: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14384: $changes{$type}{$item} = 1;
14385: }
1.216 raeburn 14386: }
14387: }
14388: }
1.242 raeburn 14389: $idx ++;
1.216 raeburn 14390: }
14391: }
14392: }
14393: }
1.235 raeburn 14394: if (ref($validationitemsref) eq 'ARRAY') {
14395: foreach my $item (@{$validationitemsref}) {
14396: if ($item eq 'fields') {
14397: my @changed;
14398: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14399: if (@{$confhash{'validation'}{$item}} > 0) {
14400: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14401: }
1.266 raeburn 14402: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14403: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14404: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14405: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14406: $domconfig{'requestcourses'}{'validation'}{$item});
14407: } else {
14408: @changed = @{$confhash{'validation'}{$item}};
14409: }
1.235 raeburn 14410: } else {
14411: @changed = @{$confhash{'validation'}{$item}};
14412: }
14413: } else {
14414: @changed = @{$confhash{'validation'}{$item}};
14415: }
14416: if (@changed) {
14417: if ($confhash{'validation'}{$item}) {
14418: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14419: } else {
14420: $changes{'validation'}{$item} = &mt('None');
14421: }
14422: }
14423: } else {
14424: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14425: if ($item eq 'markup') {
14426: if ($env{'form.requestcourses_validation_'.$item}) {
14427: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14428: }
14429: }
1.266 raeburn 14430: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14431: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14432: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14433: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14434: }
14435: } else {
14436: if ($confhash{'validation'}{$item} ne '') {
14437: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14438: }
1.235 raeburn 14439: }
14440: } else {
14441: if ($confhash{'validation'}{$item} ne '') {
14442: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14443: }
14444: }
14445: }
14446: }
14447: }
14448: if ($env{'form.validationdc'}) {
14449: my $newval = $env{'form.validationdc'};
1.285 raeburn 14450: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14451: if (exists($domcoords{$newval})) {
14452: $confhash{'validation'}{'dc'} = $newval;
14453: }
14454: }
14455: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14456: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14457: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14458: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14459: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14460: if ($confhash{'validation'}{'dc'} eq '') {
14461: $changes{'validation'}{'dc'} = &mt('None');
14462: } else {
14463: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14464: }
1.235 raeburn 14465: }
1.266 raeburn 14466: } elsif ($confhash{'validation'}{'dc'} ne '') {
14467: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14468: }
14469: } elsif ($confhash{'validation'}{'dc'} ne '') {
14470: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14471: }
14472: } elsif ($confhash{'validation'}{'dc'} ne '') {
14473: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14474: }
1.266 raeburn 14475: } else {
14476: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14477: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14478: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14479: $changes{'validation'}{'dc'} = &mt('None');
14480: }
14481: }
1.235 raeburn 14482: }
14483: }
1.102 raeburn 14484: }
14485: } else {
1.86 raeburn 14486: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14487: }
1.72 raeburn 14488: foreach my $item (@usertools) {
14489: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14490: my $unset;
1.101 raeburn 14491: if ($context eq 'requestcourses') {
1.104 raeburn 14492: $unset = '0';
14493: if ($type eq '_LC_adv') {
14494: $unset = '';
14495: }
1.101 raeburn 14496: if ($confhash{$item}{$type} eq 'autolimit') {
14497: $confhash{$item}{$type} .= '=';
14498: unless ($limithash{$item}{$type} =~ /\D/) {
14499: $confhash{$item}{$type} .= $limithash{$item}{$type};
14500: }
14501: }
1.163 raeburn 14502: } elsif ($context eq 'requestauthor') {
14503: $unset = '0';
14504: if ($type eq '_LC_adv') {
14505: $unset = '';
14506: }
1.72 raeburn 14507: } else {
1.101 raeburn 14508: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14509: $confhash{$item}{$type} = 1;
14510: } else {
14511: $confhash{$item}{$type} = 0;
14512: }
1.72 raeburn 14513: }
1.86 raeburn 14514: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14515: if ($action eq 'requestauthor') {
14516: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14517: $changes{$type} = 1;
14518: }
14519: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14520: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14521: $changes{$item}{$type} = 1;
14522: }
14523: } else {
14524: if ($context eq 'requestcourses') {
1.104 raeburn 14525: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14526: $changes{$item}{$type} = 1;
14527: }
14528: } else {
14529: if (!$confhash{$item}{$type}) {
14530: $changes{$item}{$type} = 1;
14531: }
14532: }
14533: }
14534: } else {
14535: if ($context eq 'requestcourses') {
1.104 raeburn 14536: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14537: $changes{$item}{$type} = 1;
14538: }
1.163 raeburn 14539: } elsif ($context eq 'requestauthor') {
14540: if ($confhash{$type} ne $unset) {
14541: $changes{$type} = 1;
14542: }
1.72 raeburn 14543: } else {
14544: if (!$confhash{$item}{$type}) {
14545: $changes{$item}{$type} = 1;
14546: }
14547: }
14548: }
1.1 raeburn 14549: }
14550: }
1.163 raeburn 14551: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14552: if (ref($domconfig{'quotas'}) eq 'HASH') {
14553: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14554: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14555: if (exists($confhash{'defaultquota'}{$key})) {
14556: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14557: $changes{'defaultquota'}{$key} = 1;
14558: }
14559: } else {
14560: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14561: }
14562: }
1.86 raeburn 14563: } else {
14564: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14565: if (exists($confhash{'defaultquota'}{$key})) {
14566: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14567: $changes{'defaultquota'}{$key} = 1;
14568: }
14569: } else {
14570: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14571: }
1.1 raeburn 14572: }
14573: }
1.197 raeburn 14574: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14575: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14576: }
14577: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14578: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14579: }
1.1 raeburn 14580: }
1.86 raeburn 14581: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14582: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14583: if (ref($domconfig{'quotas'}) eq 'HASH') {
14584: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14585: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14586: $changes{'defaultquota'}{$key} = 1;
14587: }
14588: } else {
14589: if (!exists($domconfig{'quotas'}{$key})) {
14590: $changes{'defaultquota'}{$key} = 1;
14591: }
1.72 raeburn 14592: }
14593: } else {
1.86 raeburn 14594: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14595: }
1.1 raeburn 14596: }
14597: }
14598: }
1.72 raeburn 14599:
1.163 raeburn 14600: if ($context eq 'requestauthor') {
14601: $domdefaults{'requestauthor'} = \%confhash;
14602: } else {
14603: foreach my $key (keys(%confhash)) {
1.242 raeburn 14604: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14605: $domdefaults{$key} = $confhash{$key};
14606: }
1.163 raeburn 14607: }
1.72 raeburn 14608: }
1.163 raeburn 14609:
1.1 raeburn 14610: my %quotahash = (
1.86 raeburn 14611: $action => { %confhash }
1.1 raeburn 14612: );
14613: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14614: $dom);
14615: if ($putresult eq 'ok') {
14616: if (keys(%changes) > 0) {
1.72 raeburn 14617: my $cachetime = 24*60*60;
14618: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14619: if (ref($lastactref) eq 'HASH') {
14620: $lastactref->{'domdefaults'} = 1;
14621: }
1.1 raeburn 14622: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14623: unless (($context eq 'requestcourses') ||
1.163 raeburn 14624: ($context eq 'requestauthor')) {
1.86 raeburn 14625: if (ref($changes{'defaultquota'}) eq 'HASH') {
14626: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14627: foreach my $type (@{$types},'default') {
14628: if (defined($changes{'defaultquota'}{$type})) {
14629: my $typetitle = $usertypes->{$type};
14630: if ($type eq 'default') {
14631: $typetitle = $othertitle;
14632: }
1.213 raeburn 14633: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14634: }
14635: }
1.86 raeburn 14636: $resulttext .= '</ul></li>';
1.72 raeburn 14637: }
14638: }
1.80 raeburn 14639: my %newenv;
1.72 raeburn 14640: foreach my $item (@usertools) {
1.163 raeburn 14641: my (%haschgs,%inconf);
14642: if ($context eq 'requestauthor') {
14643: %haschgs = %changes;
1.210 raeburn 14644: %inconf = %confhash;
1.163 raeburn 14645: } else {
14646: if (ref($changes{$item}) eq 'HASH') {
14647: %haschgs = %{$changes{$item}};
14648: }
14649: if (ref($confhash{$item}) eq 'HASH') {
14650: %inconf = %{$confhash{$item}};
14651: }
14652: }
14653: if (keys(%haschgs) > 0) {
1.80 raeburn 14654: my $newacc =
14655: &Apache::lonnet::usertools_access($env{'user.name'},
14656: $env{'user.domain'},
1.86 raeburn 14657: $item,'reload',$context);
1.210 raeburn 14658: if (($context eq 'requestcourses') ||
1.163 raeburn 14659: ($context eq 'requestauthor')) {
1.108 raeburn 14660: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14661: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14662: }
14663: } else {
14664: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14665: $newenv{'environment.availabletools.'.$item} = $newacc;
14666: }
1.80 raeburn 14667: }
1.163 raeburn 14668: unless ($context eq 'requestauthor') {
14669: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14670: }
1.72 raeburn 14671: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14672: if ($haschgs{$type}) {
1.72 raeburn 14673: my $typetitle = $usertypes->{$type};
14674: if ($type eq 'default') {
14675: $typetitle = $othertitle;
14676: } elsif ($type eq '_LC_adv') {
14677: $typetitle = 'LON-CAPA Advanced Users';
14678: }
1.163 raeburn 14679: if ($inconf{$type}) {
1.101 raeburn 14680: if ($context eq 'requestcourses') {
14681: my $cond;
1.163 raeburn 14682: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14683: if ($1 eq '') {
14684: $cond = &mt('(Automatic processing of any request).');
14685: } else {
14686: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14687: }
14688: } else {
1.163 raeburn 14689: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14690: }
14691: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14692: } elsif ($context eq 'requestauthor') {
14693: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14694: $titles{$inconf{$type}},$typetitle);
14695:
1.101 raeburn 14696: } else {
14697: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14698: }
1.72 raeburn 14699: } else {
1.104 raeburn 14700: if ($type eq '_LC_adv') {
1.163 raeburn 14701: if ($inconf{$type} eq '0') {
1.104 raeburn 14702: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14703: } else {
14704: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14705: }
14706: } else {
14707: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14708: }
1.72 raeburn 14709: }
14710: }
1.26 raeburn 14711: }
1.163 raeburn 14712: unless ($context eq 'requestauthor') {
14713: $resulttext .= '</ul></li>';
14714: }
1.26 raeburn 14715: }
1.1 raeburn 14716: }
1.163 raeburn 14717: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14718: if (ref($changes{'notify'}) eq 'HASH') {
14719: if ($changes{'notify'}{'approval'}) {
14720: if (ref($confhash{'notify'}) eq 'HASH') {
14721: if ($confhash{'notify'}{'approval'}) {
14722: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14723: } else {
1.163 raeburn 14724: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14725: }
14726: }
14727: }
14728: }
14729: }
1.216 raeburn 14730: if ($action eq 'requestcourses') {
14731: my @offon = ('off','on');
14732: if ($changes{'uniquecode'}) {
1.218 raeburn 14733: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14734: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14735: $resulttext .= '<li>'.
14736: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14737: '</li>';
14738: } else {
14739: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14740: '</li>';
14741: }
1.216 raeburn 14742: }
1.242 raeburn 14743: foreach my $type ('textbooks','templates') {
14744: if (ref($changes{$type}) eq 'HASH') {
14745: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14746: foreach my $key (sort(keys(%{$changes{$type}}))) {
14747: my %coursehash = &Apache::lonnet::coursedescription($key);
14748: my $coursetitle = $coursehash{'description'};
14749: my $position = $confhash{$type}{$key}{'order'} + 1;
14750: $resulttext .= '<li>';
1.243 raeburn 14751: foreach my $item ('subject','title','publisher','author') {
14752: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14753: ($type eq 'templates'));
1.242 raeburn 14754: my $name = $item.':';
14755: $name =~ s/^(\w)/\U$1/;
14756: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14757: }
14758: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14759: if ($type eq 'textbooks') {
14760: if ($confhash{$type}{$key}{'image'}) {
14761: $resulttext .= ' '.&mt('Image: [_1]',
14762: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14763: ' alt="Textbook cover" />').'<br />';
14764: }
14765: }
14766: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14767: }
1.242 raeburn 14768: $resulttext .= '</ul></li>';
1.216 raeburn 14769: }
14770: }
1.235 raeburn 14771: if (ref($changes{'validation'}) eq 'HASH') {
14772: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14773: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14774: foreach my $item (@{$validationitemsref}) {
14775: if (exists($changes{'validation'}{$item})) {
14776: if ($item eq 'markup') {
14777: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14778: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14779: } else {
14780: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14781: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14782: }
14783: }
14784: }
14785: if (exists($changes{'validation'}{'dc'})) {
14786: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14787: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14788: }
14789: }
14790: }
1.216 raeburn 14791: }
1.1 raeburn 14792: $resulttext .= '</ul>';
1.80 raeburn 14793: if (keys(%newenv)) {
14794: &Apache::lonnet::appenv(\%newenv);
14795: }
1.1 raeburn 14796: } else {
1.86 raeburn 14797: if ($context eq 'requestcourses') {
14798: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14799: } elsif ($context eq 'requestauthor') {
14800: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14801: } else {
1.90 weissno 14802: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14803: }
1.1 raeburn 14804: }
14805: } else {
1.11 albertel 14806: $resulttext = '<span class="LC_error">'.
14807: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14808: }
1.216 raeburn 14809: if ($errors) {
14810: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14811: '<ul>'.$errors.'</ul></p>';
14812: }
1.3 raeburn 14813: return $resulttext;
1.1 raeburn 14814: }
14815:
1.216 raeburn 14816: sub process_textbook_image {
1.242 raeburn 14817: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14818: my $filename = $env{'form.'.$caller.'.filename'};
14819: my ($error,$url);
14820: my ($width,$height) = (50,50);
14821: if ($configuserok eq 'ok') {
14822: if ($switchserver) {
14823: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14824: $switchserver);
14825: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14826: my $modified = [];
1.216 raeburn 14827: my ($result,$imageurl) =
1.421 raeburn 14828: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14829: "$type/$cdom/$cnum/cover",$width,$height,
14830: '',$modified);
1.216 raeburn 14831: if ($result eq 'ok') {
14832: $url = $imageurl;
1.421 raeburn 14833: &update_modify_urls($r,$modified);
1.216 raeburn 14834: } else {
14835: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14836: }
14837: } else {
14838: $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);
14839: }
14840: } else {
14841: $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);
14842: }
14843: return ($url,$error);
14844: }
14845:
1.267 raeburn 14846: sub modify_ltitools {
14847: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14848: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14849: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14850:
1.267 raeburn 14851: my $confname = $dom.'-domainconfig';
14852: my $servadm = $r->dir_config('lonAdmEMail');
14853: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14854:
14855: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14856: my $toolserror =
14857: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14858: $lastactref,$configuserok,$switchserver,$author_ok);
14859:
14860: my $home = &Apache::lonnet::domain($dom,'primary');
14861: unless (($home eq 'no_host') || ($home eq '')) {
14862: my @ids=&Apache::lonnet::current_machine_ids();
14863: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14864: }
14865:
14866: if (keys(%ltitoolschg)) {
14867: foreach my $id (keys(%ltitoolschg)) {
14868: if (ref($ltitoolschg{$id}) eq 'HASH') {
14869: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14870: if (($inner eq 'secret') || ($inner eq 'key')) {
14871: if ($is_home) {
14872: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14873: }
14874: }
14875: }
1.267 raeburn 14876: }
1.421 raeburn 14877: }
14878: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14879: if (keys(%ltitoolschg)) {
14880: %newltitools = %ltitoolschg;
14881: }
14882: }
14883: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14884: foreach my $id (%{$domconfig{'ltitools'}}) {
14885: next if ($id !~ /^\d+$/);
14886: unless (exists($ltitoolschg{$id})) {
14887: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14888: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14889: if (($inner eq 'secret') || ($inner eq 'key')) {
14890: if ($is_home) {
14891: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14892: }
14893: } else {
14894: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14895: }
14896: }
14897: } else {
14898: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14899: }
1.421 raeburn 14900: }
14901: }
14902: }
14903: if ($toolserror) {
14904: $errors = '<li>'.$toolserror.'</li>';
14905: }
14906: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14907: $resulttext = &mt('No changes made.');
14908: if ($errors) {
14909: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14910: $errors.'</ul>';
14911: }
14912: return $resulttext;
14913: }
14914: my %ltitoolshash = (
14915: $action => { %newltitools }
14916: );
14917: if (keys(%secchanges)) {
14918: $ltitoolshash{'toolsec'} = \%newtoolsec;
14919: }
14920: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14921: if ($putresult eq 'ok') {
14922: my %keystore;
14923: if ($is_home) {
14924: my %toolsenchash = (
14925: $action => { %newtoolsenc }
14926: );
14927: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 14928: my $cachetime = 24*60*60;
14929: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 14930: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
14931: }
14932: $resulttext = &mt('Changes made:').'<ul>';
14933: if (keys(%secchanges) > 0) {
1.423 raeburn 14934: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 14935: }
14936: if (keys(%ltitoolschg) > 0) {
14937: $resulttext .= $ltitoolsoutput;
14938: }
1.423 raeburn 14939: my $cachetime = 24*60*60;
14940: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
14941: if (ref($lastactref) eq 'HASH') {
14942: $lastactref->{'ltitools'} = 1;
14943: }
1.421 raeburn 14944: } else {
14945: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14946: }
14947: if ($errors) {
14948: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
14949: $errors.'</ul></p>';
14950: }
14951: return $resulttext;
14952: }
14953:
14954: sub fetch_secrets {
14955: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
14956: my %keyset;
14957: %{$currsec} = ();
14958: $newsec->{'private'}{'keys'} = [];
14959: $newsec->{'encrypt'} = {};
14960: $newsec->{'rules'} = {};
14961: if ($context eq 'ltisec') {
14962: $newsec->{'linkprot'} = {};
14963: }
14964: if (ref($domconfig->{$context}) eq 'HASH') {
14965: %{$currsec} = %{$domconfig->{$context}};
14966: if ($context eq 'ltisec') {
14967: if (ref($currsec->{'linkprot'}) eq 'HASH') {
14968: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
14969: unless ($id =~ /^\d+$/) {
14970: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 14971: }
1.267 raeburn 14972: }
14973: }
1.421 raeburn 14974: }
14975: if (ref($currsec->{'private'}) eq 'HASH') {
14976: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
14977: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
14978: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 14979: }
1.421 raeburn 14980: }
14981: }
14982: my @items= ('crs','dom');
14983: if ($context eq 'ltisec') {
14984: push(@items,'consumers');
14985: }
14986: foreach my $item (@items) {
14987: my $formelement;
14988: if (($context eq 'toolsec') || ($item eq 'consumers')) {
14989: $formelement = 'form.'.$context.'_'.$item;
14990: } else {
14991: $formelement = 'form.'.$context.'_'.$item.'linkprot';
14992: }
14993: if ($env{$formelement}) {
14994: $newsec->{'encrypt'}{$item} = 1;
14995: if (ref($currsec->{'encrypt'}) eq 'HASH') {
14996: unless ($currsec->{'encrypt'}{$item}) {
14997: $secchanges->{'encrypt'} = 1;
14998: }
14999: } else {
15000: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15001: }
1.421 raeburn 15002: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15003: if ($currsec->{'encrypt'}{$item}) {
15004: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15005: }
1.421 raeburn 15006: }
15007: }
15008: my $secrets;
15009: if ($context eq 'ltisec') {
15010: $secrets = 'ltisecrets';
15011: } else {
15012: $secrets = 'toolsecrets';
15013: }
15014: unless (exists($currsec->{'rules'})) {
15015: $currsec->{'rules'} = {};
15016: }
15017: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15018:
15019: my @ids=&Apache::lonnet::current_machine_ids();
15020: my %servers = &Apache::lonnet::get_servers($dom,'library');
15021:
15022: foreach my $hostid (keys(%servers)) {
15023: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15024: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15025: if (exists($env{$keyitem})) {
15026: $env{$keyitem} =~ s/(`)/'/g;
15027: if ($keyset{$hostid}) {
15028: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15029: if ($env{$keyitem} ne '') {
15030: $secchanges->{'private'} = 1;
15031: $newkeyset->{$hostid} = $env{$keyitem};
15032: }
1.296 raeburn 15033: }
1.421 raeburn 15034: } elsif ($env{$keyitem} ne '') {
15035: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15036: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15037: }
1.421 raeburn 15038: $secchanges->{'private'} = 1;
15039: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15040: }
15041: }
1.421 raeburn 15042: }
15043: }
15044: }
15045:
15046: sub store_security {
1.424 raeburn 15047: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15048: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15049: (ref($keystore) eq 'HASH'));
15050: if (keys(%{$secchanges})) {
15051: if ($secchanges->{'private'}) {
15052: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15053: foreach my $hostid (keys(%{$newkeyset})) {
15054: my $storehash = {
15055: key => $newkeyset->{$hostid},
15056: who => $env{'user.name'}.':'.$env{'user.domain'},
15057: };
15058: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15059: $dom,$hostid);
15060: }
15061: }
15062: }
15063: }
15064:
15065: sub lti_security_results {
1.423 raeburn 15066: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15067: my $output;
1.423 raeburn 15068: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15069: my $needs_update;
1.421 raeburn 15070: foreach my $item (keys(%{$secchanges})) {
15071: if ($item eq 'encrypt') {
1.423 raeburn 15072: $needs_update = 1;
1.421 raeburn 15073: my %encrypted;
15074: if ($context eq 'lti') {
15075: %encrypted = (
15076: crs => {
15077: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15078: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15079: },
15080: dom => {
15081: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15082: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15083: },
15084: consumers => {
15085: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15086: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15087: },
15088: );
1.267 raeburn 15089: } else {
1.421 raeburn 15090: %encrypted = (
15091: crs => {
15092: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15093: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15094: },
15095: dom => {
15096: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15097: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15098: },
15099: );
15100: }
15101: my @types= ('crs','dom');
15102: if ($context eq 'lti') {
1.423 raeburn 15103: foreach my $type (@types) {
15104: undef($domdefaults{'linkprotenc_'.$type});
15105: }
1.421 raeburn 15106: push(@types,'consumers');
1.423 raeburn 15107: undef($domdefaults{'ltienc_consumers'});
15108: } elsif ($context eq 'ltitools') {
15109: foreach my $type (@types) {
15110: undef($domdefaults{'toolenc_'.$type});
15111: }
1.267 raeburn 15112: }
1.421 raeburn 15113: foreach my $type (@types) {
15114: my $shown = $encrypted{$type}{'off'};
15115: if (ref($newsec->{$item}) eq 'HASH') {
15116: if ($newsec->{$item}{$type}) {
1.423 raeburn 15117: if ($context eq 'lti') {
15118: if ($type eq 'consumers') {
15119: $domdefaults{'ltienc_consumers'} = 1;
15120: } else {
15121: $domdefaults{'linkprotenc_'.$type} = 1;
15122: }
15123: } elsif ($context eq 'ltitools') {
15124: $domdefaults{'toolenc_'.$type} = 1;
15125: }
1.421 raeburn 15126: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15127: }
1.267 raeburn 15128: }
1.421 raeburn 15129: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15130: }
1.421 raeburn 15131: } elsif ($item eq 'rules') {
15132: my %titles = &Apache::lonlocal::texthash(
15133: min => 'Minimum password length',
15134: max => 'Maximum password length',
15135: chars => 'Required characters',
15136: );
15137: foreach my $rule ('min','max') {
15138: if ($newsec->{rules}{$rule} eq '') {
15139: if ($rule eq 'min') {
15140: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15141: ' '.&mt('Default of [_1] will be used',
15142: $Apache::lonnet::passwdmin).'</li>';
15143: } else {
15144: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15145: }
15146: } else {
15147: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15148: }
15149: }
15150: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15151: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15152: my %rulenames = &Apache::lonlocal::texthash(
15153: uc => 'At least one upper case letter',
15154: lc => 'At least one lower case letter',
15155: num => 'At least one number',
15156: spec => 'At least one non-alphanumeric',
15157: );
15158: my $needed = '<ul><li>'.
15159: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15160: '</li></ul>';
15161: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15162: } else {
15163: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15164: }
1.421 raeburn 15165: } else {
15166: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15167: }
1.421 raeburn 15168: } elsif ($item eq 'private') {
1.423 raeburn 15169: $needs_update = 1;
15170: if ($context eq 'lti') {
15171: undef($domdefaults{'ltiprivhosts'});
15172: } elsif ($context eq 'ltitools') {
15173: undef($domdefaults{'toolprivhosts'});
15174: }
1.421 raeburn 15175: if (keys(%{$newkeyset})) {
1.423 raeburn 15176: my @privhosts;
1.421 raeburn 15177: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15178: if ($keystore->{$hostid} eq 'ok') {
15179: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15180: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15181: push(@privhosts,$hostid);
15182: }
15183: }
15184: }
15185: if (@privhosts) {
15186: if ($context eq 'lti') {
15187: $domdefaults{'ltiprivhosts'} = \@privhosts;
15188: } elsif ($context eq 'ltitools') {
15189: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15190: }
15191: }
15192: }
1.421 raeburn 15193: } elsif ($item eq 'linkprot') {
15194: next;
1.434 raeburn 15195: } elsif ($item eq 'suggested') {
15196: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15197: (ref($newsec->{'suggested'}) eq 'HASH')) {
15198: my $suggestions;
15199: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15200: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15201: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15202: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15203: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15204: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15205: '</li>';
15206: } else {
15207: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15208: $newsec->{'suggested'}->{$id}).'</li>';
15209: }
15210: }
15211: if ($suggestions) {
15212: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15213: '<ul>'.$suggestions.'</ul>'.
15214: '</li>';
15215: }
15216: }
1.267 raeburn 15217: }
15218: }
1.423 raeburn 15219: if ($needs_update) {
15220: my $cachetime = 24*60*60;
15221: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15222: }
1.421 raeburn 15223: return $output;
15224: }
15225:
15226: sub modify_proctoring {
15227: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15228: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15229: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15230: my $confname = $dom.'-domainconfig';
15231: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15232: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15233: my %providernames = &proctoring_providernames();
15234: my $maxnum = scalar(keys(%providernames));
15235:
15236: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15237: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15238: if (ref($requref) eq 'HASH') {
15239: %requserfields = %{$requref};
15240: }
15241: if (ref($opturef) eq 'HASH') {
15242: %optuserfields = %{$opturef};
15243: }
15244: if (ref($defref) eq 'HASH') {
15245: %defaults = %{$defref};
15246: }
15247: if (ref($extref) eq 'HASH') {
15248: %extended = %{$extref};
15249: }
15250: if (ref($crsref) eq 'HASH') {
15251: %crsconf = %{$crsref};
15252: }
15253: if (ref($rolesref) eq 'ARRAY') {
15254: @courseroles = @{$rolesref};
15255: }
15256: if (ref($ltiref) eq 'ARRAY') {
15257: @ltiroles = @{$ltiref};
15258: }
15259:
15260: if (ref($domconfig{$action}) eq 'HASH') {
15261: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15262: if (@todeleteimages) {
15263: map { $imgdeletions{$_} = 1; } @todeleteimages;
15264: }
15265: }
15266: my %customadds;
15267: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15268: if (@newcustom) {
15269: map { $customadds{$_} = 1; } @newcustom;
15270: }
15271: foreach my $provider (sort(keys(%providernames))) {
15272: $confhash{$provider} = {};
15273: my $pos = $env{'form.proctoring_pos_'.$provider};
15274: $pos =~ s/\D+//g;
15275: $allpos[$pos] = $provider;
15276: my (%current,%currentenc);
15277: my $showroles = 0;
15278: if (ref($domconfig{$action}) eq 'HASH') {
15279: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15280: %current = %{$domconfig{$action}{$provider}};
15281: foreach my $item ('key','secret') {
15282: $currentenc{$item} = $current{$item};
15283: delete($current{$item});
15284: }
15285: }
15286: }
15287: if ($env{'form.proctoring_available_'.$provider}) {
15288: $confhash{$provider}{'available'} = 1;
15289: unless ($current{'available'}) {
15290: $changes{$provider} = 1;
15291: }
15292: } else {
15293: %{$confhash{$provider}} = %current;
15294: %{$encconfhash{$provider}} = %currentenc;
15295: $confhash{$provider}{'available'} = 0;
15296: if ($current{'available'}) {
15297: $changes{$provider} = 1;
15298: }
15299: }
15300: if ($confhash{$provider}{'available'}) {
15301: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15302: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15303: if ($field eq 'lifetime') {
15304: if ($possval =~ /^\d+$/) {
15305: $confhash{$provider}{$field} = $possval;
15306: }
15307: } elsif ($field eq 'version') {
15308: if ($possval =~ /^\d+\.\d+$/) {
15309: $confhash{$provider}{$field} = $possval;
15310: }
15311: } elsif ($field eq 'sigmethod') {
15312: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15313: $confhash{$provider}{$field} = $possval;
15314: }
15315: } elsif ($field eq 'url') {
15316: $confhash{$provider}{$field} = $possval;
15317: } elsif (($field eq 'key') || ($field eq 'secret')) {
15318: $encconfhash{$provider}{$field} = $possval;
15319: unless ($currentenc{$field} eq $possval) {
15320: $changes{$provider} = 1;
15321: }
15322: }
15323: unless (($field eq 'key') || ($field eq 'secret')) {
15324: unless ($current{$field} eq $confhash{$provider}{$field}) {
15325: $changes{$provider} = 1;
15326: }
15327: }
15328: }
15329: if ($imgdeletions{$provider}) {
15330: $changes{$provider} = 1;
15331: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15332: my ($imageurl,$error) =
15333: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15334: $configuserok,$switchserver,$author_ok);
15335: if ($imageurl) {
15336: $confhash{$provider}{'image'} = $imageurl;
15337: $changes{$provider} = 1;
15338: }
15339: if ($error) {
15340: &Apache::lonnet::logthis($error);
15341: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15342: }
15343: } elsif (exists($current{'image'})) {
15344: $confhash{$provider}{'image'} = $current{'image'};
15345: }
15346: if (ref($requserfields{$provider}) eq 'ARRAY') {
15347: if (@{$requserfields{$provider}} > 0) {
15348: if (grep(/^user$/,@{$requserfields{$provider}})) {
15349: if ($env{'form.proctoring_userincdom_'.$provider}) {
15350: $confhash{$provider}{'incdom'} = 1;
15351: }
15352: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15353: $changes{$provider} = 1;
15354: }
15355: }
15356: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15357: $showroles = 1;
15358: }
15359: }
15360: }
15361: $confhash{$provider}{'fields'} = [];
15362: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15363: if (@{$optuserfields{$provider}} > 0) {
15364: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15365: foreach my $field (@{$optuserfields{$provider}}) {
15366: if (grep(/^\Q$field\E$/,@optfields)) {
15367: push(@{$confhash{$provider}{'fields'}},$field);
15368: }
15369: }
15370: }
15371: if (ref($current{'fields'}) eq 'ARRAY') {
15372: unless ($changes{$provider}) {
15373: my @new = sort(@{$confhash{$provider}{'fields'}});
15374: my @old = sort(@{$current{'fields'}});
15375: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15376: if (@diffs) {
15377: $changes{$provider} = 1;
15378: }
15379: }
15380: } elsif (@{$confhash{$provider}{'fields'}}) {
15381: $changes{$provider} = 1;
15382: }
15383: }
15384: if (ref($defaults{$provider}) eq 'ARRAY') {
15385: if (@{$defaults{$provider}} > 0) {
15386: my %options;
15387: if (ref($extended{$provider}) eq 'HASH') {
15388: %options = %{$extended{$provider}};
15389: }
15390: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15391: foreach my $field (@{$defaults{$provider}}) {
15392: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15393: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15394: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15395: push(@{$confhash{$provider}{'defaults'}},$poss);
15396: }
15397: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15398: foreach my $inner (keys(%{$options{$field}})) {
15399: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15400: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15401: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15402: $confhash{$provider}{'defaults'}{$inner} = $poss;
15403: }
15404: } else {
15405: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15406: }
15407: }
15408: } else {
15409: if (grep(/^\Q$field\E$/,@checked)) {
15410: push(@{$confhash{$provider}{'defaults'}},$field);
15411: }
15412: }
15413: }
15414: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15415: if (ref($current{'defaults'}) eq 'ARRAY') {
15416: unless ($changes{$provider}) {
15417: my @new = sort(@{$confhash{$provider}{'defaults'}});
15418: my @old = sort(@{$current{'defaults'}});
15419: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15420: if (@diffs) {
15421: $changes{$provider} = 1;
15422: }
15423: }
15424: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15425: if (@{$current{'defaults'}}) {
15426: $changes{$provider} = 1;
15427: }
15428: }
15429: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15430: if (ref($current{'defaults'}) eq 'HASH') {
15431: unless ($changes{$provider}) {
15432: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15433: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15434: $changes{$provider} = 1;
15435: last;
15436: }
15437: }
15438: }
15439: unless ($changes{$provider}) {
15440: foreach my $key (keys(%{$current{'defaults'}})) {
15441: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15442: $changes{$provider} = 1;
15443: last;
15444: }
15445: }
15446: }
15447: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15448: $changes{$provider} = 1;
15449: }
15450: }
15451: }
15452: }
15453: if (ref($crsconf{$provider}) eq 'ARRAY') {
15454: if (@{$crsconf{$provider}} > 0) {
15455: $confhash{$provider}{'crsconf'} = [];
15456: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15457: foreach my $crsfield (@{$crsconf{$provider}}) {
15458: if (grep(/^\Q$crsfield\E$/,@checked)) {
15459: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15460: }
15461: }
15462: if (ref($current{'crsconf'}) eq 'ARRAY') {
15463: unless ($changes{$provider}) {
15464: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15465: my @old = sort(@{$current{'crsconf'}});
15466: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15467: if (@diffs) {
15468: $changes{$provider} = 1;
15469: }
15470: }
15471: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15472: $changes{$provider} = 1;
15473: }
15474: }
15475: }
15476: if ($showroles) {
15477: $confhash{$provider}{'roles'} = {};
15478: foreach my $role (@courseroles) {
15479: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15480: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15481: $confhash{$provider}{'roles'}{$role} = $poss;
15482: }
15483: }
15484: unless ($changes{$provider}) {
15485: if (ref($current{'roles'}) eq 'HASH') {
15486: foreach my $role (keys(%{$current{'roles'}})) {
15487: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15488: $changes{$provider} = 1;
15489: last
15490: }
15491: }
15492: unless ($changes{$provider}) {
15493: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15494: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15495: $changes{$provider} = 1;
15496: last;
15497: }
15498: }
15499: }
15500: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15501: $changes{$provider} = 1;
15502: }
15503: }
15504: }
15505: if (ref($current{'custom'}) eq 'HASH') {
15506: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15507: foreach my $key (keys(%{$current{'custom'}})) {
15508: if (grep(/^\Q$key\E$/,@customdels)) {
15509: $changes{$provider} = 1;
15510: } else {
15511: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15512: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15513: $changes{$provider} = 1;
15514: }
15515: }
15516: }
15517: }
15518: if ($customadds{$provider}) {
15519: my $name = $env{'form.proctoring_custom_name_'.$provider};
15520: $name =~ s/(`)/'/g;
15521: $name =~ s/^\s+//;
15522: $name =~ s/\s+$//;
15523: my $value = $env{'form.proctoring_custom_value_'.$provider};
15524: $value =~ s/(`)/'/g;
15525: $value =~ s/^\s+//;
15526: $value =~ s/\s+$//;
15527: if ($name ne '') {
15528: $confhash{$provider}{'custom'}{$name} = $value;
15529: $changes{$provider} = 1;
15530: }
15531: }
15532: }
15533: }
15534: if (@allpos > 0) {
15535: my $idx = 0;
15536: foreach my $provider (@allpos) {
15537: if ($provider ne '') {
15538: $confhash{$provider}{'order'} = $idx;
15539: unless ($changes{$provider}) {
15540: if (ref($domconfig{$action}) eq 'HASH') {
15541: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15542: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15543: $changes{$provider} = 1;
15544: }
15545: }
15546: }
15547: }
15548: $idx ++;
15549: }
15550: }
15551: }
15552: my %proc_hash = (
15553: $action => { %confhash }
15554: );
15555: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15556: $dom);
15557: if ($putresult eq 'ok') {
15558: my %proc_enchash = (
15559: $action => { %encconfhash }
15560: );
1.384 raeburn 15561: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15562: if (keys(%changes) > 0) {
15563: my $cachetime = 24*60*60;
15564: my %procall = %confhash;
15565: foreach my $provider (keys(%procall)) {
15566: if (ref($encconfhash{$provider}) eq 'HASH') {
15567: foreach my $key ('key','secret') {
15568: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15569: }
15570: }
15571: }
15572: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15573: if (ref($lastactref) eq 'HASH') {
15574: $lastactref->{'proctoring'} = 1;
15575: }
15576: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15577: my %bynum;
15578: foreach my $provider (sort(keys(%changes))) {
15579: my $position = $confhash{$provider}{'order'};
15580: $bynum{$position} = $provider;
15581: }
15582: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15583: my $provider = $bynum{$pos};
15584: my %lt = &proctoring_titles($provider);
15585: my %fieldtitles = &proctoring_fieldtitles($provider);
15586: if (!$confhash{$provider}{'available'}) {
15587: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15588: } else {
15589: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15590: if ($confhash{$provider}{'image'}) {
15591: $resulttext .= ' '.
15592: '<img src="'.$confhash{$provider}{'image'}.'"'.
15593: ' alt="'.&mt('Proctoring icon').'" />';
15594: }
15595: $resulttext .= '<ul>';
15596: my $position = $pos + 1;
15597: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15598: foreach my $key ('version','sigmethod','url','lifetime') {
15599: if ($confhash{$provider}{$key} ne '') {
15600: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15601: }
15602: }
15603: if ($encconfhash{$provider}{'key'} ne '') {
15604: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15605: }
15606: if ($encconfhash{$provider}{'secret'} ne '') {
15607: $resulttext .= '<li>'.$lt{'secret'}.': ';
15608: my $num = length($encconfhash{$provider}{'secret'});
15609: $resulttext .= ('*'x$num).'</li>';
15610: }
15611: my (@fields,$showroles);
15612: if (ref($requserfields{$provider}) eq 'ARRAY') {
15613: push(@fields,@{$requserfields{$provider}});
15614: }
15615: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15616: push(@fields,@{$confhash{$provider}{'fields'}});
15617: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15618: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15619: }
15620: if (@fields) {
15621: if (grep(/^roles$/,@fields)) {
15622: $showroles = 1;
15623: }
15624: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15625: join('", "', map { $lt{$_}; } @fields).'"</li>';
15626: }
15627: if (ref($requserfields{$provider}) eq 'ARRAY') {
15628: if (grep(/^user$/,@{$requserfields{$provider}})) {
15629: if ($confhash{$provider}{'incdom'}) {
15630: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15631: } else {
15632: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15633: }
15634: }
15635: }
15636: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15637: if (@{$confhash{$provider}{'defaults'}} > 0) {
15638: $resulttext .= '<li>'.$lt{'defa'};
15639: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15640: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15641: }
15642: $resulttext =~ s/,$//;
15643: $resulttext .= '</li>';
15644: }
15645: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15646: if (keys(%{$confhash{$provider}{'defaults'}})) {
15647: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15648: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15649: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15650: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15651: }
15652: }
15653: $resulttext .= '</ul></li>';
15654: }
15655: }
15656: if (ref($crsconf{$provider}) eq 'ARRAY') {
15657: if (@{$crsconf{$provider}} > 0) {
15658: $resulttext .= '<li>'.&mt('Configurable in course:');
15659: my $numconfig = 0;
15660: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15661: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15662: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15663: $numconfig ++;
15664: if ($provider eq 'examity') {
15665: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15666: } else {
15667: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15668: }
15669: }
15670: $resulttext =~ s/,$//;
15671: }
15672: }
15673: if (!$numconfig) {
15674: $resulttext .= ' '.&mt('None');
15675: }
15676: $resulttext .= '</li>';
15677: }
15678: }
15679: if ($showroles) {
15680: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15681: my $rolemaps;
15682: foreach my $role (@courseroles) {
15683: if ($confhash{$provider}{'roles'}{$role}) {
15684: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15685: $confhash{$provider}{'roles'}{$role}.',';
15686: }
15687: }
15688: if ($rolemaps) {
15689: $rolemaps =~ s/,$//;
15690: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15691: }
15692: }
15693: }
15694: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15695: my $customlist;
15696: if (keys(%{$confhash{$provider}{'custom'}})) {
15697: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15698: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15699: }
15700: $customlist =~ s/,$//;
15701: }
15702: if ($customlist) {
15703: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15704: }
15705: }
15706: $resulttext .= '</ul></li>';
15707: }
15708: }
15709: $resulttext .= '</ul>';
15710: } else {
15711: $resulttext = &mt('No changes made.');
15712: }
15713: } else {
15714: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15715: }
15716: if ($errors) {
15717: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15718: $errors.'</ul>';
15719: }
15720: return $resulttext;
15721: }
15722:
15723: sub process_proctoring_image {
15724: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15725: my $filename = $env{'form.'.$caller.'.filename'};
15726: my ($error,$url);
15727: my ($width,$height) = (21,21);
15728: if ($configuserok eq 'ok') {
15729: if ($switchserver) {
15730: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15731: $switchserver);
15732: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15733: my $modified = [];
1.372 raeburn 15734: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15735: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15736: "proctoring/$provider/icon",$width,$height,
15737: '',$modified);
1.372 raeburn 15738: if ($result eq 'ok') {
15739: if ($madethumb) {
15740: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15741: my $imagethumb = "$path/tn-".$imagefile;
15742: $url = $imagethumb;
15743: } else {
15744: $url = $imageurl;
15745: }
1.421 raeburn 15746: &update_modify_urls($r,$modified);
1.372 raeburn 15747: } else {
15748: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15749: }
15750: } else {
15751: $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);
15752: }
15753: } else {
15754: $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);
15755: }
15756: return ($url,$error);
15757: }
15758:
1.320 raeburn 15759: sub modify_lti {
15760: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15761: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15762: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15763: my (%posslti,%posslticrs,%posscrstype);
15764: my @courseroles = ('cc','in','ta','ep','st');
15765: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15766: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15767: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15768: my %coursetypetitles = &Apache::lonlocal::texthash (
15769: official => 'Official',
15770: unofficial => 'Unofficial',
15771: community => 'Community',
15772: textbook => 'Textbook',
15773: placement => 'Placement Test',
1.392 raeburn 15774: lti => 'LTI Provider',
1.320 raeburn 15775: );
1.325 raeburn 15776: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15777: my %lt = <i_names();
15778: map { $posslti{$_} = 1; } @ltiroles;
15779: map { $posslticrs{$_} = 1; } @lticourseroles;
15780: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15781:
1.326 raeburn 15782: my %menutitles = <imenu_titles();
1.421 raeburn 15783: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15784:
1.421 raeburn 15785: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15786:
1.406 raeburn 15787: my (%linkprotchg,$linkprotoutput,$is_home);
15788: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15789: \%linkprotchg,'domain');
15790: my $home = &Apache::lonnet::domain($dom,'primary');
15791: unless (($home eq 'no_host') || ($home eq '')) {
15792: my @ids=&Apache::lonnet::current_machine_ids();
15793: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15794: }
15795:
15796: if (keys(%linkprotchg)) {
15797: $secchanges{'linkprot'} = 1;
15798: my %oldlinkprot;
15799: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15800: %oldlinkprot = %{$currltisec{'linkprot'}};
15801: }
15802: foreach my $id (keys(%linkprotchg)) {
15803: if (ref($linkprotchg{$id}) eq 'HASH') {
15804: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15805: if (($inner eq 'secret') || ($inner eq 'key')) {
15806: if ($is_home) {
15807: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15808: }
15809: }
15810: }
15811: } else {
15812: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15813: }
15814: }
15815: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15816: if (keys(%linkprotchg)) {
15817: %{$newltisec{'linkprot'}} = %linkprotchg;
15818: }
15819: }
15820: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15821: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15822: next if ($id !~ /^\d+$/);
15823: unless (exists($linkprotchg{$id})) {
15824: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15825: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15826: if (($inner eq 'secret') || ($inner eq 'key')) {
15827: if ($is_home) {
15828: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15829: }
15830: } else {
15831: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15832: }
15833: }
15834: } else {
15835: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15836: }
15837: }
15838: }
15839: }
15840: if ($proterror) {
15841: $errors .= '<li>'.$proterror.'</li>';
15842: }
1.434 raeburn 15843:
15844: my (%delsuggested,%suggids,@suggested);;
15845: if (ref($currltisec{'suggested'}) eq 'HASH') {
15846: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15847: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15848: for (my $i=0; $i<$maxnum; $i++) {
15849: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15850: $itemid =~ s/\D+//g;
15851: if ($itemid) {
15852: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15853: push(@suggested,$i);
15854: $suggids{$i} = $itemid;
15855: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15856: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15857: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15858: }
15859: } else {
15860: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15861: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15862: } else {
15863: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15864: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15865: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15866: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15867: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15868: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15869: $secchanges{'suggested'}{$itemid} = 1;
15870: }
15871: }
15872: }
15873: }
15874: }
15875: }
15876: }
15877: foreach my $key (keys(%delsuggested)) {
15878: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15879: $secchanges{'suggested'}{$key} = 1;
15880: }
15881: if (($env{'form.linkprot_suggested_add'}) &&
15882: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15883: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15884: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15885: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15886: if ($newsuggid) {
15887: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15888: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15889: $secchanges{'suggested'}{$newsuggid} = 1;
15890: } else {
15891: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15892: if ($errormsg) {
15893: $error .= ' ('.$errormsg.')';
15894: }
15895: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15896: }
15897: }
1.320 raeburn 15898: my (@items,%deletions,%itemids);
15899: if ($env{'form.lti_add'}) {
15900: my $consumer = $env{'form.lti_consumer_add'};
15901: $consumer =~ s/(`)/'/g;
1.434 raeburn 15902: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15903: if ($newid) {
15904: $itemids{'add'} = $newid;
15905: push(@items,'add');
15906: $changes{$newid} = 1;
15907: } else {
15908: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15909: if ($errormsg) {
15910: $error .= ' ('.$errormsg.')';
15911: }
1.320 raeburn 15912: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15913: }
15914: }
15915: if (ref($domconfig{$action}) eq 'HASH') {
15916: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15917: if (@todelete) {
15918: map { $deletions{$_} = 1; } @todelete;
15919: }
15920: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15921: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15922: my $itemid = $env{'form.lti_id_'.$i};
15923: $itemid =~ s/\D+//g;
15924: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15925: if ($deletions{$itemid}) {
15926: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
15927: } else {
1.390 raeburn 15928: push(@items,$i);
15929: $itemids{$i} = $itemid;
1.320 raeburn 15930: }
15931: }
15932: }
15933: }
1.424 raeburn 15934: my (%keystore,$secstored);
15935: if ($is_home) {
15936: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
15937: }
15938:
15939: my ($cipher,$privnum);
15940: if ((@items > 0) && ($is_home)) {
15941: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
15942: $newltisec{'encrypt'},$keystore{$home});
15943: }
1.320 raeburn 15944: foreach my $idx (@items) {
15945: my $itemid = $itemids{$idx};
15946: next unless ($itemid);
1.424 raeburn 15947: my %currlti;
15948: unless ($idx eq 'add') {
15949: if (ref($domconfig{$action}) eq 'HASH') {
15950: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15951: %currlti = %{$domconfig{$action}{$itemid}};
15952: }
15953: }
15954: }
1.390 raeburn 15955: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 15956: $position =~ s/\D+//g;
15957: if ($position ne '') {
15958: $allpos[$position] = $itemid;
15959: }
1.424 raeburn 15960: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 15961: my $formitem = 'form.lti_'.$item.'_'.$idx;
15962: $env{$formitem} =~ s/(`)/'/g;
15963: if ($item eq 'lifetime') {
15964: $env{$formitem} =~ s/[^\d.]//g;
15965: }
15966: if ($env{$formitem} ne '') {
1.424 raeburn 15967: $confhash{$itemid}{$item} = $env{$formitem};
15968: unless (($idx eq 'add') || ($changes{$itemid})) {
15969: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
15970: $changes{$itemid} = 1;
1.320 raeburn 15971: }
15972: }
15973: }
15974: }
15975: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
15976: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
15977: }
1.345 raeburn 15978: if ($confhash{$itemid}{'requser'}) {
15979: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 15980: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 15981: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
15982: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
15983: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
15984: my $mapuser = $env{'form.lti_customuser_'.$idx};
15985: $mapuser =~ s/(`)/'/g;
1.405 raeburn 15986: $mapuser =~ s/^\s+|\s+$//g;
15987: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 15988: }
15989: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
15990: my @makeuser;
15991: foreach my $ltirole (sort(@possmakeuser)) {
15992: if ($posslti{$ltirole}) {
15993: push(@makeuser,$ltirole);
15994: }
15995: }
15996: $confhash{$itemid}{'makeuser'} = \@makeuser;
15997: if (@makeuser) {
15998: my $lcauth = $env{'form.lti_lcauth_'.$idx};
15999: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16000: $confhash{$itemid}{'lcauth'} = $lcauth;
16001: if ($lcauth ne 'internal') {
16002: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16003: $lcauthparm =~ s/^(\s+|\s+)$//g;
16004: $lcauthparm =~ s/`//g;
16005: if ($lcauthparm ne '') {
16006: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16007: }
16008: }
16009: } else {
16010: $confhash{$itemid}{'lcauth'} = 'lti';
16011: }
1.320 raeburn 16012: }
1.345 raeburn 16013: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16014: if (@possinstdata) {
16015: foreach my $field (@possinstdata) {
16016: if (exists($fieldtitles{$field})) {
16017: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16018: }
16019: }
16020: }
1.363 raeburn 16021: if ($env{'form.lti_callback_'.$idx}) {
16022: if ($env{'form.lti_callbackparam_'.$idx}) {
16023: my $callback = $env{'form.lti_callbackparam_'.$idx};
16024: $callback =~ s/^\s+|\s+$//g;
16025: $confhash{$itemid}{'callback'} = $callback;
16026: }
16027: }
1.391 raeburn 16028: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16029: if ($env{'form.lti_'.$field.'_'.$idx}) {
16030: $confhash{$itemid}{$field} = 1;
16031: }
1.320 raeburn 16032: }
1.345 raeburn 16033: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16034: $confhash{$itemid}{lcmenu} = [];
16035: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16036: foreach my $field (@possmenu) {
16037: if (exists($menutitles{$field})) {
16038: if ($field eq 'grades') {
16039: next unless ($env{'form.lti_inlinemenu_'.$idx});
16040: }
16041: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16042: }
16043: }
16044: }
1.391 raeburn 16045: if ($confhash{$itemid}{'crsinc'}) {
16046: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16047: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16048: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16049: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16050: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16051: $mapcrs =~ s/(`)/'/g;
16052: $mapcrs =~ s/^\s+|\s+$//g;
16053: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16054: }
16055: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16056: my @crstypes;
16057: foreach my $type (sort(@posstypes)) {
16058: if ($posscrstype{$type}) {
16059: push(@crstypes,$type);
16060: }
16061: }
16062: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16063: if ($env{'form.lti_storecrs_'.$idx}) {
16064: $confhash{$itemid}{'storecrs'} = 1;
16065: }
1.391 raeburn 16066: if ($env{'form.lti_makecrs_'.$idx}) {
16067: $confhash{$itemid}{'makecrs'} = 1;
16068: }
16069: foreach my $ltirole (@lticourseroles) {
16070: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16071: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16072: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16073: }
16074: }
16075: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16076: my @selfenroll;
16077: foreach my $type (sort(@possenroll)) {
16078: if ($posslticrs{$type}) {
16079: push(@selfenroll,$type);
16080: }
16081: }
16082: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16083: if ($env{'form.lti_crssec_'.$idx}) {
16084: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16085: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16086: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16087: my $section = $env{'form.lti_customsection_'.$idx};
16088: $section =~ s/(`)/'/g;
16089: $section =~ s/^\s+|\s+$//g;
16090: if ($section ne '') {
16091: $confhash{$itemid}{'section'} = $section;
16092: }
16093: }
16094: }
16095: foreach my $field ('passback','roster') {
16096: if ($env{'form.lti_'.$field.'_'.$idx}) {
16097: $confhash{$itemid}{$field} = 1;
16098: }
16099: }
16100: if ($env{'form.lti_passback_'.$idx}) {
16101: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16102: $confhash{$itemid}{'passbackformat'} = '1.0';
16103: } else {
16104: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16105: }
16106: }
1.391 raeburn 16107: }
16108: unless (($idx eq 'add') || ($changes{$itemid})) {
16109: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16110: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16111: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16112: $changes{$itemid} = 1;
16113: }
1.345 raeburn 16114: }
16115: unless ($changes{$itemid}) {
1.424 raeburn 16116: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16117: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16118: $changes{$itemid} = 1;
16119: }
16120: }
1.345 raeburn 16121: }
1.391 raeburn 16122: foreach my $field ('mapcrstype','selfenroll') {
16123: unless ($changes{$itemid}) {
1.424 raeburn 16124: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16125: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16126: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16127: $confhash{$itemid}{$field});
16128: if (@diffs) {
16129: $changes{$itemid} = 1;
16130: }
1.424 raeburn 16131: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16132: $changes{$itemid} = 1;
16133: }
16134: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16135: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16136: $changes{$itemid} = 1;
16137: }
16138: }
1.391 raeburn 16139: }
16140: }
16141: unless ($changes{$itemid}) {
1.424 raeburn 16142: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16143: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16144: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16145: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16146: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16147: $changes{$itemid} = 1;
16148: last;
16149: }
16150: }
1.391 raeburn 16151: unless ($changes{$itemid}) {
16152: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16153: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16154: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16155: $changes{$itemid} = 1;
16156: last;
16157: }
16158: }
16159: }
1.424 raeburn 16160: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16161: $changes{$itemid} = 1;
1.345 raeburn 16162: }
1.391 raeburn 16163: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16164: unless ($changes{$itemid}) {
16165: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16166: $changes{$itemid} = 1;
16167: }
16168: }
16169: }
16170: }
16171: }
16172: unless ($changes{$itemid}) {
16173: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16174: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16175: $changes{$itemid} = 1;
1.320 raeburn 16176: }
1.391 raeburn 16177: }
16178: unless ($changes{$itemid}) {
16179: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16180: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16181: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16182: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16183: $confhash{$itemid}{$field});
16184: if (@diffs) {
16185: $changes{$itemid} = 1;
16186: }
1.424 raeburn 16187: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16188: $changes{$itemid} = 1;
16189: }
16190: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16191: if (@{$confhash{$itemid}{$field}} > 0) {
16192: $changes{$itemid} = 1;
16193: }
1.345 raeburn 16194: }
1.320 raeburn 16195: }
16196: }
16197: }
16198: }
16199: }
1.424 raeburn 16200: if ($is_home) {
16201: my $keyitem = 'form.lti_key_'.$idx;
16202: $env{$keyitem} =~ s/(`)/'/g;
16203: if ($env{$keyitem} ne '') {
16204: $ltienc{$itemid}{'key'} = $env{$keyitem};
16205: unless ($changes{$itemid}) {
16206: if ($currlti{'key'} ne $env{$keyitem}) {
16207: $changes{$itemid} = 1;
16208: }
16209: }
16210: }
16211: my $secretitem = 'form.lti_secret_'.$idx;
16212: $env{$secretitem} =~ s/(`)/'/g;
16213: if ($currlti{'usable'}) {
16214: if ($env{'form.lti_changesecret_'.$idx}) {
16215: if ($env{$secretitem} ne '') {
16216: if ($privnum && $cipher) {
16217: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16218: $confhash{$itemid}{'cipher'} = $privnum;
16219: } else {
16220: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16221: }
16222: $changes{$itemid} = 1;
16223: }
16224: } else {
16225: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16226: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16227: }
16228: if (ref($ltienc{$itemid}) eq 'HASH') {
16229: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16230: $confhash{$itemid}{'usable'} = 1;
16231: }
16232: }
16233: } elsif ($env{$secretitem} ne '') {
16234: if ($privnum && $cipher) {
16235: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16236: $confhash{$itemid}{'cipher'} = $privnum;
16237: } else {
16238: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16239: }
16240: if (ref($ltienc{$itemid}) eq 'HASH') {
16241: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16242: $confhash{$itemid}{'usable'} = 1;
16243: }
16244: }
16245: $changes{$itemid} = 1;
16246: }
16247: }
16248: unless ($changes{$itemid}) {
16249: foreach my $key (keys(%currlti)) {
16250: if (ref($currlti{$key}) eq 'HASH') {
16251: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16252: foreach my $innerkey (keys(%{$currlti{$key}})) {
16253: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16254: $changes{$itemid} = 1;
16255: last;
16256: }
16257: }
16258: } elsif (keys(%{$currlti{$key}}) > 0) {
16259: $changes{$itemid} = 1;
16260: }
16261: }
16262: last if ($changes{$itemid});
16263: }
16264: }
1.320 raeburn 16265: }
16266: if (@allpos > 0) {
16267: my $idx = 0;
16268: foreach my $itemid (@allpos) {
16269: if ($itemid ne '') {
16270: $confhash{$itemid}{'order'} = $idx;
16271: if (ref($domconfig{$action}) eq 'HASH') {
16272: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16273: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16274: $changes{$itemid} = 1;
16275: }
16276: }
16277: }
16278: $idx ++;
16279: }
16280: }
16281: }
1.424 raeburn 16282:
16283: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16284: return &mt('No changes made.');
16285: }
16286:
1.320 raeburn 16287: my %ltihash = (
1.405 raeburn 16288: $action => { %confhash }
16289: );
1.424 raeburn 16290: my %ltienchash;
16291:
16292: if ($is_home) {
16293: %ltienchash = (
16294: $action => { %ltienc }
16295: );
16296: }
1.405 raeburn 16297: if (keys(%secchanges)) {
16298: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16299: if ($secchanges{'linkprot'}) {
16300: if ($is_home) {
16301: $ltienchash{'linkprot'} = \%newltienc;
16302: }
16303: }
1.405 raeburn 16304: }
16305: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16306: if ($putresult eq 'ok') {
1.424 raeburn 16307: if (keys(%ltienchash)) {
16308: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16309: }
16310: $resulttext = &mt('Changes made:').'<ul>';
16311: if (keys(%secchanges) > 0) {
1.423 raeburn 16312: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16313: if (exists($secchanges{'linkprot'})) {
16314: $resulttext .= $linkprotoutput;
1.405 raeburn 16315: }
16316: }
1.320 raeburn 16317: if (keys(%changes) > 0) {
16318: my $cachetime = 24*60*60;
1.424 raeburn 16319: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16320: if (ref($lastactref) eq 'HASH') {
16321: $lastactref->{'lti'} = 1;
16322: }
16323: my %bynum;
16324: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16325: if (ref($confhash{$itemid}) eq 'HASH') {
16326: my $position = $confhash{$itemid}{'order'};
16327: $bynum{$position} = $itemid;
16328: }
1.320 raeburn 16329: }
16330: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16331: my $itemid = $bynum{$pos};
1.424 raeburn 16332: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16333: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16334: my $position = $pos + 1;
16335: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16336: foreach my $item ('version','lifetime') {
16337: if ($confhash{$itemid}{$item} ne '') {
16338: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16339: }
16340: }
1.424 raeburn 16341: if ($ltienc{$itemid}{'key'} ne '') {
16342: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16343: }
1.424 raeburn 16344: if ($ltienc{$itemid}{'secret'} ne '') {
16345: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16346: }
1.345 raeburn 16347: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16348: if ($confhash{$itemid}{'callback'}) {
16349: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16350: } else {
1.392 raeburn 16351: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16352: }
1.345 raeburn 16353: if ($confhash{$itemid}{'mapuser'}) {
16354: my $shownmapuser;
16355: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16356: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16357: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16358: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16359: } else {
16360: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16361: }
1.345 raeburn 16362: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16363: }
1.345 raeburn 16364: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16365: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16366: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16367: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16368: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16369: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16370: } else {
16371: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16372: $confhash{$itemid}{'lcauth'});
16373: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16374: $resulttext .= '; '.&mt('a randomly generated password will be created');
16375: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16376: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16377: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16378: }
16379: } else {
16380: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16381: }
16382: }
16383: $resulttext .= '</li>';
16384: } else {
16385: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16386: }
1.320 raeburn 16387: }
1.345 raeburn 16388: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16389: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16390: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16391: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16392: } else {
1.345 raeburn 16393: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16394: }
1.320 raeburn 16395: }
1.391 raeburn 16396: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16397: $resulttext .= '<li>'.$lt{$item}.': ';
16398: if ($confhash{$itemid}{$item}) {
16399: $resulttext .= &mt('Yes');
16400: } else {
16401: $resulttext .= &mt('No');
1.337 raeburn 16402: }
1.345 raeburn 16403: $resulttext .= '</li>';
1.320 raeburn 16404: }
1.345 raeburn 16405: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16406: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16407: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16408: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16409: } else {
16410: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16411: }
16412: }
16413: if ($confhash{$itemid}{'crsinc'}) {
16414: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16415: my $rolemaps;
16416: foreach my $role (@ltiroles) {
16417: if ($confhash{$itemid}{'maproles'}{$role}) {
16418: $rolemaps .= (' 'x2).$role.'='.
16419: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16420: 'Course').',';
16421: }
16422: }
16423: if ($rolemaps) {
16424: $rolemaps =~ s/,$//;
16425: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16426: }
16427: }
16428: if ($confhash{$itemid}{'mapcrs'}) {
16429: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16430: }
16431: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16432: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16433: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16434: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16435: '</li>';
16436: } else {
16437: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16438: }
16439: }
1.392 raeburn 16440: if ($confhash{$itemid}{'storecrs'}) {
16441: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16442: }
1.391 raeburn 16443: if ($confhash{$itemid}{'makecrs'}) {
16444: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16445: } else {
16446: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16447: }
16448: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16449: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16450: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16451: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16452: '</li>';
16453: } else {
16454: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16455: }
16456: }
16457: if ($confhash{$itemid}{'section'}) {
16458: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16459: $resulttext .= '<li>'.&mt('User section from standard field:').
16460: ' (course_section_sourcedid)'.'</li>';
16461: } else {
16462: $resulttext .= '<li>'.&mt('User section from:').' '.
16463: $confhash{$itemid}{'section'}.'</li>';
16464: }
1.345 raeburn 16465: } else {
1.391 raeburn 16466: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16467: }
16468: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16469: $resulttext .= '<li>'.$lt{$item}.': ';
16470: if ($confhash{$itemid}{$item}) {
16471: $resulttext .= &mt('Yes');
16472: if ($item eq 'passback') {
16473: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16474: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16475: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16476: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16477: }
16478: }
16479: } else {
16480: $resulttext .= &mt('No');
16481: }
16482: $resulttext .= '</li>';
16483: }
16484: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16485: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16486: $resulttext .= '<li>'.&mt('Menu items:').' '.
16487: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16488: } else {
16489: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16490: }
1.345 raeburn 16491: }
1.326 raeburn 16492: }
16493: }
1.320 raeburn 16494: $resulttext .= '</ul></li>';
16495: }
16496: }
1.424 raeburn 16497: if (keys(%deletions)) {
16498: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16499: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16500: }
16501: }
1.320 raeburn 16502: }
1.405 raeburn 16503: $resulttext .= '</ul>';
1.424 raeburn 16504: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16505: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16506: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16507: $lastactref->{'domdefaults'} = 1;
16508: }
16509: }
1.320 raeburn 16510: } else {
16511: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16512: }
16513: if ($errors) {
16514: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16515: $errors.'</ul>';
16516: }
16517: return $resulttext;
16518: }
16519:
1.424 raeburn 16520: sub get_priv_creds {
16521: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16522: my ($needenc,$cipher,$privnum);
16523: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16524: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16525: $needenc = $encrypt->{'consumers'}
16526: } else {
16527: $needenc = $domdefs{'ltienc_consumers'};
16528: }
16529: if ($needenc) {
16530: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16531: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16532: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16533: my $privkey = $privhash{'key'};
16534: $privnum = $privhash{'version'};
16535: if (($privnum) && ($privkey ne '')) {
16536: $cipher = Crypt::CBC->new({'key' => $privkey,
16537: 'cipher' => 'DES'});
16538: }
16539: }
16540: }
16541: return ($cipher,$privnum);
16542: }
16543:
1.320 raeburn 16544: sub get_lti_id {
1.434 raeburn 16545: my ($domain,$consumer,$dbname) = @_;
16546: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16547: return ('','invalid db');
16548: }
16549: # get lock on db
1.320 raeburn 16550: my $lockhash = {
16551: lock => $env{'user.name'}.
16552: ':'.$env{'user.domain'},
16553: };
16554: my $tries = 0;
1.434 raeburn 16555: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16556: my ($id,$error);
16557:
16558: while (($gotlock ne 'ok') && ($tries<10)) {
16559: $tries ++;
16560: sleep (0.1);
1.434 raeburn 16561: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16562: }
16563: if ($gotlock eq 'ok') {
1.434 raeburn 16564: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16565: if ($currids{'lock'}) {
16566: delete($currids{'lock'});
16567: if (keys(%currids)) {
16568: my @curr = sort { $a <=> $b } keys(%currids);
16569: if ($curr[-1] =~ /^\d+$/) {
16570: $id = 1 + $curr[-1];
16571: }
16572: } else {
16573: $id = 1;
16574: }
16575: if ($id) {
1.434 raeburn 16576: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16577: $error = 'nostore';
16578: }
16579: } else {
16580: $error = 'nonumber';
16581: }
16582: }
1.434 raeburn 16583: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16584: } else {
16585: $error = 'nolock';
16586: }
16587: return ($id,$error);
16588: }
16589:
1.3 raeburn 16590: sub modify_autoenroll {
1.205 raeburn 16591: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16592: my ($resulttext,%changes);
16593: my %currautoenroll;
16594: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16595: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16596: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16597: }
16598: }
16599: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16600: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16601: sender => 'Sender for notification messages',
1.274 raeburn 16602: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16603: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16604: my @offon = ('off','on');
1.17 raeburn 16605: my $sender_uname = $env{'form.sender_uname'};
16606: my $sender_domain = $env{'form.sender_domain'};
16607: if ($sender_domain eq '') {
16608: $sender_uname = '';
16609: } elsif ($sender_uname eq '') {
16610: $sender_domain = '';
16611: }
1.129 raeburn 16612: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16613: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16614: $autofailsafe =~ s{^\s+|\s+$}{}g;
16615: if ($autofailsafe =~ /\D/) {
16616: undef($autofailsafe);
16617: }
1.274 raeburn 16618: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16619: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16620: $failsafe = 'off';
1.400 raeburn 16621: undef($autofailsafe);
1.274 raeburn 16622: }
1.1 raeburn 16623: my %autoenrollhash = (
1.129 raeburn 16624: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16625: 'sender_uname' => $sender_uname,
16626: 'sender_domain' => $sender_domain,
16627: 'co-owners' => $coowners,
1.399 raeburn 16628: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16629: 'failsafe' => $failsafe,
1.1 raeburn 16630: }
16631: );
1.4 raeburn 16632: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16633: $dom);
1.1 raeburn 16634: if ($putresult eq 'ok') {
16635: if (exists($currautoenroll{'run'})) {
16636: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16637: $changes{'run'} = 1;
16638: }
16639: } elsif ($autorun) {
16640: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16641: $changes{'run'} = 1;
1.1 raeburn 16642: }
16643: }
1.17 raeburn 16644: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16645: $changes{'sender'} = 1;
16646: }
1.17 raeburn 16647: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16648: $changes{'sender'} = 1;
16649: }
1.129 raeburn 16650: if ($currautoenroll{'co-owners'} ne '') {
16651: if ($currautoenroll{'co-owners'} ne $coowners) {
16652: $changes{'coowners'} = 1;
16653: }
16654: } elsif ($coowners) {
16655: $changes{'coowners'} = 1;
1.274 raeburn 16656: }
1.399 raeburn 16657: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16658: $changes{'autofailsafe'} = 1;
16659: }
1.399 raeburn 16660: if ($currautoenroll{'failsafe'} ne $failsafe) {
16661: $changes{'failsafe'} = 1;
16662: }
1.1 raeburn 16663: if (keys(%changes) > 0) {
16664: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16665: if ($changes{'run'}) {
1.1 raeburn 16666: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16667: }
16668: if ($changes{'sender'}) {
1.17 raeburn 16669: if ($sender_uname eq '' || $sender_domain eq '') {
16670: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16671: } else {
16672: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16673: }
1.1 raeburn 16674: }
1.129 raeburn 16675: if ($changes{'coowners'}) {
16676: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16677: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16678: if (ref($lastactref) eq 'HASH') {
16679: $lastactref->{'domainconfig'} = 1;
16680: }
1.129 raeburn 16681: }
1.274 raeburn 16682: if ($changes{'autofailsafe'}) {
1.399 raeburn 16683: if ($autofailsafe ne '') {
16684: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16685: } else {
1.399 raeburn 16686: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16687: }
1.399 raeburn 16688: }
16689: if ($changes{'failsafe'}) {
16690: if ($failsafe eq 'off') {
16691: unless ($changes{'autofailsafe'}) {
16692: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16693: }
16694: } elsif ($failsafe eq 'zero') {
16695: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16696: } else {
16697: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16698: }
16699: }
16700: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16701: &Apache::lonnet::get_domain_defaults($dom,1);
16702: if (ref($lastactref) eq 'HASH') {
16703: $lastactref->{'domdefaults'} = 1;
16704: }
16705: }
1.1 raeburn 16706: $resulttext .= '</ul>';
16707: } else {
16708: $resulttext = &mt('No changes made to auto-enrollment settings');
16709: }
16710: } else {
1.11 albertel 16711: $resulttext = '<span class="LC_error">'.
16712: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16713: }
1.3 raeburn 16714: return $resulttext;
1.1 raeburn 16715: }
16716:
16717: sub modify_autoupdate {
1.3 raeburn 16718: my ($dom,%domconfig) = @_;
1.1 raeburn 16719: my ($resulttext,%currautoupdate,%fields,%changes);
16720: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16721: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16722: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16723: }
16724: }
16725: my @offon = ('off','on');
16726: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16727: run => 'Auto-update:',
16728: classlists => 'Updates to user information in classlists?',
16729: unexpired => 'Skip updates for users without active or future roles?',
16730: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16731: );
1.44 raeburn 16732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16733: my %fieldtitles = &Apache::lonlocal::texthash (
16734: id => 'Student/Employee ID',
1.20 raeburn 16735: permanentemail => 'E-mail address',
1.1 raeburn 16736: lastname => 'Last Name',
16737: firstname => 'First Name',
16738: middlename => 'Middle Name',
1.132 raeburn 16739: generation => 'Generation',
1.1 raeburn 16740: );
1.142 raeburn 16741: $othertitle = &mt('All users');
1.1 raeburn 16742: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16743: $othertitle = &mt('Other users');
1.1 raeburn 16744: }
16745: foreach my $key (keys(%env)) {
16746: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16747: my ($usertype,$item) = ($1,$2);
16748: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16749: if ($usertype eq 'default') {
16750: push(@{$fields{$1}},$2);
16751: } elsif (ref($types) eq 'ARRAY') {
16752: if (grep(/^\Q$usertype\E$/,@{$types})) {
16753: push(@{$fields{$1}},$2);
16754: }
16755: }
16756: }
1.1 raeburn 16757: }
16758: }
1.131 raeburn 16759: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16760: @lockablenames = sort(@lockablenames);
16761: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16762: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16763: if (@changed) {
16764: $changes{'lockablenames'} = 1;
16765: }
16766: } else {
16767: if (@lockablenames) {
16768: $changes{'lockablenames'} = 1;
16769: }
16770: }
1.1 raeburn 16771: my %updatehash = (
16772: autoupdate => { run => $env{'form.autoupdate_run'},
16773: classlists => $env{'form.classlists'},
1.385 raeburn 16774: unexpired => $env{'form.unexpired'},
1.1 raeburn 16775: fields => {%fields},
1.131 raeburn 16776: lockablenames => \@lockablenames,
1.1 raeburn 16777: }
16778: );
1.385 raeburn 16779: my $lastactivedays;
16780: if ($env{'form.lastactive'}) {
16781: $lastactivedays = $env{'form.lastactivedays'};
16782: $lastactivedays =~ s/^\s+|\s+$//g;
16783: unless ($lastactivedays =~ /^\d+$/) {
16784: undef($lastactivedays);
16785: $env{'form.lastactive'} = 0;
16786: }
16787: }
16788: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16789: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16790: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16791: if (exists($updatehash{autoupdate}{$key})) {
16792: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16793: $changes{$key} = 1;
16794: }
16795: }
16796: } elsif ($key eq 'fields') {
16797: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16798: foreach my $item (@{$types},'default') {
1.1 raeburn 16799: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16800: my $change = 0;
16801: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16802: if (!exists($fields{$item})) {
16803: $change = 1;
1.132 raeburn 16804: last;
1.1 raeburn 16805: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16806: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16807: $change = 1;
1.132 raeburn 16808: last;
1.1 raeburn 16809: }
16810: }
16811: }
16812: if ($change) {
16813: push(@{$changes{$key}},$item);
16814: }
1.26 raeburn 16815: }
1.1 raeburn 16816: }
16817: }
1.131 raeburn 16818: } elsif ($key eq 'lockablenames') {
16819: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16820: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16821: if (@changed) {
16822: $changes{'lockablenames'} = 1;
16823: }
16824: } else {
16825: if (@lockablenames) {
16826: $changes{'lockablenames'} = 1;
16827: }
16828: }
16829: }
16830: }
16831: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16832: if (@lockablenames) {
16833: $changes{'lockablenames'} = 1;
1.1 raeburn 16834: }
16835: }
1.385 raeburn 16836: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16837: if ($updatehash{'autoupdate'}{'unexpired'}) {
16838: $changes{'unexpired'} = 1;
16839: }
16840: }
16841: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16842: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16843: $changes{'lastactive'} = 1;
16844: }
16845: }
1.26 raeburn 16846: foreach my $item (@{$types},'default') {
16847: if (defined($fields{$item})) {
16848: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16849: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16850: my $change = 0;
16851: if (ref($fields{$item}) eq 'ARRAY') {
16852: foreach my $type (@{$fields{$item}}) {
16853: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16854: $change = 1;
16855: last;
16856: }
16857: }
16858: }
16859: if ($change) {
16860: push(@{$changes{'fields'}},$item);
16861: }
16862: } else {
1.26 raeburn 16863: push(@{$changes{'fields'}},$item);
16864: }
16865: } else {
16866: push(@{$changes{'fields'}},$item);
1.1 raeburn 16867: }
16868: }
16869: }
16870: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16871: $dom);
16872: if ($putresult eq 'ok') {
16873: if (keys(%changes) > 0) {
16874: $resulttext = &mt('Changes made:').'<ul>';
16875: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16876: if ($key eq 'lockablenames') {
16877: $resulttext .= '<li>';
16878: if (@lockablenames) {
16879: $usertypes->{'default'} = $othertitle;
16880: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16881: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16882: } else {
16883: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16884: }
16885: $resulttext .= '</li>';
16886: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16887: foreach my $item (@{$changes{$key}}) {
16888: my @newvalues;
16889: foreach my $type (@{$fields{$item}}) {
16890: push(@newvalues,$fieldtitles{$type});
16891: }
1.3 raeburn 16892: my $newvaluestr;
16893: if (@newvalues > 0) {
16894: $newvaluestr = join(', ',@newvalues);
16895: } else {
16896: $newvaluestr = &mt('none');
1.6 raeburn 16897: }
1.1 raeburn 16898: if ($item eq 'default') {
1.26 raeburn 16899: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16900: } else {
1.26 raeburn 16901: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16902: }
16903: }
16904: } else {
16905: my $newvalue;
16906: if ($key eq 'run') {
16907: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16908: } elsif ($key eq 'lastactive') {
16909: $newvalue = $offon[$env{'form.lastactive'}];
16910: unless ($lastactivedays eq '') {
16911: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16912: }
1.1 raeburn 16913: } else {
16914: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16915: }
1.1 raeburn 16916: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16917: }
16918: }
16919: $resulttext .= '</ul>';
16920: } else {
1.3 raeburn 16921: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16922: }
16923: } else {
1.11 albertel 16924: $resulttext = '<span class="LC_error">'.
16925: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16926: }
1.3 raeburn 16927: return $resulttext;
1.1 raeburn 16928: }
16929:
1.125 raeburn 16930: sub modify_autocreate {
16931: my ($dom,%domconfig) = @_;
16932: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
16933: if (ref($domconfig{'autocreate'}) eq 'HASH') {
16934: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
16935: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
16936: }
16937: }
16938: my %title= ( xml => 'Auto-creation of courses in XML course description files',
16939: req => 'Auto-creation of validated requests for official courses',
16940: xmldc => 'Identity of course creator of courses from XML files',
16941: );
16942: my @types = ('xml','req');
16943: foreach my $item (@types) {
16944: $newvals{$item} = $env{'form.autocreate_'.$item};
16945: $newvals{$item} =~ s/\D//g;
16946: $newvals{$item} = 0 if ($newvals{$item} eq '');
16947: }
16948: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 16949: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 16950: unless (exists($domcoords{$newvals{'xmldc'}})) {
16951: $newvals{'xmldc'} = '';
16952: }
16953: %autocreatehash = (
16954: autocreate => { xml => $newvals{'xml'},
16955: req => $newvals{'req'},
16956: }
16957: );
16958: if ($newvals{'xmldc'} ne '') {
16959: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
16960: }
16961: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
16962: $dom);
16963: if ($putresult eq 'ok') {
16964: my @items = @types;
16965: if ($newvals{'xml'}) {
16966: push(@items,'xmldc');
16967: }
16968: foreach my $item (@items) {
16969: if (exists($currautocreate{$item})) {
16970: if ($currautocreate{$item} ne $newvals{$item}) {
16971: $changes{$item} = 1;
16972: }
16973: } elsif ($newvals{$item}) {
16974: $changes{$item} = 1;
16975: }
16976: }
16977: if (keys(%changes) > 0) {
16978: my @offon = ('off','on');
16979: $resulttext = &mt('Changes made:').'<ul>';
16980: foreach my $item (@types) {
16981: if ($changes{$item}) {
16982: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 16983: $resulttext .= '<li>'.
16984: &mt("$title{$item} set to [_1]$newtxt [_2]",
16985: '<b>','</b>').
16986: '</li>';
1.125 raeburn 16987: }
16988: }
16989: if ($changes{'xmldc'}) {
16990: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
16991: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 16992: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 16993: }
16994: $resulttext .= '</ul>';
16995: } else {
16996: $resulttext = &mt('No changes made to auto-creation settings');
16997: }
16998: } else {
16999: $resulttext = '<span class="LC_error">'.
17000: &mt('An error occurred: [_1]',$putresult).'</span>';
17001: }
17002: return $resulttext;
17003: }
17004:
1.23 raeburn 17005: sub modify_directorysrch {
1.295 raeburn 17006: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17007: my ($resulttext,%changes);
17008: my %currdirsrch;
17009: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17010: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17011: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17012: }
17013: }
1.277 raeburn 17014: my %title = ( available => 'Institutional directory search available',
17015: localonly => 'Other domains can search institution',
17016: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17017: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17018: searchby => 'Search types',
17019: searchtypes => 'Search latitude');
17020: my @offon = ('off','on');
1.24 raeburn 17021: my @otherdoms = ('Yes','No');
1.23 raeburn 17022:
1.25 raeburn 17023: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17024: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17025: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17026:
1.44 raeburn 17027: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17028: if (keys(%{$usertypes}) == 0) {
17029: @cansearch = ('default');
17030: } else {
17031: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17032: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17033: if (!grep(/^\Q$type\E$/,@cansearch)) {
17034: push(@{$changes{'cansearch'}},$type);
17035: }
1.23 raeburn 17036: }
1.26 raeburn 17037: foreach my $type (@cansearch) {
17038: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17039: push(@{$changes{'cansearch'}},$type);
17040: }
1.23 raeburn 17041: }
1.26 raeburn 17042: } else {
17043: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17044: }
17045: }
17046:
17047: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17048: foreach my $by (@{$currdirsrch{'searchby'}}) {
17049: if (!grep(/^\Q$by\E$/,@searchby)) {
17050: push(@{$changes{'searchby'}},$by);
17051: }
17052: }
17053: foreach my $by (@searchby) {
17054: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17055: push(@{$changes{'searchby'}},$by);
17056: }
17057: }
17058: } else {
17059: push(@{$changes{'searchby'}},@searchby);
17060: }
1.25 raeburn 17061:
17062: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17063: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17064: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17065: push(@{$changes{'searchtypes'}},$type);
17066: }
17067: }
17068: foreach my $type (@searchtypes) {
17069: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17070: push(@{$changes{'searchtypes'}},$type);
17071: }
17072: }
17073: } else {
17074: if (exists($currdirsrch{'searchtypes'})) {
17075: foreach my $type (@searchtypes) {
17076: if ($type ne $currdirsrch{'searchtypes'}) {
17077: push(@{$changes{'searchtypes'}},$type);
17078: }
17079: }
17080: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17081: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17082: }
17083: } else {
17084: push(@{$changes{'searchtypes'}},@searchtypes);
17085: }
17086: }
17087:
1.23 raeburn 17088: my %dirsrch_hash = (
17089: directorysrch => { available => $env{'form.dirsrch_available'},
17090: cansearch => \@cansearch,
1.277 raeburn 17091: localonly => $env{'form.dirsrch_instlocalonly'},
17092: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17093: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17094: searchby => \@searchby,
1.25 raeburn 17095: searchtypes => \@searchtypes,
1.23 raeburn 17096: }
17097: );
17098: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17099: $dom);
17100: if ($putresult eq 'ok') {
17101: if (exists($currdirsrch{'available'})) {
17102: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17103: $changes{'available'} = 1;
17104: }
17105: } else {
17106: if ($env{'form.dirsrch_available'} eq '1') {
17107: $changes{'available'} = 1;
17108: }
17109: }
1.277 raeburn 17110: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17111: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17112: $changes{'lcavailable'} = 1;
17113: }
1.277 raeburn 17114: } else {
17115: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17116: $changes{'lcavailable'} = 1;
17117: }
17118: }
1.24 raeburn 17119: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17120: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17121: $changes{'localonly'} = 1;
17122: }
1.24 raeburn 17123: } else {
1.277 raeburn 17124: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17125: $changes{'localonly'} = 1;
17126: }
17127: }
1.277 raeburn 17128: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17129: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17130: $changes{'lclocalonly'} = 1;
17131: }
1.277 raeburn 17132: } else {
17133: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17134: $changes{'lclocalonly'} = 1;
17135: }
17136: }
1.23 raeburn 17137: if (keys(%changes) > 0) {
17138: $resulttext = &mt('Changes made:').'<ul>';
17139: if ($changes{'available'}) {
17140: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17141: }
1.277 raeburn 17142: if ($changes{'lcavailable'}) {
17143: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17144: }
1.24 raeburn 17145: if ($changes{'localonly'}) {
1.277 raeburn 17146: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17147: }
1.277 raeburn 17148: if ($changes{'lclocalonly'}) {
17149: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17150: }
1.23 raeburn 17151: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17152: my $chgtext;
1.26 raeburn 17153: if (ref($usertypes) eq 'HASH') {
17154: if (keys(%{$usertypes}) > 0) {
17155: foreach my $type (@{$types}) {
17156: if (grep(/^\Q$type\E$/,@cansearch)) {
17157: $chgtext .= $usertypes->{$type}.'; ';
17158: }
17159: }
17160: if (grep(/^default$/,@cansearch)) {
17161: $chgtext .= $othertitle;
17162: } else {
17163: $chgtext =~ s/\; $//;
17164: }
1.210 raeburn 17165: $resulttext .=
1.178 raeburn 17166: '<li>'.
17167: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17168: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17169: '</li>';
1.23 raeburn 17170: }
17171: }
17172: }
17173: if (ref($changes{'searchby'}) eq 'ARRAY') {
17174: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17175: my $chgtext;
17176: foreach my $type (@{$titleorder}) {
17177: if (grep(/^\Q$type\E$/,@searchby)) {
17178: if (defined($searchtitles->{$type})) {
17179: $chgtext .= $searchtitles->{$type}.'; ';
17180: }
17181: }
17182: }
17183: $chgtext =~ s/\; $//;
17184: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17185: }
1.25 raeburn 17186: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17187: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17188: my $chgtext;
17189: foreach my $type (@{$srchtypeorder}) {
17190: if (grep(/^\Q$type\E$/,@searchtypes)) {
17191: if (defined($srchtypes_desc->{$type})) {
17192: $chgtext .= $srchtypes_desc->{$type}.'; ';
17193: }
17194: }
17195: }
17196: $chgtext =~ s/\; $//;
1.178 raeburn 17197: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17198: }
17199: $resulttext .= '</ul>';
1.295 raeburn 17200: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17201: if (ref($lastactref) eq 'HASH') {
17202: $lastactref->{'directorysrch'} = 1;
17203: }
1.23 raeburn 17204: } else {
1.277 raeburn 17205: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17206: }
17207: } else {
17208: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17209: &mt('An error occurred: [_1]',$putresult).'</span>';
17210: }
17211: return $resulttext;
17212: }
17213:
1.28 raeburn 17214: sub modify_contacts {
1.205 raeburn 17215: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17216: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17217: if (ref($domconfig{'contacts'}) eq 'HASH') {
17218: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17219: $currsetting{$key} = $domconfig{'contacts'}{$key};
17220: }
17221: }
1.286 raeburn 17222: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17223: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17224: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17225: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17226: my @toggles = ('reporterrors','reportupdates','reportstatus');
17227: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17228: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17229: foreach my $type (@mailings) {
17230: @{$newsetting{$type}} =
17231: &Apache::loncommon::get_env_multiple('form.'.$type);
17232: foreach my $item (@contacts) {
17233: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17234: $contacts_hash{contacts}{$type}{$item} = 1;
17235: } else {
17236: $contacts_hash{contacts}{$type}{$item} = 0;
17237: }
1.289 raeburn 17238: }
1.28 raeburn 17239: $others{$type} = $env{'form.'.$type.'_others'};
17240: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17241: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17242: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17243: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17244: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17245: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17246: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17247: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17248: }
1.134 raeburn 17249: }
1.28 raeburn 17250: }
17251: foreach my $item (@contacts) {
17252: $to{$item} = $env{'form.'.$item};
17253: $contacts_hash{'contacts'}{$item} = $to{$item};
17254: }
1.203 raeburn 17255: foreach my $item (@toggles) {
17256: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17257: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17258: }
17259: }
1.340 raeburn 17260: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17261: foreach my $item (@lonstatus) {
17262: if ($item eq 'excluded') {
17263: my (%serverhomes,@excluded);
17264: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17265: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17266: if (@possexcluded) {
17267: foreach my $id (sort(@possexcluded)) {
17268: if ($serverhomes{$id}) {
17269: push(@excluded,$id);
17270: }
17271: }
17272: }
17273: if (@excluded) {
17274: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17275: }
17276: } elsif ($item eq 'weights') {
1.377 raeburn 17277: foreach my $type ('E','W','N','U') {
1.340 raeburn 17278: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17279: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17280: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17281: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17282: $env{'form.error'.$item.'_'.$type};
17283: }
17284: }
17285: }
17286: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17287: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17288: if ($env{'form.error'.$item} =~ /^\d+$/) {
17289: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17290: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17291: }
17292: }
17293: }
17294: }
1.286 raeburn 17295: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17296: foreach my $field (@{$fields}) {
17297: if (ref($possoptions->{$field}) eq 'ARRAY') {
17298: my $value = $env{'form.helpform_'.$field};
17299: $value =~ s/^\s+|\s+$//g;
17300: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17301: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17302: if ($field eq 'screenshot') {
17303: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17304: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17305: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17306: }
17307: }
17308: }
17309: }
17310: }
17311: }
1.315 raeburn 17312: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17313: my (@statuses,%usertypeshash,@overrides);
17314: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17315: @statuses = @{$types};
17316: if (ref($usertypes) eq 'HASH') {
17317: %usertypeshash = %{$usertypes};
17318: }
17319: }
17320: if (@statuses) {
17321: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17322: foreach my $type (@possoverrides) {
17323: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17324: push(@overrides,$type);
17325: }
17326: }
17327: if (@overrides) {
17328: foreach my $type (@overrides) {
17329: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17330: foreach my $item (@contacts) {
17331: if (grep(/^\Q$item\E$/,@standard)) {
17332: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17333: $newsetting{'override_'.$type}{$item} = 1;
17334: } else {
17335: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17336: $newsetting{'override_'.$type}{$item} = 0;
17337: }
17338: }
17339: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17340: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17341: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17342: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17343: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17344: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17345: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17346: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17347: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17348: }
1.425 raeburn 17349: }
1.315 raeburn 17350: }
17351: }
1.28 raeburn 17352: if (keys(%currsetting) > 0) {
17353: foreach my $item (@contacts) {
17354: if ($to{$item} ne $currsetting{$item}) {
17355: $changes{$item} = 1;
17356: }
17357: }
17358: foreach my $type (@mailings) {
17359: foreach my $item (@contacts) {
17360: if (ref($currsetting{$type}) eq 'HASH') {
17361: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17362: push(@{$changes{$type}},$item);
17363: }
17364: } else {
17365: push(@{$changes{$type}},@{$newsetting{$type}});
17366: }
17367: }
17368: if ($others{$type} ne $currsetting{$type}{'others'}) {
17369: push(@{$changes{$type}},'others');
17370: }
1.289 raeburn 17371: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17372: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17373: push(@{$changes{$type}},'bcc');
17374: }
1.286 raeburn 17375: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17376: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17377: push(@{$changes{$type}},'include');
17378: }
17379: }
17380: }
17381: if (ref($fields) eq 'ARRAY') {
17382: if (ref($currsetting{'helpform'}) eq 'HASH') {
17383: foreach my $field (@{$fields}) {
17384: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17385: push(@{$changes{'helpform'}},$field);
17386: }
17387: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17388: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17389: push(@{$changes{'helpform'}},'maxsize');
17390: }
17391: }
17392: }
17393: } else {
17394: foreach my $field (@{$fields}) {
17395: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17396: push(@{$changes{'helpform'}},$field);
17397: }
17398: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17399: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17400: push(@{$changes{'helpform'}},'maxsize');
17401: }
17402: }
17403: }
1.134 raeburn 17404: }
1.28 raeburn 17405: }
1.315 raeburn 17406: if (@statuses) {
1.425 raeburn 17407: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17408: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17409: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17410: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17411: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17412: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17413: push(@{$changes{'overrides'}},$key);
17414: last;
17415: }
17416: }
17417: } else {
17418: push(@{$changes{'overrides'}},$key);
17419: }
17420: }
17421: }
17422: foreach my $key (@overrides) {
17423: unless (exists($currsetting{'overrides'}{$key})) {
17424: push(@{$changes{'overrides'}},$key);
17425: }
17426: }
17427: } else {
17428: foreach my $key (@overrides) {
1.425 raeburn 17429: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17430: }
17431: }
17432: }
1.340 raeburn 17433: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17434: foreach my $key ('excluded','weights','threshold','sysmail') {
17435: if ($key eq 'excluded') {
17436: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17437: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17438: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17439: (@{$currsetting{'lonstatus'}{$key}})) {
17440: my @diffs =
17441: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17442: $currsetting{'lonstatus'}{$key});
17443: if (@diffs) {
17444: push(@{$changes{'lonstatus'}},$key);
17445: }
17446: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17447: push(@{$changes{'lonstatus'}},$key);
17448: }
17449: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17450: (@{$currsetting{'lonstatus'}{$key}})) {
17451: push(@{$changes{'lonstatus'}},$key);
17452: }
17453: } elsif ($key eq 'weights') {
17454: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17455: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17456: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17457: foreach my $type ('E','W','N','U') {
1.340 raeburn 17458: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17459: $currsetting{'lonstatus'}{$key}{$type}) {
17460: push(@{$changes{'lonstatus'}},$key);
17461: last;
17462: }
17463: }
17464: } else {
1.341 raeburn 17465: foreach my $type ('E','W','N','U') {
1.340 raeburn 17466: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17467: push(@{$changes{'lonstatus'}},$key);
17468: last;
17469: }
17470: }
17471: }
17472: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17473: foreach my $type ('E','W','N','U') {
1.340 raeburn 17474: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17475: push(@{$changes{'lonstatus'}},$key);
17476: last;
17477: }
17478: }
17479: }
17480: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17481: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17482: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17483: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17484: push(@{$changes{'lonstatus'}},$key);
17485: }
17486: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17487: push(@{$changes{'lonstatus'}},$key);
17488: }
17489: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17490: push(@{$changes{'lonstatus'}},$key);
17491: }
17492: }
17493: }
17494: } else {
17495: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17496: foreach my $key ('excluded','weights','threshold','sysmail') {
17497: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17498: push(@{$changes{'lonstatus'}},$key);
17499: }
17500: }
17501: }
17502: }
1.28 raeburn 17503: } else {
17504: my %default;
17505: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17506: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17507: $default{'errormail'} = 'adminemail';
17508: $default{'packagesmail'} = 'adminemail';
17509: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17510: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17511: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17512: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17513: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17514: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17515: foreach my $item (@contacts) {
17516: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17517: $changes{$item} = 1;
1.203 raeburn 17518: }
1.28 raeburn 17519: }
17520: foreach my $type (@mailings) {
17521: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17522: push(@{$changes{$type}},@{$newsetting{$type}});
17523: }
17524: if ($others{$type} ne '') {
17525: push(@{$changes{$type}},'others');
1.134 raeburn 17526: }
1.286 raeburn 17527: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17528: if ($bcc{$type} ne '') {
17529: push(@{$changes{$type}},'bcc');
17530: }
1.286 raeburn 17531: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17532: push(@{$changes{$type}},'include');
17533: }
1.134 raeburn 17534: }
1.28 raeburn 17535: }
1.286 raeburn 17536: if (ref($fields) eq 'ARRAY') {
17537: foreach my $field (@{$fields}) {
17538: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17539: push(@{$changes{'helpform'}},$field);
17540: }
17541: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17542: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17543: push(@{$changes{'helpform'}},'maxsize');
17544: }
17545: }
17546: }
1.289 raeburn 17547: }
1.340 raeburn 17548: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17549: foreach my $key ('excluded','weights','threshold','sysmail') {
17550: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17551: push(@{$changes{'lonstatus'}},$key);
17552: }
17553: }
17554: }
1.28 raeburn 17555: }
1.203 raeburn 17556: foreach my $item (@toggles) {
17557: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17558: $changes{$item} = 1;
17559: } elsif ((!$env{'form.'.$item}) &&
17560: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17561: $changes{$item} = 1;
17562: }
17563: }
1.28 raeburn 17564: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17565: $dom);
17566: if ($putresult eq 'ok') {
17567: if (keys(%changes) > 0) {
1.205 raeburn 17568: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17569: if (ref($lastactref) eq 'HASH') {
17570: $lastactref->{'domainconfig'} = 1;
17571: }
1.28 raeburn 17572: my ($titles,$short_titles) = &contact_titles();
17573: $resulttext = &mt('Changes made:').'<ul>';
17574: foreach my $item (@contacts) {
17575: if ($changes{$item}) {
17576: $resulttext .= '<li>'.$titles->{$item}.
17577: &mt(' set to: ').
17578: '<span class="LC_cusr_emph">'.
17579: $to{$item}.'</span></li>';
17580: }
17581: }
17582: foreach my $type (@mailings) {
17583: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17584: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17585: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17586: } else {
17587: $resulttext .= '<li>'.$titles->{$type}.': ';
17588: }
1.28 raeburn 17589: my @text;
17590: foreach my $item (@{$newsetting{$type}}) {
17591: push(@text,$short_titles->{$item});
17592: }
17593: if ($others{$type} ne '') {
17594: push(@text,$others{$type});
17595: }
1.286 raeburn 17596: if (@text) {
17597: $resulttext .= '<span class="LC_cusr_emph">'.
17598: join(', ',@text).'</span>';
17599: }
17600: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17601: if ($bcc{$type} ne '') {
1.286 raeburn 17602: my $bcctext;
17603: if (@text) {
1.289 raeburn 17604: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17605: } else {
17606: $bcctext = '(Bcc)';
17607: }
17608: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17609: } elsif (!@text) {
17610: $resulttext .= &mt('No one');
1.425 raeburn 17611: }
1.289 raeburn 17612: if ($includestr{$type} ne '') {
1.286 raeburn 17613: if ($includeloc{$type} eq 'b') {
17614: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17615: } elsif ($includeloc{$type} eq 's') {
17616: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17617: }
1.134 raeburn 17618: }
1.286 raeburn 17619: } elsif (!@text) {
17620: $resulttext .= &mt('No recipients');
1.134 raeburn 17621: }
17622: $resulttext .= '</li>';
1.28 raeburn 17623: }
17624: }
1.315 raeburn 17625: if (ref($changes{'overrides'}) eq 'ARRAY') {
17626: my @deletions;
17627: foreach my $type (@{$changes{'overrides'}}) {
17628: if ($usertypeshash{$type}) {
17629: if (grep(/^\Q$type\E/,@overrides)) {
17630: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17631: $usertypeshash{$type}).'<ul><li>';
17632: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17633: my @text;
17634: foreach my $item (@contacts) {
1.425 raeburn 17635: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17636: push(@text,$short_titles->{$item});
17637: }
17638: }
17639: if ($newsetting{'override_'.$type}{'others'} ne '') {
17640: push(@text,$newsetting{'override_'.$type}{'others'});
17641: }
1.425 raeburn 17642:
1.315 raeburn 17643: if (@text) {
17644: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17645: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17646: }
17647: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17648: my $bcctext;
17649: if (@text) {
17650: $bcctext = ' '.&mt('with Bcc to');
17651: } else {
17652: $bcctext = '(Bcc)';
17653: }
17654: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17655: } elsif (!@text) {
17656: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17657: }
17658: $resulttext .= '</li>';
17659: if ($newsetting{'override_'.$type}{'include'} ne '') {
17660: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17661: if ($loc eq 'b') {
17662: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17663: } elsif ($loc eq 's') {
17664: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17665: }
17666: }
17667: }
17668: $resulttext .= '</li></ul></li>';
17669: } else {
17670: push(@deletions,$usertypeshash{$type});
17671: }
17672: }
17673: }
17674: if (@deletions) {
17675: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17676: join(', ',@deletions)).'</li>';
17677: }
17678: }
1.203 raeburn 17679: my @offon = ('off','on');
1.340 raeburn 17680: my $corelink = &core_link_msu();
1.203 raeburn 17681: if ($changes{'reporterrors'}) {
17682: $resulttext .= '<li>'.
17683: &mt('E-mail error reports to [_1] set to "'.
17684: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17685: $corelink).
1.203 raeburn 17686: '</li>';
17687: }
17688: if ($changes{'reportupdates'}) {
17689: $resulttext .= '<li>'.
17690: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17691: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17692: $corelink).
1.203 raeburn 17693: '</li>';
17694: }
1.340 raeburn 17695: if ($changes{'reportstatus'}) {
17696: $resulttext .= '<li>'.
17697: &mt('E-mail status if errors above threshold to [_1] set to "'.
17698: $offon[$env{'form.reportstatus'}].'".',
17699: $corelink).
17700: '</li>';
17701: }
17702: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17703: $resulttext .= '<li>'.
17704: &mt('Nightly status check e-mail settings').':<ul>';
17705: my (%defval,%use_def,%shown);
17706: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17707: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17708: $defval{'weights'} =
1.341 raeburn 17709: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17710: $defval{'excluded'} = &mt('None');
17711: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17712: foreach my $item ('threshold','sysmail','weights','excluded') {
17713: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17714: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17715: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17716: } elsif ($item eq 'weights') {
17717: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17718: foreach my $type ('E','W','N','U') {
1.340 raeburn 17719: $shown{$item} .= $lonstatus_names->{$type}.'=';
17720: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17721: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17722: } else {
17723: $shown{$item} .= $lonstatus_defs->{$type};
17724: }
17725: $shown{$item} .= ', ';
17726: }
17727: $shown{$item} =~ s/, $//;
17728: } else {
17729: $shown{$item} = $defval{$item};
17730: }
17731: } elsif ($item eq 'excluded') {
17732: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17733: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17734: } else {
17735: $shown{$item} = $defval{$item};
17736: }
17737: }
17738: } else {
17739: $shown{$item} = $defval{$item};
17740: }
17741: }
17742: } else {
17743: foreach my $item ('threshold','weights','excluded','sysmail') {
17744: $shown{$item} = $defval{$item};
17745: }
17746: }
17747: foreach my $item ('threshold','weights','excluded','sysmail') {
17748: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17749: $shown{$item}).'</li>';
17750: }
17751: $resulttext .= '</ul></li>';
17752: }
1.286 raeburn 17753: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17754: my (@optional,@required,@unused,$maxsizechg);
17755: foreach my $field (@{$changes{'helpform'}}) {
17756: if ($field eq 'maxsize') {
17757: $maxsizechg = 1;
17758: next;
17759: }
17760: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17761: push(@optional,$field);
1.286 raeburn 17762: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17763: push(@unused,$field);
17764: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17765: push(@required,$field);
1.286 raeburn 17766: }
17767: }
17768: if (@optional) {
17769: $resulttext .= '<li>'.
17770: &mt('Help form fields changed to "Optional": [_1].',
17771: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17772: '</li>';
17773: }
17774: if (@required) {
17775: $resulttext .= '<li>'.
17776: &mt('Help form fields changed to "Required": [_1].',
17777: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17778: '</li>';
17779: }
17780: if (@unused) {
17781: $resulttext .= '<li>'.
17782: &mt('Help form fields changed to "Not shown": [_1].',
17783: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17784: '</li>';
17785: }
17786: if ($maxsizechg) {
17787: $resulttext .= '<li>'.
17788: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17789: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17790: '</li>';
17791: }
17792: }
1.28 raeburn 17793: $resulttext .= '</ul>';
17794: } else {
1.288 raeburn 17795: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17796: }
17797: } else {
17798: $resulttext = '<span class="LC_error">'.
17799: &mt('An error occurred: [_1].',$putresult).'</span>';
17800: }
17801: return $resulttext;
17802: }
17803:
1.357 raeburn 17804: sub modify_privacy {
1.427 raeburn 17805: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17806: my ($resulttext,%current,%changes);
17807: if (ref($domconfig{'privacy'}) eq 'HASH') {
17808: %current = %{$domconfig{'privacy'}};
17809: }
17810: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17811: my @items = ('domain','author','course','community');
17812: my %names = &Apache::lonlocal::texthash (
17813: domain => 'Assigned domain role(s)',
17814: author => 'Assigned co-author role(s)',
17815: course => 'Assigned course role(s)',
1.416 raeburn 17816: community => 'Assigned community role(s)',
1.357 raeburn 17817: );
17818: my %roles = &Apache::lonlocal::texthash (
17819: domain => 'Domain role',
17820: author => 'Co-author role',
17821: course => 'Course role',
17822: community => 'Community role',
17823: );
17824: my %titles = &Apache::lonlocal::texthash (
17825: approval => 'Approval for role in different domain',
17826: othdom => 'User information available in other domain',
17827: priv => 'Information viewable by privileged user in same domain',
17828: unpriv => 'Information viewable by unprivileged user in same domain',
17829: instdom => 'Other domain shares institution/provider',
17830: extdom => 'Other domain has different institution/provider',
17831: none => 'Not allowed',
17832: user => 'User authorizes',
17833: domain => 'Domain Coordinator authorizes',
17834: auto => 'Unrestricted',
1.418 raeburn 17835: notify => 'Notify when role needs authorization',
1.357 raeburn 17836: );
17837: my %fieldnames = &Apache::lonlocal::texthash (
17838: id => 'Student/Employee ID',
17839: permanentemail => 'E-mail address',
17840: lastname => 'Last Name',
17841: firstname => 'First Name',
17842: middlename => 'Middle Name',
17843: generation => 'Generation',
17844: );
17845: my ($othertitle,$usertypes,$types) =
17846: &Apache::loncommon::sorted_inst_types($dom);
17847: my (%by_ip,%by_location,@intdoms,@instdoms);
17848: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17849:
17850: my %privacyhash = (
17851: 'approval' => {
17852: instdom => {},
17853: extdom => {},
17854: },
17855: 'othdom' => {},
17856: 'priv' => {},
17857: 'unpriv' => {},
17858: );
17859: foreach my $item (@items) {
17860: if (@instdoms > 1) {
1.416 raeburn 17861: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17862: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17863: }
17864: if (ref($current{'approval'}) eq 'HASH') {
17865: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17866: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17867: $changes{'approval'} = 1;
17868: }
17869: }
17870: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17871: $changes{'approval'} = 1;
17872: }
17873: }
17874: if (keys(%by_location) > 0) {
17875: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17876: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17877: }
17878: if (ref($current{'approval'}) eq 'HASH') {
17879: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17880: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17881: $changes{'approval'} = 1;
17882: }
17883: }
17884: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17885: $changes{'approval'} = 1;
17886: }
17887: }
17888: foreach my $status ('priv','unpriv') {
17889: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17890: my @newvalues;
17891: foreach my $field (@possibles) {
17892: if (grep(/^\Q$field\E$/,@fields)) {
17893: $privacyhash{$status}{$item}{$field} = 1;
17894: push(@newvalues,$field);
17895: }
17896: }
17897: @newvalues = sort(@newvalues);
17898: if (ref($current{$status}) eq 'HASH') {
17899: if (ref($current{$status}{$item}) eq 'HASH') {
17900: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17901: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17902: if (@diffs > 0) {
17903: $changes{$status} = 1;
17904: }
17905: }
17906: } else {
17907: my @stdfields;
17908: foreach my $field (@fields) {
17909: if ($field eq 'id') {
17910: next if ($status eq 'unpriv');
17911: next if (($status eq 'priv') && ($item eq 'community'));
17912: }
17913: push(@stdfields,$field);
17914: }
17915: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17916: if (@diffs > 0) {
17917: $changes{$status} = 1;
17918: }
17919: }
17920: }
17921: }
17922: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17923: my @statuses;
17924: if (ref($types) eq 'ARRAY') {
17925: @statuses = @{$types};
17926: }
17927: foreach my $type (@statuses,'default') {
17928: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
17929: my @newvalues;
17930: foreach my $field (sort(@possfields)) {
17931: if (grep(/^\Q$field\E$/,@fields)) {
17932: $privacyhash{'othdom'}{$type}{$field} = 1;
17933: push(@newvalues,$field);
17934: }
17935: }
17936: @newvalues = sort(@newvalues);
17937: if (ref($current{'othdom'}) eq 'HASH') {
17938: if (ref($current{'othdom'}{$type}) eq 'HASH') {
17939: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
17940: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17941: if (@diffs > 0) {
17942: $changes{'othdom'} = 1;
17943: }
17944: }
17945: } else {
17946: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
17947: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17948: if (@diffs > 0) {
17949: $changes{'othdom'} = 1;
17950: }
17951: }
17952: }
1.417 raeburn 17953: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
17954: my %notify;
17955: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
17956: if (exists($domcoords{$possdc})) {
17957: $notify{$possdc} = 1;
17958: }
17959: }
17960: my $notify = join(',',sort(keys(%notify)));
17961: if ($current{'notify'} ne $notify) {
17962: $changes{'notify'} = 1;
17963: }
17964: $privacyhash{'notify'} = $notify;
1.357 raeburn 17965: }
17966: my %confighash = (
17967: privacy => \%privacyhash,
17968: );
17969: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
17970: if ($putresult eq 'ok') {
17971: if (keys(%changes) > 0) {
17972: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 17973: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 17974: if ($changes{$key}) {
17975: $resulttext .= '<li>'.$titles{$key}.':<ul>';
17976: if ($key eq 'approval') {
17977: if (keys(%{$privacyhash{$key}{instdom}})) {
17978: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
17979: foreach my $item (@items) {
17980: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
17981: }
17982: $resulttext .= '</ul></li>';
17983: }
17984: if (keys(%{$privacyhash{$key}{extdom}})) {
17985: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
17986: foreach my $item (@items) {
17987: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
17988: }
17989: $resulttext .= '</ul></li>';
17990: }
1.417 raeburn 17991: } elsif ($key eq 'notify') {
17992: if ($privacyhash{$key}) {
17993: foreach my $dc (split(/,/,$privacyhash{$key})) {
17994: my ($dcname,$dcdom) = split(/:/,$dc);
17995: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
17996: }
17997: } else {
17998: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
17999: }
1.357 raeburn 18000: } elsif ($key eq 'othdom') {
18001: my @statuses;
18002: if (ref($types) eq 'ARRAY') {
18003: @statuses = @{$types};
18004: }
18005: if (ref($privacyhash{$key}) eq 'HASH') {
18006: foreach my $status (@statuses,'default') {
18007: if ($status eq 'default') {
18008: $resulttext .= '<li>'.$othertitle.': ';
18009: } elsif (ref($usertypes) eq 'HASH') {
18010: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18011: } else {
18012: next;
18013: }
18014: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18015: if (keys(%{$privacyhash{$key}{$status}})) {
18016: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18017: } else {
18018: $resulttext .= &mt('none');
18019: }
18020: }
18021: $resulttext .= '</li>';
18022: }
18023: }
18024: } else {
18025: foreach my $item (@items) {
18026: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18027: $resulttext .= '<li>'.$names{$item}.': ';
18028: if (keys(%{$privacyhash{$key}{$item}})) {
18029: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18030: } else {
18031: $resulttext .= &mt('none');
18032: }
18033: $resulttext .= '</li>';
18034: }
18035: }
18036: }
18037: $resulttext .= '</ul></li>';
18038: }
18039: }
1.421 raeburn 18040: $resulttext .= '</ul>';
1.427 raeburn 18041: if ($changes{'approval'}) {
18042: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18043: delete($domdefaults{'userapprovals'});
18044: if (ref($privacyhash{'approval'}) eq 'HASH') {
18045: foreach my $domtype ('instdom','extdom') {
18046: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18047: foreach my $roletype ('domain','author','course','community') {
18048: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18049: $domdefaults{'userapprovals'} = 1;
18050: last;
18051: }
18052: }
18053: }
18054: last if ($domdefaults{'userapprovals'});
18055: }
18056: }
18057: my $cachetime = 24*60*60;
18058: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18059: if (ref($lastactref) eq 'HASH') {
18060: $lastactref->{'domdefaults'} = 1;
18061: }
18062: }
1.357 raeburn 18063: } else {
18064: $resulttext = &mt('No changes made to user information settings');
18065: }
18066: } else {
18067: $resulttext = '<span class="LC_error">'.
18068: &mt('An error occurred: [_1]',$putresult).'</span>';
18069: }
18070: return $resulttext;
18071: }
18072:
1.354 raeburn 18073: sub modify_passwords {
18074: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18075: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18076: $updatedefaults,$updateconf);
1.354 raeburn 18077: my $customfn = 'resetpw.html';
18078: if (ref($domconfig{'passwords'}) eq 'HASH') {
18079: %current = %{$domconfig{'passwords'}};
18080: }
18081: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18082: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18083: if (ref($types) eq 'ARRAY') {
18084: @oktypes = @{$types};
18085: }
18086: push(@oktypes,'default');
18087:
18088: my %titles = &Apache::lonlocal::texthash (
18089: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18090: intauth_check => 'Check bcrypt cost if authenticated',
18091: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18092: permanent => 'Permanent e-mail address',
18093: critical => 'Critical notification address',
18094: notify => 'Notification address',
18095: min => 'Minimum password length',
18096: max => 'Maximum password length',
18097: chars => 'Required characters',
18098: expire => 'Password expiration (days)',
1.356 raeburn 18099: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18100: reset => 'Resetting Forgotten Password',
18101: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18102: rules => 'Rules for LON-CAPA Passwords',
18103: crsownerchg => 'Course Owner Changing Student Passwords',
18104: username => 'Username',
18105: email => 'E-mail address',
18106: );
18107:
18108: #
18109: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18110: #
18111: my (%curr_defaults,%save_defaults);
18112: if (ref($domconfig{'defaults'}) eq 'HASH') {
18113: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18114: if ($key =~ /^intauth_(cost|check|switch)$/) {
18115: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18116: } else {
18117: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18118: }
18119: }
18120: }
18121: my %staticdefaults = (
18122: 'resetlink' => 2,
18123: 'resetcase' => \@oktypes,
18124: 'resetprelink' => 'both',
18125: 'resetemail' => ['critical','notify','permanent'],
18126: 'intauth_cost' => 10,
18127: 'intauth_check' => 0,
18128: 'intauth_switch' => 0,
18129: );
1.365 raeburn 18130: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18131: foreach my $type (@oktypes) {
18132: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18133: }
18134: my $linklife = $env{'form.passwords_link'};
18135: $linklife =~ s/^\s+|\s+$//g;
18136: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18137: $newvalues{'resetlink'} = $linklife;
18138: if ($current{'resetlink'}) {
18139: if ($current{'resetlink'} ne $linklife) {
18140: $changes{'reset'} = 1;
18141: }
1.368 raeburn 18142: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18143: if ($staticdefaults{'resetlink'} ne $linklife) {
18144: $changes{'reset'} = 1;
18145: }
18146: }
18147: } elsif ($current{'resetlink'}) {
18148: $changes{'reset'} = 1;
18149: }
18150: my @casesens;
18151: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18152: foreach my $case (sort(@posscase)) {
18153: if (grep(/^\Q$case\E$/,@oktypes)) {
18154: push(@casesens,$case);
18155: }
18156: }
18157: $newvalues{'resetcase'} = \@casesens;
18158: if (ref($current{'resetcase'}) eq 'ARRAY') {
18159: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18160: if (@diffs > 0) {
18161: $changes{'reset'} = 1;
18162: }
1.368 raeburn 18163: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18164: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18165: if (@diffs > 0) {
18166: $changes{'reset'} = 1;
18167: }
18168: }
18169: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18170: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18171: if (exists($current{'resetprelink'})) {
18172: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18173: $changes{'reset'} = 1;
18174: }
1.368 raeburn 18175: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18176: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18177: $changes{'reset'} = 1;
18178: }
18179: }
18180: } elsif ($current{'resetprelink'}) {
18181: $changes{'reset'} = 1;
18182: }
18183: foreach my $type (@oktypes) {
18184: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18185: my @postlink;
18186: foreach my $item (sort(@possplink)) {
18187: if ($item =~ /^(email|username)$/) {
18188: push(@postlink,$item);
18189: }
18190: }
18191: $newvalues{'resetpostlink'}{$type} = \@postlink;
18192: unless ($changes{'reset'}) {
18193: if (ref($current{'resetpostlink'}) eq 'HASH') {
18194: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18195: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18196: if (@diffs > 0) {
18197: $changes{'reset'} = 1;
18198: }
18199: } else {
18200: $changes{'reset'} = 1;
18201: }
1.368 raeburn 18202: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18203: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18204: if (@diffs > 0) {
18205: $changes{'reset'} = 1;
18206: }
18207: }
18208: }
18209: }
18210: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18211: my @resetemail;
18212: foreach my $item (sort(@possemailsrc)) {
18213: if ($item =~ /^(permanent|critical|notify)$/) {
18214: push(@resetemail,$item);
18215: }
18216: }
18217: $newvalues{'resetemail'} = \@resetemail;
18218: unless ($changes{'reset'}) {
18219: if (ref($current{'resetemail'}) eq 'ARRAY') {
18220: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18221: if (@diffs > 0) {
18222: $changes{'reset'} = 1;
18223: }
1.368 raeburn 18224: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18225: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18226: if (@diffs > 0) {
18227: $changes{'reset'} = 1;
18228: }
18229: }
18230: }
18231: if ($env{'form.passwords_stdtext'} == 0) {
18232: $newvalues{'resetremove'} = 1;
18233: unless ($current{'resetremove'}) {
18234: $changes{'reset'} = 1;
18235: }
18236: } elsif ($current{'resetremove'}) {
18237: $changes{'reset'} = 1;
18238: }
18239: if ($env{'form.passwords_customfile.filename'} ne '') {
18240: my $servadm = $r->dir_config('lonAdmEMail');
18241: my ($configuserok,$author_ok,$switchserver) =
18242: &config_check($dom,$confname,$servadm);
18243: my $error;
18244: if ($configuserok eq 'ok') {
18245: if ($switchserver) {
18246: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18247: } else {
18248: if ($author_ok eq 'ok') {
1.421 raeburn 18249: my $modified = [];
1.354 raeburn 18250: my ($result,$customurl) =
1.421 raeburn 18251: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18252: $confname,'customtext/resetpw','','',$customfn,
18253: $modified);
1.354 raeburn 18254: if ($result eq 'ok') {
18255: $newvalues{'resetcustom'} = $customurl;
18256: $changes{'reset'} = 1;
1.421 raeburn 18257: &update_modify_urls($r,$modified);
1.354 raeburn 18258: } else {
18259: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18260: }
18261: } else {
18262: $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);
18263: }
18264: }
18265: } else {
18266: $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);
18267: }
18268: if ($error) {
18269: &Apache::lonnet::logthis($error);
18270: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18271: }
18272: } elsif ($current{'resetcustom'}) {
18273: if ($env{'form.passwords_custom_del'}) {
18274: $changes{'reset'} = 1;
18275: } else {
18276: $newvalues{'resetcustom'} = $current{'resetcustom'};
18277: }
18278: }
18279: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18280: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18281: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18282: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18283: $changes{'intauth'} = 1;
18284: }
18285: } else {
18286: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18287: }
18288: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18289: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18290: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18291: $changes{'intauth'} = 1;
18292: }
18293: } else {
18294: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18295: }
18296: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18297: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18298: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18299: $changes{'intauth'} = 1;
18300: }
18301: } else {
18302: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18303: }
18304: foreach my $item ('cost','check','switch') {
18305: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18306: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18307: $updatedefaults = 1;
18308: }
18309: }
1.405 raeburn 18310: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18311: my %crsownerchg = (
18312: by => [],
18313: for => [],
18314: );
18315: foreach my $item ('by','for') {
18316: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18317: foreach my $type (sort(@posstypes)) {
18318: if (grep(/^\Q$type\E$/,@oktypes)) {
18319: push(@{$crsownerchg{$item}},$type);
18320: }
18321: }
18322: }
18323: $newvalues{'crsownerchg'} = \%crsownerchg;
18324: if (ref($current{'crsownerchg'}) eq 'HASH') {
18325: foreach my $item ('by','for') {
18326: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18327: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18328: if (@diffs > 0) {
18329: $changes{'crsownerchg'} = 1;
18330: last;
18331: }
18332: }
18333: }
1.368 raeburn 18334: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18335: foreach my $item ('by','for') {
18336: if (@{$crsownerchg{$item}} > 0) {
18337: $changes{'crsownerchg'} = 1;
18338: last;
18339: }
1.354 raeburn 18340: }
18341: }
18342:
18343: my %confighash = (
18344: defaults => \%save_defaults,
18345: passwords => \%newvalues,
18346: );
18347: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18348:
18349: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18350: if ($putresult eq 'ok') {
18351: if (keys(%changes) > 0) {
18352: $resulttext = &mt('Changes made: ').'<ul>';
18353: foreach my $key ('reset','intauth','rules','crsownerchg') {
18354: if ($changes{$key}) {
1.355 raeburn 18355: unless ($key eq 'intauth') {
18356: $updateconf = 1;
18357: }
1.354 raeburn 18358: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18359: if ($key eq 'reset') {
18360: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18361: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18362: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18363: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18364: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18365: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18366: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18367: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18368: }
1.354 raeburn 18369: } else {
18370: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18371: }
18372: if ($confighash{'passwords'}{'resetlink'}) {
18373: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18374: } else {
18375: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18376: &mt('Will default to 2 hours').'</li>';
18377: }
18378: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18379: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18380: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18381: } else {
18382: my $casesens;
18383: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18384: if ($type eq 'default') {
18385: $casesens .= $othertitle.', ';
18386: } elsif ($usertypes->{$type} ne '') {
18387: $casesens .= $usertypes->{$type}.', ';
18388: }
18389: }
18390: $casesens =~ s/\Q, \E$//;
18391: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18392: }
18393: } else {
18394: $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>';
18395: }
18396: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18397: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18398: } else {
18399: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18400: }
18401: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18402: my $output;
18403: if (ref($types) eq 'ARRAY') {
18404: foreach my $type (@{$types}) {
18405: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18406: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18407: $output .= $usertypes->{$type}.' -- '.&mt('none');
18408: } else {
18409: $output .= $usertypes->{$type}.' -- '.
18410: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18411: }
18412: }
18413: }
18414: }
18415: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18416: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18417: $output .= $othertitle.' -- '.&mt('none');
18418: } else {
18419: $output .= $othertitle.' -- '.
18420: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18421: }
18422: }
18423: if ($output) {
18424: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18425: } else {
18426: $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>';
18427: }
18428: } else {
18429: $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>';
18430: }
18431: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18432: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18433: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18434: } else {
18435: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18436: }
18437: } else {
1.379 raeburn 18438: $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 18439: }
18440: if ($confighash{'passwords'}{'resetremove'}) {
18441: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18442: } else {
18443: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18444: }
18445: if ($confighash{'passwords'}{'resetcustom'}) {
18446: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18447: &mt('custom text'),600,500,undef,undef,
18448: undef,undef,'background-color:#ffffff');
18449: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18450: } else {
18451: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18452: }
18453: } elsif ($key eq 'intauth') {
18454: foreach my $item ('cost','switch','check') {
18455: my $value = $save_defaults{$key.'_'.$item};
18456: if ($item eq 'switch') {
18457: my %optiondesc = &Apache::lonlocal::texthash (
18458: 0 => 'No',
18459: 1 => 'Yes',
18460: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18461: );
18462: if ($value =~ /^(0|1|2)$/) {
18463: $value = $optiondesc{$value};
18464: } else {
18465: $value = &mt('none -- defaults to No');
18466: }
18467: } elsif ($item eq 'check') {
18468: my %optiondesc = &Apache::lonlocal::texthash (
18469: 0 => 'No',
18470: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18471: 2 => 'Yes, disallow login if stored cost is less than domain default',
18472: );
18473: if ($value =~ /^(0|1|2)$/) {
18474: $value = $optiondesc{$value};
18475: } else {
18476: $value = &mt('none -- defaults to No');
18477: }
18478: }
18479: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18480: }
18481: } elsif ($key eq 'rules') {
1.356 raeburn 18482: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18483: if ($confighash{'passwords'}{$rule} eq '') {
18484: if ($rule eq 'min') {
1.356 raeburn 18485: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18486: ' '.&mt('Default of [_1] will be used',
18487: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18488: } else {
18489: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18490: }
18491: } else {
18492: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18493: }
18494: }
1.370 raeburn 18495: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18496: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18497: my %rulenames = &Apache::lonlocal::texthash(
18498: uc => 'At least one upper case letter',
18499: lc => 'At least one lower case letter',
18500: num => 'At least one number',
18501: spec => 'At least one non-alphanumeric',
18502: );
18503: my $needed = '<ul><li>'.
18504: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18505: '</li></ul>';
1.370 raeburn 18506: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18507: } else {
18508: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18509: }
18510: } else {
18511: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18512: }
1.354 raeburn 18513: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18514: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18515: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18516: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18517: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18518: } else {
18519: my %crsownerstr;
18520: foreach my $item ('by','for') {
18521: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18522: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18523: if ($type eq 'default') {
18524: $crsownerstr{$item} .= $othertitle.', ';
18525: } elsif ($usertypes->{$type} ne '') {
18526: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18527: }
18528: }
18529: $crsownerstr{$item} =~ s/\Q, \E$//;
18530: }
18531: }
18532: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18533: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18534: }
1.354 raeburn 18535: } else {
1.359 raeburn 18536: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18537: }
18538: }
18539: $resulttext .= '</ul></li>';
18540: }
18541: }
18542: $resulttext .= '</ul>';
18543: } else {
18544: $resulttext = &mt('No changes made to password settings');
18545: }
1.355 raeburn 18546: my $cachetime = 24*60*60;
1.354 raeburn 18547: if ($updatedefaults) {
18548: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18549: if (ref($lastactref) eq 'HASH') {
18550: $lastactref->{'domdefaults'} = 1;
18551: }
18552: }
1.355 raeburn 18553: if ($updateconf) {
18554: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18555: if (ref($lastactref) eq 'HASH') {
18556: $lastactref->{'passwdconf'} = 1;
18557: }
18558: }
1.354 raeburn 18559: } else {
18560: $resulttext = '<span class="LC_error">'.
18561: &mt('An error occurred: [_1]',$putresult).'</span>';
18562: }
18563: if ($errors) {
18564: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18565: $errors.'</ul></p>';
18566: }
18567: return $resulttext;
18568: }
18569:
1.405 raeburn 18570: sub password_rule_changes {
18571: my ($prefix,$newvalues,$current,$changes) = @_;
18572: return unless ((ref($newvalues) eq 'HASH') &&
18573: (ref($current) eq 'HASH') &&
18574: (ref($changes) eq 'HASH'));
18575: my (@rules,%staticdefaults);
18576: if ($prefix eq 'passwords') {
18577: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18578: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18579: @rules = ('min','max');
18580: }
18581: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18582: foreach my $rule (@rules) {
18583: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18584: my $ruleok;
18585: if ($rule eq 'expire') {
18586: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18587: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18588: $ruleok = 1;
18589: }
18590: } elsif ($rule eq 'min') {
18591: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18592: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18593: $ruleok = 1;
18594: }
18595: }
18596: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18597: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18598: $ruleok = 1;
18599: }
18600: if ($ruleok) {
18601: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18602: if (exists($current->{$rule})) {
18603: if ($newvalues->{$rule} ne $current->{$rule}) {
18604: $changes->{'rules'} = 1;
18605: }
18606: } elsif ($rule eq 'min') {
18607: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18608: $changes->{'rules'} = 1;
18609: }
18610: } else {
18611: $changes->{'rules'} = 1;
18612: }
18613: } elsif (exists($current->{$rule})) {
18614: $changes->{'rules'} = 1;
18615: }
18616: }
18617: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18618: my @chars;
18619: foreach my $item (sort(@posschars)) {
18620: if ($item =~ /^(uc|lc|num|spec)$/) {
18621: push(@chars,$item);
18622: }
18623: }
18624: $newvalues->{'chars'} = \@chars;
18625: unless ($changes->{'rules'}) {
18626: if (ref($current->{'chars'}) eq 'ARRAY') {
18627: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18628: if (@diffs > 0) {
18629: $changes->{'rules'} = 1;
18630: }
18631: } else {
18632: if (@chars > 0) {
18633: $changes->{'rules'} = 1;
18634: }
18635: }
18636: }
18637: return;
18638: }
18639:
1.28 raeburn 18640: sub modify_usercreation {
1.27 raeburn 18641: my ($dom,%domconfig) = @_;
1.224 raeburn 18642: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18643: my $warningmsg;
1.27 raeburn 18644: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18645: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18646: if ($key eq 'cancreate') {
18647: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18648: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18649: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18650: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18651: } else {
1.224 raeburn 18652: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18653: }
18654: }
18655: }
18656: } elsif ($key eq 'email_rule') {
18657: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18658: } else {
18659: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18660: }
1.27 raeburn 18661: }
18662: }
18663: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18664: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18665: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18666: foreach my $item(@contexts) {
1.224 raeburn 18667: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18668: }
1.34 raeburn 18669: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18670: foreach my $item (@contexts) {
1.224 raeburn 18671: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18672: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18673: }
1.27 raeburn 18674: }
1.34 raeburn 18675: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18676: foreach my $item (@contexts) {
1.43 raeburn 18677: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18678: if ($cancreate{$item} ne 'any') {
18679: push(@{$changes{'cancreate'}},$item);
18680: }
18681: } else {
18682: if ($cancreate{$item} ne 'none') {
18683: push(@{$changes{'cancreate'}},$item);
18684: }
1.27 raeburn 18685: }
18686: }
18687: } else {
1.43 raeburn 18688: foreach my $item (@contexts) {
1.34 raeburn 18689: push(@{$changes{'cancreate'}},$item);
18690: }
1.27 raeburn 18691: }
1.34 raeburn 18692:
1.27 raeburn 18693: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18694: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18695: if (!grep(/^\Q$type\E$/,@username_rule)) {
18696: push(@{$changes{'username_rule'}},$type);
18697: }
18698: }
18699: foreach my $type (@username_rule) {
18700: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18701: push(@{$changes{'username_rule'}},$type);
18702: }
18703: }
18704: } else {
18705: push(@{$changes{'username_rule'}},@username_rule);
18706: }
18707:
1.32 raeburn 18708: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18709: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18710: if (!grep(/^\Q$type\E$/,@id_rule)) {
18711: push(@{$changes{'id_rule'}},$type);
18712: }
18713: }
18714: foreach my $type (@id_rule) {
18715: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18716: push(@{$changes{'id_rule'}},$type);
18717: }
18718: }
18719: } else {
18720: push(@{$changes{'id_rule'}},@id_rule);
18721: }
18722:
1.43 raeburn 18723: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18724: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18725: my %authhash;
1.43 raeburn 18726: foreach my $item (@authen_contexts) {
1.28 raeburn 18727: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18728: foreach my $auth (@authtypes) {
18729: if (grep(/^\Q$auth\E$/,@authallowed)) {
18730: $authhash{$item}{$auth} = 1;
18731: } else {
18732: $authhash{$item}{$auth} = 0;
18733: }
18734: }
18735: }
18736: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18737: foreach my $item (@authen_contexts) {
1.28 raeburn 18738: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18739: foreach my $auth (@authtypes) {
18740: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18741: push(@{$changes{'authtypes'}},$item);
18742: last;
18743: }
18744: }
18745: }
18746: }
18747: } else {
1.43 raeburn 18748: foreach my $item (@authen_contexts) {
1.28 raeburn 18749: push(@{$changes{'authtypes'}},$item);
18750: }
18751: }
18752:
1.224 raeburn 18753: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18754: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18755: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18756: $save_usercreate{'id_rule'} = \@id_rule;
18757: $save_usercreate{'username_rule'} = \@username_rule,
18758: $save_usercreate{'authtypes'} = \%authhash;
18759:
1.27 raeburn 18760: my %usercreation_hash = (
1.224 raeburn 18761: usercreation => \%save_usercreate,
18762: );
1.27 raeburn 18763:
18764: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18765: $dom);
1.50 raeburn 18766:
1.224 raeburn 18767: if ($putresult eq 'ok') {
18768: if (keys(%changes) > 0) {
18769: $resulttext = &mt('Changes made:').'<ul>';
18770: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18771: my %lt = &usercreation_types();
18772: foreach my $type (@{$changes{'cancreate'}}) {
18773: my $chgtext = $lt{$type}.', ';
18774: if ($cancreate{$type} eq 'none') {
18775: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18776: } elsif ($cancreate{$type} eq 'any') {
18777: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18778: } elsif ($cancreate{$type} eq 'official') {
18779: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18780: } elsif ($cancreate{$type} eq 'unofficial') {
18781: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18782: }
18783: $resulttext .= '<li>'.$chgtext.'</li>';
18784: }
18785: }
18786: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18787: my ($rules,$ruleorder) =
18788: &Apache::lonnet::inst_userrules($dom,'username');
18789: my $chgtext = '<ul>';
18790: foreach my $type (@username_rule) {
18791: if (ref($rules->{$type}) eq 'HASH') {
18792: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18793: }
18794: }
18795: $chgtext .= '</ul>';
18796: if (@username_rule > 0) {
18797: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18798: } else {
18799: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18800: }
18801: }
18802: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18803: my ($idrules,$idruleorder) =
18804: &Apache::lonnet::inst_userrules($dom,'id');
18805: my $chgtext = '<ul>';
18806: foreach my $type (@id_rule) {
18807: if (ref($idrules->{$type}) eq 'HASH') {
18808: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18809: }
18810: }
18811: $chgtext .= '</ul>';
18812: if (@id_rule > 0) {
18813: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18814: } else {
18815: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18816: }
18817: }
18818: my %authname = &authtype_names();
18819: my %context_title = &context_names();
18820: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18821: my $chgtext = '<ul>';
18822: foreach my $type (@{$changes{'authtypes'}}) {
18823: my @allowed;
18824: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18825: foreach my $auth (@authtypes) {
18826: if ($authhash{$type}{$auth}) {
18827: push(@allowed,$authname{$auth});
18828: }
18829: }
18830: if (@allowed > 0) {
18831: $chgtext .= join(', ',@allowed).'</li>';
18832: } else {
18833: $chgtext .= &mt('none').'</li>';
18834: }
18835: }
18836: $chgtext .= '</ul>';
18837: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18838: $resulttext .= '</li>';
18839: }
18840: $resulttext .= '</ul>';
18841: } else {
18842: $resulttext = &mt('No changes made to user creation settings');
18843: }
18844: } else {
18845: $resulttext = '<span class="LC_error">'.
18846: &mt('An error occurred: [_1]',$putresult).'</span>';
18847: }
18848: if ($warningmsg ne '') {
18849: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18850: }
18851: return $resulttext;
18852: }
18853:
18854: sub modify_selfcreation {
1.305 raeburn 18855: my ($dom,$lastactref,%domconfig) = @_;
18856: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18857: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18858: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18859: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18860: if (ref($typesref) eq 'ARRAY') {
18861: @types = @{$typesref};
18862: }
18863: if (ref($usertypesref) eq 'HASH') {
18864: %usertypes = %{$usertypesref};
1.228 raeburn 18865: }
1.303 raeburn 18866: $usertypes{'default'} = $othertitle;
1.224 raeburn 18867: #
18868: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18869: #
18870: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18871: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18872: if ($key eq 'cancreate') {
18873: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18874: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18875: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18876: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18877: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18878: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18879: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18880: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18881: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18882: } else {
18883: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18884: }
18885: }
18886: }
18887: } elsif ($key eq 'email_rule') {
18888: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18889: } else {
18890: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18891: }
18892: }
18893: }
18894: #
18895: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18896: #
18897: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18898: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18899: if ($key eq 'selfcreate') {
18900: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18901: } else {
18902: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18903: }
18904: }
18905: }
1.305 raeburn 18906: #
18907: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18908: #
18909: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18910: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18911: if ($key eq 'inststatusguest') {
18912: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18913: } else {
18914: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18915: }
18916: }
18917: }
1.224 raeburn 18918:
18919: my @contexts = ('selfcreate');
18920: @{$cancreate{'selfcreate'}} = ();
18921: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18922: if (@types) {
18923: @{$cancreate{'statustocreate'}} = ();
18924: }
1.236 raeburn 18925: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 18926: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 18927: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 18928: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 18929: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 18930: my %selfcreatetypes = (
18931: sso => 'users authenticated by institutional single sign on',
18932: login => 'users authenticated by institutional log-in',
1.303 raeburn 18933: email => 'users verified by e-mail',
1.50 raeburn 18934: );
1.224 raeburn 18935: #
18936: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
18937: # is permitted.
18938: #
1.305 raeburn 18939: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 18940:
1.305 raeburn 18941: my (@statuses,%email_rule);
1.228 raeburn 18942: foreach my $item ('login','sso','email') {
1.224 raeburn 18943: if ($item eq 'email') {
1.236 raeburn 18944: if ($env{'form.cancreate_email'}) {
1.305 raeburn 18945: if (@types) {
18946: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
18947: foreach my $status (@poss_statuses) {
18948: if (grep(/^\Q$status\E$/,(@types,'default'))) {
18949: push(@statuses,$status);
18950: }
18951: }
18952: $save_inststatus{'inststatusguest'} = \@statuses;
18953: } else {
18954: push(@statuses,'default');
18955: }
18956: if (@statuses) {
18957: my %curr_rule;
18958: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
18959: foreach my $type (@statuses) {
18960: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 18961: }
1.305 raeburn 18962: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
18963: foreach my $type (@statuses) {
18964: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
18965: }
18966: }
18967: push(@{$cancreate{'selfcreate'}},'email');
18968: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
18969: my %curremaildom;
18970: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
18971: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
18972: }
18973: foreach my $type (@statuses) {
18974: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
18975: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
18976: }
18977: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
18978: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
18979: }
18980: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
18981: #
18982: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
18983: #
18984: my $chosen = $1;
18985: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
18986: my $emaildom;
18987: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 18988: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 18989: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
18990: if (ref($curremaildom{$type}) eq 'HASH') {
18991: if (exists($curremaildom{$type}{$chosen})) {
18992: if ($curremaildom{$type}{$chosen} ne $emaildom) {
18993: push(@{$changes{'cancreate'}},'emaildomain');
18994: }
18995: } elsif ($emaildom ne '') {
18996: push(@{$changes{'cancreate'}},'emaildomain');
18997: }
18998: } elsif ($emaildom ne '') {
18999: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19000: }
1.305 raeburn 19001: }
19002: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19003: } elsif ($chosen eq 'custom') {
19004: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19005: $email_rule{$type} = [];
19006: if (ref($emailrules) eq 'HASH') {
19007: foreach my $rule (@possemail_rules) {
19008: if (exists($emailrules->{$rule})) {
19009: push(@{$email_rule{$type}},$rule);
19010: }
19011: }
19012: }
19013: if (@{$email_rule{$type}}) {
19014: $cancreate{'emailoptions'}{$type} = 'custom';
19015: if (ref($curr_rule{$type}) eq 'ARRAY') {
19016: if (@{$curr_rule{$type}} > 0) {
19017: foreach my $rule (@{$curr_rule{$type}}) {
19018: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19019: push(@{$changes{'email_rule'}},$type);
19020: }
19021: }
19022: }
19023: foreach my $type (@{$email_rule{$type}}) {
19024: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19025: push(@{$changes{'email_rule'}},$type);
19026: }
19027: }
19028: } else {
19029: push(@{$changes{'email_rule'}},$type);
19030: }
19031: }
19032: } else {
19033: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19034: }
19035: }
19036: }
19037: if (@types) {
19038: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19039: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19040: if (@changed) {
19041: push(@{$changes{'inststatus'}},'inststatusguest');
19042: }
19043: } else {
19044: push(@{$changes{'inststatus'}},'inststatusguest');
19045: }
19046: }
19047: } else {
19048: delete($env{'form.cancreate_email'});
19049: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19050: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19051: push(@{$changes{'inststatus'}},'inststatusguest');
19052: }
19053: }
19054: }
19055: } else {
19056: $save_inststatus{'inststatusguest'} = [];
19057: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19058: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19059: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19060: }
19061: }
1.224 raeburn 19062: }
19063: } else {
19064: if ($env{'form.cancreate_'.$item}) {
19065: push(@{$cancreate{'selfcreate'}},$item);
19066: }
19067: }
19068: }
1.305 raeburn 19069: my (%userinfo,%savecaptcha);
1.224 raeburn 19070: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19071: #
1.228 raeburn 19072: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19073: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19074: #
1.236 raeburn 19075:
1.244 raeburn 19076: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19077: push(@contexts,'emailusername');
1.305 raeburn 19078: if (@statuses) {
19079: foreach my $type (@statuses) {
1.228 raeburn 19080: if (ref($infofields) eq 'ARRAY') {
19081: foreach my $field (@{$infofields}) {
19082: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19083: $cancreate{'emailusername'}{$type}{$field} = $1;
19084: }
19085: }
1.224 raeburn 19086: }
19087: }
19088: }
19089: #
19090: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19091: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19092: #
19093:
19094: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19095: @approvalnotify = sort(@approvalnotify);
19096: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19097: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19098: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19099: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19100: push(@{$changes{'cancreate'}},'notify');
19101: }
19102: } else {
19103: if ($cancreate{'notify'}{'approval'}) {
19104: push(@{$changes{'cancreate'}},'notify');
19105: }
19106: }
19107: } elsif ($cancreate{'notify'}{'approval'}) {
19108: push(@{$changes{'cancreate'}},'notify');
19109: }
19110:
19111: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19112: }
19113: #
1.236 raeburn 19114: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19115: # institutional log-in.
19116: #
19117: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19118: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19119: ($domdefaults{'auth_def'} eq 'localauth'))) {
19120: $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.').' '.
19121: &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.');
19122: }
19123: }
19124: my @fields = ('lastname','firstname','middlename','generation',
19125: 'permanentemail','id');
1.240 raeburn 19126: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19127: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19128: #
19129: # Where usernames may created for institutional log-in and/or institutional single sign on:
19130: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19131: # may self-create accounts
19132: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19133: # which the user may supply, if institutional data is unavailable.
19134: #
19135: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19136: if (@types) {
1.305 raeburn 19137: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19138: push(@contexts,'statustocreate');
1.303 raeburn 19139: foreach my $type (@types) {
1.224 raeburn 19140: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19141: foreach my $field (@fields) {
19142: if (grep(/^\Q$field\E$/,@modifiable)) {
19143: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19144: } else {
19145: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19146: }
19147: }
19148: }
19149: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19150: foreach my $type (@types) {
1.224 raeburn 19151: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19152: foreach my $field (@fields) {
19153: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19154: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19155: push(@{$changes{'selfcreate'}},$type);
19156: last;
19157: }
19158: }
19159: }
19160: }
19161: } else {
1.303 raeburn 19162: foreach my $type (@types) {
1.224 raeburn 19163: push(@{$changes{'selfcreate'}},$type);
19164: }
19165: }
19166: }
1.240 raeburn 19167: foreach my $field (@shibfields) {
19168: if ($env{'form.shibenv_'.$field} ne '') {
19169: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19170: }
19171: }
19172: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19173: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19174: foreach my $field (@shibfields) {
19175: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19176: push(@{$changes{'cancreate'}},'shibenv');
19177: }
19178: }
19179: } else {
19180: foreach my $field (@shibfields) {
19181: if ($env{'form.shibenv_'.$field}) {
19182: push(@{$changes{'cancreate'}},'shibenv');
19183: last;
19184: }
19185: }
19186: }
19187: }
1.224 raeburn 19188: }
19189: foreach my $item (@contexts) {
19190: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19191: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19192: if (ref($cancreate{$item}) eq 'ARRAY') {
19193: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19194: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19195: push(@{$changes{'cancreate'}},$item);
19196: }
19197: }
19198: }
19199: }
19200: if (ref($cancreate{$item}) eq 'ARRAY') {
19201: foreach my $type (@{$cancreate{$item}}) {
19202: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19203: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19204: push(@{$changes{'cancreate'}},$item);
19205: }
19206: }
19207: }
19208: }
19209: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19210: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19211: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19212: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19213: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19214: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19215: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19216: push(@{$changes{'cancreate'}},$item);
19217: }
19218: }
19219: }
1.305 raeburn 19220: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19221: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19222: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19223: push(@{$changes{'cancreate'}},$item);
19224: }
1.224 raeburn 19225: }
19226: }
19227: }
1.305 raeburn 19228: foreach my $type (keys(%{$cancreate{$item}})) {
19229: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19230: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19231: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19232: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19233: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19234: push(@{$changes{'cancreate'}},$item);
19235: }
19236: }
19237: } else {
19238: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19239: push(@{$changes{'cancreate'}},$item);
19240: }
19241: }
19242: }
1.305 raeburn 19243: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19244: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19245: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19246: push(@{$changes{'cancreate'}},$item);
19247: }
1.224 raeburn 19248: }
19249: }
19250: }
19251: }
19252: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19253: if (ref($cancreate{$item}) eq 'ARRAY') {
19254: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19255: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19256: push(@{$changes{'cancreate'}},$item);
19257: }
19258: }
1.305 raeburn 19259: }
19260: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19261: if (ref($cancreate{$item}) eq 'HASH') {
19262: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19263: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19264: }
19265: }
19266: } elsif ($item eq 'emailusername') {
1.228 raeburn 19267: if (ref($cancreate{$item}) eq 'HASH') {
19268: foreach my $type (keys(%{$cancreate{$item}})) {
19269: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19270: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19271: if ($cancreate{$item}{$type}{$field}) {
19272: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19273: push(@{$changes{'cancreate'}},$item);
19274: }
19275: last;
19276: }
19277: }
19278: }
19279: }
1.224 raeburn 19280: }
19281: }
19282: }
19283: #
19284: # Populate %save_usercreate hash with updates to self-creation configuration.
19285: #
19286: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19287: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19288: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19289: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19290: if (ref($cancreate{'notify'}) eq 'HASH') {
19291: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19292: }
1.236 raeburn 19293: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19294: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19295: }
1.303 raeburn 19296: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19297: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19298: }
1.305 raeburn 19299: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19300: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19301: }
1.303 raeburn 19302: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19303: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19304: }
1.224 raeburn 19305: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19306: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19307: }
1.240 raeburn 19308: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19309: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19310: }
1.224 raeburn 19311: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19312: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19313:
19314: my %userconfig_hash = (
19315: usercreation => \%save_usercreate,
19316: usermodification => \%save_usermodify,
1.305 raeburn 19317: inststatus => \%save_inststatus,
1.224 raeburn 19318: );
1.305 raeburn 19319:
1.224 raeburn 19320: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19321: $dom);
19322: #
1.305 raeburn 19323: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19324: #
1.27 raeburn 19325: if ($putresult eq 'ok') {
19326: if (keys(%changes) > 0) {
19327: $resulttext = &mt('Changes made:').'<ul>';
19328: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19329: my %lt = &selfcreation_types();
1.34 raeburn 19330: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19331: my $chgtext = '';
1.45 raeburn 19332: if ($type eq 'selfcreate') {
1.50 raeburn 19333: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19334: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19335: } else {
1.224 raeburn 19336: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19337: '<ul>';
1.50 raeburn 19338: foreach my $case (@{$cancreate{$type}}) {
19339: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19340: }
19341: $chgtext .= '</ul>';
1.100 raeburn 19342: if (ref($cancreate{$type}) eq 'ARRAY') {
19343: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19344: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19345: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19346: $chgtext .= '<span class="LC_warning">'.
19347: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19348: '</span><br />';
19349: }
19350: }
19351: }
19352: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19353: if (!@statuses) {
19354: $chgtext .= '<span class="LC_warning">'.
19355: &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.").
19356: '</span><br />';
1.303 raeburn 19357:
1.100 raeburn 19358: }
19359: }
19360: }
1.43 raeburn 19361: }
1.240 raeburn 19362: } elsif ($type eq 'shibenv') {
19363: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19364: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19365: } else {
19366: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19367: '<ul>';
19368: foreach my $field (@shibfields) {
19369: next if ($cancreate{$type}{$field} eq '');
19370: if ($field eq 'inststatus') {
19371: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19372: } else {
19373: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19374: }
19375: }
19376: $chgtext .= '</ul>';
1.303 raeburn 19377: }
1.93 raeburn 19378: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19379: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19380: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19381: if (@{$cancreate{'selfcreate'}} > 0) {
19382: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19383: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19384: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19385: $chgtext .= '<br />'.
19386: '<span class="LC_warning">'.
19387: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19388: '</span>';
19389: }
1.303 raeburn 19390: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19391: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19392: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19393: } else {
19394: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19395: }
19396: $chgtext .= '<ul>';
19397: foreach my $case (@{$cancreate{$type}}) {
19398: if ($case eq 'default') {
19399: $chgtext .= '<li>'.$othertitle.'</li>';
19400: } else {
1.303 raeburn 19401: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19402: }
19403: }
1.100 raeburn 19404: $chgtext .= '</ul>';
19405: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19406: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19407: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19408: '</span>';
1.100 raeburn 19409: }
19410: }
19411: } else {
19412: if (@{$cancreate{$type}} == 0) {
19413: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19414: } else {
19415: $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 19416: }
19417: }
1.303 raeburn 19418: $chgtext .= '<br />';
1.93 raeburn 19419: }
1.236 raeburn 19420: } elsif ($type eq 'selfcreateprocessing') {
19421: my %choices = &Apache::lonlocal::texthash (
19422: automatic => 'Automatic approval',
19423: approval => 'Queued for approval',
19424: );
1.305 raeburn 19425: if (@types) {
19426: if (@statuses) {
1.425 raeburn 19427: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19428: '<ul>';
1.305 raeburn 19429: foreach my $status (@statuses) {
19430: if ($status eq 'default') {
19431: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19432: } else {
1.305 raeburn 19433: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19434: }
19435: }
19436: $chgtext .= '</ul>';
19437: }
19438: } else {
19439: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19440: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19441: }
19442: } elsif ($type eq 'emailverified') {
19443: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19444: all => 'Same as e-mail',
19445: first => 'Omit @domain',
19446: free => 'Free to choose',
1.303 raeburn 19447: );
1.305 raeburn 19448: if (@types) {
19449: if (@statuses) {
1.303 raeburn 19450: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19451: '<ul>';
1.305 raeburn 19452: foreach my $status (@statuses) {
1.362 raeburn 19453: if ($status eq 'default') {
1.305 raeburn 19454: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19455: } else {
1.305 raeburn 19456: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19457: }
19458: }
19459: $chgtext .= '</ul>';
19460: }
19461: } else {
1.305 raeburn 19462: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19463: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19464: }
1.305 raeburn 19465: } elsif ($type eq 'emailoptions') {
19466: my %options = &Apache::lonlocal::texthash (
19467: any => 'Any e-mail',
19468: inst => 'Institutional only',
19469: noninst => 'Non-institutional only',
19470: custom => 'Custom restrictions',
19471: );
19472: if (@types) {
19473: if (@statuses) {
19474: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19475: '<ul>';
19476: foreach my $status (@statuses) {
19477: if ($type eq 'default') {
19478: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19479: } else {
19480: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19481: }
19482: }
1.305 raeburn 19483: $chgtext .= '</ul>';
19484: }
19485: } else {
19486: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19487: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19488: } else {
19489: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19490: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19491: }
1.305 raeburn 19492: }
19493: } elsif ($type eq 'emaildomain') {
19494: my $output;
19495: if (@statuses) {
19496: foreach my $type (@statuses) {
19497: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19498: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19499: if ($type eq 'default') {
19500: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19501: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19502: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19503: } else {
19504: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19505: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19506: }
1.303 raeburn 19507: } else {
1.305 raeburn 19508: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19509: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19510: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19511: } else {
19512: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19513: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19514: }
1.303 raeburn 19515: }
1.305 raeburn 19516: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19517: if ($type eq 'default') {
19518: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19519: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19520: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19521: } else {
19522: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19523: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19524: }
1.303 raeburn 19525: } else {
1.305 raeburn 19526: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19527: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19528: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19529: } else {
19530: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19531: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19532: }
1.303 raeburn 19533: }
19534: }
19535: }
19536: }
1.305 raeburn 19537: }
19538: if ($output ne '') {
19539: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19540: '<ul>'.$output.'</ul>';
1.236 raeburn 19541: }
1.165 raeburn 19542: } elsif ($type eq 'captcha') {
1.224 raeburn 19543: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19544: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19545: } else {
19546: my %captchas = &captcha_phrases();
1.224 raeburn 19547: if ($captchas{$savecaptcha{$type}}) {
19548: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19549: } else {
1.210 raeburn 19550: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19551: }
19552: }
19553: } elsif ($type eq 'recaptchakeys') {
19554: my ($privkey,$pubkey);
1.224 raeburn 19555: if (ref($savecaptcha{$type}) eq 'HASH') {
19556: $pubkey = $savecaptcha{$type}{'public'};
19557: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19558: }
19559: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19560: if (!$pubkey) {
19561: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19562: } else {
19563: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19564: }
19565: if (!$privkey) {
19566: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19567: } else {
19568: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19569: }
19570: $chgtext .= '</ul>';
1.269 raeburn 19571: } elsif ($type eq 'recaptchaversion') {
19572: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19573: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19574: }
1.224 raeburn 19575: } elsif ($type eq 'emailusername') {
19576: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19577: if (@statuses) {
19578: foreach my $type (@statuses) {
1.228 raeburn 19579: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19580: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19581: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19582: '<ul>';
19583: foreach my $field (@{$infofields}) {
19584: if ($cancreate{'emailusername'}{$type}{$field}) {
19585: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19586: }
19587: }
1.245 raeburn 19588: $chgtext .= '</ul>';
19589: } else {
1.303 raeburn 19590: $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 19591: }
19592: } else {
1.303 raeburn 19593: $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 19594: }
19595: }
19596: }
19597: }
19598: } elsif ($type eq 'notify') {
1.303 raeburn 19599: my $numapprove = 0;
1.224 raeburn 19600: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19601: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19602: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19603: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19604: $numapprove ++;
1.224 raeburn 19605: }
19606: }
1.43 raeburn 19607: }
1.303 raeburn 19608: unless ($numapprove) {
19609: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19610: }
1.34 raeburn 19611: }
1.224 raeburn 19612: if ($chgtext) {
19613: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19614: }
19615: }
19616: }
1.305 raeburn 19617: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19618: my ($emailrules,$emailruleorder) =
19619: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19620: foreach my $type (@{$changes{'email_rule'}}) {
19621: if (ref($email_rule{$type}) eq 'ARRAY') {
19622: my $chgtext = '<ul>';
19623: foreach my $rule (@{$email_rule{$type}}) {
19624: if (ref($emailrules->{$rule}) eq 'HASH') {
19625: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19626: }
19627: }
19628: $chgtext .= '</ul>';
1.310 raeburn 19629: my $typename;
1.305 raeburn 19630: if (@types) {
19631: if ($type eq 'default') {
19632: $typename = $othertitle;
19633: } else {
19634: $typename = $usertypes{$type};
1.425 raeburn 19635: }
1.305 raeburn 19636: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19637: }
19638: if (@{$email_rule{$type}} > 0) {
19639: $resulttext .= '<li>'.
19640: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19641: $usertypes{$type}).
19642: $chgtext.
19643: '</li>';
19644: } else {
19645: $resulttext .= '<li>'.
1.310 raeburn 19646: &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 19647: '</li>'.
1.310 raeburn 19648: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19649: }
1.43 raeburn 19650: }
19651: }
1.305 raeburn 19652: }
19653: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19654: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19655: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19656: my $chgtext = '<ul>';
19657: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19658: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19659: }
19660: $chgtext .= '</ul>';
19661: $resulttext .= '<li>'.
19662: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19663: $chgtext.
19664: '</li>';
19665: } else {
19666: $resulttext .= '<li>'.
19667: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19668: '</li>';
19669: }
1.43 raeburn 19670: }
19671: }
1.224 raeburn 19672: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19673: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19674: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19675: foreach my $type (@{$changes{'selfcreate'}}) {
19676: my $typename = $type;
1.303 raeburn 19677: if (keys(%usertypes) > 0) {
19678: if ($usertypes{$type} ne '') {
19679: $typename = $usertypes{$type};
1.224 raeburn 19680: }
19681: }
19682: my @modifiable;
19683: $resulttext .= '<li>'.
19684: &mt('Self-creation of account by users with status: [_1]',
19685: '<span class="LC_cusr_emph">'.$typename.'</span>').
19686: ' - '.&mt('modifiable fields (if institutional data blank): ');
19687: foreach my $field (@fields) {
19688: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19689: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19690: }
19691: }
1.224 raeburn 19692: if (@modifiable > 0) {
19693: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19694: } else {
1.224 raeburn 19695: $resulttext .= &mt('none');
1.43 raeburn 19696: }
1.224 raeburn 19697: $resulttext .= '</li>';
1.28 raeburn 19698: }
1.224 raeburn 19699: $resulttext .= '</ul></li>';
1.28 raeburn 19700: }
1.27 raeburn 19701: $resulttext .= '</ul>';
1.305 raeburn 19702: my $cachetime = 24*60*60;
19703: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19704: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19705: if (ref($lastactref) eq 'HASH') {
19706: $lastactref->{'domdefaults'} = 1;
19707: }
1.27 raeburn 19708: } else {
1.224 raeburn 19709: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19710: }
19711: } else {
19712: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19713: &mt('An error occurred: [_1]',$putresult).'</span>';
19714: }
1.43 raeburn 19715: if ($warningmsg ne '') {
19716: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19717: }
1.23 raeburn 19718: return $resulttext;
19719: }
19720:
1.165 raeburn 19721: sub process_captcha {
1.369 raeburn 19722: my ($container,$changes,$newsettings,$currsettings) = @_;
19723: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19724: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19725: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19726: $newsettings->{'captcha'} = 'original';
19727: }
1.369 raeburn 19728: my %current;
19729: if (ref($currsettings) eq 'HASH') {
19730: %current = %{$currsettings};
19731: }
19732: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19733: if ($container eq 'cancreate') {
1.169 raeburn 19734: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19735: push(@{$changes->{'cancreate'}},'captcha');
19736: } elsif (!defined($changes->{'cancreate'})) {
19737: $changes->{'cancreate'} = ['captcha'];
19738: }
1.368 raeburn 19739: } elsif ($container eq 'passwords') {
19740: $changes->{'reset'} = 1;
1.169 raeburn 19741: } else {
19742: $changes->{'captcha'} = 1;
1.165 raeburn 19743: }
19744: }
1.269 raeburn 19745: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19746: if ($newsettings->{'captcha'} eq 'recaptcha') {
19747: $newpub = $env{'form.'.$container.'_recaptchapub'};
19748: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19749: $newpub =~ s/[^\w\-]//g;
19750: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19751: $newsettings->{'recaptchakeys'} = {
19752: public => $newpub,
19753: private => $newpriv,
19754: };
1.269 raeburn 19755: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19756: $newversion =~ s/\D//g;
19757: if ($newversion ne '2') {
19758: $newversion = 1;
19759: }
19760: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19761: }
1.369 raeburn 19762: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19763: $currpub = $current{'recaptchakeys'}{'public'};
19764: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19765: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19766: $newsettings->{'recaptchakeys'} = {
19767: public => '',
19768: private => '',
19769: }
19770: }
1.165 raeburn 19771: }
1.369 raeburn 19772: if ($current{'captcha'} eq 'recaptcha') {
19773: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19774: if ($currversion ne '2') {
19775: $currversion = 1;
19776: }
19777: }
19778: if ($currversion ne $newversion) {
19779: if ($container eq 'cancreate') {
19780: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19781: push(@{$changes->{'cancreate'}},'recaptchaversion');
19782: } elsif (!defined($changes->{'cancreate'})) {
19783: $changes->{'cancreate'} = ['recaptchaversion'];
19784: }
1.368 raeburn 19785: } elsif ($container eq 'passwords') {
19786: $changes->{'reset'} = 1;
1.269 raeburn 19787: } else {
19788: $changes->{'recaptchaversion'} = 1;
19789: }
19790: }
1.165 raeburn 19791: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19792: if ($container eq 'cancreate') {
19793: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19794: push(@{$changes->{'cancreate'}},'recaptchakeys');
19795: } elsif (!defined($changes->{'cancreate'})) {
19796: $changes->{'cancreate'} = ['recaptchakeys'];
19797: }
1.368 raeburn 19798: } elsif ($container eq 'passwords') {
19799: $changes->{'reset'} = 1;
1.169 raeburn 19800: } else {
1.210 raeburn 19801: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19802: }
19803: }
19804: return;
19805: }
19806:
1.33 raeburn 19807: sub modify_usermodification {
19808: my ($dom,%domconfig) = @_;
1.224 raeburn 19809: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19810: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19811: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19812: if ($key eq 'selfcreate') {
19813: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19814: } else {
19815: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19816: }
1.33 raeburn 19817: }
19818: }
1.224 raeburn 19819: my @contexts = ('author','course');
1.33 raeburn 19820: my %context_title = (
19821: author => 'In author context',
19822: course => 'In course context',
19823: );
19824: my @fields = ('lastname','firstname','middlename','generation',
19825: 'permanentemail','id');
19826: my %roles = (
19827: author => ['ca','aa'],
19828: course => ['st','ep','ta','in','cr'],
19829: );
19830: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19831: foreach my $context (@contexts) {
19832: foreach my $role (@{$roles{$context}}) {
19833: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
19834: foreach my $item (@fields) {
19835: if (grep(/^\Q$item\E$/,@modifiable)) {
19836: $modifyhash{$context}{$role}{$item} = 1;
19837: } else {
19838: $modifyhash{$context}{$role}{$item} = 0;
19839: }
19840: }
19841: }
19842: if (ref($curr_usermodification{$context}) eq 'HASH') {
19843: foreach my $role (@{$roles{$context}}) {
19844: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19845: foreach my $field (@fields) {
19846: if ($modifyhash{$context}{$role}{$field} ne
19847: $curr_usermodification{$context}{$role}{$field}) {
19848: push(@{$changes{$context}},$role);
19849: last;
19850: }
19851: }
19852: }
19853: }
19854: } else {
19855: foreach my $context (@contexts) {
19856: foreach my $role (@{$roles{$context}}) {
19857: push(@{$changes{$context}},$role);
19858: }
19859: }
19860: }
19861: }
19862: my %usermodification_hash = (
19863: usermodification => \%modifyhash,
19864: );
19865: my $putresult = &Apache::lonnet::put_dom('configuration',
19866: \%usermodification_hash,$dom);
19867: if ($putresult eq 'ok') {
19868: if (keys(%changes) > 0) {
19869: $resulttext = &mt('Changes made: ').'<ul>';
19870: foreach my $context (@contexts) {
19871: if (ref($changes{$context}) eq 'ARRAY') {
19872: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19873: if (ref($changes{$context}) eq 'ARRAY') {
19874: foreach my $role (@{$changes{$context}}) {
19875: my $rolename;
1.224 raeburn 19876: if ($role eq 'cr') {
19877: $rolename = &mt('Custom');
1.33 raeburn 19878: } else {
1.224 raeburn 19879: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19880: }
19881: my @modifiable;
1.224 raeburn 19882: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19883: foreach my $field (@fields) {
19884: if ($modifyhash{$context}{$role}{$field}) {
19885: push(@modifiable,$fieldtitles{$field});
19886: }
19887: }
19888: if (@modifiable > 0) {
19889: $resulttext .= join(', ',@modifiable);
19890: } else {
19891: $resulttext .= &mt('none');
19892: }
19893: $resulttext .= '</li>';
19894: }
19895: $resulttext .= '</ul></li>';
19896: }
19897: }
19898: }
19899: $resulttext .= '</ul>';
19900: } else {
19901: $resulttext = &mt('No changes made to user modification settings');
19902: }
19903: } else {
19904: $resulttext = '<span class="LC_error">'.
19905: &mt('An error occurred: [_1]',$putresult).'</span>';
19906: }
19907: return $resulttext;
19908: }
19909:
1.43 raeburn 19910: sub modify_defaults {
1.212 raeburn 19911: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19912: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19913: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19914: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19915: 'portal_def');
1.325 raeburn 19916: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19917: foreach my $item (@items) {
19918: $newvalues{$item} = $env{'form.'.$item};
19919: if ($item eq 'auth_def') {
19920: if ($newvalues{$item} ne '') {
19921: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
19922: push(@errors,$item);
19923: }
19924: }
19925: } elsif ($item eq 'lang_def') {
19926: if ($newvalues{$item} ne '') {
19927: if ($newvalues{$item} =~ /^(\w+)/) {
19928: my $langcode = $1;
1.103 raeburn 19929: if ($langcode ne 'x_chef') {
19930: if (code2language($langcode) eq '') {
19931: push(@errors,$item);
19932: }
1.43 raeburn 19933: }
19934: } else {
19935: push(@errors,$item);
19936: }
19937: }
1.54 raeburn 19938: } elsif ($item eq 'timezone_def') {
19939: if ($newvalues{$item} ne '') {
1.62 raeburn 19940: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 19941: push(@errors,$item);
19942: }
19943: }
1.68 raeburn 19944: } elsif ($item eq 'datelocale_def') {
19945: if ($newvalues{$item} ne '') {
19946: my @datelocale_ids = DateTime::Locale->ids();
19947: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
19948: push(@errors,$item);
19949: }
19950: }
1.141 raeburn 19951: } elsif ($item eq 'portal_def') {
19952: if ($newvalues{$item} ne '') {
1.414 raeburn 19953: 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])\/?$/) {
19954: foreach my $field ('email','web') {
19955: if ($env{'form.'.$item.'_'.$field}) {
19956: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
19957: }
19958: }
19959: } else {
1.141 raeburn 19960: push(@errors,$item);
19961: }
19962: }
1.43 raeburn 19963: }
19964: if (grep(/^\Q$item\E$/,@errors)) {
19965: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 19966: if ($item eq 'portal_def') {
19967: if ($domdefaults{$item}) {
19968: foreach my $field ('email','web') {
19969: if (exists($domdefaults{$item.'_'.$field})) {
19970: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
19971: }
19972: }
19973: }
19974: }
1.43 raeburn 19975: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
19976: $changes{$item} = 1;
19977: }
1.414 raeburn 19978: if ($item eq 'portal_def') {
19979: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 19980: if ($newvalues{$item} eq '') {
1.414 raeburn 19981: foreach my $field ('email','web') {
19982: if (exists($domdefaults{$item.'_'.$field})) {
19983: delete($domdefaults{$item.'_'.$field});
19984: }
19985: }
19986: } else {
19987: unless ($changes{$item}) {
19988: foreach my $field ('email','web') {
19989: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
19990: $changes{$item} = 1;
19991: last;
19992: }
19993: }
19994: }
19995: foreach my $field ('email','web') {
19996: if ($newvalues{$item.'_'.$field}) {
19997: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
19998: } elsif (exists($domdefaults{$item.'_'.$field})) {
19999: delete($domdefaults{$item.'_'.$field});
20000: }
20001: }
20002: }
20003: }
20004: }
1.72 raeburn 20005: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20006: }
1.354 raeburn 20007: my %staticdefaults = (
20008: 'intauth_cost' => 10,
20009: 'intauth_check' => 0,
20010: 'intauth_switch' => 0,
20011: );
20012: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20013: if (exists($domdefaults{$item})) {
20014: $newvalues{$item} = $domdefaults{$item};
20015: } else {
20016: $newvalues{$item} = $staticdefaults{$item};
20017: }
20018: }
1.409 raeburn 20019: my ($unamemaprules,$ruleorder);
20020: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20021: if (@possunamemaprules) {
20022: ($unamemaprules,$ruleorder) =
20023: &Apache::lonnet::inst_userrules($dom,'unamemap');
20024: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20025: if (@{$ruleorder} > 0) {
20026: my %possrules;
20027: map { $possrules{$_} = 1; } @possunamemaprules;
20028: foreach my $rule (@{$ruleorder}) {
20029: if ($possrules{$rule}) {
20030: push(@{$newvalues{'unamemap_rule'}},$rule);
20031: }
20032: }
20033: }
20034: }
20035: }
20036: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20037: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20038: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20039: $newvalues{'unamemap_rule'});
20040: if (@rulediffs) {
20041: $changes{'unamemap_rule'} = 1;
20042: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20043: }
20044: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20045: $changes{'unamemap_rule'} = 1;
20046: delete($domdefaults{'unamemap_rule'});
20047: }
20048: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20049: if (@{$newvalues{'unamemap_rule'}} > 0) {
20050: $changes{'unamemap_rule'} = 1;
20051: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20052: }
20053: }
1.43 raeburn 20054: my %defaults_hash = (
1.72 raeburn 20055: defaults => \%newvalues,
20056: );
1.43 raeburn 20057: my $title = &defaults_titles();
1.236 raeburn 20058:
20059: my $currinststatus;
20060: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20061: $currinststatus = $domconfig{'inststatus'};
20062: } else {
20063: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20064: $currinststatus = {
20065: inststatustypes => $usertypes,
20066: inststatusorder => $types,
20067: inststatusguest => [],
20068: };
20069: }
20070: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20071: my @allpos;
20072: my %alltypes;
1.305 raeburn 20073: my @inststatusguest;
20074: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20075: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20076: unless (grep(/^\Q$type\E$/,@todelete)) {
20077: push(@inststatusguest,$type);
20078: }
20079: }
20080: }
20081: my ($currtitles,$currorder);
1.236 raeburn 20082: if (ref($currinststatus) eq 'HASH') {
20083: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20084: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20085: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20086: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20087: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20088: }
20089: }
20090: unless (grep(/^\Q$type\E$/,@todelete)) {
20091: my $position = $env{'form.inststatus_pos_'.$type};
20092: $position =~ s/\D+//g;
20093: $allpos[$position] = $type;
20094: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20095: $alltypes{$type} =~ s/`//g;
20096: }
20097: }
20098: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20099: $currtitles =~ s/,$//;
20100: }
20101: }
20102: if ($env{'form.addinststatus'}) {
20103: my $newtype = $env{'form.addinststatus'};
20104: $newtype =~ s/\W//g;
20105: unless (exists($alltypes{$newtype})) {
20106: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20107: $alltypes{$newtype} =~ s/`//g;
20108: my $position = $env{'form.addinststatus_pos'};
20109: $position =~ s/\D+//g;
20110: if ($position ne '') {
20111: $allpos[$position] = $newtype;
20112: }
20113: }
20114: }
1.305 raeburn 20115: my @orderedstatus;
1.236 raeburn 20116: foreach my $type (@allpos) {
20117: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20118: push(@orderedstatus,$type);
20119: }
20120: }
20121: foreach my $type (keys(%alltypes)) {
20122: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20123: delete($alltypes{$type});
20124: }
20125: }
20126: $defaults_hash{'inststatus'} = {
20127: inststatustypes => \%alltypes,
20128: inststatusorder => \@orderedstatus,
1.305 raeburn 20129: inststatusguest => \@inststatusguest,
1.236 raeburn 20130: };
20131: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20132: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20133: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20134: }
20135: }
20136: if ($currorder ne join(',',@orderedstatus)) {
20137: $changes{'inststatus'}{'inststatusorder'} = 1;
20138: }
20139: my $newtitles;
20140: foreach my $item (@orderedstatus) {
20141: $newtitles .= $alltypes{$item}.',';
20142: }
20143: $newtitles =~ s/,$//;
20144: if ($currtitles ne $newtitles) {
20145: $changes{'inststatus'}{'inststatustypes'} = 1;
20146: }
1.43 raeburn 20147: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20148: $dom);
20149: if ($putresult eq 'ok') {
20150: if (keys(%changes) > 0) {
20151: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20152: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20153: 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";
20154: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20155: if ($item eq 'inststatus') {
20156: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20157: if (@orderedstatus) {
1.236 raeburn 20158: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20159: foreach my $type (@orderedstatus) {
20160: $resulttext .= $alltypes{$type}.', ';
20161: }
20162: $resulttext =~ s/, $//;
20163: $resulttext .= '</li>';
1.305 raeburn 20164: } else {
1.425 raeburn 20165: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20166: }
20167: }
1.409 raeburn 20168: } elsif ($item eq 'unamemap_rule') {
20169: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20170: my @rulenames;
20171: if (ref($unamemaprules) eq 'HASH') {
20172: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20173: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20174: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20175: }
20176: }
20177: }
20178: if (@rulenames) {
20179: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20180: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20181: '</li>';
20182: } else {
20183: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20184: }
20185: } else {
20186: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20187: }
1.236 raeburn 20188: } else {
20189: my $value = $env{'form.'.$item};
20190: if ($value eq '') {
20191: $value = &mt('none');
20192: } elsif ($item eq 'auth_def') {
20193: my %authnames = &authtype_names();
20194: my %shortauth = (
20195: internal => 'int',
20196: krb4 => 'krb4',
20197: krb5 => 'krb5',
20198: localauth => 'loc',
1.325 raeburn 20199: lti => 'lti',
1.236 raeburn 20200: );
20201: $value = $authnames{$shortauth{$value}};
20202: }
20203: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20204: $mailmsgtext .= "$title->{$item} set to $value\n";
20205: if ($item eq 'portal_def') {
20206: if ($env{'form.'.$item} ne '') {
20207: foreach my $field ('email','web') {
20208: $value = $env{'form.'.$item.'_'.$field};
20209: if ($value) {
20210: $value = &mt('Yes');
20211: } else {
20212: $value = &mt('No');
20213: }
20214: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20215: }
20216: }
20217: }
1.43 raeburn 20218: }
20219: }
20220: $resulttext .= '</ul>';
20221: $mailmsgtext .= "\n";
20222: my $cachetime = 24*60*60;
1.72 raeburn 20223: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20224: if (ref($lastactref) eq 'HASH') {
20225: $lastactref->{'domdefaults'} = 1;
20226: }
1.68 raeburn 20227: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20228: my $notify = 1;
20229: if (ref($domconfig{'contacts'}) eq 'HASH') {
20230: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20231: $notify = 0;
20232: }
20233: }
20234: if ($notify) {
20235: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20236: "LON-CAPA Domain Settings Change - $dom",
20237: $mailmsgtext);
20238: }
1.54 raeburn 20239: }
1.43 raeburn 20240: } else {
1.54 raeburn 20241: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20242: }
20243: } else {
20244: $resulttext = '<span class="LC_error">'.
20245: &mt('An error occurred: [_1]',$putresult).'</span>';
20246: }
20247: if (@errors > 0) {
20248: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20249: foreach my $item (@errors) {
20250: $resulttext .= ' "'.$title->{$item}.'",';
20251: }
20252: $resulttext =~ s/,$//;
20253: }
20254: return $resulttext;
20255: }
20256:
1.46 raeburn 20257: sub modify_scantron {
1.205 raeburn 20258: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20259: my ($resulttext,%confhash,%changes,$errors);
20260: my $custom = 'custom.tab';
20261: my $default = 'default.tab';
20262: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20263: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20264: &config_check($dom,$confname,$servadm);
20265: if ($env{'form.scantronformat.filename'} ne '') {
20266: my $error;
20267: if ($configuserok eq 'ok') {
20268: if ($switchserver) {
1.130 raeburn 20269: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20270: } else {
20271: if ($author_ok eq 'ok') {
1.421 raeburn 20272: my $modified = [];
1.46 raeburn 20273: my ($result,$scantronurl) =
1.421 raeburn 20274: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20275: $confname,'scantron','','',$custom,
20276: $modified);
1.46 raeburn 20277: if ($result eq 'ok') {
20278: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20279: $changes{'scantronformat'} = 1;
1.421 raeburn 20280: &update_modify_urls($r,$modified);
1.46 raeburn 20281: } else {
20282: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20283: }
20284: } else {
20285: $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);
20286: }
20287: }
20288: } else {
20289: $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);
20290: }
20291: if ($error) {
20292: &Apache::lonnet::logthis($error);
20293: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20294: }
20295: }
1.48 raeburn 20296: if (ref($domconfig{'scantron'}) eq 'HASH') {
20297: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20298: if ($env{'form.scantronformat_del'}) {
20299: $confhash{'scantron'}{'scantronformat'} = '';
20300: $changes{'scantronformat'} = 1;
1.347 raeburn 20301: } else {
20302: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20303: }
20304: }
20305: }
1.347 raeburn 20306: my @options = ('hdr','pad','rem');
1.346 raeburn 20307: my @fields = &scantroncsv_fields();
20308: my %titles = &scantronconfig_titles();
1.347 raeburn 20309: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20310: my ($newdat,$currdat,%newcol,%currcol);
20311: if (grep(/^dat$/,@formats)) {
20312: $confhash{'scantron'}{config}{dat} = 1;
20313: $newdat = 1;
20314: } else {
20315: $newdat = 0;
20316: }
20317: if (grep(/^csv$/,@formats)) {
20318: my %bynum;
20319: foreach my $field (@fields) {
20320: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20321: my $posscol = $1;
20322: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20323: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20324: $bynum{$posscol} = $field;
20325: $newcol{$field} = $posscol;
20326: }
20327: }
20328: }
1.347 raeburn 20329: if (keys(%newcol)) {
20330: foreach my $option (@options) {
20331: if ($env{'form.scantroncsv_'.$option}) {
20332: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20333: }
20334: }
20335: }
1.346 raeburn 20336: }
20337: $currdat = 1;
20338: if (ref($domconfig{'scantron'}) eq 'HASH') {
20339: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20340: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20341: $currdat = 0;
20342: }
20343: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20344: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20345: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20346: }
1.346 raeburn 20347: }
20348: }
20349: }
20350: if ($currdat != $newdat) {
20351: $changes{'config'} = 1;
20352: } else {
20353: foreach my $field (@fields) {
20354: if ($currcol{$field} ne '') {
20355: if ($currcol{$field} ne $newcol{$field}) {
20356: $changes{'config'} = 1;
20357: last;
1.347 raeburn 20358: }
1.346 raeburn 20359: } elsif ($newcol{$field} ne '') {
20360: $changes{'config'} = 1;
20361: last;
20362: }
20363: }
20364: }
1.46 raeburn 20365: if (keys(%confhash) > 0) {
20366: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20367: $dom);
20368: if ($putresult eq 'ok') {
20369: if (keys(%changes) > 0) {
1.48 raeburn 20370: if (ref($confhash{'scantron'}) eq 'HASH') {
20371: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20372: if ($changes{'scantronformat'}) {
20373: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20374: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20375: } else {
20376: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20377: }
20378: }
1.347 raeburn 20379: if ($changes{'config'}) {
1.346 raeburn 20380: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20381: if ($confhash{'scantron'}{'config'}{'dat'}) {
20382: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20383: }
20384: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20385: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20386: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20387: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20388: foreach my $field (@fields) {
20389: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20390: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20391: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20392: }
20393: }
20394: $resulttext .= '</ul></li>';
20395: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20396: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20397: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20398: foreach my $option (@options) {
20399: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20400: $resulttext .= '<li>'.$titles{$option}.'</li>';
20401: }
20402: }
20403: $resulttext .= '</ul></li>';
20404: }
1.346 raeburn 20405: }
20406: }
20407: }
20408: }
20409: } else {
20410: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20411: }
1.46 raeburn 20412: }
1.48 raeburn 20413: $resulttext .= '</ul>';
20414: } else {
1.130 raeburn 20415: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20416: }
20417: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20418: if (ref($lastactref) eq 'HASH') {
20419: $lastactref->{'domainconfig'} = 1;
20420: }
1.46 raeburn 20421: } else {
1.346 raeburn 20422: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20423: }
20424: } else {
20425: $resulttext = '<span class="LC_error">'.
20426: &mt('An error occurred: [_1]',$putresult).'</span>';
20427: }
20428: } else {
1.130 raeburn 20429: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20430: }
20431: if ($errors) {
1.353 raeburn 20432: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20433: $errors.'</ul></p>';
1.46 raeburn 20434: }
20435: return $resulttext;
20436: }
20437:
1.48 raeburn 20438: sub modify_coursecategories {
1.239 raeburn 20439: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20440: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20441: $cathash);
1.48 raeburn 20442: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20443: my @catitems = ('unauth','auth');
20444: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20445: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20446: $cathash = $domconfig{'coursecategories'}{'cats'};
20447: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20448: $changes{'togglecats'} = 1;
20449: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20450: }
20451: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20452: $changes{'categorize'} = 1;
20453: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20454: }
1.120 raeburn 20455: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20456: $changes{'togglecatscomm'} = 1;
20457: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20458: }
20459: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20460: $changes{'categorizecomm'} = 1;
20461: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20462:
20463: }
20464: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20465: $changes{'togglecatsplace'} = 1;
20466: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20467: }
20468: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20469: $changes{'categorizeplace'} = 1;
20470: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20471: }
1.238 raeburn 20472: foreach my $item (@catitems) {
20473: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20474: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20475: $changes{$item} = 1;
20476: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20477: }
20478: }
20479: }
1.57 raeburn 20480: } else {
20481: $changes{'togglecats'} = 1;
20482: $changes{'categorize'} = 1;
1.124 raeburn 20483: $changes{'togglecatscomm'} = 1;
20484: $changes{'categorizecomm'} = 1;
1.272 raeburn 20485: $changes{'togglecatsplace'} = 1;
20486: $changes{'categorizeplace'} = 1;
1.87 raeburn 20487: $domconfig{'coursecategories'} = {
20488: togglecats => $env{'form.togglecats'},
20489: categorize => $env{'form.categorize'},
1.124 raeburn 20490: togglecatscomm => $env{'form.togglecatscomm'},
20491: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20492: togglecatsplace => $env{'form.togglecatsplace'},
20493: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20494: };
1.238 raeburn 20495: foreach my $item (@catitems) {
20496: if ($env{'form.coursecat_'.$item} ne 'std') {
20497: $changes{$item} = 1;
20498: }
20499: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20500: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20501: }
20502: }
1.57 raeburn 20503: }
20504: if (ref($cathash) eq 'HASH') {
20505: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20506: push (@deletecategory,'instcode::0');
20507: }
1.120 raeburn 20508: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20509: push(@deletecategory,'communities::0');
20510: }
1.272 raeburn 20511: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20512: push(@deletecategory,'placement::0');
20513: }
1.48 raeburn 20514: }
1.57 raeburn 20515: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20516: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20517: if (@deletecategory > 0) {
20518: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20519: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20520: foreach my $item (@deletecategory) {
1.57 raeburn 20521: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20522: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20523: $deletions{$item} = 1;
1.57 raeburn 20524: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20525: }
20526: }
20527: }
1.57 raeburn 20528: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20529: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20530: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20531: $reorderings{$item} = 1;
1.57 raeburn 20532: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20533: }
20534: if ($env{'form.addcategory_name_'.$item} ne '') {
20535: my $newcat = $env{'form.addcategory_name_'.$item};
20536: my $newdepth = $depth+1;
20537: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20538: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20539: $adds{$newitem} = 1;
20540: }
20541: if ($env{'form.subcat_'.$item} ne '') {
20542: my $newcat = $env{'form.subcat_'.$item};
20543: my $newdepth = $depth+1;
20544: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20545: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20546: $adds{$newitem} = 1;
20547: }
20548: }
20549: }
20550: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20551: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20552: my $newitem = 'instcode::0';
1.57 raeburn 20553: if ($cathash->{$newitem} eq '') {
20554: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20555: $adds{$newitem} = 1;
20556: }
20557: } else {
20558: my $newitem = 'instcode::0';
1.57 raeburn 20559: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20560: $adds{$newitem} = 1;
20561: }
20562: }
1.120 raeburn 20563: if ($env{'form.communities'} eq '1') {
20564: if (ref($cathash) eq 'HASH') {
20565: my $newitem = 'communities::0';
20566: if ($cathash->{$newitem} eq '') {
20567: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20568: $adds{$newitem} = 1;
20569: }
20570: } else {
20571: my $newitem = 'communities::0';
20572: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20573: $adds{$newitem} = 1;
20574: }
20575: }
1.272 raeburn 20576: if ($env{'form.placement'} eq '1') {
20577: if (ref($cathash) eq 'HASH') {
20578: my $newitem = 'placement::0';
20579: if ($cathash->{$newitem} eq '') {
20580: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20581: $adds{$newitem} = 1;
20582: }
20583: } else {
20584: my $newitem = 'placement::0';
20585: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20586: $adds{$newitem} = 1;
20587: }
20588: }
1.48 raeburn 20589: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20590: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20591: ($env{'form.addcategory_name'} ne 'communities') &&
20592: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20593: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20594: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20595: $adds{$newitem} = 1;
20596: }
1.48 raeburn 20597: }
1.57 raeburn 20598: my $putresult;
1.48 raeburn 20599: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20600: if (keys(%deletions) > 0) {
20601: foreach my $key (keys(%deletions)) {
20602: if ($predelallitems{$key} ne '') {
20603: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20604: }
20605: }
20606: }
20607: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20608: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20609: if (ref($chkcats[0]) eq 'ARRAY') {
20610: my $depth = 0;
20611: my $chg = 0;
20612: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20613: my $name = $chkcats[0][$i];
20614: my $item;
20615: if ($name eq '') {
20616: $chg ++;
20617: } else {
20618: $item = &escape($name).'::0';
20619: if ($chg) {
1.57 raeburn 20620: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20621: }
20622: $depth ++;
1.57 raeburn 20623: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20624: $depth --;
20625: }
20626: }
20627: }
1.57 raeburn 20628: }
20629: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20630: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20631: if ($putresult eq 'ok') {
1.57 raeburn 20632: my %title = (
1.120 raeburn 20633: togglecats => 'Show/Hide a course in catalog',
20634: categorize => 'Assign a category to a course',
20635: togglecatscomm => 'Show/Hide a community in catalog',
20636: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20637: );
20638: my %level = (
1.120 raeburn 20639: dom => 'set in Domain ("Modify Course/Community")',
20640: crs => 'set in Course ("Course Configuration")',
20641: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20642: none => 'No catalog',
20643: std => 'Standard catalog',
20644: domonly => 'Domain-only catalog',
20645: codesrch => 'Code search form',
1.57 raeburn 20646: );
1.48 raeburn 20647: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20648: if ($changes{'togglecats'}) {
20649: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20650: }
20651: if ($changes{'categorize'}) {
20652: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20653: }
1.120 raeburn 20654: if ($changes{'togglecatscomm'}) {
20655: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20656: }
20657: if ($changes{'categorizecomm'}) {
20658: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20659: }
1.238 raeburn 20660: if ($changes{'unauth'}) {
20661: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20662: }
20663: if ($changes{'auth'}) {
20664: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20665: }
1.57 raeburn 20666: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20667: my $cathash;
20668: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20669: $cathash = $domconfig{'coursecategories'}{'cats'};
20670: } else {
20671: $cathash = {};
20672: }
20673: my (@cats,@trails,%allitems);
20674: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20675: if (keys(%deletions) > 0) {
20676: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20677: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20678: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20679: }
20680: $resulttext .= '</ul></li>';
20681: }
20682: if (keys(%reorderings) > 0) {
20683: my %sort_by_trail;
20684: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20685: foreach my $key (keys(%reorderings)) {
20686: if ($allitems{$key} ne '') {
20687: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20688: }
1.48 raeburn 20689: }
1.57 raeburn 20690: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20691: $resulttext .= '<li>'.$trails[$trail].'</li>';
20692: }
20693: $resulttext .= '</ul></li>';
1.48 raeburn 20694: }
1.57 raeburn 20695: if (keys(%adds) > 0) {
20696: my %sort_by_trail;
20697: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20698: foreach my $key (keys(%adds)) {
20699: if ($allitems{$key} ne '') {
20700: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20701: }
20702: }
20703: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20704: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20705: }
1.57 raeburn 20706: $resulttext .= '</ul></li>';
1.48 raeburn 20707: }
1.364 raeburn 20708: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20709: if (ref($lastactref) eq 'HASH') {
20710: $lastactref->{'cats'} = 1;
20711: }
1.48 raeburn 20712: }
20713: $resulttext .= '</ul>';
1.239 raeburn 20714: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20715: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20716: if ($changes{'auth'}) {
20717: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20718: }
20719: if ($changes{'unauth'}) {
20720: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20721: }
20722: my $cachetime = 24*60*60;
20723: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20724: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20725: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20726: }
20727: }
1.48 raeburn 20728: } else {
20729: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20730: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20731: }
20732: } else {
1.120 raeburn 20733: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20734: }
20735: return $resulttext;
20736: }
20737:
1.69 raeburn 20738: sub modify_serverstatuses {
20739: my ($dom,%domconfig) = @_;
20740: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20741: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20742: %currserverstatus = %{$domconfig{'serverstatuses'}};
20743: }
20744: my @pages = &serverstatus_pages();
20745: foreach my $type (@pages) {
20746: $newserverstatus{$type}{'namedusers'} = '';
20747: $newserverstatus{$type}{'machines'} = '';
20748: if (defined($env{'form.'.$type.'_namedusers'})) {
20749: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20750: my @okusers;
20751: foreach my $user (@users) {
20752: my ($uname,$udom) = split(/:/,$user);
20753: if (($udom =~ /^$match_domain$/) &&
20754: (&Apache::lonnet::domain($udom)) &&
20755: ($uname =~ /^$match_username$/)) {
20756: if (!grep(/^\Q$user\E/,@okusers)) {
20757: push(@okusers,$user);
20758: }
20759: }
20760: }
20761: if (@okusers > 0) {
20762: @okusers = sort(@okusers);
20763: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20764: }
20765: }
20766: if (defined($env{'form.'.$type.'_machines'})) {
20767: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20768: my @okmachines;
20769: foreach my $ip (@machines) {
20770: my @parts = split(/\./,$ip);
20771: next if (@parts < 4);
20772: my $badip = 0;
20773: for (my $i=0; $i<4; $i++) {
20774: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20775: $badip = 1;
20776: last;
20777: }
20778: }
20779: if (!$badip) {
20780: push(@okmachines,$ip);
20781: }
20782: }
20783: @okmachines = sort(@okmachines);
20784: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20785: }
20786: }
20787: my %serverstatushash = (
20788: serverstatuses => \%newserverstatus,
20789: );
20790: foreach my $type (@pages) {
1.83 raeburn 20791: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20792: my (@current,@new);
1.83 raeburn 20793: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20794: if ($currserverstatus{$type}{$setting} ne '') {
20795: @current = split(/,/,$currserverstatus{$type}{$setting});
20796: }
20797: }
20798: if ($newserverstatus{$type}{$setting} ne '') {
20799: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20800: }
20801: if (@current > 0) {
20802: if (@new > 0) {
20803: foreach my $item (@current) {
20804: if (!grep(/^\Q$item\E$/,@new)) {
20805: $changes{$type}{$setting} = 1;
1.82 raeburn 20806: last;
20807: }
20808: }
1.84 raeburn 20809: foreach my $item (@new) {
20810: if (!grep(/^\Q$item\E$/,@current)) {
20811: $changes{$type}{$setting} = 1;
20812: last;
1.82 raeburn 20813: }
20814: }
20815: } else {
1.83 raeburn 20816: $changes{$type}{$setting} = 1;
1.69 raeburn 20817: }
1.83 raeburn 20818: } elsif (@new > 0) {
20819: $changes{$type}{$setting} = 1;
1.69 raeburn 20820: }
20821: }
20822: }
20823: if (keys(%changes) > 0) {
1.81 raeburn 20824: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20825: my $putresult = &Apache::lonnet::put_dom('configuration',
20826: \%serverstatushash,$dom);
20827: if ($putresult eq 'ok') {
20828: $resulttext .= &mt('Changes made:').'<ul>';
20829: foreach my $type (@pages) {
1.84 raeburn 20830: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20831: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20832: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20833: if ($newserverstatus{$type}{'namedusers'} eq '') {
20834: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20835: } else {
20836: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20837: }
1.84 raeburn 20838: }
20839: if ($changes{$type}{'machines'}) {
1.69 raeburn 20840: if ($newserverstatus{$type}{'machines'} eq '') {
20841: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20842: } else {
20843: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20844: }
20845:
20846: }
20847: $resulttext .= '</ul></li>';
20848: }
20849: }
20850: $resulttext .= '</ul>';
20851: } else {
20852: $resulttext = '<span class="LC_error">'.
20853: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20854:
20855: }
20856: } else {
20857: $resulttext = &mt('No changes made to access to server status pages');
20858: }
20859: return $resulttext;
20860: }
20861:
1.118 jms 20862: sub modify_helpsettings {
1.285 raeburn 20863: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20864: my ($resulttext,$errors,%changes,%helphash);
20865: my %defaultchecked = ('submitbugs' => 'on');
20866: my @offon = ('off','on');
1.118 jms 20867: my @toggles = ('submitbugs');
1.285 raeburn 20868: my %current = ('submitbugs' => '',
20869: 'adhoc' => {},
20870: );
1.118 jms 20871: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20872: %current = %{$domconfig{'helpsettings'}};
20873: }
1.285 raeburn 20874: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20875: foreach my $item (@toggles) {
20876: if ($defaultchecked{$item} eq 'on') {
20877: if ($current{$item} eq '') {
20878: if ($env{'form.'.$item} eq '0') {
20879: $changes{$item} = 1;
20880: }
20881: } elsif ($current{$item} ne $env{'form.'.$item}) {
20882: $changes{$item} = 1;
20883: }
20884: } elsif ($defaultchecked{$item} eq 'off') {
20885: if ($current{$item} eq '') {
20886: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20887: $changes{$item} = 1;
20888: }
1.282 raeburn 20889: } elsif ($current{$item} ne $env{'form.'.$item}) {
20890: $changes{$item} = 1;
20891: }
20892: }
20893: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20894: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20895: }
20896: }
1.285 raeburn 20897: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20898: my $confname = $dom.'-domainconfig';
20899: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20900: my (@allpos,%newsettings,%changedprivs,$newrole);
20901: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20902: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20903: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20904: my %lt = &Apache::lonlocal::texthash(
20905: s => 'system',
20906: d => 'domain',
20907: order => 'Display order',
20908: access => 'Role usage',
1.291 raeburn 20909: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20910: dh => 'All with domain helpdesk role',
20911: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20912: none => 'None',
20913: status => 'Determined based on institutional status',
20914: inc => 'Include all, but exclude specific personnel',
20915: exc => 'Exclude all, but include specific personnel',
20916: );
20917: for (my $num=0; $num<=$maxnum; $num++) {
20918: my ($prefix,$identifier,$rolename,%curr);
20919: if ($num == $maxnum) {
20920: next unless ($env{'form.newcusthelp'} == $maxnum);
20921: $identifier = 'custhelp'.$num;
20922: $prefix = 'helproles_'.$num;
20923: $rolename = $env{'form.custhelpname'.$num};
20924: $rolename=~s/[^A-Za-z0-9]//gs;
20925: next if ($rolename eq '');
20926: next if (exists($existing{'rolesdef_'.$rolename}));
20927: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20928: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20929: $newprivs{'c'},$confname,$dom);
20930: if ($result ne 'ok') {
20931: $errors .= '<li><span class="LC_error">'.
20932: &mt('An error occurred storing the new custom role: [_1]',
20933: $result).'</span></li>';
20934: next;
20935: } else {
20936: $changedprivs{$rolename} = \%newprivs;
20937: $newrole = $rolename;
20938: }
20939: } else {
20940: $prefix = 'helproles_'.$num;
20941: $rolename = $env{'form.'.$prefix};
20942: next if ($rolename eq '');
20943: next unless (exists($existing{'rolesdef_'.$rolename}));
20944: $identifier = 'custhelp'.$num;
20945: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
20946: my %currprivs;
1.289 raeburn 20947: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 20948: split(/\_/,$existing{'rolesdef_'.$rolename});
20949: foreach my $level ('c','d','s') {
20950: if ($newprivs{$level} ne $currprivs{$level}) {
20951: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
20952: $newprivs{'c'},$confname,$dom);
20953: if ($result ne 'ok') {
20954: $errors .= '<li><span class="LC_error">'.
20955: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
20956: $rolename,$result).'</span></li>';
20957: } else {
20958: $changedprivs{$rolename} = \%newprivs;
20959: }
20960: last;
20961: }
20962: }
20963: if (ref($current{'adhoc'}) eq 'HASH') {
20964: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
20965: %curr = %{$current{'adhoc'}{$rolename}};
20966: }
20967: }
20968: }
20969: my $newpos = $env{'form.'.$prefix.'_pos'};
20970: $newpos =~ s/\D+//g;
20971: $allpos[$newpos] = $rolename;
20972: my $newdesc = $env{'form.'.$prefix.'_desc'};
20973: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
20974: if ($curr{'desc'}) {
20975: if ($curr{'desc'} ne $newdesc) {
20976: $changes{'customrole'}{$rolename}{'desc'} = 1;
20977: $newsettings{$rolename}{'desc'} = $newdesc;
20978: }
20979: } elsif ($newdesc ne '') {
20980: $changes{'customrole'}{$rolename}{'desc'} = 1;
20981: $newsettings{$rolename}{'desc'} = $newdesc;
20982: }
20983: my $access = $env{'form.'.$prefix.'_access'};
20984: if (grep(/^\Q$access\E$/,@accesstypes)) {
20985: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
20986: if ($access eq 'status') {
20987: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
20988: if (scalar(@statuses) == 0) {
1.289 raeburn 20989: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 20990: } else {
20991: my (@shownstatus,$numtypes);
20992: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
20993: if (ref($types) eq 'ARRAY') {
20994: $numtypes = scalar(@{$types});
20995: foreach my $type (sort(@statuses)) {
20996: if ($type eq 'default') {
20997: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
20998: } elsif (grep(/^\Q$type\E$/,@{$types})) {
20999: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21000: push(@shownstatus,$usertypes->{$type});
21001: }
21002: }
21003: }
21004: if (grep(/^default$/,@statuses)) {
21005: push(@shownstatus,$othertitle);
21006: }
21007: if (scalar(@shownstatus) == 1+$numtypes) {
21008: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21009: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21010: } else {
21011: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21012: if (ref($curr{'status'}) eq 'ARRAY') {
21013: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21014: if (@diffs) {
21015: $changes{'customrole'}{$rolename}{$access} = 1;
21016: }
21017: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21018: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21019: }
1.166 raeburn 21020: }
21021: }
1.285 raeburn 21022: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21023: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21024: my @newspecstaff;
21025: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21026: foreach my $person (sort(@personnel)) {
21027: if ($domhelpdesk{$person}) {
21028: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21029: }
21030: }
21031: if (ref($curr{$access}) eq 'ARRAY') {
21032: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21033: if (@diffs) {
21034: $changes{'customrole'}{$rolename}{$access} = 1;
21035: }
21036: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21037: $changes{'customrole'}{$rolename}{$access} = 1;
21038: }
21039: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21040: my ($uname,$udom) = split(/:/,$person);
21041: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21042: }
21043: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21044: }
1.285 raeburn 21045: } else {
21046: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21047: }
21048: unless ($curr{'access'} eq $access) {
21049: $changes{'customrole'}{$rolename}{'access'} = 1;
21050: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21051: }
21052: }
1.285 raeburn 21053: if (@allpos > 0) {
21054: my $idx = 0;
21055: foreach my $rolename (@allpos) {
21056: if ($rolename ne '') {
21057: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21058: if (ref($current{'adhoc'}) eq 'HASH') {
21059: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21060: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21061: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21062: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21063: }
21064: }
1.282 raeburn 21065: }
1.285 raeburn 21066: $idx ++;
1.166 raeburn 21067: }
21068: }
1.118 jms 21069: }
1.123 jms 21070: my $putresult;
21071: if (keys(%changes) > 0) {
1.166 raeburn 21072: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21073: if ($putresult eq 'ok') {
1.285 raeburn 21074: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21075: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21076: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21077: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21078: }
21079: }
21080: my $cachetime = 24*60*60;
21081: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21082: if (ref($lastactref) eq 'HASH') {
21083: $lastactref->{'domdefaults'} = 1;
21084: }
21085: } else {
21086: $errors .= '<li><span class="LC_error">'.
21087: &mt('An error occurred storing the settings: [_1]',
21088: $putresult).'</span></li>';
21089: }
21090: }
21091: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21092: $resulttext = &mt('Changes made:').'<ul>';
21093: my (%shownprivs,@levelorder);
21094: @levelorder = ('c','d','s');
21095: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21096: foreach my $item (sort(keys(%changes))) {
21097: if ($item eq 'submitbugs') {
21098: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21099: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21100: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21101: } elsif ($item eq 'customrole') {
21102: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21103: my @keyorder = ('order','desc','access','status','exc','inc');
21104: my %keytext = &Apache::lonlocal::texthash(
21105: order => 'Order',
21106: desc => 'Role description',
21107: access => 'Role usage',
1.300 droeschl 21108: status => 'Allowed institutional types',
1.285 raeburn 21109: exc => 'Allowed personnel',
21110: inc => 'Disallowed personnel',
21111: );
1.282 raeburn 21112: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21113: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21114: if ($role eq $newrole) {
21115: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21116: $role).'<ul>';
21117: } else {
21118: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21119: $role).'<ul>';
21120: }
21121: foreach my $key (@keyorder) {
21122: if ($changes{'customrole'}{$role}{$key}) {
21123: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21124: $keytext{$key},$newsettings{$role}{$key}).
21125: '</li>';
21126: }
21127: }
21128: if (ref($changedprivs{$role}) eq 'HASH') {
21129: $shownprivs{$role} = 1;
21130: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21131: foreach my $level (@levelorder) {
21132: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21133: next if ($item eq '');
21134: my ($priv) = split(/\&/,$item,2);
21135: if (&Apache::lonnet::plaintext($priv)) {
21136: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21137: unless ($level eq 'c') {
21138: $resulttext .= ' ('.$lt{$level}.')';
21139: }
21140: $resulttext .= '</li>';
21141: }
21142: }
21143: }
21144: $resulttext .= '</ul>';
21145: }
21146: $resulttext .= '</ul></li>';
21147: }
21148: }
21149: }
21150: }
21151: }
21152: }
21153: if (keys(%changedprivs)) {
21154: foreach my $role (sort(keys(%changedprivs))) {
21155: unless ($shownprivs{$role}) {
21156: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21157: $role).'<ul>'.
21158: '<li>'.&mt('Privileges set to :').'<ul>';
21159: foreach my $level (@levelorder) {
21160: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21161: next if ($item eq '');
21162: my ($priv) = split(/\&/,$item,2);
21163: if (&Apache::lonnet::plaintext($priv)) {
21164: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21165: unless ($level eq 'c') {
21166: $resulttext .= ' ('.$lt{$level}.')';
21167: }
21168: $resulttext .= '</li>';
21169: }
1.282 raeburn 21170: }
21171: }
1.285 raeburn 21172: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21173: }
21174: }
21175: }
1.285 raeburn 21176: $resulttext .= '</ul>';
21177: } else {
21178: $resulttext = &mt('No changes made to help settings');
1.118 jms 21179: }
21180: if ($errors) {
1.168 raeburn 21181: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21182: $errors.'</ul>';
1.118 jms 21183: }
21184: return $resulttext;
21185: }
21186:
1.121 raeburn 21187: sub modify_coursedefaults {
1.212 raeburn 21188: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21189: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21190: my %defaultchecked = (
21191: 'canuse_pdfforms' => 'off',
21192: 'uselcmath' => 'on',
1.398 raeburn 21193: 'usejsme' => 'on',
21194: 'inline_chem' => 'on',
1.404 raeburn 21195: 'ltiauth' => 'off',
1.257 raeburn 21196: );
1.404 raeburn 21197: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21198: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21199: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21200: 'coursequota_official','coursequota_unofficial','coursequota_community',
21201: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21202: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21203: 'mysqltables_placement');
1.271 raeburn 21204: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21205: my %staticdefaults = (
21206: anonsurvey_threshold => 10,
21207: uploadquota => 500,
1.428 raeburn 21208: coursequota => 20,
1.257 raeburn 21209: postsubmit => 60,
1.276 raeburn 21210: mysqltables => 172800,
1.422 raeburn 21211: domexttool => 1,
1.432 raeburn 21212: crsauthor => 1,
1.198 raeburn 21213: );
1.314 raeburn 21214: my %texoptions = (
21215: MathJax => 'MathJax',
21216: mimetex => &mt('Convert to Images'),
21217: tth => &mt('TeX to HTML'),
21218: );
1.121 raeburn 21219: $defaultshash{'coursedefaults'} = {};
21220:
21221: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21222: if ($domconfig{'coursedefaults'} eq '') {
21223: $domconfig{'coursedefaults'} = {};
21224: }
21225: }
21226:
21227: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21228: foreach my $item (@toggles) {
21229: if ($defaultchecked{$item} eq 'on') {
21230: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21231: ($env{'form.'.$item} eq '0')) {
21232: $changes{$item} = 1;
1.192 raeburn 21233: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21234: $changes{$item} = 1;
21235: }
21236: } elsif ($defaultchecked{$item} eq 'off') {
21237: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21238: ($env{'form.'.$item} eq '1')) {
21239: $changes{$item} = 1;
21240: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21241: $changes{$item} = 1;
21242: }
21243: }
21244: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21245: }
1.198 raeburn 21246: foreach my $item (@numbers) {
21247: my ($currdef,$newdef);
1.208 raeburn 21248: $newdef = $env{'form.'.$item};
1.198 raeburn 21249: if ($item eq 'anonsurvey_threshold') {
21250: $currdef = $domconfig{'coursedefaults'}{$item};
21251: $newdef =~ s/\D//g;
21252: if ($newdef eq '' || $newdef < 1) {
21253: $newdef = 1;
21254: }
21255: $defaultshash{'coursedefaults'}{$item} = $newdef;
21256: } else {
1.428 raeburn 21257: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21258: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21259: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21260: }
21261: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21262: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21263: }
21264: if ($currdef ne $newdef) {
21265: if ($item eq 'anonsurvey_threshold') {
21266: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21267: $changes{$item} = 1;
21268: }
1.428 raeburn 21269: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21270: my $setting = $1;
1.276 raeburn 21271: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21272: $changes{$setting} = 1;
1.198 raeburn 21273: }
21274: }
1.139 raeburn 21275: }
21276: }
1.314 raeburn 21277: my $texengine;
21278: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21279: $texengine = $env{'form.texengine'};
1.349 raeburn 21280: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21281: if ($currdef eq '') {
21282: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21283: $changes{'texengine'} = 1;
21284: }
1.349 raeburn 21285: } elsif ($currdef ne $texengine) {
1.314 raeburn 21286: $changes{'texengine'} = 1;
21287: }
21288: }
21289: if ($texengine ne '') {
21290: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21291: }
1.264 raeburn 21292: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21293: my @currclonecode;
21294: if (ref($currclone) eq 'HASH') {
21295: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21296: @currclonecode = @{$currclone->{'instcode'}};
21297: }
21298: }
21299: my $newclone;
1.289 raeburn 21300: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21301: $newclone = $env{'form.canclone'};
21302: }
21303: if ($newclone eq 'instcode') {
21304: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21305: my (%codedefaults,@code_order,@clonecode);
21306: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21307: \@code_order);
21308: foreach my $item (@code_order) {
21309: if (grep(/^\Q$item\E$/,@newcodes)) {
21310: push(@clonecode,$item);
21311: }
21312: }
21313: if (@clonecode) {
21314: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21315: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21316: if (@diffs) {
21317: $changes{'canclone'} = 1;
21318: }
21319: } else {
21320: $newclone eq '';
21321: }
21322: } elsif ($newclone ne '') {
1.289 raeburn 21323: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21324: }
1.264 raeburn 21325: if ($newclone ne $currclone) {
21326: $changes{'canclone'} = 1;
21327: }
1.257 raeburn 21328: my %credits;
21329: foreach my $type (@types) {
21330: unless ($type eq 'community') {
21331: $credits{$type} = $env{'form.'.$type.'_credits'};
21332: $credits{$type} =~ s/[^\d.]+//g;
21333: }
21334: }
21335: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21336: ($env{'form.coursecredits'} eq '1')) {
21337: $changes{'coursecredits'} = 1;
21338: foreach my $type (keys(%credits)) {
21339: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21340: }
21341: } else {
1.289 raeburn 21342: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21343: foreach my $type (@types) {
21344: unless ($type eq 'community') {
1.289 raeburn 21345: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21346: $changes{'coursecredits'} = 1;
21347: }
21348: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21349: }
21350: }
21351: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21352: foreach my $type (@types) {
21353: unless ($type eq 'community') {
21354: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21355: $changes{'coursecredits'} = 1;
21356: last;
21357: }
21358: }
21359: }
21360: }
21361: }
21362: if ($env{'form.postsubmit'} eq '1') {
21363: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21364: my %currtimeout;
21365: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21366: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21367: $changes{'postsubmit'} = 1;
21368: }
21369: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21370: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21371: }
21372: } else {
21373: $changes{'postsubmit'} = 1;
21374: }
21375: foreach my $type (@types) {
21376: my $timeout = $env{'form.'.$type.'_timeout'};
21377: $timeout =~ s/\D//g;
21378: if ($timeout == $staticdefaults{'postsubmit'}) {
21379: $timeout = '';
21380: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21381: $timeout = '0';
21382: }
21383: unless ($timeout eq '') {
21384: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21385: }
21386: if (exists($currtimeout{$type})) {
21387: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21388: $changes{'postsubmit'} = 1;
1.257 raeburn 21389: }
21390: } elsif ($timeout ne '') {
21391: $changes{'postsubmit'} = 1;
21392: }
21393: }
21394: } else {
21395: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21396: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21397: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21398: $changes{'postsubmit'} = 1;
21399: }
21400: } else {
21401: $changes{'postsubmit'} = 1;
21402: }
1.192 raeburn 21403: }
1.432 raeburn 21404: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor);
1.422 raeburn 21405: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21406: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21407: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.422 raeburn 21408: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21409: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21410: } else {
21411: foreach my $type (@types) {
21412: if ($staticdefaults{'domexttool'}) {
21413: $olddomexttool{$type} = 1;
21414: } else {
21415: $olddomexttool{$type} = 0;
21416: }
21417: }
21418: }
21419: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21420: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21421: } else {
21422: foreach my $type (@types) {
21423: if ($staticdefaults{'exttool'}) {
21424: $oldexttool{$type} = 1;
21425: } else {
21426: $oldexttool{$type} = 0;
21427: }
21428: }
21429: }
1.432 raeburn 21430: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21431: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21432: } else {
21433: foreach my $type (@types) {
21434: if ($staticdefaults{'crsauthor'}) {
21435: $oldcrsauthor{$type} = 1;
21436: } else {
21437: $oldcrsauthor{$type} = 0;
21438: }
21439: }
21440: }
1.422 raeburn 21441: foreach my $type (@types) {
21442: unless ($newdomexttool{$type}) {
21443: $newdomexttool{$type} = 0;
21444: }
21445: unless ($newexttool{$type}) {
21446: $newexttool{$type} = 0;
21447: }
1.432 raeburn 21448: unless ($newcrsauthor{$type}) {
21449: $newcrsauthor{$type} = 0;
21450: }
1.422 raeburn 21451: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21452: $changes{'domexttool'} = 1;
21453: }
21454: if ($newexttool{$type} != $oldexttool{$type}) {
21455: $changes{'exttool'} = 1;
21456: }
1.432 raeburn 21457: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21458: $changes{'crsauthor'} = 1;
21459: }
1.422 raeburn 21460: }
21461: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21462: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21463: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.121 raeburn 21464: }
21465: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21466: $dom);
21467: if ($putresult eq 'ok') {
21468: if (keys(%changes) > 0) {
1.213 raeburn 21469: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21470: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21471: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21472: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21473: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21474: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21475: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21476: 'ltiauth') {
1.257 raeburn 21477: if ($changes{$item}) {
21478: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21479: }
1.289 raeburn 21480: }
1.192 raeburn 21481: if ($changes{'coursecredits'}) {
21482: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21483: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21484: $domdefaults{$type.'credits'} =
21485: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21486: }
21487: }
21488: }
21489: if ($changes{'postsubmit'}) {
21490: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21491: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21492: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21493: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21494: $domdefaults{$type.'postsubtimeout'} =
21495: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21496: }
21497: }
1.192 raeburn 21498: }
21499: }
1.198 raeburn 21500: if ($changes{'uploadquota'}) {
21501: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21502: foreach my $type (@types) {
21503: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21504: }
21505: }
21506: }
1.428 raeburn 21507: if ($changes{'coursequota'}) {
21508: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21509: foreach my $type (@types) {
21510: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21511: }
21512: }
21513: }
1.264 raeburn 21514: if ($changes{'canclone'}) {
21515: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21516: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21517: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21518: if (@clonecodes) {
21519: $domdefaults{'canclone'} = join('+',@clonecodes);
21520: }
21521: }
21522: } else {
21523: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21524: }
21525: }
1.422 raeburn 21526: if ($changes{'domexttool'}) {
21527: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21528: foreach my $type (@types) {
21529: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21530: }
21531: }
21532: }
21533: if ($changes{'exttool'}) {
21534: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21535: foreach my $type (@types) {
21536: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21537: }
21538: }
21539: }
1.432 raeburn 21540: if ($changes{'crsauthor'}) {
21541: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21542: foreach my $type (@types) {
21543: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21544: }
21545: }
21546: }
1.121 raeburn 21547: my $cachetime = 24*60*60;
21548: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21549: if (ref($lastactref) eq 'HASH') {
21550: $lastactref->{'domdefaults'} = 1;
21551: }
1.121 raeburn 21552: }
21553: $resulttext = &mt('Changes made:').'<ul>';
21554: foreach my $item (sort(keys(%changes))) {
21555: if ($item eq 'canuse_pdfforms') {
21556: if ($env{'form.'.$item} eq '1') {
21557: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21558: } else {
21559: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21560: }
1.257 raeburn 21561: } elsif ($item eq 'uselcmath') {
21562: if ($env{'form.'.$item} eq '1') {
21563: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21564: } else {
21565: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21566: }
21567: } elsif ($item eq 'usejsme') {
21568: if ($env{'form.'.$item} eq '1') {
21569: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21570: } else {
1.289 raeburn 21571: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21572: }
1.398 raeburn 21573: } elsif ($item eq 'inline_chem') {
21574: if ($env{'form.'.$item} eq '1') {
21575: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21576: } else {
21577: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21578: }
1.314 raeburn 21579: } elsif ($item eq 'texengine') {
21580: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21581: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21582: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21583: }
1.139 raeburn 21584: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21585: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21586: } elsif ($item eq 'uploadquota') {
21587: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21588: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21589: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21590: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21591: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21592: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21593: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21594: '</ul>'.
21595: '</li>';
21596: } else {
21597: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21598: }
1.428 raeburn 21599: } elsif ($item eq 'coursequota') {
21600: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21601: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21602: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21603: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21604: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21605: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21606: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21607: '</ul>'.
21608: '</li>';
21609: } else {
21610: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21611: }
1.276 raeburn 21612: } elsif ($item eq 'mysqltables') {
21613: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21614: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21615: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21616: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21617: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21618: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21619: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21620: '</ul>'.
21621: '</li>';
21622: } else {
21623: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21624: }
1.257 raeburn 21625: } elsif ($item eq 'postsubmit') {
21626: if ($domdefaults{'postsubmit'} eq 'off') {
21627: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21628: } else {
21629: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21630: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21631: $resulttext .= &mt('durations:').'<ul>';
21632: foreach my $type (@types) {
21633: $resulttext .= '<li>';
21634: my $timeout;
21635: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21636: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21637: }
21638: my $display;
21639: if ($timeout eq '0') {
21640: $display = &mt('unlimited');
21641: } elsif ($timeout eq '') {
21642: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21643: } else {
21644: $display = &mt('[quant,_1,second]',$timeout);
21645: }
21646: if ($type eq 'community') {
21647: $resulttext .= &mt('Communities');
21648: } elsif ($type eq 'official') {
21649: $resulttext .= &mt('Official courses');
21650: } elsif ($type eq 'unofficial') {
21651: $resulttext .= &mt('Unofficial courses');
21652: } elsif ($type eq 'textbook') {
21653: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21654: } elsif ($type eq 'placement') {
21655: $resulttext .= &mt('Placement tests');
1.257 raeburn 21656: }
21657: $resulttext .= ' -- '.$display.'</li>';
21658: }
21659: $resulttext .= '</ul>';
21660: }
1.289 raeburn 21661: $resulttext .= '</li>';
1.257 raeburn 21662: }
1.192 raeburn 21663: } elsif ($item eq 'coursecredits') {
21664: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21665: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21666: ($domdefaults{'unofficialcredits'} eq '') &&
21667: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21668: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21669: } else {
21670: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21671: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21672: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21673: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21674: '</ul>'.
21675: '</li>';
21676: }
21677: } else {
21678: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21679: }
1.264 raeburn 21680: } elsif ($item eq 'canclone') {
21681: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21682: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21683: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21684: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21685: }
21686: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21687: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21688: } else {
1.289 raeburn 21689: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21690: }
1.404 raeburn 21691: } elsif ($item eq 'ltiauth') {
21692: if ($env{'form.'.$item} eq '1') {
21693: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21694: } else {
21695: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21696: }
1.432 raeburn 21697: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21698: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21699: my %status = (
21700: domexttool => {
21701: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21702: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21703: },
21704: exttool => {
21705: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21706: default => &mt('External Tools can not be defined in any course types, by default'),
21707: },
21708: crsauthor => {
21709: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21710: default => &mt('Standard Problems can be created within any course type, by default'),
21711: },
21712: );
21713:
21714: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21715: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21716: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21717: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21718: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21719: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21720: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21721: '</ul>'.
21722: '</li>';
21723: } else {
1.432 raeburn 21724: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21725: }
1.140 raeburn 21726: }
1.121 raeburn 21727: }
21728: $resulttext .= '</ul>';
21729: } else {
21730: $resulttext = &mt('No changes made to course defaults');
21731: }
21732: } else {
21733: $resulttext = '<span class="LC_error">'.
21734: &mt('An error occurred: [_1]',$putresult).'</span>';
21735: }
21736: return $resulttext;
21737: }
21738:
1.231 raeburn 21739: sub modify_selfenrollment {
21740: my ($dom,$lastactref,%domconfig) = @_;
21741: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21742: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21743: my %titles = &tool_titles();
1.232 raeburn 21744: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21745: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21746: $ordered{'default'} = ['types','registered','approval','limit'];
21747:
21748: my (%roles,%shown,%toplevel);
21749: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21750:
21751: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21752: if ($domconfig{'selfenrollment'} eq '') {
21753: $domconfig{'selfenrollment'} = {};
21754: }
21755: }
21756: %toplevel = (
21757: admin => 'Configuration Rights',
21758: default => 'Default settings',
21759: validation => 'Validation of self-enrollment requests',
21760: );
1.233 raeburn 21761: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21762:
21763: if (ref($ordered{'admin'}) eq 'ARRAY') {
21764: foreach my $item (@{$ordered{'admin'}}) {
21765: foreach my $type (@types) {
21766: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21767: $selfenrollhash{'admin'}{$type}{$item} = 1;
21768: } else {
21769: $selfenrollhash{'admin'}{$type}{$item} = 0;
21770: }
21771: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21772: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21773: if ($selfenrollhash{'admin'}{$type}{$item} ne
21774: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21775: push(@{$changes{'admin'}{$type}},$item);
21776: }
21777: } else {
21778: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21779: push(@{$changes{'admin'}{$type}},$item);
21780: }
21781: }
21782: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21783: push(@{$changes{'admin'}{$type}},$item);
21784: }
21785: }
21786: }
21787: }
21788:
21789: foreach my $item (@{$ordered{'default'}}) {
21790: foreach my $type (@types) {
21791: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21792: if ($item eq 'types') {
21793: unless (($value eq 'all') || ($value eq 'dom')) {
21794: $value = '';
21795: }
21796: } elsif ($item eq 'registered') {
21797: unless ($value eq '1') {
21798: $value = 0;
21799: }
21800: } elsif ($item eq 'approval') {
21801: unless ($value =~ /^[012]$/) {
21802: $value = 0;
21803: }
21804: } else {
21805: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21806: $value = 'none';
21807: }
21808: }
21809: $selfenrollhash{'default'}{$type}{$item} = $value;
21810: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21811: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21812: if ($selfenrollhash{'default'}{$type}{$item} ne
21813: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21814: push(@{$changes{'default'}{$type}},$item);
21815: }
21816: } else {
21817: push(@{$changes{'default'}{$type}},$item);
21818: }
21819: } else {
21820: push(@{$changes{'default'}{$type}},$item);
21821: }
21822: if ($item eq 'limit') {
21823: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21824: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21825: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21826: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21827: }
21828: } else {
21829: $selfenrollhash{'default'}{$type}{'cap'} = '';
21830: }
21831: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21832: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21833: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21834: push(@{$changes{'default'}{$type}},'cap');
21835: }
21836: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21837: push(@{$changes{'default'}{$type}},'cap');
21838: }
21839: }
21840: }
21841: }
21842:
21843: foreach my $item (@{$itemsref}) {
21844: if ($item eq 'fields') {
21845: my @changed;
21846: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21847: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21848: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21849: }
21850: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21851: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21852: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21853: $domconfig{'selfenrollment'}{'validation'}{$item});
21854: } else {
21855: @changed = @{$selfenrollhash{'validation'}{$item}};
21856: }
21857: } else {
21858: @changed = @{$selfenrollhash{'validation'}{$item}};
21859: }
21860: if (@changed) {
21861: if ($selfenrollhash{'validation'}{$item}) {
21862: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21863: } else {
21864: $changes{'validation'}{$item} = &mt('None');
21865: }
21866: }
21867: } else {
21868: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21869: if ($item eq 'markup') {
21870: if ($env{'form.selfenroll_validation_'.$item}) {
21871: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21872: }
21873: }
21874: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21875: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
21876: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
21877: }
21878: }
21879: }
21880: }
21881:
21882: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
21883: $dom);
21884: if ($putresult eq 'ok') {
21885: if (keys(%changes) > 0) {
21886: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
21887: $resulttext = &mt('Changes made:').'<ul>';
21888: foreach my $key ('admin','default','validation') {
21889: if (ref($changes{$key}) eq 'HASH') {
21890: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
21891: if ($key eq 'validation') {
21892: foreach my $item (@{$itemsref}) {
21893: if (exists($changes{$key}{$item})) {
21894: if ($item eq 'markup') {
21895: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21896: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
21897: } else {
21898: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
21899: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
21900: }
21901: }
21902: }
21903: } else {
21904: foreach my $type (@types) {
21905: if ($type eq 'community') {
21906: $roles{'1'} = &mt('Community personnel');
21907: } else {
21908: $roles{'1'} = &mt('Course personnel');
21909: }
21910: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 21911: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21912: if ($key eq 'admin') {
21913: my @mgrdc = ();
21914: if (ref($ordered{$key}) eq 'ARRAY') {
21915: foreach my $item (@{$ordered{'admin'}}) {
21916: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
21917: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
21918: push(@mgrdc,$item);
21919: }
21920: }
21921: }
21922: if (@mgrdc) {
21923: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
21924: } else {
21925: delete($domdefaults{$type.'selfenrolladmdc'});
21926: }
21927: }
21928: } else {
21929: if (ref($ordered{$key}) eq 'ARRAY') {
21930: foreach my $item (@{$ordered{$key}}) {
21931: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21932: $domdefaults{$type.'selfenroll'.$item} =
21933: $selfenrollhash{$key}{$type}{$item};
21934: }
21935: }
21936: }
21937: }
21938: }
1.231 raeburn 21939: $resulttext .= '<li>'.$titles{$type}.'<ul>';
21940: foreach my $item (@{$ordered{$key}}) {
21941: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
21942: $resulttext .= '<li>';
21943: if ($key eq 'admin') {
21944: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
21945: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
21946: } else {
21947: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
21948: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
21949: }
21950: $resulttext .= '</li>';
21951: }
21952: }
21953: $resulttext .= '</ul></li>';
21954: }
21955: }
21956: $resulttext .= '</ul></li>';
21957: }
21958: }
1.305 raeburn 21959: }
21960: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
21961: my $cachetime = 24*60*60;
21962: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21963: if (ref($lastactref) eq 'HASH') {
21964: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 21965: }
1.231 raeburn 21966: }
21967: $resulttext .= '</ul>';
21968: } else {
21969: $resulttext = &mt('No changes made to self-enrollment settings');
21970: }
21971: } else {
21972: $resulttext = '<span class="LC_error">'.
21973: &mt('An error occurred: [_1]',$putresult).'</span>';
21974: }
21975: return $resulttext;
21976: }
21977:
1.373 raeburn 21978: sub modify_wafproxy {
21979: my ($dom,$action,$lastactref,%domconfig) = @_;
21980: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 21981: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
21982: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 21983: foreach my $server (sort(keys(%servers))) {
21984: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21985: if ($serverhome eq $server) {
21986: my $serverdom = &Apache::lonnet::host_domain($server);
21987: if ($serverdom eq $dom) {
21988: $canset{$server} = 1;
21989: }
21990: }
21991: }
1.381 raeburn 21992: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
21993: %{$values{$dom}} = ();
21994: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
21995: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
21996: }
1.388 raeburn 21997: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
21998: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
21999: }
1.382 raeburn 22000: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22001: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22002: }
22003: }
1.373 raeburn 22004: my $output;
22005: if (keys(%canset)) {
22006: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22007: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22008: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22009: if ($env{'form.wafproxy_'.$dom}) {
22010: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22011: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22012: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22013: $changes{'alias'} = 1;
22014: }
1.388 raeburn 22015: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22016: $wafproxy{'saml'}{$key} = 1;
22017: }
22018: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22019: $changes{'saml'} = 1;
22020: }
1.381 raeburn 22021: } else {
22022: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22023: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22024: if ($curralias{$key}) {
22025: $changes{'alias'} = 1;
22026: }
1.388 raeburn 22027: if ($currsaml{$key}) {
22028: $changes{'saml'} = 1;
22029: }
1.373 raeburn 22030: }
22031: if ($wafproxy{'alias'}{$key} eq '') {
22032: if ($curralias{$key}) {
22033: $expirecache{$key} = 1;
22034: }
22035: delete($wafproxy{'alias'}{$key});
22036: }
1.388 raeburn 22037: if ($wafproxy{'saml'}{$key} eq '') {
22038: if ($currsaml{$key}) {
22039: $expiresaml{$key} = 1;
22040: }
22041: delete($wafproxy{'saml'}{$key});
22042: }
1.373 raeburn 22043: }
22044: unless (keys(%{$wafproxy{'alias'}})) {
22045: delete($wafproxy{'alias'});
22046: }
1.388 raeburn 22047: unless (keys(%{$wafproxy{'saml'}})) {
22048: delete($wafproxy{'saml'});
22049: }
22050: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22051: my %warn = (
22052: trusted => 'trusted IP range(s)',
1.381 raeburn 22053: vpnint => 'internal IP range(s) for VPN sessions(s)',
22054: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22055: );
1.382 raeburn 22056: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22057: my $possible = $env{'form.wafproxy_'.$item};
22058: $possible =~ s/^\s+|\s+$//g;
22059: if ($possible ne '') {
1.381 raeburn 22060: if ($item eq 'remoteip') {
22061: if ($possible =~ /^[mhn]$/) {
22062: $wafproxy{$item} = $possible;
22063: }
22064: } elsif ($item eq 'ipheader') {
22065: if ($wafproxy{'remoteip'} eq 'h') {
22066: $wafproxy{$item} = $possible;
22067: }
1.382 raeburn 22068: } elsif ($item eq 'sslopt') {
22069: if ($possible =~ /^0|1$/) {
22070: $wafproxy{$item} = $possible;
22071: }
1.373 raeburn 22072: } else {
22073: my (@ok,$count);
1.381 raeburn 22074: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22075: unless ($env{'form.wafproxy_vpnaccess'}) {
22076: $possible = '';
22077: }
22078: } elsif ($item eq 'trusted') {
22079: unless ($wafproxy{'remoteip'} eq 'h') {
22080: $possible = '';
22081: }
22082: }
22083: unless ($possible eq '') {
22084: $possible =~ s/[\r\n]+/\s/g;
22085: $possible =~ s/\s*-\s*/-/g;
22086: $possible =~ s/\s+/,/g;
1.393 raeburn 22087: $possible =~ s/,+/,/g;
1.381 raeburn 22088: }
1.373 raeburn 22089: $count = 0;
1.381 raeburn 22090: if ($possible ne '') {
1.373 raeburn 22091: foreach my $poss (split(/\,/,$possible)) {
22092: $count ++;
1.393 raeburn 22093: $poss = &validate_ip_pattern($poss);
22094: if ($poss ne '') {
1.373 raeburn 22095: push(@ok,$poss);
22096: }
22097: }
22098: my $diff = $count - scalar(@ok);
22099: if ($diff) {
22100: push(@warnings,'<li>'.
22101: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22102: $diff,$warn{$item}).
22103: '</li>');
22104: }
1.393 raeburn 22105: if (@ok) {
22106: my @cidr_list;
22107: foreach my $item (@ok) {
22108: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22109: }
22110: $wafproxy{$item} = join(',',@cidr_list);
22111: }
1.373 raeburn 22112: }
22113: }
1.381 raeburn 22114: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22115: $changes{$item} = 1;
22116: }
1.381 raeburn 22117: } elsif ($currvalue{$item}) {
22118: $changes{$item} = 1;
1.425 raeburn 22119: }
1.381 raeburn 22120: }
22121: } else {
22122: if (keys(%curralias)) {
22123: $changes{'alias'} = 1;
1.388 raeburn 22124: }
22125: if (keys(%currsaml)) {
22126: $changes{'saml'} = 1;
1.425 raeburn 22127: }
1.381 raeburn 22128: if (keys(%currvalue)) {
22129: foreach my $key (keys(%currvalue)) {
22130: $changes{$key} = 1;
1.373 raeburn 22131: }
22132: }
22133: }
22134: if (keys(%changes)) {
22135: my %defaultshash = (
22136: wafproxy => \%wafproxy,
1.425 raeburn 22137: );
1.373 raeburn 22138: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22139: $dom);
22140: if ($putresult eq 'ok') {
22141: my $cachetime = 24*60*60;
22142: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22143: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22144: if ($changes{$item}) {
22145: unless ($updatedomdefs) {
22146: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22147: $updatedomdefs = 1;
22148: }
22149: if ($wafproxy{$item}) {
22150: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22151: } elsif (exists($domdefaults{'waf_'.$item})) {
22152: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22153: }
1.373 raeburn 22154: }
22155: }
22156: if ($updatedomdefs) {
22157: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22158: if (ref($lastactref) eq 'HASH') {
22159: $lastactref->{'domdefaults'} = 1;
22160: }
22161: }
22162: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22163: my %updates = %expirecache;
22164: foreach my $key (keys(%expirecache)) {
22165: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22166: }
22167: if (ref($wafproxy{'alias'}) eq 'HASH') {
22168: my $cachetime = 24*60*60;
22169: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22170: $updates{$key} = 1;
22171: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22172: $cachetime);
22173: }
22174: }
22175: if (ref($lastactref) eq 'HASH') {
22176: $lastactref->{'proxyalias'} = \%updates;
22177: }
22178: }
1.388 raeburn 22179: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22180: my %samlupdates = %expiresaml;
22181: foreach my $key (keys(%expiresaml)) {
22182: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22183: }
22184: if (ref($wafproxy{'saml'}) eq 'HASH') {
22185: my $cachetime = 24*60*60;
22186: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22187: $samlupdates{$key} = 1;
22188: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22189: $cachetime);
22190: }
22191: }
22192: if (ref($lastactref) eq 'HASH') {
22193: $lastactref->{'proxysaml'} = \%samlupdates;
22194: }
22195: }
1.373 raeburn 22196: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22197: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22198: if ($changes{$item}) {
22199: if ($item eq 'alias') {
22200: my $numaliased = 0;
22201: if (ref($wafproxy{'alias'}) eq 'HASH') {
22202: my $shown;
22203: if (keys(%{$wafproxy{'alias'}})) {
22204: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22205: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22206: &Apache::lonnet::hostname($server),
22207: $wafproxy{'alias'}{$server}).'</li>';
22208: $numaliased ++;
22209: }
22210: if ($numaliased) {
22211: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22212: '<ul>'.$shown.'</ul>').'</li>';
22213: }
22214: }
22215: }
22216: unless ($numaliased) {
22217: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22218: }
1.388 raeburn 22219: } elsif ($item eq 'saml') {
1.425 raeburn 22220: my $shown;
1.388 raeburn 22221: if (ref($wafproxy{'saml'}) eq 'HASH') {
22222: if (keys(%{$wafproxy{'saml'}})) {
22223: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22224: }
22225: }
22226: if ($shown) {
1.396 raeburn 22227: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22228: $shown).'</li>';
22229: } else {
1.396 raeburn 22230: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22231: }
1.373 raeburn 22232: } else {
1.381 raeburn 22233: if ($item eq 'remoteip') {
22234: my %ip_methods = &remoteip_methods();
22235: if ($wafproxy{$item} =~ /^[mh]$/) {
22236: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22237: $ip_methods{$wafproxy{$item}}).'</li>';
22238: } else {
22239: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22240: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22241: '</li>';
22242: } else {
22243: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22244: }
22245: }
22246: } elsif ($item eq 'ipheader') {
1.373 raeburn 22247: if ($wafproxy{$item}) {
1.381 raeburn 22248: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22249: $wafproxy{$item}).'</li>';
22250: } else {
1.381 raeburn 22251: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22252: }
22253: } elsif ($item eq 'trusted') {
22254: if ($wafproxy{$item}) {
1.381 raeburn 22255: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22256: $wafproxy{$item}).'</li>';
22257: } else {
22258: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22259: }
1.381 raeburn 22260: } elsif ($item eq 'vpnint') {
22261: if ($wafproxy{$item}) {
22262: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22263: $wafproxy{$item}).'</li>';
22264: } else {
22265: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22266: }
22267: } elsif ($item eq 'vpnext') {
1.373 raeburn 22268: if ($wafproxy{$item}) {
1.381 raeburn 22269: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22270: $wafproxy{$item}).'</li>';
22271: } else {
1.381 raeburn 22272: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22273: }
1.382 raeburn 22274: } elsif ($item eq 'sslopt') {
22275: if ($wafproxy{$item}) {
22276: $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>';
22277: } else {
22278: $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>';
22279: }
1.373 raeburn 22280: }
22281: }
22282: }
22283: }
1.420 raeburn 22284: $output .= '</ul>';
1.373 raeburn 22285: } else {
22286: $output = '<span class="LC_error">'.
22287: &mt('An error occurred: [_1]',$putresult).'</span>';
22288: }
22289: } elsif (keys(%canset)) {
22290: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22291: }
22292: if (@warnings) {
22293: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22294: join("\n",@warnings).'</ul>';
22295: }
22296: return $output;
22297: }
22298:
22299: sub validate_ip_pattern {
22300: my ($pattern) = @_;
22301: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22302: my ($start,$end) = ($1,$2);
22303: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22304: if (($start !~ m{/}) && ($end !~ m{/})) {
22305: return $start.'-'.$end;
22306: }
22307: }
22308: } elsif ($pattern ne '') {
22309: $pattern = &Net::CIDR::cidrvalidate($pattern);
22310: if ($pattern ne '') {
22311: return $pattern;
1.373 raeburn 22312: }
22313: }
1.393 raeburn 22314: return;
1.373 raeburn 22315: }
22316:
1.137 raeburn 22317: sub modify_usersessions {
1.212 raeburn 22318: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22319: my @hostingtypes = ('version','excludedomain','includedomain');
22320: my @offloadtypes = ('primary','default');
22321: my %types = (
22322: remote => \@hostingtypes,
22323: hosted => \@hostingtypes,
22324: spares => \@offloadtypes,
22325: );
22326: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22327: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22328: my (%by_ip,%by_location,@intdoms,@instdoms);
22329: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22330: my @locations = sort(keys(%by_location));
1.137 raeburn 22331: my (%defaultshash,%changes);
22332: foreach my $prefix (@prefixes) {
22333: $defaultshash{'usersessions'}{$prefix} = {};
22334: }
1.212 raeburn 22335: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22336: my $resulttext;
1.138 raeburn 22337: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22338: foreach my $prefix (@prefixes) {
1.145 raeburn 22339: next if ($prefix eq 'spares');
22340: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22341: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22342: if ($type eq 'version') {
22343: my $value = $env{'form.'.$prefix.'_'.$type};
22344: my $okvalue;
22345: if ($value ne '') {
22346: if (grep(/^\Q$value\E$/,@lcversions)) {
22347: $okvalue = $value;
22348: }
22349: }
22350: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22351: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22352: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22353: if ($inuse == 0) {
22354: $changes{$prefix}{$type} = 1;
22355: } else {
22356: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22357: $changes{$prefix}{$type} = 1;
22358: }
22359: if ($okvalue ne '') {
22360: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22361: }
22362: }
22363: } else {
22364: if (($inuse == 1) && ($okvalue ne '')) {
22365: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22366: $changes{$prefix}{$type} = 1;
22367: }
22368: }
22369: } else {
22370: if (($inuse == 1) && ($okvalue ne '')) {
22371: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22372: $changes{$prefix}{$type} = 1;
22373: }
22374: }
22375: } else {
22376: if (($inuse == 1) && ($okvalue ne '')) {
22377: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22378: $changes{$prefix}{$type} = 1;
22379: }
22380: }
22381: } else {
22382: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22383: my @okvals;
22384: foreach my $val (@vals) {
1.138 raeburn 22385: if ($val =~ /:/) {
22386: my @items = split(/:/,$val);
22387: foreach my $item (@items) {
22388: if (ref($by_location{$item}) eq 'ARRAY') {
22389: push(@okvals,$item);
22390: }
22391: }
22392: } else {
22393: if (ref($by_location{$val}) eq 'ARRAY') {
22394: push(@okvals,$val);
22395: }
1.137 raeburn 22396: }
22397: }
22398: @okvals = sort(@okvals);
22399: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22400: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22401: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22402: if ($inuse == 0) {
22403: $changes{$prefix}{$type} = 1;
22404: } else {
22405: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22406: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22407: if (@changed > 0) {
22408: $changes{$prefix}{$type} = 1;
22409: }
22410: }
22411: } else {
22412: if ($inuse == 1) {
22413: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22414: $changes{$prefix}{$type} = 1;
22415: }
22416: }
22417: } else {
22418: if ($inuse == 1) {
22419: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22420: $changes{$prefix}{$type} = 1;
22421: }
22422: }
22423: } else {
22424: if ($inuse == 1) {
22425: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22426: $changes{$prefix}{$type} = 1;
22427: }
22428: }
22429: }
22430: }
22431: }
1.145 raeburn 22432:
22433: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22434: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22435: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22436: my $savespares;
22437:
22438: foreach my $lonhost (sort(keys(%servers))) {
22439: my $serverhomeID =
22440: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22441: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22442: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22443: my %spareschg;
22444: foreach my $type (@{$types{'spares'}}) {
22445: my @okspares;
22446: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22447: foreach my $server (@checked) {
1.152 raeburn 22448: if (&Apache::lonnet::hostname($server) ne '') {
22449: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22450: unless (grep(/^\Q$server\E$/,@okspares)) {
22451: push(@okspares,$server);
22452: }
1.145 raeburn 22453: }
22454: }
22455: }
22456: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22457: my $newspare;
1.152 raeburn 22458: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22459: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22460: $newspare = $new;
22461: }
22462: }
1.152 raeburn 22463: my @spares;
22464: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22465: @spares = sort(@okspares,$newspare);
22466: } else {
22467: @spares = sort(@okspares);
22468: }
22469: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22470: if (ref($spareid{$lonhost}) eq 'HASH') {
22471: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22472: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22473: if (@diffs > 0) {
22474: $spareschg{$type} = 1;
22475: }
22476: }
22477: }
22478: }
22479: if (keys(%spareschg) > 0) {
22480: $changes{'spares'}{$lonhost} = \%spareschg;
22481: }
22482: }
1.261 raeburn 22483: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22484: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22485: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22486: my @okoffload;
22487: if (@offloadnow) {
22488: foreach my $server (@offloadnow) {
22489: if (&Apache::lonnet::hostname($server) ne '') {
22490: unless (grep(/^\Q$server\E$/,@okoffload)) {
22491: push(@okoffload,$server);
22492: }
22493: }
22494: }
22495: if (@okoffload) {
22496: foreach my $lonhost (@okoffload) {
22497: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22498: }
22499: }
22500: }
1.371 raeburn 22501: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22502: my @okoffloadoth;
22503: if (@offloadoth) {
22504: foreach my $server (@offloadoth) {
22505: if (&Apache::lonnet::hostname($server) ne '') {
22506: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22507: push(@okoffloadoth,$server);
22508: }
22509: }
22510: }
22511: if (@okoffloadoth) {
22512: foreach my $lonhost (@okoffloadoth) {
22513: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22514: }
22515: }
22516: }
1.145 raeburn 22517: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22518: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22519: if (ref($changes{'spares'}) eq 'HASH') {
22520: if (keys(%{$changes{'spares'}}) > 0) {
22521: $savespares = 1;
22522: }
22523: }
22524: } else {
22525: $savespares = 1;
22526: }
1.371 raeburn 22527: foreach my $offload ('offloadnow','offloadoth') {
22528: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22529: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22530: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22531: $changes{$offload} = 1;
22532: last;
22533: }
1.261 raeburn 22534: }
1.371 raeburn 22535: unless ($changes{$offload}) {
22536: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22537: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22538: $changes{$offload} = 1;
22539: last;
22540: }
1.261 raeburn 22541: }
22542: }
1.371 raeburn 22543: } else {
22544: if (($offload eq 'offloadnow') && (@okoffload)) {
22545: $changes{'offloadnow'} = 1;
22546: }
22547: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22548: $changes{'offloadoth'} = 1;
22549: }
1.425 raeburn 22550: }
1.371 raeburn 22551: }
22552: } else {
22553: if (@okoffload) {
1.261 raeburn 22554: $changes{'offloadnow'} = 1;
22555: }
1.371 raeburn 22556: if (@okoffloadoth) {
22557: $changes{'offloadoth'} = 1;
22558: }
1.145 raeburn 22559: }
1.147 raeburn 22560: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22561: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22562: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22563: $dom);
22564: if ($putresult eq 'ok') {
22565: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22566: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22567: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22568: }
22569: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22570: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22571: }
1.261 raeburn 22572: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22573: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22574: }
1.371 raeburn 22575: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22576: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22577: }
1.137 raeburn 22578: }
22579: my $cachetime = 24*60*60;
22580: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22581: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22582: if (ref($lastactref) eq 'HASH') {
22583: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22584: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22585: }
1.147 raeburn 22586: if (keys(%changes) > 0) {
22587: my %lt = &usersession_titles();
22588: $resulttext = &mt('Changes made:').'<ul>';
22589: foreach my $prefix (@prefixes) {
22590: if (ref($changes{$prefix}) eq 'HASH') {
22591: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22592: if ($prefix eq 'spares') {
22593: if (ref($changes{$prefix}) eq 'HASH') {
22594: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22595: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22596: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22597: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22598: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22599: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22600: foreach my $type (@{$types{$prefix}}) {
22601: if ($changes{$prefix}{$lonhost}{$type}) {
22602: my $offloadto = &mt('None');
22603: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22604: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22605: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22606: }
1.145 raeburn 22607: }
1.147 raeburn 22608: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22609: }
1.137 raeburn 22610: }
22611: }
1.147 raeburn 22612: $resulttext .= '</li>';
1.137 raeburn 22613: }
22614: }
1.147 raeburn 22615: } else {
22616: foreach my $type (@{$types{$prefix}}) {
22617: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22618: my ($newvalue,$notinuse);
1.147 raeburn 22619: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22620: if (ref($defaultshash{'usersessions'}{$prefix})) {
22621: if ($type eq 'version') {
22622: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22623: } else {
22624: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22625: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22626: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22627: }
22628: } else {
22629: $notinuse = 1;
1.147 raeburn 22630: }
1.145 raeburn 22631: }
22632: }
22633: }
1.147 raeburn 22634: if ($newvalue eq '') {
22635: if ($type eq 'version') {
22636: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22637: } elsif ($notinuse) {
22638: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22639: } else {
22640: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22641: }
1.145 raeburn 22642: } else {
1.147 raeburn 22643: if ($type eq 'version') {
1.344 raeburn 22644: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22645: }
22646: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22647: }
1.137 raeburn 22648: }
22649: }
22650: }
1.147 raeburn 22651: $resulttext .= '</ul>';
1.137 raeburn 22652: }
22653: }
1.261 raeburn 22654: if ($changes{'offloadnow'}) {
22655: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22656: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22657: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22658: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22659: $resulttext .= '<li>'.$lonhost.'</li>';
22660: }
22661: $resulttext .= '</ul>';
22662: } else {
1.371 raeburn 22663: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22664: }
22665: } else {
22666: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22667: }
22668: }
22669: if ($changes{'offloadoth'}) {
22670: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22671: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22672: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22673: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22674: $resulttext .= '<li>'.$lonhost.'</li>';
22675: }
22676: $resulttext .= '</ul>';
22677: } else {
22678: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22679: }
22680: } else {
1.371 raeburn 22681: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22682: }
22683: }
1.147 raeburn 22684: $resulttext .= '</ul>';
22685: } else {
22686: $resulttext = $nochgmsg;
1.137 raeburn 22687: }
22688: } else {
22689: $resulttext = '<span class="LC_error">'.
22690: &mt('An error occurred: [_1]',$putresult).'</span>';
22691: }
22692: } else {
1.147 raeburn 22693: $resulttext = $nochgmsg;
1.137 raeburn 22694: }
22695: return $resulttext;
22696: }
22697:
1.275 raeburn 22698: sub modify_ssl {
22699: my ($dom,$lastactref,%domconfig) = @_;
22700: my (%by_ip,%by_location,@intdoms,@instdoms);
22701: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22702: my @locations = sort(keys(%by_location));
22703: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22704: my (%defaultshash,%changes);
22705: my $action = 'ssl';
1.293 raeburn 22706: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22707: foreach my $prefix (@prefixes) {
22708: $defaultshash{$action}{$prefix} = {};
22709: }
22710: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22711: my $resulttext;
22712: my %iphost = &Apache::lonnet::get_iphost();
22713: my @reptypes = ('certreq','nocertreq');
22714: my @connecttypes = ('dom','intdom','other');
22715: my %types = (
1.293 raeburn 22716: connto => \@connecttypes,
22717: connfrom => \@connecttypes,
22718: replication => \@reptypes,
1.275 raeburn 22719: );
22720: foreach my $prefix (sort(keys(%types))) {
22721: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22722: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22723: my $value = 'yes';
22724: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22725: $value = $env{'form.'.$prefix.'_'.$type};
22726: }
1.335 raeburn 22727: if (ref($domconfig{$action}) eq 'HASH') {
22728: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22729: if ($domconfig{$action}{$prefix}{$type} ne '') {
22730: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22731: $changes{$prefix}{$type} = 1;
22732: }
22733: $defaultshash{$action}{$prefix}{$type} = $value;
22734: } else {
22735: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22736: $changes{$prefix}{$type} = 1;
22737: }
22738: } else {
22739: $defaultshash{$action}{$prefix}{$type} = $value;
22740: $changes{$prefix}{$type} = 1;
22741: }
22742: } else {
22743: $defaultshash{$action}{$prefix}{$type} = $value;
22744: $changes{$prefix}{$type} = 1;
22745: }
22746: if (($type eq 'dom') && (keys(%servers) == 1)) {
22747: delete($changes{$prefix}{$type});
22748: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22749: delete($changes{$prefix}{$type});
22750: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22751: delete($changes{$prefix}{$type});
22752: }
22753: } elsif ($prefix eq 'replication') {
22754: if (@locations > 0) {
22755: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22756: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22757: my @okvals;
22758: foreach my $val (@vals) {
22759: if ($val =~ /:/) {
22760: my @items = split(/:/,$val);
22761: foreach my $item (@items) {
22762: if (ref($by_location{$item}) eq 'ARRAY') {
22763: push(@okvals,$item);
22764: }
22765: }
22766: } else {
22767: if (ref($by_location{$val}) eq 'ARRAY') {
22768: push(@okvals,$val);
22769: }
22770: }
22771: }
22772: @okvals = sort(@okvals);
22773: if (ref($domconfig{$action}) eq 'HASH') {
22774: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22775: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22776: if ($inuse == 0) {
22777: $changes{$prefix}{$type} = 1;
22778: } else {
22779: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22780: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22781: if (@changed > 0) {
22782: $changes{$prefix}{$type} = 1;
22783: }
22784: }
22785: } else {
22786: if ($inuse == 1) {
22787: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22788: $changes{$prefix}{$type} = 1;
22789: }
22790: }
22791: } else {
22792: if ($inuse == 1) {
22793: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22794: $changes{$prefix}{$type} = 1;
22795: }
22796: }
22797: } else {
22798: if ($inuse == 1) {
22799: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22800: $changes{$prefix}{$type} = 1;
22801: }
22802: }
22803: }
22804: }
22805: }
22806: }
1.336 raeburn 22807: if (keys(%changes)) {
22808: foreach my $prefix (keys(%changes)) {
22809: if (ref($changes{$prefix}) eq 'HASH') {
22810: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22811: delete($changes{$prefix});
22812: }
22813: } else {
22814: delete($changes{$prefix});
22815: }
22816: }
22817: }
1.275 raeburn 22818: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22819: if (keys(%changes) > 0) {
22820: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22821: $dom);
22822: if ($putresult eq 'ok') {
22823: if (ref($defaultshash{$action}) eq 'HASH') {
22824: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22825: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22826: }
1.293 raeburn 22827: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22828: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22829: }
22830: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22831: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22832: }
22833: }
22834: my $cachetime = 24*60*60;
22835: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22836: if (ref($lastactref) eq 'HASH') {
22837: $lastactref->{'domdefaults'} = 1;
22838: }
22839: if (keys(%changes) > 0) {
22840: my %titles = &ssl_titles();
22841: $resulttext = &mt('Changes made:').'<ul>';
22842: foreach my $prefix (@prefixes) {
22843: if (ref($changes{$prefix}) eq 'HASH') {
22844: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22845: foreach my $type (@{$types{$prefix}}) {
22846: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22847: my ($newvalue,$notinuse);
1.275 raeburn 22848: if (ref($defaultshash{$action}) eq 'HASH') {
22849: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22850: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22851: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22852: } else {
22853: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22854: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22855: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22856: }
22857: } else {
22858: $notinuse = 1;
1.275 raeburn 22859: }
22860: }
22861: }
1.344 raeburn 22862: if ($notinuse) {
22863: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22864: } elsif ($newvalue eq '') {
1.275 raeburn 22865: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22866: } else {
22867: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22868: }
22869: }
22870: }
22871: }
22872: $resulttext .= '</ul>';
22873: }
22874: }
22875: } else {
22876: $resulttext = $nochgmsg;
22877: }
22878: } else {
22879: $resulttext = '<span class="LC_error">'.
22880: &mt('An error occurred: [_1]',$putresult).'</span>';
22881: }
22882: } else {
22883: $resulttext = $nochgmsg;
22884: }
22885: return $resulttext;
22886: }
22887:
1.279 raeburn 22888: sub modify_trust {
22889: my ($dom,$lastactref,%domconfig) = @_;
22890: my (%by_ip,%by_location,@intdoms,@instdoms);
22891: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22892: my @locations = sort(keys(%by_location));
22893: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
22894: my @types = ('exc','inc');
22895: my (%defaultshash,%changes);
22896: foreach my $prefix (@prefixes) {
22897: $defaultshash{'trust'}{$prefix} = {};
22898: }
22899: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22900: my $resulttext;
22901: foreach my $prefix (@prefixes) {
22902: foreach my $type (@types) {
22903: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22904: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22905: my @okvals;
22906: foreach my $val (@vals) {
22907: if ($val =~ /:/) {
22908: my @items = split(/:/,$val);
22909: foreach my $item (@items) {
22910: if (ref($by_location{$item}) eq 'ARRAY') {
22911: push(@okvals,$item);
22912: }
22913: }
22914: } else {
22915: if (ref($by_location{$val}) eq 'ARRAY') {
22916: push(@okvals,$val);
22917: }
22918: }
22919: }
22920: @okvals = sort(@okvals);
22921: if (ref($domconfig{'trust'}) eq 'HASH') {
22922: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
22923: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22924: if ($inuse == 0) {
22925: $changes{$prefix}{$type} = 1;
22926: } else {
22927: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22928: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
22929: if (@changed > 0) {
22930: $changes{$prefix}{$type} = 1;
22931: }
22932: }
22933: } else {
22934: if ($inuse == 1) {
22935: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22936: $changes{$prefix}{$type} = 1;
22937: }
22938: }
22939: } else {
22940: if ($inuse == 1) {
22941: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22942: $changes{$prefix}{$type} = 1;
22943: }
22944: }
22945: } else {
22946: if ($inuse == 1) {
22947: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
22948: $changes{$prefix}{$type} = 1;
22949: }
22950: }
22951: }
22952: }
22953: my $nochgmsg = &mt('No changes made to trust settings.');
22954: if (keys(%changes) > 0) {
22955: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22956: $dom);
22957: if ($putresult eq 'ok') {
22958: if (ref($defaultshash{'trust'}) eq 'HASH') {
22959: foreach my $prefix (@prefixes) {
22960: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
22961: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
22962: }
22963: }
22964: }
22965: my $cachetime = 24*60*60;
22966: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 22967: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 22968: if (ref($lastactref) eq 'HASH') {
22969: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 22970: $lastactref->{'trust'} = 1;
1.279 raeburn 22971: }
22972: if (keys(%changes) > 0) {
22973: my %lt = &trust_titles();
22974: $resulttext = &mt('Changes made:').'<ul>';
22975: foreach my $prefix (@prefixes) {
22976: if (ref($changes{$prefix}) eq 'HASH') {
22977: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22978: foreach my $type (@types) {
22979: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22980: my ($newvalue,$notinuse);
1.279 raeburn 22981: if (ref($defaultshash{'trust'}) eq 'HASH') {
22982: if (ref($defaultshash{'trust'}{$prefix})) {
22983: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
22984: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
22985: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
22986: }
1.344 raeburn 22987: } else {
22988: $notinuse = 1;
1.279 raeburn 22989: }
22990: }
22991: }
1.344 raeburn 22992: if ($notinuse) {
22993: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
22994: } elsif ($newvalue eq '') {
1.279 raeburn 22995: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22996: } else {
22997: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
22998: }
22999: }
23000: }
23001: $resulttext .= '</ul>';
23002: }
23003: }
23004: $resulttext .= '</ul>';
23005: } else {
23006: $resulttext = $nochgmsg;
23007: }
23008: } else {
23009: $resulttext = '<span class="LC_error">'.
23010: &mt('An error occurred: [_1]',$putresult).'</span>';
23011: }
23012: } else {
23013: $resulttext = $nochgmsg;
23014: }
23015: return $resulttext;
23016: }
23017:
1.150 raeburn 23018: sub modify_loadbalancing {
23019: my ($dom,%domconfig) = @_;
23020: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23021: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23022: my ($othertitle,$usertypes,$types) =
23023: &Apache::loncommon::sorted_inst_types($dom);
23024: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23025: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23026: my @sparestypes = ('primary','default');
23027: my %typetitles = &sparestype_titles();
23028: my $resulttext;
1.342 raeburn 23029: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23030: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23031: %existing = %{$domconfig{'loadbalancing'}};
23032: }
23033: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23034: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23035: my ($saveloadbalancing,%defaultshash,%changes);
23036: my ($alltypes,$othertypes,$titles) =
23037: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23038: my %ruletitles = &offloadtype_text();
23039: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23040: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23041: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23042: if ($balancer eq '') {
23043: next;
23044: }
1.210 raeburn 23045: if (!exists($servers{$balancer})) {
1.171 raeburn 23046: if (exists($currbalancer{$balancer})) {
23047: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23048: }
1.171 raeburn 23049: next;
23050: }
23051: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23052: push(@{$changes{'delete'}},$balancer);
23053: next;
23054: }
23055: if (!exists($currbalancer{$balancer})) {
23056: push(@{$changes{'add'}},$balancer);
23057: }
23058: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23059: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23060: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23061: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23062: $saveloadbalancing = 1;
23063: }
23064: foreach my $sparetype (@sparestypes) {
23065: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23066: my @offloadto;
23067: foreach my $target (@targets) {
23068: if (($servers{$target}) && ($target ne $balancer)) {
23069: if ($sparetype eq 'default') {
23070: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23071: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23072: }
23073: }
1.171 raeburn 23074: unless(grep(/^\Q$target\E$/,@offloadto)) {
23075: push(@offloadto,$target);
23076: }
1.150 raeburn 23077: }
23078: }
1.284 raeburn 23079: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23080: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23081: push(@offloadto,$balancer);
23082: }
23083: }
23084: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23085: }
1.342 raeburn 23086: if ($env{'form.loadbalancing_cookie_'.$i}) {
23087: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23088: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23089: unless ($currcookies{$balancer}) {
23090: $changes{'curr'}{$balancer}{'cookie'} = 1;
23091: }
23092: }
23093: } elsif (exists($currbalancer{$balancer})) {
23094: if ($currcookies{$balancer}) {
23095: $changes{'curr'}{$balancer}{'cookie'} = 1;
23096: }
23097: }
1.171 raeburn 23098: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23099: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23100: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23101: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23102: if (@targetdiffs > 0) {
1.171 raeburn 23103: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23104: }
1.171 raeburn 23105: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23106: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23107: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23108: }
23109: }
23110: }
23111: } else {
1.171 raeburn 23112: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23113: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23114: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23115: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23116: $changes{'curr'}{$balancer}{'targets'} = 1;
23117: }
1.150 raeburn 23118: }
23119: }
1.210 raeburn 23120: }
1.150 raeburn 23121: }
23122: my $ishomedom;
1.171 raeburn 23123: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23124: $ishomedom = 1;
1.150 raeburn 23125: }
23126: if (ref($alltypes) eq 'ARRAY') {
23127: foreach my $type (@{$alltypes}) {
23128: my $rule;
1.210 raeburn 23129: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23130: (!$ishomedom)) {
1.171 raeburn 23131: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23132: }
23133: if ($rule eq 'specific') {
1.255 raeburn 23134: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23135: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23136: $rule = $specifiedhost;
23137: }
1.150 raeburn 23138: }
1.171 raeburn 23139: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23140: if (ref($currrules{$balancer}) eq 'HASH') {
23141: if ($rule ne $currrules{$balancer}{$type}) {
23142: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23143: }
23144: } elsif ($rule ne '') {
1.171 raeburn 23145: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23146: }
23147: }
23148: }
1.171 raeburn 23149: }
23150: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23151: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23152: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23153: $defaultshash{'loadbalancing'} = {};
23154: }
23155: my $putresult = &Apache::lonnet::put_dom('configuration',
23156: \%defaultshash,$dom);
23157: if ($putresult eq 'ok') {
23158: if (keys(%changes) > 0) {
1.252 raeburn 23159: my %toupdate;
1.171 raeburn 23160: if (ref($changes{'delete'}) eq 'ARRAY') {
23161: foreach my $balancer (sort(@{$changes{'delete'}})) {
23162: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23163: $toupdate{$balancer} = 1;
1.150 raeburn 23164: }
1.171 raeburn 23165: }
23166: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23167: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23168: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23169: $toupdate{$balancer} = 1;
1.171 raeburn 23170: }
23171: }
23172: if (ref($changes{'curr'}) eq 'HASH') {
23173: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23174: $toupdate{$balancer} = 1;
1.171 raeburn 23175: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23176: if ($changes{'curr'}{$balancer}{'targets'}) {
23177: my %offloadstr;
23178: foreach my $sparetype (@sparestypes) {
23179: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23180: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23181: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23182: }
23183: }
1.150 raeburn 23184: }
1.171 raeburn 23185: if (keys(%offloadstr) == 0) {
23186: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23187: } else {
1.171 raeburn 23188: my $showoffload;
23189: foreach my $sparetype (@sparestypes) {
23190: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23191: if (defined($offloadstr{$sparetype})) {
23192: $showoffload .= $offloadstr{$sparetype};
23193: } else {
23194: $showoffload .= &mt('None');
23195: }
23196: $showoffload .= (' 'x3);
23197: }
23198: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23199: }
23200: }
23201: }
1.171 raeburn 23202: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23203: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23204: foreach my $type (@{$alltypes}) {
23205: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23206: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23207: my $balancetext;
23208: if ($rule eq '') {
23209: $balancetext = $ruletitles{'default'};
1.209 raeburn 23210: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23211: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23212: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23213: foreach my $sparetype (@sparestypes) {
23214: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23215: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23216: }
23217: }
1.253 raeburn 23218: foreach my $item (@{$alltypes}) {
23219: next if ($item =~ /^_LC_ipchange/);
23220: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23221: if ($hasrule eq 'homeserver') {
23222: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23223: } else {
23224: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23225: if ($servers{$hasrule}) {
23226: $toupdate{$hasrule} = 1;
23227: }
23228: }
23229: }
23230: }
1.254 raeburn 23231: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23232: $balancetext = $ruletitles{$rule};
23233: } else {
23234: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23235: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23236: if ($receiver) {
23237: $toupdate{$receiver};
23238: }
23239: }
23240: } else {
23241: $balancetext = $ruletitles{$rule};
1.252 raeburn 23242: }
1.171 raeburn 23243: } else {
23244: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23245: }
1.210 raeburn 23246: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23247: }
23248: }
23249: }
23250: }
1.342 raeburn 23251: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23252: if ($currcookies{$balancer}) {
23253: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23254: $balancer).'</li>';
23255: } else {
23256: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23257: $balancer).'</li>';
23258: }
1.342 raeburn 23259: }
1.375 raeburn 23260: }
23261: }
23262: if (keys(%toupdate)) {
23263: my %thismachine;
23264: my $updatedhere;
23265: my $cachetime = 60*60*24;
23266: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23267: foreach my $lonhost (keys(%toupdate)) {
23268: if ($thismachine{$lonhost}) {
23269: unless ($updatedhere) {
23270: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23271: $defaultshash{'loadbalancing'},
23272: $cachetime);
23273: $updatedhere = 1;
1.252 raeburn 23274: }
1.375 raeburn 23275: } else {
23276: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23277: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23278: }
1.150 raeburn 23279: }
1.171 raeburn 23280: }
23281: if ($resulttext ne '') {
23282: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23283: } else {
23284: $resulttext = $nochgmsg;
23285: }
23286: } else {
1.171 raeburn 23287: $resulttext = $nochgmsg;
1.150 raeburn 23288: }
23289: } else {
1.171 raeburn 23290: $resulttext = '<span class="LC_error">'.
23291: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23292: }
23293: } else {
1.171 raeburn 23294: $resulttext = $nochgmsg;
1.150 raeburn 23295: }
23296: return $resulttext;
23297: }
23298:
1.48 raeburn 23299: sub recurse_check {
23300: my ($chkcats,$categories,$depth,$name) = @_;
23301: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23302: my $chg = 0;
23303: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23304: my $category = $chkcats->[$depth]{$name}[$j];
23305: my $item;
23306: if ($category eq '') {
23307: $chg ++;
23308: } else {
23309: my $deeper = $depth + 1;
23310: $item = &escape($category).':'.&escape($name).':'.$depth;
23311: if ($chg) {
23312: $categories->{$item} -= $chg;
23313: }
23314: &recurse_check($chkcats,$categories,$deeper,$category);
23315: $deeper --;
23316: }
23317: }
23318: }
23319: return;
23320: }
23321:
23322: sub recurse_cat_deletes {
23323: my ($item,$coursecategories,$deletions) = @_;
23324: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23325: my $subdepth = $depth + 1;
23326: if (ref($coursecategories) eq 'HASH') {
23327: foreach my $subitem (keys(%{$coursecategories})) {
23328: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23329: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23330: delete($coursecategories->{$subitem});
23331: $deletions->{$subitem} = 1;
23332: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23333: }
1.48 raeburn 23334: }
23335: }
23336: return;
23337: }
23338:
1.125 raeburn 23339: sub active_dc_picker {
1.191 raeburn 23340: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23341: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23342: my @domcoord = keys(%domcoords);
23343: if (keys(%currhash)) {
23344: foreach my $dc (keys(%currhash)) {
23345: unless (exists($domcoords{$dc})) {
23346: push(@domcoord,$dc);
23347: }
23348: }
23349: }
23350: @domcoord = sort(@domcoord);
1.210 raeburn 23351: my $numdcs = scalar(@domcoord);
1.191 raeburn 23352: my $rows = 0;
23353: my $table;
1.125 raeburn 23354: if ($numdcs > 1) {
1.191 raeburn 23355: $table = '<table>';
23356: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23357: my $rem = $i%($numinrow);
23358: if ($rem == 0) {
23359: if ($i > 0) {
1.191 raeburn 23360: $table .= '</tr>';
1.125 raeburn 23361: }
1.191 raeburn 23362: $table .= '<tr>';
23363: $rows ++;
1.125 raeburn 23364: }
1.191 raeburn 23365: my $check = '';
23366: if ($inputtype eq 'radio') {
23367: if (keys(%currhash) == 0) {
23368: if (!$i) {
23369: $check = ' checked="checked"';
23370: }
23371: } elsif (exists($currhash{$domcoord[$i]})) {
23372: $check = ' checked="checked"';
23373: }
23374: } else {
23375: if (exists($currhash{$domcoord[$i]})) {
23376: $check = ' checked="checked"';
1.125 raeburn 23377: }
23378: }
1.191 raeburn 23379: if ($i == @domcoord - 1) {
1.125 raeburn 23380: my $colsleft = $numinrow - $rem;
23381: if ($colsleft > 1) {
1.191 raeburn 23382: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23383: } else {
1.191 raeburn 23384: $table .= '<td class="LC_left_item">';
1.125 raeburn 23385: }
23386: } else {
1.191 raeburn 23387: $table .= '<td class="LC_left_item">';
23388: }
23389: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23390: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23391: $table .= '<span class="LC_nobreak"><label>'.
23392: '<input type="'.$inputtype.'" name="'.$name.'"'.
23393: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23394: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23395: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23396: }
1.219 raeburn 23397: $table .= '</label></span></td>';
1.191 raeburn 23398: }
23399: $table .= '</tr></table>';
23400: } elsif ($numdcs == 1) {
1.219 raeburn 23401: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23402: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23403: if ($inputtype eq 'radio') {
1.247 raeburn 23404: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23405: if ($user ne $dcname.':'.$dcdom) {
23406: $table .= ' ('.$dcname.':'.$dcdom.')';
23407: }
1.191 raeburn 23408: } else {
23409: my $check;
23410: if (exists($currhash{$domcoord[0]})) {
23411: $check = ' checked="checked"';
1.125 raeburn 23412: }
1.247 raeburn 23413: $table = '<span class="LC_nobreak"><label>'.
23414: '<input type="checkbox" name="'.$name.'" '.
23415: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23416: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23417: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23418: }
1.220 raeburn 23419: $table .= '</label></span>';
1.191 raeburn 23420: $rows ++;
1.125 raeburn 23421: }
23422: }
1.191 raeburn 23423: return ($numdcs,$table,$rows);
1.125 raeburn 23424: }
23425:
1.137 raeburn 23426: sub usersession_titles {
23427: return &Apache::lonlocal::texthash(
23428: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23429: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23430: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23431: version => 'LON-CAPA version requirement',
1.138 raeburn 23432: excludedomain => 'Allow all, but exclude specific domains',
23433: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23434: primary => 'Primary (checked first)',
1.154 raeburn 23435: default => 'Default',
1.137 raeburn 23436: );
23437: }
23438:
1.152 raeburn 23439: sub id_for_thisdom {
23440: my (%servers) = @_;
23441: my %altids;
23442: foreach my $server (keys(%servers)) {
23443: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23444: if ($serverhome ne $server) {
23445: $altids{$serverhome} = $server;
23446: }
23447: }
23448: return %altids;
23449: }
23450:
1.150 raeburn 23451: sub count_servers {
23452: my ($currbalancer,%servers) = @_;
23453: my (@spares,$numspares);
23454: foreach my $lonhost (sort(keys(%servers))) {
23455: next if ($currbalancer eq $lonhost);
23456: push(@spares,$lonhost);
23457: }
23458: if ($currbalancer) {
23459: $numspares = scalar(@spares);
23460: } else {
23461: $numspares = scalar(@spares) - 1;
23462: }
23463: return ($numspares,@spares);
23464: }
23465:
23466: sub lonbalance_targets_js {
1.171 raeburn 23467: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23468: my $select = &mt('Select');
23469: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23470: if (ref($servers) eq 'HASH') {
23471: $alltargets = join("','",sort(keys(%{$servers})));
23472: my @homedoms;
23473: foreach my $server (sort(keys(%{$servers}))) {
23474: if (&Apache::lonnet::host_domain($server) eq $dom) {
23475: push(@homedoms,'1');
23476: } else {
23477: push(@homedoms,'0');
23478: }
23479: }
23480: $allishome = join("','",@homedoms);
23481: }
23482: if (ref($types) eq 'ARRAY') {
23483: if (@{$types} > 0) {
23484: @alltypes = @{$types};
23485: }
23486: }
23487: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23488: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23489: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23490: if (ref($settings) eq 'HASH') {
23491: %existing = %{$settings};
23492: }
23493: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23494: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23495: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23496: return <<"END";
23497:
23498: <script type="text/javascript">
23499: // <![CDATA[
23500:
1.171 raeburn 23501: currBalancers = new Array('$balancers');
23502:
23503: function toggleTargets(balnum) {
23504: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23505: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23506: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23507: var prevbalancer = prevhostitem.value;
23508: var baltotal = document.getElementById('loadbalancing_total').value;
23509: prevhostitem.value = balancer;
23510: if (prevbalancer != '') {
23511: var prevIdx = currBalancers.indexOf(prevbalancer);
23512: if (prevIdx != -1) {
23513: currBalancers.splice(prevIdx,1);
23514: }
23515: }
1.150 raeburn 23516: if (balancer == '') {
1.171 raeburn 23517: hideSpares(balnum);
1.150 raeburn 23518: } else {
1.171 raeburn 23519: var currIdx = currBalancers.indexOf(balancer);
23520: if (currIdx == -1) {
23521: currBalancers.push(balancer);
23522: }
1.150 raeburn 23523: var homedoms = new Array('$allishome');
1.171 raeburn 23524: var ishomedom = homedoms[lonhostitem.selectedIndex];
23525: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23526: }
1.171 raeburn 23527: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23528: return;
23529: }
23530:
1.171 raeburn 23531: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23532: var alltargets = new Array('$alltargets');
23533: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23534: var offloadtypes = new Array('primary','default');
23535:
1.171 raeburn 23536: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23537: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23538:
1.151 raeburn 23539: for (var i=0; i<offloadtypes.length; i++) {
23540: var count = 0;
23541: for (var j=0; j<alltargets.length; j++) {
23542: if (alltargets[j] != balancer) {
1.171 raeburn 23543: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23544: item.value = alltargets[j];
23545: item.style.textAlign='left';
23546: item.style.textFace='normal';
23547: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23548: if (currBalancers.indexOf(alltargets[j]) == -1) {
23549: item.disabled = '';
23550: } else {
23551: item.disabled = 'disabled';
23552: item.checked = false;
23553: }
1.151 raeburn 23554: count ++;
23555: }
1.150 raeburn 23556: }
23557: }
1.151 raeburn 23558: for (var k=0; k<insttypes.length; k++) {
23559: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23560: if (ishomedom == 1) {
1.171 raeburn 23561: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23562: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23563: } else {
1.171 raeburn 23564: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23565: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23566: }
23567: } else {
1.171 raeburn 23568: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23569: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23570: }
1.151 raeburn 23571: if ((insttypes[k] != '_LC_external') &&
23572: ((insttypes[k] != '_LC_internetdom') ||
23573: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23574: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23575: item.options.length = 0;
23576: item.options[0] = new Option("","",true,true);
1.210 raeburn 23577: var idx = 0;
1.151 raeburn 23578: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23579: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23580: idx ++;
23581: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23582: }
23583: }
23584: }
23585: }
23586: return;
23587: }
23588:
1.171 raeburn 23589: function hideSpares(balnum) {
1.150 raeburn 23590: var alltargets = new Array('$alltargets');
23591: var insttypes = new Array('$allinsttypes');
23592: var offloadtypes = new Array('primary','default');
23593:
1.171 raeburn 23594: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23595: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23596:
23597: var total = alltargets.length - 1;
23598: for (var i=0; i<offloadtypes; i++) {
23599: for (var j=0; j<total; j++) {
1.171 raeburn 23600: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23601: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23602: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23603: }
1.150 raeburn 23604: }
23605: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23606: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23607: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23608: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23609: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23610: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23611: }
23612: }
23613: return;
23614: }
23615:
1.171 raeburn 23616: function checkOffloads(item,balnum,type) {
1.150 raeburn 23617: var alltargets = new Array('$alltargets');
23618: var offloadtypes = new Array('primary','default');
23619: if (item.checked) {
23620: var total = alltargets.length - 1;
23621: var other;
23622: if (type == offloadtypes[0]) {
1.151 raeburn 23623: other = offloadtypes[1];
1.150 raeburn 23624: } else {
1.151 raeburn 23625: other = offloadtypes[0];
1.150 raeburn 23626: }
23627: for (var i=0; i<total; i++) {
1.171 raeburn 23628: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23629: if (server == item.value) {
1.171 raeburn 23630: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23631: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23632: }
23633: }
23634: }
23635: }
23636: return;
23637: }
23638:
1.171 raeburn 23639: function singleServerToggle(balnum,type) {
23640: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23641: if (offloadtoSelIdx == 0) {
1.171 raeburn 23642: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23643: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23644:
23645: } else {
1.171 raeburn 23646: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23647: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23648: }
23649: return;
23650: }
23651:
1.171 raeburn 23652: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23653: if (type == '_LC_external') {
1.171 raeburn 23654: return;
1.150 raeburn 23655: }
1.171 raeburn 23656: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23657: for (var i=0; i<typesRules.length; i++) {
23658: if (formname.elements[typesRules[i]].checked) {
23659: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23660: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23661: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23662: } else {
1.171 raeburn 23663: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23664: }
23665: }
23666: }
23667: return;
23668: }
23669:
23670: function balancerDeleteChange(balnum) {
23671: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23672: var baltotal = document.getElementById('loadbalancing_total').value;
23673: var addtarget;
23674: var removetarget;
23675: var action = 'delete';
23676: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23677: var lonhost = hostitem.value;
23678: var currIdx = currBalancers.indexOf(lonhost);
23679: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23680: if (currIdx != -1) {
23681: currBalancers.splice(currIdx,1);
23682: }
23683: addtarget = lonhost;
23684: } else {
23685: if (currIdx == -1) {
23686: currBalancers.push(lonhost);
23687: }
23688: removetarget = lonhost;
23689: action = 'undelete';
23690: }
23691: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23692: }
23693: return;
23694: }
23695:
23696: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23697: if (baltotal > 1) {
23698: var offloadtypes = new Array('primary','default');
23699: var alltargets = new Array('$alltargets');
23700: var insttypes = new Array('$allinsttypes');
23701: for (var i=0; i<baltotal; i++) {
23702: if (i != balnum) {
23703: for (var j=0; j<offloadtypes.length; j++) {
23704: var total = alltargets.length - 1;
23705: for (var k=0; k<total; k++) {
23706: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23707: var server = serveritem.value;
23708: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23709: if (server == addtarget) {
23710: serveritem.disabled = '';
23711: }
23712: }
23713: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23714: if (server == removetarget) {
23715: serveritem.disabled = 'disabled';
23716: serveritem.checked = false;
23717: }
23718: }
23719: }
23720: }
23721: for (var j=0; j<insttypes.length; j++) {
23722: if (insttypes[j] != '_LC_external') {
23723: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23724: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23725: var currSel = singleserver.selectedIndex;
23726: var currVal = singleserver.options[currSel].value;
23727: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23728: var numoptions = singleserver.options.length;
23729: var needsnew = 1;
23730: for (var k=0; k<numoptions; k++) {
23731: if (singleserver.options[k] == addtarget) {
23732: needsnew = 0;
23733: break;
23734: }
23735: }
23736: if (needsnew == 1) {
23737: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23738: }
23739: }
23740: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23741: singleserver.options.length = 0;
23742: if ((currVal) && (currVal != removetarget)) {
23743: singleserver.options[0] = new Option("","",false,false);
23744: } else {
23745: singleserver.options[0] = new Option("","",true,true);
23746: }
23747: var idx = 0;
23748: for (var m=0; m<alltargets.length; m++) {
23749: if (currBalancers.indexOf(alltargets[m]) == -1) {
23750: idx ++;
23751: if (currVal == alltargets[m]) {
23752: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23753: } else {
23754: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23755: }
23756: }
23757: }
23758: }
23759: }
23760: }
23761: }
1.150 raeburn 23762: }
23763: }
23764: }
23765: return;
23766: }
23767:
1.152 raeburn 23768: // ]]>
23769: </script>
23770:
23771: END
23772: }
23773:
23774: sub new_spares_js {
23775: my @sparestypes = ('primary','default');
23776: my $types = join("','",@sparestypes);
23777: my $select = &mt('Select');
23778: return <<"END";
23779:
23780: <script type="text/javascript">
23781: // <![CDATA[
23782:
23783: function updateNewSpares(formname,lonhost) {
23784: var types = new Array('$types');
23785: var include = new Array();
23786: var exclude = new Array();
23787: for (var i=0; i<types.length; i++) {
23788: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23789: for (var j=0; j<spareboxes.length; j++) {
23790: if (formname.elements[spareboxes[j]].checked) {
23791: exclude.push(formname.elements[spareboxes[j]].value);
23792: } else {
23793: include.push(formname.elements[spareboxes[j]].value);
23794: }
23795: }
23796: }
23797: for (var i=0; i<types.length; i++) {
23798: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23799: var selIdx = newSpare.selectedIndex;
23800: var currnew = newSpare.options[selIdx].value;
23801: var okSpares = new Array();
23802: for (var j=0; j<newSpare.options.length; j++) {
23803: var possible = newSpare.options[j].value;
23804: if (possible != '') {
23805: if (exclude.indexOf(possible) == -1) {
23806: okSpares.push(possible);
23807: } else {
23808: if (currnew == possible) {
23809: selIdx = 0;
23810: }
23811: }
23812: }
23813: }
23814: for (var k=0; k<include.length; k++) {
23815: if (okSpares.indexOf(include[k]) == -1) {
23816: okSpares.push(include[k]);
23817: }
23818: }
23819: okSpares.sort();
23820: newSpare.options.length = 0;
23821: if (selIdx == 0) {
23822: newSpare.options[0] = new Option("$select","",true,true);
23823: } else {
23824: newSpare.options[0] = new Option("$select","",false,false);
23825: }
23826: for (var m=0; m<okSpares.length; m++) {
23827: var idx = m+1;
23828: var selThis = 0;
23829: if (selIdx != 0) {
23830: if (okSpares[m] == currnew) {
23831: selThis = 1;
23832: }
23833: }
23834: if (selThis == 1) {
23835: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23836: } else {
23837: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23838: }
23839: }
23840: }
23841: return;
23842: }
23843:
23844: function checkNewSpares(lonhost,type) {
23845: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23846: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23847: if (chosen != '') {
1.152 raeburn 23848: var othertype;
23849: var othernewSpare;
23850: if (type == 'primary') {
23851: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23852: }
23853: if (type == 'default') {
23854: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23855: }
23856: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23857: othernewSpare.selectedIndex = 0;
23858: }
23859: }
23860: return;
23861: }
23862:
23863: // ]]>
23864: </script>
23865:
23866: END
23867:
23868: }
23869:
23870: sub common_domprefs_js {
23871: return <<"END";
23872:
23873: <script type="text/javascript">
23874: // <![CDATA[
23875:
1.150 raeburn 23876: function getIndicesByName(formname,item) {
1.152 raeburn 23877: var group = new Array();
1.150 raeburn 23878: for (var i=0;i<formname.elements.length;i++) {
23879: if (formname.elements[i].name == item) {
1.152 raeburn 23880: group.push(formname.elements[i].id);
1.150 raeburn 23881: }
23882: }
1.152 raeburn 23883: return group;
1.150 raeburn 23884: }
23885:
23886: // ]]>
23887: </script>
23888:
23889: END
1.152 raeburn 23890:
1.150 raeburn 23891: }
23892:
1.165 raeburn 23893: sub recaptcha_js {
23894: my %lt = &captcha_phrases();
23895: return <<"END";
23896:
23897: <script type="text/javascript">
23898: // <![CDATA[
23899:
23900: function updateCaptcha(caller,context) {
23901: var privitem;
23902: var pubitem;
23903: var privtext;
23904: var pubtext;
1.269 raeburn 23905: var versionitem;
23906: var versiontext;
1.165 raeburn 23907: if (document.getElementById(context+'_recaptchapub')) {
23908: pubitem = document.getElementById(context+'_recaptchapub');
23909: } else {
23910: return;
23911: }
23912: if (document.getElementById(context+'_recaptchapriv')) {
23913: privitem = document.getElementById(context+'_recaptchapriv');
23914: } else {
23915: return;
23916: }
23917: if (document.getElementById(context+'_recaptchapubtxt')) {
23918: pubtext = document.getElementById(context+'_recaptchapubtxt');
23919: } else {
23920: return;
23921: }
23922: if (document.getElementById(context+'_recaptchaprivtxt')) {
23923: privtext = document.getElementById(context+'_recaptchaprivtxt');
23924: } else {
23925: return;
23926: }
1.269 raeburn 23927: if (document.getElementById(context+'_recaptchaversion')) {
23928: versionitem = document.getElementById(context+'_recaptchaversion');
23929: } else {
23930: return;
23931: }
23932: if (document.getElementById(context+'_recaptchavertxt')) {
23933: versiontext = document.getElementById(context+'_recaptchavertxt');
23934: } else {
23935: return;
23936: }
1.165 raeburn 23937: if (caller.checked) {
23938: if (caller.value == 'recaptcha') {
23939: pubitem.type = 'text';
23940: privitem.type = 'text';
23941: pubitem.size = '40';
23942: privitem.size = '40';
23943: pubtext.innerHTML = "$lt{'pub'}";
23944: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 23945: versionitem.type = 'text';
23946: versionitem.size = '3';
1.289 raeburn 23947: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 23948: } else {
23949: pubitem.type = 'hidden';
23950: privitem.type = 'hidden';
1.269 raeburn 23951: versionitem.type = 'hidden';
1.165 raeburn 23952: pubtext.innerHTML = '';
23953: privtext.innerHTML = '';
1.269 raeburn 23954: versiontext.innerHTML = '';
1.165 raeburn 23955: }
23956: }
23957: return;
23958: }
23959:
23960: // ]]>
23961: </script>
23962:
23963: END
23964:
23965: }
23966:
1.236 raeburn 23967: sub toggle_display_js {
1.192 raeburn 23968: return <<"END";
23969:
23970: <script type="text/javascript">
23971: // <![CDATA[
23972:
1.236 raeburn 23973: function toggleDisplay(domForm,caller) {
23974: if (document.getElementById(caller)) {
23975: var divitem = document.getElementById(caller);
23976: var optionsElement = domForm.coursecredits;
1.264 raeburn 23977: var checkval = 1;
23978: var dispval = 'block';
1.303 raeburn 23979: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 23980: if (caller == 'emailoptions') {
1.372 raeburn 23981: optionsElement = domForm.cancreate_email;
1.236 raeburn 23982: }
1.257 raeburn 23983: if (caller == 'studentsubmission') {
23984: optionsElement = domForm.postsubmit;
23985: }
1.264 raeburn 23986: if (caller == 'cloneinstcode') {
23987: optionsElement = domForm.canclone;
23988: checkval = 'instcode';
23989: }
1.303 raeburn 23990: if (selfcreateRegExp.test(caller)) {
23991: optionsElement = domForm.elements[caller];
23992: checkval = 'other';
23993: dispval = 'inline'
23994: }
1.236 raeburn 23995: if (optionsElement.length) {
1.192 raeburn 23996: var currval;
1.236 raeburn 23997: for (var i=0; i<optionsElement.length; i++) {
23998: if (optionsElement[i].checked) {
23999: currval = optionsElement[i].value;
1.192 raeburn 24000: }
24001: }
1.264 raeburn 24002: if (currval == checkval) {
24003: divitem.style.display = dispval;
1.192 raeburn 24004: } else {
1.236 raeburn 24005: divitem.style.display = 'none';
1.192 raeburn 24006: }
24007: }
24008: }
24009: return;
24010: }
24011:
24012: // ]]>
24013: </script>
24014:
24015: END
24016:
24017: }
24018:
1.165 raeburn 24019: sub captcha_phrases {
24020: return &Apache::lonlocal::texthash (
24021: priv => 'Private key',
24022: pub => 'Public key',
24023: original => 'original (CAPTCHA)',
24024: recaptcha => 'successor (ReCAPTCHA)',
24025: notused => 'unused',
1.289 raeburn 24026: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24027: );
24028: }
24029:
1.205 raeburn 24030: sub devalidate_remote_domconfs {
1.212 raeburn 24031: my ($dom,$cachekeys) = @_;
24032: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24033: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24034: my %thismachine;
24035: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24036: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24037: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24038: 'ipaccess','trust');
1.386 raeburn 24039: my %cache_by_lonhost;
24040: if (exists($cachekeys->{'samllanding'})) {
24041: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24042: my %landing = %{$cachekeys->{'samllanding'}};
24043: my %domservers = &Apache::lonnet::get_servers($dom);
24044: if (keys(%domservers)) {
24045: foreach my $server (keys(%domservers)) {
24046: my @cached;
24047: next if ($thismachine{$server});
24048: if ($landing{$server}) {
24049: push(@cached,&escape('samllanding').':'.&escape($server));
24050: }
24051: if (@cached) {
24052: $cache_by_lonhost{$server} = \@cached;
24053: }
24054: }
24055: }
24056: }
24057: }
1.260 raeburn 24058: if (keys(%servers)) {
1.205 raeburn 24059: foreach my $server (keys(%servers)) {
24060: next if ($thismachine{$server});
1.212 raeburn 24061: my @cached;
24062: foreach my $name (@posscached) {
24063: if ($cachekeys->{$name}) {
1.388 raeburn 24064: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24065: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24066: foreach my $key (keys(%{$cachekeys->{$name}})) {
24067: push(@cached,&escape($name).':'.&escape($key));
24068: }
24069: }
24070: } else {
24071: push(@cached,&escape($name).':'.&escape($dom));
24072: }
1.212 raeburn 24073: }
24074: }
1.386 raeburn 24075: if ((exists($cache_by_lonhost{$server})) &&
24076: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24077: push(@cached,@{$cache_by_lonhost{$server}});
24078: }
1.212 raeburn 24079: if (@cached) {
24080: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24081: }
1.205 raeburn 24082: }
24083: }
24084: return;
24085: }
24086:
1.3 raeburn 24087: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>