Annotation of loncom/interface/domainprefs.pm, revision 1.443
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.443 ! raeburn 4: # $Id: domainprefs.pm,v 1.442 2024/07/14 16:08:04 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.443 ! raeburn 475: col2 => 'User information updatable by co-author manager'},
! 476: {col1 => 'Target user has role',
1.227 bisitz 477: col2 => 'User information updatable in course context'}],
1.230 raeburn 478: print => \&print_usermodification,
479: modify => \&modify_usermodification,
1.33 raeburn 480: },
1.69 raeburn 481: 'scantron' =>
1.346 raeburn 482: { text => 'Bubblesheet format',
1.67 raeburn 483: help => 'Domain_Configuration_Scantron_Format',
1.346 raeburn 484: header => [ {col1 => 'Bubblesheet format file',
485: col2 => ''},
486: {col1 => 'Bubblesheet data upload formats',
487: col2 => 'Settings'}],
1.230 raeburn 488: print => \&print_scantron,
489: modify => \&modify_scantron,
1.46 raeburn 490: },
1.86 raeburn 491: 'requestcourses' =>
492: {text => 'Request creation of courses',
493: help => 'Domain_Configuration_Request_Courses',
494: header => [{col1 => 'User affiliation',
1.102 raeburn 495: col2 => 'Availability/Processing of requests',},
496: {col1 => 'Setting',
1.216 raeburn 497: col2 => 'Value'},
498: {col1 => 'Available textbooks',
1.235 raeburn 499: col2 => ''},
1.242 raeburn 500: {col1 => 'Available templates',
501: col2 => ''},
1.235 raeburn 502: {col1 => 'Validation (not official courses)',
503: col2 => 'Value'},],
1.230 raeburn 504: print => \&print_quotas,
505: modify => \&modify_quotas,
1.86 raeburn 506: },
1.163 raeburn 507: 'requestauthor' =>
1.223 bisitz 508: {text => 'Request Authoring Space',
1.163 raeburn 509: help => 'Domain_Configuration_Request_Author',
510: header => [{col1 => 'User affiliation',
511: col2 => 'Availability/Processing of requests',},
512: {col1 => 'Setting',
513: col2 => 'Value'}],
1.230 raeburn 514: print => \&print_quotas,
515: modify => \&modify_quotas,
1.163 raeburn 516: },
1.69 raeburn 517: 'coursecategories' =>
1.120 raeburn 518: { text => 'Cataloging of courses/communities',
1.67 raeburn 519: help => 'Domain_Configuration_Cataloging_Courses',
1.238 raeburn 520: header => [{col1 => 'Catalog type/availability',
521: col2 => '',},
522: {col1 => 'Category settings for standard catalog',
1.57 raeburn 523: col2 => '',},
524: {col1 => 'Categories',
525: col2 => '',
526: }],
1.230 raeburn 527: print => \&print_coursecategories,
528: modify => \&modify_coursecategories,
1.69 raeburn 529: },
530: 'serverstatuses' =>
1.77 raeburn 531: {text => 'Access to server status pages',
1.69 raeburn 532: help => 'Domain_Configuration_Server_Status',
533: header => [{col1 => 'Status Page',
534: col2 => 'Other named users',
535: col3 => 'Specific IPs',
536: }],
1.230 raeburn 537: print => \&print_serverstatuses,
538: modify => \&modify_serverstatuses,
1.69 raeburn 539: },
1.118 jms 540: 'helpsettings' =>
1.282 raeburn 541: {text => 'Support settings',
1.118 jms 542: help => 'Domain_Configuration_Help_Settings',
1.282 raeburn 543: header => [{col1 => 'Help Page Settings (logged-in users)',
544: col2 => 'Value'},
545: {col1 => 'Helpdesk Roles',
546: col2 => 'Settings'},],
1.230 raeburn 547: print => \&print_helpsettings,
548: modify => \&modify_helpsettings,
1.118 jms 549: },
1.121 raeburn 550: 'coursedefaults' =>
551: {text => 'Course/Community defaults',
552: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 553: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
554: col2 => 'Value',},
555: {col1 => 'Defaults which can be overridden for each course by a DC',
556: col2 => 'Value',},],
1.230 raeburn 557: print => \&print_coursedefaults,
558: modify => \&modify_coursedefaults,
1.121 raeburn 559: },
1.231 raeburn 560: 'selfenrollment' =>
561: {text => 'Self-enrollment in Course/Community',
562: help => 'Domain_Configuration_Selfenrollment',
563: header => [{col1 => 'Configuration Rights',
564: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
565: {col1 => 'Defaults',
566: col2 => 'Value'},
567: {col1 => 'Self-enrollment validation (optional)',
568: col2 => 'Value'},],
569: print => \&print_selfenrollment,
570: modify => \&modify_selfenrollment,
571: },
1.120 raeburn 572: 'privacy' =>
1.427 raeburn 573: {text => 'Role assignments and user privacy',
1.120 raeburn 574: help => 'Domain_Configuration_User_Privacy',
1.357 raeburn 575: header => [{col1 => 'Role assigned in different domain',
576: col2 => 'Approval options'},
577: {col1 => 'Role assigned in different domain to user of type',
578: col2 => 'User information available in that domain'},
579: {col1 => "Role assigned in user's domain",
580: col2 => 'Information viewable by privileged user'},
581: {col1 => "Role assigned in user's domain",
582: col2 => 'Information viewable by unprivileged user'}],
1.230 raeburn 583: print => \&print_privacy,
584: modify => \&modify_privacy,
1.120 raeburn 585: },
1.141 raeburn 586: 'usersessions' =>
1.145 raeburn 587: {text => 'User session hosting/offloading',
1.137 raeburn 588: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 589: header => [{col1 => 'Domain server',
590: col2 => 'Servers to offload sessions to when busy'},
591: {col1 => 'Hosting of users from other domains',
1.137 raeburn 592: col2 => 'Rules'},
593: {col1 => "Hosting domain's own users elsewhere",
594: col2 => 'Rules'}],
1.230 raeburn 595: print => \&print_usersessions,
596: modify => \&modify_usersessions,
1.137 raeburn 597: },
1.279 raeburn 598: 'loadbalancing' =>
1.185 raeburn 599: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 600: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 601: header => [{col1 => 'Balancers',
1.150 raeburn 602: col2 => 'Default destinations',
1.183 bisitz 603: col3 => 'User affiliation',
1.150 raeburn 604: col4 => 'Overrides'},
605: ],
1.230 raeburn 606: print => \&print_loadbalancing,
607: modify => \&modify_loadbalancing,
1.150 raeburn 608: },
1.425 raeburn 609: 'ltitools' =>
1.267 raeburn 610: {text => 'External Tools (LTI)',
1.296 raeburn 611: help => 'Domain_Configuration_LTI_Tools',
1.421 raeburn 612: header => [{col1 => 'Encryption of shared secrets',
613: col2 => 'Settings'},
614: {col1 => 'Rules for shared secrets',
615: col2 => 'Settings'},
616: {col1 => 'Providers',
617: col2 => 'Settings',}],
1.267 raeburn 618: print => \&print_ltitools,
619: modify => \&modify_ltitools,
620: },
1.372 raeburn 621: 'proctoring' =>
622: {text => 'Remote Proctoring Integration',
623: help => 'Domain_Configuration_Proctoring',
624: header => [{col1 => 'Name',
625: col2 => 'Configuration'}],
626: print => \&print_proctoring,
627: modify => \&modify_proctoring,
628: },
1.279 raeburn 629: 'ssl' =>
1.275 raeburn 630: {text => 'LON-CAPA Network (SSL)',
631: help => 'Domain_Configuration_Network_SSL',
632: header => [{col1 => 'Server',
633: col2 => 'Certificate Status'},
634: {col1 => 'Connections to other servers',
635: col2 => 'Rules'},
1.293 raeburn 636: {col1 => 'Connections from other servers',
637: col2 => 'Rules'},
1.275 raeburn 638: {col1 => "Replicating domain's published content",
639: col2 => 'Rules'}],
640: print => \&print_ssl,
641: modify => \&modify_ssl,
642: },
1.279 raeburn 643: 'trust' =>
644: {text => 'Trust Settings',
645: help => 'Domain_Configuration_Trust',
646: header => [{col1 => "Access to this domain's content by others",
647: col2 => 'Rules'},
648: {col1 => "Access to other domain's content by this domain",
649: col2 => 'Rules'},
650: {col1 => "Enrollment in this domain's courses by others",
651: col2 => 'Rules',},
652: {col1 => "Co-author roles in this domain for others",
653: col2 => 'Rules',},
654: {col1 => "Co-author roles for this domain's users elsewhere",
655: col2 => 'Rules',},
656: {col1 => "Domain roles in this domain assignable to others",
657: col2 => 'Rules'},
658: {col1 => "Course catalog for this domain displayed elsewhere",
659: col2 => 'Rules'},
660: {col1 => "Requests for creation of courses in this domain by others",
661: col2 => 'Rules'},
662: {col1 => "Users in other domains can send messages to this domain",
663: col2 => 'Rules'},],
664: print => \&print_trust,
665: modify => \&modify_trust,
666: },
1.425 raeburn 667: 'lti' =>
1.405 raeburn 668: {text => 'LTI Link Protection and LTI Consumers',
1.320 raeburn 669: help => 'Domain_Configuration_LTI_Provider',
1.405 raeburn 670: header => [{col1 => 'Encryption of shared secrets',
671: col2 => 'Settings'},
1.425 raeburn 672: {col1 => 'Rules for shared secrets',
1.405 raeburn 673: col2 => 'Settings'},
1.434 raeburn 674: {col1 => 'Link Protectors in Courses',
1.436 raeburn 675: col2 => 'Values'},
1.406 raeburn 676: {col1 => 'Link Protectors',
1.405 raeburn 677: col2 => 'Settings'},
678: {col1 => 'Consumers',
679: col2 => 'Settings'},],
1.320 raeburn 680: print => \&print_lti,
681: modify => \&modify_lti,
682: },
1.425 raeburn 683: 'ipaccess' =>
1.394 raeburn 684: {text => 'IP-based access control',
685: help => 'Domain_Configuration_IP_Access',
686: header => [{col1 => 'Setting',
687: col2 => 'Value'},],
688: print => \&print_ipaccess,
689: modify => \&modify_ipaccess,
690: },
1.436 raeburn 691: 'authordefaults' =>
1.429 raeburn 692: {text => 'Authoring Space defaults',
693: help => 'Domain_Configuration_Author_Defaults',
694: header => [{col1 => 'Defaults which can be overridden by Author',
695: col2 => 'Settings',},
696: {col1 => 'Defaults which can be overridden by a Dom. Coord.',
697: col2 => 'Settings',},],
698: print => \&print_authordefaults,
699: modify => \&modify_authordefaults,
700: },
1.3 raeburn 701: );
1.110 raeburn 702: if (keys(%servers) > 1) {
703: $prefs{'login'} = { text => 'Log-in page options',
704: help => 'Domain_Configuration_Login_Page',
705: header => [{col1 => 'Log-in Service',
706: col2 => 'Server Setting',},
707: {col1 => 'Log-in Page Items',
1.405 raeburn 708: col2 => 'Settings'},
1.168 raeburn 709: {col1 => 'Log-in Help',
1.256 raeburn 710: col2 => 'Value'},
711: {col1 => 'Custom HTML in document head',
1.386 raeburn 712: col2 => 'Value'},
713: {col1 => 'SSO',
714: col2 => 'Dual login: SSO and non-SSO options'},
715: ],
1.230 raeburn 716: print => \&print_login,
717: modify => \&modify_login,
1.110 raeburn 718: };
719: }
1.174 foxr 720:
1.6 raeburn 721: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 722: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 723: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 724: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 725: text=>"Settings to display/modify"});
1.9 raeburn 726: my $confname = $dom.'-domainconfig';
1.174 foxr 727:
1.3 raeburn 728: if ($phase eq 'process') {
1.212 raeburn 729: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
730: \%prefs,\%domconfig,$confname,\@roles);
1.224 raeburn 731: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.205 raeburn 732: $r->rflush();
1.212 raeburn 733: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 734: }
1.30 raeburn 735: } elsif ($phase eq 'display') {
1.192 raeburn 736: my $js = &recaptcha_js().
1.236 raeburn 737: &toggle_display_js();
1.171 raeburn 738: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 739: my ($othertitle,$usertypes,$types) =
740: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 741: $js .= &lonbalance_targets_js($dom,$types,\%servers,
742: $domconfig{'loadbalancing'}).
1.170 raeburn 743: &new_spares_js().
744: &common_domprefs_js().
745: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 746: }
1.216 raeburn 747: if (grep(/^requestcourses$/,@actions)) {
748: my $javascript_validations;
749: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
750: $js .= <<END;
751: <script type="text/javascript">
752: $javascript_validations
753: </script>
754: $coursebrowserjs
755: END
1.394 raeburn 756: } elsif (grep(/^ipaccess$/,@actions)) {
757: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.216 raeburn 758: }
1.305 raeburn 759: if (grep(/^selfcreation$/,@actions)) {
760: $js .= &selfcreate_javascript();
761: }
1.286 raeburn 762: if (grep(/^contacts$/,@actions)) {
763: $js .= &contacts_javascript();
764: }
1.346 raeburn 765: if (grep(/^scantron$/,@actions)) {
766: $js .= &scantron_javascript();
767: }
1.150 raeburn 768: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 769: } else {
1.180 raeburn 770: # check if domconfig user exists for the domain.
771: my $servadm = $r->dir_config('lonAdmEMail');
772: my ($configuserok,$author_ok,$switchserver) =
773: &config_check($dom,$confname,$servadm);
774: unless ($configuserok eq 'ok') {
1.181 raeburn 775: &Apache::lonconfigsettings::print_header($r,$phase,$context);
776: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 777: $confname).
1.181 raeburn 778: '<br />'
779: );
1.180 raeburn 780: if ($switchserver) {
1.181 raeburn 781: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
782: '<br />'.
783: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
784: '<br />'.
785: &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).
786: '<br />'.
787: &mt('To do that now, use the following link: [_1]',$switchserver)
788: );
789: } else {
790: $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.').
791: '<br />'.
792: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
793: );
1.180 raeburn 794: }
795: $r->print(&Apache::loncommon::end_page());
796: return OK;
797: }
1.21 raeburn 798: if (keys(%domconfig) == 0) {
799: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 800: my @ids=&Apache::lonnet::current_machine_ids();
801: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 802: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 803: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 804: my $custom_img_count = 0;
805: foreach my $img (@loginimages) {
806: if ($designhash{$dom.'.login.'.$img} ne '') {
807: $custom_img_count ++;
808: }
809: }
810: foreach my $role (@roles) {
811: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
812: $custom_img_count ++;
813: }
814: }
815: if ($custom_img_count > 0) {
1.94 raeburn 816: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 817: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 818: $r->print(
819: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
820: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
821: &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 />'.
822: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
823: if ($switch_server) {
1.30 raeburn 824: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 825: }
1.91 raeburn 826: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 827: return OK;
828: }
829: }
830: }
1.91 raeburn 831: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 832: }
833: return OK;
834: }
835:
836: sub process_changes {
1.205 raeburn 837: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 838: my %domconfig;
839: if (ref($values) eq 'HASH') {
840: %domconfig = %{$values};
841: }
1.3 raeburn 842: my $output;
843: if ($action eq 'login') {
1.205 raeburn 844: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 845: } elsif ($action eq 'rolecolors') {
1.9 raeburn 846: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 847: $lastactref,%domconfig);
1.3 raeburn 848: } elsif ($action eq 'quotas') {
1.216 raeburn 849: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 850: } elsif ($action eq 'autoenroll') {
1.205 raeburn 851: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 852: } elsif ($action eq 'autoupdate') {
853: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 854: } elsif ($action eq 'autocreate') {
855: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 856: } elsif ($action eq 'directorysrch') {
1.295 raeburn 857: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 858: } elsif ($action eq 'usercreation') {
1.28 raeburn 859: $output = &modify_usercreation($dom,%domconfig);
1.224 raeburn 860: } elsif ($action eq 'selfcreation') {
1.305 raeburn 861: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 862: } elsif ($action eq 'usermodification') {
863: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 864: } elsif ($action eq 'contacts') {
1.205 raeburn 865: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 866: } elsif ($action eq 'defaults') {
1.212 raeburn 867: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 868: } elsif ($action eq 'scantron') {
1.205 raeburn 869: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 870: } elsif ($action eq 'coursecategories') {
1.239 raeburn 871: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 872: } elsif ($action eq 'serverstatuses') {
873: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 874: } elsif ($action eq 'requestcourses') {
1.216 raeburn 875: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.163 raeburn 876: } elsif ($action eq 'requestauthor') {
1.216 raeburn 877: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.118 jms 878: } elsif ($action eq 'helpsettings') {
1.285 raeburn 879: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.121 raeburn 880: } elsif ($action eq 'coursedefaults') {
1.212 raeburn 881: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.231 raeburn 882: } elsif ($action eq 'selfenrollment') {
883: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 884: } elsif ($action eq 'usersessions') {
1.212 raeburn 885: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 886: } elsif ($action eq 'loadbalancing') {
887: $output = &modify_loadbalancing($dom,%domconfig);
1.267 raeburn 888: } elsif ($action eq 'ltitools') {
889: $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
1.372 raeburn 890: } elsif ($action eq 'proctoring') {
891: $output = &modify_proctoring($r,$dom,$action,$lastactref,%domconfig);
1.275 raeburn 892: } elsif ($action eq 'ssl') {
893: $output = &modify_ssl($dom,$lastactref,%domconfig);
1.279 raeburn 894: } elsif ($action eq 'trust') {
895: $output = &modify_trust($dom,$lastactref,%domconfig);
1.320 raeburn 896: } elsif ($action eq 'lti') {
897: $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.357 raeburn 898: } elsif ($action eq 'privacy') {
1.427 raeburn 899: $output = &modify_privacy($dom,$lastactref,%domconfig);
1.354 raeburn 900: } elsif ($action eq 'passwords') {
901: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.373 raeburn 902: } elsif ($action eq 'wafproxy') {
903: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
1.394 raeburn 904: } elsif ($action eq 'ipaccess') {
905: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.429 raeburn 906: } elsif ($action eq 'authordefaults') {
907: $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 908: }
909: return $output;
910: }
911:
912: sub print_config_box {
1.9 raeburn 913: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 914: my $rowtotal = 0;
1.49 raeburn 915: my $output;
916: if ($action eq 'coursecategories') {
917: $output = &coursecategories_javascript($settings);
1.236 raeburn 918: } elsif ($action eq 'defaults') {
919: $output = &defaults_javascript($settings);
1.354 raeburn 920: } elsif ($action eq 'passwords') {
1.405 raeburn 921: $output = &passwords_javascript($action);
1.282 raeburn 922: } elsif ($action eq 'helpsettings') {
923: my (%privs,%levelscurrent);
924: my %full=();
925: my %levels=(
926: course => {},
927: domain => {},
928: system => {},
929: );
930: my $context = 'domain';
931: my $crstype = 'Course';
932: my $formname = 'display';
933: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
934: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
935: $output =
1.425 raeburn 936: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
1.282 raeburn 937: \@templateroles);
1.334 raeburn 938: } elsif ($action eq 'ltitools') {
1.421 raeburn 939: $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
1.334 raeburn 940: } elsif ($action eq 'lti') {
1.421 raeburn 941: $output .= &passwords_javascript('ltisecrets')."\n".
1.405 raeburn 942: <i_javascript($dom,$settings);
1.372 raeburn 943: } elsif ($action eq 'proctoring') {
944: $output .= &proctoring_javascript($settings);
1.381 raeburn 945: } elsif ($action eq 'wafproxy') {
946: $output .= &wafproxy_javascript($dom);
1.385 raeburn 947: } elsif ($action eq 'autoupdate') {
948: $output .= &autoupdate_javascript();
1.399 raeburn 949: } elsif ($action eq 'autoenroll') {
950: $output .= &autoenroll_javascript();
1.386 raeburn 951: } elsif ($action eq 'login') {
952: $output .= &saml_javascript();
1.394 raeburn 953: } elsif ($action eq 'ipaccess') {
954: $output .= &ipaccess_javascript($settings);
1.429 raeburn 955: } elsif ($action eq 'authordefaults') {
956: $output .= &authordefaults_javascript();
1.91 raeburn 957: }
1.236 raeburn 958: $output .=
1.30 raeburn 959: '<table class="LC_nested_outer">
1.3 raeburn 960: <tr>
1.306 raeburn 961: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 962: &mt($item->{text}).' '.
963: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
964: '</tr>';
1.30 raeburn 965: $rowtotal ++;
1.110 raeburn 966: my $numheaders = 1;
967: if (ref($item->{'header'}) eq 'ARRAY') {
968: $numheaders = scalar(@{$item->{'header'}});
969: }
970: if ($numheaders > 1) {
1.64 raeburn 971: my $colspan = '';
1.145 raeburn 972: my $rightcolspan = '';
1.369 raeburn 973: my $leftnobr = '';
1.238 raeburn 974: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.277 raeburn 975: ($action eq 'directorysrch') ||
1.386 raeburn 976: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 977: $colspan = ' colspan="2"';
978: }
1.145 raeburn 979: if ($action eq 'usersessions') {
980: $rightcolspan = ' colspan="3"';
981: }
1.369 raeburn 982: if ($action eq 'passwords') {
983: $leftnobr = ' LC_nobreak';
984: }
1.30 raeburn 985: $output .= '
1.3 raeburn 986: <tr>
987: <td>
988: <table class="LC_nested">
989: <tr class="LC_info_row">
1.369 raeburn 990: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 991: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 992: </tr>';
1.69 raeburn 993: $rowtotal ++;
1.230 raeburn 994: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.236 raeburn 995: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.277 raeburn 996: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'ssl') ||
1.286 raeburn 997: ($action eq 'directorysrch') || ($action eq 'trust') || ($action eq 'helpsettings') ||
1.421 raeburn 998: ($action eq 'contacts') || ($action eq 'privacy') || ($action eq 'wafproxy') ||
1.429 raeburn 999: ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.230 raeburn 1000: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.354 raeburn 1001: } elsif ($action eq 'passwords') {
1002: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 1003: } elsif ($action eq 'coursecategories') {
1.230 raeburn 1004: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.346 raeburn 1005: } elsif ($action eq 'scantron') {
1006: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1007: } elsif ($action eq 'login') {
1.386 raeburn 1008: if ($numheaders == 5) {
1.168 raeburn 1009: $colspan = ' colspan="2"';
1010: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
1011: } else {
1012: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
1013: }
1.230 raeburn 1014: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.163 raeburn 1015: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 1016: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1017: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.6 raeburn 1018: }
1.30 raeburn 1019: $output .= '
1.6 raeburn 1020: </table>
1021: </td>
1022: </tr>
1023: <tr>
1024: <td>
1025: <table class="LC_nested">
1026: <tr class="LC_info_row">
1.230 raeburn 1027: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 1028: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 1029: </tr>';
1030: $rowtotal ++;
1.230 raeburn 1031: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
1032: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.275 raeburn 1033: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.409 raeburn 1034: ($action eq 'trust') || ($action eq 'contacts') || ($action eq 'defaults') ||
1.421 raeburn 1035: ($action eq 'privacy') || ($action eq 'passwords') || ($action eq 'lti') ||
1.443 ! raeburn 1036: ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.238 raeburn 1037: if ($action eq 'coursecategories') {
1038: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
1039: $colspan = ' colspan="2"';
1.279 raeburn 1040: } elsif ($action eq 'trust') {
1041: $output .= $item->{'print'}->('shared',$dom,$settings,\$rowtotal);
1.354 raeburn 1042: } elsif ($action eq 'passwords') {
1043: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.434 raeburn 1044: } elsif ($action eq 'lti') {
1045: $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
1046: </table>
1047: </td>
1048: </tr>
1049: <tr>
1050: <td>
1051: <table class="LC_nested">
1052: <tr class="LC_info_row">
1053: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1054: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1055: </tr>'."\n".
1056: $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.238 raeburn 1057: } else {
1058: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1059: }
1.279 raeburn 1060: if ($action eq 'trust') {
1061: $output .= '
1062: </table>
1063: </td>
1064: </tr>';
1065: my @trusthdrs = qw(2 3 4 5 6 7);
1066: my @prefixes = qw(enroll othcoau coaurem domroles catalog reqcrs);
1067: for (my $i=0; $i<@trusthdrs; $i++) {
1068: $output .= '
1069: <tr>
1070: <td>
1071: <table class="LC_nested">
1072: <tr class="LC_info_row">
1073: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col1'}).'</td>
1074: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$trusthdrs[$i]]->{'col2'}).'</td></tr>'.
1075: $item->{'print'}->($prefixes[$i],$dom,$settings,\$rowtotal).'
1076: </table>
1077: </td>
1078: </tr>';
1079: }
1080: $output .= '
1081: <tr>
1082: <td>
1083: <table class="LC_nested">
1084: <tr class="LC_info_row">
1085: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col1'}).'</td>
1086: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[8]->{'col2'}).'</td></tr>'.
1087: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1088: } else {
1.434 raeburn 1089: my $hdridx = 2;
1090: if ($action eq 'lti') {
1091: $hdridx = 3;
1092: }
1.279 raeburn 1093: $output .= '
1.63 raeburn 1094: </table>
1095: </td>
1096: </tr>
1097: <tr>
1098: <td>
1099: <table class="LC_nested">
1100: <tr class="LC_info_row">
1.434 raeburn 1101: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1102: <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.238 raeburn 1103: </tr>'."\n";
1.279 raeburn 1104: if ($action eq 'coursecategories') {
1105: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.405 raeburn 1106: } elsif (($action eq 'contacts') || ($action eq 'privacy') ||
1107: ($action eq 'passwords') || ($action eq 'lti')) {
1.354 raeburn 1108: if ($action eq 'passwords') {
1109: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
1110: } else {
1111: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
1112: }
1.434 raeburn 1113: $hdridx ++;
1.354 raeburn 1114: $output .= '
1.340 raeburn 1115: </tr>
1116: </table>
1117: </td>
1118: </tr>
1119: <tr>
1120: <td>
1121: <table class="LC_nested">
1122: <tr class="LC_info_row">
1.434 raeburn 1123: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1124: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.354 raeburn 1125: if ($action eq 'passwords') {
1126: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1127: } else {
1128: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1129: }
1130: $output .= '
1.340 raeburn 1131: </table>
1132: </td>
1133: </tr>
1134: <tr>';
1.279 raeburn 1135: } else {
1136: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1137: }
1.238 raeburn 1138: }
1.63 raeburn 1139: $rowtotal ++;
1.443 ! raeburn 1140: } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
1.409 raeburn 1141: ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1.443 ! raeburn 1142: ($action eq 'wafproxy')) {
1.230 raeburn 1143: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.346 raeburn 1144: } elsif ($action eq 'scantron') {
1145: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.293 raeburn 1146: } elsif ($action eq 'ssl') {
1147: $output .= $item->{'print'}->('connto',$dom,$settings,\$rowtotal).'
1148: </table>
1149: </td>
1150: </tr>
1151: <tr>
1152: <td>
1153: <table class="LC_nested">
1154: <tr class="LC_info_row">
1155: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1156: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1157: $item->{'print'}->('connfrom',$dom,$settings,\$rowtotal).'
1158: </table>
1159: </td>
1160: </tr>
1161: <tr>
1162: <td>
1163: <table class="LC_nested">
1164: <tr class="LC_info_row">
1165: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1166: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'.
1167: $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.110 raeburn 1168: } elsif ($action eq 'login') {
1.386 raeburn 1169: if ($numheaders == 5) {
1.168 raeburn 1170: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1171: </table>
1172: </td>
1173: </tr>
1174: <tr>
1175: <td>
1176: <table class="LC_nested">
1177: <tr class="LC_info_row">
1178: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.216 raeburn 1179: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.168 raeburn 1180: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1181: $rowtotal ++;
1182: } else {
1183: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1184: }
1.256 raeburn 1185: $output .= '
1186: </table>
1187: </td>
1188: </tr>
1189: <tr>
1190: <td>
1191: <table class="LC_nested">
1192: <tr class="LC_info_row">';
1.386 raeburn 1193: if ($numheaders == 5) {
1.256 raeburn 1194: $output .= '
1195: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1196: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1197: </tr>';
1198: } else {
1199: $output .= '
1200: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1201: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1202: </tr>';
1203: }
1204: $rowtotal ++;
1.386 raeburn 1205: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1206: </table>
1207: </td>
1208: </tr>
1209: <tr>
1210: <td>
1211: <table class="LC_nested">
1212: <tr class="LC_info_row">';
1213: if ($numheaders == 5) {
1214: $output .= '
1215: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1216: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1217: </tr>';
1218: } else {
1219: $output .= '
1220: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1221: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1222: </tr>';
1223: }
1224: $rowtotal ++;
1225: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1226: } elsif ($action eq 'requestcourses') {
1.247 raeburn 1227: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1228: $rowtotal ++;
1229: $output .= &print_studentcode($settings,\$rowtotal).'
1.216 raeburn 1230: </table>
1231: </td>
1232: </tr>
1233: <tr>
1234: <td>
1235: <table class="LC_nested">
1236: <tr class="LC_info_row">
1237: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1238: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.242 raeburn 1239: &textbookcourses_javascript($settings).
1240: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1241: </table>
1242: </td>
1243: </tr>
1244: <tr>
1245: <td>
1246: <table class="LC_nested">
1247: <tr class="LC_info_row">
1248: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1249: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1250: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.235 raeburn 1251: </table>
1252: </td>
1253: </tr>
1254: <tr>
1255: <td>
1256: <table class="LC_nested">
1257: <tr class="LC_info_row">
1.306 raeburn 1258: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1259: <td class="LC_right_item" style="vertical-align: top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.235 raeburn 1260: </tr>'.
1261: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.163 raeburn 1262: } elsif ($action eq 'requestauthor') {
1263: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.247 raeburn 1264: $rowtotal ++;
1.122 jms 1265: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1266: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1267: </table>
1268: </td>
1269: </tr>
1270: <tr>
1271: <td>
1272: <table class="LC_nested">
1273: <tr class="LC_info_row">
1.306 raeburn 1274: <td class="LC_left_item"'.$colspan.' style="vertical-align: top">'.
1.69 raeburn 1275: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1.306 raeburn 1276: <td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1277: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1278: </tr>'.
1.30 raeburn 1279: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1280: </table>
1281: </td>
1282: </tr>
1283: <tr>
1284: <td>
1285: <table class="LC_nested">
1286: <tr class="LC_info_row">
1.59 bisitz 1287: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1288: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1289: </tr>'.
1.30 raeburn 1290: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1291: $rowtotal += 2;
1.6 raeburn 1292: }
1.3 raeburn 1293: } else {
1.30 raeburn 1294: $output .= '
1.3 raeburn 1295: <tr>
1296: <td>
1297: <table class="LC_nested">
1.30 raeburn 1298: <tr class="LC_info_row">';
1.277 raeburn 1299: if ($action eq 'login') {
1.30 raeburn 1300: $output .= '
1.59 bisitz 1301: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1302: } elsif ($action eq 'serverstatuses') {
1303: $output .= '
1.306 raeburn 1304: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).
1.69 raeburn 1305: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1306:
1.6 raeburn 1307: } else {
1.30 raeburn 1308: $output .= '
1.306 raeburn 1309: <td class="LC_left_item" style="vertical-align: top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1310: }
1.72 raeburn 1311: if (defined($item->{'header'}->[0]->{'col3'})) {
1.306 raeburn 1312: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.72 raeburn 1313: &mt($item->{'header'}->[0]->{'col2'});
1314: if ($action eq 'serverstatuses') {
1315: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1316: }
1.69 raeburn 1317: } else {
1.306 raeburn 1318: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.69 raeburn 1319: &mt($item->{'header'}->[0]->{'col2'});
1320: }
1321: $output .= '</td>';
1322: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1323: if (defined($item->{'header'}->[0]->{'col4'})) {
1.306 raeburn 1324: $output .= '<td class="LC_left_item" style="vertical-align: top">'.
1.150 raeburn 1325: &mt($item->{'header'}->[0]->{'col3'});
1326: } else {
1.306 raeburn 1327: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1328: &mt($item->{'header'}->[0]->{'col3'});
1329: }
1.69 raeburn 1330: if ($action eq 'serverstatuses') {
1331: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1332: }
1333: $output .= '</td>';
1.6 raeburn 1334: }
1.150 raeburn 1335: if ($item->{'header'}->[0]->{'col4'}) {
1.306 raeburn 1336: $output .= '<td class="LC_right_item" style="vertical-align: top">'.
1.150 raeburn 1337: &mt($item->{'header'}->[0]->{'col4'});
1338: }
1.69 raeburn 1339: $output .= '</tr>';
1.48 raeburn 1340: $rowtotal ++;
1.168 raeburn 1341: if ($action eq 'quotas') {
1.86 raeburn 1342: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.277 raeburn 1343: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.286 raeburn 1344: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.421 raeburn 1345: ($action eq 'proctoring') || ($action eq 'ipaccess')) {
1.230 raeburn 1346: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1347: }
1.3 raeburn 1348: }
1.30 raeburn 1349: $output .= '
1.3 raeburn 1350: </table>
1351: </td>
1352: </tr>
1.30 raeburn 1353: </table><br />';
1354: return ($output,$rowtotal);
1.1 raeburn 1355: }
1356:
1.3 raeburn 1357: sub print_login {
1.168 raeburn 1358: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.386 raeburn 1359: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1360: my %choices = &login_choices();
1.386 raeburn 1361: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1362: %lt = &login_file_options();
1363: $switchserver = &check_switchserver($dom,$confname);
1364: }
1.168 raeburn 1365: if ($caller eq 'service') {
1.149 raeburn 1366: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1367: my $choice = $choices{'disallowlogin'};
1368: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1369: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.306 raeburn 1370: '<td style="text-align: right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1371: '<th>'.$choices{'server'}.'</th>'.
1372: '<th>'.$choices{'serverpath'}.'</th>'.
1373: '<th>'.$choices{'custompath'}.'</th>'.
1374: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1375: my %disallowed;
1376: if (ref($settings) eq 'HASH') {
1377: if (ref($settings->{'loginvia'}) eq 'HASH') {
1378: %disallowed = %{$settings->{'loginvia'}};
1379: }
1380: }
1381: foreach my $lonhost (sort(keys(%servers))) {
1382: my $direct = 'selected="selected"';
1.128 raeburn 1383: if (ref($disallowed{$lonhost}) eq 'HASH') {
1384: if ($disallowed{$lonhost}{'server'} ne '') {
1385: $direct = '';
1386: }
1.110 raeburn 1387: }
1.115 raeburn 1388: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1389: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1390: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1391: '</option>';
1.184 raeburn 1392: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1393: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1394: my $selected = '';
1.128 raeburn 1395: if (ref($disallowed{$lonhost}) eq 'HASH') {
1396: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1397: $selected = 'selected="selected"';
1398: }
1.110 raeburn 1399: }
1400: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1401: $servers{$hostid}.'</option>';
1402: }
1.128 raeburn 1403: $datatable .= '</select></td>'.
1404: '<td><select name="'.$lonhost.'_serverpath">';
1405: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1406: my $pathname = $path;
1407: if ($path eq 'custom') {
1408: $pathname = &mt('Custom Path').' ->';
1409: }
1410: my $selected = '';
1411: if (ref($disallowed{$lonhost}) eq 'HASH') {
1412: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1413: $selected = 'selected="selected"';
1414: }
1415: } elsif ($path eq '') {
1416: $selected = 'selected="selected"';
1417: }
1418: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1419: }
1420: $datatable .= '</select></td>';
1421: my ($custom,$exempt);
1422: if (ref($disallowed{$lonhost}) eq 'HASH') {
1423: $custom = $disallowed{$lonhost}{'custompath'};
1424: $exempt = $disallowed{$lonhost}{'exempt'};
1425: }
1426: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1427: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1428: '</tr>';
1.110 raeburn 1429: }
1430: $datatable .= '</table></td></tr>';
1431: return $datatable;
1.168 raeburn 1432: } elsif ($caller eq 'page') {
1433: my %defaultchecked = (
1434: 'coursecatalog' => 'on',
1.188 raeburn 1435: 'helpdesk' => 'on',
1.168 raeburn 1436: 'adminmail' => 'off',
1437: 'newuser' => 'off',
1438: );
1.188 raeburn 1439: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 1440: my (%checkedon,%checkedoff);
1.42 raeburn 1441: foreach my $item (@toggles) {
1.168 raeburn 1442: if ($defaultchecked{$item} eq 'on') {
1443: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1444: $checkedoff{$item} = ' ';
1.168 raeburn 1445: } elsif ($defaultchecked{$item} eq 'off') {
1446: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1447: $checkedon{$item} = ' ';
1448: }
1.1 raeburn 1449: }
1.168 raeburn 1450: my @images = ('img','logo','domlogo','login');
1.402 raeburn 1451: my @alttext = ('img','logo','domlogo');
1.168 raeburn 1452: my @logintext = ('textcol','bgcol');
1453: my @bgs = ('pgbg','mainbg','sidebg');
1454: my @links = ('link','alink','vlink');
1455: my %designhash = &Apache::loncommon::get_domainconf($dom);
1456: my %defaultdesign = %Apache::loncommon::defaultdesign;
1457: my (%is_custom,%designs);
1458: my %defaults = (
1459: font => $defaultdesign{'login.font'},
1460: );
1.6 raeburn 1461: foreach my $item (@images) {
1.168 raeburn 1462: $defaults{$item} = $defaultdesign{'login.'.$item};
1463: $defaults{'showlogo'}{$item} = 1;
1464: }
1465: foreach my $item (@bgs) {
1466: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1467: }
1.41 raeburn 1468: foreach my $item (@logintext) {
1.168 raeburn 1469: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1470: }
1.168 raeburn 1471: foreach my $item (@links) {
1472: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1473: }
1.168 raeburn 1474: if (ref($settings) eq 'HASH') {
1475: foreach my $item (@toggles) {
1476: if ($settings->{$item} eq '1') {
1477: $checkedon{$item} = ' checked="checked" ';
1478: $checkedoff{$item} = ' ';
1479: } elsif ($settings->{$item} eq '0') {
1480: $checkedoff{$item} = ' checked="checked" ';
1481: $checkedon{$item} = ' ';
1482: }
1483: }
1484: foreach my $item (@images) {
1485: if (defined($settings->{$item})) {
1486: $designs{$item} = $settings->{$item};
1487: $is_custom{$item} = 1;
1488: }
1489: if (defined($settings->{'showlogo'}{$item})) {
1490: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1491: }
1492: }
1.402 raeburn 1493: foreach my $item (@alttext) {
1494: if (ref($settings->{'alttext'}) eq 'HASH') {
1495: if ($settings->{'alttext'}->{$item} ne '') {
1496: $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1497: }
1498: }
1499: }
1.168 raeburn 1500: foreach my $item (@logintext) {
1501: if ($settings->{$item} ne '') {
1502: $designs{'logintext'}{$item} = $settings->{$item};
1503: $is_custom{$item} = 1;
1504: }
1505: }
1506: if ($settings->{'font'} ne '') {
1507: $designs{'font'} = $settings->{'font'};
1508: $is_custom{'font'} = 1;
1509: }
1510: foreach my $item (@bgs) {
1511: if ($settings->{$item} ne '') {
1512: $designs{'bgs'}{$item} = $settings->{$item};
1513: $is_custom{$item} = 1;
1514: }
1515: }
1516: foreach my $item (@links) {
1517: if ($settings->{$item} ne '') {
1518: $designs{'links'}{$item} = $settings->{$item};
1519: $is_custom{$item} = 1;
1520: }
1521: }
1522: } else {
1523: if ($designhash{$dom.'.login.font'} ne '') {
1524: $designs{'font'} = $designhash{$dom.'.login.font'};
1525: $is_custom{'font'} = 1;
1526: }
1527: foreach my $item (@images) {
1528: if ($designhash{$dom.'.login.'.$item} ne '') {
1529: $designs{$item} = $designhash{$dom.'.login.'.$item};
1530: $is_custom{$item} = 1;
1531: }
1532: }
1533: foreach my $item (@bgs) {
1534: if ($designhash{$dom.'.login.'.$item} ne '') {
1535: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1536: $is_custom{$item} = 1;
1537: }
1.6 raeburn 1538: }
1.168 raeburn 1539: foreach my $item (@links) {
1540: if ($designhash{$dom.'.login.'.$item} ne '') {
1541: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1542: $is_custom{$item} = 1;
1543: }
1.6 raeburn 1544: }
1545: }
1.168 raeburn 1546: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1547: logo => 'Institution Logo',
1548: domlogo => 'Domain Logo',
1549: login => 'Login box');
1550: my $itemcount = 1;
1551: foreach my $item (@toggles) {
1552: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1553: $datatable .=
1554: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1555: '</td><td>'.
1556: '<span class="LC_nobreak"><label><input type="radio" name="'.
1557: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1558: '</label> <label><input type="radio" name="'.$item.'"'.
1559: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1560: '</tr>';
1561: $itemcount ++;
1.6 raeburn 1562: }
1.168 raeburn 1563: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1564: $datatable .= '</tr></table></td></tr>';
1565: } elsif ($caller eq 'help') {
1.386 raeburn 1566: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.168 raeburn 1567: my $itemcount = 1;
1568: $defaulturl = '/adm/loginproblems.html';
1569: $defaulttype = 'default';
1570: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1571: my @currlangs;
1572: if (ref($settings) eq 'HASH') {
1573: if (ref($settings->{'helpurl'}) eq 'HASH') {
1574: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1575: next if ($settings->{'helpurl'}{$key} eq '');
1576: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1577: $type{$key} = 'custom';
1578: unless ($key eq 'nolang') {
1579: push(@currlangs,$key);
1580: }
1581: }
1582: } elsif ($settings->{'helpurl'} ne '') {
1583: $type{'nolang'} = 'custom';
1584: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1585: }
1586: }
1.168 raeburn 1587: foreach my $lang ('nolang',sort(@currlangs)) {
1588: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1589: $datatable .= '<tr'.$css_class.'>';
1590: if ($url{$lang} eq '') {
1591: $url{$lang} = $defaulturl;
1592: }
1593: if ($type{$lang} eq '') {
1594: $type{$lang} = $defaulttype;
1595: }
1596: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1597: if ($lang eq 'nolang') {
1598: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1599: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1600: } else {
1601: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1602: $langchoices{$lang},
1603: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1604: }
1605: $datatable .= '</span></td>'."\n".
1606: '<td class="LC_left_item">';
1607: if ($type{$lang} eq 'custom') {
1608: $datatable .= '<span class="LC_nobreak"><label>'.
1609: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1610: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1611: } else {
1612: $datatable .= $lt{'upl'};
1613: }
1614: $datatable .='<br />';
1615: if ($switchserver) {
1616: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1617: } else {
1618: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1619: }
1.168 raeburn 1620: $datatable .= '</td></tr>';
1621: $itemcount ++;
1.6 raeburn 1622: }
1.168 raeburn 1623: my @addlangs;
1624: foreach my $lang (sort(keys(%langchoices))) {
1625: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1626: push(@addlangs,$lang);
1627: }
1628: if (@addlangs > 0) {
1629: my %toadd;
1630: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1631: $toadd{''} = &mt('Select');
1632: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1633: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1634: &mt('Add log-in help page for a specific language:').' '.
1635: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1636: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1637: if ($switchserver) {
1638: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1639: } else {
1640: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1641: }
1.168 raeburn 1642: $datatable .= '</td></tr>';
1.169 raeburn 1643: $itemcount ++;
1.6 raeburn 1644: }
1.169 raeburn 1645: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.256 raeburn 1646: } elsif ($caller eq 'headtag') {
1647: my %domservers = &Apache::lonnet::get_servers($dom);
1648: my $choice = $choices{'headtag'};
1649: $css_class = ' class="LC_odd_row"';
1650: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1.306 raeburn 1651: '<td style="text-align: left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.256 raeburn 1652: '<th>'.$choices{'current'}.'</th>'.
1653: '<th>'.$choices{'action'}.'</th>'.
1654: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1655: my (%currurls,%currexempt);
1656: if (ref($settings) eq 'HASH') {
1657: if (ref($settings->{'headtag'}) eq 'HASH') {
1658: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1659: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1660: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1661: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1662: }
1663: }
1664: }
1665: }
1666: foreach my $lonhost (sort(keys(%domservers))) {
1667: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1668: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1669: if ($currurls{$lonhost}) {
1670: $datatable .= '<td class="LC_right_item"><a href="'.
1671: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1672: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1673: '">'.$lt{'curr'}.'</a></td>'.
1674: '<td><span class="LC_nobreak"><label>'.
1675: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1676: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1677: } else {
1678: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1679: }
1680: $datatable .='<br />';
1681: if ($switchserver) {
1682: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1683: } else {
1684: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1685: }
1.330 raeburn 1686: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.256 raeburn 1687: }
1688: $datatable .= '</table></td></tr>';
1.386 raeburn 1689: } elsif ($caller eq 'saml') {
1690: my %domservers = &Apache::lonnet::get_servers($dom);
1691: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1692: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1693: '<th>'.$choices{'samllanding'}.'</th>'.
1694: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.412 raeburn 1695: my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.386 raeburn 1696: foreach my $lonhost (keys(%domservers)) {
1697: $samlurl{$lonhost} = '/adm/sso';
1698: $styleon{$lonhost} = 'display:none';
1699: $styleoff{$lonhost} = '';
1700: }
1.411 raeburn 1701: if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.386 raeburn 1702: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1703: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1704: $saml{$lonhost} = 1;
1705: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1706: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1707: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1708: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1709: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.412 raeburn 1710: $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.386 raeburn 1711: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1712: $styleon{$lonhost} = '';
1713: $styleoff{$lonhost} = 'display:none';
1714: } else {
1715: $styleon{$lonhost} = 'display:none';
1716: $styleoff{$lonhost} = '';
1717: }
1718: }
1719: }
1720: my $itemcount = 1;
1721: foreach my $lonhost (sort(keys(%domservers))) {
1722: my $samlon = ' ';
1723: my $samloff = ' checked="checked" ';
1724: if ($saml{$lonhost}) {
1725: $samlon = $samloff;
1726: $samloff = ' ';
1727: }
1.412 raeburn 1728: my $samlwinon = '';
1729: my $samlwinoff = ' checked="checked"';
1730: if ($samlwindow{$lonhost}) {
1731: $samlwinon = $samlwinoff;
1732: $samlwinoff = '';
1733: }
1.386 raeburn 1734: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1735: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1736: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1737: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1738: &mt('No').'</label>'.(' 'x2).
1739: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1740: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1741: &mt('Yes').'</label></span></td>'.
1742: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.412 raeburn 1743: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.386 raeburn 1744: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.412 raeburn 1745: '<th>'.&mt('Alt Text').'</th></tr>'.
1746: '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.386 raeburn 1747: $samltext{$lonhost}.'" /></td><td>';
1748: if ($samlimg{$lonhost}) {
1749: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1750: '<span class="LC_nobreak"><label>'.
1751: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1752: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1753: } else {
1754: $datatable .= $lt{'upl'};
1755: }
1756: $datatable .='<br />';
1757: if ($switchserver) {
1758: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1759: } else {
1760: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1761: }
1762: $datatable .= '</td>'.
1.412 raeburn 1763: '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1764: 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1765: '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1766: '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1767: '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1768: '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1769: '<tr'.$css_class.'>'.
1770: '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.386 raeburn 1771: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.412 raeburn 1772: '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.386 raeburn 1773: $samltitle{$lonhost}.'</textarea></td>'.
1.412 raeburn 1774: '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1775: &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1776: 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1777: '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.386 raeburn 1778: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1779: '</table></td>'.
1780: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1781: $itemcount ++;
1782: }
1783: $datatable .= '</table></td></tr>';
1.1 raeburn 1784: }
1.6 raeburn 1785: return $datatable;
1786: }
1787:
1788: sub login_choices {
1789: my %choices =
1790: &Apache::lonlocal::texthash (
1.116 bisitz 1791: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1792: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1793: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1794: disallowlogin => "Login page requests redirected",
1795: hostid => "Server",
1.128 raeburn 1796: server => "Redirect to:",
1797: serverpath => "Path",
1798: custompath => "Custom",
1799: exempt => "Exempt IP(s)",
1.110 raeburn 1800: directlogin => "No redirect",
1801: newuser => "Link to create a user account",
1802: img => "Header",
1803: logo => "Main Logo",
1804: domlogo => "Domain Logo",
1805: login => "Log-in Header",
1806: textcol => "Text color",
1807: bgcol => "Box color",
1808: bgs => "Background colors",
1809: links => "Link colors",
1810: font => "Font color",
1811: pgbg => "Header",
1812: mainbg => "Page",
1813: sidebg => "Login box",
1814: link => "Link",
1815: alink => "Active link",
1816: vlink => "Visited link",
1.256 raeburn 1817: headtag => "Custom markup",
1818: action => "Action",
1819: current => "Current",
1.386 raeburn 1820: samllanding => "Dual login?",
1821: samloptions => "Options",
1.402 raeburn 1822: alttext => "Alt text",
1.6 raeburn 1823: );
1824: return %choices;
1825: }
1826:
1.386 raeburn 1827: sub login_file_options {
1828: return &Apache::lonlocal::texthash(
1829: del => 'Delete?',
1830: rep => 'Replace:',
1831: upl => 'Upload:',
1832: curr => 'View contents',
1833: default => 'Default',
1834: custom => 'Custom',
1835: none => 'None',
1836: );
1837: }
1838:
1.394 raeburn 1839: sub print_ipaccess {
1840: my ($dom,$settings,$rowtotal) = @_;
1841: my $css_class;
1842: my $itemcount = 0;
1843: my $datatable;
1844: my %ordered;
1845: if (ref($settings) eq 'HASH') {
1846: foreach my $item (keys(%{$settings})) {
1847: if (ref($settings->{$item}) eq 'HASH') {
1848: my $num = $settings->{$item}{'order'};
1849: if ($num eq '') {
1850: $num = scalar(keys(%{$settings}));
1851: }
1852: $ordered{$num} = $item;
1853: }
1854: }
1855: }
1856: my $maxnum = scalar(keys(%ordered));
1857: if (keys(%ordered)) {
1858: my @items = sort { $a <=> $b } keys(%ordered);
1859: for (my $i=0; $i<@items; $i++) {
1860: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1861: my $item = $ordered{$items[$i]};
1862: my ($name,$ipranges,%commblocks,%courses);
1863: if (ref($settings->{$item}) eq 'HASH') {
1864: $name = $settings->{$item}->{'name'};
1865: $ipranges = $settings->{$item}->{'ip'};
1866: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1867: %commblocks = %{$settings->{$item}->{'commblocks'}};
1868: }
1869: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1870: %courses = %{$settings->{$item}->{'courses'}};
1871: }
1872: }
1873: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1874: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1875: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1876: for (my $k=0; $k<=$maxnum; $k++) {
1877: my $vpos = $k+1;
1878: my $selstr;
1879: if ($k == $i) {
1880: $selstr = ' selected="selected" ';
1881: }
1882: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1883: }
1884: $datatable .= '</select>'.(' 'x2).
1885: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1886: &mt('Delete?').'</label></span></td>'.
1887: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1888: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1889: '</td></tr>';
1890: $itemcount ++;
1891: }
1892: }
1893: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1894: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1895: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1896: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1897: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1898: for (my $k=0; $k<$maxnum+1; $k++) {
1899: my $vpos = $k+1;
1900: my $selstr;
1901: if ($k == $maxnum) {
1902: $selstr = ' selected="selected" ';
1903: }
1904: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1905: }
1906: $datatable .= '</select> '."\n".
1907: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1908: '<td colspan="2">'.
1909: &ipaccess_options('add',$itemcount,$dom).
1910: '</td>'."\n".
1911: '</tr>'."\n";
1912: $$rowtotal ++;
1913: return $datatable;
1914: }
1915:
1916: sub ipaccess_options {
1917: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1918: my (%currblocks,%currcourses,$output);
1919: if (ref($blocksref) eq 'HASH') {
1920: %currblocks = %{$blocksref};
1921: }
1922: if (ref($coursesref) eq 'HASH') {
1923: %currcourses = %{$coursesref};
1924: }
1925: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1926: '<span class="LC_nobreak">'.&mt('Name').': '.
1927: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1928: '</span></fieldset>'.
1929: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1930: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1931: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1932: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1933: $ipranges.'</textarea></fieldset>'.
1934: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1935: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1936: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1937: '<table>';
1938: foreach my $cid (sort(keys(%currcourses))) {
1939: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1940: $output .= '<tr><td><span class="LC_nobreak">'.
1941: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1942: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1943: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1944: }
1945: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1946: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1947: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1948: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1949: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1950: '</span></td></tr></table>'."\n".
1951: '</fieldset>';
1952: return $output;
1953: }
1954:
1955: sub blocker_checkboxes {
1956: my ($num,$blocks) = @_;
1957: my ($typeorder,$types) = &commblocktype_text();
1958: my $numinrow = 6;
1959: my $output = '<table>';
1960: for (my $i=0; $i<@{$typeorder}; $i++) {
1961: my $block = $typeorder->[$i];
1962: my $blockstatus;
1963: if (ref($blocks) eq 'HASH') {
1964: if ($blocks->{$block} eq 'on') {
1965: $blockstatus = 'checked="checked"';
1966: }
1967: }
1968: my $rem = $i%($numinrow);
1969: if ($rem == 0) {
1970: if ($i > 0) {
1971: $output .= '</tr>';
1972: }
1973: $output .= '<tr>';
1974: }
1975: if ($i == scalar(@{$typeorder})-1) {
1976: my $colsleft = $numinrow-$rem;
1977: if ($colsleft > 1) {
1978: $output .= '<td colspan="'.$colsleft.'">';
1979: } else {
1980: $output .= '<td>';
1981: }
1982: } else {
1983: $output .= '<td>';
1984: }
1985: my $item = 'ipaccess_block_'.$num;
1986: if ($blockstatus) {
1987: $blockstatus = ' '.$blockstatus;
1988: }
1989: $output .= '<span class="LC_nobreak"><label>'."\n".
1990: '<input type="checkbox" name="'.$item.'"'.
1991: $blockstatus.' value="'.$block.'"'.' />'.
1992: $types->{$block}.'</label></span>'."\n".
1993: '<br /></td>';
1994: }
1995: $output .= '</tr></table>';
1996: return $output;
1997: }
1998:
1999: sub commblocktype_text {
2000: my %types = &Apache::lonlocal::texthash(
2001: 'com' => 'Messaging',
2002: 'chat' => 'Chat Room',
2003: 'boards' => 'Discussion',
2004: 'port' => 'Portfolio',
2005: 'groups' => 'Groups',
2006: 'blogs' => 'Blogs',
2007: 'about' => 'User Information',
2008: 'printout' => 'Printouts',
2009: 'passwd' => 'Change Password',
2010: 'grades' => 'Gradebook',
1.397 raeburn 2011: 'search' => 'Course search',
2012: 'wishlist' => 'Stored links',
2013: 'annotate' => 'Annotations',
1.394 raeburn 2014: );
1.397 raeburn 2015: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.394 raeburn 2016: return ($typeorder,\%types);
2017: }
2018:
1.6 raeburn 2019: sub print_rolecolors {
1.30 raeburn 2020: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2021: my %choices = &color_font_choices();
2022: my @bgs = ('pgbg','tabbg','sidebg');
2023: my @links = ('link','alink','vlink');
2024: my @images = ('img');
2025: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2026: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2027: my %defaultdesign = %Apache::loncommon::defaultdesign;
2028: my (%is_custom,%designs);
1.200 raeburn 2029: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2030: if (ref($settings) eq 'HASH') {
2031: if (ref($settings->{$role}) eq 'HASH') {
2032: if ($settings->{$role}->{'img'} ne '') {
2033: $designs{'img'} = $settings->{$role}->{'img'};
2034: $is_custom{'img'} = 1;
2035: }
2036: if ($settings->{$role}->{'font'} ne '') {
2037: $designs{'font'} = $settings->{$role}->{'font'};
2038: $is_custom{'font'} = 1;
2039: }
1.97 tempelho 2040: if ($settings->{$role}->{'fontmenu'} ne '') {
2041: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2042: $is_custom{'fontmenu'} = 1;
2043: }
1.6 raeburn 2044: foreach my $item (@bgs) {
2045: if ($settings->{$role}->{$item} ne '') {
2046: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2047: $is_custom{$item} = 1;
2048: }
2049: }
2050: foreach my $item (@links) {
2051: if ($settings->{$role}->{$item} ne '') {
2052: $designs{'links'}{$item} = $settings->{$role}->{$item};
2053: $is_custom{$item} = 1;
2054: }
2055: }
2056: }
2057: } else {
2058: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
2059: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
2060: $is_custom{'img'} = 1;
2061: }
1.97 tempelho 2062: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2063: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2064: $is_custom{'fontmenu'} = 1;
2065: }
1.6 raeburn 2066: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2067: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2068: $is_custom{'font'} = 1;
2069: }
2070: foreach my $item (@bgs) {
2071: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2072: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2073: $is_custom{$item} = 1;
2074:
2075: }
2076: }
2077: foreach my $item (@links) {
2078: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2079: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2080: $is_custom{$item} = 1;
2081: }
2082: }
2083: }
2084: my $itemcount = 1;
1.30 raeburn 2085: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2086: $datatable .= '</tr></table></td></tr>';
2087: return $datatable;
2088: }
2089:
1.200 raeburn 2090: sub role_defaults {
2091: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2092: my %defaults;
2093: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2094: return %defaults;
2095: }
2096: my %defaultdesign = %Apache::loncommon::defaultdesign;
2097: if ($role eq 'login') {
2098: %defaults = (
2099: font => $defaultdesign{$role.'.font'},
2100: );
2101: if (ref($logintext) eq 'ARRAY') {
2102: foreach my $item (@{$logintext}) {
2103: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2104: }
2105: }
2106: foreach my $item (@{$images}) {
2107: $defaults{'showlogo'}{$item} = 1;
2108: }
2109: } else {
2110: %defaults = (
2111: img => $defaultdesign{$role.'.img'},
2112: font => $defaultdesign{$role.'.font'},
2113: fontmenu => $defaultdesign{$role.'.fontmenu'},
2114: );
2115: }
2116: foreach my $item (@{$bgs}) {
2117: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2118: }
2119: foreach my $item (@{$links}) {
2120: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2121: }
2122: foreach my $item (@{$images}) {
2123: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2124: }
2125: return %defaults;
2126: }
2127:
1.6 raeburn 2128: sub display_color_options {
1.9 raeburn 2129: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2130: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2131: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2132: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2133: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2134: '<td>'.$choices->{'font'}.'</td>';
2135: if (!$is_custom->{'font'}) {
1.329 raeburn 2136: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2137: } else {
2138: $datatable .= '<td> </td>';
2139: }
1.174 foxr 2140: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2141:
1.8 raeburn 2142: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2143: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2144: ' value="'.$current_color.'" /> '.
1.329 raeburn 2145: ' </span></td></tr>';
1.107 raeburn 2146: unless ($role eq 'login') {
2147: $datatable .= '<tr'.$css_class.'>'.
2148: '<td>'.$choices->{'fontmenu'}.'</td>';
2149: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2150: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2151: } else {
2152: $datatable .= '<td> </td>';
2153: }
1.202 raeburn 2154: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2155: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2156: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2157: '<input class="colorchooser" type="text" size="10" name="'
2158: .$role.'_fontmenu"'.
2159: ' value="'.$current_color.'" /> '.
1.329 raeburn 2160: ' </span></td></tr>';
1.97 tempelho 2161: }
1.9 raeburn 2162: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2163: foreach my $img (@{$images}) {
1.18 albertel 2164: $itemcount ++;
1.6 raeburn 2165: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2166: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2167: '<td>'.$choices->{$img};
1.402 raeburn 2168: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2169: if ($role eq 'login') {
2170: if ($img eq 'login') {
2171: $login_hdr_pick =
1.135 bisitz 2172: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2173: $logincolors =
2174: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2175: $designs,$defaults);
1.402 raeburn 2176: } else {
2177: if ($img ne 'domlogo') {
2178: $datatable.= &logo_display_options($img,$defaults,$designs);
2179: }
2180: if (ref($designs->{'alttext'}) eq 'HASH') {
2181: $alttext = $designs->{'alttext'}{$img};
2182: }
1.70 raeburn 2183: }
2184: }
2185: $datatable .= '</td>';
1.6 raeburn 2186: if ($designs->{$img} ne '') {
2187: $imgfile = $designs->{$img};
1.18 albertel 2188: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2189: } else {
2190: $imgfile = $defaults->{$img};
2191: }
2192: if ($imgfile) {
1.9 raeburn 2193: my ($showfile,$fullsize);
2194: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2195: my $urldir = $1;
2196: my $filename = $2;
2197: my @info = &Apache::lonnet::stat_file($designs->{$img});
2198: if (@info) {
2199: my $thumbfile = 'tn-'.$filename;
2200: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2201: if (@thumb) {
2202: $showfile = $urldir.'/'.$thumbfile;
2203: } else {
2204: $showfile = $imgfile;
2205: }
2206: } else {
2207: $showfile = '';
2208: }
2209: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2210: $showfile = $imgfile;
1.6 raeburn 2211: my $imgdir = $1;
2212: my $filename = $2;
1.159 raeburn 2213: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2214: $showfile = "/$imgdir/tn-".$filename;
2215: } else {
1.159 raeburn 2216: my $input = $londocroot.$imgfile;
2217: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2218: if (!-e $output) {
1.9 raeburn 2219: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2220: my ($fullwidth,$fullheight) = &check_dimensions($input);
2221: if ($fullwidth ne '' && $fullheight ne '') {
2222: if ($fullwidth > $width && $fullheight > $height) {
2223: my $size = $width.'x'.$height;
1.316 raeburn 2224: my @args = ('convert','-sample',$size,$input,$output);
2225: system({$args[0]} @args);
1.159 raeburn 2226: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2227: }
2228: }
1.6 raeburn 2229: }
2230: }
1.16 raeburn 2231: }
1.6 raeburn 2232: if ($showfile) {
1.40 raeburn 2233: if ($showfile =~ m{^/(adm|res)/}) {
2234: if ($showfile =~ m{^/res/}) {
2235: my $local_showfile =
2236: &Apache::lonnet::filelocation('',$showfile);
2237: &Apache::lonnet::repcopy($local_showfile);
2238: }
2239: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2240: }
2241: if ($imgfile) {
2242: if ($imgfile =~ m{^/(adm|res)/}) {
2243: if ($imgfile =~ m{^/res/}) {
2244: my $local_imgfile =
2245: &Apache::lonnet::filelocation('',$imgfile);
2246: &Apache::lonnet::repcopy($local_imgfile);
2247: }
2248: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2249: } else {
2250: $fullsize = $imgfile;
2251: }
2252: }
1.41 raeburn 2253: $datatable .= '<td>';
2254: if ($img eq 'login') {
1.135 bisitz 2255: $datatable .= $login_hdr_pick;
2256: }
1.41 raeburn 2257: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2258: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2259: } else {
1.201 raeburn 2260: $datatable .= '<td> </td><td class="LC_left_item">'.
2261: &mt('Upload:').'<br />';
1.6 raeburn 2262: }
2263: } else {
1.201 raeburn 2264: $datatable .= '<td> </td><td class="LC_left_item">'.
2265: &mt('Upload:').'<br />';
1.6 raeburn 2266: }
1.9 raeburn 2267: if ($switchserver) {
2268: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2269: } else {
1.135 bisitz 2270: if ($img ne 'login') { # suppress file selection for Log-in header
2271: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2272: }
1.9 raeburn 2273: }
1.402 raeburn 2274: if (($role eq 'login') && ($img ne 'login')) {
2275: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2276: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2277: '</label></span>';
2278: }
1.9 raeburn 2279: $datatable .= '</td></tr>';
1.6 raeburn 2280: }
2281: $itemcount ++;
2282: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2283: $datatable .= '<tr'.$css_class.'>'.
2284: '<td>'.$choices->{'bgs'}.'</td>';
2285: my $bgs_def;
2286: foreach my $item (@{$bgs}) {
2287: if (!$is_custom->{$item}) {
1.329 raeburn 2288: $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 2289: }
2290: }
2291: if ($bgs_def) {
1.8 raeburn 2292: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2293: } else {
2294: $datatable .= '<td> </td>';
2295: }
2296: $datatable .= '<td class="LC_right_item">'.
2297: '<table border="0"><tr>';
1.174 foxr 2298:
1.6 raeburn 2299: foreach my $item (@{$bgs}) {
1.306 raeburn 2300: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2301: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2302: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2303: $datatable .= ' ';
1.6 raeburn 2304: }
1.174 foxr 2305: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2306: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2307: }
2308: $datatable .= '</tr></table></td></tr>';
2309: $itemcount ++;
2310: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2311: $datatable .= '<tr'.$css_class.'>'.
2312: '<td>'.$choices->{'links'}.'</td>';
2313: my $links_def;
2314: foreach my $item (@{$links}) {
2315: if (!$is_custom->{$item}) {
1.329 raeburn 2316: $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 2317: }
2318: }
2319: if ($links_def) {
1.8 raeburn 2320: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2321: } else {
2322: $datatable .= '<td> </td>';
2323: }
2324: $datatable .= '<td class="LC_right_item">'.
2325: '<table border="0"><tr>';
2326: foreach my $item (@{$links}) {
1.234 raeburn 2327: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2328: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2329: if ($designs->{'links'}{$item}) {
1.174 foxr 2330: $datatable.=' ';
1.6 raeburn 2331: }
1.174 foxr 2332: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2333: '" /></td>';
2334: }
1.30 raeburn 2335: $$rowtotal += $itemcount;
1.3 raeburn 2336: return $datatable;
2337: }
2338:
1.70 raeburn 2339: sub logo_display_options {
2340: my ($img,$defaults,$designs) = @_;
2341: my $checkedon;
2342: if (ref($defaults) eq 'HASH') {
2343: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2344: if ($defaults->{'showlogo'}{$img}) {
2345: $checkedon = 'checked="checked" ';
2346: }
2347: }
2348: }
2349: if (ref($designs) eq 'HASH') {
2350: if (ref($designs->{'showlogo'}) eq 'HASH') {
2351: if (defined($designs->{'showlogo'}{$img})) {
2352: if ($designs->{'showlogo'}{$img} == 0) {
2353: $checkedon = '';
2354: } elsif ($designs->{'showlogo'}{$img} == 1) {
2355: $checkedon = 'checked="checked" ';
2356: }
2357: }
2358: }
2359: }
2360: return '<br /><label> <input type="checkbox" name="'.
2361: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2362: &mt('show').'</label>'."\n";
2363: }
2364:
1.41 raeburn 2365: sub login_header_options {
1.135 bisitz 2366: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2367: my $output = '';
1.41 raeburn 2368: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2369: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2370: if (!$is_custom->{'textcol'}) {
2371: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2372: ' ';
2373: }
2374: if (!$is_custom->{'bgcol'}) {
2375: $output .= $choices->{'bgcol'}.': '.
2376: '<span id="css_'.$role.'_font" style="background-color: '.
2377: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2378: }
2379: $output .= '<br />';
2380: }
2381: $output .='<br />';
2382: return $output;
2383: }
2384:
2385: sub login_text_colors {
1.201 raeburn 2386: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2387: my $color_menu = '<table border="0"><tr>';
2388: foreach my $item (@{$logintext}) {
1.306 raeburn 2389: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2390: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2391: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2392: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2393: }
2394: $color_menu .= '</tr></table><br />';
2395: return $color_menu;
2396: }
2397:
2398: sub image_changes {
2399: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2400: my $output;
1.135 bisitz 2401: if ($img eq 'login') {
1.331 raeburn 2402: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2403: } elsif (!$is_custom) {
1.70 raeburn 2404: if ($img ne 'domlogo') {
1.331 raeburn 2405: $output = &mt('Default image:').'<br />';
1.41 raeburn 2406: } else {
1.331 raeburn 2407: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2408: }
2409: }
1.331 raeburn 2410: if ($img ne 'login') {
1.135 bisitz 2411: if ($img_import) {
2412: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2413: }
2414: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2415: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2416: if ($is_custom) {
2417: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2418: '<input type="checkbox" name="'.
2419: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2420: '</label> '.&mt('Replace:').'</span><br />';
2421: } else {
1.306 raeburn 2422: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2423: }
1.41 raeburn 2424: }
2425: return $output;
2426: }
2427:
1.3 raeburn 2428: sub print_quotas {
1.86 raeburn 2429: my ($dom,$settings,$rowtotal,$action) = @_;
2430: my $context;
2431: if ($action eq 'quotas') {
2432: $context = 'tools';
2433: } else {
2434: $context = $action;
2435: }
1.429 raeburn 2436: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2437: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2438: my $typecount = 0;
1.101 raeburn 2439: my ($css_class,%titles);
1.86 raeburn 2440: if ($context eq 'requestcourses') {
1.325 raeburn 2441: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2442: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2443: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2444: %titles = &courserequest_titles();
1.163 raeburn 2445: } elsif ($context eq 'requestauthor') {
2446: @usertools = ('author');
2447: @options = ('norequest','approval','automatic');
1.210 raeburn 2448: %titles = &authorrequest_titles();
1.86 raeburn 2449: } else {
1.430 raeburn 2450: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2451: %titles = &tool_titles();
1.86 raeburn 2452: }
1.26 raeburn 2453: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2454: foreach my $type (@{$types}) {
1.429 raeburn 2455: my $currdefquota;
1.163 raeburn 2456: unless (($context eq 'requestcourses') ||
2457: ($context eq 'requestauthor')) {
1.86 raeburn 2458: if (ref($settings) eq 'HASH') {
2459: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2460: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2461: } else {
2462: $currdefquota = $settings->{$type};
2463: }
1.78 raeburn 2464: }
1.72 raeburn 2465: }
1.3 raeburn 2466: if (defined($usertypes->{$type})) {
2467: $typecount ++;
2468: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2469: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2470: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2471: '<td class="LC_left_item">';
1.101 raeburn 2472: if ($context eq 'requestcourses') {
2473: $datatable .= '<table><tr>';
2474: }
2475: my %cell;
1.72 raeburn 2476: foreach my $item (@usertools) {
1.101 raeburn 2477: if ($context eq 'requestcourses') {
2478: my ($curroption,$currlimit);
2479: if (ref($settings) eq 'HASH') {
2480: if (ref($settings->{$item}) eq 'HASH') {
2481: $curroption = $settings->{$item}->{$type};
2482: if ($curroption =~ /^autolimit=(\d*)$/) {
2483: $currlimit = $1;
2484: }
2485: }
2486: }
2487: if (!$curroption) {
2488: $curroption = 'norequest';
2489: }
2490: $datatable .= '<th>'.$titles{$item}.'</th>';
2491: foreach my $option (@options) {
2492: my $val = $option;
2493: if ($option eq 'norequest') {
2494: $val = 0;
2495: }
2496: if ($option eq 'validate') {
2497: my $canvalidate = 0;
2498: if (ref($validations{$item}) eq 'HASH') {
2499: if ($validations{$item}{$type}) {
2500: $canvalidate = 1;
2501: }
2502: }
2503: next if (!$canvalidate);
2504: }
2505: my $checked = '';
2506: if ($option eq $curroption) {
2507: $checked = ' checked="checked"';
2508: } elsif ($option eq 'autolimit') {
2509: if ($curroption =~ /^autolimit/) {
2510: $checked = ' checked="checked"';
2511: }
2512: }
2513: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2514: '<input type="radio" name="crsreq_'.$item.
2515: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2516: $titles{$option}.'</label>';
1.101 raeburn 2517: if ($option eq 'autolimit') {
1.127 raeburn 2518: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2519: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2520: 'value="'.$currlimit.'" />';
1.101 raeburn 2521: }
1.127 raeburn 2522: $cell{$item} .= '</span> ';
1.103 raeburn 2523: if ($option eq 'autolimit') {
1.127 raeburn 2524: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2525: }
1.101 raeburn 2526: }
1.163 raeburn 2527: } elsif ($context eq 'requestauthor') {
2528: my $curroption;
2529: if (ref($settings) eq 'HASH') {
2530: $curroption = $settings->{$type};
2531: }
2532: if (!$curroption) {
2533: $curroption = 'norequest';
2534: }
2535: foreach my $option (@options) {
2536: my $val = $option;
2537: if ($option eq 'norequest') {
2538: $val = 0;
2539: }
2540: my $checked = '';
2541: if ($option eq $curroption) {
2542: $checked = ' checked="checked"';
2543: }
2544: $datatable .= '<span class="LC_nobreak"><label>'.
2545: '<input type="radio" name="authorreq_'.$type.
2546: '" value="'.$val.'"'.$checked.' />'.
2547: $titles{$option}.'</label></span> ';
2548: }
1.101 raeburn 2549: } else {
2550: my $checked = 'checked="checked" ';
1.413 raeburn 2551: if ($item eq 'timezone') {
2552: $checked = '';
2553: }
1.101 raeburn 2554: if (ref($settings) eq 'HASH') {
2555: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2556: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2557: $checked = '';
2558: } elsif ($settings->{$item}->{$type} == 1) {
2559: $checked = 'checked="checked" ';
2560: }
1.78 raeburn 2561: }
1.72 raeburn 2562: }
1.101 raeburn 2563: $datatable .= '<span class="LC_nobreak"><label>'.
2564: '<input type="checkbox" name="'.$context.'_'.$item.
2565: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2566: '</label></span> ';
1.72 raeburn 2567: }
1.101 raeburn 2568: }
2569: if ($context eq 'requestcourses') {
2570: $datatable .= '</tr><tr>';
2571: foreach my $item (@usertools) {
1.106 raeburn 2572: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2573: }
2574: $datatable .= '</tr></table>';
1.72 raeburn 2575: }
1.86 raeburn 2576: $datatable .= '</td>';
1.163 raeburn 2577: unless (($context eq 'requestcourses') ||
2578: ($context eq 'requestauthor')) {
1.86 raeburn 2579: $datatable .=
1.197 raeburn 2580: '<td class="LC_right_item">'.
1.429 raeburn 2581: '<span class="LC_nobreak">'.
1.3 raeburn 2582: '<input type="text" name="quota_'.$type.
1.72 raeburn 2583: '" value="'.$currdefquota.
1.197 raeburn 2584: '" size="5" /></span></td>';
1.86 raeburn 2585: }
2586: $datatable .= '</tr>';
1.3 raeburn 2587: }
2588: }
2589: }
1.163 raeburn 2590: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2591: $defaultquota = '20';
2592: if (ref($settings) eq 'HASH') {
2593: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2594: $defaultquota = $settings->{'defaultquota'}->{'default'};
2595: } elsif (defined($settings->{'default'})) {
2596: $defaultquota = $settings->{'default'};
2597: }
1.3 raeburn 2598: }
2599: }
2600: $typecount ++;
2601: $css_class = $typecount%2?' class="LC_odd_row"':'';
2602: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2603: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2604: '<td class="LC_left_item">';
1.101 raeburn 2605: if ($context eq 'requestcourses') {
2606: $datatable .= '<table><tr>';
2607: }
2608: my %defcell;
1.72 raeburn 2609: foreach my $item (@usertools) {
1.101 raeburn 2610: if ($context eq 'requestcourses') {
2611: my ($curroption,$currlimit);
2612: if (ref($settings) eq 'HASH') {
2613: if (ref($settings->{$item}) eq 'HASH') {
2614: $curroption = $settings->{$item}->{'default'};
2615: if ($curroption =~ /^autolimit=(\d*)$/) {
2616: $currlimit = $1;
2617: }
2618: }
2619: }
2620: if (!$curroption) {
2621: $curroption = 'norequest';
2622: }
2623: $datatable .= '<th>'.$titles{$item}.'</th>';
2624: foreach my $option (@options) {
2625: my $val = $option;
2626: if ($option eq 'norequest') {
2627: $val = 0;
2628: }
2629: if ($option eq 'validate') {
2630: my $canvalidate = 0;
2631: if (ref($validations{$item}) eq 'HASH') {
2632: if ($validations{$item}{'default'}) {
2633: $canvalidate = 1;
2634: }
2635: }
2636: next if (!$canvalidate);
2637: }
2638: my $checked = '';
2639: if ($option eq $curroption) {
2640: $checked = ' checked="checked"';
2641: } elsif ($option eq 'autolimit') {
2642: if ($curroption =~ /^autolimit/) {
2643: $checked = ' checked="checked"';
2644: }
2645: }
2646: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2647: '<input type="radio" name="crsreq_'.$item.
2648: '_default" value="'.$val.'"'.$checked.' />'.
2649: $titles{$option}.'</label>';
2650: if ($option eq 'autolimit') {
1.127 raeburn 2651: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2652: $item.'_limit_default" size="1" '.
2653: 'value="'.$currlimit.'" />';
2654: }
1.127 raeburn 2655: $defcell{$item} .= '</span> ';
1.104 raeburn 2656: if ($option eq 'autolimit') {
1.127 raeburn 2657: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2658: }
1.101 raeburn 2659: }
1.163 raeburn 2660: } elsif ($context eq 'requestauthor') {
2661: my $curroption;
2662: if (ref($settings) eq 'HASH') {
1.172 raeburn 2663: $curroption = $settings->{'default'};
1.163 raeburn 2664: }
2665: if (!$curroption) {
2666: $curroption = 'norequest';
2667: }
2668: foreach my $option (@options) {
2669: my $val = $option;
2670: if ($option eq 'norequest') {
2671: $val = 0;
2672: }
2673: my $checked = '';
2674: if ($option eq $curroption) {
2675: $checked = ' checked="checked"';
2676: }
2677: $datatable .= '<span class="LC_nobreak"><label>'.
2678: '<input type="radio" name="authorreq_default"'.
2679: ' value="'.$val.'"'.$checked.' />'.
2680: $titles{$option}.'</label></span> ';
2681: }
1.101 raeburn 2682: } else {
2683: my $checked = 'checked="checked" ';
2684: if (ref($settings) eq 'HASH') {
2685: if (ref($settings->{$item}) eq 'HASH') {
2686: if ($settings->{$item}->{'default'} == 0) {
2687: $checked = '';
2688: } elsif ($settings->{$item}->{'default'} == 1) {
2689: $checked = 'checked="checked" ';
2690: }
1.78 raeburn 2691: }
1.72 raeburn 2692: }
1.101 raeburn 2693: $datatable .= '<span class="LC_nobreak"><label>'.
2694: '<input type="checkbox" name="'.$context.'_'.$item.
2695: '" value="default" '.$checked.'/>'.$titles{$item}.
2696: '</label></span> ';
2697: }
2698: }
2699: if ($context eq 'requestcourses') {
2700: $datatable .= '</tr><tr>';
2701: foreach my $item (@usertools) {
1.106 raeburn 2702: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2703: }
1.101 raeburn 2704: $datatable .= '</tr></table>';
1.72 raeburn 2705: }
1.86 raeburn 2706: $datatable .= '</td>';
1.163 raeburn 2707: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2708: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2709: '<span class="LC_nobreak">'.
1.86 raeburn 2710: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2711: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2712: }
2713: $datatable .= '</tr>';
1.72 raeburn 2714: $typecount ++;
2715: $css_class = $typecount%2?' class="LC_odd_row"':'';
2716: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2717: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2718: if ($context eq 'requestcourses') {
1.109 raeburn 2719: $datatable .= &mt('(overrides affiliation, if set)').
2720: '</td>'.
2721: '<td class="LC_left_item">'.
2722: '<table><tr>';
1.101 raeburn 2723: } else {
1.109 raeburn 2724: $datatable .= &mt('(overrides affiliation, if checked)').
2725: '</td>'.
2726: '<td class="LC_left_item" colspan="2">'.
2727: '<br />';
1.101 raeburn 2728: }
2729: my %advcell;
1.72 raeburn 2730: foreach my $item (@usertools) {
1.101 raeburn 2731: if ($context eq 'requestcourses') {
2732: my ($curroption,$currlimit);
2733: if (ref($settings) eq 'HASH') {
2734: if (ref($settings->{$item}) eq 'HASH') {
2735: $curroption = $settings->{$item}->{'_LC_adv'};
2736: if ($curroption =~ /^autolimit=(\d*)$/) {
2737: $currlimit = $1;
2738: }
2739: }
2740: }
2741: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2742: my $checked = '';
2743: if ($curroption eq '') {
2744: $checked = ' checked="checked"';
2745: }
2746: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2747: '<input type="radio" name="crsreq_'.$item.
2748: '__LC_adv" value=""'.$checked.' />'.
2749: &mt('No override set').'</label></span> ';
1.101 raeburn 2750: foreach my $option (@options) {
2751: my $val = $option;
2752: if ($option eq 'norequest') {
2753: $val = 0;
2754: }
2755: if ($option eq 'validate') {
2756: my $canvalidate = 0;
2757: if (ref($validations{$item}) eq 'HASH') {
2758: if ($validations{$item}{'_LC_adv'}) {
2759: $canvalidate = 1;
2760: }
2761: }
2762: next if (!$canvalidate);
2763: }
2764: my $checked = '';
1.104 raeburn 2765: if ($val eq $curroption) {
1.101 raeburn 2766: $checked = ' checked="checked"';
2767: } elsif ($option eq 'autolimit') {
2768: if ($curroption =~ /^autolimit/) {
2769: $checked = ' checked="checked"';
2770: }
2771: }
2772: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2773: '<input type="radio" name="crsreq_'.$item.
2774: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2775: $titles{$option}.'</label>';
2776: if ($option eq 'autolimit') {
1.127 raeburn 2777: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2778: $item.'_limit__LC_adv" size="1" '.
2779: 'value="'.$currlimit.'" />';
2780: }
1.127 raeburn 2781: $advcell{$item} .= '</span> ';
1.104 raeburn 2782: if ($option eq 'autolimit') {
1.127 raeburn 2783: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2784: }
1.101 raeburn 2785: }
1.163 raeburn 2786: } elsif ($context eq 'requestauthor') {
2787: my $curroption;
2788: if (ref($settings) eq 'HASH') {
2789: $curroption = $settings->{'_LC_adv'};
2790: }
2791: my $checked = '';
2792: if ($curroption eq '') {
2793: $checked = ' checked="checked"';
2794: }
2795: $datatable .= '<span class="LC_nobreak"><label>'.
2796: '<input type="radio" name="authorreq__LC_adv"'.
2797: ' value=""'.$checked.' />'.
2798: &mt('No override set').'</label></span> ';
2799: foreach my $option (@options) {
2800: my $val = $option;
2801: if ($option eq 'norequest') {
2802: $val = 0;
2803: }
2804: my $checked = '';
2805: if ($val eq $curroption) {
2806: $checked = ' checked="checked"';
2807: }
2808: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2809: '<input type="radio" name="authorreq__LC_adv"'.
2810: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2811: $titles{$option}.'</label></span> ';
2812: }
1.101 raeburn 2813: } else {
2814: my $checked = 'checked="checked" ';
2815: if (ref($settings) eq 'HASH') {
2816: if (ref($settings->{$item}) eq 'HASH') {
2817: if ($settings->{$item}->{'_LC_adv'} == 0) {
2818: $checked = '';
2819: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2820: $checked = 'checked="checked" ';
2821: }
1.79 raeburn 2822: }
1.72 raeburn 2823: }
1.101 raeburn 2824: $datatable .= '<span class="LC_nobreak"><label>'.
2825: '<input type="checkbox" name="'.$context.'_'.$item.
2826: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2827: '</label></span> ';
2828: }
2829: }
2830: if ($context eq 'requestcourses') {
2831: $datatable .= '</tr><tr>';
2832: foreach my $item (@usertools) {
1.106 raeburn 2833: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2834: }
1.101 raeburn 2835: $datatable .= '</tr></table>';
1.72 raeburn 2836: }
1.98 raeburn 2837: $datatable .= '</td></tr>';
1.30 raeburn 2838: $$rowtotal += $typecount;
1.3 raeburn 2839: return $datatable;
2840: }
2841:
1.163 raeburn 2842: sub print_requestmail {
1.305 raeburn 2843: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2844: my ($now,$datatable,%currapp);
1.102 raeburn 2845: $now = time;
2846: if (ref($settings) eq 'HASH') {
2847: if (ref($settings->{'notify'}) eq 'HASH') {
2848: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2849: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2850: }
2851: }
2852: }
1.191 raeburn 2853: my $numinrow = 2;
1.224 raeburn 2854: my $css_class;
1.305 raeburn 2855: if ($$rowtotal%2) {
2856: $css_class = 'LC_odd_row';
2857: }
2858: if ($customcss) {
2859: $css_class .= " $customcss";
2860: }
2861: $css_class =~ s/^\s+//;
2862: if ($css_class) {
2863: $css_class = ' class="'.$css_class.'"';
2864: }
2865: if ($rowstyle) {
2866: $css_class .= ' style="'.$rowstyle.'"';
2867: }
1.163 raeburn 2868: my $text;
2869: if ($action eq 'requestcourses') {
2870: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2871: } elsif ($action eq 'requestauthor') {
2872: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2873: } else {
1.224 raeburn 2874: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2875: }
1.224 raeburn 2876: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2877: ' <td>'.$text.'</td>'.
1.102 raeburn 2878: ' <td class="LC_left_item">';
1.191 raeburn 2879: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2880: $action.'notifyapproval',%currapp);
1.191 raeburn 2881: if ($numdc > 0) {
2882: $datatable .= $table;
1.102 raeburn 2883: } else {
2884: $datatable .= &mt('There are no active Domain Coordinators');
2885: }
2886: $datatable .='</td></tr>';
2887: return $datatable;
2888: }
2889:
1.216 raeburn 2890: sub print_studentcode {
2891: my ($settings,$rowtotal) = @_;
2892: my $rownum = 0;
1.218 raeburn 2893: my ($output,%current);
1.325 raeburn 2894: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2895: if (ref($settings) eq 'HASH') {
2896: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2897: foreach my $type (@crstypes) {
2898: $current{$type} = $settings->{'uniquecode'}{$type};
2899: }
1.218 raeburn 2900: }
2901: }
2902: $output .= '<tr>'.
2903: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2904: '<td class="LC_left_item">';
2905: foreach my $type (@crstypes) {
2906: my $check = ' ';
2907: if ($current{$type}) {
2908: $check = ' checked="checked" ';
2909: }
2910: $output .= '<span class="LC_nobreak"><label>'.
2911: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2912: &mt($type).'</label></span>'.(' 'x2).' ';
2913: }
2914: $output .= '</td></tr>';
2915: $$rowtotal ++;
2916: return $output;
1.216 raeburn 2917: }
2918:
2919: sub print_textbookcourses {
1.242 raeburn 2920: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2921: my $rownum = 0;
2922: my $css_class;
2923: my $itemcount = 1;
2924: my $maxnum = 0;
2925: my $bookshash;
2926: if (ref($settings) eq 'HASH') {
1.242 raeburn 2927: $bookshash = $settings->{$type};
1.216 raeburn 2928: }
2929: my %ordered;
2930: if (ref($bookshash) eq 'HASH') {
2931: foreach my $item (keys(%{$bookshash})) {
2932: if (ref($bookshash->{$item}) eq 'HASH') {
2933: my $num = $bookshash->{$item}{'order'};
2934: $ordered{$num} = $item;
2935: }
2936: }
2937: }
2938: my $confname = $dom.'-domainconfig';
2939: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2940: my $maxnum = scalar(keys(%ordered));
2941: my $datatable;
1.216 raeburn 2942: if (keys(%ordered)) {
2943: my @items = sort { $a <=> $b } keys(%ordered);
2944: for (my $i=0; $i<@items; $i++) {
2945: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2946: my $key = $ordered{$items[$i]};
2947: my %coursehash=&Apache::lonnet::coursedescription($key);
2948: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2949: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2950: if (ref($bookshash->{$key}) eq 'HASH') {
2951: $subject = $bookshash->{$key}->{'subject'};
2952: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2953: if ($type eq 'textbooks') {
1.243 raeburn 2954: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2955: $author = $bookshash->{$key}->{'author'};
2956: $image = $bookshash->{$key}->{'image'};
2957: if ($image ne '') {
2958: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2959: my $imagethumb = "$path/tn-".$imagefile;
2960: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2961: }
1.216 raeburn 2962: }
2963: }
1.242 raeburn 2964: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2965: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2966: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2967: for (my $k=0; $k<=$maxnum; $k++) {
2968: my $vpos = $k+1;
2969: my $selstr;
2970: if ($k == $i) {
2971: $selstr = ' selected="selected" ';
2972: }
2973: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2974: }
2975: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2976: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2977: &mt('Delete?').'</label></span></td>'.
2978: '<td colspan="2">'.
1.242 raeburn 2979: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2980: (' 'x2).
1.242 raeburn 2981: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2982: if ($type eq 'textbooks') {
2983: $datatable .= (' 'x2).
1.243 raeburn 2984: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2985: (' 'x2).
1.242 raeburn 2986: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2987: (' 'x2).
2988: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2989: if ($image) {
1.267 raeburn 2990: $datatable .= $imgsrc.
1.242 raeburn 2991: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2992: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2993: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2994: }
2995: if ($switchserver) {
2996: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2997: } else {
2998: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2999: }
1.216 raeburn 3000: }
1.242 raeburn 3001: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 3002: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
3003: $coursetitle.'</span></td></tr>'."\n";
3004: $itemcount ++;
3005: }
3006: }
3007: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 3008: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3009: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3010: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3011: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3012: for (my $k=0; $k<$maxnum+1; $k++) {
3013: my $vpos = $k+1;
3014: my $selstr;
3015: if ($k == $maxnum) {
3016: $selstr = ' selected="selected" ';
3017: }
3018: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3019: }
3020: $datatable .= '</select> '."\n".
1.334 raeburn 3021: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3022: '<td colspan="2">'.
1.242 raeburn 3023: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3024: (' 'x2).
1.242 raeburn 3025: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3026: (' 'x2);
3027: if ($type eq 'textbooks') {
1.243 raeburn 3028: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3029: (' 'x2).
3030: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3031: (' 'x2).
3032: '<span class="LC_nobreak">'.&mt('Image:').' ';
3033: if ($switchserver) {
3034: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3035: } else {
3036: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3037: }
1.334 raeburn 3038: $datatable .= '</span>'."\n";
1.216 raeburn 3039: }
1.334 raeburn 3040: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3041: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3042: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3043: &Apache::loncommon::selectcourse_link
1.334 raeburn 3044: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3045: '</span></td>'."\n".
3046: '</tr>'."\n";
3047: $itemcount ++;
3048: return $datatable;
3049: }
3050:
1.217 raeburn 3051: sub textbookcourses_javascript {
1.242 raeburn 3052: my ($settings) = @_;
3053: return unless(ref($settings) eq 'HASH');
3054: my (%ordered,%total,%jstext);
3055: foreach my $type ('textbooks','templates') {
3056: $total{$type} = 0;
3057: if (ref($settings->{$type}) eq 'HASH') {
3058: foreach my $item (keys(%{$settings->{$type}})) {
3059: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3060: my $num = $settings->{$type}->{$item}{'order'};
3061: $ordered{$type}{$num} = $item;
3062: }
3063: }
3064: $total{$type} = scalar(keys(%{$settings->{$type}}));
3065: }
3066: my @jsarray = ();
3067: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3068: push(@jsarray,$ordered{$type}{$item});
3069: }
3070: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3071: }
3072: return <<"ENDSCRIPT";
3073: <script type="text/javascript">
3074: // <![CDATA[
1.242 raeburn 3075: function reorderBooks(form,item,caller) {
1.217 raeburn 3076: var changedVal;
1.242 raeburn 3077: $jstext{'textbooks'};
3078: $jstext{'templates'};
3079: var newpos;
3080: var maxh;
3081: if (caller == 'textbooks') {
3082: newpos = 'textbooks_addbook_pos';
3083: maxh = 1 + $total{'textbooks'};
3084: } else {
3085: newpos = 'templates_addbook_pos';
3086: maxh = 1 + $total{'templates'};
3087: }
1.217 raeburn 3088: var current = new Array;
3089: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3090: if (item == newpos) {
3091: changedVal = newitemVal;
3092: } else {
3093: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3094: current[newitemVal] = newpos;
3095: }
1.242 raeburn 3096: if (caller == 'textbooks') {
3097: for (var i=0; i<textbooks.length; i++) {
3098: var elementName = 'textbooks_'+textbooks[i];
3099: if (elementName != item) {
3100: if (form.elements[elementName]) {
3101: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3102: current[currVal] = elementName;
3103: }
3104: }
3105: }
3106: }
3107: if (caller == 'templates') {
3108: for (var i=0; i<templates.length; i++) {
3109: var elementName = 'templates_'+templates[i];
3110: if (elementName != item) {
3111: if (form.elements[elementName]) {
3112: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3113: current[currVal] = elementName;
3114: }
1.217 raeburn 3115: }
3116: }
3117: }
3118: var oldVal;
3119: for (var j=0; j<maxh; j++) {
3120: if (current[j] == undefined) {
3121: oldVal = j;
3122: }
3123: }
3124: if (oldVal < changedVal) {
3125: for (var k=oldVal+1; k<=changedVal ; k++) {
3126: var elementName = current[k];
3127: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3128: }
3129: } else {
3130: for (var k=changedVal; k<oldVal; k++) {
3131: var elementName = current[k];
3132: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3133: }
3134: }
3135: return;
3136: }
3137:
3138: // ]]>
3139: </script>
3140:
3141: ENDSCRIPT
3142: }
3143:
1.267 raeburn 3144: sub ltitools_javascript {
3145: my ($settings) = @_;
1.319 raeburn 3146: my $togglejs = <itools_toggle_js();
3147: unless (ref($settings) eq 'HASH') {
3148: return $togglejs;
3149: }
1.267 raeburn 3150: my (%ordered,$total,%jstext);
3151: $total = 0;
3152: foreach my $item (keys(%{$settings})) {
3153: if (ref($settings->{$item}) eq 'HASH') {
3154: my $num = $settings->{$item}{'order'};
3155: $ordered{$num} = $item;
3156: }
3157: }
3158: $total = scalar(keys(%{$settings}));
3159: my @jsarray = ();
3160: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3161: push(@jsarray,$ordered{$item});
3162: }
3163: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3164: return <<"ENDSCRIPT";
3165: <script type="text/javascript">
3166: // <![CDATA[
1.319 raeburn 3167: function reorderLTITools(form,item) {
1.267 raeburn 3168: var changedVal;
3169: $jstext
3170: var newpos = 'ltitools_add_pos';
3171: var maxh = 1 + $total;
3172: var current = new Array;
3173: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3174: if (item == newpos) {
3175: changedVal = newitemVal;
3176: } else {
3177: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3178: current[newitemVal] = newpos;
3179: }
3180: for (var i=0; i<ltitools.length; i++) {
3181: var elementName = 'ltitools_'+ltitools[i];
3182: if (elementName != item) {
3183: if (form.elements[elementName]) {
3184: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3185: current[currVal] = elementName;
3186: }
3187: }
3188: }
3189: var oldVal;
3190: for (var j=0; j<maxh; j++) {
3191: if (current[j] == undefined) {
3192: oldVal = j;
3193: }
3194: }
3195: if (oldVal < changedVal) {
3196: for (var k=oldVal+1; k<=changedVal ; k++) {
3197: var elementName = current[k];
3198: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3199: }
3200: } else {
3201: for (var k=changedVal; k<oldVal; k++) {
3202: var elementName = current[k];
3203: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3204: }
3205: }
3206: return;
3207: }
3208:
3209: // ]]>
3210: </script>
3211:
1.319 raeburn 3212: $togglejs
3213:
3214: ENDSCRIPT
3215: }
3216:
3217: sub ltitools_toggle_js {
3218: return <<"ENDSCRIPT";
3219: <script type="text/javascript">
3220: // <![CDATA[
3221:
3222: function toggleLTITools(form,setting,item) {
3223: var radioname = '';
3224: var divid = '';
3225: if ((setting == 'passback') || (setting == 'roster')) {
3226: radioname = 'ltitools_'+setting+'_'+item;
3227: divid = 'ltitools_'+setting+'time_'+item;
3228: var num = form.elements[radioname].length;
3229: if (num) {
3230: var setvis = '';
3231: for (var i=0; i<num; i++) {
3232: if (form.elements[radioname][i].checked) {
3233: if (form.elements[radioname][i].value == '1') {
3234: if (document.getElementById(divid)) {
3235: document.getElementById(divid).style.display = 'inline-block';
3236: }
3237: setvis = 1;
3238: }
3239: break;
3240: }
3241: }
3242: }
3243: if (!setvis) {
3244: if (document.getElementById(divid)) {
3245: document.getElementById(divid).style.display = 'none';
3246: }
3247: }
3248: }
1.324 raeburn 3249: if (setting == 'user') {
3250: divid = 'ltitools_'+setting+'_div_'+item;
3251: var checkid = 'ltitools_'+setting+'_field_'+item;
3252: if (document.getElementById(divid)) {
3253: if (document.getElementById(checkid)) {
3254: if (document.getElementById(checkid).checked) {
3255: document.getElementById(divid).style.display = 'inline-block';
3256: } else {
3257: document.getElementById(divid).style.display = 'none';
3258: }
3259: }
3260: }
3261: }
1.319 raeburn 3262: return;
3263: }
3264: // ]]>
3265: </script>
3266:
1.267 raeburn 3267: ENDSCRIPT
3268: }
3269:
1.381 raeburn 3270: sub wafproxy_javascript {
3271: my ($dom) = @_;
3272: return <<"ENDSCRIPT";
3273: <script type="text/javascript">
3274: // <![CDATA[
3275: function updateWAF() {
3276: if (document.getElementById('wafproxy_remoteip')) {
3277: var wafremote = 0;
3278: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3279: wafremote = 1;
3280: }
3281: var fields = new Array('header','trust');
3282: for (var i=0; i<fields.length; i++) {
3283: if (document.getElementById('wafproxy_'+fields[i])) {
3284: if (wafremote == 1) {
3285: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3286: }
3287: else {
3288: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3289: }
3290: }
3291: }
3292: if (document.getElementById('wafproxyranges_$dom')) {
3293: if (wafremote == 1) {
3294: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3295: } else {
3296: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3297: if (document.display.wafproxy_vpnaccess[i].checked) {
3298: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3299: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3300: }
3301: }
3302: }
3303: }
3304: }
3305: }
3306: return;
3307: }
3308:
3309: function checkWAF() {
3310: if (document.getElementById('wafproxy_remoteip')) {
3311: var wafvpn = 0;
3312: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3313: if (document.display.wafproxy_vpnaccess[i].checked) {
3314: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3315: wafvpn = 1;
3316: }
3317: break;
3318: }
3319: }
3320: var vpn = new Array('vpnint','vpnext');
3321: for (var i=0; i<vpn.length; i++) {
3322: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3323: if (wafvpn == 1) {
3324: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3325: }
3326: else {
3327: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3328: }
3329: }
3330: }
3331: if (document.getElementById('wafproxyranges_$dom')) {
3332: if (wafvpn == 1) {
3333: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3334: }
3335: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3336: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3337: }
3338: }
3339: }
3340: return;
3341: }
3342:
3343: function toggleWAF() {
3344: if (document.getElementById('wafproxy_table')) {
3345: var wafproxy = 0;
3346: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3347: if (document.display.wafproxy_${dom}[i].checked) {
3348: if (document.display.wafproxy_${dom}[i].value == 1) {
3349: wafproxy = 1;
3350: break;
3351: }
3352: }
3353: }
3354: if (wafproxy == 1) {
3355: document.getElementById('wafproxy_table').style.display='inline';
3356: }
3357: else {
3358: document.getElementById('wafproxy_table').style.display='none';
3359: }
3360: if (document.getElementById('wafproxyrow_${dom}')) {
3361: if (wafproxy == 1) {
3362: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3363: }
3364: else {
3365: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3366: }
3367: }
3368: if (document.getElementById('nowafproxyrow_$dom')) {
3369: if (wafproxy == 1) {
3370: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3371: }
3372: else {
3373: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3374: }
3375: }
3376: }
3377: return;
3378: }
3379: // ]]>
3380: </script>
3381:
3382: ENDSCRIPT
3383: }
3384:
1.372 raeburn 3385: sub proctoring_javascript {
3386: my ($settings) = @_;
3387: my (%ordered,$total,%jstext);
3388: $total = 0;
3389: if (ref($settings) eq 'HASH') {
3390: foreach my $item (keys(%{$settings})) {
3391: if (ref($settings->{$item}) eq 'HASH') {
3392: my $num = $settings->{$item}{'order'};
3393: $ordered{$num} = $item;
3394: }
3395: }
3396: $total = scalar(keys(%{$settings}));
3397: } else {
3398: %ordered = (
3399: 0 => 'proctorio',
3400: 1 => 'examity',
3401: );
3402: $total = 2;
3403: }
3404: my @jsarray = ();
3405: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3406: push(@jsarray,$ordered{$item});
3407: }
3408: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3409: return <<"ENDSCRIPT";
3410: <script type="text/javascript">
3411: // <![CDATA[
3412: function reorderProctoring(form,item) {
3413: var changedVal;
3414: $jstext
3415: var maxh = $total;
3416: var current = new Array;
3417: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3418: for (var i=0; i<proctors.length; i++) {
3419: var elementName = 'proctoring_pos_'+proctors[i];
3420: if (elementName != item) {
3421: if (form.elements[elementName]) {
3422: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3423: current[currVal] = elementName;
3424: }
3425: }
3426: }
3427: var oldVal;
3428: for (var j=0; j<maxh; j++) {
3429: if (current[j] == undefined) {
3430: oldVal = j;
3431: }
3432: }
3433: if (oldVal < changedVal) {
3434: for (var k=oldVal+1; k<=changedVal ; k++) {
3435: var elementName = current[k];
3436: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3437: }
3438: } else {
3439: for (var k=changedVal; k<oldVal; k++) {
3440: var elementName = current[k];
3441: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3442: }
3443: }
3444: return;
3445: }
3446:
3447: function toggleProctoring(form,item) {
3448: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3449: if (fieldsets.length) {
3450: var radioname = 'proctoring_available_'+item;
3451: var num = form.elements[radioname].length;
3452: if (num) {
3453: var setvis = '';
3454: for (var i=0; i<num; i++) {
3455: if (form.elements[radioname][i].checked) {
3456: if (form.elements[radioname][i].value == '1') {
3457: setvis = 1;
3458: break;
3459: }
3460: }
3461: }
3462: for (var j=0; j<fieldsets.length; j++) {
3463: if (setvis) {
3464: fieldsets[j].style.display = 'block';
3465: } else {
3466: fieldsets[j].style.display = 'none';
3467: }
3468: }
3469: }
3470: }
3471: return;
3472: }
3473:
3474: // ]]>
3475: </script>
3476:
3477: ENDSCRIPT
3478: }
3479:
3480:
1.320 raeburn 3481: sub lti_javascript {
1.405 raeburn 3482: my ($dom,$settings) = @_;
3483: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3484: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3485: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3486: return $togglejs.'
3487: <script type="text/javascript">
3488: // <![CDATA[
3489:
3490: '.$linkprot_js.'
3491:
3492: // ]]>
3493: </script>
3494: ';
1.320 raeburn 3495: }
3496: my (%ordered,$total,%jstext);
1.390 raeburn 3497: $total = scalar(keys(%{$settings}));
1.320 raeburn 3498: foreach my $item (keys(%{$settings})) {
3499: if (ref($settings->{$item}) eq 'HASH') {
3500: my $num = $settings->{$item}{'order'};
1.390 raeburn 3501: if ($num eq '') {
3502: $num = $total - 1;
3503: }
1.320 raeburn 3504: $ordered{$num} = $item;
3505: }
3506: }
3507: my @jsarray = ();
3508: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3509: push(@jsarray,$ordered{$item});
3510: }
3511: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3512: return <<"ENDSCRIPT";
3513: <script type="text/javascript">
3514: // <![CDATA[
3515: function reorderLTI(form,item) {
3516: var changedVal;
3517: $jstext
3518: var newpos = 'lti_pos_add';
3519: var maxh = 1 + $total;
3520: var current = new Array;
3521: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3522: if (item == newpos) {
3523: changedVal = newitemVal;
3524: } else {
3525: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3526: current[newitemVal] = newpos;
3527: }
3528: for (var i=0; i<lti.length; i++) {
3529: var elementName = 'lti_pos_'+lti[i];
3530: if (elementName != item) {
3531: if (form.elements[elementName]) {
3532: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3533: current[currVal] = elementName;
3534: }
3535: }
3536: }
3537: var oldVal;
3538: for (var j=0; j<maxh; j++) {
3539: if (current[j] == undefined) {
3540: oldVal = j;
3541: }
3542: }
3543: if (oldVal < changedVal) {
3544: for (var k=oldVal+1; k<=changedVal ; k++) {
3545: var elementName = current[k];
3546: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3547: }
3548: } else {
3549: for (var k=changedVal; k<oldVal; k++) {
3550: var elementName = current[k];
3551: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3552: }
3553: }
3554: return;
3555: }
1.406 raeburn 3556:
3557: $linkprot_js
3558:
1.320 raeburn 3559: // ]]>
3560: </script>
3561:
3562: $togglejs
3563:
3564: ENDSCRIPT
3565: }
3566:
3567: sub lti_toggle_js {
1.405 raeburn 3568: my ($dom) = @_;
1.325 raeburn 3569: my %lcauthparmtext = &Apache::lonlocal::texthash (
3570: localauth => 'Local auth argument',
3571: krb => 'Kerberos domain',
3572: );
1.391 raeburn 3573: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3574: &js_escape(\$crsincalert);
1.405 raeburn 3575: my %servers = &Apache::lonnet::get_servers($dom,'library');
3576: my $primary = &Apache::lonnet::domain($dom,'primary');
3577: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3578: return <<"ENDSCRIPT";
3579: <script type="text/javascript">
3580: // <![CDATA[
3581:
3582: function toggleLTI(form,setting,item) {
1.391 raeburn 3583: if ((setting == 'requser') || (setting == 'crsinc')) {
3584: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3585: var setvis = '';
3586: var radioname = 'lti_requser_'+item;
3587: var num = form.elements[radioname].length;
3588: if (num) {
3589: for (var i=0; i<num; i++) {
3590: if (form.elements[radioname][i].checked) {
3591: if (form.elements[radioname][i].value == '1') {
3592: setvis = 1;
3593: break;
3594: }
3595: }
3596: }
3597: }
3598: if (usrfieldsets.length) {
3599: for (var j=0; j<usrfieldsets.length; j++) {
3600: if (setvis) {
3601: usrfieldsets[j].style.display = 'block';
3602: } else {
3603: usrfieldsets[j].style.display = 'none';
3604: }
3605: }
3606: }
3607: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3608: if (crsfieldsets.length) {
3609: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3610: var num = form.elements[radioname].length;
3611: if (num) {
1.391 raeburn 3612: var crsvis = '';
1.345 raeburn 3613: for (var i=0; i<num; i++) {
3614: if (form.elements[radioname][i].checked) {
3615: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3616: if (setvis == '') {
3617: if (setting == 'crsinc'){
3618: alert("$crsincalert");
3619: form.elements[radioname][0].checked = true;
3620: }
3621: } else {
3622: crsvis = 1;
3623: }
3624: break;
1.345 raeburn 3625: }
3626: }
3627: }
1.391 raeburn 3628: setvis = crsvis;
3629: }
3630: for (var j=0; j<crsfieldsets.length; j++) {
3631: if (setvis) {
3632: crsfieldsets[j].style.display = 'block';
3633: } else {
3634: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3635: }
3636: }
3637: }
1.363 raeburn 3638: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3639: var radioname = '';
3640: var divid = '';
3641: if (setting == 'user') {
3642: radioname = 'lti_mapuser_'+item;
3643: divid = 'lti_userfield_'+item;
1.343 raeburn 3644: } else if (setting == 'crs') {
1.320 raeburn 3645: radioname = 'lti_mapcrs_'+item;
3646: divid = 'lti_crsfield_'+item;
1.363 raeburn 3647: } else if (setting == 'callback') {
3648: radioname = 'lti_callback_'+item;
3649: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3650: } else {
1.351 raeburn 3651: radioname = 'lti_passback_'+item;
1.337 raeburn 3652: divid = 'lti_passback_'+item;
1.320 raeburn 3653: }
3654: var num = form.elements[radioname].length;
3655: if (num) {
3656: var setvis = '';
3657: for (var i=0; i<num; i++) {
3658: if (form.elements[radioname][i].checked) {
1.363 raeburn 3659: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3660: if (form.elements[radioname][i].value == '1') {
3661: if (document.getElementById(divid)) {
3662: document.getElementById(divid).style.display = 'inline-block';
3663: }
3664: setvis = 1;
3665: break;
3666: }
3667: } else {
3668: if (form.elements[radioname][i].value == 'other') {
3669: if (document.getElementById(divid)) {
3670: document.getElementById(divid).style.display = 'inline-block';
3671: }
3672: setvis = 1;
3673: break;
1.320 raeburn 3674: }
3675: }
1.425 raeburn 3676: }
1.320 raeburn 3677: }
3678: if (!setvis) {
3679: if (document.getElementById(divid)) {
3680: document.getElementById(divid).style.display = 'none';
3681: }
3682: }
3683: }
3684: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3685: var numsec = form.elements['lti_crssec_'+item].length;
3686: if (numsec) {
3687: var setvis = '';
3688: for (var i=0; i<numsec; i++) {
3689: if (form.elements['lti_crssec_'+item][i].checked) {
3690: if (form.elements['lti_crssec_'+item][i].value == '1') {
3691: if (document.getElementById('lti_crssecfield_'+item)) {
3692: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3693: setvis = 1;
3694: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3695: if (numsrcsec) {
3696: var setsrcvis = '';
3697: for (var j=0; j<numsrcsec; j++) {
3698: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3699: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3700: if (document.getElementById('lti_secsrcfield_'+item)) {
3701: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3702: setsrcvis = 1;
3703: }
3704: }
3705: }
3706: }
3707: if (!setsrcvis) {
3708: if (document.getElementById('lti_secsrcfield_'+item)) {
3709: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3710: }
3711: }
3712: }
3713: }
3714: }
3715: }
3716: }
3717: if (!setvis) {
3718: if (document.getElementById('lti_crssecfield_'+item)) {
3719: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3720: }
3721: if (document.getElementById('lti_secsrcfield_'+item)) {
3722: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3723: }
3724: }
3725: }
1.325 raeburn 3726: } else if (setting == 'lcauth') {
3727: var numauth = form.elements['lti_lcauth_'+item].length;
3728: if (numauth) {
3729: for (var i=0; i<numauth; i++) {
3730: if (form.elements['lti_lcauth_'+item][i].checked) {
3731: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3732: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3733: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3734: } else {
3735: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3736: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3737: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3738: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3739: } else {
3740: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3741: }
3742: }
3743: }
3744: }
3745: }
3746: }
3747: }
1.326 raeburn 3748: } else if (setting == 'lcmenu') {
3749: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3750: var divid = 'lti_menufield_'+item;
3751: var setvis = '';
3752: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3753: var radioname = menus[i];
1.326 raeburn 3754: var num = form.elements[radioname].length;
3755: if (num) {
3756: for (var j=0; j<num; j++) {
3757: if (form.elements[radioname][j].checked) {
3758: if (form.elements[radioname][j].value == '1') {
3759: if (document.getElementById(divid)) {
3760: document.getElementById(divid).style.display = 'inline-block';
3761: }
3762: setvis = 1;
3763: break;
3764: }
3765: }
3766: }
3767: }
3768: if (setvis == 1) {
3769: break;
3770: }
3771: }
3772: if (!setvis) {
3773: if (document.getElementById(divid)) {
3774: document.getElementById(divid).style.display = 'none';
3775: }
3776: }
1.320 raeburn 3777: }
3778: return;
3779: }
1.405 raeburn 3780:
1.320 raeburn 3781: // ]]>
3782: </script>
3783:
3784: ENDSCRIPT
3785: }
3786:
1.385 raeburn 3787: sub autoupdate_javascript {
3788: return <<"ENDSCRIPT";
3789: <script type="text/javascript">
3790: // <![CDATA[
3791: function toggleLastActiveDays(form) {
3792: var radioname = 'lastactive';
3793: var divid = 'lastactive_div';
3794: var num = form.elements[radioname].length;
3795: if (num) {
3796: var setvis = '';
3797: for (var i=0; i<num; i++) {
3798: if (form.elements[radioname][i].checked) {
3799: if (form.elements[radioname][i].value == '1') {
3800: if (document.getElementById(divid)) {
3801: document.getElementById(divid).style.display = 'inline-block';
3802: }
3803: setvis = 1;
3804: }
3805: break;
3806: }
3807: }
3808: if (!setvis) {
3809: if (document.getElementById(divid)) {
3810: document.getElementById(divid).style.display = 'none';
3811: }
3812: }
3813: }
3814: return;
3815: }
3816: // ]]>
3817: </script>
3818:
3819: ENDSCRIPT
3820: }
3821:
1.399 raeburn 3822: sub autoenroll_javascript {
3823: return <<"ENDSCRIPT";
3824: <script type="text/javascript">
3825: // <![CDATA[
3826: function toggleFailsafe(form) {
3827: var radioname = 'autoenroll_failsafe';
3828: var divid = 'autoenroll_failsafe_div';
3829: var num = form.elements[radioname].length;
3830: if (num) {
3831: var setvis = '';
3832: for (var i=0; i<num; i++) {
3833: if (form.elements[radioname][i].checked) {
3834: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3835: if (document.getElementById(divid)) {
3836: document.getElementById(divid).style.display = 'inline-block';
3837: }
3838: setvis = 1;
3839: }
3840: break;
3841: }
3842: }
3843: if (!setvis) {
3844: if (document.getElementById(divid)) {
3845: document.getElementById(divid).style.display = 'none';
3846: }
3847: }
3848: }
3849: return;
3850: }
3851: // ]]>
3852: </script>
3853:
3854: ENDSCRIPT
3855: }
3856:
1.386 raeburn 3857: sub saml_javascript {
3858: return <<"ENDSCRIPT";
3859: <script type="text/javascript">
3860: // <![CDATA[
1.425 raeburn 3861: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3862: var radioname = 'saml_'+hostid;
3863: var tablecellon = 'samloptionson_'+hostid;
3864: var tablecelloff = 'samloptionsoff_'+hostid;
3865: var num = form.elements[radioname].length;
3866: if (num) {
1.425 raeburn 3867: var setvis = '';
1.386 raeburn 3868: for (var i=0; i<num; i++) {
3869: if (form.elements[radioname][i].checked) {
1.425 raeburn 3870: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3871: if (document.getElementById(tablecellon)) {
3872: document.getElementById(tablecellon).style.display='';
3873: }
3874: if (document.getElementById(tablecelloff)) {
3875: document.getElementById(tablecelloff).style.display='none';
3876: }
3877: setvis = 1;
3878: }
3879: break;
3880: }
3881: }
3882: if (!setvis) {
3883: if (document.getElementById(tablecellon)) {
3884: document.getElementById(tablecellon).style.display='none';
3885: }
3886: if (document.getElementById(tablecelloff)) {
3887: document.getElementById(tablecelloff).style.display='';
3888: }
3889: }
3890: }
3891: return;
3892: }
3893: // ]]>
3894: </script>
3895:
3896: ENDSCRIPT
3897: }
3898:
1.394 raeburn 3899: sub ipaccess_javascript {
3900: my ($settings) = @_;
3901: my (%ordered,$total,%jstext);
3902: $total = 0;
3903: if (ref($settings) eq 'HASH') {
3904: foreach my $item (keys(%{$settings})) {
3905: if (ref($settings->{$item}) eq 'HASH') {
3906: my $num = $settings->{$item}{'order'};
3907: $ordered{$num} = $item;
3908: }
3909: }
3910: $total = scalar(keys(%{$settings}));
3911: }
3912: my @jsarray = ();
3913: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3914: push(@jsarray,$ordered{$item});
3915: }
3916: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3917: return <<"ENDSCRIPT";
3918: <script type="text/javascript">
3919: // <![CDATA[
3920: function reorderIPaccess(form,item) {
3921: var changedVal;
3922: $jstext
3923: var newpos = 'ipaccess_pos_add';
3924: var maxh = 1 + $total;
3925: var current = new Array;
3926: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3927: if (item == newpos) {
3928: changedVal = newitemVal;
3929: } else {
3930: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3931: current[newitemVal] = newpos;
3932: }
3933: for (var i=0; i<ipaccess.length; i++) {
3934: var elementName = 'ipaccess_pos_'+ipaccess[i];
3935: if (elementName != item) {
3936: if (form.elements[elementName]) {
3937: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3938: current[currVal] = elementName;
3939: }
3940: }
3941: }
3942: var oldVal;
3943: for (var j=0; j<maxh; j++) {
3944: if (current[j] == undefined) {
3945: oldVal = j;
3946: }
3947: }
3948: if (oldVal < changedVal) {
3949: for (var k=oldVal+1; k<=changedVal ; k++) {
3950: var elementName = current[k];
3951: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3952: }
3953: } else {
3954: for (var k=changedVal; k<oldVal; k++) {
3955: var elementName = current[k];
3956: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3957: }
3958: }
3959: return;
3960: }
3961: // ]]>
3962: </script>
3963:
3964: ENDSCRIPT
3965: }
3966:
1.429 raeburn 3967: sub authordefaults_javascript {
3968: my %alert = &Apache::lonlocal::texthash (
3969: reqd => 'Warning: at least one editor needs to be available.',
3970: rest => 'Unchecking this editor disallowed while others unchecked.',
3971: );
3972: &js_escape(\%alert);
3973: return <<"ENDSCRIPT";
3974: <script type="text/javascript">
3975: // <![CDATA[
3976:
3977: function checkEditors(form,checkbox,current) {
3978: if (form.elements[checkbox].length != undefined) {
3979: var count = 0;
3980: for (var i=0; i<form.elements[checkbox].length; i++) {
3981: if (form.elements[checkbox][i].checked) {
3982: count ++;
3983: }
3984: }
3985: if (count == 0) {
3986: if (current.type =='radio') {
3987: current.checked = true;
3988: alert('$alert{reqd}\\n$alert{rest}');
3989: }
3990: }
3991: }
3992: return;
3993: }
3994: // ]]>
3995: </script>
3996:
3997: ENDSCRIPT
3998: }
3999:
1.3 raeburn 4000: sub print_autoenroll {
1.30 raeburn 4001: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 4002: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 4003: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
4004: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
4005: $failsafesty = 'none';
4006: %failsafechecked = (
4007: off => ' checked="checked"',
4008: );
1.3 raeburn 4009: if (ref($settings) eq 'HASH') {
4010: if (exists($settings->{'run'})) {
4011: if ($settings->{'run'} eq '0') {
4012: $runoff = ' checked="checked" ';
4013: $runon = ' ';
4014: } else {
4015: $runon = ' checked="checked" ';
4016: $runoff = ' ';
4017: }
4018: } else {
4019: if ($autorun) {
4020: $runon = ' checked="checked" ';
4021: $runoff = ' ';
4022: } else {
4023: $runoff = ' checked="checked" ';
4024: $runon = ' ';
4025: }
4026: }
1.129 raeburn 4027: if (exists($settings->{'co-owners'})) {
4028: if ($settings->{'co-owners'} eq '0') {
4029: $coownersoff = ' checked="checked" ';
4030: $coownerson = ' ';
4031: } else {
4032: $coownerson = ' checked="checked" ';
4033: $coownersoff = ' ';
4034: }
4035: } else {
4036: $coownersoff = ' checked="checked" ';
4037: $coownerson = ' ';
4038: }
1.3 raeburn 4039: if (exists($settings->{'sender_domain'})) {
4040: $defdom = $settings->{'sender_domain'};
4041: }
1.399 raeburn 4042: if (exists($settings->{'failsafe'})) {
4043: $failsafe = $settings->{'failsafe'};
4044: if ($failsafe eq 'zero') {
1.400 raeburn 4045: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4046: $failsafechecked{'off'} = '';
4047: $failsafesty = 'inline-block';
4048: } elsif ($failsafe eq 'any') {
4049: $failsafechecked{'any'} = ' checked="checked"';
4050: $failsafechecked{'off'} = '';
4051: }
4052: $autofailsafe = $settings->{'autofailsafe'};
4053: } elsif (exists($settings->{'autofailsafe'})) {
4054: $autofailsafe = $settings->{'autofailsafe'};
4055: if ($autofailsafe ne '') {
4056: $failsafechecked{'zero'} = ' checked="checked"';
4057: $failsafe = 'zero';
1.400 raeburn 4058: $failsafechecked{'off'} = '';
1.399 raeburn 4059: }
1.274 raeburn 4060: }
1.14 raeburn 4061: } else {
4062: if ($autorun) {
4063: $runon = ' checked="checked" ';
4064: $runoff = ' ';
4065: } else {
4066: $runoff = ' checked="checked" ';
4067: $runon = ' ';
4068: }
1.3 raeburn 4069: }
4070: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4071: my $notif_sender;
4072: if (ref($settings) eq 'HASH') {
4073: $notif_sender = $settings->{'sender_uname'};
4074: }
1.3 raeburn 4075: my $datatable='<tr class="LC_odd_row">'.
4076: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4077: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4078: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4079: $runon.' value="1" />'.&mt('Yes').'</label> '.
4080: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4081: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4082: '</tr><tr>'.
4083: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4084: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4085: &mt('username').': '.
4086: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4087: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4088: ': '.$domform.'</span></td></tr>'.
4089: '<tr class="LC_odd_row">'.
4090: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4091: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4092: '<input type="radio" name="autoassign_coowners"'.
4093: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4094: '<label><input type="radio" name="autoassign_coowners"'.
4095: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4096: '</tr><tr>'.
4097: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4098: '<td class="LC_left_item"><span class="LC_nobreak">'.
4099: '<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> '.
4100: '<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 />'.
4101: '<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 4102: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4103: '<span class="LC_nobreak">'.
4104: &mt('Threshold for number of students in section to drop: [_1]',
4105: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4106: '</span></div></td></tr>';
1.274 raeburn 4107: $$rowtotal += 4;
1.3 raeburn 4108: return $datatable;
4109: }
4110:
4111: sub print_autoupdate {
1.30 raeburn 4112: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4113: my ($enable,$datatable);
1.3 raeburn 4114: if ($position eq 'top') {
1.385 raeburn 4115: my %choices = &Apache::lonlocal::texthash (
4116: run => 'Auto-update active?',
4117: classlists => 'Update information in classlists?',
4118: unexpired => 'Skip updates for users without active or future roles?',
4119: lastactive => 'Skip updates for inactive users?',
4120: );
4121: my $itemcount = 0;
1.3 raeburn 4122: my $updateon = ' ';
4123: my $updateoff = ' checked="checked" ';
4124: if (ref($settings) eq 'HASH') {
4125: if ($settings->{'run'} eq '1') {
4126: $updateon = $updateoff;
4127: $updateoff = ' ';
4128: }
4129: }
1.385 raeburn 4130: $enable = '<tr class="LC_odd_row">'.
4131: '<td>'.$choices{'run'}.'</td>'.
4132: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4133: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4134: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4135: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4136: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4137: '</tr>';
1.385 raeburn 4138: my @toggles = ('classlists','unexpired');
4139: my %defaultchecked = ('classlists' => 'off',
4140: 'unexpired' => 'off'
4141: );
4142: $$rowtotal ++;
4143: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4144: \%choices,$itemcount,'','','left','no');
4145: $datatable = $enable.$datatable;
4146: $$rowtotal += $itemcount;
4147: my $lastactiveon = ' ';
4148: my $lastactiveoff = ' checked="checked" ';
4149: my $lastactivestyle = 'none';
4150: my $lastactivedays;
4151: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4152: if (ref($settings) eq 'HASH') {
4153: if ($settings->{'lastactive'} =~ /^\d+$/) {
4154: $lastactiveon = $lastactiveoff;
4155: $lastactiveoff = ' ';
4156: $lastactivestyle = 'inline-block';
4157: $lastactivedays = $settings->{'lastactive'};
4158: }
4159: }
4160: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4161: $datatable .= '<tr'.$css_class.'>'.
4162: '<td>'.$choices{'lastactive'}.'</td>'.
4163: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4164: '<input type="radio" name="lastactive"'.
4165: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4166: ' <label>'.
4167: '<input type="radio" name="lastactive"'.
4168: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4169: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4170: ': '.&mt('inactive = no activity in last [_1] days',
4171: '<input type="text" size="5" name="lastactivedays" value="'.
4172: $lastactivedays.'" />').
4173: '</span></td>'.
4174: '</tr>';
4175: $$rowtotal ++;
1.131 raeburn 4176: } elsif ($position eq 'middle') {
4177: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4178: my $numinrow = 3;
4179: my $locknamesettings;
4180: $datatable .= &insttypes_row($settings,$types,$usertypes,
4181: $dom,$numinrow,$othertitle,
1.305 raeburn 4182: 'lockablenames',$rowtotal);
1.131 raeburn 4183: $$rowtotal ++;
1.3 raeburn 4184: } else {
1.44 raeburn 4185: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4186: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4187: 'permanentemail','id');
1.33 raeburn 4188: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4189: my $numrows = 0;
1.26 raeburn 4190: if (ref($types) eq 'ARRAY') {
4191: if (@{$types} > 0) {
4192: $datatable =
4193: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4194: \@fields,$types,\$numrows);
1.30 raeburn 4195: $$rowtotal += @{$types};
1.26 raeburn 4196: }
1.3 raeburn 4197: }
4198: $datatable .=
4199: &usertype_update_row($settings,{'default' => $othertitle},
4200: \%fieldtitles,\@fields,['default'],
4201: \$numrows);
1.30 raeburn 4202: $$rowtotal ++;
1.3 raeburn 4203: }
4204: return $datatable;
4205: }
4206:
1.125 raeburn 4207: sub print_autocreate {
4208: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4209: my (%createon,%createoff,%currhash);
1.125 raeburn 4210: my @types = ('xml','req');
4211: if (ref($settings) eq 'HASH') {
4212: foreach my $item (@types) {
4213: $createoff{$item} = ' checked="checked" ';
4214: $createon{$item} = ' ';
4215: if (exists($settings->{$item})) {
4216: if ($settings->{$item}) {
4217: $createon{$item} = ' checked="checked" ';
4218: $createoff{$item} = ' ';
4219: }
4220: }
4221: }
1.210 raeburn 4222: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4223: $currhash{$settings->{'xmldc'}} = 1;
4224: }
1.125 raeburn 4225: } else {
4226: foreach my $item (@types) {
4227: $createoff{$item} = ' checked="checked" ';
4228: $createon{$item} = ' ';
4229: }
4230: }
4231: $$rowtotal += 2;
1.191 raeburn 4232: my $numinrow = 2;
1.125 raeburn 4233: my $datatable='<tr class="LC_odd_row">'.
4234: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4235: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4236: '<input type="radio" name="autocreate_xml"'.
4237: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4238: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4239: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4240: '</td></tr><tr>'.
4241: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4242: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4243: '<input type="radio" name="autocreate_req"'.
4244: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4245: '<label><input type="radio" name="autocreate_req"'.
4246: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4247: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4248: 'autocreate_xmldc',%currhash);
1.247 raeburn 4249: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4250: if ($numdc > 1) {
1.247 raeburn 4251: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4252: '</td><td class="LC_left_item">';
1.125 raeburn 4253: } else {
1.247 raeburn 4254: $datatable .= &mt('Course creation processed as:').
4255: '</td><td class="LC_right_item">';
1.125 raeburn 4256: }
1.247 raeburn 4257: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4258: $$rowtotal += $rows;
1.125 raeburn 4259: return $datatable;
4260: }
4261:
1.23 raeburn 4262: sub print_directorysrch {
1.277 raeburn 4263: my ($position,$dom,$settings,$rowtotal) = @_;
4264: my $datatable;
4265: if ($position eq 'top') {
4266: my $instsrchon = ' ';
4267: my $instsrchoff = ' checked="checked" ';
4268: my ($exacton,$containson,$beginson);
4269: my $instlocalon = ' ';
4270: my $instlocaloff = ' checked="checked" ';
4271: if (ref($settings) eq 'HASH') {
4272: if ($settings->{'available'} eq '1') {
4273: $instsrchon = $instsrchoff;
4274: $instsrchoff = ' ';
4275: }
4276: if ($settings->{'localonly'} eq '1') {
4277: $instlocalon = $instlocaloff;
4278: $instlocaloff = ' ';
4279: }
4280: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4281: foreach my $type (@{$settings->{'searchtypes'}}) {
4282: if ($type eq 'exact') {
4283: $exacton = ' checked="checked" ';
4284: } elsif ($type eq 'contains') {
4285: $containson = ' checked="checked" ';
4286: } elsif ($type eq 'begins') {
4287: $beginson = ' checked="checked" ';
4288: }
4289: }
4290: } else {
4291: if ($settings->{'searchtypes'} eq 'exact') {
4292: $exacton = ' checked="checked" ';
4293: } elsif ($settings->{'searchtypes'} eq 'contains') {
4294: $containson = ' checked="checked" ';
4295: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4296: $exacton = ' checked="checked" ';
4297: $containson = ' checked="checked" ';
4298: }
4299: }
1.277 raeburn 4300: }
4301: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4302: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4303:
4304: my $numinrow = 4;
4305: my $cansrchrow = 0;
4306: $datatable='<tr class="LC_odd_row">'.
4307: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4308: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4309: '<input type="radio" name="dirsrch_available"'.
4310: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4311: '<label><input type="radio" name="dirsrch_available"'.
4312: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4313: '</tr><tr>'.
4314: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4315: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4316: '<input type="radio" name="dirsrch_instlocalonly"'.
4317: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4318: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4319: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4320: '</tr>';
4321: $$rowtotal += 2;
4322: if (ref($usertypes) eq 'HASH') {
4323: if (keys(%{$usertypes}) > 0) {
4324: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4325: $numinrow,$othertitle,'cansearch',
4326: $rowtotal);
1.277 raeburn 4327: $cansrchrow = 1;
1.25 raeburn 4328: }
1.23 raeburn 4329: }
1.277 raeburn 4330: if ($cansrchrow) {
4331: $$rowtotal ++;
4332: $datatable .= '<tr>';
4333: } else {
4334: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4335: }
1.277 raeburn 4336: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4337: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4338: foreach my $title (@{$titleorder}) {
4339: if (defined($searchtitles->{$title})) {
4340: my $check = ' ';
4341: if (ref($settings) eq 'HASH') {
4342: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4343: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4344: $check = ' checked="checked" ';
4345: }
1.39 raeburn 4346: }
1.25 raeburn 4347: }
1.277 raeburn 4348: $datatable .= '<td class="LC_left_item">'.
4349: '<span class="LC_nobreak"><label>'.
4350: '<input type="checkbox" name="searchby" '.
4351: 'value="'.$title.'"'.$check.'/>'.
4352: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4353: }
4354: }
1.277 raeburn 4355: $datatable .= '</tr></table></td></tr>';
4356: $$rowtotal ++;
4357: if ($cansrchrow) {
4358: $datatable .= '<tr class="LC_odd_row">';
4359: } else {
4360: $datatable .= '<tr>';
4361: }
4362: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4363: '<td class="LC_left_item" colspan="2">'.
4364: '<span class="LC_nobreak"><label>'.
4365: '<input type="checkbox" name="searchtypes" '.
4366: $exacton.' value="exact" />'.&mt('Exact match').
4367: '</label> '.
4368: '<label><input type="checkbox" name="searchtypes" '.
4369: $beginson.' value="begins" />'.&mt('Begins with').
4370: '</label> '.
4371: '<label><input type="checkbox" name="searchtypes" '.
4372: $containson.' value="contains" />'.&mt('Contains').
4373: '</label></span></td></tr>';
4374: $$rowtotal ++;
1.26 raeburn 4375: } else {
1.277 raeburn 4376: my $domsrchon = ' checked="checked" ';
4377: my $domsrchoff = ' ';
4378: my $domlocalon = ' ';
4379: my $domlocaloff = ' checked="checked" ';
4380: if (ref($settings) eq 'HASH') {
4381: if ($settings->{'lclocalonly'} eq '1') {
4382: $domlocalon = $domlocaloff;
4383: $domlocaloff = ' ';
4384: }
4385: if ($settings->{'lcavailable'} eq '0') {
4386: $domsrchoff = $domsrchon;
4387: $domsrchon = ' ';
4388: }
4389: }
4390: $datatable='<tr class="LC_odd_row">'.
4391: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4392: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4393: '<input type="radio" name="dirsrch_domavailable"'.
4394: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4395: '<label><input type="radio" name="dirsrch_domavailable"'.
4396: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4397: '</tr><tr>'.
4398: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4399: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4400: '<input type="radio" name="dirsrch_domlocalonly"'.
4401: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4402: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4403: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4404: '</tr>';
4405: $$rowtotal += 2;
1.26 raeburn 4406: }
1.25 raeburn 4407: return $datatable;
4408: }
4409:
1.28 raeburn 4410: sub print_contacts {
1.286 raeburn 4411: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4412: my $datatable;
4413: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4414: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4415: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4416: if ($position eq 'top') {
4417: if (ref($settings) eq 'HASH') {
4418: foreach my $item (@contacts) {
4419: if (exists($settings->{$item})) {
4420: $to{$item} = $settings->{$item};
4421: }
4422: }
4423: }
4424: } elsif ($position eq 'middle') {
4425: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4426: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4427: foreach my $type (@mailings) {
4428: $otheremails{$type} = '';
4429: }
1.340 raeburn 4430: } elsif ($position eq 'lower') {
4431: if (ref($settings) eq 'HASH') {
4432: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4433: %lonstatus = %{$settings->{'lonstatus'}};
4434: }
4435: }
1.286 raeburn 4436: } else {
4437: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4438: foreach my $type (@mailings) {
4439: $otheremails{$type} = '';
4440: }
1.286 raeburn 4441: $bccemails{'helpdeskmail'} = '';
4442: $bccemails{'otherdomsmail'} = '';
4443: $includestr{'helpdeskmail'} = '';
4444: $includestr{'otherdomsmail'} = '';
4445: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4446: }
1.28 raeburn 4447: if (ref($settings) eq 'HASH') {
1.340 raeburn 4448: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4449: foreach my $type (@mailings) {
4450: if (exists($settings->{$type})) {
4451: if (ref($settings->{$type}) eq 'HASH') {
4452: foreach my $item (@contacts) {
4453: if ($settings->{$type}{$item}) {
4454: $checked{$type}{$item} = ' checked="checked" ';
4455: }
4456: }
4457: $otheremails{$type} = $settings->{$type}{'others'};
4458: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4459: $bccemails{$type} = $settings->{$type}{'bcc'};
4460: if ($settings->{$type}{'include'} ne '') {
4461: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4462: $includestr{$type} = &unescape($includestr{$type});
4463: }
4464: }
4465: }
4466: } elsif ($type eq 'lonstatusmail') {
4467: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4468: }
1.28 raeburn 4469: }
4470: }
1.286 raeburn 4471: if ($position eq 'bottom') {
4472: foreach my $type (@mailings) {
4473: $bccemails{$type} = $settings->{$type}{'bcc'};
4474: if ($settings->{$type}{'include'} ne '') {
4475: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4476: $includestr{$type} = &unescape($includestr{$type});
4477: }
4478: }
4479: if (ref($settings->{'helpform'}) eq 'HASH') {
4480: if (ref($fields) eq 'ARRAY') {
4481: foreach my $field (@{$fields}) {
4482: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4483: }
1.286 raeburn 4484: }
4485: if (exists($settings->{'helpform'}{'maxsize'})) {
4486: $maxsize = $settings->{'helpform'}{'maxsize'};
4487: } else {
1.289 raeburn 4488: $maxsize = '1.0';
1.286 raeburn 4489: }
4490: } else {
4491: if (ref($fields) eq 'ARRAY') {
4492: foreach my $field (@{$fields}) {
4493: $currfield{$field} = 'yes';
1.134 raeburn 4494: }
1.28 raeburn 4495: }
1.286 raeburn 4496: $maxsize = '1.0';
1.28 raeburn 4497: }
4498: }
4499: } else {
1.286 raeburn 4500: if ($position eq 'top') {
4501: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4502: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4503: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4504: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4505: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4506: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4507: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4508: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4509: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4510: } elsif ($position eq 'bottom') {
4511: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4512: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4513: if (ref($fields) eq 'ARRAY') {
4514: foreach my $field (@{$fields}) {
4515: $currfield{$field} = 'yes';
4516: }
4517: }
4518: $maxsize = '1.0';
4519: }
1.28 raeburn 4520: }
4521: my ($titles,$short_titles) = &contact_titles();
4522: my $rownum = 0;
4523: my $css_class;
1.286 raeburn 4524: if ($position eq 'top') {
4525: foreach my $item (@contacts) {
4526: $css_class = $rownum%2?' class="LC_odd_row"':'';
4527: $datatable .= '<tr'.$css_class.'>'.
4528: '<td><span class="LC_nobreak">'.$titles->{$item}.
4529: '</span></td><td class="LC_right_item">'.
4530: '<input type="text" name="'.$item.'" value="'.
4531: $to{$item}.'" /></td></tr>';
4532: $rownum ++;
4533: }
1.315 raeburn 4534: } elsif ($position eq 'bottom') {
4535: $css_class = $rownum%2?' class="LC_odd_row"':'';
4536: $datatable .= '<tr'.$css_class.'>'.
4537: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4538: &mt('(e-mail, subject, and description always shown)').
4539: '</td><td class="LC_left_item">';
4540: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4541: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4542: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4543: foreach my $field (@{$fields}) {
4544: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4545: if (($field eq 'screenshot') || ($field eq 'cc')) {
4546: $datatable .= ' '.&mt('(logged-in users)');
4547: }
4548: $datatable .='</td><td>';
4549: my $clickaction;
4550: if ($field eq 'screenshot') {
4551: $clickaction = ' onclick="screenshotSize(this);"';
4552: }
4553: if (ref($possoptions->{$field}) eq 'ARRAY') {
4554: foreach my $option (@{$possoptions->{$field}}) {
4555: my $checked;
4556: if ($currfield{$field} eq $option) {
4557: $checked = ' checked="checked"';
4558: }
4559: $datatable .= '<span class="LC_nobreak"><label>'.
4560: '<input type="radio" name="helpform_'.$field.'" '.
4561: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4562: '</label></span>'.(' 'x2);
4563: }
4564: }
4565: if ($field eq 'screenshot') {
4566: my $display;
4567: if ($currfield{$field} eq 'no') {
4568: $display = ' style="display:none"';
4569: }
1.334 raeburn 4570: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4571: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4572: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4573: }
4574: $datatable .= '</td></tr>';
4575: }
4576: $datatable .= '</table>';
4577: }
4578: $datatable .= '</td></tr>'."\n";
4579: $rownum ++;
4580: }
1.340 raeburn 4581: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4582: foreach my $type (@mailings) {
4583: $css_class = $rownum%2?' class="LC_odd_row"':'';
4584: $datatable .= '<tr'.$css_class.'>'.
4585: '<td><span class="LC_nobreak">'.
4586: $titles->{$type}.': </span></td>'.
4587: '<td class="LC_left_item">';
4588: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4589: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4590: }
4591: $datatable .= '<span class="LC_nobreak">';
4592: foreach my $item (@contacts) {
4593: $datatable .= '<label>'.
4594: '<input type="checkbox" name="'.$type.'"'.
4595: $checked{$type}{$item}.
4596: ' value="'.$item.'" />'.$short_titles->{$item}.
4597: '</label> ';
4598: }
4599: $datatable .= '</span><br />'.&mt('Others').': '.
4600: '<input type="text" name="'.$type.'_others" '.
4601: 'value="'.$otheremails{$type}.'" />';
4602: my %locchecked;
4603: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4604: foreach my $loc ('s','b') {
4605: if ($includeloc{$type} eq $loc) {
4606: $locchecked{$loc} = ' checked="checked"';
4607: last;
4608: }
4609: }
4610: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4611: '<input type="text" name="'.$type.'_bcc" '.
4612: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4613: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4614: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4615: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4616: '<span class="LC_nobreak">'.&mt('Location:').' '.
4617: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4618: (' 'x2).
4619: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4620: '</span></fieldset>';
4621: }
4622: $datatable .= '</td></tr>'."\n";
4623: $rownum ++;
4624: }
1.28 raeburn 4625: }
1.286 raeburn 4626: if ($position eq 'middle') {
4627: my %choices;
1.340 raeburn 4628: my $corelink = &core_link_msu();
4629: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4630: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4631: $corelink);
4632: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4633: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4634: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4635: 'reportupdates' => 'on',
4636: 'reportstatus' => 'on');
1.286 raeburn 4637: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4638: \%choices,$rownum);
4639: $datatable .= $reports;
1.340 raeburn 4640: } elsif ($position eq 'lower') {
1.378 raeburn 4641: my (%current,%excluded,%weights);
1.340 raeburn 4642: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4643: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4644: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4645: } else {
1.378 raeburn 4646: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4647: }
4648: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4649: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4650: } else {
1.378 raeburn 4651: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4652: }
4653: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4654: foreach my $type ('E','W','N','U') {
1.340 raeburn 4655: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4656: $weights{$type} = $lonstatus{'weights'}{$type};
4657: } else {
4658: $weights{$type} = $defaults->{$type};
4659: }
4660: }
4661: } else {
1.341 raeburn 4662: foreach my $type ('E','W','N','U') {
1.340 raeburn 4663: $weights{$type} = $defaults->{$type};
4664: }
4665: }
4666: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4667: if (@{$lonstatus{'excluded'}} > 0) {
4668: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4669: }
4670: }
1.425 raeburn 4671: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4672: $css_class = $rownum%2?' class="LC_odd_row"':'';
4673: $datatable .= '<tr'.$css_class.'>'.
4674: '<td class="LC_left_item"><span class="LC_nobreak">'.
4675: $titles->{$item}.
4676: '</span></td><td class="LC_left_item">'.
4677: '<input type="text" name="'.$item.'" value="'.
4678: $current{$item}.'" size="5" /></td></tr>';
4679: $rownum ++;
4680: }
1.340 raeburn 4681: $css_class = $rownum%2?' class="LC_odd_row"':'';
4682: $datatable .= '<tr'.$css_class.'>'.
4683: '<td class="LC_left_item">'.
4684: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4685: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4686: foreach my $type ('E','W','N','U') {
1.340 raeburn 4687: $datatable .= '<td>'.$names->{$type}.'<br />'.
4688: '<input type="text" name="errorweights_'.$type.'" value="'.
4689: $weights{$type}.'" size="5" /></td>';
4690: }
4691: $datatable .= '</tr></table></tr>';
4692: $rownum ++;
4693: $css_class = $rownum%2?' class="LC_odd_row"':'';
4694: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4695: $titles->{'errorexcluded'}.'</td>'.
4696: '<td class="LC_left_item"><table>';
4697: my $numinrow = 4;
4698: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4699: for (my $i=0; $i<@ids; $i++) {
4700: my $rem = $i%($numinrow);
4701: if ($rem == 0) {
4702: if ($i > 0) {
4703: $datatable .= '</tr>';
4704: }
4705: $datatable .= '<tr>';
4706: }
4707: my $check;
4708: if ($excluded{$ids[$i]}) {
4709: $check = ' checked="checked" ';
4710: }
4711: $datatable .= '<td class="LC_left_item">'.
4712: '<span class="LC_nobreak"><label>'.
4713: '<input type="checkbox" name="errorexcluded" '.
4714: 'value="'.$ids[$i].'"'.$check.' />'.
4715: $ids[$i].'</label></span></td>';
4716: }
4717: my $colsleft = $numinrow - @ids%($numinrow);
4718: if ($colsleft > 1 ) {
4719: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4720: ' </td>';
4721: } elsif ($colsleft == 1) {
4722: $datatable .= '<td class="LC_left_item"> </td>';
4723: }
4724: $datatable .= '</tr></table></td></tr>';
4725: $rownum ++;
1.286 raeburn 4726: } elsif ($position eq 'bottom') {
1.315 raeburn 4727: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4728: my (@posstypes,%usertypeshash);
4729: if (ref($types) eq 'ARRAY') {
4730: @posstypes = @{$types};
4731: }
4732: if (@posstypes) {
4733: if (ref($usertypes) eq 'HASH') {
4734: %usertypeshash = %{$usertypes};
4735: }
4736: my @overridden;
4737: my $numinrow = 4;
4738: if (ref($settings) eq 'HASH') {
4739: if (ref($settings->{'overrides'}) eq 'HASH') {
4740: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4741: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4742: push(@overridden,$key);
4743: foreach my $item (@contacts) {
4744: if ($settings->{'overrides'}{$key}{$item}) {
4745: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4746: }
4747: }
4748: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4749: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4750: $includeloc{'override_'.$key} = '';
4751: $includestr{'override_'.$key} = '';
4752: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4753: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4754: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4755: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4756: }
1.286 raeburn 4757: }
4758: }
4759: }
1.315 raeburn 4760: }
4761: my $customclass = 'LC_helpdesk_override';
4762: my $optionsprefix = 'LC_options_helpdesk_';
4763:
4764: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4765: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4766: $numinrow,$othertitle,'overrides',
4767: \$rownum,$onclicktypes,$customclass);
4768: $rownum ++;
4769: $usertypeshash{'default'} = $othertitle;
4770: foreach my $status (@posstypes) {
4771: my $css_class;
4772: if ($rownum%2) {
4773: $css_class = 'LC_odd_row ';
4774: }
4775: $css_class .= $customclass;
4776: my $rowid = $optionsprefix.$status;
4777: my $hidden = 1;
4778: my $currstyle = 'display:none';
4779: if (grep(/^\Q$status\E$/,@overridden)) {
4780: $currstyle = 'display:table-row';
4781: $hidden = 0;
4782: }
4783: my $key = 'override_'.$status;
4784: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4785: $includeloc{$key},$includestr{$key},$status,$rowid,
4786: $usertypeshash{$status},$css_class,$currstyle,
4787: \@contacts,$short_titles);
4788: unless ($hidden) {
4789: $rownum ++;
1.286 raeburn 4790: }
4791: }
1.134 raeburn 4792: }
1.28 raeburn 4793: }
1.30 raeburn 4794: $$rowtotal += $rownum;
1.28 raeburn 4795: return $datatable;
4796: }
4797:
1.340 raeburn 4798: sub core_link_msu {
4799: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4800: &mt('LON-CAPA core group - MSU'),600,500);
4801: }
4802:
1.315 raeburn 4803: sub overridden_helpdesk {
4804: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4805: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4806: my $class = 'LC_left_item';
4807: if ($css_class) {
4808: $css_class = ' class="'.$css_class.'"';
4809: }
4810: if ($rowid) {
4811: $rowid = ' id="'.$rowid.'"';
4812: }
4813: if ($rowstyle) {
4814: $rowstyle = ' style="'.$rowstyle.'"';
4815: }
4816: my ($output,$description);
4817: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4818: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4819: "<td>$description</td>\n".
4820: '<td class="'.$class.'" colspan="2">'.
4821: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4822: '<span class="LC_nobreak">';
4823: if (ref($contacts) eq 'ARRAY') {
4824: foreach my $item (@{$contacts}) {
4825: my $check;
4826: if (ref($checked) eq 'HASH') {
4827: $check = $checked->{$item};
4828: }
4829: my $title;
4830: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4831: $title = $short_titles->{$item};
1.315 raeburn 4832: }
4833: $output .= '<label>'.
4834: '<input type="checkbox" name="override_'.$type.'"'.$check.
4835: ' value="'.$item.'" />'.$title.'</label> ';
4836: }
4837: }
4838: $output .= '</span><br />'.&mt('Others').': '.
4839: '<input type="text" name="override_'.$type.'_others" '.
4840: 'value="'.$otheremails.'" />';
4841: my %locchecked;
4842: foreach my $loc ('s','b') {
4843: if ($includeloc eq $loc) {
4844: $locchecked{$loc} = ' checked="checked"';
4845: last;
4846: }
4847: }
4848: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4849: '<input type="text" name="override_'.$type.'_bcc" '.
4850: 'value="'.$bccemails.'" /></fieldset>'.
4851: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4852: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4853: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4854: '<span class="LC_nobreak">'.&mt('Location:').' '.
4855: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4856: (' 'x2).
4857: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4858: '</span></fieldset>'.
4859: '</td></tr>'."\n";
4860: return $output;
4861: }
4862:
1.286 raeburn 4863: sub contacts_javascript {
4864: return <<"ENDSCRIPT";
4865:
4866: <script type="text/javascript">
4867: // <![CDATA[
4868:
4869: function screenshotSize(field) {
4870: if (document.getElementById('help_screenshotsize')) {
4871: if (field.value == 'no') {
1.289 raeburn 4872: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4873: } else {
4874: document.getElementById('help_screenshotsize').style.display="";
4875: }
4876: }
4877: return;
4878: }
4879:
1.315 raeburn 4880: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4881: if (form.elements[checkbox].length != undefined) {
4882: var count = 0;
4883: if (docount) {
4884: for (var i=0; i<form.elements[checkbox].length; i++) {
4885: if (form.elements[checkbox][i].checked) {
4886: count ++;
4887: }
4888: }
4889: }
4890: for (var i=0; i<form.elements[checkbox].length; i++) {
4891: var type = form.elements[checkbox][i].value;
4892: if (document.getElementById(prefix+type)) {
4893: if (form.elements[checkbox][i].checked) {
4894: document.getElementById(prefix+type).style.display = 'table-row';
4895: if (count % 2 == 1) {
4896: document.getElementById(prefix+type).className = target+' LC_odd_row';
4897: } else {
4898: document.getElementById(prefix+type).className = target;
4899: }
4900: count ++;
4901: } else {
4902: document.getElementById(prefix+type).style.display = 'none';
4903: }
4904: }
4905: }
4906: }
4907: return;
4908: }
4909:
1.286 raeburn 4910: // ]]>
4911: </script>
4912:
4913: ENDSCRIPT
4914: }
4915:
1.118 jms 4916: sub print_helpsettings {
1.282 raeburn 4917: my ($position,$dom,$settings,$rowtotal) = @_;
4918: my $confname = $dom.'-domainconfig';
1.285 raeburn 4919: my $formname = 'display';
1.168 raeburn 4920: my ($datatable,$itemcount);
1.282 raeburn 4921: if ($position eq 'top') {
4922: $itemcount = 1;
4923: my (%choices,%defaultchecked,@toggles);
4924: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4925: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4926: &mt('LON-CAPA bug tracker'),600,500));
4927: %defaultchecked = ('submitbugs' => 'on');
4928: @toggles = ('submitbugs');
4929: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4930: \%choices,$itemcount);
4931: $$rowtotal ++;
4932: } else {
4933: my $css_class;
4934: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4935: my (%customroles,%ordered,%current);
1.301 raeburn 4936: if (ref($settings) eq 'HASH') {
4937: if (ref($settings->{'adhoc'}) eq 'HASH') {
4938: %current = %{$settings->{'adhoc'}};
4939: }
1.285 raeburn 4940: }
4941: my $count = 0;
4942: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4943: if ($key=~/^rolesdef\_(\w+)$/) {
4944: my $rolename = $1;
1.285 raeburn 4945: my (%privs,$order);
1.282 raeburn 4946: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4947: $customroles{$rolename} = \%privs;
1.285 raeburn 4948: if (ref($current{$rolename}) eq 'HASH') {
4949: $order = $current{$rolename}{'order'};
4950: }
4951: if ($order eq '') {
4952: $order = $count;
4953: }
4954: $ordered{$order} = $rolename;
4955: $count++;
4956: }
4957: }
4958: my $maxnum = scalar(keys(%ordered));
4959: my @roles_by_num = ();
4960: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4961: push(@roles_by_num,$item);
4962: }
4963: my $context = 'domprefs';
4964: my $crstype = 'Course';
4965: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4966: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4967: my ($numstatustypes,@jsarray);
4968: if (ref($types) eq 'ARRAY') {
4969: if (@{$types} > 0) {
4970: $numstatustypes = scalar(@{$types});
4971: push(@accesstypes,'status');
4972: @jsarray = ('bystatus');
1.282 raeburn 4973: }
4974: }
1.290 raeburn 4975: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4976: if (keys(%domhelpdesk)) {
4977: push(@accesstypes,('inc','exc'));
4978: push(@jsarray,('notinc','notexc'));
4979: }
4980: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4981: my $context = 'domprefs';
4982: my $crstype = 'Course';
1.285 raeburn 4983: my $prefix = 'helproles_';
4984: my $add_class = 'LC_hidden';
4985: foreach my $num (@roles_by_num) {
4986: my $role = $ordered{$num};
4987: my ($desc,$access,@statuses);
4988: if (ref($current{$role}) eq 'HASH') {
4989: $desc = $current{$role}{'desc'};
4990: $access = $current{$role}{'access'};
4991: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4992: @statuses = @{$current{$role}{'insttypes'}};
4993: }
4994: }
4995: if ($desc eq '') {
4996: $desc = $role;
4997: }
4998: my $identifier = 'custhelp'.$num;
1.282 raeburn 4999: my %full=();
5000: my %levels= (
5001: course => {},
5002: domain => {},
5003: system => {},
5004: );
5005: my %levelscurrent=(
5006: course => {},
5007: domain => {},
5008: system => {},
5009: );
5010: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5011: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5013: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5014: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5015: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5016: for (my $k=0; $k<=$maxnum; $k++) {
5017: my $vpos = $k+1;
5018: my $selstr;
5019: if ($k == $num) {
5020: $selstr = ' selected="selected" ';
5021: }
5022: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5023: }
5024: $datatable .= '</select>'.(' 'x2).
5025: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5026: '</td>'.
5027: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5028: &mt('Name shown to users:').
5029: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5030: '</fieldset>'.
5031: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5032: $othertitle,$usertypes,$types,\%domhelpdesk).
5033: '<fieldset>'.
5034: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5035: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5036: \%levelscurrent,$identifier,
5037: 'LC_hidden',$prefix.$num.'_privs').
5038: '</fieldset></td>';
1.282 raeburn 5039: $itemcount ++;
5040: }
5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5042: my $newcust = 'custhelp'.$count;
5043: my (%privs,%levelscurrent);
5044: my %full=();
5045: my %levels= (
5046: course => {},
5047: domain => {},
5048: system => {},
5049: );
5050: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5051: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5052: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5053: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5054: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5055: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5056: for (my $k=0; $k<$maxnum+1; $k++) {
5057: my $vpos = $k+1;
5058: my $selstr;
5059: if ($k == $maxnum) {
5060: $selstr = ' selected="selected" ';
5061: }
5062: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5063: }
5064: $datatable .= '</select> '."\n".
1.282 raeburn 5065: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5066: '</label></span></td>'.
1.285 raeburn 5067: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5068: '<span class="LC_nobreak">'.
5069: &mt('Internal name:').
5070: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5071: '</span>'.(' 'x4).
5072: '<span class="LC_nobreak">'.
5073: &mt('Name shown to users:').
5074: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5075: '</span></fieldset>'.
5076: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5077: $usertypes,$types,\%domhelpdesk).
5078: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5079: &Apache::lonuserutils::custom_role_header($context,$crstype,
5080: \@templateroles,$newcust).
5081: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5082: \%levelscurrent,$newcust).
1.334 raeburn 5083: '</fieldset>'.
5084: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5085: '</td></tr>';
1.282 raeburn 5086: $count ++;
5087: $$rowtotal += $count;
5088: }
1.166 raeburn 5089: return $datatable;
1.121 raeburn 5090: }
5091:
1.285 raeburn 5092: sub adhocbutton {
5093: my ($prefix,$num,$field,$visibility) = @_;
5094: my %lt = &Apache::lonlocal::texthash(
5095: show => 'Show details',
5096: hide => 'Hide details',
5097: );
5098: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5099: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5100: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5101: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5102: }
5103:
5104: sub helpsettings_javascript {
5105: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5106: return unless(ref($roles_by_num) eq 'ARRAY');
5107: my %html_js_lt = &Apache::lonlocal::texthash(
5108: show => 'Show details',
5109: hide => 'Hide details',
5110: );
5111: &html_escape(\%html_js_lt);
5112: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5113: return <<"ENDSCRIPT";
5114: <script type="text/javascript">
5115: // <![CDATA[
5116:
5117: function reorderHelpRoles(form,item) {
5118: var changedVal;
5119: $jstext
5120: var newpos = 'helproles_${total}_pos';
5121: var maxh = 1 + $total;
5122: var current = new Array();
5123: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5124: if (item == newpos) {
5125: changedVal = newitemVal;
5126: } else {
5127: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5128: current[newitemVal] = newpos;
5129: }
5130: for (var i=0; i<helproles.length; i++) {
5131: var elementName = 'helproles_'+helproles[i]+'_pos';
5132: if (elementName != item) {
5133: if (form.elements[elementName]) {
5134: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5135: current[currVal] = elementName;
5136: }
5137: }
5138: }
5139: var oldVal;
5140: for (var j=0; j<maxh; j++) {
5141: if (current[j] == undefined) {
5142: oldVal = j;
5143: }
5144: }
5145: if (oldVal < changedVal) {
5146: for (var k=oldVal+1; k<=changedVal ; k++) {
5147: var elementName = current[k];
5148: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5149: }
5150: } else {
5151: for (var k=changedVal; k<oldVal; k++) {
5152: var elementName = current[k];
5153: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5154: }
5155: }
5156: return;
5157: }
5158:
5159: function helpdeskAccess(num) {
5160: var curraccess = null;
5161: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5162: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5163: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5164: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5165: }
5166: }
5167: }
5168: var shown = Array();
5169: var hidden = Array();
5170: if (curraccess == 'none') {
5171: hidden = Array('$hiddenstr');
5172: } else {
5173: if (curraccess == 'status') {
5174: shown = Array('bystatus');
5175: hidden = Array('notinc','notexc');
5176: } else {
5177: if (curraccess == 'exc') {
5178: shown = Array('notexc');
5179: hidden = Array('notinc','bystatus');
5180: }
5181: if (curraccess == 'inc') {
5182: shown = Array('notinc');
5183: hidden = Array('notexc','bystatus');
5184: }
1.293 raeburn 5185: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5186: hidden = Array('notinc','notexc','bystatus');
5187: }
5188: }
5189: }
5190: if (hidden.length > 0) {
5191: for (var i=0; i<hidden.length; i++) {
5192: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5193: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5194: }
5195: }
5196: }
5197: if (shown.length > 0) {
5198: for (var i=0; i<shown.length; i++) {
5199: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5200: if (shown[i] == 'privs') {
5201: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5202: } else {
5203: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5204: }
5205: }
5206: }
5207: }
5208: return;
5209: }
5210:
5211: function toggleHelpdeskItem(num,field) {
5212: if (document.getElementById('helproles_'+num+'_'+field)) {
5213: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5214: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5215: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5216: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5217: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5218: }
5219: } else {
5220: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5221: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5222: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5223: }
5224: }
5225: }
5226: return;
5227: }
5228:
5229: // ]]>
5230: </script>
5231:
5232: ENDSCRIPT
5233: }
5234:
5235: sub helpdeskroles_access {
5236: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5237: $usertypes,$types,$domhelpdesk) = @_;
5238: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5239: my %lt = &Apache::lonlocal::texthash(
5240: 'rou' => 'Role usage',
5241: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5242: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5243: 'dh' => 'All with domain helpdesk role',
5244: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5245: 'none' => 'None',
5246: 'status' => 'Determined based on institutional status',
5247: 'inc' => 'Include all, but exclude specific personnel',
5248: 'exc' => 'Exclude all, but include specific personnel',
5249: );
5250: my %usecheck = (
5251: all => ' checked="checked"',
5252: );
5253: my %displaydiv = (
5254: status => 'none',
5255: inc => 'none',
5256: exc => 'none',
5257: priv => 'block',
5258: );
5259: my $output;
5260: if (ref($current) eq 'HASH') {
5261: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5262: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5263: $usecheck{$current->{access}} = $usecheck{'all'};
5264: delete($usecheck{'all'});
5265: if ($current->{access} =~ /^(status|inc|exc)$/) {
5266: my $access = $1;
5267: $displaydiv{$access} = 'inline';
5268: } elsif ($current->{access} eq 'none') {
5269: $displaydiv{'priv'} = 'none';
5270: }
5271: }
5272: }
5273: }
5274: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5275: '<p>'.$lt{'whi'}.'</p>';
5276: foreach my $access (@{$accesstypes}) {
5277: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5278: ' onclick="helpdeskAccess('."'$num'".');" />'.
5279: $lt{$access}.'</label>';
5280: if ($access eq 'status') {
5281: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5282: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5283: $othertitle,$usertypes,$types).
5284: '</div>';
5285: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5286: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5287: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5288: '</div>';
5289: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5290: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5291: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5292: '</div>';
5293: }
5294: $output .= '</p>';
5295: }
5296: $output .= '</fieldset>';
5297: return $output;
5298: }
5299:
1.121 raeburn 5300: sub radiobutton_prefs {
1.192 raeburn 5301: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5302: $additional,$align,$firstval) = @_;
1.121 raeburn 5303: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5304: (ref($choices) eq 'HASH'));
5305:
1.170 raeburn 5306: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5307:
5308: foreach my $item (@{$toggles}) {
5309: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5310: $checkedon{$item} = ' checked="checked" ';
5311: $checkedoff{$item} = ' ';
1.121 raeburn 5312: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5313: $checkedoff{$item} = ' checked="checked" ';
5314: $checkedon{$item} = ' ';
5315: }
5316: }
5317: if (ref($settings) eq 'HASH') {
1.121 raeburn 5318: foreach my $item (@{$toggles}) {
1.118 jms 5319: if ($settings->{$item} eq '1') {
5320: $checkedon{$item} = ' checked="checked" ';
5321: $checkedoff{$item} = ' ';
5322: } elsif ($settings->{$item} eq '0') {
5323: $checkedoff{$item} = ' checked="checked" ';
5324: $checkedon{$item} = ' ';
5325: }
5326: }
1.121 raeburn 5327: }
1.192 raeburn 5328: if ($onclick) {
5329: $onclick = ' onclick="'.$onclick.'"';
5330: }
1.121 raeburn 5331: foreach my $item (@{$toggles}) {
1.118 jms 5332: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5333: $datatable .=
1.306 raeburn 5334: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5335: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5336: '</span></td>';
5337: if ($align eq 'left') {
5338: $datatable .= '<td class="LC_left_item">';
5339: } else {
5340: $datatable .= '<td class="LC_right_item">';
5341: }
1.385 raeburn 5342: $datatable .= '<span class="LC_nobreak">';
5343: if ($firstval eq 'no') {
5344: $datatable .=
5345: '<label><input type="radio" name="'.
5346: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5347: '</label> <label><input type="radio" name="'.$item.'" '.
5348: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5349: } else {
5350: $datatable .=
5351: '<label><input type="radio" name="'.
5352: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5353: '</label> <label><input type="radio" name="'.$item.'" '.
5354: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5355: }
5356: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5357: $itemcount ++;
1.121 raeburn 5358: }
5359: return ($datatable,$itemcount);
5360: }
5361:
1.267 raeburn 5362: sub print_ltitools {
1.421 raeburn 5363: my ($position,$dom,$settings,$rowtotal) = @_;
5364: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5365: if (ref($settings) eq 'HASH') {
1.421 raeburn 5366: if ($position eq 'top') {
5367: if (exists($settings->{'encrypt'})) {
5368: if (ref($settings->{'encrypt'}) eq 'HASH') {
5369: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5370: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5371: }
5372: }
1.267 raeburn 5373: }
1.421 raeburn 5374: if (exists($settings->{'private'})) {
5375: if (ref($settings->{'private'}) eq 'HASH') {
5376: if (ref($settings->{'private'}) eq 'HASH') {
5377: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5378: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5379: }
5380: }
5381: }
5382: }
1.421 raeburn 5383: } elsif ($position eq 'middle') {
5384: if (exists($settings->{'rules'})) {
5385: if (ref($settings->{'rules'}) eq 'HASH') {
5386: %rules = %{$settings->{'rules'}};
1.273 raeburn 5387: }
5388: }
1.421 raeburn 5389: } else {
5390: foreach my $key ('encrypt','private','rules') {
5391: if (exists($settings->{$key})) {
5392: delete($settings->{$key});
1.267 raeburn 5393: }
5394: }
5395: }
5396: }
1.421 raeburn 5397: my $datatable;
5398: my $itemcount = 1;
5399: if ($position eq 'top') {
5400: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5401: } elsif ($position eq 'middle') {
5402: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5403: $$rowtotal += $itemcount;
5404: } else {
5405: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5406: }
5407: return $datatable;
5408: }
5409:
5410: sub ltitools_names {
5411: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5412: 'title' => 'Title',
5413: 'version' => 'Version',
5414: 'msgtype' => 'Message Type',
1.323 raeburn 5415: 'sigmethod' => 'Signature Method',
1.296 raeburn 5416: 'url' => 'URL',
5417: 'key' => 'Key',
1.322 raeburn 5418: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5419: 'secret' => 'Secret',
1.425 raeburn 5420: 'icon' => 'Icon',
1.324 raeburn 5421: 'user' => 'User',
1.296 raeburn 5422: 'fullname' => 'Full Name',
5423: 'firstname' => 'First Name',
5424: 'lastname' => 'Last Name',
5425: 'email' => 'E-mail',
5426: 'roles' => 'Role',
1.298 raeburn 5427: 'window' => 'Window',
5428: 'tab' => 'Tab',
1.296 raeburn 5429: 'iframe' => 'iFrame',
5430: 'height' => 'Height',
5431: 'width' => 'Width',
5432: 'linktext' => 'Default Link Text',
5433: 'explanation' => 'Default Explanation',
5434: 'passback' => 'Tool can return grades:',
5435: 'roster' => 'Tool can retrieve roster:',
5436: 'crstarget' => 'Display target',
5437: 'crslabel' => 'Course label',
1.425 raeburn 5438: 'crstitle' => 'Course title',
1.296 raeburn 5439: 'crslinktext' => 'Link Text',
5440: 'crsexplanation' => 'Explanation',
1.318 raeburn 5441: 'crsappend' => 'Provider URL',
1.267 raeburn 5442: );
5443: return %lt;
5444: }
5445:
1.421 raeburn 5446: sub secrets_form {
5447: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5448: my @ids=&Apache::lonnet::current_machine_ids();
5449: my %servers = &Apache::lonnet::get_servers($dom,'library');
5450: my $primary = &Apache::lonnet::domain($dom,'primary');
5451: my ($css_class,$extra,$numshown,$itemcount,$output);
5452: $itemcount = 0;
5453: foreach my $hostid (sort(keys(%servers))) {
5454: my ($showextra,$divsty,$switch);
5455: if ($hostid eq $primary) {
5456: if ($context eq 'ltisec') {
5457: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5458: $showextra = 1;
5459: }
5460: if ($encrypt->{'ltisec_crslinkprot'}) {
5461: $showextra = 1;
5462: }
5463: } else {
5464: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5465: $showextra = 1;
5466: }
5467: }
5468: unless (grep(/^\Q$hostid\E$/,@ids)) {
5469: $switch = 1;
5470: }
5471: if ($showextra) {
5472: $numshown ++;
5473: $divsty = 'display:inline-block';
5474: } else {
5475: $divsty = 'display:none';
5476: }
5477: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5478: '<legend>'.$hostid.'</legend>';
5479: if ($switch) {
5480: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5481: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5482: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5483: if (exists($privkeys->{$hostid})) {
5484: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5485: '<span class="LC_nobreak">'.
5486: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5487: '<span class="LC_nobreak">'.&mt('Change?').
5488: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5489: (' 'x2).
5490: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5491: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5492: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5493: '</span></div>';
5494: } else {
5495: $extra .= '<span class="LC_nobreak">'.
5496: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5497: '</span>'."\n";
5498: }
5499: } elsif (exists($privkeys->{$hostid})) {
5500: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5501: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5502: '<span class="LC_nobreak">'.&mt('Change?').
5503: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5504: (' 'x2).
5505: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5506: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5507: '<span class="LC_nobreak">'.&mt('New Key').':'.
5508: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5509: '<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>'.
5510: '</span></div>';
5511: } else {
5512: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5513: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5514: '<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>';
5515: }
5516: $extra .= '</fieldset>';
5517: }
5518: }
5519: my (%choices,@toggles,%defaultchecked);
5520: if ($context eq 'ltisec') {
5521: %choices = &Apache::lonlocal::texthash (
5522: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5523: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5524: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5525: );
5526: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5527: %defaultchecked = (
5528: 'ltisec_crslinkprot' => 'off',
5529: 'ltisec_domlinkprot' => 'off',
5530: 'ltisec_consumers' => 'off',
5531: );
5532: } else {
5533: %choices = &Apache::lonlocal::texthash (
5534: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5535: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5536: );
5537: @toggles = qw(toolsec_crs toolsec_dom);
5538: %defaultchecked = (
5539: 'toolsec_crs' => 'off',
5540: 'toolsec_dom' => 'off',
5541: );
5542: }
5543: my ($onclick,$itemcount);
5544: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5545: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5546: \%choices,$itemcount,$onclick,'','left','no');
5547:
5548: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5549: my $noprivkeysty = 'display:inline-block';
5550: if ($numshown) {
5551: $noprivkeysty = 'display:none';
5552: }
5553: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5554: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5555: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5556: $extra.
5557: '</td></tr>';
5558: $itemcount ++;
5559: $$rowtotal += $itemcount;
5560: return $output;
5561: }
5562:
1.372 raeburn 5563: sub print_proctoring {
5564: my ($dom,$settings,$rowtotal) = @_;
5565: my $itemcount = 1;
5566: my (%ordered,%providernames,%current,%currentdef);
5567: my $confname = $dom.'-domainconfig';
5568: my $switchserver = &check_switchserver($dom,$confname);
5569: if (ref($settings) eq 'HASH') {
5570: foreach my $item (keys(%{$settings})) {
5571: if (ref($settings->{$item}) eq 'HASH') {
5572: my $num = $settings->{$item}{'order'};
5573: $ordered{$num} = $item;
5574: }
5575: }
5576: } else {
5577: %ordered = (
5578: 1 => 'proctorio',
5579: 2 => 'examity',
5580: );
5581: }
5582: %providernames = &proctoring_providernames();
5583: my $maxnum = scalar(keys(%ordered));
5584: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5585: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5586: if (ref($requref) eq 'HASH') {
5587: %requserfields = %{$requref};
5588: }
5589: if (ref($opturef) eq 'HASH') {
5590: %optuserfields = %{$opturef};
5591: }
5592: if (ref($defref) eq 'HASH') {
5593: %defaults = %{$defref};
5594: }
5595: if (ref($extref) eq 'HASH') {
5596: %extended = %{$extref};
5597: }
5598: if (ref($crsref) eq 'HASH') {
5599: %crsconf = %{$crsref};
5600: }
5601: if (ref($rolesref) eq 'ARRAY') {
5602: @courseroles = @{$rolesref};
5603: }
5604: if (ref($ltiref) eq 'ARRAY') {
5605: @ltiroles = @{$ltiref};
5606: }
5607: my $datatable;
5608: my $css_class;
5609: if (keys(%ordered)) {
5610: my @items = sort { $a <=> $b } keys(%ordered);
5611: for (my $i=0; $i<@items; $i++) {
5612: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5613: my $provider = $ordered{$items[$i]};
5614: my $optionsty = 'none';
5615: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5616: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5617: if (ref($settings) eq 'HASH') {
5618: if (ref($settings->{$provider}) eq 'HASH') {
5619: %current = %{$settings->{$provider}};
5620: if ($current{'available'}) {
5621: $optionsty = 'block';
5622: $available = 1;
5623: }
5624: if ($current{'lifetime'} =~ /^\d+$/) {
5625: $lifetime = $current{'lifetime'};
5626: }
5627: if ($current{'version'} =~ /^\d+\.\d+$/) {
5628: $version = $current{'version'};
5629: }
5630: if ($current{'image'} ne '') {
5631: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5632: }
5633: if (ref($current{'fields'}) eq 'ARRAY') {
5634: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5635: }
5636: $userincdom = $current{'incdom'};
5637: if (ref($current{'roles'}) eq 'HASH') {
5638: %rolemaps = %{$current{'roles'}};
5639: $checkedfields{'roles'} = 1;
5640: }
5641: if (ref($current{'defaults'}) eq 'ARRAY') {
5642: foreach my $val (@{$current{'defaults'}}) {
5643: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5644: $inuse{$val} = 1;
5645: } else {
5646: foreach my $poss (keys(%{$extended{$provider}})) {
5647: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5648: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5649: $inuse{$poss} = $val;
5650: last;
5651: }
5652: }
5653: }
5654: }
5655: }
5656: } elsif (ref($current{'defaults'}) eq 'HASH') {
5657: foreach my $key (keys(%{$current{'defaults'}})) {
5658: my $currval = $current{'defaults'}{$key};
5659: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5660: $inuse{$key} = 1;
5661: } else {
5662: my $match;
5663: foreach my $poss (keys(%{$extended{$provider}})) {
5664: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5665: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5666: $inuse{$poss} = $key;
5667: last;
5668: }
5669: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5670: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5671: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5672: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5673: $currentdef{$inner} = $currval;
5674: $match = 1;
5675: last;
5676: }
5677: } elsif ($inner eq $key) {
5678: $currentdef{$key} = $currval;
5679: $match = 1;
5680: last;
5681: }
5682: }
5683: }
5684: last if ($match);
5685: }
5686: }
5687: }
5688: }
5689: if (ref($current{'crsconf'}) eq 'ARRAY') {
5690: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5691: }
5692: }
5693: }
5694: my %lt = &proctoring_titles($provider);
5695: my %fieldtitles = &proctoring_fieldtitles($provider);
5696: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5697: my %checkedavailable = (
5698: yes => '',
5699: no => ' checked="checked"',
5700: );
5701: if ($available) {
5702: $checkedavailable{'yes'} = $checkedavailable{'no'};
5703: $checkedavailable{'no'} = '';
5704: }
5705: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5706: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5707: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5708: for (my $k=0; $k<$maxnum; $k++) {
5709: my $vpos = $k+1;
5710: my $selstr;
5711: if ($k == $i) {
5712: $selstr = ' selected="selected" ';
5713: }
5714: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5715: }
5716: if ($version eq '') {
5717: if ($provider eq 'proctorio') {
5718: $version = '1.0';
5719: } elsif ($provider eq 'examity') {
5720: $version = '1.1';
5721: }
5722: }
5723: if ($lifetime eq '') {
5724: $lifetime = '300';
5725: }
5726: $datatable .=
5727: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5728: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5729: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5730: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5731: '</td>'.
5732: '<td colspan="2">'.
5733: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5734: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5735: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5736: (' 'x2).
5737: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5738: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5739: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5740: (' 'x2).
5741: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5742: '<br />'.
5743: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5744: '<br />'.
5745: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5746: (' 'x2).
5747: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5748: '<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";
5749: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5750: if ($imgsrc) {
5751: $datatable .= $imgsrc.
5752: '<label><input type="checkbox" name="proctoring_image_del"'.
5753: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5754: '<span class="LC_nobreak"> '.&mt('Replace:');
5755: }
5756: $datatable .= ' ';
5757: if ($switchserver) {
5758: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5759: } else {
5760: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5761: }
5762: unless ($imgsrc) {
5763: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5764: }
5765: $datatable .= '</fieldset>'."\n";
5766: if (ref($requserfields{$provider}) eq 'ARRAY') {
5767: if (@{$requserfields{$provider}} > 0) {
5768: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5769: foreach my $field (@{$requserfields{$provider}}) {
5770: $datatable .= '<span class="LC_nobreak">'.
5771: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5772: $lt{$field}.'</label>';
5773: if ($field eq 'user') {
5774: my $seluserdom = '';
5775: my $unseluserdom = ' selected="selected"';
5776: if ($userincdom) {
5777: $seluserdom = $unseluserdom;
5778: $unseluserdom = '';
5779: }
5780: $datatable .= ': '.
5781: '<select name="proctoring_userincdom_'.$provider.'">'.
5782: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5783: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5784: '</select> ';
5785: } else {
5786: $datatable .= ' ';
5787: if ($field eq 'roles') {
5788: $showroles = 1;
5789: }
5790: }
5791: $datatable .= '</span> ';
5792: }
5793: }
5794: $datatable .= '</fieldset>'."\n";
5795: }
5796: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5797: if (@{$optuserfields{$provider}} > 0) {
5798: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5799: foreach my $field (@{$optuserfields{$provider}}) {
5800: my $checked;
5801: if ($checkedfields{$field}) {
5802: $checked = ' checked="checked"';
5803: }
5804: $datatable .= '<span class="LC_nobreak">'.
5805: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5806: }
5807: $datatable .= '</fieldset>'."\n";
5808: }
5809: }
5810: if (ref($defaults{$provider}) eq 'ARRAY') {
5811: if (@{$defaults{$provider}}) {
5812: my (%options,@selectboxes);
5813: if (ref($extended{$provider}) eq 'HASH') {
5814: %options = %{$extended{$provider}};
5815: }
5816: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5817: my ($rem,$numinrow,$dropdowns);
5818: if ($provider eq 'proctorio') {
5819: $datatable .= '<table>';
5820: $numinrow = 4;
5821: }
5822: my $i = 0;
5823: foreach my $field (@{$defaults{$provider}}) {
5824: my $checked;
5825: if ($inuse{$field}) {
5826: $checked = ' checked="checked"';
5827: }
5828: if ($provider eq 'examity') {
5829: if ($field eq 'display') {
5830: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5831: foreach my $option ('iframe','tab','window') {
5832: my $checkdisp;
5833: if ($currentdef{'target'} eq $option) {
5834: $checkdisp = ' checked="checked"';
5835: }
5836: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5837: $fieldtitles{$option}.'</label>'.(' 'x2);
5838: }
5839: $datatable .= (' 'x4);
5840: foreach my $dimen ('width','height') {
5841: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5842: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5843: 'value="'.$currentdef{$dimen}.'" /></label>'.
5844: (' 'x2);
5845: }
5846: $datatable .= '</span><br />'.
5847: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5848: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5849: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5850: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5851: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5852: $currentdef{'explanation'}.
5853: '</textarea></div><div style=""></div><br />';
5854: }
5855: } else {
5856: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5857: my ($output,$selnone);
5858: unless ($checked) {
5859: $selnone = ' selected="selected"';
5860: }
5861: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5862: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5863: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5864: foreach my $option (@{$options{$field}}) {
5865: my $sel;
5866: if ($inuse{$field} eq $option) {
5867: $sel = ' selected="selected"';
5868: }
5869: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5870: }
5871: $output .= '</select></span>';
5872: push(@selectboxes,$output);
5873: } else {
5874: $rem = $i%($numinrow);
5875: if ($rem == 0) {
5876: if ($i > 0) {
5877: $datatable .= '</tr>';
5878: }
5879: $datatable .= '<tr>';
5880: }
5881: $datatable .= '<td class="LC_left_item">'.
5882: '<span class="LC_nobreak">'.
5883: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5884: $fieldtitles{$field}.'</label></span></td>';
5885: $i++;
5886: }
5887: }
5888: }
5889: if ($provider eq 'proctorio') {
5890: if ($numinrow) {
5891: $rem = $i%$numinrow;
5892: }
5893: my $colsleft = $numinrow - $rem;
5894: if ($colsleft > 1) {
5895: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5896: } else {
5897: $datatable .= '<td class="LC_left_item">';
5898: }
5899: $datatable .= ' '.
5900: '</td></tr></table>';
5901: if (@selectboxes) {
5902: $datatable .= '<hr /><table>';
5903: $numinrow = 2;
5904: for (my $i=0; $i<@selectboxes; $i++) {
5905: $rem = $i%($numinrow);
5906: if ($rem == 0) {
5907: if ($i > 0) {
5908: $datatable .= '</tr>';
5909: }
5910: $datatable .= '<tr>';
5911: }
5912: $datatable .= '<td class="LC_left_item">'.
5913: $selectboxes[$i].'</td>';
5914: }
5915: if ($numinrow) {
5916: $rem = $i%$numinrow;
5917: }
5918: $colsleft = $numinrow - $rem;
5919: if ($colsleft > 1) {
5920: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5921: } else {
5922: $datatable .= '<td class="LC_left_item">';
5923: }
5924: $datatable .= ' '.
5925: '</td></tr></table>';
5926: }
5927: }
5928: $datatable .= '</fieldset>';
5929: }
5930: if (ref($crsconf{$provider}) eq 'ARRAY') {
5931: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5932: '<legend>'.&mt('Configurable in course').'</legend>';
5933: my ($rem,$numinrow);
5934: if ($provider eq 'proctorio') {
5935: $datatable .= '<table>';
5936: $numinrow = 4;
5937: }
5938: my $i = 0;
5939: foreach my $item (@{$crsconf{$provider}}) {
5940: my $name;
5941: if ($provider eq 'examity') {
5942: $name = $lt{'crs'.$item};
5943: } elsif ($provider eq 'proctorio') {
5944: $name = $fieldtitles{$item};
5945: $rem = $i%($numinrow);
5946: if ($rem == 0) {
5947: if ($i > 0) {
5948: $datatable .= '</tr>';
5949: }
5950: $datatable .= '<tr>';
5951: }
5952: $datatable .= '<td class="LC_left_item>';
5953: }
5954: my $checked;
5955: if ($crsconfig{$item}) {
5956: $checked = ' checked="checked"';
5957: }
5958: $datatable .= '<span class="LC_nobreak"><label>'.
5959: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5960: $name.'</label></span>';
5961: if ($provider eq 'examity') {
5962: $datatable .= ' ';
5963: }
5964: $datatable .= "\n";
5965: $i++;
5966: }
5967: if ($provider eq 'proctorio') {
5968: if ($numinrow) {
5969: $rem = $i%$numinrow;
5970: }
5971: my $colsleft = $numinrow - $rem;
5972: if ($colsleft > 1) {
5973: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5974: } else {
5975: $datatable .= '<td class="LC_left_item">';
5976: }
5977: $datatable .= ' '.
5978: '</td></tr></table>';
5979: }
5980: $datatable .= '</fieldset>';
5981: }
5982: if ($showroles) {
5983: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5984: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5985: foreach my $role (@courseroles) {
5986: my ($selected,$selectnone);
5987: if (!$rolemaps{$role}) {
5988: $selectnone = ' selected="selected"';
5989: }
5990: $datatable .= '<td style="text-align: center">'.
5991: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5992: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5993: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5994: foreach my $ltirole (@ltiroles) {
5995: unless ($selectnone) {
5996: if ($rolemaps{$role} eq $ltirole) {
5997: $selected = ' selected="selected"';
5998: } else {
5999: $selected = '';
6000: }
6001: }
6002: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
6003: }
6004: $datatable .= '</select></td>';
6005: }
6006: $datatable .= '</tr></table></fieldset>'.
6007: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6008: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6009: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6010: '<tr><td></td><td>lms</td>'.
6011: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6012: ' value="Loncapa" disabled="disabled"/></td></tr>';
6013: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6014: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6015: my %custom = %{$settings->{$provider}->{'custom'}};
6016: if (keys(%custom) > 0) {
6017: foreach my $key (sort(keys(%custom))) {
6018: next if ($key eq 'lms');
6019: $datatable .= '<tr><td><span class="LC_nobreak">'.
6020: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6021: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6022: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6023: ' value="'.$custom{$key}.'" /></td></tr>';
6024: }
6025: }
6026: }
6027: $datatable .= '<tr><td><span class="LC_nobreak">'.
6028: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6029: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6030: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6031: '</table></fieldset></td></tr>'."\n";
6032: }
6033: $datatable .= '</td></tr>';
6034: }
6035: $itemcount ++;
6036: }
6037: }
6038: return $datatable;
6039: }
6040:
6041: sub proctoring_data {
6042: my $requserfields = {
6043: proctorio => ['user'],
6044: examity => ['roles','user'],
6045: };
6046: my $optuserfields = {
6047: proctorio => ['fullname'],
6048: examity => ['fullname','firstname','lastname','email'],
6049: };
6050: my $defaults = {
6051: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6052: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6053: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6054: 'closetabs','onescreen','print','downloads','cache','rightclick',
6055: 'reentry','calculator','whiteboard'],
6056: examity => ['display'],
6057: };
6058: my $extended = {
6059: proctorio => {
6060: verifyid => ['verifyidauto','verifyidlive'],
6061: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6062: tabslinks => ['notabs','linksonly'],
6063: reentry => ['noreentry','agentreentry'],
6064: calculator => ['calculatorbasic','calculatorsci'],
6065: },
6066: examity => {
6067: display => {
6068: target => ['iframe','tab','window'],
6069: width => '',
6070: height => '',
6071: linktext => '',
6072: explanation => '',
6073: },
6074: },
6075: };
6076: my $crsconf = {
6077: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6078: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6079: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6080: 'closetabs','onescreen','print','downloads','cache','rightclick',
6081: 'reentry','calculator','whiteboard'],
6082: examity => ['label','title','target','linktext','explanation','append'],
6083: };
6084: my $courseroles = ['cc','in','ta','ep','st'];
6085: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6086: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6087: }
6088:
6089: sub proctoring_titles {
6090: my ($item) = @_;
6091: my (%common_lt,%custom_lt);
6092: %common_lt = &Apache::lonlocal::texthash (
6093: 'avai' => 'Available?',
6094: 'base' => 'Basic Settings',
6095: 'requ' => 'User data required to be sent on launch',
6096: 'optu' => 'User data optionally sent on launch',
6097: 'udsl' => 'User data sent on launch',
6098: 'defa' => 'Defaults for items configurable in course',
6099: 'sigmethod' => 'Signature Method',
6100: 'key' => 'Key',
6101: 'lifetime' => 'Nonce lifetime (s)',
6102: 'secret' => 'Secret',
6103: 'icon' => 'Icon',
6104: 'fullname' => 'Full Name',
6105: 'visible' => 'Visible input',
6106: 'username' => 'username',
6107: 'user' => 'User',
6108: );
6109: if ($item eq 'proctorio') {
6110: %custom_lt = &Apache::lonlocal::texthash (
6111: 'version' => 'OAuth version',
6112: 'url' => 'API URL',
6113: 'uname:dom' => 'username-domain',
6114: );
6115: } elsif ($item eq 'examity') {
6116: %custom_lt = &Apache::lonlocal::texthash (
6117: 'version' => 'LTI Version',
6118: 'url' => 'URL',
6119: 'uname:dom' => 'username:domain',
6120: 'msgtype' => 'Message Type',
6121: 'firstname' => 'First Name',
6122: 'lastname' => 'Last Name',
6123: 'email' => 'E-mail',
6124: 'roles' => 'Role',
6125: 'crstarget' => 'Display target',
6126: 'crslabel' => 'Course label',
6127: 'crstitle' => 'Course title',
6128: 'crslinktext' => 'Link Text',
6129: 'crsexplanation' => 'Explanation',
6130: 'crsappend' => 'Provider URL',
6131: );
6132: }
6133: my %lt = (%common_lt,%custom_lt);
6134: return %lt;
6135: }
6136:
6137: sub proctoring_fieldtitles {
6138: my ($item) = @_;
6139: if ($item eq 'proctorio') {
6140: return &Apache::lonlocal::texthash (
6141: 'recordvideo' => 'Record video',
6142: 'recordaudio' => 'Record audio',
6143: 'recordscreen' => 'Record screen',
6144: 'recordwebtraffic' => 'Record web traffic',
6145: 'recordroomstart' => 'Record room scan',
6146: 'verifyvideo' => 'Verify webcam',
6147: 'verifyaudio' => 'Verify microphone',
6148: 'verifydesktop' => 'Verify desktop recording',
6149: 'verifyid' => 'Photo ID verification',
6150: 'verifysignature' => 'Require signature',
6151: 'fullscreen' => 'Fullscreen',
6152: 'clipboard' => 'Disable copy/paste',
6153: 'tabslinks' => 'New tabs/windows',
6154: 'closetabs' => 'Close other tabs',
6155: 'onescreen' => 'Limit to single screen',
6156: 'print' => 'Disable Printing',
6157: 'downloads' => 'Disable Downloads',
6158: 'cache' => 'Empty cache after exam',
6159: 'rightclick' => 'Disable right click',
6160: 'reentry' => 'Re-entry to exam',
6161: 'calculator' => 'Onscreen calculator',
6162: 'whiteboard' => 'Onscreen whiteboard',
6163: 'verifyidauto' => 'Automated verification',
6164: 'verifyidlive' => 'Live agent verification',
6165: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6166: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6167: 'fullscreensever' => 'Forced, navigation away ends exam',
6168: 'notabs' => 'Disaallowed',
6169: 'linksonly' => 'Allowed from links in exam',
6170: 'noreentry' => 'Disallowed',
6171: 'agentreentry' => 'Agent required for re-entry',
6172: 'calculatorbasic' => 'Basic',
6173: 'calculatorsci' => 'Scientific',
6174: );
6175: } elsif ($item eq 'examity') {
6176: return &Apache::lonlocal::texthash (
6177: 'target' => 'Display target',
6178: 'window' => 'Window',
6179: 'tab' => 'Tab',
6180: 'iframe' => 'iFrame',
6181: 'height' => 'Height (pixels)',
6182: 'width' => 'Width (pixels)',
6183: 'linktext' => 'Default Link Text',
6184: 'explanation' => 'Default Explanation',
6185: 'append' => 'Provider URL',
6186: );
6187: }
6188: }
6189:
6190: sub proctoring_providernames {
6191: return (
6192: proctorio => 'Proctorio',
6193: examity => 'Examity',
6194: );
6195: }
6196:
1.320 raeburn 6197: sub print_lti {
1.405 raeburn 6198: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6199: my $itemcount = 1;
1.405 raeburn 6200: my ($datatable,$css_class);
1.434 raeburn 6201: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6202: if (ref($settings) eq 'HASH') {
1.405 raeburn 6203: if ($position eq 'top') {
6204: if (exists($settings->{'encrypt'})) {
6205: if (ref($settings->{'encrypt'}) eq 'HASH') {
6206: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6207: if ($key eq 'consumers') {
6208: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6209: } else {
6210: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6211: }
6212: }
6213: }
6214: }
6215: if (exists($settings->{'private'})) {
6216: if (ref($settings->{'private'}) eq 'HASH') {
6217: if (ref($settings->{'private'}) eq 'HASH') {
6218: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6219: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6220: }
6221: }
6222: }
6223: }
1.434 raeburn 6224: } elsif ($position eq 'upper') {
1.405 raeburn 6225: if (exists($settings->{'rules'})) {
6226: if (ref($settings->{'rules'}) eq 'HASH') {
6227: %rules = %{$settings->{'rules'}};
6228: }
6229: }
1.434 raeburn 6230: } elsif ($position eq 'middle') {
6231: if (exists($settings->{'suggested'})) {
6232: if (ref($settings->{'suggested'}) eq 'HASH') {
6233: %suggestions = %{$settings->{'suggested'}};
6234: }
6235: }
1.405 raeburn 6236: } elsif ($position eq 'lower') {
6237: if (exists($settings->{'linkprot'})) {
6238: if (ref($settings->{'linkprot'}) eq 'HASH') {
6239: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6240: if ($linkprot{'lock'}) {
6241: delete($linkprot{'lock'});
6242: }
1.405 raeburn 6243: }
6244: }
6245: } else {
1.434 raeburn 6246: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6247: if (exists($settings->{$key})) {
6248: delete($settings->{$key});
1.390 raeburn 6249: }
1.320 raeburn 6250: }
6251: }
6252: }
1.405 raeburn 6253: if ($position eq 'top') {
1.421 raeburn 6254: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6255: } elsif ($position eq 'upper') {
6256: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6257: $$rowtotal += $itemcount;
1.421 raeburn 6258: } elsif ($position eq 'middle') {
1.434 raeburn 6259: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6260: $$rowtotal += $itemcount;
6261: } elsif ($position eq 'lower') {
1.434 raeburn 6262: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6263: } else {
1.424 raeburn 6264: my ($switchserver,$switchmessage);
6265: $switchserver = &check_switchserver($dom);
6266: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6267: my $maxnum = 0;
6268: my %ordered;
6269: if (ref($settings) eq 'HASH') {
6270: foreach my $item (keys(%{$settings})) {
6271: if (ref($settings->{$item}) eq 'HASH') {
6272: my $num = $settings->{$item}{'order'};
6273: if ($num eq '') {
6274: $num = scalar(keys(%{$settings}));
6275: }
6276: $ordered{$num} = $item;
1.405 raeburn 6277: }
1.352 raeburn 6278: }
1.405 raeburn 6279: }
6280: $maxnum = scalar(keys(%ordered));
6281: my %lt = <i_names();
6282: if (keys(%ordered)) {
6283: my @items = sort { $a <=> $b } keys(%ordered);
6284: for (my $i=0; $i<@items; $i++) {
6285: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6286: my $item = $ordered{$items[$i]};
1.424 raeburn 6287: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6288: if (ref($settings->{$item}) eq 'HASH') {
6289: $key = $settings->{$item}->{'key'};
1.424 raeburn 6290: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6291: $lifetime = $settings->{$item}->{'lifetime'};
6292: $consumer = $settings->{$item}->{'consumer'};
6293: $requser = $settings->{$item}->{'requser'};
6294: $crsinc = $settings->{$item}->{'crsinc'};
6295: $current = $settings->{$item};
6296: }
6297: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6298: my %checkedrequser = (
6299: yes => ' checked="checked"',
6300: no => '',
6301: );
6302: if (!$requser) {
6303: $checkedrequser{'no'} = $checkedrequser{'yes'};
6304: $checkedrequser{'yes'} = '';
6305: }
6306: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6307: my %checkedcrsinc = (
1.391 raeburn 6308: yes => ' checked="checked"',
6309: no => '',
1.405 raeburn 6310: );
6311: if (!$crsinc) {
6312: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6313: $checkedcrsinc{'yes'} = '';
6314: }
6315: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6316: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6317: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6318: for (my $k=0; $k<=$maxnum; $k++) {
6319: my $vpos = $k+1;
6320: my $selstr;
6321: if ($k == $i) {
6322: $selstr = ' selected="selected" ';
6323: }
6324: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6325: }
1.405 raeburn 6326: $datatable .= '</select>'.(' 'x2).
6327: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6328: &mt('Delete?').'</label></span></td>'.
6329: '<td colspan="2">'.
6330: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6331: '<span class="LC_nobreak">'.$lt{'consumer'}.
6332: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6333: (' 'x2).
6334: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6335: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6336: (' 'x2).
6337: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6338: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6339: if ($key ne '') {
6340: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6341: if ($switchserver) {
6342: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6343: } else {
6344: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6345: }
6346: $datatable .= '</span> '.(' 'x2);
6347: } elsif (!$switchserver) {
6348: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6349: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6350: '</span> '.(' 'x2);
6351: }
6352: if ($switchserver) {
6353: if ($usable ne '') {
6354: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6355: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6356: '<span class="LC_nobreak">'.&mt('Change secret?').
6357: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6358: (' 'x2).
6359: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6360: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6361: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6362: '</div>';
6363: } elsif ($key eq '') {
6364: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6365: } else {
6366: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6367: }
6368: } else {
6369: if ($usable ne '') {
6370: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6371: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6372: '<span class="LC_nobreak">'.&mt('Change?').
6373: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6374: (' 'x2).
6375: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6376: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6377: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6378: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6379: '<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>';
6380: } else {
6381: $datatable .=
6382: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6383: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6384: '<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>';
6385: }
6386: }
1.425 raeburn 6387: $datatable .= '<br /><br />'.
1.405 raeburn 6388: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6389: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6390: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6391: '<br /><br />'.
6392: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6393: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6394: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6395: (' 'x4).
6396: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6397: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6398: $itemcount ++;
1.320 raeburn 6399: }
6400: }
1.405 raeburn 6401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6402: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6403: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6404: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6405: '<select name="lti_pos_add"'.$chgstr.'>';
6406: for (my $k=0; $k<$maxnum+1; $k++) {
6407: my $vpos = $k+1;
6408: my $selstr;
6409: if ($k == $maxnum) {
6410: $selstr = ' selected="selected" ';
6411: }
6412: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6413: }
1.405 raeburn 6414: $datatable .= '</select> '."\n".
6415: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6416: '<td colspan="2">'.
6417: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6418: '<span class="LC_nobreak">'.$lt{'consumer'}.
6419: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6420: (' 'x2).
6421: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6422: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6423: (' 'x2).
1.424 raeburn 6424: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6425: if ($switchserver) {
6426: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6427: } else {
6428: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6429: (' 'x2).
6430: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6431: '<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";
6432: }
6433: $datatable .= '<br /><br />'.
1.405 raeburn 6434: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6435: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6436: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6437: '<br /><br />'.
6438: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6439: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6440: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6441: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6442: '</td>'."\n".
6443: '</tr>'."\n";
6444: $itemcount ++;
1.320 raeburn 6445: }
1.405 raeburn 6446: $$rowtotal += $itemcount;
6447: return $datatable;
1.320 raeburn 6448: }
6449:
6450: sub lti_names {
6451: my %lt = &Apache::lonlocal::texthash(
6452: 'version' => 'LTI Version',
6453: 'url' => 'URL',
6454: 'key' => 'Key',
1.322 raeburn 6455: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6456: 'consumer' => 'Consumer',
1.320 raeburn 6457: 'secret' => 'Secret',
1.345 raeburn 6458: 'requser' => "User's identity sent",
1.391 raeburn 6459: 'crsinc' => "Course's identity sent",
1.320 raeburn 6460: 'email' => 'Email address',
6461: 'sourcedid' => 'User ID',
6462: 'other' => 'Other',
6463: 'passback' => 'Can return grades to Consumer:',
6464: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6465: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6466: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6467: );
6468: return %lt;
6469: }
6470:
6471: sub lti_options {
1.325 raeburn 6472: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6473: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6474: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6475: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6476: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6477: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6478: $checked{'mapcrstype'} = {};
6479: $checked{'makeuser'} = {};
6480: $checked{'selfenroll'} = {};
6481: $checked{'crssec'} = {};
6482: $checked{'crssecsrc'} = {};
1.325 raeburn 6483: $checked{'lcauth'} = {};
1.326 raeburn 6484: $checked{'menuitem'} = {};
1.325 raeburn 6485: if ($num eq 'add') {
6486: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6487: }
1.320 raeburn 6488: my $userfieldsty = 'none';
6489: my $crsfieldsty = 'none';
6490: my $crssecfieldsty = 'none';
6491: my $secsrcfieldsty = 'none';
1.363 raeburn 6492: my $callbacksty = 'none';
1.337 raeburn 6493: my $passbacksty = 'none';
1.345 raeburn 6494: my $optionsty = 'block';
1.391 raeburn 6495: my $crssty = 'block';
1.325 raeburn 6496: my $lcauthparm;
6497: my $lcauthparmstyle = 'display:none';
6498: my $lcauthparmtext;
1.326 raeburn 6499: my $menusty;
1.325 raeburn 6500: my $numinrow = 4;
1.326 raeburn 6501: my %menutitles = <imenu_titles();
1.320 raeburn 6502:
6503: if (ref($current) eq 'HASH') {
1.345 raeburn 6504: if (!$current->{'requser'}) {
6505: $optionsty = 'none';
1.391 raeburn 6506: $crssty = 'none';
6507: } elsif (!$current->{'crsinc'}) {
6508: $crssty = 'none';
1.345 raeburn 6509: }
1.320 raeburn 6510: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6511: $checked{'mapuser'}{'sourcedid'} = '';
6512: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6513: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6514: } else {
6515: $checked{'mapuser'}{'other'} = ' checked="checked"';
6516: $userfield = $current->{'mapuser'};
6517: $userfieldsty = 'inline-block';
6518: }
6519: }
6520: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6521: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6522: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6523: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6524: } else {
6525: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6526: $cidfield = $current->{'mapcrs'};
6527: $crsfieldsty = 'inline-block';
6528: }
6529: }
6530: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6531: foreach my $type (@{$current->{'mapcrstype'}}) {
6532: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6533: }
6534: }
1.392 raeburn 6535: if (!$current->{'storecrs'}) {
6536: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6537: $checked{'storecrs'}{'Y'} = '';
6538: }
1.345 raeburn 6539: if ($current->{'makecrs'}) {
1.320 raeburn 6540: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6541: }
1.320 raeburn 6542: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6543: foreach my $role (@{$current->{'makeuser'}}) {
6544: $checked{'makeuser'}{$role} = ' checked="checked"';
6545: }
6546: }
1.325 raeburn 6547: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6548: $checked{'lcauth'}{$1} = ' checked="checked"';
6549: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6550: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6551: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6552: if ($current->{'lcauth'} eq 'localauth') {
6553: $lcauthparmtext = &mt('Local auth argument');
6554: } else {
6555: $lcauthparmtext = &mt('Kerberos domain');
6556: }
6557: }
6558: }
1.320 raeburn 6559: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6560: foreach my $role (@{$current->{'selfenroll'}}) {
6561: $checked{'selfenroll'}{$role} = ' checked="checked"';
6562: }
6563: }
6564: if (ref($current->{'maproles'}) eq 'HASH') {
6565: %rolemaps = %{$current->{'maproles'}};
6566: }
6567: if ($current->{'section'} ne '') {
1.425 raeburn 6568: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6569: $crssecfieldsty = 'inline-block';
6570: if ($current->{'section'} eq 'course_section_sourcedid') {
6571: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6572: } else {
6573: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6574: $crssecsrc = $current->{'section'};
6575: $secsrcfieldsty = 'inline-block';
6576: }
6577: } else {
6578: $checked{'crssec'}{'N'} = ' checked="checked"';
6579: }
1.363 raeburn 6580: if ($current->{'callback'} ne '') {
6581: $callback = $current->{'callback'};
6582: $checked{'callback'}{'Y'} = ' checked="checked"';
6583: $callbacksty = 'inline-block';
6584: } else {
6585: $checked{'callback'}{'N'} = ' checked="checked"';
6586: }
1.326 raeburn 6587: if ($current->{'topmenu'}) {
6588: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6589: } else {
6590: $checked{'topmenu'}{'N'} = ' checked="checked"';
6591: }
6592: if ($current->{'inlinemenu'}) {
6593: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6594: } else {
6595: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6596: }
6597: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6598: $menusty = 'inline-block';
6599: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6600: foreach my $item (@{$current->{'lcmenu'}}) {
6601: if (exists($menutitles{$item})) {
6602: $checked{'menuitem'}{$item} = ' checked="checked"';
6603: }
6604: }
6605: }
6606: } else {
6607: $menusty = 'none';
6608: }
1.320 raeburn 6609: } else {
6610: $checked{'makecrs'}{'N'} = ' checked="checked"';
6611: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6612: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6613: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6614: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6615: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6616: $menusty = 'inline-block';
1.320 raeburn 6617: }
1.325 raeburn 6618: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6619: my %coursetypetitles = &Apache::lonlocal::texthash (
6620: official => 'Official',
6621: unofficial => 'Unofficial',
6622: community => 'Community',
6623: textbook => 'Textbook',
6624: placement => 'Placement Test',
1.325 raeburn 6625: lti => 'LTI Provider',
1.320 raeburn 6626: );
1.325 raeburn 6627: my @authtypes = ('internal','krb4','krb5','localauth');
6628: my %shortauth = (
6629: internal => 'int',
6630: krb4 => 'krb4',
6631: krb5 => 'krb5',
6632: localauth => 'loc'
6633: );
6634: my %authnames = &authtype_names();
1.320 raeburn 6635: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6636: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6637: my @courseroles = ('cc','in','ta','ep','st');
6638: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6639: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6640: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6641: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6642: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6643: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6644: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6645: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6646: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6647: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6648: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6649: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6650: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6651: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6652: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6653: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6654: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6655: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6656: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6657: foreach my $option ('sourcedid','email','other') {
6658: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6659: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6660: ($option eq 'other' ? '' : (' 'x2) );
6661: }
6662: $output .= '</span></div>'.
6663: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6664: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6665: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6666: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6667: foreach my $ltirole (@ltiroles) {
6668: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6669: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6670: }
6671: $output .= '</fieldset>'.
1.391 raeburn 6672: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6673: '<table>'.
6674: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6675: '</table>'.
6676: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6677: '<td class="LC_left_item">';
6678: foreach my $auth ('lti',@authtypes) {
6679: my $authtext;
6680: if ($auth eq 'lti') {
6681: $authtext = &mt('None');
6682: } else {
6683: $authtext = $authnames{$shortauth{$auth}};
6684: }
6685: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6686: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6687: $authtext.'</label></span> ';
6688: }
6689: $output .= '</td></tr>'.
6690: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6691: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6692: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6693: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6694: '</table></fieldset>'.
1.391 raeburn 6695: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6696: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6697: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6698: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6699: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6700: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6701: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6702: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6703: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6704: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6705: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6706: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6707: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6708: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6709: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6710: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6711: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6712: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6713: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6714: (' 'x2);
6715: }
6716: $output .= '</span></div></fieldset>'.
6717: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6718: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6719: &mt('Unique course identifier').': ';
6720: foreach my $option ('course_offering_sourcedid','context_id','other') {
6721: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6722: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6723: ($option eq 'other' ? '' : (' 'x2) );
6724: }
1.334 raeburn 6725: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6726: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6727: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6728: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6729: foreach my $type (@coursetypes) {
6730: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6731: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6732: (' 'x2);
6733: }
1.392 raeburn 6734: $output .= '</span><br /><br />'.
6735: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6736: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6737: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6738: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6739: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6740: '</fieldset>'.
1.391 raeburn 6741: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6742: foreach my $ltirole (@lticourseroles) {
6743: my ($selected,$selectnone);
6744: if ($rolemaps{$ltirole} eq '') {
6745: $selectnone = ' selected="selected"';
6746: }
6747: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6748: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6749: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6750: foreach my $role (@courseroles) {
6751: unless ($selectnone) {
6752: if ($rolemaps{$ltirole} eq $role) {
6753: $selected = ' selected="selected"';
6754: } else {
6755: $selected = '';
6756: }
6757: }
6758: $output .= '<option value="'.$role.'"'.$selected.'>'.
6759: &Apache::lonnet::plaintext($role,'Course').
6760: '</option>';
6761: }
6762: $output .= '</select></td>';
6763: }
6764: $output .= '</tr></table></fieldset>'.
6765: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6766: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6767: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6768: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6769: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6770: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6771: '</fieldset>'.
1.391 raeburn 6772: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6773: foreach my $lticrsrole (@lticourseroles) {
6774: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6775: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6776: }
6777: $output .= '</fieldset>'.
1.391 raeburn 6778: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6779: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6780: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6781: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6782: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6783: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6784: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6785: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6786: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6787: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6788: &mt('Standard field').'</label>'.(' 'x2).
6789: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6790: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6791: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6792: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6793: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6794: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6795: foreach my $extra ('roster','passback') {
1.320 raeburn 6796: my $checkedon = '';
6797: my $checkedoff = ' checked="checked"';
1.337 raeburn 6798: if ($extra eq 'passback') {
6799: $pb1p1chk = ' checked="checked"';
6800: $pb1p0chk = '';
1.425 raeburn 6801: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6802: } else {
1.425 raeburn 6803: $onclickpb = '';
1.337 raeburn 6804: }
1.320 raeburn 6805: if (ref($current) eq 'HASH') {
6806: if (($current->{$extra})) {
6807: $checkedon = $checkedoff;
6808: $checkedoff = '';
1.337 raeburn 6809: if ($extra eq 'passback') {
6810: $passbacksty = 'inline-block';
6811: }
6812: if ($current->{'passbackformat'} eq '1.0') {
6813: $pb1p0chk = ' checked="checked"';
6814: $pb1p1chk = '';
6815: }
1.320 raeburn 6816: }
6817: }
6818: $output .= $lt{$extra}.' '.
1.337 raeburn 6819: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6820: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6821: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6822: &mt('Yes').'</label><br />';
6823: }
1.337 raeburn 6824: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6825: '<span class="LC_nobreak">'.&mt('Grade format').
6826: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6827: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6828: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6829: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6830: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6831: $output .= '</span></div></fieldset>';
1.320 raeburn 6832: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6833: #
6834: # $output .= '</fieldset>'.
6835: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6836: return $output;
6837: }
6838:
1.326 raeburn 6839: sub ltimenu_titles {
6840: return &Apache::lonlocal::texthash(
6841: fullname => 'Full name',
6842: coursetitle => 'Course title',
6843: role => 'Role',
6844: logout => 'Logout',
6845: grades => 'Grades',
6846: );
6847: }
6848:
1.434 raeburn 6849: sub linkprot_suggestions {
6850: my ($suggested,$itemcount) = @_;
6851: my $count = 0;
6852: my $next = 1;
6853: my %lt = &Apache::lonlocal::texthash(
6854: 'name' => 'Suggested Launcher',
6855: 'info' => 'Recommendations',
6856: );
6857: my ($datatable,$css_class,$dest);
6858: if (ref($suggested) eq 'HASH') {
6859: my @current = sort { $a <=> $b } keys(%{$suggested});
6860: $next += $current[-1];
6861: for (my $i=0; $i<@current; $i++) {
6862: my $num = $current[$i];
6863: my %values;
6864: if (ref($suggested->{$num}) eq 'HASH') {
6865: %values = %{$suggested->{$num}};
6866: } else {
6867: next;
6868: }
6869: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6870: $datatable .=
6871: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6872: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6873: &mt('Delete?').'</label></span></td><td>'."\n".
6874: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6875: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6876: '</fieldset></div>'.
6877: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6878: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6879: '</fieldset></div>'.
6880: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6881: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6882: $$itemcount ++;
6883: }
6884: }
6885: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6886: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6887: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6888: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6889: '<td>'."\n".
6890: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6891: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6892: '</fieldset></div>'.
6893: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6894: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6895: '</fieldset></div>'.
6896: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6897: '</td></tr>'."\n";
6898: return $datatable;
6899: }
6900:
1.121 raeburn 6901: sub print_coursedefaults {
1.139 raeburn 6902: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6903: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6904: my $itemcount = 1;
1.192 raeburn 6905: my %choices = &Apache::lonlocal::texthash (
6906: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6907: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6908: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6909: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6910: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6911: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6912: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6913: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6914: texengine => 'Default method to display mathematics',
1.257 raeburn 6915: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6916: canclone => "People who may clone a course (besides course's owner and coordinators)",
6917: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6918: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6919: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6920: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6921: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6922: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6923: );
1.198 raeburn 6924: my %staticdefaults = (
6925: anonsurvey_threshold => 10,
6926: uploadquota => 500,
1.428 raeburn 6927: coursequota => 20,
1.257 raeburn 6928: postsubmit => 60,
1.276 raeburn 6929: mysqltables => 172800,
1.422 raeburn 6930: domexttool => 1,
6931: exttool => 0,
1.432 raeburn 6932: crsauthor => 1,
1.438 raeburn 6933: crseditors => ['edit','xml'],
1.198 raeburn 6934: );
1.139 raeburn 6935: if ($position eq 'top') {
1.257 raeburn 6936: %defaultchecked = (
6937: 'canuse_pdfforms' => 'off',
6938: 'uselcmath' => 'on',
6939: 'usejsme' => 'on',
1.398 raeburn 6940: 'inline_chem' => 'on',
1.289 raeburn 6941: 'canclone' => 'none',
1.257 raeburn 6942: );
1.398 raeburn 6943: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6944: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6945: if (ref($settings) eq 'HASH') {
6946: if ($settings->{'texengine'}) {
6947: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6948: $deftex = $settings->{'texengine'};
6949: }
6950: }
6951: }
6952: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6953: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6954: '<span class="LC_nobreak">'.$choices{'texengine'}.
6955: '</span></td><td class="LC_right_item">'.
6956: '<select name="texengine">'."\n";
6957: my %texoptions = (
6958: MathJax => 'MathJax',
6959: mimetex => &mt('Convert to Images'),
6960: tth => &mt('TeX to HTML'),
6961: );
6962: foreach my $renderer ('MathJax','mimetex','tth') {
6963: my $selected = '';
6964: if ($renderer eq $deftex) {
6965: $selected = ' selected="selected"';
6966: }
6967: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6968: }
6969: $mathdisp .= '</select></td></tr>'."\n";
6970: $itemcount ++;
1.139 raeburn 6971: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6972: \%choices,$itemcount);
1.314 raeburn 6973: $datatable = $mathdisp.$datatable;
1.264 raeburn 6974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6975: $datatable .=
1.306 raeburn 6976: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6977: '<span class="LC_nobreak">'.$choices{'canclone'}.
6978: '</span></td><td class="LC_left_item">';
6979: my $currcanclone = 'none';
6980: my $onclick;
6981: my @cloneoptions = ('none','domain');
1.380 raeburn 6982: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6983: none => 'No additional course requesters',
6984: domain => "Any course requester in course's domain",
6985: instcode => 'Course requests for official courses ...',
6986: );
6987: my (%codedefaults,@code_order,@posscodes);
6988: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6989: \@code_order) eq 'ok') {
6990: if (@code_order > 0) {
6991: push(@cloneoptions,'instcode');
6992: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6993: }
6994: }
6995: if (ref($settings) eq 'HASH') {
6996: if ($settings->{'canclone'}) {
6997: if (ref($settings->{'canclone'}) eq 'HASH') {
6998: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6999: if (@code_order > 0) {
7000: $currcanclone = 'instcode';
7001: @posscodes = @{$settings->{'canclone'}{'instcode'}};
7002: }
7003: }
7004: } elsif ($settings->{'canclone'} eq 'domain') {
7005: $currcanclone = $settings->{'canclone'};
7006: }
7007: }
1.289 raeburn 7008: }
1.264 raeburn 7009: foreach my $option (@cloneoptions) {
7010: my ($checked,$additional);
7011: if ($currcanclone eq $option) {
7012: $checked = ' checked="checked"';
7013: }
7014: if ($option eq 'instcode') {
7015: if (@code_order) {
7016: my $show = 'none';
7017: if ($checked) {
7018: $show = 'block';
7019: }
1.317 raeburn 7020: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7021: &mt('Institutional codes for new and cloned course have identical:').
7022: '<br />';
7023: foreach my $item (@code_order) {
7024: my $codechk;
7025: if ($checked) {
7026: if (grep(/^\Q$item\E$/,@posscodes)) {
7027: $codechk = ' checked="checked"';
7028: }
7029: }
7030: $additional .= '<label>'.
7031: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7032: $item.'</label>';
7033: }
7034: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7035: }
7036: }
7037: $datatable .=
7038: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7039: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7040: '</label> '.$additional.'</span><br />';
7041: }
7042: $datatable .= '</td>'.
7043: '</tr>';
7044: $itemcount ++;
1.139 raeburn 7045: } else {
7046: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7047: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7048: %deftimeout,%currmysql);
1.192 raeburn 7049: my $currusecredits = 0;
1.257 raeburn 7050: my $postsubmitclient = 1;
1.405 raeburn 7051: my $ltiauth = 0;
1.422 raeburn 7052: my %domexttool;
7053: my %exttool;
1.432 raeburn 7054: my %crsauthor;
1.438 raeburn 7055: my %crseditors;
1.271 raeburn 7056: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7057: if (ref($settings) eq 'HASH') {
1.404 raeburn 7058: if ($settings->{'ltiauth'}) {
7059: $ltiauth = 1;
1.405 raeburn 7060: }
1.422 raeburn 7061: if (ref($settings->{'domexttool'}) eq 'HASH') {
7062: foreach my $type (@types) {
7063: if ($settings->{'domexttool'}->{$type}) {
7064: $domexttool{$type} = ' checked="checked"';
7065: }
7066: }
7067: } else {
7068: foreach my $type (@types) {
7069: if ($staticdefaults{'domexttool'}) {
7070: $domexttool{$type} = ' checked="checked"';
7071: }
7072: }
7073: }
7074: if (ref($settings->{'exttool'}) eq 'HASH') {
7075: foreach my $type (@types) {
7076: if ($settings->{'exttool'}->{$type}) {
7077: $exttool{$type} = ' checked="checked"';
7078: }
7079: }
7080: }
1.432 raeburn 7081: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7082: foreach my $type (@types) {
7083: if ($settings->{'crsauthor'}->{$type}) {
7084: $crsauthor{$type} = ' checked="checked"';
7085: }
7086: }
7087: } else {
7088: foreach my $type (@types) {
7089: if ($staticdefaults{'crsauthor'}) {
7090: $crsauthor{$type} = ' checked="checked"';
7091: }
7092: }
7093: }
1.438 raeburn 7094: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7095: foreach my $editor (@{$settings->{'crseditors'}}) {
7096: $crseditors{$editor} = ' checked="checked"';
7097: }
7098: } else {
7099: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7100: $crseditors{$editor} = ' checked="checked"';
7101: }
7102: }
1.139 raeburn 7103: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7104: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7105: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7106: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7107: }
7108: }
1.428 raeburn 7109: if (ref($settings->{'coursequota'}) eq 'HASH') {
7110: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7111: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7112: }
7113: }
1.192 raeburn 7114: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7115: foreach my $type (@types) {
7116: next if ($type eq 'community');
7117: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7118: if ($defcredits{$type} ne '') {
7119: $currusecredits = 1;
7120: }
7121: }
7122: }
7123: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7124: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7125: $postsubmitclient = 0;
7126: foreach my $type (@types) {
7127: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7128: }
7129: } else {
7130: foreach my $type (@types) {
7131: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7132: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7133: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7134: } else {
7135: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7136: }
7137: } else {
7138: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7139: }
7140: }
7141: }
7142: } else {
7143: foreach my $type (@types) {
7144: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7145: }
7146: }
1.276 raeburn 7147: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7148: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7149: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7150: }
7151: } else {
7152: foreach my $type (@types) {
7153: $currmysql{$type} = $staticdefaults{'mysqltables'};
7154: }
7155: }
1.258 raeburn 7156: } else {
7157: foreach my $type (@types) {
7158: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7159: if ($staticdefaults{'domexttool'}) {
7160: $domexttool{$type} = ' checked="checked"';
7161: }
1.432 raeburn 7162: if ($staticdefaults{'crsauthor'}) {
7163: $crsauthor{$type} = ' checked="checked"';
7164: }
1.258 raeburn 7165: }
1.438 raeburn 7166: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7167: $crseditors{$editor} = ' checked="checked"';
7168: }
1.139 raeburn 7169: }
7170: if (!$currdefresponder) {
1.198 raeburn 7171: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7172: } elsif ($currdefresponder < 1) {
7173: $currdefresponder = 1;
7174: }
1.198 raeburn 7175: foreach my $type (@types) {
7176: if ($curruploadquota{$type} eq '') {
7177: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7178: }
1.428 raeburn 7179: if ($currcoursequota{$type} eq '') {
7180: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7181: }
1.198 raeburn 7182: }
1.139 raeburn 7183: $datatable .=
1.192 raeburn 7184: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7185: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7186: '</span></td>'.
7187: '<td class="LC_right_item"><span class="LC_nobreak">'.
7188: '<input type="text" name="anonsurvey_threshold"'.
7189: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7190: '</td></tr>'."\n";
7191: $itemcount ++;
7192: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7193: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7194: $choices{'uploadquota'}.
7195: '</span></td>'.
1.306 raeburn 7196: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7197: '<table><tr>';
1.198 raeburn 7198: foreach my $type (@types) {
1.306 raeburn 7199: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7200: '<input type="text" name="uploadquota_'.$type.'"'.
7201: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7202: }
7203: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7204: $itemcount ++;
1.428 raeburn 7205: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7206: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7207: $choices{'coursequota'}.
7208: '</span></td>'.
7209: '<td style="text-align: right" class="LC_right_item">'.
7210: '<table><tr>';
7211: foreach my $type (@types) {
7212: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7213: '<input type="text" name="coursequota_'.$type.'"'.
7214: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7215: }
7216: $datatable .= '</tr></table></td></tr>'."\n";
7217: $itemcount ++;
1.236 raeburn 7218: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7219: my $display = 'none';
1.192 raeburn 7220: if ($currusecredits) {
7221: $display = 'block';
7222: }
7223: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7224: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7225: foreach my $type (@types) {
7226: next if ($type eq 'community');
1.306 raeburn 7227: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7228: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7229: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7230: }
7231: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7232: %defaultchecked = ('coursecredits' => 'off');
7233: @toggles = ('coursecredits');
7234: my $current = {
7235: 'coursecredits' => $currusecredits,
7236: };
7237: (my $table,$itemcount) =
7238: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7239: \%choices,$itemcount,$onclick,$additional,'left');
7240: $datatable .= $table;
7241: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7242: my $display = 'none';
7243: if ($postsubmitclient) {
7244: $display = 'block';
7245: }
7246: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7247: &mt('Number of seconds submit is disabled').'<br />'.
7248: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7249: '<table><tr>';
1.257 raeburn 7250: foreach my $type (@types) {
1.306 raeburn 7251: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7252: '<input type="text" name="'.$type.'_timeout" value="'.
7253: $deftimeout{$type}.'" size="5" /></td>';
7254: }
7255: $additional .= '</tr></table></div>'."\n";
7256: %defaultchecked = ('postsubmit' => 'on');
7257: @toggles = ('postsubmit');
1.280 raeburn 7258: $current = {
7259: 'postsubmit' => $postsubmitclient,
7260: };
1.257 raeburn 7261: ($table,$itemcount) =
7262: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7263: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7264: $datatable .= $table;
1.276 raeburn 7265: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7266: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7267: $choices{'mysqltables'}.
7268: '</span></td>'.
1.306 raeburn 7269: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7270: '<table><tr>';
7271: foreach my $type (@types) {
1.306 raeburn 7272: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7273: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7274: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7275: }
7276: $datatable .= '</tr></table></td></tr>'."\n";
7277: $itemcount ++;
1.404 raeburn 7278: %defaultchecked = ('ltiauth' => 'off');
7279: @toggles = ('ltiauth');
7280: $current = {
7281: 'ltiauth' => $ltiauth,
7282: };
7283: ($table,$itemcount) =
7284: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7285: \%choices,$itemcount,undef,undef,'left');
7286: $datatable .= $table;
1.422 raeburn 7287: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7288: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7289: $choices{'domexttool'}.
7290: '</span></td>'.
7291: '<td style="text-align: right" class="LC_right_item">'.
7292: '<table><tr>';
7293: foreach my $type (@types) {
7294: $datatable .= '<td style="text-align: left">'.
7295: '<span class="LC_nobreak">'.
1.438 raeburn 7296: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7297: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7298: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7299: }
7300: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7301: $itemcount ++;
1.422 raeburn 7302: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7303: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7304: $choices{'exttool'}.
7305: '</span></td>'.
7306: '<td style="text-align: right" class="LC_right_item">'.
7307: '<table><tr>';
7308: foreach my $type (@types) {
7309: $datatable .= '<td style="text-align: left">'.
7310: '<span class="LC_nobreak">'.
1.438 raeburn 7311: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7312: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7313: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7314: }
7315: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7316: $itemcount ++;
7317: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7318: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7319: $choices{'crsauthor'}.
7320: '</span></td>'.
7321: '<td style="text-align: right" class="LC_right_item">'.
7322: '<table><tr>';
7323: foreach my $type (@types) {
7324: $datatable .= '<td style="text-align: left">'.
7325: '<span class="LC_nobreak">'.
1.438 raeburn 7326: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7327: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7328: &mt($type).'</label></span></td>'."\n";
7329: }
7330: $datatable .= '</tr></table></td></tr>'."\n";
7331: $itemcount ++;
7332: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7333: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7334: $choices{'crseditors'}.
7335: '</span></td>'.
7336: '<td style="text-align: right" class="LC_right_item">'.
7337: '<table><tr>';
7338: my @editors = ('edit','xml','daxe');
7339: my %editornames = &crseditor_titles();
7340: foreach my $editor (@editors) {
7341: $datatable .= '<td style="text-align: left">'.
7342: '<span class="LC_nobreak">'.
7343: '<label><input type="checkbox" name="crseditors"'.
7344: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7345: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7346: }
7347: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7348: }
1.192 raeburn 7349: $$rowtotal += $itemcount;
1.121 raeburn 7350: return $datatable;
1.118 jms 7351: }
7352:
1.438 raeburn 7353: sub crseditor_titles {
7354: return &Apache::lonlocal::texthash(
7355: edit => 'Standard editor (Edit)',
7356: xml => 'Text editor (EditXML)',
7357: daxe => 'Daxe editor (Daxe)',
7358: );
7359: }
7360:
1.429 raeburn 7361: sub print_authordefaults {
7362: my ($position,$dom,$settings,$rowtotal) = @_;
7363: my ($css_class,$datatable,%checkedon,%checkedoff);
7364: my $itemcount = 1;
7365: my %titles = &authordefaults_titles();
7366: if ($position eq 'top') {
7367: my %defaultchecked = (
7368: 'nocodemirror' => 'off',
1.437 raeburn 7369: 'daxecollapse' => 'off',
1.429 raeburn 7370: 'domcoordacc' => 'on',
7371: );
1.437 raeburn 7372: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7373: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7374: \%titles,$itemcount);
7375: my %staticdefaults = (
7376: 'copyright' => 'default',
7377: 'sourceavail' => 'closed',
7378: );
7379: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7380: my %currrights;
7381: foreach my $item ('copyright','sourceavail') {
7382: $currrights{$item} = $staticdefaults{$item};
7383: if (ref($settings) eq 'HASH') {
7384: if (exists($settings->{$item})) {
7385: $currrights{$item} = $settings->{$item};
7386: }
7387: }
7388: }
7389: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7390: '<span class="LC_nobreak">'.$titles{'copyright'}.
7391: '</span></td><td class="LC_right_item">'.
7392: &selectbox('copyright',$currrights{'copyright'},'',
7393: \&Apache::loncommon::copyrightdescription,
7394: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7395: '</td></tr>'."\n";
7396: $itemcount ++;
7397: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7398: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7399: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7400: '</span></td><td class="LC_right_item">'.
7401: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7402: \&Apache::loncommon::source_copyrightdescription,
7403: (&Apache::loncommon::source_copyrightids)).
7404: '</td></tr>'."\n";
7405: } else {
7406: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7407: my $curreditors;
7408: my %staticdefaults = (
7409: editors => ['edit','xml'],
7410: authorquota => 500,
7411: webdav => 0,
7412: );
7413: my $curreditors = $staticdefaults{'editors'};
7414: if ((ref($settings) eq 'HASH') &&
7415: (ref($settings->{'editors'}) eq 'ARRAY')) {
7416: $curreditors = $settings->{'editors'};
7417: } else {
7418: $curreditors = $staticdefaults{'editors'};
7419: }
7420: my @editors = ('edit','xml','daxe');
7421: $datatable = '<tr'.$css_class.'>'."\n".
7422: '<td>'.$titles{'editors'}.'</td>'."\n".
7423: '<td class="LC_left_item">'."\n".
7424: '<span class="LC_nobreak">';
7425: foreach my $editor (@editors) {
7426: my $checked;
7427: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7428: $checked = ' checked="checked"';
7429: }
7430: $datatable .= '<label>'.
7431: '<input type="checkbox" name="author_editors" '.
7432: $checked.' value="'.$editor.'" '.
7433: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7434: $titles{$editor}.'</label> ';
7435: }
7436: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7437: $itemcount ++;
7438: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7439: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7440: my @insttypes;
7441: if (ref($types) eq 'ARRAY') {
7442: @insttypes = @{$types};
7443: }
7444: my $typecount = 0;
7445: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7446: my @items = ('webdav','authorquota');
7447: my %quotas;
7448: if (ref($domconf{'quotas'}) eq 'HASH') {
7449: %quotas = %{$domconf{'quotas'}};
7450: foreach my $item (@items) {
7451: if (ref($quotas{$item}) eq 'HASH') {
7452: foreach my $type (@insttypes,'default') {
7453: if ($item eq 'authorquota') {
7454: if ($quotas{$item}{$type} !~ /^\d+$/) {
7455: $quotas{$item}{$type} = $staticdefaults{$item};
7456: }
7457: } elsif ($item eq 'webdav') {
7458: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7459: $quotas{$item}{$type} = $staticdefaults{$item};
7460: }
7461: }
7462: }
7463: } else {
7464: foreach my $type (@insttypes,'default') {
7465: $quotas{$item}{$type} = $staticdefaults{$item};
7466: }
7467: }
7468: }
7469: } else {
7470: foreach my $item (@items) {
7471: foreach my $type (@insttypes,'default') {
7472: $quotas{$item}{$type} = $staticdefaults{$item};
7473: }
7474: }
7475: }
7476: if (ref($usertypes) eq 'HASH') {
7477: my $numinrow = 4;
7478: my $onclick = '';
7479: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7480: $numinrow,$othertitle,'authorquota',
7481: \$itemcount,$onclick);
7482: $itemcount ++;
7483: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7484: $numinrow,$othertitle,'webdav',
7485: \$itemcount);
7486: $itemcount ++;
7487: }
7488: my $checkedno = ' checked="checked"';
7489: my ($checkedon,$checkedoff);
7490: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7491: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7492: if ($quotas{'webdav'}{'_LC_adv'}) {
7493: $checkedon = $checkedno;
7494: } else {
7495: $checkedoff = $checkedno;
7496: }
7497: undef($checkedno);
7498: }
7499: }
7500: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7501: $datatable .= '<tr'.$css_class.'>'.
7502: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7503: $titles{'webdav_LC_adv_over'}.
7504: '</td>'.
7505: '<td class="LC_left_item">';
7506: foreach my $option ('none','off','on') {
7507: my ($text,$val,$checked);
7508: if ($option eq 'none') {
7509: $text = $titles{'none'};
7510: $val = '';
7511: $checked = $checkedno;
7512: } elsif ($option eq 'off') {
7513: $text = $titles{'overoff'};
7514: $val = 0;
7515: $checked = $checkedoff;
7516: } elsif ($option eq 'on') {
7517: $text = $titles{'overon'};
7518: $val = 1;
7519: $checked = $checkedon;
1.436 raeburn 7520: }
1.429 raeburn 7521: $datatable .= '<span class="LC_nobreak"><label>'.
7522: '<input type="radio" name="webdav_LC_adv"'.
7523: ' value="'.$val.'"'.$checked.' />'.
7524: $text.'</label></span> ';
7525: }
7526: $datatable .= '</td></tr>';
7527: $itemcount ++;
1.440 raeburn 7528: my %defchecked = (
7529: 'archive' => 'off',
7530: );
7531: my @toggles = ('archive');
7532: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7533: {'archive' => 'off'},
7534: \%titles,$itemcount);
7535: $datatable .= $archive."\n";
7536: $itemcount ++;
1.429 raeburn 7537: }
7538: $$rowtotal += $itemcount;
7539: return $datatable;
7540: }
7541:
7542: sub authordefaults_titles {
7543: return &Apache::lonlocal::texthash(
7544: copyright => 'Copyright/Distribution',
7545: sourceavail => ' Source Available',
7546: editors => 'Available Editors',
7547: webdav => 'WebDAV',
7548: authorquota => 'Authoring Space quotas (MB)',
7549: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7550: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7551: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7552: edit => 'Standard editor (Edit)',
7553: xml => 'Text editor (EditXML)',
7554: daxe => 'Daxe editor (Daxe)',
7555: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7556: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7557: none => 'No override set',
7558: overon => 'Override -- webDAV on',
1.436 raeburn 7559: overoff => 'Override -- webDAV off',
1.440 raeburn 7560: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7561: );
7562: }
7563:
7564: sub selectbox {
7565: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7566: my $selout = '<select name="'.$name.'">';
7567: foreach my $id (@idlist) {
7568: $selout.='<option value="'.$id.'"';
7569: if ($id eq $value) {
7570: $selout.=' selected="selected"';
7571: }
7572: if ($readonly) {
7573: $selout .= ' disabled="disabled"';
7574: }
7575: $selout.='>'.&{$functionref}($id).'</option>';
7576: }
7577: $selout.='</select>';
7578: return $selout;
7579: }
7580:
1.231 raeburn 7581: sub print_selfenrollment {
7582: my ($position,$dom,$settings,$rowtotal) = @_;
7583: my ($css_class,$datatable);
7584: my $itemcount = 1;
1.271 raeburn 7585: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7586: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7587: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7588: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7589: my @rows;
7590: my $key;
7591: if ($position eq 'top') {
7592: $key = 'admin';
7593: if (ref($rowsref) eq 'ARRAY') {
7594: @rows = @{$rowsref};
7595: }
7596: } elsif ($position eq 'middle') {
7597: $key = 'default';
7598: @rows = ('types','registered','approval','limit');
7599: }
7600: foreach my $row (@rows) {
7601: if (defined($titlesref->{$row})) {
7602: $itemcount ++;
7603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7604: $datatable .= '<tr'.$css_class.'>'.
7605: '<td>'.$titlesref->{$row}.'</td>'.
7606: '<td class="LC_left_item">'.
7607: '<table><tr>';
7608: my (%current,%currentcap);
7609: if (ref($settings) eq 'HASH') {
7610: if (ref($settings->{$key}) eq 'HASH') {
7611: foreach my $type (@types) {
7612: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7613: $current{$type} = $settings->{$key}->{$type}->{$row};
7614: }
7615: if (($row eq 'limit') && ($key eq 'default')) {
7616: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7617: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7618: }
7619: }
7620: }
7621: }
7622: }
7623: my %roles = (
7624: '0' => &Apache::lonnet::plaintext('dc'),
7625: );
7626:
7627: foreach my $type (@types) {
7628: unless (($row eq 'registered') && ($key eq 'default')) {
7629: $datatable .= '<th>'.&mt($type).'</th>';
7630: }
7631: }
7632: unless (($row eq 'registered') && ($key eq 'default')) {
7633: $datatable .= '</tr><tr>';
7634: }
7635: foreach my $type (@types) {
7636: if ($type eq 'community') {
7637: $roles{'1'} = &mt('Community personnel');
7638: } else {
7639: $roles{'1'} = &mt('Course personnel');
7640: }
7641: $datatable .= '<td style="vertical-align: top">';
7642: if ($position eq 'top') {
7643: my %checked;
7644: if ($current{$type} eq '0') {
7645: $checked{'0'} = ' checked="checked"';
7646: } else {
7647: $checked{'1'} = ' checked="checked"';
7648: }
7649: foreach my $role ('1','0') {
7650: $datatable .= '<span class="LC_nobreak"><label>'.
7651: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7652: 'value="'.$role.'"'.$checked{$role}.' />'.
7653: $roles{$role}.'</label></span> ';
7654: }
7655: } else {
7656: if ($row eq 'types') {
7657: my %checked;
7658: if ($current{$type} =~ /^(all|dom)$/) {
7659: $checked{$1} = ' checked="checked"';
7660: } else {
7661: $checked{''} = ' checked="checked"';
7662: }
7663: foreach my $val ('','dom','all') {
7664: $datatable .= '<span class="LC_nobreak"><label>'.
7665: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7666: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7667: }
7668: } elsif ($row eq 'registered') {
7669: my %checked;
7670: if ($current{$type} eq '1') {
7671: $checked{'1'} = ' checked="checked"';
7672: } else {
7673: $checked{'0'} = ' checked="checked"';
7674: }
7675: foreach my $val ('0','1') {
7676: $datatable .= '<span class="LC_nobreak"><label>'.
7677: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7678: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7679: }
7680: } elsif ($row eq 'approval') {
7681: my %checked;
7682: if ($current{$type} =~ /^([12])$/) {
7683: $checked{$1} = ' checked="checked"';
7684: } else {
7685: $checked{'0'} = ' checked="checked"';
7686: }
7687: for my $val (0..2) {
7688: $datatable .= '<span class="LC_nobreak"><label>'.
7689: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7690: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7691: }
7692: } elsif ($row eq 'limit') {
7693: my %checked;
7694: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7695: $checked{$1} = ' checked="checked"';
7696: } else {
7697: $checked{'none'} = ' checked="checked"';
7698: }
7699: my $cap;
7700: if ($currentcap{$type} =~ /^\d+$/) {
7701: $cap = $currentcap{$type};
7702: }
7703: foreach my $val ('none','allstudents','selfenrolled') {
7704: $datatable .= '<span class="LC_nobreak"><label>'.
7705: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7706: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7707: }
7708: $datatable .= '<br />'.
7709: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7710: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7711: '</span>';
7712: }
7713: }
7714: $datatable .= '</td>';
7715: }
7716: $datatable .= '</tr>';
7717: }
7718: $datatable .= '</table></td></tr>';
7719: }
7720: } elsif ($position eq 'bottom') {
1.235 raeburn 7721: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7722: }
7723: $$rowtotal += $itemcount;
7724: return $datatable;
7725: }
7726:
7727: sub print_validation_rows {
7728: my ($caller,$dom,$settings,$rowtotal) = @_;
7729: my ($itemsref,$namesref,$fieldsref);
7730: if ($caller eq 'selfenroll') {
7731: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7732: } elsif ($caller eq 'requestcourses') {
7733: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7734: }
7735: my %currvalidation;
7736: if (ref($settings) eq 'HASH') {
7737: if (ref($settings->{'validation'}) eq 'HASH') {
7738: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7739: }
1.235 raeburn 7740: }
7741: my $datatable;
7742: my $itemcount = 0;
7743: foreach my $item (@{$itemsref}) {
7744: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7745: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7746: $namesref->{$item}.
7747: '</span></td>'.
7748: '<td class="LC_left_item">';
7749: if (($item eq 'url') || ($item eq 'button')) {
7750: $datatable .= '<span class="LC_nobreak">'.
7751: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7752: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7753: } elsif ($item eq 'fields') {
7754: my @currfields;
7755: if (ref($currvalidation{$item}) eq 'ARRAY') {
7756: @currfields = @{$currvalidation{$item}};
7757: }
7758: foreach my $field (@{$fieldsref}) {
7759: my $check = '';
7760: if (grep(/^\Q$field\E$/,@currfields)) {
7761: $check = ' checked="checked"';
7762: }
7763: $datatable .= '<span class="LC_nobreak"><label>'.
7764: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7765: ' value="'.$field.'"'.$check.' />'.$field.
7766: '</label></span> ';
7767: }
7768: } elsif ($item eq 'markup') {
1.334 raeburn 7769: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7770: $currvalidation{$item}.
1.231 raeburn 7771: '</textarea>';
1.235 raeburn 7772: }
7773: $datatable .= '</td></tr>'."\n";
7774: if (ref($rowtotal)) {
1.231 raeburn 7775: $itemcount ++;
7776: }
7777: }
1.235 raeburn 7778: if ($caller eq 'requestcourses') {
7779: my %currhash;
1.248 raeburn 7780: if (ref($settings) eq 'HASH') {
7781: if (ref($settings->{'validation'}) eq 'HASH') {
7782: if ($settings->{'validation'}{'dc'} ne '') {
7783: $currhash{$settings->{'validation'}{'dc'}} = 1;
7784: }
1.235 raeburn 7785: }
7786: }
7787: my $numinrow = 2;
7788: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7789: 'validationdc',%currhash);
1.247 raeburn 7790: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7791: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7792: if ($numdc > 1) {
1.247 raeburn 7793: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7794: } else {
1.247 raeburn 7795: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7796: }
1.247 raeburn 7797: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7798: $itemcount ++;
7799: }
7800: if (ref($rowtotal)) {
7801: $$rowtotal += $itemcount;
7802: }
1.231 raeburn 7803: return $datatable;
7804: }
7805:
1.357 raeburn 7806: sub print_privacy {
7807: my ($position,$dom,$settings,$rowtotal) = @_;
7808: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7809: my $itemcount = 0;
1.417 raeburn 7810: if ($position eq 'top') {
7811: $numinrow = 2;
7812: } else {
1.357 raeburn 7813: @items = ('domain','author','course','community');
7814: %names = &Apache::lonlocal::texthash (
7815: domain => 'Assigned domain role(s)',
7816: author => 'Assigned co-author role(s)',
7817: course => 'Assigned course role(s)',
1.416 raeburn 7818: community => 'Assigned community role(s)',
1.357 raeburn 7819: );
7820: $numinrow = 4;
7821: ($othertitle,$usertypes,$types) =
7822: &Apache::loncommon::sorted_inst_types($dom);
7823: }
7824: if (($position eq 'top') || ($position eq 'middle')) {
7825: my (%by_ip,%by_location,@intdoms,@instdoms);
7826: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7827: if ($position eq 'top') {
7828: my %curr;
7829: my @options = ('none','user','domain','auto');
7830: my %titles = &Apache::lonlocal::texthash (
7831: none => 'Not allowed',
7832: user => 'User authorizes',
7833: domain => 'DC authorizes',
7834: auto => 'Unrestricted',
7835: instdom => 'Other domain shares institution/provider',
7836: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7837: notify => 'Notify when role needs authorization',
1.357 raeburn 7838: );
7839: my %names = &Apache::lonlocal::texthash (
7840: domain => 'Domain role',
7841: author => 'Co-author role',
7842: course => 'Course role',
7843: community => 'Community role',
7844: );
7845: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7846: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7847: foreach my $domtype ('instdom','extdom') {
7848: my (%checked,$skip);
7849: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7850: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7851: '<td class="LC_left_item">';
7852: if ($domtype eq 'instdom') {
7853: unless (@instdoms > 1) {
7854: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7855: $skip = 1;
7856: }
7857: } elsif ($domtype eq 'extdom') {
7858: if (keys(%by_location) == 0) {
7859: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7860: $skip = 1;
7861: }
7862: }
7863: unless ($skip) {
7864: foreach my $roletype ('domain','author','course','community') {
7865: $checked{'auto'} = ' checked="checked"';
7866: if (ref($settings) eq 'HASH') {
7867: if (ref($settings->{approval}) eq 'HASH') {
7868: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7869: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7870: $checked{$1} = ' checked="checked"';
7871: $checked{'auto'} = '';
7872: }
7873: }
7874: }
7875: }
7876: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7877: foreach my $option (@options) {
7878: $datatable .= '<span class="LC_nobreak"><label>'.
7879: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7880: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7881: '</label></span> ';
7882: }
7883: $datatable .= '</fieldset>';
7884: }
7885: }
7886: $datatable .= '</td></tr>';
7887: $itemcount ++;
7888: }
1.417 raeburn 7889: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7890: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7891: '<td class="LC_left_item">';
7892: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7893: my %curr;
7894: if (ref($settings) eq 'HASH') {
7895: if ($settings->{'notify'} ne '') {
7896: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7897: }
7898: }
7899: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7900: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7901: 'privacy_notify',%curr);
7902: if ($numdc > 0) {
7903: $datatable .= $table;
7904: } else {
7905: $datatable .= &mt('There are no active Domain Coordinators');
7906: }
7907: } else {
7908: $datatable .= &mt('Nothing to set here, as there are no other domains');
7909: }
7910: $datatable .='</td></tr>';
1.357 raeburn 7911: } elsif ($position eq 'middle') {
7912: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7913: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7914: foreach my $item (@{$types}) {
7915: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7916: $numinrow,$itemcount,'','','','','',
7917: '',$usertypes->{$item});
7918: $itemcount ++;
7919: }
7920: }
7921: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7922: $numinrow,$itemcount,'','','','','',
7923: '',$othertitle);
7924: $itemcount ++;
7925: } else {
1.360 raeburn 7926: my (@insttypes,%insttitles);
7927: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7928: @insttypes = @{$types};
7929: %insttitles = %{$usertypes};
7930: }
7931: foreach my $item (@insttypes,'default') {
7932: my $title;
7933: if ($item eq 'default') {
7934: $title = $othertitle;
7935: } else {
7936: $title = $insttitles{$item};
7937: }
7938: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7939: $datatable .= '<tr'.$css_class.'>'.
7940: '<td class="LC_left_item">'.$title.'</td>'.
7941: '<td class="LC_left_item">'.
7942: &mt('Nothing to set here, as there are no other domains').
7943: '</td></tr>';
7944: $itemcount ++;
7945: }
1.357 raeburn 7946: }
7947: }
7948: } else {
7949: my $prefix;
7950: if ($position eq 'lower') {
7951: $prefix = 'priv';
7952: } else {
7953: $prefix = 'unpriv';
7954: }
7955: foreach my $item (@items) {
7956: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7957: $numinrow,$itemcount,'','','','','',
7958: '',$names{$item});
7959: $itemcount ++;
7960: }
7961: }
7962: if (ref($rowtotal)) {
7963: $$rowtotal += $itemcount;
7964: }
7965: return $datatable;
7966: }
7967:
1.354 raeburn 7968: sub print_passwords {
7969: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7970: my ($datatable,$css_class);
7971: my $itemcount = 0;
7972: my %titles = &Apache::lonlocal::texthash (
7973: captcha => '"Forgot Password" CAPTCHA validation',
7974: link => 'Reset link expiration (hours)',
7975: case => 'Case-sensitive usernames/e-mail',
7976: prelink => 'Information required (form 1)',
7977: postlink => 'Information required (form 2)',
7978: emailsrc => 'LON-CAPA e-mail address type(s)',
7979: customtext => 'Domain specific text (HTML)',
7980: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7981: intauth_check => 'Check bcrypt cost if authenticated',
7982: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7983: permanent => 'Permanent e-mail address',
7984: critical => 'Critical notification address',
7985: notify => 'Notification address',
7986: min => 'Minimum password length',
7987: max => 'Maximum password length',
7988: chars => 'Required characters',
7989: expire => 'Password expiration (days)',
1.356 raeburn 7990: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7991: );
7992: if ($position eq 'top') {
7993: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7994: my $shownlinklife = 2;
7995: my $prelink = 'both';
7996: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7997: if (ref($settings) eq 'HASH') {
7998: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7999: $shownlinklife = $settings->{resetlink};
8000: }
8001: if (ref($settings->{resetcase}) eq 'ARRAY') {
8002: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
8003: }
8004: if ($settings->{resetprelink} =~ /^(both|either)$/) {
8005: $prelink = $settings->{resetprelink};
8006: }
8007: if (ref($settings->{resetpostlink}) eq 'HASH') {
8008: %postlink = %{$settings->{resetpostlink}};
8009: }
8010: if (ref($settings->{resetemail}) eq 'ARRAY') {
8011: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8012: }
8013: if ($settings->{resetremove}) {
8014: $nostdtext = 1;
8015: }
8016: if ($settings->{resetcustom}) {
8017: $customurl = $settings->{resetcustom};
8018: }
8019: } else {
8020: if (ref($types) eq 'ARRAY') {
8021: foreach my $item (@{$types}) {
8022: $casesens{$item} = 1;
8023: $postlink{$item} = ['username','email'];
8024: }
8025: }
8026: $casesens{'default'} = 1;
8027: $postlink{'default'} = ['username','email'];
8028: $prelink = 'both';
8029: %emailsrc = (
8030: permanent => 1,
8031: critical => 1,
8032: notify => 1,
8033: );
8034: }
8035: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8036: $itemcount ++;
8037: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8038: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8039: '<td class="LC_left_item">'.
8040: '<input type="textbox" value="'.$shownlinklife.'" '.
8041: 'name="passwords_link" size="3" /></td></tr>';
8042: $itemcount ++;
8043: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8044: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8045: '<td class="LC_left_item">';
8046: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8047: foreach my $item (@{$types}) {
8048: my $checkedcase;
8049: if ($casesens{$item}) {
8050: $checkedcase = ' checked="checked"';
8051: }
8052: $datatable .= '<span class="LC_nobreak"><label>'.
8053: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8054: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8055: '</span> ';
1.354 raeburn 8056: }
8057: }
8058: my $checkedcase;
8059: if ($casesens{'default'}) {
8060: $checkedcase = ' checked="checked"';
8061: }
8062: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8063: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8064: $othertitle.'</label></span></td>';
8065: $itemcount ++;
8066: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8067: my %checkedpre = (
8068: both => ' checked="checked"',
8069: either => '',
8070: );
8071: if ($prelink eq 'either') {
8072: $checkedpre{either} = ' checked="checked"';
8073: $checkedpre{both} = '';
8074: }
8075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8076: '<td class="LC_left_item"><span class="LC_nobreak">'.
8077: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8078: &mt('Both username and e-mail address').'</label></span> '.
8079: '<span class="LC_nobreak"><label>'.
8080: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8081: &mt('Either username or e-mail address').'</label></span></td></tr>';
8082: $itemcount ++;
8083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8084: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8085: '<td class="LC_left_item">';
8086: my %postlinked;
8087: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8088: foreach my $item (@{$types}) {
8089: undef(%postlinked);
8090: $datatable .= '<fieldset style="display: inline-block;">'.
8091: '<legend>'.$usertypes->{$item}.'</legend>';
8092: if (ref($postlink{$item}) eq 'ARRAY') {
8093: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8094: }
8095: foreach my $field ('email','username') {
8096: my $checked;
8097: if ($postlinked{$field}) {
8098: $checked = ' checked="checked"';
8099: }
8100: $datatable .= '<span class="LC_nobreak"><label>'.
8101: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8102: $field.'"'.$checked.' />'.$field.'</label>'.
8103: '<span> ';
8104: }
8105: $datatable .= '</fieldset>';
8106: }
8107: }
8108: if (ref($postlink{'default'}) eq 'ARRAY') {
8109: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8110: }
8111: $datatable .= '<fieldset style="display: inline-block;">'.
8112: '<legend>'.$othertitle.'</legend>';
8113: foreach my $field ('email','username') {
8114: my $checked;
8115: if ($postlinked{$field}) {
8116: $checked = ' checked="checked"';
8117: }
8118: $datatable .= '<span class="LC_nobreak"><label>'.
8119: '<input type="checkbox" name="passwords_postlink_default" value="'.
8120: $field.'"'.$checked.' />'.$field.'</label>'.
8121: '<span> ';
8122: }
8123: $datatable .= '</fieldset></td></tr>';
8124: $itemcount ++;
8125: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8126: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8127: '<td class="LC_left_item">';
8128: foreach my $type ('permanent','critical','notify') {
8129: my $checkedemail;
8130: if ($emailsrc{$type}) {
8131: $checkedemail = ' checked="checked"';
8132: }
8133: $datatable .= '<span class="LC_nobreak"><label>'.
8134: '<input type="checkbox" name="passwords_emailsrc" value="'.
8135: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8136: '<span> ';
8137: }
8138: $datatable .= '</td></tr>';
8139: $itemcount ++;
8140: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8141: my $switchserver = &check_switchserver($dom,$confname);
8142: my ($showstd,$noshowstd);
8143: if ($nostdtext) {
8144: $noshowstd = ' checked="checked"';
8145: } else {
8146: $showstd = ' checked="checked"';
8147: }
8148: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8149: '<td class="LC_left_item"><span class="LC_nobreak">'.
8150: &mt('Retain standard text:').
8151: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8152: &mt('Yes').'</label>'.' '.
8153: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8154: &mt('No').'</label></span><br />'.
8155: '<span class="LC_fontsize_small">'.
8156: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8157: &mt('Include custom text:');
8158: if ($customurl) {
1.369 raeburn 8159: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8160: undef,undef,undef,undef,'background-color:#ffffff');
8161: $datatable .= '<span class="LC_nobreak"> '.$link.
8162: '<label><input type="checkbox" name="passwords_custom_del"'.
8163: ' value="1" />'.&mt('Delete?').'</label></span>'.
8164: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8165: }
8166: if ($switchserver) {
8167: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8168: } else {
8169: $datatable .='<span class="LC_nobreak"> '.
8170: '<input type="file" name="passwords_customfile" /></span>';
8171: }
8172: $datatable .= '</td></tr>';
8173: } elsif ($position eq 'middle') {
8174: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8175: my @items = ('intauth_cost','intauth_check','intauth_switch');
8176: my %defaults;
8177: if (ref($domconf{'defaults'}) eq 'HASH') {
8178: %defaults = %{$domconf{'defaults'}};
8179: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8180: $defaults{'intauth_cost'} = 10;
8181: }
8182: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8183: $defaults{'intauth_check'} = 0;
8184: }
8185: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8186: $defaults{'intauth_switch'} = 0;
8187: }
8188: } else {
8189: %defaults = (
8190: 'intauth_cost' => 10,
8191: 'intauth_check' => 0,
8192: 'intauth_switch' => 0,
8193: );
8194: }
8195: foreach my $item (@items) {
8196: if ($itemcount%2) {
8197: $css_class = '';
8198: } else {
8199: $css_class = ' class="LC_odd_row" ';
8200: }
8201: $datatable .= '<tr'.$css_class.'>'.
8202: '<td><span class="LC_nobreak">'.$titles{$item}.
8203: '</span></td><td class="LC_left_item" colspan="3">';
8204: if ($item eq 'intauth_switch') {
8205: my @options = (0,1,2);
8206: my %optiondesc = &Apache::lonlocal::texthash (
8207: 0 => 'No',
8208: 1 => 'Yes',
8209: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8210: );
8211: $datatable .= '<table width="100%">';
8212: foreach my $option (@options) {
8213: my $checked = ' ';
8214: if ($defaults{$item} eq $option) {
8215: $checked = ' checked="checked"';
8216: }
8217: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8218: '<label><input type="radio" name="'.$item.
8219: '" value="'.$option.'"'.$checked.' />'.
8220: $optiondesc{$option}.'</label></span></td></tr>';
8221: }
8222: $datatable .= '</table>';
8223: } elsif ($item eq 'intauth_check') {
8224: my @options = (0,1,2);
8225: my %optiondesc = &Apache::lonlocal::texthash (
8226: 0 => 'No',
8227: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8228: 2 => 'Yes, disallow login if stored cost is less than domain default',
8229: );
8230: $datatable .= '<table width="100%">';
8231: foreach my $option (@options) {
8232: my $checked = ' ';
8233: my $onclick;
8234: if ($defaults{$item} eq $option) {
8235: $checked = ' checked="checked"';
8236: }
8237: if ($option == 2) {
8238: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8239: }
8240: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8241: '<label><input type="radio" name="'.$item.
8242: '" value="'.$option.'"'.$checked.$onclick.' />'.
8243: $optiondesc{$option}.'</label></span></td></tr>';
8244: }
8245: $datatable .= '</table>';
8246: } else {
8247: $datatable .= '<input type="text" name="'.$item.'" value="'.
8248: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8249: }
8250: $datatable .= '</td></tr>';
8251: $itemcount ++;
8252: }
8253: } elsif ($position eq 'lower') {
1.405 raeburn 8254: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8255: } else {
1.359 raeburn 8256: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8257: my %ownerchg = (
8258: by => {},
8259: for => {},
8260: );
8261: my %ownertitles = &Apache::lonlocal::texthash (
8262: by => 'Course owner status(es) allowed',
8263: for => 'Student status(es) allowed',
8264: );
1.354 raeburn 8265: if (ref($settings) eq 'HASH') {
1.359 raeburn 8266: if (ref($settings->{crsownerchg}) eq 'HASH') {
8267: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8268: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8269: }
8270: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8271: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8272: }
1.354 raeburn 8273: }
8274: }
8275: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8276: $datatable .= '<tr '.$css_class.'>'.
8277: '<td>'.
8278: &mt('Requirements').'<ul>'.
1.359 raeburn 8279: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8280: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8281: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8282: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8283: '</ul>'.
8284: '</td>'.
1.359 raeburn 8285: '<td class="LC_left_item">';
8286: foreach my $item ('by','for') {
8287: $datatable .= '<fieldset style="display: inline-block;">'.
8288: '<legend>'.$ownertitles{$item}.'</legend>';
8289: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8290: foreach my $type (@{$types}) {
8291: my $checked;
8292: if ($ownerchg{$item}{$type}) {
8293: $checked = ' checked="checked"';
8294: }
8295: $datatable .= '<span class="LC_nobreak"><label>'.
8296: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8297: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8298: '</span> ';
1.359 raeburn 8299: }
8300: }
8301: my $checked;
8302: if ($ownerchg{$item}{'default'}) {
8303: $checked = ' checked="checked"';
8304: }
8305: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8306: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8307: $othertitle.'</label></span></fieldset>';
8308: }
8309: $datatable .= '</td></tr>';
1.354 raeburn 8310: }
8311: return $datatable;
8312: }
8313:
1.405 raeburn 8314: sub password_rules {
8315: my ($prefix,$itemcountref,$settings) = @_;
8316: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8317: my %titles;
8318: if ($prefix eq 'passwords') {
8319: %titles = &Apache::lonlocal::texthash (
8320: min => 'Minimum password length',
8321: max => 'Maximum password length',
8322: chars => 'Required characters',
8323: );
1.421 raeburn 8324: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8325: %titles = &Apache::lonlocal::texthash (
8326: min => 'Minimum secret length',
8327: max => 'Maximum secret length',
8328: chars => 'Required characters',
8329: );
8330: }
8331: $min = $Apache::lonnet::passwdmin;
8332: my $datatable;
8333: my $itemcount;
8334: if (ref($itemcountref)) {
8335: $itemcount = $$itemcountref;
8336: }
8337: if (ref($settings) eq 'HASH') {
8338: if ($settings->{min}) {
8339: $min = $settings->{min};
8340: }
8341: if ($settings->{max}) {
8342: $max = $settings->{max};
8343: }
8344: if (ref($settings->{chars}) eq 'ARRAY') {
8345: map { $chars{$_} = 1; } (@{$settings->{chars}});
8346: }
1.425 raeburn 8347: if ($prefix eq 'passwords') {
1.405 raeburn 8348: if ($settings->{expire}) {
8349: $expire = $settings->{expire};
8350: }
8351: if ($settings->{numsaved}) {
8352: $numsaved = $settings->{numsaved};
8353: }
8354: }
8355: }
8356: my %rulenames = &Apache::lonlocal::texthash(
8357: uc => 'At least one upper case letter',
8358: lc => 'At least one lower case letter',
8359: num => 'At least one number',
8360: spec => 'At least one non-alphanumeric',
8361: );
8362: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8363: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8364: '<td class="LC_left_item"><span class="LC_nobreak">'.
8365: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8366: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8367: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8368: '</span></td></tr>';
8369: $itemcount ++;
8370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8371: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8372: '<td class="LC_left_item"><span class="LC_nobreak">'.
8373: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8374: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8375: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8376: '</span></td></tr>';
8377: $itemcount ++;
8378: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8379: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8380: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8381: '</span></td>';
8382: my $numinrow = 2;
8383: my @possrules = ('uc','lc','num','spec');
8384: $datatable .= '<td class="LC_left_item"><table>';
8385: for (my $i=0; $i<@possrules; $i++) {
8386: my ($rem,$checked);
8387: if ($chars{$possrules[$i]}) {
8388: $checked = ' checked="checked"';
8389: }
8390: $rem = $i%($numinrow);
8391: if ($rem == 0) {
8392: if ($i > 0) {
8393: $datatable .= '</tr>';
8394: }
8395: $datatable .= '<tr>';
8396: }
8397: $datatable .= '<td><span class="LC_nobreak"><label>'.
8398: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8399: $rulenames{$possrules[$i]}.'</label></span></td>';
8400: }
8401: my $rem = @possrules%($numinrow);
8402: my $colsleft = $numinrow - $rem;
8403: if ($colsleft > 1 ) {
8404: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8405: ' </td>';
8406: } elsif ($colsleft == 1) {
8407: $datatable .= '<td class="LC_left_item"> </td>';
8408: }
8409: $datatable .='</table></td></tr>';
8410: $itemcount ++;
8411: if ($prefix eq 'passwords') {
8412: $titles{'expire'} = &mt('Password expiration (days)');
8413: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8414: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8415: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8416: '<td class="LC_left_item"><span class="LC_nobreak">'.
8417: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8418: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8419: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8420: '</span></td></tr>';
8421: $itemcount ++;
8422: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8423: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8424: '<td class="LC_left_item"><span class="LC_nobreak">'.
8425: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8426: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8427: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8428: '</span></td></tr>';
8429: $itemcount ++;
8430: }
8431: if (ref($itemcountref)) {
8432: $$itemcountref += $itemcount;
8433: }
8434: return $datatable;
8435: }
8436:
1.373 raeburn 8437: sub print_wafproxy {
8438: my ($position,$dom,$settings,$rowtotal) = @_;
8439: my $css_class;
8440: my $itemcount = 0;
8441: my $datatable;
8442: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8443: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8444: my %lt = &wafproxy_titles();
1.373 raeburn 8445: foreach my $server (sort(keys(%servers))) {
8446: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8447: next if ($serverhome eq '');
1.373 raeburn 8448: my $serverdom;
8449: if ($serverhome ne $server) {
8450: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8451: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8452: $othercontrol{$server} = $serverdom;
8453: }
1.373 raeburn 8454: } else {
8455: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8456: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8457: if ($serverdom ne $dom) {
8458: $othercontrol{$server} = $serverdom;
8459: } else {
8460: $setdom = 1;
8461: if (ref($settings) eq 'HASH') {
8462: if (ref($settings->{'alias'}) eq 'HASH') {
8463: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8464: if ($aliases{$dom} ne '') {
8465: $showdom = 1;
8466: }
1.373 raeburn 8467: }
1.388 raeburn 8468: if (ref($settings->{'saml'}) eq 'HASH') {
8469: $saml{$dom} = $settings->{'saml'};
8470: }
1.373 raeburn 8471: }
8472: }
8473: }
8474: }
1.381 raeburn 8475: if ($setdom) {
8476: %{$values{$dom}} = ();
8477: if (ref($settings) eq 'HASH') {
8478: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8479: $values{$dom}{$item} = $settings->{$item};
8480: }
8481: }
8482: }
1.373 raeburn 8483: if (keys(%othercontrol)) {
8484: %otherdoms = reverse(%othercontrol);
8485: foreach my $domain (keys(%otherdoms)) {
8486: %{$values{$domain}} = ();
8487: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8488: if (ref($config{'wafproxy'}) eq 'HASH') {
8489: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8490: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8491: $saml{$domain} = $config{'wafproxy'}{'saml'};
8492: }
1.383 raeburn 8493: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8494: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8495: }
8496: }
8497: }
8498: }
8499: if ($position eq 'top') {
8500: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8501: my %aliasinfo;
1.373 raeburn 8502: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8503: $itemcount ++;
8504: my $dom_in_effect;
8505: my $aliasrows = '<tr>'.
1.383 raeburn 8506: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8507: &mt('Hostname').': '.
8508: '<span class="LC_nobreak LC_cusr_emph">'.
8509: &Apache::lonnet::hostname($server).
8510: '</span></td><td> </td>';
1.373 raeburn 8511: if ($othercontrol{$server}) {
1.381 raeburn 8512: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8513: my ($current,$forsaml);
1.383 raeburn 8514: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8515: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8516: }
1.388 raeburn 8517: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8518: if ($saml{$dom_in_effect}{$server}) {
8519: $forsaml = 1;
8520: }
8521: }
1.383 raeburn 8522: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8523: &mt('Alias').': ';
1.373 raeburn 8524: if ($current) {
1.381 raeburn 8525: $aliasrows .= $current;
1.388 raeburn 8526: if ($forsaml) {
1.396 raeburn 8527: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8528: }
1.373 raeburn 8529: } else {
1.383 raeburn 8530: $aliasrows .= &mt('None');
1.373 raeburn 8531: }
1.383 raeburn 8532: $aliasrows .= ' <span class="LC_small">('.
8533: &mt('controlled by domain: [_1]',
8534: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8535: } else {
1.381 raeburn 8536: $dom_in_effect = $dom;
1.388 raeburn 8537: my ($current,$samlon,$samloff);
8538: $samloff = ' checked="checked"';
1.373 raeburn 8539: if (ref($aliases{$dom}) eq 'HASH') {
8540: if ($aliases{$dom}{$server}) {
8541: $current = $aliases{$dom}{$server};
8542: }
8543: }
1.388 raeburn 8544: if (ref($saml{$dom}) eq 'HASH') {
8545: if ($saml{$dom}{$server}) {
8546: $samlon = $samloff;
8547: undef($samloff);
8548: }
8549: }
1.383 raeburn 8550: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8551: &mt('Alias').': '.
1.381 raeburn 8552: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8553: 'value="'.$current.'" size="30" />'.
8554: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8555: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8556: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8557: &mt('No').'</label> <label>'.
1.388 raeburn 8558: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8559: &mt('Yes').'</label></span>'.
1.425 raeburn 8560: '</td>';
1.381 raeburn 8561: }
8562: $aliasrows .= '</tr>';
8563: $aliasinfo{$dom_in_effect} .= $aliasrows;
8564: }
8565: if ($aliasinfo{$dom}) {
8566: my ($onclick,$wafon,$wafoff,$showtable);
8567: $onclick = ' onclick="javascript:toggleWAF();"';
8568: $wafoff = ' checked="checked"';
8569: $showtable = ' style="display:none";';
8570: if ($showdom) {
8571: $wafon = $wafoff;
8572: $wafoff = '';
8573: $showtable = ' style="display:inline;"';
8574: }
8575: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8576: $datatable = '<tr'.$css_class.'>'.
8577: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8578: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8579: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8580: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8581: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8582: &mt('No').'</label></span></td>'.
8583: '<td class="LC_left_item">'.
8584: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8585: '</table></td></tr>';
8586: $itemcount++;
8587: }
1.383 raeburn 8588: if (keys(%otherdoms)) {
8589: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8590: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8591: $datatable .= '<tr'.$css_class.'>'.
8592: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8593: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8594: '</table></td></tr>';
1.381 raeburn 8595: $itemcount++;
1.373 raeburn 8596: }
8597: }
8598: } else {
1.383 raeburn 8599: my %ip_methods = &remoteip_methods();
1.373 raeburn 8600: if ($setdom) {
8601: $itemcount ++;
8602: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8603: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8604: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8605: $wafstyle = ' style="display:none;"';
8606: $nowafstyle = ' style="display:table-row;"';
8607: $currwafdisplay = ' style="display: none"';
8608: $wafrangestyle = ' style="display: none"';
8609: $curr_remotip = 'n';
1.382 raeburn 8610: $ssltossl = ' checked="checked"';
1.381 raeburn 8611: if ($showdom) {
8612: $wafstyle = ' style="display:table-row;"';
8613: $nowafstyle = ' style="display:none;"';
8614: if (keys(%{$values{$dom}})) {
8615: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8616: $curr_remotip = $values{$dom}{remoteip};
8617: }
8618: if ($curr_remotip eq 'h') {
8619: $currwafdisplay = ' style="display:table-row"';
8620: $wafrangestyle = ' style="display:inline-block;"';
8621: }
1.382 raeburn 8622: if ($values{$dom}{'sslopt'}) {
8623: $alltossl = ' checked="checked"';
8624: $ssltossl = '';
8625: }
1.381 raeburn 8626: }
8627: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8628: $vpndircheck = ' checked="checked"';
8629: $currwafvpn = ' style="display:table-row;"';
8630: $wafrangestyle = ' style="display:inline-block;"';
8631: } else {
8632: $vpnaliascheck = ' checked="checked"';
8633: $currwafvpn = ' style="display:none;"';
8634: }
8635: }
8636: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8637: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8638: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8639: '</tr>'.
8640: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8641: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8642: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8643: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8644: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8645: '<td class="LC_left_item"><table>'.
8646: '<tr>'.
8647: '<td valign="top">'.$lt{'remoteip'}.': '.
8648: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8649: foreach my $option ('m','h','n') {
8650: my $sel;
8651: if ($option eq $curr_remotip) {
8652: $sel = ' selected="selected"';
8653: }
8654: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8655: $ip_methods{$option}.'</option>';
8656: }
8657: $datatable .= '</select></td></tr>'."\n".
8658: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8659: $lt{'ipheader'}.': '.
8660: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8661: 'name="wafproxy_ipheader" />'.
8662: '</td></tr>'."\n".
8663: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8664: $lt{'trusted'}.':<br />'.
1.381 raeburn 8665: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8666: $values{$dom}{'trusted'}.'</textarea>'.
8667: '</td></tr>'."\n".
8668: '<tr><td><hr /></td></tr>'."\n".
8669: '<tr>'.
8670: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8671: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8672: $lt{'vpndirect'}.'</label>'.(' 'x2).
8673: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8674: $lt{'vpnaliased'}.'</label></span></td></tr>';
8675: foreach my $item ('vpnint','vpnext') {
8676: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8677: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8678: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8679: $values{$dom}{$item}.'</textarea>'.
8680: '</td></tr>'."\n";
1.373 raeburn 8681: }
1.382 raeburn 8682: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8683: '<tr>'.
8684: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8685: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8686: $lt{'alltossl'}.'</label>'.(' 'x2).
8687: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8688: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8689: '</table></td></tr>';
1.373 raeburn 8690: }
8691: if (keys(%otherdoms)) {
8692: foreach my $domain (sort(keys(%otherdoms))) {
8693: $itemcount ++;
8694: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8695: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8696: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8697: '<td class="LC_left_item"><table>';
1.382 raeburn 8698: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8699: my $showval = &mt('None');
1.382 raeburn 8700: if ($item eq 'ssl') {
8701: $showval = $lt{'ssltossl'};
8702: }
1.373 raeburn 8703: if ($values{$domain}{$item}) {
1.381 raeburn 8704: $showval = $values{$domain}{$item};
1.382 raeburn 8705: if ($item eq 'ssl') {
8706: $showval = $lt{'alltossl'};
1.383 raeburn 8707: } elsif ($item eq 'remoteip') {
8708: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8709: }
1.373 raeburn 8710: }
8711: $datatable .= '<tr>'.
8712: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8713: }
1.381 raeburn 8714: $datatable .= '</table></td></tr>';
1.373 raeburn 8715: }
8716: }
8717: }
8718: $$rowtotal += $itemcount;
8719: return $datatable;
8720: }
8721:
8722: sub wafproxy_titles {
8723: return &Apache::lonlocal::texthash(
1.381 raeburn 8724: remoteip => "Method for determining user's IP",
8725: ipheader => 'Request header containing remote IP',
8726: trusted => 'Trusted IP range(s)',
8727: vpnaccess => 'Access from institutional VPN',
8728: vpndirect => 'via regular hostname (no WAF)',
8729: vpnaliased => 'via aliased hostname (WAF)',
8730: vpnint => 'Internal IP Range(s) for VPN sessions',
8731: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8732: sslopt => 'Forwarding http/https',
1.381 raeburn 8733: alltossl => 'WAF forwards both http and https requests to https',
8734: ssltossl => 'WAF forwards http requests to http and https to https',
8735: );
8736: }
8737:
8738: sub remoteip_methods {
8739: return &Apache::lonlocal::texthash(
8740: m => 'Use Apache mod_remoteip',
8741: h => 'Use headers parsed by LON-CAPA',
8742: n => 'Not in use',
1.373 raeburn 8743: );
8744: }
8745:
1.137 raeburn 8746: sub print_usersessions {
8747: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8748: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8749: my (%by_ip,%by_location,@intdoms,@instdoms);
8750: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8751:
8752: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8753: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8754: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8755: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8756: if ($position eq 'top') {
1.152 raeburn 8757: if (keys(%serverhomes) > 1) {
1.145 raeburn 8758: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8759: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8760: if (ref($settings) eq 'HASH') {
8761: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8762: $curroffloadnow = $settings->{'offloadnow'};
8763: }
1.371 raeburn 8764: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8765: $curroffloadoth = $settings->{'offloadoth'};
8766: }
1.261 raeburn 8767: }
1.371 raeburn 8768: my $other_insts = scalar(keys(%by_location));
8769: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8770: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8771: } else {
1.140 raeburn 8772: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8773: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8774: '</td></tr>';
1.140 raeburn 8775: }
1.137 raeburn 8776: } else {
1.279 raeburn 8777: my %titles = &usersession_titles();
8778: my ($prefix,@types);
8779: if ($position eq 'bottom') {
8780: $prefix = 'remote';
8781: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8782: } else {
1.279 raeburn 8783: $prefix = 'hosted';
8784: @types = ('excludedomain','includedomain');
8785: }
8786: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8787: }
8788: $$rowtotal += $itemcount;
8789: return $datatable;
8790: }
8791:
8792: sub rules_by_location {
8793: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8794: my ($datatable,$itemcount,$css_class);
8795: if (keys(%{$by_location}) == 0) {
8796: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8797: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8798: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8799: '</td></tr>';
8800: $itemcount = 1;
8801: } else {
8802: $itemcount = 0;
8803: my $numinrow = 5;
8804: my (%current,%checkedon,%checkedoff);
8805: my @locations = sort(keys(%{$by_location}));
8806: foreach my $type (@{$types}) {
8807: $checkedon{$type} = '';
8808: $checkedoff{$type} = ' checked="checked"';
8809: }
8810: if (ref($settings) eq 'HASH') {
8811: if (ref($settings->{$prefix}) eq 'HASH') {
8812: foreach my $key (keys(%{$settings->{$prefix}})) {
8813: $current{$key} = $settings->{$prefix}{$key};
8814: if ($key eq 'version') {
8815: if ($current{$key} ne '') {
1.145 raeburn 8816: $checkedon{$key} = ' checked="checked"';
8817: $checkedoff{$key} = '';
8818: }
1.279 raeburn 8819: } elsif (ref($current{$key}) eq 'ARRAY') {
8820: $checkedon{$key} = ' checked="checked"';
8821: $checkedoff{$key} = '';
1.137 raeburn 8822: }
8823: }
8824: }
1.279 raeburn 8825: }
8826: foreach my $type (@{$types}) {
8827: next if ($type ne 'version' && !@locations);
8828: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8829: $datatable .= '<tr'.$css_class.'>
8830: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8831: <span class="LC_nobreak">
8832: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8833: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8834: if ($type eq 'version') {
8835: my @lcversions = &Apache::lonnet::all_loncaparevs();
8836: my $selector = '<select name="'.$prefix.'_version">';
8837: foreach my $version (@lcversions) {
8838: my $selected = '';
8839: if ($current{'version'} eq $version) {
8840: $selected = ' selected="selected"';
1.145 raeburn 8841: }
1.279 raeburn 8842: $selector .= ' <option value="'.$version.'"'.
8843: $selected.'>'.$version.'</option>';
8844: }
8845: $selector .= '</select> ';
8846: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8847: } else {
8848: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8849: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8850: ' />'.(' 'x2).
8851: '<input type="button" value="'.&mt('uncheck all').'" '.
8852: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8853: "\n".
8854: '</div><div><table>';
8855: my $rem;
8856: for (my $i=0; $i<@locations; $i++) {
8857: my ($showloc,$value,$checkedtype);
8858: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8859: my $ip = $by_location->{$locations[$i]}->[0];
8860: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8861: $value = join(':',@{$by_ip->{$ip}});
8862: $showloc = join(', ',@{$by_ip->{$ip}});
8863: if (ref($current{$type}) eq 'ARRAY') {
8864: foreach my $loc (@{$by_ip->{$ip}}) {
8865: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8866: $checkedtype = ' checked="checked"';
8867: last;
1.145 raeburn 8868: }
1.138 raeburn 8869: }
8870: }
8871: }
1.137 raeburn 8872: }
1.279 raeburn 8873: $rem = $i%($numinrow);
8874: if ($rem == 0) {
8875: if ($i > 0) {
8876: $datatable .= '</tr>';
8877: }
8878: $datatable .= '<tr>';
8879: }
8880: $datatable .= '<td class="LC_left_item">'.
8881: '<span class="LC_nobreak"><label>'.
8882: '<input type="checkbox" name="'.$prefix.'_'.$type.
8883: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8884: '</label></span></td>';
8885: }
8886: $rem = @locations%($numinrow);
8887: my $colsleft = $numinrow - $rem;
8888: if ($colsleft > 1 ) {
8889: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8890: ' </td>';
8891: } elsif ($colsleft == 1) {
8892: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8893: }
1.279 raeburn 8894: $datatable .= '</tr></table>';
1.137 raeburn 8895: }
1.279 raeburn 8896: $datatable .= '</td></tr>';
8897: $itemcount ++;
1.137 raeburn 8898: }
8899: }
1.279 raeburn 8900: return ($datatable,$itemcount);
1.137 raeburn 8901: }
8902:
1.275 raeburn 8903: sub print_ssl {
8904: my ($position,$dom,$settings,$rowtotal) = @_;
8905: my ($css_class,$datatable);
8906: my $itemcount = 1;
8907: if ($position eq 'top') {
1.281 raeburn 8908: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8909: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8910: my $same_institution;
8911: if ($intdom ne '') {
8912: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8913: if (ref($internet_names) eq 'ARRAY') {
8914: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8915: $same_institution = 1;
8916: }
8917: }
8918: }
1.275 raeburn 8919: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8920: $datatable = '<tr'.$css_class.'><td colspan="2">';
8921: if ($same_institution) {
8922: my %domservers = &Apache::lonnet::get_servers($dom);
8923: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8924: } else {
8925: $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.");
8926: }
8927: $datatable .= '</td></tr>';
1.275 raeburn 8928: $itemcount ++;
8929: } else {
8930: my %titles = &ssl_titles();
8931: my (%by_ip,%by_location,@intdoms,@instdoms);
8932: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8933: my @alldoms = &Apache::lonnet::all_domains();
8934: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8935: my @domservers = &Apache::lonnet::get_servers($dom);
8936: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8937: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8938: if (($position eq 'connto') || ($position eq 'connfrom')) {
8939: my $legacy;
8940: unless (ref($settings) eq 'HASH') {
8941: my $name;
8942: if ($position eq 'connto') {
8943: $name = 'loncAllowInsecure';
8944: } else {
8945: $name = 'londAllowInsecure';
8946: }
8947: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8948: my @ids=&Apache::lonnet::current_machine_ids();
8949: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8950: my %what = (
8951: $name => 1,
8952: );
8953: my ($result,$returnhash) =
8954: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8955: if ($result eq 'ok') {
8956: if (ref($returnhash) eq 'HASH') {
8957: $legacy = $returnhash->{$name};
8958: }
8959: }
8960: } else {
8961: $legacy = $Apache::lonnet::perlvar{$name};
8962: }
8963: }
1.275 raeburn 8964: foreach my $type ('dom','intdom','other') {
8965: my %checked;
8966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8967: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8968: '<td class="LC_right_item">';
8969: my $skip;
8970: if ($type eq 'dom') {
8971: unless (keys(%servers) > 1) {
8972: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8973: $skip = 1;
8974: }
8975: }
8976: if ($type eq 'intdom') {
8977: unless (@instdoms > 1) {
8978: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8979: $skip = 1;
8980: }
8981: } elsif ($type eq 'other') {
8982: if (keys(%by_location) == 0) {
8983: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8984: $skip = 1;
8985: }
8986: }
8987: unless ($skip) {
8988: $checked{'yes'} = ' checked="checked"';
8989: if (ref($settings) eq 'HASH') {
1.293 raeburn 8990: if (ref($settings->{$position}) eq 'HASH') {
8991: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8992: $checked{$1} = $checked{'yes'};
8993: delete($checked{'yes'});
8994: }
8995: }
1.293 raeburn 8996: } else {
8997: if ($legacy == 0) {
8998: $checked{'req'} = $checked{'yes'};
8999: delete($checked{'yes'});
9000: }
1.275 raeburn 9001: }
9002: foreach my $option ('no','yes','req') {
9003: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 9004: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 9005: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
9006: '</label></span>'.(' 'x2);
9007: }
9008: }
9009: $datatable .= '</td></tr>';
9010: $itemcount ++;
9011: }
9012: } else {
9013: my $prefix = 'replication';
9014: my @types = ('certreq','nocertreq');
1.279 raeburn 9015: if (keys(%by_location) == 0) {
9016: $datatable .= '<tr'.$css_class.'><td>'.
9017: &mt('Nothing to set here, as there are no other institutions').
9018: '</td></tr>';
9019: $itemcount ++;
1.275 raeburn 9020: } else {
1.279 raeburn 9021: ($datatable,$itemcount) =
9022: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9023: }
9024: }
9025: }
9026: $$rowtotal += $itemcount;
9027: return $datatable;
9028: }
9029:
9030: sub ssl_titles {
9031: return &Apache::lonlocal::texthash (
9032: dom => 'LON-CAPA servers/VMs from same domain',
9033: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9034: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9035: connto => 'Connections to other servers',
9036: connfrom => 'Connections from other servers',
1.275 raeburn 9037: replication => 'Replicating content to other institutions',
9038: certreq => 'Client certificate required, but specific domains exempt',
9039: nocertreq => 'No client certificate required, except for specific domains',
9040: no => 'SSL not used',
9041: yes => 'SSL Optional (used if available)',
9042: req => 'SSL Required',
9043: );
1.279 raeburn 9044: }
9045:
9046: sub print_trust {
9047: my ($prefix,$dom,$settings,$rowtotal) = @_;
9048: my ($css_class,$datatable,%checked,%choices);
9049: my (%by_ip,%by_location,@intdoms,@instdoms);
9050: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9051: my $itemcount = 1;
9052: my %titles = &trust_titles();
9053: my @types = ('exc','inc');
9054: if ($prefix eq 'top') {
9055: $prefix = 'content';
9056: } elsif ($prefix eq 'bottom') {
9057: $prefix = 'msg';
9058: }
9059: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9060: $$rowtotal += $itemcount;
9061: return $datatable;
9062: }
9063:
9064: sub trust_titles {
9065: return &Apache::lonlocal::texthash(
9066: content => "Access to this domain's content by others",
9067: shared => "Access to other domain's content by this domain",
9068: enroll => "Enrollment in this domain's courses by others",
9069: othcoau => "Co-author roles in this domain for others",
9070: coaurem => "Co-author roles for this domain's users elsewhere",
9071: domroles => "Domain roles in this domain assignable to others",
9072: catalog => "Course Catalog for this domain displayed elsewhere",
9073: reqcrs => "Requests for creation of courses in this domain by others",
9074: msg => "Users in other domains can send messages to this domain",
9075: exc => "Allow all, but exclude specific domains",
9076: inc => "Deny all, but include specific domains",
9077: );
1.275 raeburn 9078: }
9079:
1.138 raeburn 9080: sub build_location_hashes {
1.275 raeburn 9081: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9082: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9083: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9084: my %iphost = &Apache::lonnet::get_iphost();
9085: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9086: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9087: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9088: foreach my $id (@{$iphost{$primary_ip}}) {
9089: my $intdom = &Apache::lonnet::internet_dom($id);
9090: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9091: push(@{$intdoms},$intdom);
9092: }
9093: }
9094: }
9095: foreach my $ip (keys(%iphost)) {
9096: if (ref($iphost{$ip}) eq 'ARRAY') {
9097: foreach my $id (@{$iphost{$ip}}) {
9098: my $location = &Apache::lonnet::internet_dom($id);
9099: if ($location) {
1.275 raeburn 9100: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9101: my $dom = &Apache::lonnet::host_domain($id);
9102: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9103: push(@{$instdoms},$dom);
9104: }
9105: next;
9106: }
1.138 raeburn 9107: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9108: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9109: push(@{$by_ip->{$ip}},$location);
9110: }
9111: } else {
9112: $by_ip->{$ip} = [$location];
9113: }
9114: }
9115: }
9116: }
9117: }
9118: foreach my $ip (sort(keys(%{$by_ip}))) {
9119: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9120: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9121: my $first = $by_ip->{$ip}->[0];
9122: if (ref($by_location->{$first}) eq 'ARRAY') {
9123: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9124: push(@{$by_location->{$first}},$ip);
9125: }
9126: } else {
9127: $by_location->{$first} = [$ip];
9128: }
9129: }
9130: }
9131: return;
9132: }
9133:
1.145 raeburn 9134: sub current_offloads_to {
9135: my ($dom,$settings,$servers) = @_;
9136: my (%spareid,%otherdomconfigs);
1.152 raeburn 9137: if (ref($servers) eq 'HASH') {
1.145 raeburn 9138: foreach my $lonhost (sort(keys(%{$servers}))) {
9139: my $gotspares;
1.152 raeburn 9140: if (ref($settings) eq 'HASH') {
9141: if (ref($settings->{'spares'}) eq 'HASH') {
9142: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9143: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9144: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9145: $gotspares = 1;
9146: }
1.145 raeburn 9147: }
9148: }
9149: unless ($gotspares) {
9150: my $gotspares;
9151: my $serverhomeID =
9152: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9153: my $serverhomedom =
9154: &Apache::lonnet::host_domain($serverhomeID);
9155: if ($serverhomedom ne $dom) {
9156: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9157: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9158: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9159: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9160: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9161: $gotspares = 1;
9162: }
9163: }
9164: } else {
9165: $otherdomconfigs{$serverhomedom} =
9166: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9167: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9168: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9169: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9170: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9171: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9172: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9173: $gotspares = 1;
9174: }
9175: }
9176: }
9177: }
9178: }
9179: }
9180: }
9181: unless ($gotspares) {
9182: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9183: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9184: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9185: } else {
9186: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9187: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9188: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9189: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9190: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9191: } else {
1.150 raeburn 9192: my %what = (
9193: spareid => 1,
9194: );
9195: my ($result,$returnhash) =
9196: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9197: if ($result eq 'ok') {
9198: if (ref($returnhash) eq 'HASH') {
9199: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9200: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9201: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9202: }
9203: }
1.145 raeburn 9204: }
9205: }
9206: }
9207: }
9208: }
9209: }
9210: return %spareid;
9211: }
9212:
9213: sub spares_row {
1.371 raeburn 9214: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9215: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9216: my $css_class;
9217: my $numinrow = 4;
9218: my $itemcount = 1;
9219: my $datatable;
1.152 raeburn 9220: my %typetitles = &sparestype_titles();
9221: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9222: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9223: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9224: my ($othercontrol,$serverdom);
9225: if ($serverhome ne $server) {
9226: $serverdom = &Apache::lonnet::host_domain($serverhome);
9227: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9228: } else {
9229: $serverdom = &Apache::lonnet::host_domain($server);
9230: if ($serverdom ne $dom) {
9231: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9232: }
9233: }
9234: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9235: my ($checkednow,$checkedoth);
1.261 raeburn 9236: if (ref($curroffloadnow) eq 'HASH') {
9237: if ($curroffloadnow->{$server}) {
9238: $checkednow = ' checked="checked"';
9239: }
9240: }
1.371 raeburn 9241: if (ref($curroffloadoth) eq 'HASH') {
9242: if ($curroffloadoth->{$server}) {
9243: $checkedoth = ' checked="checked"';
9244: }
9245: }
1.145 raeburn 9246: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9247: $datatable .= '<tr'.$css_class.'>
9248: <td rowspan="2">
1.183 bisitz 9249: <span class="LC_nobreak">'.
9250: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9251: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9252: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9253: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9254: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9255: "\n";
1.371 raeburn 9256: if ($other_insts) {
9257: $datatable .= '<br />'.
9258: '<span class="LC_nobreak">'."\n".
9259: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9260: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9261: "\n";
9262: }
1.145 raeburn 9263: my (%current,%canselect);
1.152 raeburn 9264: my @choices =
9265: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9266: foreach my $type ('primary','default') {
9267: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9268: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9269: my @spares = @{$spareid->{$server}{$type}};
9270: if (@spares > 0) {
1.152 raeburn 9271: if ($othercontrol) {
9272: $current{$type} = join(', ',@spares);
9273: } else {
9274: $current{$type} .= '<table>';
9275: my $numspares = scalar(@spares);
9276: for (my $i=0; $i<@spares; $i++) {
9277: my $rem = $i%($numinrow);
9278: if ($rem == 0) {
9279: if ($i > 0) {
9280: $current{$type} .= '</tr>';
9281: }
9282: $current{$type} .= '<tr>';
1.145 raeburn 9283: }
1.152 raeburn 9284: $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'".');" /> '.
9285: $spareid->{$server}{$type}[$i].
9286: '</label></td>'."\n";
9287: }
9288: my $rem = @spares%($numinrow);
9289: my $colsleft = $numinrow - $rem;
9290: if ($colsleft > 1 ) {
9291: $current{$type} .= '<td colspan="'.$colsleft.
9292: '" class="LC_left_item">'.
9293: ' </td>';
9294: } elsif ($colsleft == 1) {
9295: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9296: }
1.152 raeburn 9297: $current{$type} .= '</tr></table>';
1.150 raeburn 9298: }
1.145 raeburn 9299: }
9300: }
9301: if ($current{$type} eq '') {
9302: $current{$type} = &mt('None specified');
9303: }
1.152 raeburn 9304: if ($othercontrol) {
9305: if ($type eq 'primary') {
9306: $canselect{$type} = $othercontrol;
9307: }
9308: } else {
9309: $canselect{$type} =
9310: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9311: '<select name="newspare_'.$type.'_'.$server.'" '.
9312: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9313: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9314: if (@choices > 0) {
9315: foreach my $lonhost (@choices) {
9316: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9317: }
9318: }
9319: $canselect{$type} .= '</select>'."\n";
9320: }
9321: } else {
9322: $current{$type} = &mt('Could not be determined');
9323: if ($type eq 'primary') {
9324: $canselect{$type} = $othercontrol;
9325: }
1.145 raeburn 9326: }
1.152 raeburn 9327: if ($type eq 'default') {
9328: $datatable .= '<tr'.$css_class.'>';
9329: }
9330: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9331: '<td>'.$current{$type}.'</td>'."\n".
9332: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9333: }
9334: $itemcount ++;
9335: }
9336: }
9337: $$rowtotal += $itemcount;
9338: return $datatable;
9339: }
9340:
1.152 raeburn 9341: sub possible_newspares {
9342: my ($server,$currspares,$serverhomes,$altids) = @_;
9343: my $serverhostname = &Apache::lonnet::hostname($server);
9344: my %excluded;
9345: if ($serverhostname ne '') {
9346: %excluded = (
9347: $serverhostname => 1,
9348: );
9349: }
9350: if (ref($currspares) eq 'HASH') {
9351: foreach my $type (keys(%{$currspares})) {
9352: if (ref($currspares->{$type}) eq 'ARRAY') {
9353: if (@{$currspares->{$type}} > 0) {
9354: foreach my $curr (@{$currspares->{$type}}) {
9355: my $hostname = &Apache::lonnet::hostname($curr);
9356: $excluded{$hostname} = 1;
9357: }
9358: }
9359: }
9360: }
9361: }
9362: my @choices;
9363: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9364: if (keys(%{$serverhomes}) > 1) {
9365: foreach my $name (sort(keys(%{$serverhomes}))) {
9366: unless ($excluded{$name}) {
9367: if (exists($altids->{$serverhomes->{$name}})) {
9368: push(@choices,$altids->{$serverhomes->{$name}});
9369: } else {
9370: push(@choices,$serverhomes->{$name});
1.145 raeburn 9371: }
9372: }
9373: }
9374: }
9375: }
1.152 raeburn 9376: return sort(@choices);
1.145 raeburn 9377: }
9378:
1.150 raeburn 9379: sub print_loadbalancing {
9380: my ($dom,$settings,$rowtotal) = @_;
9381: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9382: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9383: my $numinrow = 1;
9384: my $datatable;
9385: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9386: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9387: if (ref($settings) eq 'HASH') {
9388: %existing = %{$settings};
9389: }
9390: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9391: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9392: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9393: } else {
9394: return;
9395: }
9396: my ($othertitle,$usertypes,$types) =
9397: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9398: my $rownum = 8;
1.150 raeburn 9399: if (ref($types) eq 'ARRAY') {
9400: $rownum += scalar(@{$types});
9401: }
1.171 raeburn 9402: my @css_class = ('LC_odd_row','LC_even_row');
9403: my $balnum = 0;
9404: my $islast;
9405: my (@toshow,$disabledtext);
9406: if (keys(%currbalancer) > 0) {
9407: @toshow = sort(keys(%currbalancer));
9408: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9409: push(@toshow,'');
9410: }
9411: } else {
9412: @toshow = ('');
9413: $disabledtext = &mt('No existing load balancer');
9414: }
9415: foreach my $lonhost (@toshow) {
9416: if ($balnum == scalar(@toshow)-1) {
9417: $islast = 1;
9418: } else {
9419: $islast = 0;
9420: }
9421: my $cssidx = $balnum%2;
9422: my $targets_div_style = 'display: none';
9423: my $disabled_div_style = 'display: block';
9424: my $homedom_div_style = 'display: none';
9425: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9426: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9427: '<p>';
9428: if ($lonhost eq '') {
1.210 raeburn 9429: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9430: if (keys(%currbalancer) > 0) {
9431: $datatable .= &mt('Add balancer:');
9432: } else {
9433: $datatable .= &mt('Enable balancer:');
9434: }
9435: $datatable .= ' '.
9436: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9437: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9438: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9439: '<option value="" selected="selected">'.&mt('None').
9440: '</option>'."\n";
9441: foreach my $server (sort(keys(%servers))) {
9442: next if ($currbalancer{$server});
9443: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9444: }
1.210 raeburn 9445: $datatable .=
1.171 raeburn 9446: '</select>'."\n".
9447: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9448: } else {
9449: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9450: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9451: &mt('Stop balancing').'</label>'.
9452: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9453: $targets_div_style = 'display: block';
9454: $disabled_div_style = 'display: none';
9455: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9456: $homedom_div_style = 'display: block';
9457: }
9458: }
1.306 raeburn 9459: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9460: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9461: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9462: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9463: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9464: my @sparestypes = ('primary','default');
9465: my %typetitles = &sparestype_titles();
1.284 raeburn 9466: my %hostherechecked = (
9467: no => ' checked="checked"',
9468: );
1.342 raeburn 9469: my %balcookiechecked = (
1.425 raeburn 9470: no => ' checked="checked"',
1.342 raeburn 9471: );
1.171 raeburn 9472: foreach my $sparetype (@sparestypes) {
9473: my $targettable;
9474: for (my $i=0; $i<$numspares; $i++) {
9475: my $checked;
9476: if (ref($currtargets{$lonhost}) eq 'HASH') {
9477: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9478: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9479: $checked = ' checked="checked"';
9480: }
9481: }
9482: }
9483: my ($chkboxval,$disabled);
9484: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9485: $chkboxval = $spares[$i];
9486: }
9487: if (exists($currbalancer{$spares[$i]})) {
9488: $disabled = ' disabled="disabled"';
9489: }
1.210 raeburn 9490: $targettable .=
1.253 raeburn 9491: '<td><span class="LC_nobreak"><label>'.
9492: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9493: $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 9494: '</span></label></span></td>';
1.171 raeburn 9495: my $rem = $i%($numinrow);
9496: if ($rem == 0) {
9497: if (($i > 0) && ($i < $numspares-1)) {
9498: $targettable .= '</tr>';
9499: }
9500: if ($i < $numspares-1) {
9501: $targettable .= '<tr>';
1.150 raeburn 9502: }
9503: }
9504: }
1.171 raeburn 9505: if ($targettable ne '') {
9506: my $rem = $numspares%($numinrow);
9507: my $colsleft = $numinrow - $rem;
9508: if ($colsleft > 1 ) {
9509: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9510: ' </td>';
9511: } elsif ($colsleft == 1) {
9512: $targettable .= '<td class="LC_left_item"> </td>';
9513: }
9514: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9515: '<table><tr>'.$targettable.'</tr></table><br />';
9516: }
1.284 raeburn 9517: $hostherechecked{$sparetype} = '';
9518: if (ref($currtargets{$lonhost}) eq 'HASH') {
9519: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9520: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9521: $hostherechecked{$sparetype} = ' checked="checked"';
9522: $hostherechecked{'no'} = '';
9523: }
9524: }
9525: }
9526: }
1.342 raeburn 9527: if ($currcookies{$lonhost}) {
9528: %balcookiechecked = (
9529: yes => ' checked="checked"',
9530: );
9531: }
1.284 raeburn 9532: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9533: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9534: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9535: foreach my $sparetype (@sparestypes) {
9536: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9537: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9538: '</i></label><br />';
1.171 raeburn 9539: }
1.342 raeburn 9540: $datatable .= &mt('Use balancer cookie').'<br />'.
9541: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9542: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9543: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9544: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9545: '</div></td></tr>'.
1.171 raeburn 9546: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9547: $othertitle,$usertypes,$types,\%servers,
9548: \%currbalancer,$lonhost,
9549: $targets_div_style,$homedom_div_style,
9550: $css_class[$cssidx],$balnum,$islast);
9551: $$rowtotal += $rownum;
9552: $balnum ++;
9553: }
9554: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9555: return $datatable;
9556: }
9557:
9558: sub get_loadbalancers_config {
1.342 raeburn 9559: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9560: return unless ((ref($servers) eq 'HASH') &&
9561: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9562: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9563: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9564: if (keys(%{$existing}) > 0) {
9565: my $oldlonhost;
9566: foreach my $key (sort(keys(%{$existing}))) {
9567: if ($key eq 'lonhost') {
9568: $oldlonhost = $existing->{'lonhost'};
9569: $currbalancer->{$oldlonhost} = 1;
9570: } elsif ($key eq 'targets') {
9571: if ($oldlonhost) {
9572: $currtargets->{$oldlonhost} = $existing->{'targets'};
9573: }
9574: } elsif ($key eq 'rules') {
9575: if ($oldlonhost) {
9576: $currrules->{$oldlonhost} = $existing->{'rules'};
9577: }
9578: } elsif (ref($existing->{$key}) eq 'HASH') {
9579: $currbalancer->{$key} = 1;
9580: $currtargets->{$key} = $existing->{$key}{'targets'};
9581: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9582: if ($existing->{$key}{'cookie'}) {
9583: $currcookies->{$key} = 1;
9584: }
1.150 raeburn 9585: }
9586: }
1.171 raeburn 9587: } else {
9588: my ($balancerref,$targetsref) =
9589: &Apache::lonnet::get_lonbalancer_config($servers);
9590: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9591: foreach my $server (sort(keys(%{$balancerref}))) {
9592: $currbalancer->{$server} = 1;
9593: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9594: }
9595: }
9596: }
1.171 raeburn 9597: return;
1.150 raeburn 9598: }
9599:
9600: sub loadbalancing_rules {
9601: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9602: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9603: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9604: my $output;
1.171 raeburn 9605: my $num = 0;
1.210 raeburn 9606: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9607: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9608: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9609: foreach my $type (@{$alltypes}) {
1.171 raeburn 9610: $num ++;
1.150 raeburn 9611: my $current;
9612: if (ref($currrules) eq 'HASH') {
9613: $current = $currrules->{$type};
9614: }
1.253 raeburn 9615: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9616: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9617: $current = '';
9618: }
9619: }
9620: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9621: $servers,$currbalancer,$lonhost,$dom,
9622: $targets_div_style,$homedom_div_style,
9623: $css_class,$balnum,$num,$islast);
1.150 raeburn 9624: }
9625: }
9626: return $output;
9627: }
9628:
9629: sub loadbalancing_titles {
9630: my ($dom,$intdom,$usertypes,$types) = @_;
9631: my %othertypes = (
9632: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9633: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9634: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9635: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9636: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9637: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9638: );
1.209 raeburn 9639: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9640: my @available;
1.150 raeburn 9641: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9642: @available = @{$types};
1.150 raeburn 9643: }
1.302 raeburn 9644: unless (grep(/^default$/,@available)) {
9645: push(@available,'default');
9646: }
9647: unshift(@alltypes,@available);
1.150 raeburn 9648: my %titles;
9649: foreach my $type (@alltypes) {
9650: if ($type =~ /^_LC_/) {
9651: $titles{$type} = $othertypes{$type};
9652: } elsif ($type eq 'default') {
9653: $titles{$type} = &mt('All users from [_1]',$dom);
9654: if (ref($types) eq 'ARRAY') {
9655: if (@{$types} > 0) {
9656: $titles{$type} = &mt('Other users from [_1]',$dom);
9657: }
9658: }
9659: } elsif (ref($usertypes) eq 'HASH') {
9660: $titles{$type} = $usertypes->{$type};
9661: }
9662: }
9663: return (\@alltypes,\%othertypes,\%titles);
9664: }
9665:
9666: sub loadbalance_rule_row {
1.171 raeburn 9667: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9668: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9669: my @rulenames;
1.150 raeburn 9670: my %ruletitles = &offloadtype_text();
1.209 raeburn 9671: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9672: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9673: } else {
1.209 raeburn 9674: @rulenames = ('default','homeserver');
9675: if ($type eq '_LC_external') {
9676: push(@rulenames,'externalbalancer');
9677: } else {
9678: push(@rulenames,'specific');
9679: }
9680: push(@rulenames,'none');
1.150 raeburn 9681: }
9682: my $style = $targets_div_style;
1.253 raeburn 9683: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9684: $style = $homedom_div_style;
9685: }
1.171 raeburn 9686: my $space;
9687: if ($islast && $num == 1) {
1.317 raeburn 9688: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9689: }
1.210 raeburn 9690: my $output =
1.306 raeburn 9691: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9692: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9693: '<td valaign="top">'.$space.
9694: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9695: for (my $i=0; $i<@rulenames; $i++) {
9696: my $rule = $rulenames[$i];
9697: my ($checked,$extra);
9698: if ($rulenames[$i] eq 'default') {
9699: $rule = '';
9700: }
9701: if ($rulenames[$i] eq 'specific') {
9702: if (ref($servers) eq 'HASH') {
9703: my $default;
9704: if (($current ne '') && (exists($servers->{$current}))) {
9705: $checked = ' checked="checked"';
9706: }
9707: unless ($checked) {
9708: $default = ' selected="selected"';
9709: }
1.210 raeburn 9710: $extra =
1.171 raeburn 9711: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9712: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9713: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9714: '<option value=""'.$default.'></option>'."\n";
9715: foreach my $server (sort(keys(%{$servers}))) {
9716: if (ref($currbalancer) eq 'HASH') {
9717: next if (exists($currbalancer->{$server}));
9718: }
1.150 raeburn 9719: my $selected;
1.171 raeburn 9720: if ($server eq $current) {
1.150 raeburn 9721: $selected = ' selected="selected"';
9722: }
1.171 raeburn 9723: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9724: }
9725: $extra .= '</select>';
9726: }
9727: } elsif ($rule eq $current) {
9728: $checked = ' checked="checked"';
9729: }
9730: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9731: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9732: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9733: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9734: ')"'.$checked.' /> ';
9735: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9736: $output .= $ruletitles{'particular'};
9737: } else {
9738: $output .= $ruletitles{$rulenames[$i]};
9739: }
9740: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9741: }
9742: $output .= '</div></td></tr>'."\n";
9743: return $output;
9744: }
9745:
9746: sub offloadtype_text {
9747: my %ruletitles = &Apache::lonlocal::texthash (
9748: 'default' => 'Offloads to default destinations',
9749: 'homeserver' => "Offloads to user's home server",
9750: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9751: 'specific' => 'Offloads to specific server',
1.161 raeburn 9752: 'none' => 'No offload',
1.209 raeburn 9753: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9754: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9755: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9756: );
9757: return %ruletitles;
9758: }
9759:
9760: sub sparestype_titles {
9761: my %typestitles = &Apache::lonlocal::texthash (
9762: 'primary' => 'primary',
9763: 'default' => 'default',
9764: );
9765: return %typestitles;
9766: }
9767:
1.28 raeburn 9768: sub contact_titles {
9769: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9770: 'supportemail' => 'Support E-mail address',
9771: 'adminemail' => 'Default Server Admin E-mail address',
9772: 'errormail' => 'Error reports to be e-mailed to',
9773: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9774: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9775: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9776: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9777: 'requestsmail' => 'E-mail from course requests requiring approval',
9778: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9779: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9780: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9781: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9782: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9783: 'errorweights' => 'Weights used to compute error count',
9784: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9785: );
9786: my %short_titles = &Apache::lonlocal::texthash (
9787: adminemail => 'Admin E-mail address',
9788: supportemail => 'Support E-mail',
9789: );
9790: return (\%titles,\%short_titles);
9791: }
9792:
1.286 raeburn 9793: sub helpform_fields {
9794: my %titles = &Apache::lonlocal::texthash (
9795: 'username' => 'Name',
9796: 'user' => 'Username/domain',
9797: 'phone' => 'Phone',
9798: 'cc' => 'Cc e-mail',
9799: 'course' => 'Course Details',
9800: 'section' => 'Sections',
1.289 raeburn 9801: 'screenshot' => 'File upload',
1.286 raeburn 9802: );
9803: my @fields = ('username','phone','user','course','section','cc','screenshot');
9804: my %possoptions = (
9805: username => ['yes','no','req'],
1.289 raeburn 9806: phone => ['yes','no','req'],
1.286 raeburn 9807: user => ['yes','no'],
1.289 raeburn 9808: cc => ['yes','no'],
1.286 raeburn 9809: course => ['yes','no'],
9810: section => ['yes','no'],
9811: screenshot => ['yes','no'],
9812: );
9813: my %fieldoptions = &Apache::lonlocal::texthash (
9814: 'yes' => 'Optional',
9815: 'req' => 'Required',
9816: 'no' => "Not shown",
9817: );
9818: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9819: }
9820:
1.72 raeburn 9821: sub tool_titles {
9822: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9823: aboutme => 'Personal web page',
1.86 raeburn 9824: blog => 'Blog',
9825: portfolio => 'Portfolio',
1.430 raeburn 9826: portaccess => 'Share portfolio files',
1.413 raeburn 9827: timezone => 'Can set time zone',
1.88 bisitz 9828: official => 'Official courses (with institutional codes)',
9829: unofficial => 'Unofficial courses',
1.98 raeburn 9830: community => 'Communities',
1.216 raeburn 9831: textbook => 'Textbook courses',
1.271 raeburn 9832: placement => 'Placement tests',
1.86 raeburn 9833: );
1.72 raeburn 9834: return %titles;
9835: }
9836:
1.101 raeburn 9837: sub courserequest_titles {
9838: my %titles = &Apache::lonlocal::texthash (
9839: official => 'Official',
9840: unofficial => 'Unofficial',
9841: community => 'Communities',
1.216 raeburn 9842: textbook => 'Textbook',
1.271 raeburn 9843: placement => 'Placement tests',
1.325 raeburn 9844: lti => 'LTI Provider',
1.101 raeburn 9845: norequest => 'Not allowed',
1.325 raeburn 9846: approval => 'Approval by DC',
1.101 raeburn 9847: validate => 'With validation',
9848: autolimit => 'Numerical limit',
1.103 raeburn 9849: unlimited => '(blank for unlimited)',
1.101 raeburn 9850: );
9851: return %titles;
9852: }
9853:
1.163 raeburn 9854: sub authorrequest_titles {
9855: my %titles = &Apache::lonlocal::texthash (
9856: norequest => 'Not allowed',
9857: approval => 'Approval by Dom. Coord.',
9858: automatic => 'Automatic approval',
9859: );
9860: return %titles;
1.210 raeburn 9861: }
1.163 raeburn 9862:
1.101 raeburn 9863: sub courserequest_conditions {
9864: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9865: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9866: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9867: );
9868: return %conditions;
9869: }
9870:
9871:
1.27 raeburn 9872: sub print_usercreation {
1.30 raeburn 9873: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9874: my $numinrow = 4;
1.28 raeburn 9875: my $datatable;
9876: if ($position eq 'top') {
1.30 raeburn 9877: $$rowtotal ++;
1.34 raeburn 9878: my $rowcount = 0;
1.32 raeburn 9879: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9880: if (ref($rules) eq 'HASH') {
9881: if (keys(%{$rules}) > 0) {
1.32 raeburn 9882: $datatable .= &user_formats_row('username',$settings,$rules,
9883: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9884: $$rowtotal ++;
1.32 raeburn 9885: $rowcount ++;
9886: }
9887: }
9888: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9889: if (ref($idrules) eq 'HASH') {
9890: if (keys(%{$idrules}) > 0) {
9891: $datatable .= &user_formats_row('id',$settings,$idrules,
9892: $idruleorder,$numinrow,$rowcount);
9893: $$rowtotal ++;
9894: $rowcount ++;
1.28 raeburn 9895: }
9896: }
1.39 raeburn 9897: if ($rowcount == 0) {
9898: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9899: $$rowtotal ++;
9900: $rowcount ++;
9901: }
1.34 raeburn 9902: } elsif ($position eq 'middle') {
1.224 raeburn 9903: my @creators = ('author','course','requestcrs');
1.37 raeburn 9904: my ($rules,$ruleorder) =
9905: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9906: my %lt = &usercreation_types();
9907: my %checked;
9908: if (ref($settings) eq 'HASH') {
9909: if (ref($settings->{'cancreate'}) eq 'HASH') {
9910: foreach my $item (@creators) {
9911: $checked{$item} = $settings->{'cancreate'}{$item};
9912: }
9913: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9914: foreach my $item (@creators) {
9915: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9916: $checked{$item} = 'none';
9917: }
9918: }
9919: }
9920: }
9921: my $rownum = 0;
9922: foreach my $item (@creators) {
9923: $rownum ++;
1.224 raeburn 9924: if ($checked{$item} eq '') {
9925: $checked{$item} = 'any';
1.34 raeburn 9926: }
9927: my $css_class;
9928: if ($rownum%2) {
9929: $css_class = '';
9930: } else {
9931: $css_class = ' class="LC_odd_row" ';
9932: }
9933: $datatable .= '<tr'.$css_class.'>'.
9934: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9935: '</span></td><td style="text-align: right">';
1.224 raeburn 9936: my @options = ('any');
9937: if (ref($rules) eq 'HASH') {
9938: if (keys(%{$rules}) > 0) {
9939: push(@options,('official','unofficial'));
1.37 raeburn 9940: }
9941: }
1.224 raeburn 9942: push(@options,'none');
1.37 raeburn 9943: foreach my $option (@options) {
1.50 raeburn 9944: my $type = 'radio';
1.34 raeburn 9945: my $check = ' ';
1.224 raeburn 9946: if ($checked{$item} eq $option) {
9947: $check = ' checked="checked" ';
1.34 raeburn 9948: }
9949: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9950: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9951: $item.'" value="'.$option.'"'.$check.'/> '.
9952: $lt{$option}.'</label> </span>';
9953: }
9954: $datatable .= '</td></tr>';
9955: }
1.28 raeburn 9956: } else {
9957: my @contexts = ('author','course','domain');
1.325 raeburn 9958: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9959: my %checked;
9960: if (ref($settings) eq 'HASH') {
9961: if (ref($settings->{'authtypes'}) eq 'HASH') {
9962: foreach my $item (@contexts) {
9963: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9964: foreach my $auth (@authtypes) {
9965: if ($settings->{'authtypes'}{$item}{$auth}) {
9966: $checked{$item}{$auth} = ' checked="checked" ';
9967: }
9968: }
9969: }
9970: }
1.27 raeburn 9971: }
1.35 raeburn 9972: } else {
9973: foreach my $item (@contexts) {
1.36 raeburn 9974: foreach my $auth (@authtypes) {
1.35 raeburn 9975: $checked{$item}{$auth} = ' checked="checked" ';
9976: }
9977: }
1.27 raeburn 9978: }
1.28 raeburn 9979: my %title = &context_names();
9980: my %authname = &authtype_names();
9981: my $rownum = 0;
9982: my $css_class;
9983: foreach my $item (@contexts) {
9984: if ($rownum%2) {
9985: $css_class = '';
9986: } else {
9987: $css_class = ' class="LC_odd_row" ';
9988: }
1.30 raeburn 9989: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9990: '<td>'.$title{$item}.
9991: '</td><td class="LC_left_item">'.
9992: '<span class="LC_nobreak">';
9993: foreach my $auth (@authtypes) {
9994: $datatable .= '<label>'.
9995: '<input type="checkbox" name="'.$item.'_auth" '.
9996: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9997: $authname{$auth}.'</label> ';
9998: }
9999: $datatable .= '</span></td></tr>';
10000: $rownum ++;
1.27 raeburn 10001: }
1.30 raeburn 10002: $$rowtotal += $rownum;
1.27 raeburn 10003: }
10004: return $datatable;
10005: }
10006:
1.224 raeburn 10007: sub print_selfcreation {
10008: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10009: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10010: $emaildomain,$datatable);
1.224 raeburn 10011: if (ref($settings) eq 'HASH') {
10012: if (ref($settings->{'cancreate'}) eq 'HASH') {
10013: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10014: if (ref($createsettings) eq 'HASH') {
10015: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10016: @selfcreate = @{$createsettings->{'selfcreate'}};
10017: } elsif ($createsettings->{'selfcreate'} ne '') {
10018: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10019: @selfcreate = ('email','login','sso');
10020: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10021: @selfcreate = ($createsettings->{'selfcreate'});
10022: }
10023: }
10024: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10025: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10026: }
1.305 raeburn 10027: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10028: $emailoptions = $createsettings->{'emailoptions'};
10029: }
1.303 raeburn 10030: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10031: $emailverified = $createsettings->{'emailverified'};
10032: }
10033: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10034: $emaildomain = $createsettings->{'emaildomain'};
10035: }
1.224 raeburn 10036: }
10037: }
10038: }
10039: my %radiohash;
10040: my $numinrow = 4;
10041: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10042: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10043: if ($position eq 'top') {
10044: my %choices = &Apache::lonlocal::texthash (
10045: cancreate_login => 'Institutional Login',
10046: cancreate_sso => 'Institutional Single Sign On',
10047: );
10048: my @toggles = sort(keys(%choices));
10049: my %defaultchecked = (
10050: 'cancreate_login' => 'off',
10051: 'cancreate_sso' => 'off',
10052: );
1.228 raeburn 10053: my ($onclick,$itemcount);
1.224 raeburn 10054: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10055: \%choices,$itemcount,$onclick);
1.228 raeburn 10056: $$rowtotal += $itemcount;
1.425 raeburn 10057:
1.224 raeburn 10058: if (ref($usertypes) eq 'HASH') {
10059: if (keys(%{$usertypes}) > 0) {
10060: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10061: $dom,$numinrow,$othertitle,
1.305 raeburn 10062: 'statustocreate',$rowtotal);
1.224 raeburn 10063: $$rowtotal ++;
10064: }
10065: }
1.240 raeburn 10066: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10067: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10068: $fieldtitles{'inststatus'} = &mt('Institutional status');
10069: my $rem;
10070: my $numperrow = 2;
10071: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10072: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10073: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10074: '<td class="LC_left_item">'."\n".
1.334 raeburn 10075: '<table>'."\n";
1.240 raeburn 10076: for (my $i=0; $i<@fields; $i++) {
10077: $rem = $i%($numperrow);
10078: if ($rem == 0) {
10079: if ($i > 0) {
10080: $datatable .= '</tr>';
10081: }
10082: $datatable .= '<tr>';
10083: }
10084: my $currval;
1.248 raeburn 10085: if (ref($createsettings) eq 'HASH') {
10086: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10087: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10088: }
1.240 raeburn 10089: }
10090: $datatable .= '<td class="LC_left_item">'.
10091: '<span class="LC_nobreak">'.
10092: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10093: 'value="'.$currval.'" size="10" /> '.
10094: $fieldtitles{$fields[$i]}.'</span></td>';
10095: }
10096: my $colsleft = $numperrow - $rem;
10097: if ($colsleft > 1 ) {
10098: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10099: ' </td>';
10100: } elsif ($colsleft == 1) {
10101: $datatable .= '<td class="LC_left_item"> </td>';
10102: }
10103: $datatable .= '</tr></table></td></tr>';
10104: $$rowtotal ++;
1.224 raeburn 10105: } elsif ($position eq 'middle') {
10106: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10107: my @posstypes;
1.224 raeburn 10108: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10109: @posstypes = @{$types};
10110: }
10111: unless (grep(/^default$/,@posstypes)) {
10112: push(@posstypes,'default');
10113: }
10114: my %usertypeshash;
10115: if (ref($usertypes) eq 'HASH') {
10116: %usertypeshash = %{$usertypes};
10117: }
10118: $usertypeshash{'default'} = $othertitle;
10119: foreach my $status (@posstypes) {
10120: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10121: $numinrow,$$rowtotal,\%usertypeshash);
10122: $$rowtotal ++;
1.224 raeburn 10123: }
10124: } else {
1.236 raeburn 10125: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10126: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10127: );
10128: my @toggles = sort(keys(%choices));
10129: my %defaultchecked = (
10130: 'cancreate_email' => 'off',
10131: );
1.305 raeburn 10132: my $customclass = 'LC_selfcreate_email';
10133: my $classprefix = 'LC_canmodify_emailusername_';
10134: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10135: my $display = 'none';
1.305 raeburn 10136: my $rowstyle = 'display:none';
1.236 raeburn 10137: if (grep(/^\Qemail\E$/,@selfcreate)) {
10138: $display = 'block';
1.305 raeburn 10139: $rowstyle = 'display:table-row';
1.236 raeburn 10140: }
1.305 raeburn 10141: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10142: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10143: \%choices,$$rowtotal,$onclick);
10144: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10145: $rowstyle);
10146: $$rowtotal ++;
10147: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10148: $rowstyle);
10149: $$rowtotal ++;
10150: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10151: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10152: my ($emailrules,$emailruleorder) =
10153: &Apache::lonnet::inst_userrules($dom,'email');
10154: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10155: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10156: if (ref($types) eq 'ARRAY') {
10157: @posstypes = @{$types};
10158: }
10159: if (@posstypes) {
10160: unless (grep(/^default$/,@posstypes)) {
10161: push(@posstypes,'default');
1.302 raeburn 10162: }
10163: if (ref($usertypes) eq 'HASH') {
10164: %usertypeshash = %{$usertypes};
10165: }
1.305 raeburn 10166: my $currassign;
10167: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10168: $currassign = {
10169: selfassign => $domdefaults{'inststatusguest'},
10170: };
10171: @ordered = @{$domdefaults{'inststatusguest'}};
10172: } else {
10173: $currassign = { selfassign => [] };
10174: }
10175: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10176: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10177: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10178: $numinrow,$othertitle,'selfassign',
10179: $rowtotal,$onclicktypes,$customclass,
10180: $rowstyle);
10181: $$rowtotal ++;
1.302 raeburn 10182: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10183: foreach my $status (@posstypes) {
10184: my $css_class;
10185: if ($$rowtotal%2) {
10186: $css_class = 'LC_odd_row ';
10187: }
10188: $css_class .= $customclass;
10189: my $rowid = $optionsprefix.$status;
10190: my $hidden = 1;
10191: my $currstyle = 'display:none';
10192: if (grep(/^\Q$status\E$/,@ordered)) {
10193: $currstyle = $rowstyle;
1.425 raeburn 10194: $hidden = 0;
1.305 raeburn 10195: }
10196: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10197: $emailrules,$emailruleorder,$settings,$status,$rowid,
10198: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10199: unless ($hidden) {
10200: $$rowtotal ++;
10201: }
1.224 raeburn 10202: }
1.302 raeburn 10203: } else {
1.305 raeburn 10204: my $css_class;
10205: if ($$rowtotal%2) {
10206: $css_class = 'LC_odd_row ';
10207: }
10208: $css_class .= $customclass;
1.302 raeburn 10209: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10210: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10211: $emailrules,$emailruleorder,$settings,'default','',
10212: $othertitle,$css_class,$rowstyle,$intdom);
10213: $$rowtotal ++;
1.224 raeburn 10214: }
10215: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10216: $numinrow = 1;
1.305 raeburn 10217: if (@posstypes) {
10218: foreach my $status (@posstypes) {
10219: my $rowid = $classprefix.$status;
10220: my $datarowstyle = 'display:none';
1.425 raeburn 10221: if (grep(/^\Q$status\E$/,@ordered)) {
10222: $datarowstyle = $rowstyle;
1.305 raeburn 10223: }
10224: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10225: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10226: $infotitles,$rowid,$customclass,$datarowstyle);
10227: unless ($datarowstyle eq 'display:none') {
10228: $$rowtotal ++;
10229: }
1.224 raeburn 10230: }
1.305 raeburn 10231: } else {
10232: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10233: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10234: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10235: }
10236: }
10237: return $datatable;
10238: }
10239:
1.305 raeburn 10240: sub selfcreate_javascript {
10241: return <<"ENDSCRIPT";
10242:
10243: <script type="text/javascript">
10244: // <![CDATA[
10245:
10246: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10247: var x = document.getElementsByClassName(target);
10248: var insttypes = 0;
10249: var insttypeRegExp = new RegExp(prefix);
10250: if ((x.length != undefined) && (x.length > 0)) {
10251: if (form.elements[radio].length != undefined) {
10252: for (var i=0; i<form.elements[radio].length; i++) {
10253: if (form.elements[radio][i].checked) {
10254: if (form.elements[radio][i].value == 1) {
10255: for (var j=0; j<x.length; j++) {
10256: if (x[j].id == 'undefined') {
10257: x[j].style.display = 'table-row';
10258: } else if (insttypeRegExp.test(x[j].id)) {
10259: insttypes ++;
10260: } else {
10261: x[j].style.display = 'table-row';
10262: }
10263: }
10264: } else {
10265: for (var j=0; j<x.length; j++) {
10266: x[j].style.display = 'none';
10267: }
1.236 raeburn 10268: }
1.305 raeburn 10269: break;
10270: }
10271: }
10272: if (insttypes > 0) {
10273: toggleDataRow(form,checkbox,target,altprefix);
10274: toggleDataRow(form,checkbox,target,prefix,1);
10275: }
10276: }
10277: }
10278: return;
10279: }
10280:
10281: function toggleDataRow(form,checkbox,target,prefix,docount) {
10282: if (form.elements[checkbox].length != undefined) {
10283: var count = 0;
10284: if (docount) {
10285: for (var i=0; i<form.elements[checkbox].length; i++) {
10286: if (form.elements[checkbox][i].checked) {
10287: count ++;
1.236 raeburn 10288: }
1.305 raeburn 10289: }
10290: }
10291: for (var i=0; i<form.elements[checkbox].length; i++) {
10292: var type = form.elements[checkbox][i].value;
10293: if (document.getElementById(prefix+type)) {
10294: if (form.elements[checkbox][i].checked) {
10295: document.getElementById(prefix+type).style.display = 'table-row';
10296: if (count % 2 == 1) {
10297: document.getElementById(prefix+type).className = target+' LC_odd_row';
10298: } else {
10299: document.getElementById(prefix+type).className = target;
1.236 raeburn 10300: }
1.305 raeburn 10301: count ++;
1.236 raeburn 10302: } else {
1.305 raeburn 10303: document.getElementById(prefix+type).style.display = 'none';
10304: }
10305: }
10306: }
10307: }
10308: return;
10309: }
10310:
10311: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10312: var caller = radio+'_'+status;
10313: if (form.elements[caller].length != undefined) {
10314: for (var i=0; i<form.elements[caller].length; i++) {
10315: if (form.elements[caller][i].checked) {
10316: if (document.getElementById(altprefix+'_inst_'+status)) {
10317: var curr = form.elements[caller][i].value;
10318: if (prefix) {
10319: document.getElementById(prefix+'_'+status).style.display = 'none';
10320: }
10321: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10322: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10323: if (curr == 'custom') {
1.425 raeburn 10324: if (prefix) {
1.305 raeburn 10325: document.getElementById(prefix+'_'+status).style.display = 'inline';
10326: }
10327: } else if (curr == 'inst') {
10328: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10329: } else if (curr == 'noninst') {
10330: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10331: }
1.305 raeburn 10332: break;
1.236 raeburn 10333: }
10334: }
10335: }
10336: }
10337: }
10338:
1.305 raeburn 10339: // ]]>
10340: </script>
10341:
10342: ENDSCRIPT
10343: }
10344:
10345: sub noninst_users {
10346: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10347: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10348: my $class = 'LC_left_item';
10349: if ($css_class) {
1.425 raeburn 10350: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10351: }
10352: if ($rowid) {
10353: $rowid = ' id="'.$rowid.'"';
10354: }
10355: if ($rowstyle) {
10356: $rowstyle = ' style="'.$rowstyle.'"';
10357: }
10358: my ($output,$description);
10359: if ($type eq 'default') {
10360: $description = &mt('Requests for: [_1]',$typetitle);
10361: } else {
10362: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10363: }
10364: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10365: "<td>$description</td>\n".
1.305 raeburn 10366: '<td class="'.$class.'" colspan="2">'.
10367: '<table><tr>';
1.425 raeburn 10368: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10369: approve => 'Processing',
10370: email => 'E-mail',
10371: username => 'Username',
10372: );
10373: foreach my $item ('approve','email','username') {
10374: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10375: }
1.305 raeburn 10376: $output .= '</tr><tr>';
10377: foreach my $item ('approve','email','username') {
1.306 raeburn 10378: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10379: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10380: if ($item eq 'approve') {
10381: %choices = &Apache::lonlocal::texthash (
10382: automatic => 'Automatically approved',
10383: approval => 'Queued for approval',
10384: );
10385: @options = ('automatic','approval');
10386: $hashref = $processing;
10387: $defoption = 'automatic';
10388: $name = 'cancreate_emailprocess_'.$type;
10389: } elsif ($item eq 'email') {
10390: %choices = &Apache::lonlocal::texthash (
10391: any => 'Any e-mail',
10392: inst => 'Institutional only',
10393: noninst => 'Non-institutional only',
10394: custom => 'Custom restrictions',
10395: );
10396: @options = ('any','inst','noninst');
10397: my $showcustom;
10398: if (ref($emailrules) eq 'HASH') {
10399: if (keys(%{$emailrules}) > 0) {
10400: push(@options,'custom');
10401: $showcustom = 'cancreate_emailrule';
10402: if (ref($settings) eq 'HASH') {
10403: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10404: foreach my $rule (@{$settings->{'email_rule'}}) {
10405: if (exists($emailrules->{$rule})) {
10406: $hascustom ++;
10407: }
10408: }
10409: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10410: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10411: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10412: if (exists($emailrules->{$rule})) {
10413: $hascustom ++;
10414: }
10415: }
10416: }
10417: }
10418: }
10419: }
10420: }
10421: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10422: "'cancreate_emaildomain','$type'".');"';
10423: $hashref = $emailoptions;
10424: $defoption = 'any';
10425: $name = 'cancreate_emailoptions_'.$type;
10426: } elsif ($item eq 'username') {
10427: %choices = &Apache::lonlocal::texthash (
10428: all => 'Same as e-mail',
10429: first => 'Omit @domain',
10430: free => 'Free to choose',
10431: );
10432: @options = ('all','first','free');
10433: $hashref = $emailverified;
10434: $defoption = 'all';
10435: $name = 'cancreate_usernameoptions_'.$type;
10436: }
10437: foreach my $option (@options) {
10438: my $checked;
10439: if (ref($hashref) eq 'HASH') {
10440: if ($type eq '') {
10441: if (!exists($hashref->{'default'})) {
10442: if ($option eq $defoption) {
10443: $checked = ' checked="checked"';
10444: }
10445: } else {
10446: if ($hashref->{'default'} eq $option) {
10447: $checked = ' checked="checked"';
10448: }
1.303 raeburn 10449: }
10450: } else {
1.305 raeburn 10451: if (!exists($hashref->{$type})) {
10452: if ($option eq $defoption) {
10453: $checked = ' checked="checked"';
10454: }
10455: } else {
10456: if ($hashref->{$type} eq $option) {
10457: $checked = ' checked="checked"';
10458: }
1.303 raeburn 10459: }
10460: }
1.305 raeburn 10461: } elsif (($item eq 'email') && ($hascustom)) {
10462: if ($option eq 'custom') {
10463: $checked = ' checked="checked"';
10464: }
10465: } elsif ($option eq $defoption) {
10466: $checked = ' checked="checked"';
10467: }
10468: $output .= '<span class="LC_nobreak"><label>'.
10469: '<input type="radio" name="'.$name.'"'.
10470: $checked.' value="'.$option.'"'.$onclick.' />'.
10471: $choices{$option}.'</label></span><br />';
10472: if ($item eq 'email') {
10473: if ($option eq 'custom') {
10474: my $id = 'cancreate_emailrule_'.$type;
10475: my $display = 'none';
10476: if ($checked) {
10477: $display = 'inline';
1.303 raeburn 10478: }
1.305 raeburn 10479: my $numinrow = 2;
10480: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10481: '<legend>'.&mt('Disallow').'</legend><table>'.
10482: &user_formats_row('email',$settings,$emailrules,
10483: $emailruleorder,$numinrow,'',$type);
10484: '</table></fieldset>';
10485: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10486: my %text = &Apache::lonlocal::texthash (
10487: inst => 'must end:',
10488: noninst => 'cannot end:',
10489: );
10490: my $value;
10491: if (ref($emaildomain) eq 'HASH') {
10492: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10493: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10494: }
10495: }
1.305 raeburn 10496: if ($value eq '') {
10497: $value = '@'.$intdom;
10498: }
10499: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10500: my $display = 'none';
10501: if ($checked) {
10502: $display = 'inline';
10503: }
10504: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10505: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10506: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10507: '</div>';
1.303 raeburn 10508: }
10509: }
10510: }
1.305 raeburn 10511: $output .= '</td>'."\n";
1.303 raeburn 10512: }
1.305 raeburn 10513: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10514: return $output;
10515: }
10516:
1.165 raeburn 10517: sub captcha_choice {
1.305 raeburn 10518: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10519: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10520: $vertext,$currver);
1.165 raeburn 10521: my %lt = &captcha_phrases();
10522: $keyentry = 'hidden';
1.354 raeburn 10523: my $colspan=2;
1.165 raeburn 10524: if ($context eq 'cancreate') {
1.224 raeburn 10525: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10526: } elsif ($context eq 'login') {
10527: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10528: } elsif ($context eq 'passwords') {
10529: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10530: $colspan=1;
1.165 raeburn 10531: }
10532: if (ref($settings) eq 'HASH') {
10533: if ($settings->{'captcha'}) {
10534: $checked{$settings->{'captcha'}} = ' checked="checked"';
10535: } else {
10536: $checked{'original'} = ' checked="checked"';
10537: }
10538: if ($settings->{'captcha'} eq 'recaptcha') {
10539: $pubtext = $lt{'pub'};
10540: $privtext = $lt{'priv'};
10541: $keyentry = 'text';
1.269 raeburn 10542: $vertext = $lt{'ver'};
10543: $currver = $settings->{'recaptchaversion'};
10544: if ($currver ne '2') {
10545: $currver = 1;
10546: }
1.165 raeburn 10547: }
10548: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10549: $currpub = $settings->{'recaptchakeys'}{'public'};
10550: $currpriv = $settings->{'recaptchakeys'}{'private'};
10551: }
10552: } else {
10553: $checked{'original'} = ' checked="checked"';
10554: }
1.305 raeburn 10555: my $css_class;
10556: if ($itemcount%2) {
10557: $css_class = 'LC_odd_row';
10558: }
10559: if ($customcss) {
10560: $css_class .= " $customcss";
10561: }
10562: $css_class =~ s/^\s+//;
10563: if ($css_class) {
10564: $css_class = ' class="'.$css_class.'"';
10565: }
10566: if ($rowstyle) {
10567: $css_class .= ' style="'.$rowstyle.'"';
10568: }
1.169 raeburn 10569: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10570: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10571: '<table><tr><td>'."\n";
10572: foreach my $option ('original','recaptcha','notused') {
10573: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10574: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10575: $lt{$option}.'</label></span>';
10576: unless ($option eq 'notused') {
10577: $output .= (' 'x2)."\n";
10578: }
10579: }
10580: #
10581: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10582: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10583: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10584: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10585: #
1.165 raeburn 10586: $output .= '</td></tr>'."\n".
1.305 raeburn 10587: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10588: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10589: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10590: $currpub.'" size="40" /></span><br />'."\n".
10591: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10592: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10593: $currpriv.'" size="40" /></span><br />'.
10594: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10595: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10596: $currver.'" size="3" /></span><br />'.
10597: '</td></tr></table>'."\n".
1.165 raeburn 10598: '</td></tr>';
10599: return $output;
10600: }
10601:
1.32 raeburn 10602: sub user_formats_row {
1.305 raeburn 10603: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10604: my $output;
10605: my %text = (
10606: 'username' => 'new usernames',
10607: 'id' => 'IDs',
10608: );
1.409 raeburn 10609: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10610: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10611: $output = '<tr '.$css_class.'>'.
10612: '<td><span class="LC_nobreak">'.
10613: &mt("Format rules to check for $text{$type}: ").
10614: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10615: }
1.27 raeburn 10616: my $rem;
10617: if (ref($ruleorder) eq 'ARRAY') {
10618: for (my $i=0; $i<@{$ruleorder}; $i++) {
10619: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10620: my $rem = $i%($numinrow);
10621: if ($rem == 0) {
10622: if ($i > 0) {
10623: $output .= '</tr>';
10624: }
10625: $output .= '<tr>';
10626: }
10627: my $check = ' ';
1.39 raeburn 10628: if (ref($settings) eq 'HASH') {
10629: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10630: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10631: $check = ' checked="checked" ';
10632: }
1.305 raeburn 10633: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10634: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10635: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10636: $check = ' checked="checked" ';
10637: }
10638: }
1.27 raeburn 10639: }
10640: }
1.305 raeburn 10641: my $name = $type.'_rule';
10642: if ($type eq 'email') {
10643: $name .= '_'.$status;
10644: }
1.27 raeburn 10645: $output .= '<td class="LC_left_item">'.
10646: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10647: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10648: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10649: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10650: }
10651: }
10652: $rem = @{$ruleorder}%($numinrow);
10653: }
1.305 raeburn 10654: my $colsleft;
10655: if ($rem) {
10656: $colsleft = $numinrow - $rem;
10657: }
1.27 raeburn 10658: if ($colsleft > 1 ) {
10659: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10660: ' </td>';
10661: } elsif ($colsleft == 1) {
10662: $output .= '<td class="LC_left_item"> </td>';
10663: }
1.409 raeburn 10664: $output .= '</tr>';
10665: unless (($type eq 'email') || ($type eq 'unamemap')) {
10666: $output .= '</table></td></tr>';
1.305 raeburn 10667: }
1.27 raeburn 10668: return $output;
10669: }
10670:
1.34 raeburn 10671: sub usercreation_types {
10672: my %lt = &Apache::lonlocal::texthash (
10673: author => 'When adding a co-author',
10674: course => 'When adding a user to a course',
1.100 raeburn 10675: requestcrs => 'When requesting a course',
1.34 raeburn 10676: any => 'Any',
10677: official => 'Institutional only ',
10678: unofficial => 'Non-institutional only',
10679: none => 'None',
10680: );
10681: return %lt;
1.48 raeburn 10682: }
1.34 raeburn 10683:
1.224 raeburn 10684: sub selfcreation_types {
10685: my %lt = &Apache::lonlocal::texthash (
10686: selfcreate => 'User creates own account',
10687: any => 'Any',
10688: official => 'Institutional only ',
10689: unofficial => 'Non-institutional only',
10690: email => 'E-mail address',
10691: login => 'Institutional Login',
10692: sso => 'SSO',
10693: );
10694: }
10695:
1.28 raeburn 10696: sub authtype_names {
10697: my %lt = &Apache::lonlocal::texthash(
10698: int => 'Internal',
10699: krb4 => 'Kerberos 4',
10700: krb5 => 'Kerberos 5',
10701: loc => 'Local',
1.325 raeburn 10702: lti => 'LTI',
1.28 raeburn 10703: );
10704: return %lt;
10705: }
10706:
10707: sub context_names {
10708: my %context_title = &Apache::lonlocal::texthash(
10709: author => 'Creating users when an Author',
10710: course => 'Creating users when in a course',
10711: domain => 'Creating users when a Domain Coordinator',
10712: );
10713: return %context_title;
10714: }
10715:
1.33 raeburn 10716: sub print_usermodification {
10717: my ($position,$dom,$settings,$rowtotal) = @_;
10718: my $numinrow = 4;
10719: my ($context,$datatable,$rowcount);
10720: if ($position eq 'top') {
10721: $rowcount = 0;
10722: $context = 'author';
10723: foreach my $role ('ca','aa') {
10724: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10725: $numinrow,$rowcount);
10726: $$rowtotal ++;
10727: $rowcount ++;
10728: }
1.443 ! raeburn 10729: } elsif ($position eq 'middle') {
! 10730: $rowcount = 0;
! 10731: $context = 'coauthor';
! 10732: foreach my $role ('ca','aa') {
! 10733: $datatable .= &modifiable_userdata_row($context,$role,$settings,
! 10734: $numinrow,$rowcount);
! 10735: $$rowtotal ++;
! 10736: $rowcount ++;
! 10737: }
1.230 raeburn 10738: } elsif ($position eq 'bottom') {
1.33 raeburn 10739: $context = 'course';
10740: $rowcount = 0;
10741: foreach my $role ('st','ep','ta','in','cr') {
10742: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10743: $numinrow,$rowcount);
10744: $$rowtotal ++;
10745: $rowcount ++;
10746: }
10747: }
10748: return $datatable;
10749: }
10750:
1.43 raeburn 10751: sub print_defaults {
1.236 raeburn 10752: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10753: my $rownum = 0;
1.294 raeburn 10754: my ($datatable,$css_class,$titles);
10755: unless ($position eq 'bottom') {
10756: $titles = &defaults_titles($dom);
10757: }
1.236 raeburn 10758: if ($position eq 'top') {
10759: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10760: 'datelocale_def','portal_def');
10761: my %defaults;
10762: if (ref($settings) eq 'HASH') {
10763: %defaults = %{$settings};
1.43 raeburn 10764: } else {
1.236 raeburn 10765: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10766: foreach my $item (@items) {
10767: $defaults{$item} = $domdefaults{$item};
10768: }
1.43 raeburn 10769: }
1.236 raeburn 10770: foreach my $item (@items) {
10771: if ($rownum%2) {
10772: $css_class = '';
10773: } else {
10774: $css_class = ' class="LC_odd_row" ';
10775: }
10776: $datatable .= '<tr'.$css_class.'>'.
10777: '<td><span class="LC_nobreak">'.$titles->{$item}.
10778: '</span></td><td class="LC_right_item" colspan="3">';
10779: if ($item eq 'auth_def') {
1.325 raeburn 10780: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10781: my %shortauth = (
10782: internal => 'int',
10783: krb4 => 'krb4',
10784: krb5 => 'krb5',
1.325 raeburn 10785: localauth => 'loc',
10786: lti => 'lti',
1.236 raeburn 10787: );
10788: my %authnames = &authtype_names();
10789: foreach my $auth (@authtypes) {
10790: my $checked = ' ';
10791: if ($defaults{$item} eq $auth) {
10792: $checked = ' checked="checked" ';
10793: }
10794: $datatable .= '<label><input type="radio" name="'.$item.
10795: '" value="'.$auth.'"'.$checked.'/>'.
10796: $authnames{$shortauth{$auth}}.'</label> ';
10797: }
10798: } elsif ($item eq 'timezone_def') {
10799: my $includeempty = 1;
10800: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10801: } elsif ($item eq 'datelocale_def') {
10802: my $includeempty = 1;
10803: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10804: } elsif ($item eq 'lang_def') {
1.263 raeburn 10805: my $includeempty = 1;
10806: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10807: } elsif ($item eq 'portal_def') {
10808: $datatable .= '<input type="text" name="'.$item.'" value="'.
10809: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10810: my $portalsty = 'none';
10811: if ($defaults{$item}) {
10812: $portalsty = 'block';
10813: }
10814: foreach my $field ('email','web') {
10815: my $checkedoff = ' checked="checked"';
10816: my $checkedon;
10817: if ($defaults{$item.'_'.$field}) {
10818: $checkedon = $checkedoff;
10819: $checkedoff = '';
1.425 raeburn 10820: }
1.414 raeburn 10821: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10822: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10823: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10824: (' 'x2).
10825: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10826: '</div>';
10827: }
1.236 raeburn 10828: } else {
1.414 raeburn 10829: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10830: }
1.236 raeburn 10831: $datatable .= '</td></tr>';
10832: $rownum ++;
10833: }
1.409 raeburn 10834: } elsif ($position eq 'middle') {
1.294 raeburn 10835: my %defaults;
10836: if (ref($settings) eq 'HASH') {
1.354 raeburn 10837: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10838: my $maxnum = @{$settings->{'inststatusorder'}};
10839: for (my $i=0; $i<$maxnum; $i++) {
10840: $css_class = $rownum%2?' class="LC_odd_row"':'';
10841: my $item = $settings->{'inststatusorder'}->[$i];
10842: my $title = $settings->{'inststatustypes'}->{$item};
10843: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10844: $datatable .= '<tr'.$css_class.'>'.
10845: '<td><span class="LC_nobreak">'.
10846: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10847: for (my $k=0; $k<=$maxnum; $k++) {
10848: my $vpos = $k+1;
10849: my $selstr;
10850: if ($k == $i) {
10851: $selstr = ' selected="selected" ';
10852: }
10853: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10854: }
10855: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10856: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10857: &mt('delete').'</span></td>'.
1.380 raeburn 10858: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10859: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10860: '</span></td></tr>';
10861: }
10862: $css_class = $rownum%2?' class="LC_odd_row"':'';
10863: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10864: $datatable .= '<tr '.$css_class.'>'.
10865: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10866: for (my $k=0; $k<=$maxnum; $k++) {
10867: my $vpos = $k+1;
10868: my $selstr;
10869: if ($k == $maxnum) {
10870: $selstr = ' selected="selected" ';
10871: }
10872: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10873: }
10874: $datatable .= '</select> '.&mt('Internal ID:').
10875: '<input type="text" size="10" name="addinststatus" value="" />'.
10876: ' '.&mt('(new)').
10877: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10878: &mt('Name displayed').':'.
1.354 raeburn 10879: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10880: '</tr>'."\n";
10881: $rownum ++;
1.294 raeburn 10882: }
1.354 raeburn 10883: }
1.409 raeburn 10884: } else {
10885: my ($unamemaprules,$ruleorder) =
10886: &Apache::lonnet::inst_userrules($dom,'unamemap');
10887: $css_class = $rownum%2?' class="LC_odd_row"':'';
10888: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10889: my $numinrow = 2;
10890: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10891: &user_formats_row('unamemap',$settings,$unamemaprules,
10892: $ruleorder,$numinrow).
10893: '</table></td></tr>';
10894: }
10895: if ($datatable eq '') {
10896: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10897: &mt('No rules set for domain in customized localenroll.pm').
10898: '</td></tr>';
10899: }
1.354 raeburn 10900: }
10901: $$rowtotal += $rownum;
1.43 raeburn 10902: return $datatable;
10903: }
10904:
1.168 raeburn 10905: sub get_languages_hash {
10906: my %langchoices;
10907: foreach my $id (&Apache::loncommon::languageids()) {
10908: my $code = &Apache::loncommon::supportedlanguagecode($id);
10909: if ($code ne '') {
10910: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10911: }
10912: }
10913: return %langchoices;
10914: }
10915:
1.43 raeburn 10916: sub defaults_titles {
1.141 raeburn 10917: my ($dom) = @_;
1.43 raeburn 10918: my %titles = &Apache::lonlocal::texthash (
10919: 'auth_def' => 'Default authentication type',
10920: 'auth_arg_def' => 'Default authentication argument',
10921: 'lang_def' => 'Default language',
1.54 raeburn 10922: 'timezone_def' => 'Default timezone',
1.68 raeburn 10923: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10924: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10925: 'email' => 'Email links use portal URL',
10926: 'web' => 'Public web links use portal URL',
1.294 raeburn 10927: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10928: 'intauth_check' => 'Check bcrypt cost if authenticated',
10929: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10930: );
1.141 raeburn 10931: if ($dom) {
10932: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10933: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10934: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10935: $protocol = 'http' if ($protocol ne 'https');
10936: if ($uint_dom) {
10937: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10938: $uint_dom);
10939: }
10940: }
1.43 raeburn 10941: return (\%titles);
10942: }
10943:
1.346 raeburn 10944: sub print_scantron {
10945: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10946: if ($position eq 'top') {
10947: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10948: } else {
10949: return &print_scantronconfig($dom,$settings,\$rowtotal);
10950: }
10951: }
10952:
10953: sub scantron_javascript {
10954: return <<"ENDSCRIPT";
10955:
10956: <script type="text/javascript">
10957: // <![CDATA[
10958:
10959: function toggleScantron(form) {
1.347 raeburn 10960: var csvfieldset = new Array();
1.346 raeburn 10961: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10962: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10963: }
10964: if (document.getElementById('scantroncsv_options')) {
10965: csvfieldset.push(document.getElementById('scantroncsv_options'));
10966: }
10967: if (csvfieldset.length) {
1.346 raeburn 10968: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10969: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10970: if (scantroncsv.checked) {
1.347 raeburn 10971: for (var i=0; i<csvfieldset.length; i++) {
10972: csvfieldset[i].style.display = 'block';
10973: }
1.346 raeburn 10974: } else {
1.347 raeburn 10975: for (var i=0; i<csvfieldset.length; i++) {
10976: csvfieldset[i].style.display = 'none';
10977: }
1.346 raeburn 10978: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10979: if (csvselects.length) {
10980: for (var j=0; j<csvselects.length; j++) {
10981: csvselects[j].selectedIndex = 0;
10982: }
10983: }
10984: }
10985: }
10986: }
10987: return;
10988: }
10989: // ]]>
10990: </script>
10991:
10992: ENDSCRIPT
10993:
10994: }
10995:
1.46 raeburn 10996: sub print_scantronformat {
10997: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10998: my $itemcount = 1;
1.60 raeburn 10999: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
11000: %confhash);
1.46 raeburn 11001: my $switchserver = &check_switchserver($dom,$confname);
11002: my %lt = &Apache::lonlocal::texthash (
1.95 www 11003: default => 'Default bubblesheet format file error',
11004: custom => 'Custom bubblesheet format file error',
1.46 raeburn 11005: );
11006: my %scantronfiles = (
11007: default => 'default.tab',
11008: custom => 'custom.tab',
11009: );
11010: foreach my $key (keys(%scantronfiles)) {
11011: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11012: .$scantronfiles{$key};
11013: }
11014: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11015: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11016: if (!$switchserver) {
11017: my $servadm = $r->dir_config('lonAdmEMail');
11018: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11019: if ($configuserok eq 'ok') {
11020: if ($author_ok eq 'ok') {
11021: my %legacyfile = (
1.346 raeburn 11022: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11023: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11024: );
11025: my %md5chk;
11026: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11027: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11028: chomp($md5chk{$type});
1.46 raeburn 11029: }
11030: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11031: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11032: ($scantronurls{$type},my $error) =
1.46 raeburn 11033: &legacy_scantronformat($r,$dom,$confname,
11034: $type,$legacyfile{$type},
11035: $scantronurls{$type},
11036: $scantronfiles{$type});
1.60 raeburn 11037: if ($error ne '') {
11038: $error{$type} = $error;
11039: }
11040: }
11041: if (keys(%error) == 0) {
11042: $is_custom = 1;
1.346 raeburn 11043: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11044: $scantronurls{'custom'};
1.346 raeburn 11045: my $putresult =
1.60 raeburn 11046: &Apache::lonnet::put_dom('configuration',
11047: \%confhash,$dom);
11048: if ($putresult ne 'ok') {
1.346 raeburn 11049: $error{'custom'} =
1.60 raeburn 11050: '<span class="LC_error">'.
11051: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11052: }
1.46 raeburn 11053: }
11054: } else {
1.60 raeburn 11055: ($scantronurls{'default'},my $error) =
1.46 raeburn 11056: &legacy_scantronformat($r,$dom,$confname,
11057: 'default',$legacyfile{'default'},
11058: $scantronurls{'default'},
11059: $scantronfiles{'default'});
1.60 raeburn 11060: if ($error eq '') {
11061: $confhash{'scantron'}{'scantronformat'} = '';
11062: my $putresult =
11063: &Apache::lonnet::put_dom('configuration',
11064: \%confhash,$dom);
11065: if ($putresult ne 'ok') {
11066: $error{'default'} =
11067: '<span class="LC_error">'.
11068: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11069: }
11070: } else {
11071: $error{'default'} = $error;
11072: }
1.46 raeburn 11073: }
11074: }
11075: }
11076: } else {
1.95 www 11077: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11078: }
11079: }
11080: if (ref($settings) eq 'HASH') {
11081: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11082: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11083: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11084: $scantronurl = '';
11085: } else {
11086: $scantronurl = $settings->{'scantronformat'};
11087: }
11088: $is_custom = 1;
11089: } else {
11090: $scantronurl = $scantronurls{'default'};
11091: }
11092: } else {
1.60 raeburn 11093: if ($is_custom) {
11094: $scantronurl = $scantronurls{'custom'};
11095: } else {
11096: $scantronurl = $scantronurls{'default'};
11097: }
1.46 raeburn 11098: }
11099: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11100: $datatable .= '<tr'.$css_class.'>';
11101: if (!$is_custom) {
1.65 raeburn 11102: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11103: '<span class="LC_nobreak">';
1.46 raeburn 11104: if ($scantronurl) {
1.199 raeburn 11105: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11106: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11107: } else {
11108: $datatable = &mt('File unavailable for display');
11109: }
1.65 raeburn 11110: $datatable .= '</span></td>';
1.60 raeburn 11111: if (keys(%error) == 0) {
1.306 raeburn 11112: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11113: if (!$switchserver) {
11114: $datatable .= &mt('Upload:').'<br />';
11115: }
11116: } else {
11117: my $errorstr;
11118: foreach my $key (sort(keys(%error))) {
11119: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11120: }
11121: $datatable .= '<td>'.$errorstr;
11122: }
1.46 raeburn 11123: } else {
11124: if (keys(%error) > 0) {
11125: my $errorstr;
11126: foreach my $key (sort(keys(%error))) {
11127: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11128: }
1.60 raeburn 11129: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11130: } elsif ($scantronurl) {
1.199 raeburn 11131: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11132: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11133: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11134: $link.
11135: '<label><input type="checkbox" name="scantronformat_del"'.
11136: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11137: '<td><span class="LC_nobreak"> '.
11138: &mt('Replace:').'</span><br />';
1.46 raeburn 11139: }
11140: }
11141: if (keys(%error) == 0) {
11142: if ($switchserver) {
11143: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11144: } else {
1.65 raeburn 11145: $datatable .='<span class="LC_nobreak"> '.
11146: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11147: }
11148: }
11149: $datatable .= '</td></tr>';
11150: $$rowtotal ++;
11151: return $datatable;
11152: }
11153:
11154: sub legacy_scantronformat {
11155: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11156: my ($url,$error);
11157: my @statinfo = &Apache::lonnet::stat_file($newurl);
11158: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11159: my $modified = [];
1.46 raeburn 11160: (my $result,$url) =
1.421 raeburn 11161: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11162: 'scantron','','',$newfile,$modified);
11163: if ($result eq 'ok') {
11164: &update_modify_urls($r,$modified);
11165: } else {
1.130 raeburn 11166: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11167: }
11168: }
11169: return ($url,$error);
11170: }
1.43 raeburn 11171:
1.346 raeburn 11172: sub print_scantronconfig {
11173: my ($dom,$settings,$rowtotal) = @_;
11174: my $itemcount = 2;
11175: my $is_checked = ' checked="checked"';
1.347 raeburn 11176: my %optionson = (
11177: hdr => ' checked="checked"',
11178: pad => ' checked="checked"',
11179: rem => ' checked="checked"',
11180: );
11181: my %optionsoff = (
11182: hdr => '',
11183: pad => '',
11184: rem => '',
11185: );
1.346 raeburn 11186: my $currcsvsty = 'none';
1.347 raeburn 11187: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11188: my @fields = &scantroncsv_fields();
11189: my %titles = &scantronconfig_titles();
11190: if (ref($settings) eq 'HASH') {
11191: if (ref($settings->{config}) eq 'HASH') {
11192: if ($settings->{config}->{dat}) {
11193: $checked{'dat'} = $is_checked;
11194: }
11195: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11196: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11197: %csvfields = %{$settings->{config}->{csv}->{fields}};
11198: if (keys(%csvfields) > 0) {
11199: $checked{'csv'} = $is_checked;
11200: $currcsvsty = 'block';
11201: }
11202: }
11203: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11204: %csvoptions = %{$settings->{config}->{csv}->{options}};
11205: foreach my $option (keys(%optionson)) {
11206: unless ($csvoptions{$option}) {
11207: $optionsoff{$option} = $optionson{$option};
11208: $optionson{$option} = '';
11209: }
11210: }
1.346 raeburn 11211: }
11212: }
11213: } else {
11214: $checked{'dat'} = $is_checked;
11215: }
11216: } else {
11217: $checked{'dat'} = $is_checked;
11218: }
11219: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11220: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11221: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11222: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11223: foreach my $item ('dat','csv') {
11224: my $id;
11225: if ($item eq 'csv') {
11226: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11227: }
1.346 raeburn 11228: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11229: $titles{$item}.'</label>'.(' 'x3);
11230: if ($item eq 'csv') {
11231: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11232: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11233: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11234: foreach my $col (@fields) {
11235: my $selnone;
11236: if ($csvfields{$col} eq '') {
11237: $selnone = ' selected="selected"';
11238: }
11239: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11240: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11241: '<option value=""'.$selnone.'></option>';
11242: for (my $i=0; $i<20; $i++) {
11243: my $shown = $i+1;
11244: my $sel;
11245: unless ($selnone) {
11246: if (exists($csvfields{$col})) {
11247: if ($csvfields{$col} == $i) {
11248: $sel = ' selected="selected"';
11249: }
11250: }
11251: }
11252: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11253: }
11254: $datatable .= '</select></td></tr>';
11255: }
1.347 raeburn 11256: $datatable .= '</table></fieldset>'.
11257: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11258: '<legend>'.&mt('CSV Options').'</legend>';
11259: foreach my $option ('hdr','pad','rem') {
11260: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11261: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11262: &mt('Yes').'</label>'.(' 'x2)."\n".
11263: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11264: }
11265: $datatable .= '</fieldset>';
1.346 raeburn 11266: $itemcount ++;
11267: }
11268: }
11269: $datatable .= '</td></tr>';
11270: $$rowtotal ++;
11271: return $datatable;
11272: }
11273:
11274: sub scantronconfig_titles {
11275: return &Apache::lonlocal::texthash(
11276: dat => 'Standard format (.dat)',
11277: csv => 'Comma separated values (.csv)',
1.347 raeburn 11278: hdr => 'Remove first line in file (contains column titles)',
11279: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11280: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11281: CODE => 'CODE',
11282: ID => 'Student ID',
11283: PaperID => 'Paper ID',
11284: FirstName => 'First Name',
11285: LastName => 'Last Name',
11286: FirstQuestion => 'First Question Response',
11287: Section => 'Section',
11288: );
11289: }
11290:
11291: sub scantroncsv_fields {
11292: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11293: }
11294:
1.49 raeburn 11295: sub print_coursecategories {
1.57 raeburn 11296: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11297: my $datatable;
11298: if ($position eq 'top') {
1.238 raeburn 11299: my (%checked);
11300: my @catitems = ('unauth','auth');
11301: my @cattypes = ('std','domonly','codesrch','none');
11302: $checked{'unauth'} = 'std';
11303: $checked{'auth'} = 'std';
11304: if (ref($settings) eq 'HASH') {
11305: foreach my $type (@cattypes) {
11306: if ($type eq $settings->{'unauth'}) {
11307: $checked{'unauth'} = $type;
11308: }
11309: if ($type eq $settings->{'auth'}) {
11310: $checked{'auth'} = $type;
11311: }
11312: }
11313: }
11314: my %lt = &Apache::lonlocal::texthash (
11315: unauth => 'Catalog type for unauthenticated users',
11316: auth => 'Catalog type for authenticated users',
11317: none => 'No catalog',
11318: std => 'Standard catalog',
11319: domonly => 'Domain-only catalog',
11320: codesrch => "Code search form",
11321: );
11322: my $itemcount = 0;
11323: foreach my $item (@catitems) {
11324: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11325: $datatable .= '<tr '.$css_class.'>'.
11326: '<td>'.$lt{$item}.'</td>'.
11327: '<td class="LC_right_item"><span class="LC_nobreak">';
11328: foreach my $type (@cattypes) {
11329: my $ischecked;
11330: if ($checked{$item} eq $type) {
11331: $ischecked=' checked="checked"';
11332: }
11333: $datatable .= '<label>'.
11334: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11335: ' />'.$lt{$type}.'</label> ';
11336: }
1.327 raeburn 11337: $datatable .= '</span></td></tr>';
1.238 raeburn 11338: $itemcount ++;
11339: }
11340: $$rowtotal += $itemcount;
11341: } elsif ($position eq 'middle') {
1.57 raeburn 11342: my $toggle_cats_crs = ' ';
11343: my $toggle_cats_dom = ' checked="checked" ';
11344: my $can_cat_crs = ' ';
11345: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11346: my $toggle_catscomm_comm = ' ';
11347: my $toggle_catscomm_dom = ' checked="checked" ';
11348: my $can_catcomm_comm = ' ';
11349: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11350: my $toggle_catsplace_place = ' ';
11351: my $toggle_catsplace_dom = ' checked="checked" ';
11352: my $can_catplace_place = ' ';
11353: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11354:
1.57 raeburn 11355: if (ref($settings) eq 'HASH') {
11356: if ($settings->{'togglecats'} eq 'crs') {
11357: $toggle_cats_crs = $toggle_cats_dom;
11358: $toggle_cats_dom = ' ';
11359: }
11360: if ($settings->{'categorize'} eq 'crs') {
11361: $can_cat_crs = $can_cat_dom;
11362: $can_cat_dom = ' ';
11363: }
1.120 raeburn 11364: if ($settings->{'togglecatscomm'} eq 'comm') {
11365: $toggle_catscomm_comm = $toggle_catscomm_dom;
11366: $toggle_catscomm_dom = ' ';
11367: }
11368: if ($settings->{'categorizecomm'} eq 'comm') {
11369: $can_catcomm_comm = $can_catcomm_dom;
11370: $can_catcomm_dom = ' ';
11371: }
1.272 raeburn 11372: if ($settings->{'togglecatsplace'} eq 'place') {
11373: $toggle_catsplace_place = $toggle_catsplace_dom;
11374: $toggle_catsplace_dom = ' ';
11375: }
11376: if ($settings->{'categorizeplace'} eq 'place') {
11377: $can_catplace_place = $can_catplace_dom;
11378: $can_catplace_dom = ' ';
11379: }
1.57 raeburn 11380: }
11381: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11382: togglecats => 'Show/Hide a course in catalog',
11383: togglecatscomm => 'Show/Hide a community in catalog',
11384: togglecatsplace => 'Show/Hide a placement test in catalog',
11385: categorize => 'Assign a category to a course',
11386: categorizecomm => 'Assign a category to a community',
11387: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11388: );
11389: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11390: dom => 'Set in Domain',
11391: crs => 'Set in Course',
11392: comm => 'Set in Community',
11393: place => 'Set in Placement Test',
1.57 raeburn 11394: );
11395: $datatable = '<tr class="LC_odd_row">'.
11396: '<td>'.$title{'togglecats'}.'</td>'.
11397: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11398: '<input type="radio" name="togglecats"'.
11399: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11400: '<label><input type="radio" name="togglecats"'.
11401: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11402: '</tr><tr>'.
11403: '<td>'.$title{'categorize'}.'</td>'.
11404: '<td class="LC_right_item"><span class="LC_nobreak">'.
11405: '<label><input type="radio" name="categorize"'.
11406: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11407: '<label><input type="radio" name="categorize"'.
11408: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11409: '</tr><tr class="LC_odd_row">'.
11410: '<td>'.$title{'togglecatscomm'}.'</td>'.
11411: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11412: '<input type="radio" name="togglecatscomm"'.
11413: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11414: '<label><input type="radio" name="togglecatscomm"'.
11415: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11416: '</tr><tr>'.
11417: '<td>'.$title{'categorizecomm'}.'</td>'.
11418: '<td class="LC_right_item"><span class="LC_nobreak">'.
11419: '<label><input type="radio" name="categorizecomm"'.
11420: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11421: '<label><input type="radio" name="categorizecomm"'.
11422: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11423: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11424: '<td>'.$title{'togglecatsplace'}.'</td>'.
11425: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11426: '<input type="radio" name="togglecatsplace"'.
11427: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11428: '<label><input type="radio" name="togglecatscomm"'.
11429: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11430: '</tr><tr>'.
11431: '<td>'.$title{'categorizeplace'}.'</td>'.
11432: '<td class="LC_right_item"><span class="LC_nobreak">'.
11433: '<label><input type="radio" name="categorizeplace"'.
11434: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11435: '<label><input type="radio" name="categorizeplace"'.
11436: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11437: '</tr>';
1.272 raeburn 11438: $$rowtotal += 6;
1.57 raeburn 11439: } else {
11440: my $css_class;
11441: my $itemcount = 1;
11442: my $cathash;
11443: if (ref($settings) eq 'HASH') {
11444: $cathash = $settings->{'cats'};
11445: }
11446: if (ref($cathash) eq 'HASH') {
11447: my (@cats,@trails,%allitems,%idx,@jsarray);
11448: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11449: \%allitems,\%idx,\@jsarray);
11450: my $maxdepth = scalar(@cats);
11451: my $colattrib = '';
11452: if ($maxdepth > 2) {
11453: $colattrib = ' colspan="2" ';
11454: }
11455: my @path;
11456: if (@cats > 0) {
11457: if (ref($cats[0]) eq 'ARRAY') {
11458: my $numtop = @{$cats[0]};
11459: my $maxnum = $numtop;
1.120 raeburn 11460: my %default_names = (
11461: instcode => &mt('Official courses'),
11462: communities => &mt('Communities'),
1.272 raeburn 11463: placement => &mt('Placement Tests'),
1.120 raeburn 11464: );
11465:
11466: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11467: ($cathash->{'instcode::0'} eq '') ||
11468: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11469: ($cathash->{'communities::0'} eq '') ||
11470: (!grep(/^placement$/,@{$cats[0]})) ||
11471: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11472: $maxnum ++;
11473: }
11474: my $lastidx;
11475: for (my $i=0; $i<$numtop; $i++) {
11476: my $parent = $cats[0][$i];
11477: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11478: my $item = &escape($parent).'::0';
11479: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11480: $lastidx = $idx{$item};
11481: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11482: .'<select name="'.$item.'"'.$chgstr.'>';
11483: for (my $k=0; $k<=$maxnum; $k++) {
11484: my $vpos = $k+1;
11485: my $selstr;
11486: if ($k == $i) {
11487: $selstr = ' selected="selected" ';
11488: }
11489: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11490: }
1.214 raeburn 11491: $datatable .= '</select></span></td><td>';
1.272 raeburn 11492: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11493: $datatable .= '<span class="LC_nobreak">'
11494: .$default_names{$parent}.'</span>';
11495: if ($parent eq 'instcode') {
11496: $datatable .= '<br /><span class="LC_nobreak">('
11497: .&mt('with institutional codes')
11498: .')</span></td><td'.$colattrib.'>';
11499: } else {
11500: $datatable .= '<table><tr><td>';
11501: }
11502: $datatable .= '<span class="LC_nobreak">'
11503: .'<label><input type="radio" name="'
11504: .$parent.'" value="1" checked="checked" />'
11505: .&mt('Display').'</label>';
11506: if ($parent eq 'instcode') {
11507: $datatable .= ' ';
11508: } else {
11509: $datatable .= '</span></td></tr><tr><td>'
11510: .'<span class="LC_nobreak">';
11511: }
11512: $datatable .= '<label><input type="radio" name="'
11513: .$parent.'" value="0" />'
11514: .&mt('Do not display').'</label></span>';
1.272 raeburn 11515: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11516: $datatable .= '</td></tr></table>';
11517: }
11518: $datatable .= '</td>';
1.57 raeburn 11519: } else {
11520: $datatable .= $parent
1.214 raeburn 11521: .' <span class="LC_nobreak"><label>'
11522: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11523: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11524: }
11525: my $depth = 1;
11526: push(@path,$parent);
11527: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11528: pop(@path);
11529: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11530: $itemcount ++;
11531: }
1.48 raeburn 11532: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11533: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11534: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11535: for (my $k=0; $k<=$maxnum; $k++) {
11536: my $vpos = $k+1;
11537: my $selstr;
1.57 raeburn 11538: if ($k == $numtop) {
1.48 raeburn 11539: $selstr = ' selected="selected" ';
11540: }
11541: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11542: }
1.59 bisitz 11543: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11544: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11545: .'</tr>'."\n";
1.48 raeburn 11546: $itemcount ++;
1.272 raeburn 11547: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11548: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11549: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11550: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11551: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11552: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11553: for (my $k=0; $k<=$maxnum; $k++) {
11554: my $vpos = $k+1;
11555: my $selstr;
11556: if ($k == $maxnum) {
11557: $selstr = ' selected="selected" ';
11558: }
11559: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11560: }
1.120 raeburn 11561: $datatable .= '</select></span></td>'.
11562: '<td><span class="LC_nobreak">'.
11563: $default_names{$default}.'</span>';
11564: if ($default eq 'instcode') {
11565: $datatable .= '<br /><span class="LC_nobreak">('
11566: .&mt('with institutional codes').')</span>';
11567: }
11568: $datatable .= '</td>'
11569: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11570: .&mt('Display').'</label> '
11571: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11572: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11573: }
11574: }
11575: }
1.57 raeburn 11576: } else {
11577: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11578: }
11579: } else {
1.327 raeburn 11580: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11581: .&initialize_categories($itemcount);
1.48 raeburn 11582: }
1.57 raeburn 11583: $$rowtotal += $itemcount;
1.48 raeburn 11584: }
11585: return $datatable;
11586: }
11587:
1.69 raeburn 11588: sub print_serverstatuses {
11589: my ($dom,$settings,$rowtotal) = @_;
11590: my $datatable;
11591: my @pages = &serverstatus_pages();
11592: my (%namedaccess,%machineaccess);
11593: foreach my $type (@pages) {
11594: $namedaccess{$type} = '';
11595: $machineaccess{$type}= '';
11596: }
11597: if (ref($settings) eq 'HASH') {
11598: foreach my $type (@pages) {
11599: if (exists($settings->{$type})) {
11600: if (ref($settings->{$type}) eq 'HASH') {
11601: foreach my $key (keys(%{$settings->{$type}})) {
11602: if ($key eq 'namedusers') {
11603: $namedaccess{$type} = $settings->{$type}->{$key};
11604: } elsif ($key eq 'machines') {
11605: $machineaccess{$type} = $settings->{$type}->{$key};
11606: }
11607: }
11608: }
11609: }
11610: }
11611: }
1.81 raeburn 11612: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11613: my $rownum = 0;
11614: my $css_class;
11615: foreach my $type (@pages) {
11616: $rownum ++;
11617: $css_class = $rownum%2?' class="LC_odd_row"':'';
11618: $datatable .= '<tr'.$css_class.'>'.
11619: '<td><span class="LC_nobreak">'.
11620: $titles->{$type}.'</span></td>'.
11621: '<td class="LC_left_item">'.
11622: '<input type="text" name="'.$type.'_namedusers" '.
11623: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11624: '<td class="LC_right_item">'.
11625: '<span class="LC_nobreak">'.
11626: '<input type="text" name="'.$type.'_machines" '.
11627: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11628: '</span></td></tr>'."\n";
1.69 raeburn 11629: }
11630: $$rowtotal += $rownum;
11631: return $datatable;
11632: }
11633:
11634: sub serverstatus_pages {
11635: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11636: 'checksums','clusterstatus','certstatus','metadata_keywords',
11637: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11638: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11639: }
11640:
1.236 raeburn 11641: sub defaults_javascript {
11642: my ($settings) = @_;
1.354 raeburn 11643: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11644: my $portal_js = <<"ENDPORTAL";
11645:
11646: function portalExtras(caller) {
11647: var x = caller.value;
11648: var y = new Array('email','web');
1.425 raeburn 11649: for (var i=0; i<y.length; i++) {
1.414 raeburn 11650: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11651: var z = document.getElementById('portal_def_'+y[i]+'_div');
11652: if (x.length > 0) {
11653: z.style.display = 'block';
11654: } else {
11655: z.style.display = 'none';
11656: }
11657: }
11658: }
11659: }
11660: ENDPORTAL
1.236 raeburn 11661: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11662: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11663: if ($maxnum eq '') {
11664: $maxnum = 0;
11665: }
11666: $maxnum ++;
1.249 raeburn 11667: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11668: return <<"ENDSCRIPT";
11669: <script type="text/javascript">
11670: // <![CDATA[
11671: function reorderTypes(form,caller) {
11672: var changedVal;
11673: $jstext
11674: var newpos = 'addinststatus_pos';
11675: var current = new Array;
11676: var maxh = $maxnum;
11677: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11678: var oldVal;
11679: if (caller == newpos) {
11680: changedVal = newitemVal;
11681: } else {
11682: var curritem = 'inststatus_pos_'+caller;
11683: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11684: current[newitemVal] = newpos;
11685: }
11686: for (var i=0; i<inststatuses.length; i++) {
11687: if (inststatuses[i] != caller) {
11688: var elementName = 'inststatus_pos_'+inststatuses[i];
11689: if (form.elements[elementName]) {
11690: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11691: current[currVal] = elementName;
11692: }
11693: }
11694: }
11695: for (var j=0; j<maxh; j++) {
11696: if (current[j] == undefined) {
11697: oldVal = j;
11698: }
11699: }
11700: if (oldVal < changedVal) {
11701: for (var k=oldVal+1; k<=changedVal ; k++) {
11702: var elementName = current[k];
11703: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11704: }
11705: } else {
11706: for (var k=changedVal; k<oldVal; k++) {
11707: var elementName = current[k];
11708: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11709: }
11710: }
11711: return;
11712: }
11713:
1.414 raeburn 11714: $portal_js
11715:
11716: // ]]>
11717: </script>
11718:
11719: ENDSCRIPT
11720: } else {
11721: return <<"ENDSCRIPT";
11722: <script type="text/javascript">
11723: // <![CDATA[
11724: $portal_js
1.236 raeburn 11725: // ]]>
11726: </script>
11727:
11728: ENDSCRIPT
11729: }
1.354 raeburn 11730: return;
11731: }
11732:
11733: sub passwords_javascript {
1.405 raeburn 11734: my ($prefix) = @_;
11735: my %intalert;
11736: if ($prefix eq 'passwords') {
11737: %intalert = &Apache::lonlocal::texthash (
11738: 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.',
11739: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11740: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11741: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11742: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11743: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11744: );
1.421 raeburn 11745: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11746: %intalert = &Apache::lonlocal::texthash (
11747: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11748: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11749: );
11750: }
1.365 raeburn 11751: &js_escape(\%intalert);
11752: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11753: my $intauthjs;
1.405 raeburn 11754: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11755:
11756: function warnIntAuth(field) {
11757: if (field.name == 'intauth_check') {
11758: if (field.value == '2') {
1.365 raeburn 11759: alert('$intalert{authcheck}');
1.354 raeburn 11760: }
11761: }
11762: if (field.name == 'intauth_cost') {
11763: field.value.replace(/\s/g,'');
11764: if (field.value != '') {
11765: var regexdigit=/^\\d+\$/;
11766: if (!regexdigit.test(field.value)) {
1.365 raeburn 11767: alert('$intalert{authcost}');
11768: }
11769: }
11770: }
11771: return;
11772: }
11773:
1.405 raeburn 11774: ENDSCRIPT
11775:
11776: }
11777:
11778: $intauthjs .= <<"ENDSCRIPT";
11779:
11780: function warnInt$prefix(field) {
1.365 raeburn 11781: field.value.replace(/^\s+/,'');
11782: field.value.replace(/\s+\$/,'');
11783: var regexdigit=/^\\d+\$/;
1.408 raeburn 11784: if (field.name == '${prefix}_min') {
1.365 raeburn 11785: if (field.value == '') {
11786: alert('$intalert{passmin}');
11787: field.value = '$defmin';
11788: } else {
11789: if (!regexdigit.test(field.value)) {
11790: alert('$intalert{passmin}');
11791: field.value = '$defmin';
11792: }
1.366 raeburn 11793: var minval = parseInt(field.value,10);
1.365 raeburn 11794: if (minval < $defmin) {
11795: alert('$intalert{passmin}');
11796: field.value = '$defmin';
11797: }
11798: }
11799: } else {
11800: if (field.value == '0') {
11801: field.value = '';
11802: }
11803: if (field.value != '') {
1.408 raeburn 11804: if (field.name == '${prefix}_expire') {
1.365 raeburn 11805: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11806: if (!regexpposnum.test(field.value)) {
11807: alert('$intalert{passexp}');
11808: field.value = '';
11809: } else {
11810: var expval = parseFloat(field.value);
11811: if (expval == 0) {
11812: alert('$intalert{passexp}');
11813: field.value = '';
11814: }
11815: }
11816: } else {
11817: if (!regexdigit.test(field.value)) {
1.408 raeburn 11818: if (field.name == '${prefix}_max') {
1.365 raeburn 11819: alert('$intalert{passmax}');
11820: } else {
1.408 raeburn 11821: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11822: alert('$intalert{passnum}');
11823: }
11824: }
1.370 raeburn 11825: field.value = '';
1.365 raeburn 11826: }
1.354 raeburn 11827: }
11828: }
11829: }
11830: return;
11831: }
11832:
11833: ENDSCRIPT
11834: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11835: }
11836:
1.49 raeburn 11837: sub coursecategories_javascript {
11838: my ($settings) = @_;
1.57 raeburn 11839: my ($output,$jstext,$cathash);
1.49 raeburn 11840: if (ref($settings) eq 'HASH') {
1.57 raeburn 11841: $cathash = $settings->{'cats'};
11842: }
11843: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11844: my (@cats,@jsarray,%idx);
1.57 raeburn 11845: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11846: if (@jsarray > 0) {
11847: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11848: for (my $i=0; $i<@jsarray; $i++) {
11849: if (ref($jsarray[$i]) eq 'ARRAY') {
11850: my $catstr = join('","',@{$jsarray[$i]});
11851: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11852: }
11853: }
11854: }
11855: } else {
11856: $jstext = ' var categories = Array(1);'."\n".
11857: ' categories[0] = Array("instcode_pos");'."\n";
11858: }
1.237 bisitz 11859: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11860: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11861: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11862: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11863: &js_escape(\$instcode_reserved);
11864: &js_escape(\$communities_reserved);
1.272 raeburn 11865: &js_escape(\$placement_reserved);
1.265 damieng 11866: &js_escape(\$choose_again);
1.49 raeburn 11867: $output = <<"ENDSCRIPT";
11868: <script type="text/javascript">
1.109 raeburn 11869: // <![CDATA[
1.49 raeburn 11870: function reorderCats(form,parent,item,idx) {
11871: var changedVal;
11872: $jstext
11873: var newpos = 'addcategory_pos';
11874: if (parent == '') {
11875: var has_instcode = 0;
11876: var maxtop = categories[idx].length;
11877: for (var j=0; j<maxtop; j++) {
11878: if (categories[idx][j] == 'instcode::0') {
11879: has_instcode == 1;
11880: }
11881: }
11882: if (has_instcode == 0) {
11883: categories[idx][maxtop] = 'instcode_pos';
11884: }
11885: } else {
11886: newpos += '_'+parent;
11887: }
11888: var maxh = 1 + categories[idx].length;
11889: var current = new Array;
11890: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11891: if (item == newpos) {
11892: changedVal = newitemVal;
11893: } else {
11894: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11895: current[newitemVal] = newpos;
11896: }
11897: for (var i=0; i<categories[idx].length; i++) {
11898: var elementName = categories[idx][i];
11899: if (elementName != item) {
11900: if (form.elements[elementName]) {
11901: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11902: current[currVal] = elementName;
11903: }
11904: }
11905: }
11906: var oldVal;
11907: for (var j=0; j<maxh; j++) {
11908: if (current[j] == undefined) {
11909: oldVal = j;
11910: }
11911: }
11912: if (oldVal < changedVal) {
11913: for (var k=oldVal+1; k<=changedVal ; k++) {
11914: var elementName = current[k];
11915: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11916: }
11917: } else {
11918: for (var k=changedVal; k<oldVal; k++) {
11919: var elementName = current[k];
11920: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11921: }
11922: }
11923: return;
11924: }
1.120 raeburn 11925:
11926: function categoryCheck(form) {
11927: if (form.elements['addcategory_name'].value == 'instcode') {
11928: alert('$instcode_reserved\\n$choose_again');
11929: return false;
11930: }
11931: if (form.elements['addcategory_name'].value == 'communities') {
11932: alert('$communities_reserved\\n$choose_again');
11933: return false;
11934: }
1.272 raeburn 11935: if (form.elements['addcategory_name'].value == 'placement') {
11936: alert('$placement_reserved\\n$choose_again');
11937: return false;
11938: }
1.120 raeburn 11939: return true;
11940: }
11941:
1.109 raeburn 11942: // ]]>
1.49 raeburn 11943: </script>
11944:
11945: ENDSCRIPT
11946: return $output;
11947: }
11948:
1.48 raeburn 11949: sub initialize_categories {
11950: my ($itemcount) = @_;
1.120 raeburn 11951: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11952: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11953: instcode => 'Official courses (with institutional codes)',
11954: communities => 'Communities',
1.272 raeburn 11955: placement => 'Placement Tests',
1.120 raeburn 11956: );
1.328 raeburn 11957: my %selnum = (
11958: instcode => '0',
11959: communities => '1',
11960: placement => '2',
11961: );
11962: my %selected;
1.272 raeburn 11963: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11964: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11965: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11966: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11967: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11968: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11969: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11970: .'<option value="0"'.$selected{'0'}.'>1</option>'
11971: .'<option value="1"'.$selected{'1'}.'>2</option>'
11972: .'<option value="2"'.$selected{'2'}.'>3</option>'
11973: .'<option value="3">4</option></select> '
1.120 raeburn 11974: .$default_names{$default}
11975: .'</span></td><td><span class="LC_nobreak">'
11976: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11977: .&mt('Display').'</label> <label>'
11978: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11979: .'</label></span></td></tr>';
1.120 raeburn 11980: $itemcount ++;
11981: }
1.48 raeburn 11982: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11983: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11984: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11985: .'<select name="addcategory_pos"'.$chgstr.'>'
11986: .'<option value="0">1</option>'
11987: .'<option value="1">2</option>'
1.328 raeburn 11988: .'<option value="2">3</option>'
11989: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11990: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11991: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11992: .'</td></tr>';
1.48 raeburn 11993: return $datatable;
11994: }
11995:
11996: sub build_category_rows {
1.49 raeburn 11997: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11998: my ($text,$name,$item,$chgstr);
1.48 raeburn 11999: if (ref($cats) eq 'ARRAY') {
12000: my $maxdepth = scalar(@{$cats});
12001: if (ref($cats->[$depth]) eq 'HASH') {
12002: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
12003: my $numchildren = @{$cats->[$depth]{$parent}};
12004: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 12005: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 12006: my ($idxnum,$parent_name,$parent_item);
12007: my $higher = $depth - 1;
12008: if ($higher == 0) {
12009: $parent_name = &escape($parent).'::'.$higher;
12010: } else {
12011: if (ref($path) eq 'ARRAY') {
12012: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12013: }
12014: }
12015: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12016: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12017: if ($j < $numchildren) {
1.48 raeburn 12018: $name = $cats->[$depth]{$parent}[$j];
12019: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12020: $idxnum = $idx->{$item};
12021: } else {
12022: $name = $parent_name;
12023: $item = $parent_item;
1.48 raeburn 12024: }
1.49 raeburn 12025: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12026: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12027: for (my $i=0; $i<=$numchildren; $i++) {
12028: my $vpos = $i+1;
12029: my $selstr;
12030: if ($j == $i) {
12031: $selstr = ' selected="selected" ';
12032: }
12033: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12034: }
12035: $text .= '</select> ';
12036: if ($j < $numchildren) {
12037: my $deeper = $depth+1;
12038: $text .= $name.' '
12039: .'<label><input type="checkbox" name="deletecategory" value="'
12040: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12041: if(ref($path) eq 'ARRAY') {
12042: push(@{$path},$name);
1.49 raeburn 12043: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12044: pop(@{$path});
12045: }
12046: } else {
1.330 raeburn 12047: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12048: if ($j == $numchildren) {
12049: $text .= $name;
12050: } else {
12051: $text .= $item;
12052: }
12053: $text .= '" value="" />';
12054: }
12055: $text .= '</td></tr>';
12056: }
12057: $text .= '</table></td>';
12058: } else {
12059: my $higher = $depth-1;
12060: if ($higher == 0) {
12061: $name = &escape($parent).'::'.$higher;
12062: } else {
12063: if (ref($path) eq 'ARRAY') {
12064: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12065: }
12066: }
12067: my $colspan;
12068: if ($parent ne 'instcode') {
12069: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12070: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12071: }
12072: }
12073: }
12074: }
12075: return $text;
12076: }
12077:
1.33 raeburn 12078: sub modifiable_userdata_row {
1.305 raeburn 12079: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12080: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12081: my ($role,$rolename,$statustype);
12082: $role = $item;
1.224 raeburn 12083: if ($context eq 'cancreate') {
1.305 raeburn 12084: if ($item =~ /^(emailusername)_(.+)$/) {
12085: $role = $1;
12086: $statustype = $2;
1.228 raeburn 12087: if (ref($usertypes) eq 'HASH') {
12088: if ($usertypes->{$statustype}) {
12089: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12090: } else {
12091: $rolename = &mt('Data provided by user');
12092: }
12093: }
1.224 raeburn 12094: }
12095: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12096: if (ref($usertypes) eq 'HASH') {
12097: $rolename = $usertypes->{$role};
12098: } else {
12099: $rolename = $role;
12100: }
1.325 raeburn 12101: } elsif ($context eq 'lti') {
12102: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12103: } elsif ($context eq 'privacy') {
12104: $rolename = $itemdesc;
1.33 raeburn 12105: } else {
1.63 raeburn 12106: if ($role eq 'cr') {
12107: $rolename = &mt('Custom role');
12108: } else {
12109: $rolename = &Apache::lonnet::plaintext($role);
12110: }
1.33 raeburn 12111: }
1.224 raeburn 12112: my (@fields,%fieldtitles);
12113: if (ref($fieldsref) eq 'ARRAY') {
12114: @fields = @{$fieldsref};
12115: } else {
12116: @fields = ('lastname','firstname','middlename','generation',
12117: 'permanentemail','id');
12118: }
12119: if ((ref($titlesref) eq 'HASH')) {
12120: %fieldtitles = %{$titlesref};
12121: } else {
12122: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12123: }
1.33 raeburn 12124: my $output;
1.305 raeburn 12125: my $css_class;
12126: if ($rowcount%2) {
12127: $css_class = 'LC_odd_row';
12128: }
12129: if ($customcss) {
12130: $css_class .= " $customcss";
12131: }
12132: $css_class =~ s/^\s+//;
12133: if ($css_class) {
12134: $css_class = ' class="'.$css_class.'"';
12135: }
12136: if ($rowstyle) {
12137: $css_class .= ' style="'.$rowstyle.'"';
12138: }
12139: if ($rowid) {
12140: $rowid = ' id="'.$rowid.'"';
12141: }
12142: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12143: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12144: '<td class="LC_left_item" colspan="2"><table>';
12145: my $rem;
12146: my %checks;
12147: if (ref($settings) eq 'HASH') {
1.325 raeburn 12148: my $hashref;
12149: if ($context eq 'lti') {
12150: if (ref($settings) eq 'HASH') {
12151: $hashref = $settings->{'instdata'};
12152: }
1.357 raeburn 12153: } elsif ($context eq 'privacy') {
12154: my ($key,$inner) = split(/_/,$role);
12155: if (ref($settings) eq 'HASH') {
12156: if (ref($settings->{$key}) eq 'HASH') {
12157: $hashref = $settings->{$key}->{$inner};
12158: }
12159: }
1.325 raeburn 12160: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12161: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12162: $hashref = $settings->{'lti_instdata'};
12163: }
12164: if ($role eq 'emailusername') {
12165: if ($statustype) {
12166: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12167: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12168: }
1.325 raeburn 12169: }
12170: }
12171: }
1.425 raeburn 12172: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12173: foreach my $field (@fields) {
12174: if ($hashref->{$field}) {
12175: if ($role eq 'emailusername') {
12176: $checks{$field} = $hashref->{$field};
12177: } else {
12178: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12179: }
12180: }
12181: }
12182: }
12183: }
1.305 raeburn 12184: my $total = scalar(@fields);
12185: for (my $i=0; $i<$total; $i++) {
12186: $rem = $i%($numinrow);
1.33 raeburn 12187: if ($rem == 0) {
12188: if ($i > 0) {
12189: $output .= '</tr>';
12190: }
12191: $output .= '<tr>';
12192: }
12193: my $check = ' ';
1.228 raeburn 12194: unless ($role eq 'emailusername') {
12195: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12196: $check = $checks{$fields[$i]};
1.357 raeburn 12197: } elsif ($context eq 'privacy') {
12198: if ($role =~ /^priv_(domain|course)$/) {
12199: if (ref($settings) ne 'HASH') {
12200: $check = ' checked="checked" ';
12201: }
12202: } elsif ($role =~ /^priv_(author|community)$/) {
12203: if (ref($settings) ne 'HASH') {
12204: unless ($fields[$i] eq 'id') {
12205: $check = ' checked="checked" ';
12206: }
12207: }
12208: } elsif ($role =~ /^(unpriv|othdom)_/) {
12209: if (ref($settings) ne 'HASH') {
12210: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12211: $check = ' checked="checked" ';
12212: }
12213: }
12214: }
1.325 raeburn 12215: } elsif ($context ne 'lti') {
1.228 raeburn 12216: if ($role eq 'st') {
12217: if (ref($settings) ne 'HASH') {
12218: $check = ' checked="checked" ';
12219: }
1.33 raeburn 12220: }
12221: }
12222: }
12223: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12224: '<span class="LC_nobreak">';
1.325 raeburn 12225: my $prefix = 'canmodify';
1.228 raeburn 12226: if ($role eq 'emailusername') {
12227: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12228: $checks{$fields[$i]} = 'omit';
12229: }
12230: foreach my $option ('required','optional','omit') {
12231: my $checked='';
12232: if ($checks{$fields[$i]} eq $option) {
12233: $checked='checked="checked" ';
12234: }
12235: $output .= '<label>'.
1.325 raeburn 12236: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12237: &mt($option).'</label>'.(' ' x2);
12238: }
12239: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12240: } else {
1.325 raeburn 12241: if ($context eq 'lti') {
12242: $prefix = 'lti';
1.443 ! raeburn 12243: } elsif ($context eq 'coauthor') {
! 12244: $prefix = 'cacanmodify';
1.357 raeburn 12245: } elsif ($context eq 'privacy') {
12246: $prefix = 'privacy';
1.325 raeburn 12247: }
1.228 raeburn 12248: $output .= '<label>'.
1.325 raeburn 12249: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12250: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12251: '</label>';
12252: }
12253: $output .= '</span></td>';
1.33 raeburn 12254: }
1.305 raeburn 12255: $rem = $total%$numinrow;
12256: my $colsleft;
12257: if ($rem) {
12258: $colsleft = $numinrow - $rem;
12259: }
12260: if ($colsleft > 1) {
1.33 raeburn 12261: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12262: ' </td>';
12263: } elsif ($colsleft == 1) {
12264: $output .= '<td class="LC_left_item"> </td>';
12265: }
12266: $output .= '</tr></table></td></tr>';
12267: return $output;
12268: }
1.28 raeburn 12269:
1.93 raeburn 12270: sub insttypes_row {
1.305 raeburn 12271: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12272: $customcss,$rowstyle) = @_;
1.93 raeburn 12273: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12274: cansearch => 'Users allowed to search',
1.93 raeburn 12275: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12276: lockablenames => 'User preference to lock name',
12277: selfassign => 'Self-reportable affiliations',
12278: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12279: webdav => 'WebDAV access available',
12280: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12281: );
1.429 raeburn 12282: my ($showdom,$defaultquota);
1.93 raeburn 12283: if ($context eq 'cansearch') {
12284: $showdom = ' ('.$dom.')';
1.429 raeburn 12285: } elsif ($context eq 'authorquota') {
12286: $defaultquota = 500;
1.93 raeburn 12287: }
1.165 raeburn 12288: my $class = 'LC_left_item';
12289: if ($context eq 'statustocreate') {
12290: $class = 'LC_right_item';
12291: }
1.305 raeburn 12292: my $css_class;
12293: if ($$rowtotal%2) {
12294: $css_class = 'LC_odd_row';
12295: }
12296: if ($customcss) {
12297: $css_class .= ' '.$customcss;
12298: }
12299: $css_class =~ s/^\s+//;
12300: if ($css_class) {
12301: $css_class = ' class="'.$css_class.'"';
12302: }
12303: if ($rowstyle) {
12304: $css_class .= ' style="'.$rowstyle.'"';
12305: }
12306: if ($onclick) {
12307: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12308: }
12309: my $output = '<tr'.$css_class.'>'.
12310: '<td>'.$lt{$context}.$showdom.
12311: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12312: my $rem;
12313: if (ref($types) eq 'ARRAY') {
12314: for (my $i=0; $i<@{$types}; $i++) {
12315: if (defined($usertypes->{$types->[$i]})) {
12316: my $rem = $i%($numinrow);
12317: if ($rem == 0) {
12318: if ($i > 0) {
12319: $output .= '</tr>';
12320: }
12321: $output .= '<tr>';
1.23 raeburn 12322: }
1.429 raeburn 12323: if ($context eq 'authorquota') {
12324: my $currquota;
12325: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12326: $currquota = $settings->{$context}->{$types->[$i]};
12327: } else {
12328: $currquota = $defaultquota;
12329: }
12330: $output .= '<td class="LC_left_item">'."\n".
12331: '<label><span class="LC_nobreak">'."\n".
12332: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12333: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12334: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12335: '</label></td>';
12336: } else {
12337: my $check = ' ';
12338: if (ref($settings) eq 'HASH') {
12339: if (ref($settings->{$context}) eq 'ARRAY') {
12340: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12341: $check = ' checked="checked" ';
12342: }
12343: } elsif (ref($settings->{$context}) eq 'HASH') {
12344: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12345: $check = ' checked="checked" ';
12346: } elsif ($context eq 'webdav') {
12347: if ($settings->{$context}->{$types->[$i]}) {
12348: $check = ' checked="checked" ';
12349: }
12350: }
12351: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12352: $check = ' checked="checked" ';
12353: }
1.26 raeburn 12354: }
1.429 raeburn 12355: $output .= '<td class="LC_left_item">'.
12356: '<span class="LC_nobreak"><label>'.
12357: '<input type="checkbox" name="'.$context.'" '.
12358: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12359: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12360: }
12361: }
12362: }
1.26 raeburn 12363: $rem = @{$types}%($numinrow);
1.23 raeburn 12364: }
12365: my $colsleft = $numinrow - $rem;
1.315 raeburn 12366: if ($context eq 'overrides') {
12367: if ($colsleft > 1) {
12368: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12369: } else {
12370: $output .= '<td class="LC_left_item">';
12371: }
1.425 raeburn 12372: $output .= ' ';
1.23 raeburn 12373: } else {
1.334 raeburn 12374: if ($rem == 0) {
1.315 raeburn 12375: $output .= '<tr>';
12376: }
12377: if ($colsleft > 1) {
12378: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12379: } else {
12380: $output .= '<td class="LC_left_item">';
12381: }
1.429 raeburn 12382: if ($context eq 'authorquota') {
12383: my $currquota = 500;
12384: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12385: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12386: $currquota = $settings->{$context}{'default'};
12387: }
12388: }
12389: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12390: '<input type="text" name="'.$context.'_default" '.
12391: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12392: '</label>';
12393: } else {
12394: my $defcheck = ' ';
12395: if (ref($settings) eq 'HASH') {
12396: if (ref($settings->{$context}) eq 'ARRAY') {
12397: if (grep(/^default$/,@{$settings->{$context}})) {
12398: $defcheck = ' checked="checked" ';
12399: }
12400: } elsif (ref($settings->{$context}) eq 'HASH') {
12401: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12402: $defcheck = ' checked="checked" ';
12403: } elsif ($context eq 'webdav') {
12404: if ($settings->{$context}->{'default'}) {
12405: $defcheck = ' checked="checked" ';
12406: }
12407: }
12408: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12409: $defcheck = ' checked="checked" ';
12410: }
1.99 raeburn 12411: }
1.429 raeburn 12412: $output .= '<span class="LC_nobreak"><label>'.
12413: '<input type="checkbox" name="'.$context.'" '.
12414: 'value="default"'.$defcheck.$onclick.'/>'.
12415: $othertitle.'</label></span>';
1.26 raeburn 12416: }
1.23 raeburn 12417: }
1.315 raeburn 12418: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12419: return $output;
1.23 raeburn 12420: }
12421:
12422: sub sorted_searchtitles {
12423: my %searchtitles = &Apache::lonlocal::texthash(
12424: 'uname' => 'username',
12425: 'lastname' => 'last name',
12426: 'lastfirst' => 'last name, first name',
12427: );
12428: my @titleorder = ('uname','lastname','lastfirst');
12429: return (\%searchtitles,\@titleorder);
12430: }
12431:
1.25 raeburn 12432: sub sorted_searchtypes {
12433: my %srchtypes_desc = (
12434: exact => 'is exact match',
12435: contains => 'contains ..',
12436: begins => 'begins with ..',
12437: );
12438: my @srchtypeorder = ('exact','begins','contains');
12439: return (\%srchtypes_desc,\@srchtypeorder);
12440: }
12441:
1.3 raeburn 12442: sub usertype_update_row {
12443: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12444: my $datatable;
12445: my $numinrow = 4;
12446: foreach my $type (@{$types}) {
12447: if (defined($usertypes->{$type})) {
12448: $$rownums ++;
12449: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12450: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12451: '</td><td class="LC_left_item"><table>';
12452: for (my $i=0; $i<@{$fields}; $i++) {
12453: my $rem = $i%($numinrow);
12454: if ($rem == 0) {
12455: if ($i > 0) {
12456: $datatable .= '</tr>';
12457: }
12458: $datatable .= '<tr>';
12459: }
12460: my $check = ' ';
1.39 raeburn 12461: if (ref($settings) eq 'HASH') {
12462: if (ref($settings->{'fields'}) eq 'HASH') {
12463: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12464: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12465: $check = ' checked="checked" ';
12466: }
1.3 raeburn 12467: }
12468: }
12469: }
12470:
12471: if ($i == @{$fields}-1) {
12472: my $colsleft = $numinrow - $rem;
12473: if ($colsleft > 1) {
12474: $datatable .= '<td colspan="'.$colsleft.'">';
12475: } else {
12476: $datatable .= '<td>';
12477: }
12478: } else {
12479: $datatable .= '<td>';
12480: }
1.8 raeburn 12481: $datatable .= '<span class="LC_nobreak"><label>'.
12482: '<input type="checkbox" name="updateable_'.$type.
12483: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12484: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12485: }
12486: $datatable .= '</tr></table></td></tr>';
12487: }
12488: }
12489: return $datatable;
1.1 raeburn 12490: }
12491:
12492: sub modify_login {
1.205 raeburn 12493: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12494: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12495: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12496: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12497: %title = ( coursecatalog => 'Display course catalog',
12498: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12499: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12500: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12501: loginheader => 'Log-in box header',
12502: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12503: @offon = ('off','on');
1.112 raeburn 12504: if (ref($domconfig{login}) eq 'HASH') {
12505: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12506: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12507: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12508: }
12509: }
1.386 raeburn 12510: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12511: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12512: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12513: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12514: $saml{$lonhost} = 1;
12515: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12516: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12517: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12518: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12519: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12520: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12521: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12522: }
12523: }
12524: }
1.112 raeburn 12525: }
1.9 raeburn 12526: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12527: \%domconfig,\%loginhash);
1.188 raeburn 12528: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12529: foreach my $item (@toggles) {
12530: $loginhash{login}{$item} = $env{'form.'.$item};
12531: }
1.41 raeburn 12532: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12533: if (ref($colchanges{'login'}) eq 'HASH') {
12534: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12535: \%loginhash);
12536: }
1.110 raeburn 12537:
1.149 raeburn 12538: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12539: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12540: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12541: if (keys(%servers) > 1) {
12542: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12543: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12544: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12545: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12546: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12547: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12548: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12549: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12550: $changes{'loginvia'}{$lonhost} = 1;
12551: } else {
12552: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12553: $changes{'loginvia'}{$lonhost} = 1;
12554: }
12555: } else {
12556: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12557: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12558: $changes{'loginvia'}{$lonhost} = 1;
12559: }
12560: }
12561: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12562: foreach my $item (@loginvia_attribs) {
12563: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12564: }
12565: } else {
12566: foreach my $item (@loginvia_attribs) {
12567: my $new = $env{'form.'.$lonhost.'_'.$item};
12568: if (($item eq 'serverpath') && ($new eq 'custom')) {
12569: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12570: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12571: $new = '/';
12572: }
12573: }
12574: if (($item eq 'custompath') &&
12575: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12576: $new = '';
12577: }
12578: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12579: $changes{'loginvia'}{$lonhost} = 1;
12580: }
12581: if ($item eq 'exempt') {
1.256 raeburn 12582: $new = &check_exempt_addresses($new);
1.128 raeburn 12583: }
12584: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12585: }
12586: }
1.112 raeburn 12587: } else {
1.128 raeburn 12588: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12589: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12590: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12591: foreach my $item (@loginvia_attribs) {
12592: my $new = $env{'form.'.$lonhost.'_'.$item};
12593: if (($item eq 'serverpath') && ($new eq 'custom')) {
12594: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12595: $new = '/';
12596: }
12597: }
12598: if (($item eq 'custompath') &&
12599: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12600: $new = '';
12601: }
12602: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12603: }
1.110 raeburn 12604: }
12605: }
12606: }
12607: }
1.119 raeburn 12608:
1.168 raeburn 12609: my $servadm = $r->dir_config('lonAdmEMail');
12610: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12611: if (ref($domconfig{'login'}) eq 'HASH') {
12612: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12613: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12614: if ($lang eq 'nolang') {
12615: push(@currlangs,$lang);
12616: } elsif (defined($langchoices{$lang})) {
12617: push(@currlangs,$lang);
12618: } else {
12619: next;
12620: }
12621: }
12622: }
12623: }
12624: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12625: if (@currlangs > 0) {
12626: foreach my $lang (@currlangs) {
12627: if (grep(/^\Q$lang\E$/,@delurls)) {
12628: $changes{'helpurl'}{$lang} = 1;
12629: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12630: $changes{'helpurl'}{$lang} = 1;
12631: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12632: push(@newlangs,$lang);
12633: } else {
12634: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12635: }
12636: }
12637: }
12638: unless (grep(/^nolang$/,@currlangs)) {
12639: if ($env{'form.loginhelpurl_nolang.filename'}) {
12640: $changes{'helpurl'}{'nolang'} = 1;
12641: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12642: push(@newlangs,'nolang');
12643: }
12644: }
12645: if ($env{'form.loginhelpurl_add_lang'}) {
12646: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12647: ($env{'form.loginhelpurl_add_file.filename'})) {
12648: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12649: $addedfile = $env{'form.loginhelpurl_add_lang'};
12650: }
12651: }
12652: if ((@newlangs > 0) || ($addedfile)) {
12653: my $error;
12654: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12655: if ($configuserok eq 'ok') {
12656: if ($switchserver) {
12657: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12658: } elsif ($author_ok eq 'ok') {
12659: my @allnew = @newlangs;
12660: if ($addedfile ne '') {
12661: push(@allnew,$addedfile);
12662: }
1.421 raeburn 12663: my $modified = [];
1.168 raeburn 12664: foreach my $lang (@allnew) {
12665: my $formelem = 'loginhelpurl_'.$lang;
12666: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12667: $formelem = 'loginhelpurl_add_file';
12668: }
1.425 raeburn 12669: (my $result,$newurl{$lang}) =
1.421 raeburn 12670: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12671: "help/$lang",'','',$newfile{$lang},
12672: $modified);
1.168 raeburn 12673: if ($result eq 'ok') {
12674: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12675: $changes{'helpurl'}{$lang} = 1;
12676: } else {
12677: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12678: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12679: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12680: (!grep(/^\Q$lang\E$/,@delurls))) {
12681: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12682: }
12683: }
12684: }
1.421 raeburn 12685: &update_modify_urls($r,$modified);
1.168 raeburn 12686: } else {
12687: $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);
12688: }
12689: } else {
12690: $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);
12691: }
12692: if ($error) {
12693: &Apache::lonnet::logthis($error);
12694: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12695: }
12696: }
1.256 raeburn 12697:
12698: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12699: if (ref($domconfig{'login'}) eq 'HASH') {
12700: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12701: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12702: if ($domservers{$lonhost}) {
12703: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12704: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12705: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12706: }
12707: }
12708: }
12709: }
12710: }
12711: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12712: foreach my $lonhost (sort(keys(%domservers))) {
12713: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12714: $changes{'headtag'}{$lonhost} = 1;
12715: } else {
12716: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12717: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12718: }
12719: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12720: push(@newhosts,$lonhost);
12721: } elsif ($currheadtagurls{$lonhost}) {
12722: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12723: if ($currexempt{$lonhost}) {
1.289 raeburn 12724: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12725: $changes{'headtag'}{$lonhost} = 1;
12726: }
12727: } elsif ($possexempt{$lonhost}) {
12728: $changes{'headtag'}{$lonhost} = 1;
12729: }
12730: if ($possexempt{$lonhost}) {
12731: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12732: }
12733: }
12734: }
12735: }
12736: if (@newhosts) {
12737: my $error;
12738: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12739: if ($configuserok eq 'ok') {
12740: if ($switchserver) {
12741: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12742: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12743: my $modified = [];
1.256 raeburn 12744: foreach my $lonhost (@newhosts) {
12745: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12746: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12747: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12748: "login/headtag/$lonhost",'','',
12749: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12750: $modified);
1.256 raeburn 12751: if ($result eq 'ok') {
12752: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12753: $changes{'headtag'}{$lonhost} = 1;
12754: if ($possexempt{$lonhost}) {
12755: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12756: }
12757: } else {
12758: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12759: $newheadtagurls{$lonhost},$result);
12760: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12761: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12762: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12763: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12764: }
12765: }
12766: }
1.421 raeburn 12767: &update_modify_urls($r,$modified);
1.256 raeburn 12768: } else {
12769: $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);
12770: }
12771: } else {
12772: $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);
12773: }
12774: if ($error) {
12775: &Apache::lonnet::logthis($error);
12776: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12777: }
12778: }
1.386 raeburn 12779: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12780: my @newsamlimgs;
12781: foreach my $lonhost (keys(%domservers)) {
12782: if ($env{'form.saml_'.$lonhost}) {
12783: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12784: push(@newsamlimgs,$lonhost);
12785: }
1.412 raeburn 12786: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12787: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12788: }
12789: if ($saml{$lonhost}) {
1.412 raeburn 12790: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12791: $env{'form.saml_window_'.$lonhost} = '';
12792: }
1.386 raeburn 12793: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12794: #FIXME Need to obsolete published image
12795: delete($currsaml{$lonhost}{'img'});
12796: $changes{'saml'}{$lonhost} = 1;
12797: }
12798: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12799: $changes{'saml'}{$lonhost} = 1;
12800: }
12801: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12802: $changes{'saml'}{$lonhost} = 1;
12803: }
12804: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12805: $changes{'saml'}{$lonhost} = 1;
12806: }
12807: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12808: $changes{'saml'}{$lonhost} = 1;
12809: }
1.412 raeburn 12810: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12811: $changes{'saml'}{$lonhost} = 1;
12812: }
1.386 raeburn 12813: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12814: $changes{'saml'}{$lonhost} = 1;
12815: }
12816: } else {
12817: $changes{'saml'}{$lonhost} = 1;
12818: }
1.412 raeburn 12819: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12820: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12821: }
12822: } else {
1.425 raeburn 12823: if ($saml{$lonhost}) {
1.389 raeburn 12824: $changes{'saml'}{$lonhost} = 1;
12825: delete($currsaml{$lonhost});
12826: }
1.386 raeburn 12827: }
12828: }
12829: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12830: unless (exists($domservers{$posshost})) {
12831: delete($currsaml{$posshost});
1.386 raeburn 12832: }
12833: }
12834: %{$loginhash{'login'}{'saml'}} = %currsaml;
12835: if (@newsamlimgs) {
12836: my $error;
12837: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12838: if ($configuserok eq 'ok') {
12839: if ($switchserver) {
12840: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12841: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12842: my $modified = [];
1.386 raeburn 12843: foreach my $lonhost (@newsamlimgs) {
12844: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12845: my ($result,$imgurl) =
1.421 raeburn 12846: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12847: "login/saml/$lonhost",'','',
12848: $env{'form.saml_img_'.$lonhost.'.filename'},
12849: $modified);
1.386 raeburn 12850: if ($result eq 'ok') {
12851: $currsaml{$lonhost}{'img'} = $imgurl;
12852: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12853: $changes{'saml'}{$lonhost} = 1;
12854: } else {
12855: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12856: $lonhost,$result);
12857: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12858: }
12859: }
1.421 raeburn 12860: &update_modify_urls($r,$modified);
1.386 raeburn 12861: } else {
12862: $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);
12863: }
12864: } else {
12865: $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);
12866: }
12867: if ($error) {
12868: &Apache::lonnet::logthis($error);
12869: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12870: }
12871: }
1.169 raeburn 12872: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12873:
12874: my $defaulthelpfile = '/adm/loginproblems.html';
12875: my $defaulttext = &mt('Default in use');
12876:
1.1 raeburn 12877: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12878: $dom);
12879: if ($putresult eq 'ok') {
1.188 raeburn 12880: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12881: my %defaultchecked = (
12882: 'coursecatalog' => 'on',
1.188 raeburn 12883: 'helpdesk' => 'on',
1.42 raeburn 12884: 'adminmail' => 'off',
1.43 raeburn 12885: 'newuser' => 'off',
1.42 raeburn 12886: );
1.55 raeburn 12887: if (ref($domconfig{'login'}) eq 'HASH') {
12888: foreach my $item (@toggles) {
12889: if ($defaultchecked{$item} eq 'on') {
12890: if (($domconfig{'login'}{$item} eq '0') &&
12891: ($env{'form.'.$item} eq '1')) {
12892: $changes{$item} = 1;
12893: } elsif (($domconfig{'login'}{$item} eq '' ||
12894: $domconfig{'login'}{$item} eq '1') &&
12895: ($env{'form.'.$item} eq '0')) {
12896: $changes{$item} = 1;
12897: }
12898: } elsif ($defaultchecked{$item} eq 'off') {
12899: if (($domconfig{'login'}{$item} eq '1') &&
12900: ($env{'form.'.$item} eq '0')) {
12901: $changes{$item} = 1;
12902: } elsif (($domconfig{'login'}{$item} eq '' ||
12903: $domconfig{'login'}{$item} eq '0') &&
12904: ($env{'form.'.$item} eq '1')) {
12905: $changes{$item} = 1;
12906: }
1.42 raeburn 12907: }
12908: }
1.41 raeburn 12909: }
1.6 raeburn 12910: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12911: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12912: if (exists($changes{'saml'})) {
12913: my $hostid_in_use;
12914: my @hosts = &Apache::lonnet::current_machine_ids();
12915: if (@hosts > 1) {
12916: foreach my $hostid (@hosts) {
12917: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12918: $hostid_in_use = $hostid;
12919: last;
12920: }
12921: }
12922: } else {
12923: $hostid_in_use = $r->dir_config('lonHostID');
12924: }
12925: if (($hostid_in_use) &&
12926: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12927: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12928: }
12929: if (ref($lastactref) eq 'HASH') {
12930: if (ref($changes{'saml'}) eq 'HASH') {
12931: my %updates;
12932: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12933: $lastactref->{'samllanding'} = \%updates;
12934: }
12935: }
12936: }
1.212 raeburn 12937: if (ref($lastactref) eq 'HASH') {
12938: $lastactref->{'domainconfig'} = 1;
12939: }
1.1 raeburn 12940: $resulttext = &mt('Changes made:').'<ul>';
12941: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12942: if ($item eq 'loginvia') {
1.112 raeburn 12943: if (ref($changes{$item}) eq 'HASH') {
12944: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12945: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12946: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12947: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12948: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12949: $protocol = 'http' if ($protocol ne 'https');
12950: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12951:
12952: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12953: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12954: } else {
12955: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12956: }
12957: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12958: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12959: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12960: }
12961: $resulttext .= '</li>';
12962: } else {
12963: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12964: }
1.112 raeburn 12965: } else {
1.128 raeburn 12966: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12967: }
12968: }
1.128 raeburn 12969: $resulttext .= '</ul></li>';
1.112 raeburn 12970: }
1.168 raeburn 12971: } elsif ($item eq 'helpurl') {
12972: if (ref($changes{$item}) eq 'HASH') {
12973: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12974: if (grep(/^\Q$lang\E$/,@delurls)) {
12975: my ($chg,$link);
12976: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12977: if ($lang eq 'nolang') {
12978: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12979: } else {
12980: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12981: }
12982: $resulttext .= '<li>'.$chg.'</li>';
12983: } else {
12984: my $chg;
12985: if ($lang eq 'nolang') {
12986: $chg = &mt('custom log-in help file for no preferred language');
12987: } else {
12988: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12989: }
12990: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12991: $loginhash{'login'}{'helpurl'}{$lang}.
12992: '?inhibitmenu=yes',$chg,600,500).
12993: '</li>';
12994: }
12995: }
12996: }
1.256 raeburn 12997: } elsif ($item eq 'headtag') {
12998: if (ref($changes{$item}) eq 'HASH') {
12999: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13000: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
13001: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
13002: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
13003: $resulttext .= '<li><a href="'.
13004: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
13005: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
13006: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
13007: if ($possexempt{$lonhost}) {
13008: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
13009: } else {
13010: $resulttext .= &mt('included for any client IP');
13011: }
13012: $resulttext .= '</li>';
13013: }
13014: }
13015: }
1.386 raeburn 13016: } elsif ($item eq 'saml') {
13017: if (ref($changes{$item}) eq 'HASH') {
13018: my %notlt = (
13019: text => 'Text for log-in by SSO',
13020: img => 'SSO button image',
13021: alt => 'Alt text for button image',
13022: url => 'SSO URL',
13023: title => 'Tooltip for SSO link',
1.412 raeburn 13024: window => 'Pop-up window if iframe',
1.386 raeburn 13025: notsso => 'Text for non-SSO log-in',
13026: );
13027: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13028: if (ref($currsaml{$lonhost}) eq 'HASH') {
13029: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13030: '<ul>';
1.412 raeburn 13031: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13032: if ($currsaml{$lonhost}{$key} eq '') {
13033: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13034: } else {
13035: my $value = "'$currsaml{$lonhost}{$key}'";
13036: if ($key eq 'img') {
13037: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13038: } elsif ($key eq 'window') {
13039: $value = 'On';
1.386 raeburn 13040: }
13041: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13042: $value).'</li>';
13043: }
13044: }
13045: $resulttext .= '</ul></li>';
13046: } else {
13047: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13048: }
13049: }
13050: }
1.169 raeburn 13051: } elsif ($item eq 'captcha') {
13052: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13053: my $chgtxt;
1.169 raeburn 13054: if ($loginhash{'login'}{$item} eq 'notused') {
13055: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13056: } else {
13057: my %captchas = &captcha_phrases();
13058: if ($captchas{$loginhash{'login'}{$item}}) {
13059: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13060: } else {
13061: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13062: }
13063: }
13064: $resulttext .= '<li>'.$chgtxt.'</li>';
13065: }
13066: } elsif ($item eq 'recaptchakeys') {
13067: if (ref($loginhash{'login'}) eq 'HASH') {
13068: my ($privkey,$pubkey);
13069: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13070: $pubkey = $loginhash{'login'}{$item}{'public'};
13071: $privkey = $loginhash{'login'}{$item}{'private'};
13072: }
13073: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13074: if (!$pubkey) {
13075: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13076: } else {
13077: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13078: }
13079: if (!$privkey) {
13080: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13081: } else {
1.251 raeburn 13082: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13083: }
13084: $chgtxt .= '</ul>';
13085: $resulttext .= '<li>'.$chgtxt.'</li>';
13086: }
1.269 raeburn 13087: } elsif ($item eq 'recaptchaversion') {
13088: if (ref($loginhash{'login'}) eq 'HASH') {
13089: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13090: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13091: '</li>';
13092: }
13093: }
1.41 raeburn 13094: } else {
13095: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13096: }
1.1 raeburn 13097: }
1.6 raeburn 13098: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13099: } else {
13100: $resulttext = &mt('No changes made to log-in page settings');
13101: }
13102: } else {
1.11 albertel 13103: $resulttext = '<span class="LC_error">'.
13104: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13105: }
1.6 raeburn 13106: if ($errors) {
1.9 raeburn 13107: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13108: $errors.'</ul>';
13109: }
13110: return $resulttext;
13111: }
13112:
1.256 raeburn 13113: sub check_exempt_addresses {
13114: my ($iplist) = @_;
13115: $iplist =~ s/^\s+//;
13116: $iplist =~ s/\s+$//;
13117: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13118: my (@okips,$new);
13119: foreach my $ip (@poss_ips) {
13120: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13121: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13122: push(@okips,$ip);
13123: }
13124: }
13125: }
13126: if (@okips > 0) {
13127: $new = join(',',@okips);
13128: } else {
13129: $new = '';
13130: }
13131: return $new;
13132: }
13133:
1.6 raeburn 13134: sub color_font_choices {
13135: my %choices =
13136: &Apache::lonlocal::texthash (
13137: img => "Header",
13138: bgs => "Background colors",
13139: links => "Link colors",
1.55 raeburn 13140: images => "Images",
1.6 raeburn 13141: font => "Font color",
1.201 raeburn 13142: fontmenu => "Font menu",
1.76 raeburn 13143: pgbg => "Page",
1.6 raeburn 13144: tabbg => "Header",
13145: sidebg => "Border",
13146: link => "Link",
13147: alink => "Active link",
13148: vlink => "Visited link",
13149: );
13150: return %choices;
13151: }
13152:
1.394 raeburn 13153: sub modify_ipaccess {
13154: my ($dom,$lastactref,%domconfig) = @_;
13155: my (@allpos,%changes,%confhash,$errors,$resulttext);
13156: my (@items,%deletions,%itemids,@warnings);
13157: my ($typeorder,$types) = &commblocktype_text();
13158: if ($env{'form.ipaccess_add'}) {
13159: my $name = $env{'form.ipaccess_name_add'};
13160: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13161: if ($newid) {
13162: $itemids{'add'} = $newid;
13163: push(@items,'add');
13164: $changes{$newid} = 1;
13165: } else {
13166: $error = &mt('Failed to acquire unique ID for new IP access control item');
13167: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13168: }
13169: }
13170: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13171: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13172: if (@todelete) {
13173: map { $deletions{$_} = 1; } @todelete;
13174: }
13175: my $maxnum = $env{'form.ipaccess_maxnum'};
13176: for (my $i=0; $i<$maxnum; $i++) {
13177: my $itemid = $env{'form.ipaccess_id_'.$i};
13178: $itemid =~ s/\D+//g;
13179: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13180: if ($deletions{$itemid}) {
13181: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13182: } else {
13183: push(@items,$i);
13184: $itemids{$i} = $itemid;
13185: }
13186: }
13187: }
13188: }
13189: foreach my $idx (@items) {
13190: my $itemid = $itemids{$idx};
13191: next unless ($itemid);
13192: my %current;
13193: unless ($idx eq 'add') {
13194: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13195: %current = %{$domconfig{'ipaccess'}{$itemid}};
13196: }
13197: }
13198: my $position = $env{'form.ipaccess_pos_'.$itemid};
13199: $position =~ s/\D+//g;
13200: if ($position ne '') {
13201: $allpos[$position] = $itemid;
13202: }
13203: my $name = $env{'form.ipaccess_name_'.$idx};
13204: $name =~ s/^\s+|\s+$//g;
13205: $confhash{$itemid}{'name'} = $name;
13206: my $possrange = $env{'form.ipaccess_range_'.$idx};
13207: $possrange =~ s/^\s+|\s+$//g;
13208: unless ($possrange eq '') {
13209: $possrange =~ s/[\r\n]+/\s/g;
13210: $possrange =~ s/\s*-\s*/-/g;
13211: $possrange =~ s/\s+/,/g;
13212: $possrange =~ s/,+/,/g;
13213: if ($possrange ne '') {
13214: my (@ok,$count);
1.425 raeburn 13215: $count = 0;
1.394 raeburn 13216: foreach my $poss (split(/\,/,$possrange)) {
13217: $count ++;
13218: $poss = &validate_ip_pattern($poss);
13219: if ($poss ne '') {
13220: push(@ok,$poss);
13221: }
13222: }
13223: my $diff = $count - scalar(@ok);
13224: if ($diff) {
13225: $errors .= '<li><span class="LC_error">'.
13226: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13227: $diff,$name).
13228: '</span></li>';
13229: }
13230: if (@ok) {
13231: my @cidr_list;
13232: foreach my $item (@ok) {
13233: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13234: }
13235: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13236: }
13237: }
13238: }
13239: foreach my $field ('name','ip') {
13240: unless (($idx eq 'add') || ($changes{$itemid})) {
13241: if ($current{$field} ne $confhash{$itemid}{$field}) {
13242: $changes{$itemid} = 1;
13243: last;
13244: }
13245: }
13246: }
13247: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13248:
1.394 raeburn 13249: my %commblocks;
1.425 raeburn 13250: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13251: foreach my $type (@{$typeorder}) {
13252: if ($commblocks{$type}) {
13253: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13254: }
13255: unless (($idx eq 'add') || ($changes{$itemid})) {
13256: if (ref($current{'commblocks'}) eq 'HASH') {
13257: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13258: $changes{$itemid} = 1;
13259: }
13260: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13261: $changes{$itemid} = 1;
13262: }
13263: }
13264: }
13265: $confhash{$itemid}{'courses'} = {};
13266: my %crsdeletions;
13267: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13268: if (@delcrs) {
13269: map { $crsdeletions{$_} = 1; } @delcrs;
13270: }
13271: if (ref($current{'courses'}) eq 'HASH') {
13272: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13273: if ($crsdeletions{$cid}) {
13274: $changes{$itemid} = 1;
13275: } else {
13276: $confhash{$itemid}{'courses'}{$cid} = 1;
13277: }
13278: }
13279: }
13280: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13281: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13282: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13283: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13284: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13285: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13286: $errors .= '<li><span class="LC_error">'.
13287: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13288: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13289: '</span></li>';
13290: } else {
13291: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13292: $changes{$itemid} = 1;
13293: }
13294: }
13295: }
13296: if (@allpos > 0) {
13297: my $idx = 0;
13298: foreach my $itemid (@allpos) {
13299: if ($itemid ne '') {
13300: $confhash{$itemid}{'order'} = $idx;
13301: unless ($changes{$itemid}) {
13302: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13303: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13304: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13305: $changes{$itemid} = 1;
13306: }
13307: }
13308: }
13309: }
13310: $idx ++;
13311: }
13312: }
13313: }
13314: if (keys(%changes)) {
13315: my %defaultshash = (
13316: ipaccess => \%confhash,
13317: );
13318: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13319: $dom);
13320: if ($putresult eq 'ok') {
13321: my $cachetime = 1800;
13322: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13323: if (ref($lastactref) eq 'HASH') {
13324: $lastactref->{'ipaccess'} = 1;
13325: }
13326: $resulttext = &mt('Changes made:').'<ul>';
13327: my %bynum;
13328: foreach my $itemid (sort(keys(%changes))) {
13329: if (ref($confhash{$itemid}) eq 'HASH') {
13330: my $position = $confhash{$itemid}{'order'};
13331: if ($position =~ /^\d+$/) {
13332: $bynum{$position} = $itemid;
13333: }
13334: }
13335: }
13336: if (keys(%deletions)) {
13337: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13338: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13339: }
13340: }
13341: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13342: my $itemid = $bynum{$pos};
13343: if (ref($confhash{$itemid}) eq 'HASH') {
13344: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13345: my $position = $pos + 1;
13346: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13347: if ($confhash{$itemid}{'ip'} eq '') {
13348: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13349: } else {
13350: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13351: }
13352: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13353: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13354: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13355: '</li>';
13356: } else {
13357: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13358: }
13359: if (keys(%{$confhash{$itemid}{'courses'}})) {
13360: my @courses;
13361: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13362: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13363: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13364: }
13365: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13366: join('</li><li>',@courses).'</li></ul>';
13367: } else {
13368: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13369: }
1.395 raeburn 13370: $resulttext .= '</ul></li>';
1.394 raeburn 13371: }
13372: }
1.395 raeburn 13373: $resulttext .= '</ul>';
1.394 raeburn 13374: } else {
13375: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13376: }
13377: } else {
13378: $resulttext = &mt('No changes made');
13379: }
13380: if ($errors) {
13381: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13382: $errors.'</ul></p>';
13383: }
13384: return $resulttext;
13385: }
13386:
13387: sub get_ipaccess_id {
13388: my ($domain,$location) = @_;
13389: # get lock on ipaccess db
13390: my $lockhash = {
13391: lock => $env{'user.name'}.
13392: ':'.$env{'user.domain'},
13393: };
13394: my $tries = 0;
13395: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13396: my ($id,$error);
13397:
13398: while (($gotlock ne 'ok') && ($tries<10)) {
13399: $tries ++;
13400: sleep (0.1);
13401: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13402: }
13403: if ($gotlock eq 'ok') {
13404: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13405: if ($currids{'lock'}) {
13406: delete($currids{'lock'});
13407: if (keys(%currids)) {
13408: my @curr = sort { $a <=> $b } keys(%currids);
13409: if ($curr[-1] =~ /^\d+$/) {
13410: $id = 1 + $curr[-1];
13411: }
13412: } else {
13413: $id = 1;
13414: }
13415: if ($id) {
13416: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13417: $error = 'nostore';
13418: }
13419: } else {
13420: $error = 'nonumber';
13421: }
13422: }
13423: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13424: } else {
13425: $error = 'nolock';
13426: }
13427: return ($id,$error);
13428: }
13429:
1.429 raeburn 13430: sub modify_authordefaults {
13431: my ($dom,$lastactref,%domconfig) = @_;
13432: #
13433: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13434: #
13435: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13436: if (ref($domconfig{'quotas'}) eq 'HASH') {
13437: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13438: if ($key =~ /^webdav|authorquota$/) {
13439: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13440: } else {
13441: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13442: }
13443: }
13444: }
13445: my %staticdefaults = (
13446: 'copyright' => 'default',
13447: 'sourceavail' => 'closed',
13448: 'nocodemirror' => 'off',
1.437 raeburn 13449: 'daxecollapse' => 'off',
1.429 raeburn 13450: 'domcoordacc' => 'on',
1.439 raeburn 13451: 'editors' => ['edit','xml'],
1.429 raeburn 13452: 'authorquota' => 500,
13453: 'webdav' => 0,
1.440 raeburn 13454: 'archive' => 'off',
1.429 raeburn 13455: );
13456: my %titles = &authordefaults_titles();
1.440 raeburn 13457: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13458: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13459: $confhash{$item} = $env{'form.'.$item};
13460: }
13461: }
13462: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13463: $confhash{'copyright'} = $1;
13464: }
13465: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13466: $confhash{'sourceavail'} = $1;
13467: }
13468: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13469: my @okeditors = ('edit','xml','daxe');
13470: my @editors;
13471: foreach my $item (@posseditors) {
13472: if (grep(/^\Q$item\E$/,@okeditors)) {
13473: push(@editors,$item);
13474: }
13475: }
13476: $confhash{'editors'} = \@editors;
1.436 raeburn 13477:
1.429 raeburn 13478: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13479: my @insttypes;
13480: if (ref($types) eq 'ARRAY') {
13481: @insttypes = @{$types};
13482: }
13483: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13484: my %webdav;
13485: map { $webdav{$_} = 1; } @webdavon;
13486: foreach my $type (@insttypes,'default') {
13487: my $possquota = $env{'form.authorquota_'.$type};
13488: if ($possquota =~ /^\d+$/) {
13489: $save_quotas{'authorquota'}{$type} = $possquota;
13490: }
13491: if ($webdav{$type}) {
13492: $save_quotas{'webdav'}{$type} = 1;
13493: } else {
13494: $save_quotas{'webdav'}{$type} = 0;
13495: }
13496: }
13497: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13498: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13499: }
13500: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13501: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13502: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13503: $changes{$item} = 1;
13504: }
13505: }
13506: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13507: my @diffs =
1.429 raeburn 13508: &Apache::loncommon::compare_arrays($confhash{'editors'},
13509: $domconfig{'authordefaults'}{'editors'});
13510: unless (@diffs == 0) {
13511: $changes{'editors'} = 1;
13512: }
13513: } else {
13514: my @diffs =
13515: &Apache::loncommon::compare_arrays($confhash{'editors'},
13516: $staticdefaults{'editors'});
13517: unless (@diffs == 0) {
13518: $changes{'editors'} = 1;
13519: }
13520: }
13521: } else {
13522: my @offon = ('off','on');
1.440 raeburn 13523: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13524: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13525: $changes{$item} = 1;
13526: }
13527: }
13528: foreach my $item ('copyright','sourceavail') {
13529: if ($confhash{$item} ne $staticdefaults{$item}) {
13530: $changes{$item} = 1;
13531: }
13532: }
1.439 raeburn 13533: my @diffs =
13534: &Apache::loncommon::compare_arrays($confhash{'editors'},
13535: $staticdefaults{'editors'});
13536: unless (@diffs == 0) {
13537: $changes{'editors'} = 1;
13538: }
1.429 raeburn 13539: }
13540: foreach my $key ('authorquota','webdav') {
13541: if (ref($curr_quotas{$key}) eq 'HASH') {
13542: foreach my $type (@insttypes,'default') {
13543: if (exists($save_quotas{$key}{$type})) {
13544: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13545: $changes{$key}{$type} = 1;
13546: }
13547: } elsif (exists($curr_quotas{$key}{$type})) {
13548: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13549: } else {
13550: $save_quotas{$key}{$type} = $staticdefaults{$key};
13551: }
13552: }
13553: } else {
13554: foreach my $type (@insttypes,'default') {
13555: if (exists($save_quotas{$key}{$type})) {
13556: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13557: $changes{$key}{$type} = 1;
13558: }
13559: } else {
13560: $save_quotas{$key}{$type} = $staticdefaults{$key};
13561: }
13562: }
13563: }
13564: }
13565: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13566: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13567: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13568: $changes{'webdav_LC_adv'} = 1;
13569: }
13570: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13571: $changes{'webdav_LC_adv'} = 1;
13572: }
13573: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13574: $changes{'webdav_LC_adv'} = 1;
13575: }
13576: my %confighash = (
13577: quotas => \%save_quotas,
13578: authordefaults => \%confhash,
13579: );
13580: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13581: $dom);
13582: my $resulttext;
13583: if ($putresult eq 'ok') {
13584: if (keys(%changes)) {
1.431 raeburn 13585: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13586: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13587: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13588: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13589: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13590: }
13591: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13592: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13593: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13594: }
13595: }
13596: $resulttext = &mt('Changes made:').'<ul>';
13597: my $authoroverride;
1.437 raeburn 13598: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13599: if (exists($changes{$key})) {
1.431 raeburn 13600: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13601: my $shown;
13602: unless ($authoroverride) {
13603: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13604: $authoroverride = 1;
13605: }
1.437 raeburn 13606: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13607: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13608: } elsif ($key eq 'copyright') {
13609: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13610: } elsif ($key eq 'sourceavail') {
13611: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13612: }
1.436 raeburn 13613: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13614: }
13615: }
13616: if ($authoroverride) {
13617: $resulttext .= '</ul></li>';
13618: }
13619: my $domcoordoverride;
1.440 raeburn 13620: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13621: if (exists($changes{$key})) {
13622: my $shown;
13623: unless ($domcoordoverride) {
13624: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13625: $domcoordoverride = 1;
13626: }
13627: if ($key eq 'editors') {
1.431 raeburn 13628: if (ref($confhash{'editors'}) eq 'ARRAY') {
13629: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13630: if (@{$confhash{'editors'}}) {
13631: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13632: } else {
13633: $shown = &mt('None');
13634: }
1.429 raeburn 13635: }
13636: } elsif ($key eq 'authorquota') {
13637: foreach my $type (@insttypes) {
13638: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13639: }
13640: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13641: } elsif ($key eq 'webdav') {
13642: foreach my $type (@insttypes) {
13643: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13644: }
13645: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13646: } elsif ($key eq 'webdav_LC_adv') {
13647: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13648: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13649: } else {
13650: $shown = $titles{'none'};
13651: }
1.440 raeburn 13652: } elsif ($key eq 'archive') {
1.441 raeburn 13653: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13654: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13655: }
13656: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13657: }
1.429 raeburn 13658: }
13659: if ($domcoordoverride) {
13660: $resulttext .= '</ul></li>';
13661: }
1.439 raeburn 13662: $resulttext .= '</ul>';
1.431 raeburn 13663: my $cachetime = 24*60*60;
13664: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13665: if (ref($lastactref) eq 'HASH') {
13666: $lastactref->{'domdefaults'} = 1;
13667: }
1.429 raeburn 13668: } else {
13669: $resulttext = &mt('No changes made to Authoring Space defaults');
13670: }
13671: }
13672: return $resulttext;
13673: }
13674:
1.6 raeburn 13675: sub modify_rolecolors {
1.205 raeburn 13676: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13677: my ($resulttext,%rolehash);
13678: $rolehash{'rolecolors'} = {};
1.55 raeburn 13679: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13680: if ($domconfig{'rolecolors'} eq '') {
13681: $domconfig{'rolecolors'} = {};
13682: }
13683: }
1.9 raeburn 13684: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13685: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13686: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13687: $dom);
13688: if ($putresult eq 'ok') {
13689: if (keys(%changes) > 0) {
1.41 raeburn 13690: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13691: if (ref($lastactref) eq 'HASH') {
13692: $lastactref->{'domainconfig'} = 1;
13693: }
1.6 raeburn 13694: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13695: $rolehash{'rolecolors'});
13696: } else {
13697: $resulttext = &mt('No changes made to default color schemes');
13698: }
13699: } else {
1.11 albertel 13700: $resulttext = '<span class="LC_error">'.
13701: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13702: }
13703: if ($errors) {
13704: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13705: $errors.'</ul>';
13706: }
13707: return $resulttext;
13708: }
13709:
13710: sub modify_colors {
1.9 raeburn 13711: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13712: my (%changes,%choices);
1.51 raeburn 13713: my @bgs;
1.6 raeburn 13714: my @links = ('link','alink','vlink');
1.41 raeburn 13715: my @logintext;
1.6 raeburn 13716: my @images;
13717: my $servadm = $r->dir_config('lonAdmEMail');
13718: my $errors;
1.200 raeburn 13719: my %defaults;
1.6 raeburn 13720: foreach my $role (@{$roles}) {
13721: if ($role eq 'login') {
1.12 raeburn 13722: %choices = &login_choices();
1.41 raeburn 13723: @logintext = ('textcol','bgcol');
1.12 raeburn 13724: } else {
13725: %choices = &color_font_choices();
13726: }
13727: if ($role eq 'login') {
1.41 raeburn 13728: @images = ('img','logo','domlogo','login');
1.51 raeburn 13729: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13730: } else {
13731: @images = ('img');
1.200 raeburn 13732: @bgs = ('pgbg','tabbg','sidebg');
13733: }
13734: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
13735: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
13736: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13737: }
13738: if ($role eq 'login') {
13739: foreach my $item (@logintext) {
1.234 raeburn 13740: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13741: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13742: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13743: }
13744: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13745: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13746: }
13747: }
13748: } else {
1.234 raeburn 13749: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13750: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13751: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13752: }
13753: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13754: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13755: }
1.6 raeburn 13756: }
1.200 raeburn 13757: foreach my $item (@bgs) {
1.234 raeburn 13758: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13759: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13760: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13761: }
13762: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13763: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13764: }
13765: }
13766: foreach my $item (@links) {
1.234 raeburn 13767: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13768: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13769: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13770: }
13771: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13772: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13773: }
1.6 raeburn 13774: }
1.46 raeburn 13775: my ($configuserok,$author_ok,$switchserver) =
13776: &config_check($dom,$confname,$servadm);
1.9 raeburn 13777: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13778: if (ref($domconfig->{$role}) ne 'HASH') {
13779: $domconfig->{$role} = {};
13780: }
1.8 raeburn 13781: foreach my $img (@images) {
1.402 raeburn 13782: if ($role eq 'login') {
13783: if (($img eq 'img') || ($img eq 'logo')) {
13784: if (defined($env{'form.login_showlogo_'.$img})) {
13785: $confhash->{$role}{'showlogo'}{$img} = 1;
13786: } else {
13787: $confhash->{$role}{'showlogo'}{$img} = 0;
13788: }
13789: }
13790: if ($env{'form.login_alt_'.$img} ne '') {
13791: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13792: }
1.402 raeburn 13793: }
1.18 albertel 13794: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13795: && !defined($domconfig->{$role}{$img})
13796: && !$env{'form.'.$role.'_del_'.$img}
13797: && $env{'form.'.$role.'_import_'.$img}) {
13798: # import the old configured image from the .tab setting
13799: # if they haven't provided a new one
13800: $domconfig->{$role}{$img} =
13801: $env{'form.'.$role.'_import_'.$img};
13802: }
1.6 raeburn 13803: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13804: my $error;
1.6 raeburn 13805: if ($configuserok eq 'ok') {
1.9 raeburn 13806: if ($switchserver) {
1.12 raeburn 13807: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13808: } else {
13809: if ($author_ok eq 'ok') {
1.421 raeburn 13810: my $modified = [];
1.9 raeburn 13811: my ($result,$logourl) =
1.421 raeburn 13812: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13813: $dom,$confname,$img,$width,$height,
13814: '',$modified);
1.9 raeburn 13815: if ($result eq 'ok') {
13816: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13817: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13818: &update_modify_urls($r,$modified);
1.9 raeburn 13819: } else {
1.12 raeburn 13820: $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 13821: }
13822: } else {
1.46 raeburn 13823: $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 13824: }
13825: }
13826: } else {
1.46 raeburn 13827: $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 13828: }
13829: if ($error) {
1.8 raeburn 13830: &Apache::lonnet::logthis($error);
1.11 albertel 13831: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13832: }
13833: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13834: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13835: my $error;
13836: if ($configuserok eq 'ok') {
13837: # is confname an author?
13838: if ($switchserver eq '') {
13839: if ($author_ok eq 'ok') {
1.421 raeburn 13840: my $modified = [];
1.9 raeburn 13841: my ($result,$logourl) =
1.421 raeburn 13842: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13843: $dom,$confname,$img,$width,$height,
13844: '',$modified);
1.9 raeburn 13845: if ($result eq 'ok') {
13846: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13847: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13848: &update_modify_urls($r,$modified);
1.9 raeburn 13849: }
13850: }
13851: }
13852: }
1.6 raeburn 13853: }
13854: }
13855: }
13856: if (ref($domconfig) eq 'HASH') {
13857: if (ref($domconfig->{$role}) eq 'HASH') {
13858: foreach my $img (@images) {
13859: if ($domconfig->{$role}{$img} ne '') {
13860: if ($env{'form.'.$role.'_del_'.$img}) {
13861: $confhash->{$role}{$img} = '';
1.12 raeburn 13862: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13863: } else {
1.9 raeburn 13864: if ($confhash->{$role}{$img} eq '') {
13865: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13866: }
1.6 raeburn 13867: }
13868: } else {
13869: if ($env{'form.'.$role.'_del_'.$img}) {
13870: $confhash->{$role}{$img} = '';
1.12 raeburn 13871: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13872: }
13873: }
1.402 raeburn 13874: if ($role eq 'login') {
13875: if (($img eq 'logo') || ($img eq 'img')) {
13876: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13877: if ($confhash->{$role}{'showlogo'}{$img} ne
13878: $domconfig->{$role}{'showlogo'}{$img}) {
13879: $changes{$role}{'showlogo'}{$img} = 1;
13880: }
13881: } else {
13882: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13883: $changes{$role}{'showlogo'}{$img} = 1;
13884: }
1.70 raeburn 13885: }
1.402 raeburn 13886: }
13887: if ($img ne 'login') {
13888: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13889: if ($confhash->{$role}{'alttext'}{$img} ne
13890: $domconfig->{$role}{'alttext'}{$img}) {
13891: $changes{$role}{'alttext'}{$img} = 1;
13892: }
13893: } else {
13894: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13895: $changes{$role}{'alttext'}{$img} = 1;
13896: }
1.70 raeburn 13897: }
13898: }
13899: }
13900: }
1.6 raeburn 13901: if ($domconfig->{$role}{'font'} ne '') {
13902: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13903: $changes{$role}{'font'} = 1;
13904: }
13905: } else {
13906: if ($confhash->{$role}{'font'}) {
13907: $changes{$role}{'font'} = 1;
13908: }
13909: }
1.107 raeburn 13910: if ($role ne 'login') {
13911: if ($domconfig->{$role}{'fontmenu'} ne '') {
13912: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13913: $changes{$role}{'fontmenu'} = 1;
13914: }
13915: } else {
13916: if ($confhash->{$role}{'fontmenu'}) {
13917: $changes{$role}{'fontmenu'} = 1;
13918: }
1.97 tempelho 13919: }
13920: }
1.6 raeburn 13921: foreach my $item (@bgs) {
13922: if ($domconfig->{$role}{$item} ne '') {
13923: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13924: $changes{$role}{'bgs'}{$item} = 1;
13925: }
13926: } else {
13927: if ($confhash->{$role}{$item}) {
13928: $changes{$role}{'bgs'}{$item} = 1;
13929: }
13930: }
13931: }
13932: foreach my $item (@links) {
13933: if ($domconfig->{$role}{$item} ne '') {
13934: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13935: $changes{$role}{'links'}{$item} = 1;
13936: }
13937: } else {
13938: if ($confhash->{$role}{$item}) {
13939: $changes{$role}{'links'}{$item} = 1;
13940: }
13941: }
13942: }
1.41 raeburn 13943: foreach my $item (@logintext) {
13944: if ($domconfig->{$role}{$item} ne '') {
13945: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13946: $changes{$role}{'logintext'}{$item} = 1;
13947: }
13948: } else {
13949: if ($confhash->{$role}{$item}) {
13950: $changes{$role}{'logintext'}{$item} = 1;
13951: }
13952: }
13953: }
1.6 raeburn 13954: } else {
13955: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13956: \@logintext,$confhash,\%changes);
1.6 raeburn 13957: }
13958: } else {
13959: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13960: \@logintext,$confhash,\%changes);
1.6 raeburn 13961: }
13962: }
13963: return ($errors,%changes);
13964: }
13965:
1.46 raeburn 13966: sub config_check {
13967: my ($dom,$confname,$servadm) = @_;
13968: my ($configuserok,$author_ok,$switchserver,%currroles);
13969: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13970: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13971: $confname,$servadm);
13972: if ($configuserok eq 'ok') {
13973: $switchserver = &check_switchserver($dom,$confname);
13974: if ($switchserver eq '') {
13975: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13976: }
13977: }
13978: return ($configuserok,$author_ok,$switchserver);
13979: }
13980:
1.6 raeburn 13981: sub default_change_checker {
1.41 raeburn 13982: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13983: foreach my $item (@{$links}) {
13984: if ($confhash->{$role}{$item}) {
13985: $changes->{$role}{'links'}{$item} = 1;
13986: }
13987: }
13988: foreach my $item (@{$bgs}) {
13989: if ($confhash->{$role}{$item}) {
13990: $changes->{$role}{'bgs'}{$item} = 1;
13991: }
13992: }
1.41 raeburn 13993: foreach my $item (@{$logintext}) {
13994: if ($confhash->{$role}{$item}) {
13995: $changes->{$role}{'logintext'}{$item} = 1;
13996: }
13997: }
1.6 raeburn 13998: foreach my $img (@{$images}) {
13999: if ($env{'form.'.$role.'_del_'.$img}) {
14000: $confhash->{$role}{$img} = '';
1.12 raeburn 14001: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 14002: }
1.70 raeburn 14003: if ($role eq 'login') {
14004: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
14005: $changes->{$role}{'showlogo'}{$img} = 1;
14006: }
1.402 raeburn 14007: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
14008: if ($confhash->{$role}{'alttext'}{$img} ne '') {
14009: $changes->{$role}{'alttext'}{$img} = 1;
14010: }
14011: }
1.70 raeburn 14012: }
1.6 raeburn 14013: }
14014: if ($confhash->{$role}{'font'}) {
14015: $changes->{$role}{'font'} = 1;
14016: }
1.48 raeburn 14017: }
1.6 raeburn 14018:
14019: sub display_colorchgs {
14020: my ($dom,$changes,$roles,$confhash) = @_;
14021: my (%choices,$resulttext);
14022: if (!grep(/^login$/,@{$roles})) {
14023: $resulttext = &mt('Changes made:').'<br />';
14024: }
14025: foreach my $role (@{$roles}) {
14026: if ($role eq 'login') {
14027: %choices = &login_choices();
14028: } else {
14029: %choices = &color_font_choices();
14030: }
14031: if (ref($changes->{$role}) eq 'HASH') {
14032: if ($role ne 'login') {
14033: $resulttext .= '<h4>'.&mt($role).'</h4>';
14034: }
14035: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14036: if ($role ne 'login') {
14037: $resulttext .= '<ul>';
14038: }
14039: if (ref($changes->{$role}{$key}) eq 'HASH') {
14040: if ($role ne 'login') {
14041: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14042: }
14043: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14044: if (($role eq 'login') && ($key eq 'showlogo')) {
14045: if ($confhash->{$role}{$key}{$item}) {
14046: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14047: } else {
14048: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14049: }
1.402 raeburn 14050: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14051: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14052: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14053: $confhash->{$role}{$key}{$item}).'</li>';
14054: } else {
14055: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14056: }
1.70 raeburn 14057: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14058: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14059: } else {
1.12 raeburn 14060: my $newitem = $confhash->{$role}{$item};
14061: if ($key eq 'images') {
1.306 raeburn 14062: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14063: }
14064: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14065: }
14066: }
14067: if ($role ne 'login') {
14068: $resulttext .= '</ul></li>';
14069: }
14070: } else {
14071: if ($confhash->{$role}{$key} eq '') {
14072: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14073: } else {
14074: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14075: }
14076: }
14077: if ($role ne 'login') {
14078: $resulttext .= '</ul>';
14079: }
14080: }
14081: }
14082: }
1.3 raeburn 14083: return $resulttext;
1.1 raeburn 14084: }
14085:
1.9 raeburn 14086: sub thumb_dimensions {
14087: return ('200','50');
14088: }
14089:
1.16 raeburn 14090: sub check_dimensions {
14091: my ($inputfile) = @_;
14092: my ($fullwidth,$fullheight);
14093: if ($inputfile =~ m|^[/\w.\-]+$|) {
14094: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14095: my $imageinfo = <PIPE>;
14096: if (!close(PIPE)) {
14097: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14098: }
14099: chomp($imageinfo);
14100: my ($fullsize) =
1.21 raeburn 14101: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14102: if ($fullsize) {
14103: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14104: }
14105: }
14106: }
14107: return ($fullwidth,$fullheight);
14108: }
14109:
1.9 raeburn 14110: sub check_configuser {
14111: my ($uhome,$dom,$confname,$servadm) = @_;
14112: my ($configuserok,%currroles);
14113: if ($uhome eq 'no_host') {
14114: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14115: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14116: $configuserok =
14117: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14118: $configpass,'','','','','',undef,$servadm);
14119: } else {
14120: $configuserok = 'ok';
14121: %currroles =
14122: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14123: }
14124: return ($configuserok,%currroles);
14125: }
14126:
14127: sub check_authorstatus {
14128: my ($dom,$confname,%currroles) = @_;
14129: my $author_ok;
1.40 raeburn 14130: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14131: my $start = time;
14132: my $end = 0;
14133: $author_ok =
14134: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14135: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14136: } else {
14137: $author_ok = 'ok';
14138: }
14139: return $author_ok;
14140: }
14141:
1.421 raeburn 14142: sub update_modify_urls {
14143: my ($r,$modified) = @_;
14144: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14145: push(@{$modified_urls},$modified);
14146: unless ($registered_cleanup) {
14147: my $handlers = $r->get_handlers('PerlCleanupHandler');
14148: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14149: $registered_cleanup=1;
1.9 raeburn 14150: }
14151: }
1.155 raeburn 14152: }
14153:
14154: sub notifysubscribed {
14155: foreach my $targetsource (@{$modified_urls}){
14156: next unless (ref($targetsource) eq 'ARRAY');
14157: my ($target,$source)=@{$targetsource};
14158: if ($source ne '') {
1.316 raeburn 14159: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14160: print $logfh "\nCleanup phase: Notifications\n";
14161: my @subscribed=&subscribed_hosts($target);
14162: foreach my $subhost (@subscribed) {
14163: print $logfh "\nNotifying host ".$subhost.':';
14164: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14165: print $logfh $reply;
14166: }
14167: my @subscribedmeta=&subscribed_hosts("$target.meta");
14168: foreach my $subhost (@subscribedmeta) {
14169: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14170: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14171: $subhost);
14172: print $logfh $reply;
14173: }
14174: print $logfh "\n============ Done ============\n";
1.160 raeburn 14175: close($logfh);
1.155 raeburn 14176: }
14177: }
14178: }
14179: return OK;
14180: }
14181:
14182: sub subscribed_hosts {
14183: my ($target) = @_;
14184: my @subscribed;
1.316 raeburn 14185: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14186: while (my $subline=<$fh>) {
14187: if ($subline =~ /^($match_lonid):/) {
14188: my $host = $1;
14189: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14190: unless (grep(/^\Q$host\E$/,@subscribed)) {
14191: push(@subscribed,$host);
14192: }
14193: }
14194: }
14195: }
14196: }
14197: return @subscribed;
1.9 raeburn 14198: }
14199:
14200: sub check_switchserver {
14201: my ($dom,$confname) = @_;
1.424 raeburn 14202: my ($allowed,$switchserver,$home);
14203: if ($confname eq '') {
1.9 raeburn 14204: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14205: } else {
14206: $home = &Apache::lonnet::homeserver($confname,$dom);
14207: if ($home eq 'no_host') {
14208: $home = &Apache::lonnet::domain($dom,'primary');
14209: }
1.9 raeburn 14210: }
14211: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14212: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14213: if (!$allowed) {
1.426 raeburn 14214: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14215: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14216: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14217: }
14218: return $switchserver;
14219: }
14220:
1.1 raeburn 14221: sub modify_quotas {
1.216 raeburn 14222: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14223: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14224: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14225: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14226: $validationfieldsref);
1.86 raeburn 14227: if ($action eq 'quotas') {
1.429 raeburn 14228: $context = 'tools';
1.163 raeburn 14229: } else {
1.86 raeburn 14230: $context = $action;
14231: }
14232: if ($context eq 'requestcourses') {
1.325 raeburn 14233: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14234: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14235: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14236: %titles = &courserequest_titles();
14237: $toolregexp = join('|',@usertools);
14238: %conditions = &courserequest_conditions();
1.216 raeburn 14239: $confname = $dom.'-domainconfig';
14240: my $servadm = $r->dir_config('lonAdmEMail');
14241: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14242: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14243: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14244: } elsif ($context eq 'requestauthor') {
14245: @usertools = ('author');
14246: %titles = &authorrequest_titles();
1.86 raeburn 14247: } else {
1.430 raeburn 14248: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14249: %titles = &tool_titles();
1.86 raeburn 14250: }
1.212 raeburn 14251: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14252: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14253: foreach my $key (keys(%env)) {
1.101 raeburn 14254: if ($context eq 'requestcourses') {
14255: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14256: my $item = $1;
14257: my $type = $2;
14258: if ($type =~ /^limit_(.+)/) {
14259: $limithash{$item}{$1} = $env{$key};
14260: } else {
14261: $confhash{$item}{$type} = $env{$key};
14262: }
14263: }
1.163 raeburn 14264: } elsif ($context eq 'requestauthor') {
14265: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14266: $confhash{$1} = $env{$key};
14267: }
1.101 raeburn 14268: } else {
1.86 raeburn 14269: if ($key =~ /^form\.quota_(.+)$/) {
14270: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14271: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14272: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14273: }
1.72 raeburn 14274: }
14275: }
1.163 raeburn 14276: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14277: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14278: @approvalnotify = sort(@approvalnotify);
14279: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14280: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14281: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14282: foreach my $type (@hasuniquecode) {
14283: if (grep(/^\Q$type\E$/,@crstypes)) {
14284: $confhash{'uniquecode'}{$type} = 1;
14285: }
1.216 raeburn 14286: }
1.242 raeburn 14287: my (%newbook,%allpos);
1.216 raeburn 14288: if ($context eq 'requestcourses') {
1.242 raeburn 14289: foreach my $type ('textbooks','templates') {
14290: @{$allpos{$type}} = ();
14291: my $invalid;
14292: if ($type eq 'textbooks') {
14293: $invalid = &mt('Invalid LON-CAPA course for textbook');
14294: } else {
14295: $invalid = &mt('Invalid LON-CAPA course for template');
14296: }
14297: if ($env{'form.'.$type.'_addbook'}) {
14298: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14299: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14300: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14301: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14302: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14303: } else {
14304: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14305: my $position = $env{'form.'.$type.'_addbook_pos'};
14306: $position =~ s/\D+//g;
14307: if ($position ne '') {
14308: $allpos{$type}[$position] = $newbook{$type};
14309: }
1.216 raeburn 14310: }
1.242 raeburn 14311: } else {
14312: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14313: }
14314: }
1.242 raeburn 14315: }
1.216 raeburn 14316: }
1.102 raeburn 14317: if (ref($domconfig{$action}) eq 'HASH') {
14318: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14319: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14320: $changes{'notify'}{'approval'} = 1;
14321: }
14322: } else {
1.144 raeburn 14323: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14324: $changes{'notify'}{'approval'} = 1;
14325: }
14326: }
1.218 raeburn 14327: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14328: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14329: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14330: unless ($confhash{'uniquecode'}{$crstype}) {
14331: $changes{'uniquecode'} = 1;
14332: }
14333: }
14334: unless ($changes{'uniquecode'}) {
14335: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14336: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14337: $changes{'uniquecode'} = 1;
14338: }
14339: }
14340: }
14341: } else {
14342: $changes{'uniquecode'} = 1;
14343: }
14344: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14345: $changes{'uniquecode'} = 1;
1.216 raeburn 14346: }
14347: if ($context eq 'requestcourses') {
1.242 raeburn 14348: foreach my $type ('textbooks','templates') {
14349: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14350: my %deletions;
14351: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14352: if (@todelete) {
14353: map { $deletions{$_} = 1; } @todelete;
14354: }
14355: my %imgdeletions;
14356: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14357: if (@todeleteimages) {
14358: map { $imgdeletions{$_} = 1; } @todeleteimages;
14359: }
14360: my $maxnum = $env{'form.'.$type.'_maxnum'};
14361: for (my $i=0; $i<=$maxnum; $i++) {
14362: my $itemid = $env{'form.'.$type.'_id_'.$i};
14363: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14364: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14365: if ($deletions{$key}) {
14366: if ($domconfig{$action}{$type}{$key}{'image'}) {
14367: #FIXME need to obsolete item in RES space
14368: }
14369: next;
14370: } else {
14371: my $newpos = $env{'form.'.$itemid};
14372: $newpos =~ s/\D+//g;
1.243 raeburn 14373: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14374: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14375: ($type eq 'templates'));
1.242 raeburn 14376: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14377: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14378: $changes{$type}{$key} = 1;
14379: }
14380: }
14381: $allpos{$type}[$newpos] = $key;
14382: }
14383: if ($imgdeletions{$key}) {
14384: $changes{$type}{$key} = 1;
1.216 raeburn 14385: #FIXME need to obsolete item in RES space
1.242 raeburn 14386: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14387: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14388: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14389: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14390: } else {
14391: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14392: $cdom,$cnum,$type,$configuserok,
14393: $switchserver,$author_ok);
14394: if ($imgurl) {
14395: $confhash{$type}{$key}{'image'} = $imgurl;
14396: $changes{$type}{$key} = 1;
14397: }
14398: if ($error) {
14399: &Apache::lonnet::logthis($error);
14400: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14401: }
14402: }
1.242 raeburn 14403: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14404: $confhash{$type}{$key}{'image'} =
14405: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14406: }
14407: }
14408: }
14409: }
14410: }
14411: }
1.102 raeburn 14412: } else {
1.144 raeburn 14413: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14414: $changes{'notify'}{'approval'} = 1;
14415: }
1.218 raeburn 14416: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14417: $changes{'uniquecode'} = 1;
14418: }
14419: }
14420: if ($context eq 'requestcourses') {
1.242 raeburn 14421: foreach my $type ('textbooks','templates') {
14422: if ($newbook{$type}) {
14423: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14424: foreach my $item ('subject','title','publisher','author') {
14425: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14426: ($type eq 'template'));
1.242 raeburn 14427: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14428: if ($env{'form.'.$type.'_addbook_'.$item}) {
14429: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14430: }
14431: }
14432: if ($type eq 'textbooks') {
14433: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14434: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14435: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14436: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14437: } else {
14438: my ($imageurl,$error) =
14439: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14440: $configuserok,$switchserver,$author_ok);
14441: if ($imageurl) {
14442: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14443: }
14444: if ($error) {
14445: &Apache::lonnet::logthis($error);
14446: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14447: }
1.242 raeburn 14448: }
14449: }
1.216 raeburn 14450: }
14451: }
1.242 raeburn 14452: if (@{$allpos{$type}} > 0) {
14453: my $idx = 0;
14454: foreach my $item (@{$allpos{$type}}) {
14455: if ($item ne '') {
14456: $confhash{$type}{$item}{'order'} = $idx;
14457: if (ref($domconfig{$action}) eq 'HASH') {
14458: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14459: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14460: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14461: $changes{$type}{$item} = 1;
14462: }
1.216 raeburn 14463: }
14464: }
14465: }
1.242 raeburn 14466: $idx ++;
1.216 raeburn 14467: }
14468: }
14469: }
14470: }
1.235 raeburn 14471: if (ref($validationitemsref) eq 'ARRAY') {
14472: foreach my $item (@{$validationitemsref}) {
14473: if ($item eq 'fields') {
14474: my @changed;
14475: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14476: if (@{$confhash{'validation'}{$item}} > 0) {
14477: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14478: }
1.266 raeburn 14479: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14480: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14481: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14482: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14483: $domconfig{'requestcourses'}{'validation'}{$item});
14484: } else {
14485: @changed = @{$confhash{'validation'}{$item}};
14486: }
1.235 raeburn 14487: } else {
14488: @changed = @{$confhash{'validation'}{$item}};
14489: }
14490: } else {
14491: @changed = @{$confhash{'validation'}{$item}};
14492: }
14493: if (@changed) {
14494: if ($confhash{'validation'}{$item}) {
14495: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14496: } else {
14497: $changes{'validation'}{$item} = &mt('None');
14498: }
14499: }
14500: } else {
14501: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14502: if ($item eq 'markup') {
14503: if ($env{'form.requestcourses_validation_'.$item}) {
14504: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14505: }
14506: }
1.266 raeburn 14507: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14508: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14509: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14510: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14511: }
14512: } else {
14513: if ($confhash{'validation'}{$item} ne '') {
14514: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14515: }
1.235 raeburn 14516: }
14517: } else {
14518: if ($confhash{'validation'}{$item} ne '') {
14519: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14520: }
14521: }
14522: }
14523: }
14524: }
14525: if ($env{'form.validationdc'}) {
14526: my $newval = $env{'form.validationdc'};
1.285 raeburn 14527: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14528: if (exists($domcoords{$newval})) {
14529: $confhash{'validation'}{'dc'} = $newval;
14530: }
14531: }
14532: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14533: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14534: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14535: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14536: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14537: if ($confhash{'validation'}{'dc'} eq '') {
14538: $changes{'validation'}{'dc'} = &mt('None');
14539: } else {
14540: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14541: }
1.235 raeburn 14542: }
1.266 raeburn 14543: } elsif ($confhash{'validation'}{'dc'} ne '') {
14544: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14545: }
14546: } elsif ($confhash{'validation'}{'dc'} ne '') {
14547: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14548: }
14549: } elsif ($confhash{'validation'}{'dc'} ne '') {
14550: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14551: }
1.266 raeburn 14552: } else {
14553: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14554: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14555: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14556: $changes{'validation'}{'dc'} = &mt('None');
14557: }
14558: }
1.235 raeburn 14559: }
14560: }
1.102 raeburn 14561: }
14562: } else {
1.86 raeburn 14563: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14564: }
1.72 raeburn 14565: foreach my $item (@usertools) {
14566: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14567: my $unset;
1.101 raeburn 14568: if ($context eq 'requestcourses') {
1.104 raeburn 14569: $unset = '0';
14570: if ($type eq '_LC_adv') {
14571: $unset = '';
14572: }
1.101 raeburn 14573: if ($confhash{$item}{$type} eq 'autolimit') {
14574: $confhash{$item}{$type} .= '=';
14575: unless ($limithash{$item}{$type} =~ /\D/) {
14576: $confhash{$item}{$type} .= $limithash{$item}{$type};
14577: }
14578: }
1.163 raeburn 14579: } elsif ($context eq 'requestauthor') {
14580: $unset = '0';
14581: if ($type eq '_LC_adv') {
14582: $unset = '';
14583: }
1.72 raeburn 14584: } else {
1.101 raeburn 14585: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14586: $confhash{$item}{$type} = 1;
14587: } else {
14588: $confhash{$item}{$type} = 0;
14589: }
1.72 raeburn 14590: }
1.86 raeburn 14591: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14592: if ($action eq 'requestauthor') {
14593: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14594: $changes{$type} = 1;
14595: }
14596: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14597: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14598: $changes{$item}{$type} = 1;
14599: }
14600: } else {
14601: if ($context eq 'requestcourses') {
1.104 raeburn 14602: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14603: $changes{$item}{$type} = 1;
14604: }
14605: } else {
14606: if (!$confhash{$item}{$type}) {
14607: $changes{$item}{$type} = 1;
14608: }
14609: }
14610: }
14611: } else {
14612: if ($context eq 'requestcourses') {
1.104 raeburn 14613: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14614: $changes{$item}{$type} = 1;
14615: }
1.163 raeburn 14616: } elsif ($context eq 'requestauthor') {
14617: if ($confhash{$type} ne $unset) {
14618: $changes{$type} = 1;
14619: }
1.72 raeburn 14620: } else {
14621: if (!$confhash{$item}{$type}) {
14622: $changes{$item}{$type} = 1;
14623: }
14624: }
14625: }
1.1 raeburn 14626: }
14627: }
1.163 raeburn 14628: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14629: if (ref($domconfig{'quotas'}) eq 'HASH') {
14630: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14631: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14632: if (exists($confhash{'defaultquota'}{$key})) {
14633: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14634: $changes{'defaultquota'}{$key} = 1;
14635: }
14636: } else {
14637: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14638: }
14639: }
1.86 raeburn 14640: } else {
14641: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14642: if (exists($confhash{'defaultquota'}{$key})) {
14643: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14644: $changes{'defaultquota'}{$key} = 1;
14645: }
14646: } else {
14647: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14648: }
1.1 raeburn 14649: }
14650: }
1.197 raeburn 14651: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14652: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14653: }
14654: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14655: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14656: }
1.1 raeburn 14657: }
1.86 raeburn 14658: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14659: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14660: if (ref($domconfig{'quotas'}) eq 'HASH') {
14661: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14662: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14663: $changes{'defaultquota'}{$key} = 1;
14664: }
14665: } else {
14666: if (!exists($domconfig{'quotas'}{$key})) {
14667: $changes{'defaultquota'}{$key} = 1;
14668: }
1.72 raeburn 14669: }
14670: } else {
1.86 raeburn 14671: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14672: }
1.1 raeburn 14673: }
14674: }
14675: }
1.72 raeburn 14676:
1.163 raeburn 14677: if ($context eq 'requestauthor') {
14678: $domdefaults{'requestauthor'} = \%confhash;
14679: } else {
14680: foreach my $key (keys(%confhash)) {
1.242 raeburn 14681: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14682: $domdefaults{$key} = $confhash{$key};
14683: }
1.163 raeburn 14684: }
1.72 raeburn 14685: }
1.163 raeburn 14686:
1.1 raeburn 14687: my %quotahash = (
1.86 raeburn 14688: $action => { %confhash }
1.1 raeburn 14689: );
14690: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14691: $dom);
14692: if ($putresult eq 'ok') {
14693: if (keys(%changes) > 0) {
1.72 raeburn 14694: my $cachetime = 24*60*60;
14695: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14696: if (ref($lastactref) eq 'HASH') {
14697: $lastactref->{'domdefaults'} = 1;
14698: }
1.1 raeburn 14699: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14700: unless (($context eq 'requestcourses') ||
1.163 raeburn 14701: ($context eq 'requestauthor')) {
1.86 raeburn 14702: if (ref($changes{'defaultquota'}) eq 'HASH') {
14703: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14704: foreach my $type (@{$types},'default') {
14705: if (defined($changes{'defaultquota'}{$type})) {
14706: my $typetitle = $usertypes->{$type};
14707: if ($type eq 'default') {
14708: $typetitle = $othertitle;
14709: }
1.213 raeburn 14710: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14711: }
14712: }
1.86 raeburn 14713: $resulttext .= '</ul></li>';
1.72 raeburn 14714: }
14715: }
1.80 raeburn 14716: my %newenv;
1.72 raeburn 14717: foreach my $item (@usertools) {
1.163 raeburn 14718: my (%haschgs,%inconf);
14719: if ($context eq 'requestauthor') {
14720: %haschgs = %changes;
1.210 raeburn 14721: %inconf = %confhash;
1.163 raeburn 14722: } else {
14723: if (ref($changes{$item}) eq 'HASH') {
14724: %haschgs = %{$changes{$item}};
14725: }
14726: if (ref($confhash{$item}) eq 'HASH') {
14727: %inconf = %{$confhash{$item}};
14728: }
14729: }
14730: if (keys(%haschgs) > 0) {
1.80 raeburn 14731: my $newacc =
14732: &Apache::lonnet::usertools_access($env{'user.name'},
14733: $env{'user.domain'},
1.86 raeburn 14734: $item,'reload',$context);
1.210 raeburn 14735: if (($context eq 'requestcourses') ||
1.163 raeburn 14736: ($context eq 'requestauthor')) {
1.108 raeburn 14737: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14738: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14739: }
14740: } else {
14741: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14742: $newenv{'environment.availabletools.'.$item} = $newacc;
14743: }
1.80 raeburn 14744: }
1.163 raeburn 14745: unless ($context eq 'requestauthor') {
14746: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14747: }
1.72 raeburn 14748: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14749: if ($haschgs{$type}) {
1.72 raeburn 14750: my $typetitle = $usertypes->{$type};
14751: if ($type eq 'default') {
14752: $typetitle = $othertitle;
14753: } elsif ($type eq '_LC_adv') {
14754: $typetitle = 'LON-CAPA Advanced Users';
14755: }
1.163 raeburn 14756: if ($inconf{$type}) {
1.101 raeburn 14757: if ($context eq 'requestcourses') {
14758: my $cond;
1.163 raeburn 14759: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14760: if ($1 eq '') {
14761: $cond = &mt('(Automatic processing of any request).');
14762: } else {
14763: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14764: }
14765: } else {
1.163 raeburn 14766: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14767: }
14768: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14769: } elsif ($context eq 'requestauthor') {
14770: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14771: $titles{$inconf{$type}},$typetitle);
14772:
1.101 raeburn 14773: } else {
14774: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14775: }
1.72 raeburn 14776: } else {
1.104 raeburn 14777: if ($type eq '_LC_adv') {
1.163 raeburn 14778: if ($inconf{$type} eq '0') {
1.104 raeburn 14779: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14780: } else {
14781: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14782: }
14783: } else {
14784: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14785: }
1.72 raeburn 14786: }
14787: }
1.26 raeburn 14788: }
1.163 raeburn 14789: unless ($context eq 'requestauthor') {
14790: $resulttext .= '</ul></li>';
14791: }
1.26 raeburn 14792: }
1.1 raeburn 14793: }
1.163 raeburn 14794: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14795: if (ref($changes{'notify'}) eq 'HASH') {
14796: if ($changes{'notify'}{'approval'}) {
14797: if (ref($confhash{'notify'}) eq 'HASH') {
14798: if ($confhash{'notify'}{'approval'}) {
14799: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14800: } else {
1.163 raeburn 14801: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14802: }
14803: }
14804: }
14805: }
14806: }
1.216 raeburn 14807: if ($action eq 'requestcourses') {
14808: my @offon = ('off','on');
14809: if ($changes{'uniquecode'}) {
1.218 raeburn 14810: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14811: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14812: $resulttext .= '<li>'.
14813: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14814: '</li>';
14815: } else {
14816: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14817: '</li>';
14818: }
1.216 raeburn 14819: }
1.242 raeburn 14820: foreach my $type ('textbooks','templates') {
14821: if (ref($changes{$type}) eq 'HASH') {
14822: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14823: foreach my $key (sort(keys(%{$changes{$type}}))) {
14824: my %coursehash = &Apache::lonnet::coursedescription($key);
14825: my $coursetitle = $coursehash{'description'};
14826: my $position = $confhash{$type}{$key}{'order'} + 1;
14827: $resulttext .= '<li>';
1.243 raeburn 14828: foreach my $item ('subject','title','publisher','author') {
14829: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14830: ($type eq 'templates'));
1.242 raeburn 14831: my $name = $item.':';
14832: $name =~ s/^(\w)/\U$1/;
14833: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14834: }
14835: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14836: if ($type eq 'textbooks') {
14837: if ($confhash{$type}{$key}{'image'}) {
14838: $resulttext .= ' '.&mt('Image: [_1]',
14839: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14840: ' alt="Textbook cover" />').'<br />';
14841: }
14842: }
14843: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14844: }
1.242 raeburn 14845: $resulttext .= '</ul></li>';
1.216 raeburn 14846: }
14847: }
1.235 raeburn 14848: if (ref($changes{'validation'}) eq 'HASH') {
14849: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14850: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14851: foreach my $item (@{$validationitemsref}) {
14852: if (exists($changes{'validation'}{$item})) {
14853: if ($item eq 'markup') {
14854: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14855: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14856: } else {
14857: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14858: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14859: }
14860: }
14861: }
14862: if (exists($changes{'validation'}{'dc'})) {
14863: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14864: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14865: }
1.442 raeburn 14866: $resulttext .= '</ul></li>';
1.235 raeburn 14867: }
14868: }
1.216 raeburn 14869: }
1.1 raeburn 14870: $resulttext .= '</ul>';
1.80 raeburn 14871: if (keys(%newenv)) {
14872: &Apache::lonnet::appenv(\%newenv);
14873: }
1.1 raeburn 14874: } else {
1.86 raeburn 14875: if ($context eq 'requestcourses') {
14876: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14877: } elsif ($context eq 'requestauthor') {
14878: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14879: } else {
1.90 weissno 14880: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14881: }
1.1 raeburn 14882: }
14883: } else {
1.11 albertel 14884: $resulttext = '<span class="LC_error">'.
14885: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14886: }
1.216 raeburn 14887: if ($errors) {
14888: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14889: '<ul>'.$errors.'</ul></p>';
14890: }
1.3 raeburn 14891: return $resulttext;
1.1 raeburn 14892: }
14893:
1.216 raeburn 14894: sub process_textbook_image {
1.242 raeburn 14895: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14896: my $filename = $env{'form.'.$caller.'.filename'};
14897: my ($error,$url);
14898: my ($width,$height) = (50,50);
14899: if ($configuserok eq 'ok') {
14900: if ($switchserver) {
14901: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14902: $switchserver);
14903: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14904: my $modified = [];
1.216 raeburn 14905: my ($result,$imageurl) =
1.421 raeburn 14906: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14907: "$type/$cdom/$cnum/cover",$width,$height,
14908: '',$modified);
1.216 raeburn 14909: if ($result eq 'ok') {
14910: $url = $imageurl;
1.421 raeburn 14911: &update_modify_urls($r,$modified);
1.216 raeburn 14912: } else {
14913: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14914: }
14915: } else {
14916: $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);
14917: }
14918: } else {
14919: $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);
14920: }
14921: return ($url,$error);
14922: }
14923:
1.267 raeburn 14924: sub modify_ltitools {
14925: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14926: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14927: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14928:
1.267 raeburn 14929: my $confname = $dom.'-domainconfig';
14930: my $servadm = $r->dir_config('lonAdmEMail');
14931: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14932:
14933: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14934: my $toolserror =
14935: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14936: $lastactref,$configuserok,$switchserver,$author_ok);
14937:
14938: my $home = &Apache::lonnet::domain($dom,'primary');
14939: unless (($home eq 'no_host') || ($home eq '')) {
14940: my @ids=&Apache::lonnet::current_machine_ids();
14941: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14942: }
14943:
14944: if (keys(%ltitoolschg)) {
14945: foreach my $id (keys(%ltitoolschg)) {
14946: if (ref($ltitoolschg{$id}) eq 'HASH') {
14947: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14948: if (($inner eq 'secret') || ($inner eq 'key')) {
14949: if ($is_home) {
14950: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14951: }
14952: }
14953: }
1.267 raeburn 14954: }
1.421 raeburn 14955: }
14956: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14957: if (keys(%ltitoolschg)) {
14958: %newltitools = %ltitoolschg;
14959: }
14960: }
14961: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14962: foreach my $id (%{$domconfig{'ltitools'}}) {
14963: next if ($id !~ /^\d+$/);
14964: unless (exists($ltitoolschg{$id})) {
14965: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14966: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14967: if (($inner eq 'secret') || ($inner eq 'key')) {
14968: if ($is_home) {
14969: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14970: }
14971: } else {
14972: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14973: }
14974: }
14975: } else {
14976: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14977: }
1.421 raeburn 14978: }
14979: }
14980: }
14981: if ($toolserror) {
14982: $errors = '<li>'.$toolserror.'</li>';
14983: }
14984: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14985: $resulttext = &mt('No changes made.');
14986: if ($errors) {
14987: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14988: $errors.'</ul>';
14989: }
14990: return $resulttext;
14991: }
14992: my %ltitoolshash = (
14993: $action => { %newltitools }
14994: );
14995: if (keys(%secchanges)) {
14996: $ltitoolshash{'toolsec'} = \%newtoolsec;
14997: }
14998: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14999: if ($putresult eq 'ok') {
15000: my %keystore;
15001: if ($is_home) {
15002: my %toolsenchash = (
15003: $action => { %newtoolsenc }
15004: );
15005: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 15006: my $cachetime = 24*60*60;
15007: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 15008: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
15009: }
15010: $resulttext = &mt('Changes made:').'<ul>';
15011: if (keys(%secchanges) > 0) {
1.423 raeburn 15012: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15013: }
15014: if (keys(%ltitoolschg) > 0) {
15015: $resulttext .= $ltitoolsoutput;
15016: }
1.423 raeburn 15017: my $cachetime = 24*60*60;
15018: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15019: if (ref($lastactref) eq 'HASH') {
15020: $lastactref->{'ltitools'} = 1;
15021: }
1.421 raeburn 15022: } else {
15023: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15024: }
15025: if ($errors) {
15026: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15027: $errors.'</ul></p>';
15028: }
15029: return $resulttext;
15030: }
15031:
15032: sub fetch_secrets {
15033: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15034: my %keyset;
15035: %{$currsec} = ();
15036: $newsec->{'private'}{'keys'} = [];
15037: $newsec->{'encrypt'} = {};
15038: $newsec->{'rules'} = {};
15039: if ($context eq 'ltisec') {
15040: $newsec->{'linkprot'} = {};
15041: }
15042: if (ref($domconfig->{$context}) eq 'HASH') {
15043: %{$currsec} = %{$domconfig->{$context}};
15044: if ($context eq 'ltisec') {
15045: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15046: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15047: unless ($id =~ /^\d+$/) {
15048: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15049: }
1.267 raeburn 15050: }
15051: }
1.421 raeburn 15052: }
15053: if (ref($currsec->{'private'}) eq 'HASH') {
15054: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15055: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15056: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15057: }
1.421 raeburn 15058: }
15059: }
15060: my @items= ('crs','dom');
15061: if ($context eq 'ltisec') {
15062: push(@items,'consumers');
15063: }
15064: foreach my $item (@items) {
15065: my $formelement;
15066: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15067: $formelement = 'form.'.$context.'_'.$item;
15068: } else {
15069: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15070: }
15071: if ($env{$formelement}) {
15072: $newsec->{'encrypt'}{$item} = 1;
15073: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15074: unless ($currsec->{'encrypt'}{$item}) {
15075: $secchanges->{'encrypt'} = 1;
15076: }
15077: } else {
15078: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15079: }
1.421 raeburn 15080: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15081: if ($currsec->{'encrypt'}{$item}) {
15082: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15083: }
1.421 raeburn 15084: }
15085: }
15086: my $secrets;
15087: if ($context eq 'ltisec') {
15088: $secrets = 'ltisecrets';
15089: } else {
15090: $secrets = 'toolsecrets';
15091: }
15092: unless (exists($currsec->{'rules'})) {
15093: $currsec->{'rules'} = {};
15094: }
15095: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15096:
15097: my @ids=&Apache::lonnet::current_machine_ids();
15098: my %servers = &Apache::lonnet::get_servers($dom,'library');
15099:
15100: foreach my $hostid (keys(%servers)) {
15101: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15102: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15103: if (exists($env{$keyitem})) {
15104: $env{$keyitem} =~ s/(`)/'/g;
15105: if ($keyset{$hostid}) {
15106: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15107: if ($env{$keyitem} ne '') {
15108: $secchanges->{'private'} = 1;
15109: $newkeyset->{$hostid} = $env{$keyitem};
15110: }
1.296 raeburn 15111: }
1.421 raeburn 15112: } elsif ($env{$keyitem} ne '') {
15113: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15114: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15115: }
1.421 raeburn 15116: $secchanges->{'private'} = 1;
15117: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15118: }
15119: }
1.421 raeburn 15120: }
15121: }
15122: }
15123:
15124: sub store_security {
1.424 raeburn 15125: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15126: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15127: (ref($keystore) eq 'HASH'));
15128: if (keys(%{$secchanges})) {
15129: if ($secchanges->{'private'}) {
15130: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15131: foreach my $hostid (keys(%{$newkeyset})) {
15132: my $storehash = {
15133: key => $newkeyset->{$hostid},
15134: who => $env{'user.name'}.':'.$env{'user.domain'},
15135: };
15136: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15137: $dom,$hostid);
15138: }
15139: }
15140: }
15141: }
15142:
15143: sub lti_security_results {
1.423 raeburn 15144: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15145: my $output;
1.423 raeburn 15146: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15147: my $needs_update;
1.421 raeburn 15148: foreach my $item (keys(%{$secchanges})) {
15149: if ($item eq 'encrypt') {
1.423 raeburn 15150: $needs_update = 1;
1.421 raeburn 15151: my %encrypted;
15152: if ($context eq 'lti') {
15153: %encrypted = (
15154: crs => {
15155: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15156: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15157: },
15158: dom => {
15159: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15160: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15161: },
15162: consumers => {
15163: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15164: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15165: },
15166: );
1.267 raeburn 15167: } else {
1.421 raeburn 15168: %encrypted = (
15169: crs => {
15170: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15171: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15172: },
15173: dom => {
15174: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15175: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15176: },
15177: );
15178: }
15179: my @types= ('crs','dom');
15180: if ($context eq 'lti') {
1.423 raeburn 15181: foreach my $type (@types) {
15182: undef($domdefaults{'linkprotenc_'.$type});
15183: }
1.421 raeburn 15184: push(@types,'consumers');
1.423 raeburn 15185: undef($domdefaults{'ltienc_consumers'});
15186: } elsif ($context eq 'ltitools') {
15187: foreach my $type (@types) {
15188: undef($domdefaults{'toolenc_'.$type});
15189: }
1.267 raeburn 15190: }
1.421 raeburn 15191: foreach my $type (@types) {
15192: my $shown = $encrypted{$type}{'off'};
15193: if (ref($newsec->{$item}) eq 'HASH') {
15194: if ($newsec->{$item}{$type}) {
1.423 raeburn 15195: if ($context eq 'lti') {
15196: if ($type eq 'consumers') {
15197: $domdefaults{'ltienc_consumers'} = 1;
15198: } else {
15199: $domdefaults{'linkprotenc_'.$type} = 1;
15200: }
15201: } elsif ($context eq 'ltitools') {
15202: $domdefaults{'toolenc_'.$type} = 1;
15203: }
1.421 raeburn 15204: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15205: }
1.267 raeburn 15206: }
1.421 raeburn 15207: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15208: }
1.421 raeburn 15209: } elsif ($item eq 'rules') {
15210: my %titles = &Apache::lonlocal::texthash(
15211: min => 'Minimum password length',
15212: max => 'Maximum password length',
15213: chars => 'Required characters',
15214: );
15215: foreach my $rule ('min','max') {
15216: if ($newsec->{rules}{$rule} eq '') {
15217: if ($rule eq 'min') {
15218: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15219: ' '.&mt('Default of [_1] will be used',
15220: $Apache::lonnet::passwdmin).'</li>';
15221: } else {
15222: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15223: }
15224: } else {
15225: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15226: }
15227: }
15228: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15229: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15230: my %rulenames = &Apache::lonlocal::texthash(
15231: uc => 'At least one upper case letter',
15232: lc => 'At least one lower case letter',
15233: num => 'At least one number',
15234: spec => 'At least one non-alphanumeric',
15235: );
15236: my $needed = '<ul><li>'.
15237: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15238: '</li></ul>';
15239: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15240: } else {
15241: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15242: }
1.421 raeburn 15243: } else {
15244: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15245: }
1.421 raeburn 15246: } elsif ($item eq 'private') {
1.423 raeburn 15247: $needs_update = 1;
15248: if ($context eq 'lti') {
15249: undef($domdefaults{'ltiprivhosts'});
15250: } elsif ($context eq 'ltitools') {
15251: undef($domdefaults{'toolprivhosts'});
15252: }
1.421 raeburn 15253: if (keys(%{$newkeyset})) {
1.423 raeburn 15254: my @privhosts;
1.421 raeburn 15255: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15256: if ($keystore->{$hostid} eq 'ok') {
15257: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15258: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15259: push(@privhosts,$hostid);
15260: }
15261: }
15262: }
15263: if (@privhosts) {
15264: if ($context eq 'lti') {
15265: $domdefaults{'ltiprivhosts'} = \@privhosts;
15266: } elsif ($context eq 'ltitools') {
15267: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15268: }
15269: }
15270: }
1.421 raeburn 15271: } elsif ($item eq 'linkprot') {
15272: next;
1.434 raeburn 15273: } elsif ($item eq 'suggested') {
15274: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15275: (ref($newsec->{'suggested'}) eq 'HASH')) {
15276: my $suggestions;
15277: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15278: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15279: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15280: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15281: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15282: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15283: '</li>';
15284: } else {
15285: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15286: $newsec->{'suggested'}->{$id}).'</li>';
15287: }
15288: }
15289: if ($suggestions) {
15290: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15291: '<ul>'.$suggestions.'</ul>'.
15292: '</li>';
15293: }
15294: }
1.267 raeburn 15295: }
15296: }
1.423 raeburn 15297: if ($needs_update) {
15298: my $cachetime = 24*60*60;
15299: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15300: }
1.421 raeburn 15301: return $output;
15302: }
15303:
15304: sub modify_proctoring {
15305: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15306: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15307: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15308: my $confname = $dom.'-domainconfig';
15309: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15310: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15311: my %providernames = &proctoring_providernames();
15312: my $maxnum = scalar(keys(%providernames));
15313:
15314: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15315: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15316: if (ref($requref) eq 'HASH') {
15317: %requserfields = %{$requref};
15318: }
15319: if (ref($opturef) eq 'HASH') {
15320: %optuserfields = %{$opturef};
15321: }
15322: if (ref($defref) eq 'HASH') {
15323: %defaults = %{$defref};
15324: }
15325: if (ref($extref) eq 'HASH') {
15326: %extended = %{$extref};
15327: }
15328: if (ref($crsref) eq 'HASH') {
15329: %crsconf = %{$crsref};
15330: }
15331: if (ref($rolesref) eq 'ARRAY') {
15332: @courseroles = @{$rolesref};
15333: }
15334: if (ref($ltiref) eq 'ARRAY') {
15335: @ltiroles = @{$ltiref};
15336: }
15337:
15338: if (ref($domconfig{$action}) eq 'HASH') {
15339: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15340: if (@todeleteimages) {
15341: map { $imgdeletions{$_} = 1; } @todeleteimages;
15342: }
15343: }
15344: my %customadds;
15345: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15346: if (@newcustom) {
15347: map { $customadds{$_} = 1; } @newcustom;
15348: }
15349: foreach my $provider (sort(keys(%providernames))) {
15350: $confhash{$provider} = {};
15351: my $pos = $env{'form.proctoring_pos_'.$provider};
15352: $pos =~ s/\D+//g;
15353: $allpos[$pos] = $provider;
15354: my (%current,%currentenc);
15355: my $showroles = 0;
15356: if (ref($domconfig{$action}) eq 'HASH') {
15357: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15358: %current = %{$domconfig{$action}{$provider}};
15359: foreach my $item ('key','secret') {
15360: $currentenc{$item} = $current{$item};
15361: delete($current{$item});
15362: }
15363: }
15364: }
15365: if ($env{'form.proctoring_available_'.$provider}) {
15366: $confhash{$provider}{'available'} = 1;
15367: unless ($current{'available'}) {
15368: $changes{$provider} = 1;
15369: }
15370: } else {
15371: %{$confhash{$provider}} = %current;
15372: %{$encconfhash{$provider}} = %currentenc;
15373: $confhash{$provider}{'available'} = 0;
15374: if ($current{'available'}) {
15375: $changes{$provider} = 1;
15376: }
15377: }
15378: if ($confhash{$provider}{'available'}) {
15379: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15380: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15381: if ($field eq 'lifetime') {
15382: if ($possval =~ /^\d+$/) {
15383: $confhash{$provider}{$field} = $possval;
15384: }
15385: } elsif ($field eq 'version') {
15386: if ($possval =~ /^\d+\.\d+$/) {
15387: $confhash{$provider}{$field} = $possval;
15388: }
15389: } elsif ($field eq 'sigmethod') {
15390: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15391: $confhash{$provider}{$field} = $possval;
15392: }
15393: } elsif ($field eq 'url') {
15394: $confhash{$provider}{$field} = $possval;
15395: } elsif (($field eq 'key') || ($field eq 'secret')) {
15396: $encconfhash{$provider}{$field} = $possval;
15397: unless ($currentenc{$field} eq $possval) {
15398: $changes{$provider} = 1;
15399: }
15400: }
15401: unless (($field eq 'key') || ($field eq 'secret')) {
15402: unless ($current{$field} eq $confhash{$provider}{$field}) {
15403: $changes{$provider} = 1;
15404: }
15405: }
15406: }
15407: if ($imgdeletions{$provider}) {
15408: $changes{$provider} = 1;
15409: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15410: my ($imageurl,$error) =
15411: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15412: $configuserok,$switchserver,$author_ok);
15413: if ($imageurl) {
15414: $confhash{$provider}{'image'} = $imageurl;
15415: $changes{$provider} = 1;
15416: }
15417: if ($error) {
15418: &Apache::lonnet::logthis($error);
15419: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15420: }
15421: } elsif (exists($current{'image'})) {
15422: $confhash{$provider}{'image'} = $current{'image'};
15423: }
15424: if (ref($requserfields{$provider}) eq 'ARRAY') {
15425: if (@{$requserfields{$provider}} > 0) {
15426: if (grep(/^user$/,@{$requserfields{$provider}})) {
15427: if ($env{'form.proctoring_userincdom_'.$provider}) {
15428: $confhash{$provider}{'incdom'} = 1;
15429: }
15430: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15431: $changes{$provider} = 1;
15432: }
15433: }
15434: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15435: $showroles = 1;
15436: }
15437: }
15438: }
15439: $confhash{$provider}{'fields'} = [];
15440: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15441: if (@{$optuserfields{$provider}} > 0) {
15442: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15443: foreach my $field (@{$optuserfields{$provider}}) {
15444: if (grep(/^\Q$field\E$/,@optfields)) {
15445: push(@{$confhash{$provider}{'fields'}},$field);
15446: }
15447: }
15448: }
15449: if (ref($current{'fields'}) eq 'ARRAY') {
15450: unless ($changes{$provider}) {
15451: my @new = sort(@{$confhash{$provider}{'fields'}});
15452: my @old = sort(@{$current{'fields'}});
15453: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15454: if (@diffs) {
15455: $changes{$provider} = 1;
15456: }
15457: }
15458: } elsif (@{$confhash{$provider}{'fields'}}) {
15459: $changes{$provider} = 1;
15460: }
15461: }
15462: if (ref($defaults{$provider}) eq 'ARRAY') {
15463: if (@{$defaults{$provider}} > 0) {
15464: my %options;
15465: if (ref($extended{$provider}) eq 'HASH') {
15466: %options = %{$extended{$provider}};
15467: }
15468: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15469: foreach my $field (@{$defaults{$provider}}) {
15470: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15471: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15472: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15473: push(@{$confhash{$provider}{'defaults'}},$poss);
15474: }
15475: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15476: foreach my $inner (keys(%{$options{$field}})) {
15477: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15478: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15479: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15480: $confhash{$provider}{'defaults'}{$inner} = $poss;
15481: }
15482: } else {
15483: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15484: }
15485: }
15486: } else {
15487: if (grep(/^\Q$field\E$/,@checked)) {
15488: push(@{$confhash{$provider}{'defaults'}},$field);
15489: }
15490: }
15491: }
15492: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15493: if (ref($current{'defaults'}) eq 'ARRAY') {
15494: unless ($changes{$provider}) {
15495: my @new = sort(@{$confhash{$provider}{'defaults'}});
15496: my @old = sort(@{$current{'defaults'}});
15497: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15498: if (@diffs) {
15499: $changes{$provider} = 1;
15500: }
15501: }
15502: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15503: if (@{$current{'defaults'}}) {
15504: $changes{$provider} = 1;
15505: }
15506: }
15507: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15508: if (ref($current{'defaults'}) eq 'HASH') {
15509: unless ($changes{$provider}) {
15510: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15511: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15512: $changes{$provider} = 1;
15513: last;
15514: }
15515: }
15516: }
15517: unless ($changes{$provider}) {
15518: foreach my $key (keys(%{$current{'defaults'}})) {
15519: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15520: $changes{$provider} = 1;
15521: last;
15522: }
15523: }
15524: }
15525: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15526: $changes{$provider} = 1;
15527: }
15528: }
15529: }
15530: }
15531: if (ref($crsconf{$provider}) eq 'ARRAY') {
15532: if (@{$crsconf{$provider}} > 0) {
15533: $confhash{$provider}{'crsconf'} = [];
15534: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15535: foreach my $crsfield (@{$crsconf{$provider}}) {
15536: if (grep(/^\Q$crsfield\E$/,@checked)) {
15537: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15538: }
15539: }
15540: if (ref($current{'crsconf'}) eq 'ARRAY') {
15541: unless ($changes{$provider}) {
15542: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15543: my @old = sort(@{$current{'crsconf'}});
15544: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15545: if (@diffs) {
15546: $changes{$provider} = 1;
15547: }
15548: }
15549: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15550: $changes{$provider} = 1;
15551: }
15552: }
15553: }
15554: if ($showroles) {
15555: $confhash{$provider}{'roles'} = {};
15556: foreach my $role (@courseroles) {
15557: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15558: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15559: $confhash{$provider}{'roles'}{$role} = $poss;
15560: }
15561: }
15562: unless ($changes{$provider}) {
15563: if (ref($current{'roles'}) eq 'HASH') {
15564: foreach my $role (keys(%{$current{'roles'}})) {
15565: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15566: $changes{$provider} = 1;
15567: last
15568: }
15569: }
15570: unless ($changes{$provider}) {
15571: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15572: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15573: $changes{$provider} = 1;
15574: last;
15575: }
15576: }
15577: }
15578: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15579: $changes{$provider} = 1;
15580: }
15581: }
15582: }
15583: if (ref($current{'custom'}) eq 'HASH') {
15584: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15585: foreach my $key (keys(%{$current{'custom'}})) {
15586: if (grep(/^\Q$key\E$/,@customdels)) {
15587: $changes{$provider} = 1;
15588: } else {
15589: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15590: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15591: $changes{$provider} = 1;
15592: }
15593: }
15594: }
15595: }
15596: if ($customadds{$provider}) {
15597: my $name = $env{'form.proctoring_custom_name_'.$provider};
15598: $name =~ s/(`)/'/g;
15599: $name =~ s/^\s+//;
15600: $name =~ s/\s+$//;
15601: my $value = $env{'form.proctoring_custom_value_'.$provider};
15602: $value =~ s/(`)/'/g;
15603: $value =~ s/^\s+//;
15604: $value =~ s/\s+$//;
15605: if ($name ne '') {
15606: $confhash{$provider}{'custom'}{$name} = $value;
15607: $changes{$provider} = 1;
15608: }
15609: }
15610: }
15611: }
15612: if (@allpos > 0) {
15613: my $idx = 0;
15614: foreach my $provider (@allpos) {
15615: if ($provider ne '') {
15616: $confhash{$provider}{'order'} = $idx;
15617: unless ($changes{$provider}) {
15618: if (ref($domconfig{$action}) eq 'HASH') {
15619: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15620: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15621: $changes{$provider} = 1;
15622: }
15623: }
15624: }
15625: }
15626: $idx ++;
15627: }
15628: }
15629: }
15630: my %proc_hash = (
15631: $action => { %confhash }
15632: );
15633: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15634: $dom);
15635: if ($putresult eq 'ok') {
15636: my %proc_enchash = (
15637: $action => { %encconfhash }
15638: );
1.384 raeburn 15639: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15640: if (keys(%changes) > 0) {
15641: my $cachetime = 24*60*60;
15642: my %procall = %confhash;
15643: foreach my $provider (keys(%procall)) {
15644: if (ref($encconfhash{$provider}) eq 'HASH') {
15645: foreach my $key ('key','secret') {
15646: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15647: }
15648: }
15649: }
15650: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15651: if (ref($lastactref) eq 'HASH') {
15652: $lastactref->{'proctoring'} = 1;
15653: }
15654: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15655: my %bynum;
15656: foreach my $provider (sort(keys(%changes))) {
15657: my $position = $confhash{$provider}{'order'};
15658: $bynum{$position} = $provider;
15659: }
15660: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15661: my $provider = $bynum{$pos};
15662: my %lt = &proctoring_titles($provider);
15663: my %fieldtitles = &proctoring_fieldtitles($provider);
15664: if (!$confhash{$provider}{'available'}) {
15665: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15666: } else {
15667: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15668: if ($confhash{$provider}{'image'}) {
15669: $resulttext .= ' '.
15670: '<img src="'.$confhash{$provider}{'image'}.'"'.
15671: ' alt="'.&mt('Proctoring icon').'" />';
15672: }
15673: $resulttext .= '<ul>';
15674: my $position = $pos + 1;
15675: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15676: foreach my $key ('version','sigmethod','url','lifetime') {
15677: if ($confhash{$provider}{$key} ne '') {
15678: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15679: }
15680: }
15681: if ($encconfhash{$provider}{'key'} ne '') {
15682: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15683: }
15684: if ($encconfhash{$provider}{'secret'} ne '') {
15685: $resulttext .= '<li>'.$lt{'secret'}.': ';
15686: my $num = length($encconfhash{$provider}{'secret'});
15687: $resulttext .= ('*'x$num).'</li>';
15688: }
15689: my (@fields,$showroles);
15690: if (ref($requserfields{$provider}) eq 'ARRAY') {
15691: push(@fields,@{$requserfields{$provider}});
15692: }
15693: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15694: push(@fields,@{$confhash{$provider}{'fields'}});
15695: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15696: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15697: }
15698: if (@fields) {
15699: if (grep(/^roles$/,@fields)) {
15700: $showroles = 1;
15701: }
15702: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15703: join('", "', map { $lt{$_}; } @fields).'"</li>';
15704: }
15705: if (ref($requserfields{$provider}) eq 'ARRAY') {
15706: if (grep(/^user$/,@{$requserfields{$provider}})) {
15707: if ($confhash{$provider}{'incdom'}) {
15708: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15709: } else {
15710: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15711: }
15712: }
15713: }
15714: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15715: if (@{$confhash{$provider}{'defaults'}} > 0) {
15716: $resulttext .= '<li>'.$lt{'defa'};
15717: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15718: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15719: }
15720: $resulttext =~ s/,$//;
15721: $resulttext .= '</li>';
15722: }
15723: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15724: if (keys(%{$confhash{$provider}{'defaults'}})) {
15725: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15726: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15727: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15728: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15729: }
15730: }
15731: $resulttext .= '</ul></li>';
15732: }
15733: }
15734: if (ref($crsconf{$provider}) eq 'ARRAY') {
15735: if (@{$crsconf{$provider}} > 0) {
15736: $resulttext .= '<li>'.&mt('Configurable in course:');
15737: my $numconfig = 0;
15738: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15739: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15740: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15741: $numconfig ++;
15742: if ($provider eq 'examity') {
15743: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15744: } else {
15745: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15746: }
15747: }
15748: $resulttext =~ s/,$//;
15749: }
15750: }
15751: if (!$numconfig) {
15752: $resulttext .= ' '.&mt('None');
15753: }
15754: $resulttext .= '</li>';
15755: }
15756: }
15757: if ($showroles) {
15758: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15759: my $rolemaps;
15760: foreach my $role (@courseroles) {
15761: if ($confhash{$provider}{'roles'}{$role}) {
15762: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15763: $confhash{$provider}{'roles'}{$role}.',';
15764: }
15765: }
15766: if ($rolemaps) {
15767: $rolemaps =~ s/,$//;
15768: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15769: }
15770: }
15771: }
15772: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15773: my $customlist;
15774: if (keys(%{$confhash{$provider}{'custom'}})) {
15775: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15776: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15777: }
15778: $customlist =~ s/,$//;
15779: }
15780: if ($customlist) {
15781: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15782: }
15783: }
15784: $resulttext .= '</ul></li>';
15785: }
15786: }
15787: $resulttext .= '</ul>';
15788: } else {
15789: $resulttext = &mt('No changes made.');
15790: }
15791: } else {
15792: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15793: }
15794: if ($errors) {
15795: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15796: $errors.'</ul>';
15797: }
15798: return $resulttext;
15799: }
15800:
15801: sub process_proctoring_image {
15802: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15803: my $filename = $env{'form.'.$caller.'.filename'};
15804: my ($error,$url);
15805: my ($width,$height) = (21,21);
15806: if ($configuserok eq 'ok') {
15807: if ($switchserver) {
15808: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15809: $switchserver);
15810: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15811: my $modified = [];
1.372 raeburn 15812: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15813: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15814: "proctoring/$provider/icon",$width,$height,
15815: '',$modified);
1.372 raeburn 15816: if ($result eq 'ok') {
15817: if ($madethumb) {
15818: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15819: my $imagethumb = "$path/tn-".$imagefile;
15820: $url = $imagethumb;
15821: } else {
15822: $url = $imageurl;
15823: }
1.421 raeburn 15824: &update_modify_urls($r,$modified);
1.372 raeburn 15825: } else {
15826: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15827: }
15828: } else {
15829: $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);
15830: }
15831: } else {
15832: $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);
15833: }
15834: return ($url,$error);
15835: }
15836:
1.320 raeburn 15837: sub modify_lti {
15838: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15839: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15840: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15841: my (%posslti,%posslticrs,%posscrstype);
15842: my @courseroles = ('cc','in','ta','ep','st');
15843: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15844: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15845: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15846: my %coursetypetitles = &Apache::lonlocal::texthash (
15847: official => 'Official',
15848: unofficial => 'Unofficial',
15849: community => 'Community',
15850: textbook => 'Textbook',
15851: placement => 'Placement Test',
1.392 raeburn 15852: lti => 'LTI Provider',
1.320 raeburn 15853: );
1.325 raeburn 15854: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15855: my %lt = <i_names();
15856: map { $posslti{$_} = 1; } @ltiroles;
15857: map { $posslticrs{$_} = 1; } @lticourseroles;
15858: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15859:
1.326 raeburn 15860: my %menutitles = <imenu_titles();
1.421 raeburn 15861: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15862:
1.421 raeburn 15863: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15864:
1.406 raeburn 15865: my (%linkprotchg,$linkprotoutput,$is_home);
15866: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15867: \%linkprotchg,'domain');
15868: my $home = &Apache::lonnet::domain($dom,'primary');
15869: unless (($home eq 'no_host') || ($home eq '')) {
15870: my @ids=&Apache::lonnet::current_machine_ids();
15871: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15872: }
15873:
15874: if (keys(%linkprotchg)) {
15875: $secchanges{'linkprot'} = 1;
15876: my %oldlinkprot;
15877: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15878: %oldlinkprot = %{$currltisec{'linkprot'}};
15879: }
15880: foreach my $id (keys(%linkprotchg)) {
15881: if (ref($linkprotchg{$id}) eq 'HASH') {
15882: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15883: if (($inner eq 'secret') || ($inner eq 'key')) {
15884: if ($is_home) {
15885: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15886: }
15887: }
15888: }
15889: } else {
15890: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15891: }
15892: }
15893: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15894: if (keys(%linkprotchg)) {
15895: %{$newltisec{'linkprot'}} = %linkprotchg;
15896: }
15897: }
15898: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15899: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15900: next if ($id !~ /^\d+$/);
15901: unless (exists($linkprotchg{$id})) {
15902: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15903: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15904: if (($inner eq 'secret') || ($inner eq 'key')) {
15905: if ($is_home) {
15906: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15907: }
15908: } else {
15909: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15910: }
15911: }
15912: } else {
15913: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15914: }
15915: }
15916: }
15917: }
15918: if ($proterror) {
15919: $errors .= '<li>'.$proterror.'</li>';
15920: }
1.434 raeburn 15921:
15922: my (%delsuggested,%suggids,@suggested);;
15923: if (ref($currltisec{'suggested'}) eq 'HASH') {
15924: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15925: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15926: for (my $i=0; $i<$maxnum; $i++) {
15927: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15928: $itemid =~ s/\D+//g;
15929: if ($itemid) {
15930: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15931: push(@suggested,$i);
15932: $suggids{$i} = $itemid;
15933: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15934: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15935: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15936: }
15937: } else {
15938: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15939: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15940: } else {
15941: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15942: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15943: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15944: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15945: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15946: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15947: $secchanges{'suggested'}{$itemid} = 1;
15948: }
15949: }
15950: }
15951: }
15952: }
15953: }
15954: }
15955: foreach my $key (keys(%delsuggested)) {
15956: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15957: $secchanges{'suggested'}{$key} = 1;
15958: }
15959: if (($env{'form.linkprot_suggested_add'}) &&
15960: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15961: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15962: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15963: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15964: if ($newsuggid) {
15965: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15966: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15967: $secchanges{'suggested'}{$newsuggid} = 1;
15968: } else {
15969: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15970: if ($errormsg) {
15971: $error .= ' ('.$errormsg.')';
15972: }
15973: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15974: }
15975: }
1.320 raeburn 15976: my (@items,%deletions,%itemids);
15977: if ($env{'form.lti_add'}) {
15978: my $consumer = $env{'form.lti_consumer_add'};
15979: $consumer =~ s/(`)/'/g;
1.434 raeburn 15980: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15981: if ($newid) {
15982: $itemids{'add'} = $newid;
15983: push(@items,'add');
15984: $changes{$newid} = 1;
15985: } else {
15986: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15987: if ($errormsg) {
15988: $error .= ' ('.$errormsg.')';
15989: }
1.320 raeburn 15990: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15991: }
15992: }
15993: if (ref($domconfig{$action}) eq 'HASH') {
15994: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15995: if (@todelete) {
15996: map { $deletions{$_} = 1; } @todelete;
15997: }
15998: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15999: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 16000: my $itemid = $env{'form.lti_id_'.$i};
16001: $itemid =~ s/\D+//g;
16002: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16003: if ($deletions{$itemid}) {
16004: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16005: } else {
1.390 raeburn 16006: push(@items,$i);
16007: $itemids{$i} = $itemid;
1.320 raeburn 16008: }
16009: }
16010: }
16011: }
1.424 raeburn 16012: my (%keystore,$secstored);
16013: if ($is_home) {
16014: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16015: }
16016:
16017: my ($cipher,$privnum);
16018: if ((@items > 0) && ($is_home)) {
16019: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16020: $newltisec{'encrypt'},$keystore{$home});
16021: }
1.320 raeburn 16022: foreach my $idx (@items) {
16023: my $itemid = $itemids{$idx};
16024: next unless ($itemid);
1.424 raeburn 16025: my %currlti;
16026: unless ($idx eq 'add') {
16027: if (ref($domconfig{$action}) eq 'HASH') {
16028: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16029: %currlti = %{$domconfig{$action}{$itemid}};
16030: }
16031: }
16032: }
1.390 raeburn 16033: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16034: $position =~ s/\D+//g;
16035: if ($position ne '') {
16036: $allpos[$position] = $itemid;
16037: }
1.424 raeburn 16038: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16039: my $formitem = 'form.lti_'.$item.'_'.$idx;
16040: $env{$formitem} =~ s/(`)/'/g;
16041: if ($item eq 'lifetime') {
16042: $env{$formitem} =~ s/[^\d.]//g;
16043: }
16044: if ($env{$formitem} ne '') {
1.424 raeburn 16045: $confhash{$itemid}{$item} = $env{$formitem};
16046: unless (($idx eq 'add') || ($changes{$itemid})) {
16047: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16048: $changes{$itemid} = 1;
1.320 raeburn 16049: }
16050: }
16051: }
16052: }
16053: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16054: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16055: }
1.345 raeburn 16056: if ($confhash{$itemid}{'requser'}) {
16057: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16058: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16059: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16060: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16061: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16062: my $mapuser = $env{'form.lti_customuser_'.$idx};
16063: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16064: $mapuser =~ s/^\s+|\s+$//g;
16065: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16066: }
16067: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16068: my @makeuser;
16069: foreach my $ltirole (sort(@possmakeuser)) {
16070: if ($posslti{$ltirole}) {
16071: push(@makeuser,$ltirole);
16072: }
16073: }
16074: $confhash{$itemid}{'makeuser'} = \@makeuser;
16075: if (@makeuser) {
16076: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16077: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16078: $confhash{$itemid}{'lcauth'} = $lcauth;
16079: if ($lcauth ne 'internal') {
16080: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16081: $lcauthparm =~ s/^(\s+|\s+)$//g;
16082: $lcauthparm =~ s/`//g;
16083: if ($lcauthparm ne '') {
16084: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16085: }
16086: }
16087: } else {
16088: $confhash{$itemid}{'lcauth'} = 'lti';
16089: }
1.320 raeburn 16090: }
1.345 raeburn 16091: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16092: if (@possinstdata) {
16093: foreach my $field (@possinstdata) {
16094: if (exists($fieldtitles{$field})) {
16095: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16096: }
16097: }
16098: }
1.363 raeburn 16099: if ($env{'form.lti_callback_'.$idx}) {
16100: if ($env{'form.lti_callbackparam_'.$idx}) {
16101: my $callback = $env{'form.lti_callbackparam_'.$idx};
16102: $callback =~ s/^\s+|\s+$//g;
16103: $confhash{$itemid}{'callback'} = $callback;
16104: }
16105: }
1.391 raeburn 16106: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16107: if ($env{'form.lti_'.$field.'_'.$idx}) {
16108: $confhash{$itemid}{$field} = 1;
16109: }
1.320 raeburn 16110: }
1.345 raeburn 16111: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16112: $confhash{$itemid}{lcmenu} = [];
16113: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16114: foreach my $field (@possmenu) {
16115: if (exists($menutitles{$field})) {
16116: if ($field eq 'grades') {
16117: next unless ($env{'form.lti_inlinemenu_'.$idx});
16118: }
16119: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16120: }
16121: }
16122: }
1.391 raeburn 16123: if ($confhash{$itemid}{'crsinc'}) {
16124: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16125: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16126: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16127: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16128: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16129: $mapcrs =~ s/(`)/'/g;
16130: $mapcrs =~ s/^\s+|\s+$//g;
16131: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16132: }
16133: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16134: my @crstypes;
16135: foreach my $type (sort(@posstypes)) {
16136: if ($posscrstype{$type}) {
16137: push(@crstypes,$type);
16138: }
16139: }
16140: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16141: if ($env{'form.lti_storecrs_'.$idx}) {
16142: $confhash{$itemid}{'storecrs'} = 1;
16143: }
1.391 raeburn 16144: if ($env{'form.lti_makecrs_'.$idx}) {
16145: $confhash{$itemid}{'makecrs'} = 1;
16146: }
16147: foreach my $ltirole (@lticourseroles) {
16148: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16149: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16150: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16151: }
16152: }
16153: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16154: my @selfenroll;
16155: foreach my $type (sort(@possenroll)) {
16156: if ($posslticrs{$type}) {
16157: push(@selfenroll,$type);
16158: }
16159: }
16160: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16161: if ($env{'form.lti_crssec_'.$idx}) {
16162: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16163: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16164: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16165: my $section = $env{'form.lti_customsection_'.$idx};
16166: $section =~ s/(`)/'/g;
16167: $section =~ s/^\s+|\s+$//g;
16168: if ($section ne '') {
16169: $confhash{$itemid}{'section'} = $section;
16170: }
16171: }
16172: }
16173: foreach my $field ('passback','roster') {
16174: if ($env{'form.lti_'.$field.'_'.$idx}) {
16175: $confhash{$itemid}{$field} = 1;
16176: }
16177: }
16178: if ($env{'form.lti_passback_'.$idx}) {
16179: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16180: $confhash{$itemid}{'passbackformat'} = '1.0';
16181: } else {
16182: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16183: }
16184: }
1.391 raeburn 16185: }
16186: unless (($idx eq 'add') || ($changes{$itemid})) {
16187: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16188: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16189: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16190: $changes{$itemid} = 1;
16191: }
1.345 raeburn 16192: }
16193: unless ($changes{$itemid}) {
1.424 raeburn 16194: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16195: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16196: $changes{$itemid} = 1;
16197: }
16198: }
1.345 raeburn 16199: }
1.391 raeburn 16200: foreach my $field ('mapcrstype','selfenroll') {
16201: unless ($changes{$itemid}) {
1.424 raeburn 16202: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16203: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16204: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16205: $confhash{$itemid}{$field});
16206: if (@diffs) {
16207: $changes{$itemid} = 1;
16208: }
1.424 raeburn 16209: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16210: $changes{$itemid} = 1;
16211: }
16212: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16213: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16214: $changes{$itemid} = 1;
16215: }
16216: }
1.391 raeburn 16217: }
16218: }
16219: unless ($changes{$itemid}) {
1.424 raeburn 16220: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16221: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16222: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16223: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16224: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16225: $changes{$itemid} = 1;
16226: last;
16227: }
16228: }
1.391 raeburn 16229: unless ($changes{$itemid}) {
16230: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16231: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16232: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16233: $changes{$itemid} = 1;
16234: last;
16235: }
16236: }
16237: }
1.424 raeburn 16238: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16239: $changes{$itemid} = 1;
1.345 raeburn 16240: }
1.391 raeburn 16241: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16242: unless ($changes{$itemid}) {
16243: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16244: $changes{$itemid} = 1;
16245: }
16246: }
16247: }
16248: }
16249: }
16250: unless ($changes{$itemid}) {
16251: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16252: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16253: $changes{$itemid} = 1;
1.320 raeburn 16254: }
1.391 raeburn 16255: }
16256: unless ($changes{$itemid}) {
16257: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16258: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16259: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16260: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16261: $confhash{$itemid}{$field});
16262: if (@diffs) {
16263: $changes{$itemid} = 1;
16264: }
1.424 raeburn 16265: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16266: $changes{$itemid} = 1;
16267: }
16268: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16269: if (@{$confhash{$itemid}{$field}} > 0) {
16270: $changes{$itemid} = 1;
16271: }
1.345 raeburn 16272: }
1.320 raeburn 16273: }
16274: }
16275: }
16276: }
16277: }
1.424 raeburn 16278: if ($is_home) {
16279: my $keyitem = 'form.lti_key_'.$idx;
16280: $env{$keyitem} =~ s/(`)/'/g;
16281: if ($env{$keyitem} ne '') {
16282: $ltienc{$itemid}{'key'} = $env{$keyitem};
16283: unless ($changes{$itemid}) {
16284: if ($currlti{'key'} ne $env{$keyitem}) {
16285: $changes{$itemid} = 1;
16286: }
16287: }
16288: }
16289: my $secretitem = 'form.lti_secret_'.$idx;
16290: $env{$secretitem} =~ s/(`)/'/g;
16291: if ($currlti{'usable'}) {
16292: if ($env{'form.lti_changesecret_'.$idx}) {
16293: if ($env{$secretitem} ne '') {
16294: if ($privnum && $cipher) {
16295: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16296: $confhash{$itemid}{'cipher'} = $privnum;
16297: } else {
16298: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16299: }
16300: $changes{$itemid} = 1;
16301: }
16302: } else {
16303: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16304: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16305: }
16306: if (ref($ltienc{$itemid}) eq 'HASH') {
16307: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16308: $confhash{$itemid}{'usable'} = 1;
16309: }
16310: }
16311: } elsif ($env{$secretitem} ne '') {
16312: if ($privnum && $cipher) {
16313: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16314: $confhash{$itemid}{'cipher'} = $privnum;
16315: } else {
16316: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16317: }
16318: if (ref($ltienc{$itemid}) eq 'HASH') {
16319: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16320: $confhash{$itemid}{'usable'} = 1;
16321: }
16322: }
16323: $changes{$itemid} = 1;
16324: }
16325: }
16326: unless ($changes{$itemid}) {
16327: foreach my $key (keys(%currlti)) {
16328: if (ref($currlti{$key}) eq 'HASH') {
16329: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16330: foreach my $innerkey (keys(%{$currlti{$key}})) {
16331: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16332: $changes{$itemid} = 1;
16333: last;
16334: }
16335: }
16336: } elsif (keys(%{$currlti{$key}}) > 0) {
16337: $changes{$itemid} = 1;
16338: }
16339: }
16340: last if ($changes{$itemid});
16341: }
16342: }
1.320 raeburn 16343: }
16344: if (@allpos > 0) {
16345: my $idx = 0;
16346: foreach my $itemid (@allpos) {
16347: if ($itemid ne '') {
16348: $confhash{$itemid}{'order'} = $idx;
16349: if (ref($domconfig{$action}) eq 'HASH') {
16350: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16351: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16352: $changes{$itemid} = 1;
16353: }
16354: }
16355: }
16356: $idx ++;
16357: }
16358: }
16359: }
1.424 raeburn 16360:
16361: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16362: return &mt('No changes made.');
16363: }
16364:
1.320 raeburn 16365: my %ltihash = (
1.405 raeburn 16366: $action => { %confhash }
16367: );
1.424 raeburn 16368: my %ltienchash;
16369:
16370: if ($is_home) {
16371: %ltienchash = (
16372: $action => { %ltienc }
16373: );
16374: }
1.405 raeburn 16375: if (keys(%secchanges)) {
16376: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16377: if ($secchanges{'linkprot'}) {
16378: if ($is_home) {
16379: $ltienchash{'linkprot'} = \%newltienc;
16380: }
16381: }
1.405 raeburn 16382: }
16383: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16384: if ($putresult eq 'ok') {
1.424 raeburn 16385: if (keys(%ltienchash)) {
16386: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16387: }
16388: $resulttext = &mt('Changes made:').'<ul>';
16389: if (keys(%secchanges) > 0) {
1.423 raeburn 16390: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16391: if (exists($secchanges{'linkprot'})) {
16392: $resulttext .= $linkprotoutput;
1.405 raeburn 16393: }
16394: }
1.320 raeburn 16395: if (keys(%changes) > 0) {
16396: my $cachetime = 24*60*60;
1.424 raeburn 16397: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16398: if (ref($lastactref) eq 'HASH') {
16399: $lastactref->{'lti'} = 1;
16400: }
16401: my %bynum;
16402: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16403: if (ref($confhash{$itemid}) eq 'HASH') {
16404: my $position = $confhash{$itemid}{'order'};
16405: $bynum{$position} = $itemid;
16406: }
1.320 raeburn 16407: }
16408: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16409: my $itemid = $bynum{$pos};
1.424 raeburn 16410: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16411: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16412: my $position = $pos + 1;
16413: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16414: foreach my $item ('version','lifetime') {
16415: if ($confhash{$itemid}{$item} ne '') {
16416: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16417: }
16418: }
1.424 raeburn 16419: if ($ltienc{$itemid}{'key'} ne '') {
16420: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16421: }
1.424 raeburn 16422: if ($ltienc{$itemid}{'secret'} ne '') {
16423: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16424: }
1.345 raeburn 16425: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16426: if ($confhash{$itemid}{'callback'}) {
16427: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16428: } else {
1.392 raeburn 16429: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16430: }
1.345 raeburn 16431: if ($confhash{$itemid}{'mapuser'}) {
16432: my $shownmapuser;
16433: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16434: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16435: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16436: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16437: } else {
16438: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16439: }
1.345 raeburn 16440: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16441: }
1.345 raeburn 16442: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16443: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16444: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16445: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16446: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16447: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16448: } else {
16449: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16450: $confhash{$itemid}{'lcauth'});
16451: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16452: $resulttext .= '; '.&mt('a randomly generated password will be created');
16453: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16454: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16455: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16456: }
16457: } else {
16458: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16459: }
16460: }
16461: $resulttext .= '</li>';
16462: } else {
16463: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16464: }
1.320 raeburn 16465: }
1.345 raeburn 16466: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16467: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16468: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16469: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16470: } else {
1.345 raeburn 16471: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16472: }
1.320 raeburn 16473: }
1.391 raeburn 16474: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16475: $resulttext .= '<li>'.$lt{$item}.': ';
16476: if ($confhash{$itemid}{$item}) {
16477: $resulttext .= &mt('Yes');
16478: } else {
16479: $resulttext .= &mt('No');
1.337 raeburn 16480: }
1.345 raeburn 16481: $resulttext .= '</li>';
1.320 raeburn 16482: }
1.345 raeburn 16483: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16484: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16485: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16486: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16487: } else {
16488: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16489: }
16490: }
16491: if ($confhash{$itemid}{'crsinc'}) {
16492: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16493: my $rolemaps;
16494: foreach my $role (@ltiroles) {
16495: if ($confhash{$itemid}{'maproles'}{$role}) {
16496: $rolemaps .= (' 'x2).$role.'='.
16497: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16498: 'Course').',';
16499: }
16500: }
16501: if ($rolemaps) {
16502: $rolemaps =~ s/,$//;
16503: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16504: }
16505: }
16506: if ($confhash{$itemid}{'mapcrs'}) {
16507: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16508: }
16509: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16510: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16511: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16512: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16513: '</li>';
16514: } else {
16515: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16516: }
16517: }
1.392 raeburn 16518: if ($confhash{$itemid}{'storecrs'}) {
16519: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16520: }
1.391 raeburn 16521: if ($confhash{$itemid}{'makecrs'}) {
16522: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16523: } else {
16524: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16525: }
16526: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16527: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16528: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16529: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16530: '</li>';
16531: } else {
16532: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16533: }
16534: }
16535: if ($confhash{$itemid}{'section'}) {
16536: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16537: $resulttext .= '<li>'.&mt('User section from standard field:').
16538: ' (course_section_sourcedid)'.'</li>';
16539: } else {
16540: $resulttext .= '<li>'.&mt('User section from:').' '.
16541: $confhash{$itemid}{'section'}.'</li>';
16542: }
1.345 raeburn 16543: } else {
1.391 raeburn 16544: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16545: }
16546: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16547: $resulttext .= '<li>'.$lt{$item}.': ';
16548: if ($confhash{$itemid}{$item}) {
16549: $resulttext .= &mt('Yes');
16550: if ($item eq 'passback') {
16551: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16552: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16553: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16554: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16555: }
16556: }
16557: } else {
16558: $resulttext .= &mt('No');
16559: }
16560: $resulttext .= '</li>';
16561: }
16562: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16563: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16564: $resulttext .= '<li>'.&mt('Menu items:').' '.
16565: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16566: } else {
16567: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16568: }
1.345 raeburn 16569: }
1.326 raeburn 16570: }
16571: }
1.320 raeburn 16572: $resulttext .= '</ul></li>';
16573: }
16574: }
1.424 raeburn 16575: if (keys(%deletions)) {
16576: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16577: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16578: }
16579: }
1.320 raeburn 16580: }
1.405 raeburn 16581: $resulttext .= '</ul>';
1.424 raeburn 16582: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16583: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16584: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16585: $lastactref->{'domdefaults'} = 1;
16586: }
16587: }
1.320 raeburn 16588: } else {
16589: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16590: }
16591: if ($errors) {
16592: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16593: $errors.'</ul>';
16594: }
16595: return $resulttext;
16596: }
16597:
1.424 raeburn 16598: sub get_priv_creds {
16599: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16600: my ($needenc,$cipher,$privnum);
16601: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16602: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16603: $needenc = $encrypt->{'consumers'}
16604: } else {
16605: $needenc = $domdefs{'ltienc_consumers'};
16606: }
16607: if ($needenc) {
16608: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16609: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16610: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16611: my $privkey = $privhash{'key'};
16612: $privnum = $privhash{'version'};
16613: if (($privnum) && ($privkey ne '')) {
16614: $cipher = Crypt::CBC->new({'key' => $privkey,
16615: 'cipher' => 'DES'});
16616: }
16617: }
16618: }
16619: return ($cipher,$privnum);
16620: }
16621:
1.320 raeburn 16622: sub get_lti_id {
1.434 raeburn 16623: my ($domain,$consumer,$dbname) = @_;
16624: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16625: return ('','invalid db');
16626: }
16627: # get lock on db
1.320 raeburn 16628: my $lockhash = {
16629: lock => $env{'user.name'}.
16630: ':'.$env{'user.domain'},
16631: };
16632: my $tries = 0;
1.434 raeburn 16633: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16634: my ($id,$error);
16635:
16636: while (($gotlock ne 'ok') && ($tries<10)) {
16637: $tries ++;
16638: sleep (0.1);
1.434 raeburn 16639: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16640: }
16641: if ($gotlock eq 'ok') {
1.434 raeburn 16642: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16643: if ($currids{'lock'}) {
16644: delete($currids{'lock'});
16645: if (keys(%currids)) {
16646: my @curr = sort { $a <=> $b } keys(%currids);
16647: if ($curr[-1] =~ /^\d+$/) {
16648: $id = 1 + $curr[-1];
16649: }
16650: } else {
16651: $id = 1;
16652: }
16653: if ($id) {
1.434 raeburn 16654: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16655: $error = 'nostore';
16656: }
16657: } else {
16658: $error = 'nonumber';
16659: }
16660: }
1.434 raeburn 16661: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16662: } else {
16663: $error = 'nolock';
16664: }
16665: return ($id,$error);
16666: }
16667:
1.3 raeburn 16668: sub modify_autoenroll {
1.205 raeburn 16669: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16670: my ($resulttext,%changes);
16671: my %currautoenroll;
16672: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16673: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16674: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16675: }
16676: }
16677: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16678: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16679: sender => 'Sender for notification messages',
1.274 raeburn 16680: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16681: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16682: my @offon = ('off','on');
1.17 raeburn 16683: my $sender_uname = $env{'form.sender_uname'};
16684: my $sender_domain = $env{'form.sender_domain'};
16685: if ($sender_domain eq '') {
16686: $sender_uname = '';
16687: } elsif ($sender_uname eq '') {
16688: $sender_domain = '';
16689: }
1.129 raeburn 16690: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16691: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16692: $autofailsafe =~ s{^\s+|\s+$}{}g;
16693: if ($autofailsafe =~ /\D/) {
16694: undef($autofailsafe);
16695: }
1.274 raeburn 16696: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16697: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16698: $failsafe = 'off';
1.400 raeburn 16699: undef($autofailsafe);
1.274 raeburn 16700: }
1.1 raeburn 16701: my %autoenrollhash = (
1.129 raeburn 16702: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16703: 'sender_uname' => $sender_uname,
16704: 'sender_domain' => $sender_domain,
16705: 'co-owners' => $coowners,
1.399 raeburn 16706: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16707: 'failsafe' => $failsafe,
1.1 raeburn 16708: }
16709: );
1.4 raeburn 16710: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16711: $dom);
1.1 raeburn 16712: if ($putresult eq 'ok') {
16713: if (exists($currautoenroll{'run'})) {
16714: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16715: $changes{'run'} = 1;
16716: }
16717: } elsif ($autorun) {
16718: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16719: $changes{'run'} = 1;
1.1 raeburn 16720: }
16721: }
1.17 raeburn 16722: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16723: $changes{'sender'} = 1;
16724: }
1.17 raeburn 16725: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16726: $changes{'sender'} = 1;
16727: }
1.129 raeburn 16728: if ($currautoenroll{'co-owners'} ne '') {
16729: if ($currautoenroll{'co-owners'} ne $coowners) {
16730: $changes{'coowners'} = 1;
16731: }
16732: } elsif ($coowners) {
16733: $changes{'coowners'} = 1;
1.274 raeburn 16734: }
1.399 raeburn 16735: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16736: $changes{'autofailsafe'} = 1;
16737: }
1.399 raeburn 16738: if ($currautoenroll{'failsafe'} ne $failsafe) {
16739: $changes{'failsafe'} = 1;
16740: }
1.1 raeburn 16741: if (keys(%changes) > 0) {
16742: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16743: if ($changes{'run'}) {
1.1 raeburn 16744: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16745: }
16746: if ($changes{'sender'}) {
1.17 raeburn 16747: if ($sender_uname eq '' || $sender_domain eq '') {
16748: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16749: } else {
16750: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16751: }
1.1 raeburn 16752: }
1.129 raeburn 16753: if ($changes{'coowners'}) {
16754: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16755: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16756: if (ref($lastactref) eq 'HASH') {
16757: $lastactref->{'domainconfig'} = 1;
16758: }
1.129 raeburn 16759: }
1.274 raeburn 16760: if ($changes{'autofailsafe'}) {
1.399 raeburn 16761: if ($autofailsafe ne '') {
16762: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16763: } else {
1.399 raeburn 16764: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16765: }
1.399 raeburn 16766: }
16767: if ($changes{'failsafe'}) {
16768: if ($failsafe eq 'off') {
16769: unless ($changes{'autofailsafe'}) {
16770: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16771: }
16772: } elsif ($failsafe eq 'zero') {
16773: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16774: } else {
16775: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16776: }
16777: }
16778: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16779: &Apache::lonnet::get_domain_defaults($dom,1);
16780: if (ref($lastactref) eq 'HASH') {
16781: $lastactref->{'domdefaults'} = 1;
16782: }
16783: }
1.1 raeburn 16784: $resulttext .= '</ul>';
16785: } else {
16786: $resulttext = &mt('No changes made to auto-enrollment settings');
16787: }
16788: } else {
1.11 albertel 16789: $resulttext = '<span class="LC_error">'.
16790: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16791: }
1.3 raeburn 16792: return $resulttext;
1.1 raeburn 16793: }
16794:
16795: sub modify_autoupdate {
1.3 raeburn 16796: my ($dom,%domconfig) = @_;
1.1 raeburn 16797: my ($resulttext,%currautoupdate,%fields,%changes);
16798: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16799: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16800: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16801: }
16802: }
16803: my @offon = ('off','on');
16804: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16805: run => 'Auto-update:',
16806: classlists => 'Updates to user information in classlists?',
16807: unexpired => 'Skip updates for users without active or future roles?',
16808: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16809: );
1.44 raeburn 16810: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16811: my %fieldtitles = &Apache::lonlocal::texthash (
16812: id => 'Student/Employee ID',
1.20 raeburn 16813: permanentemail => 'E-mail address',
1.1 raeburn 16814: lastname => 'Last Name',
16815: firstname => 'First Name',
16816: middlename => 'Middle Name',
1.132 raeburn 16817: generation => 'Generation',
1.1 raeburn 16818: );
1.142 raeburn 16819: $othertitle = &mt('All users');
1.1 raeburn 16820: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16821: $othertitle = &mt('Other users');
1.1 raeburn 16822: }
16823: foreach my $key (keys(%env)) {
16824: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16825: my ($usertype,$item) = ($1,$2);
16826: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16827: if ($usertype eq 'default') {
16828: push(@{$fields{$1}},$2);
16829: } elsif (ref($types) eq 'ARRAY') {
16830: if (grep(/^\Q$usertype\E$/,@{$types})) {
16831: push(@{$fields{$1}},$2);
16832: }
16833: }
16834: }
1.1 raeburn 16835: }
16836: }
1.131 raeburn 16837: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16838: @lockablenames = sort(@lockablenames);
16839: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16840: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16841: if (@changed) {
16842: $changes{'lockablenames'} = 1;
16843: }
16844: } else {
16845: if (@lockablenames) {
16846: $changes{'lockablenames'} = 1;
16847: }
16848: }
1.1 raeburn 16849: my %updatehash = (
16850: autoupdate => { run => $env{'form.autoupdate_run'},
16851: classlists => $env{'form.classlists'},
1.385 raeburn 16852: unexpired => $env{'form.unexpired'},
1.1 raeburn 16853: fields => {%fields},
1.131 raeburn 16854: lockablenames => \@lockablenames,
1.1 raeburn 16855: }
16856: );
1.385 raeburn 16857: my $lastactivedays;
16858: if ($env{'form.lastactive'}) {
16859: $lastactivedays = $env{'form.lastactivedays'};
16860: $lastactivedays =~ s/^\s+|\s+$//g;
16861: unless ($lastactivedays =~ /^\d+$/) {
16862: undef($lastactivedays);
16863: $env{'form.lastactive'} = 0;
16864: }
16865: }
16866: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16867: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16868: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16869: if (exists($updatehash{autoupdate}{$key})) {
16870: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16871: $changes{$key} = 1;
16872: }
16873: }
16874: } elsif ($key eq 'fields') {
16875: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16876: foreach my $item (@{$types},'default') {
1.1 raeburn 16877: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16878: my $change = 0;
16879: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16880: if (!exists($fields{$item})) {
16881: $change = 1;
1.132 raeburn 16882: last;
1.1 raeburn 16883: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16884: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16885: $change = 1;
1.132 raeburn 16886: last;
1.1 raeburn 16887: }
16888: }
16889: }
16890: if ($change) {
16891: push(@{$changes{$key}},$item);
16892: }
1.26 raeburn 16893: }
1.1 raeburn 16894: }
16895: }
1.131 raeburn 16896: } elsif ($key eq 'lockablenames') {
16897: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16898: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16899: if (@changed) {
16900: $changes{'lockablenames'} = 1;
16901: }
16902: } else {
16903: if (@lockablenames) {
16904: $changes{'lockablenames'} = 1;
16905: }
16906: }
16907: }
16908: }
16909: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16910: if (@lockablenames) {
16911: $changes{'lockablenames'} = 1;
1.1 raeburn 16912: }
16913: }
1.385 raeburn 16914: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16915: if ($updatehash{'autoupdate'}{'unexpired'}) {
16916: $changes{'unexpired'} = 1;
16917: }
16918: }
16919: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16920: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16921: $changes{'lastactive'} = 1;
16922: }
16923: }
1.26 raeburn 16924: foreach my $item (@{$types},'default') {
16925: if (defined($fields{$item})) {
16926: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16927: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16928: my $change = 0;
16929: if (ref($fields{$item}) eq 'ARRAY') {
16930: foreach my $type (@{$fields{$item}}) {
16931: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16932: $change = 1;
16933: last;
16934: }
16935: }
16936: }
16937: if ($change) {
16938: push(@{$changes{'fields'}},$item);
16939: }
16940: } else {
1.26 raeburn 16941: push(@{$changes{'fields'}},$item);
16942: }
16943: } else {
16944: push(@{$changes{'fields'}},$item);
1.1 raeburn 16945: }
16946: }
16947: }
16948: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16949: $dom);
16950: if ($putresult eq 'ok') {
16951: if (keys(%changes) > 0) {
16952: $resulttext = &mt('Changes made:').'<ul>';
16953: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16954: if ($key eq 'lockablenames') {
16955: $resulttext .= '<li>';
16956: if (@lockablenames) {
16957: $usertypes->{'default'} = $othertitle;
16958: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16959: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16960: } else {
16961: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16962: }
16963: $resulttext .= '</li>';
16964: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16965: foreach my $item (@{$changes{$key}}) {
16966: my @newvalues;
16967: foreach my $type (@{$fields{$item}}) {
16968: push(@newvalues,$fieldtitles{$type});
16969: }
1.3 raeburn 16970: my $newvaluestr;
16971: if (@newvalues > 0) {
16972: $newvaluestr = join(', ',@newvalues);
16973: } else {
16974: $newvaluestr = &mt('none');
1.6 raeburn 16975: }
1.1 raeburn 16976: if ($item eq 'default') {
1.26 raeburn 16977: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16978: } else {
1.26 raeburn 16979: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16980: }
16981: }
16982: } else {
16983: my $newvalue;
16984: if ($key eq 'run') {
16985: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16986: } elsif ($key eq 'lastactive') {
16987: $newvalue = $offon[$env{'form.lastactive'}];
16988: unless ($lastactivedays eq '') {
16989: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16990: }
1.1 raeburn 16991: } else {
16992: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16993: }
1.1 raeburn 16994: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16995: }
16996: }
16997: $resulttext .= '</ul>';
16998: } else {
1.3 raeburn 16999: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 17000: }
17001: } else {
1.11 albertel 17002: $resulttext = '<span class="LC_error">'.
17003: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17004: }
1.3 raeburn 17005: return $resulttext;
1.1 raeburn 17006: }
17007:
1.125 raeburn 17008: sub modify_autocreate {
17009: my ($dom,%domconfig) = @_;
17010: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17011: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17012: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17013: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17014: }
17015: }
17016: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17017: req => 'Auto-creation of validated requests for official courses',
17018: xmldc => 'Identity of course creator of courses from XML files',
17019: );
17020: my @types = ('xml','req');
17021: foreach my $item (@types) {
17022: $newvals{$item} = $env{'form.autocreate_'.$item};
17023: $newvals{$item} =~ s/\D//g;
17024: $newvals{$item} = 0 if ($newvals{$item} eq '');
17025: }
17026: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17027: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17028: unless (exists($domcoords{$newvals{'xmldc'}})) {
17029: $newvals{'xmldc'} = '';
17030: }
17031: %autocreatehash = (
17032: autocreate => { xml => $newvals{'xml'},
17033: req => $newvals{'req'},
17034: }
17035: );
17036: if ($newvals{'xmldc'} ne '') {
17037: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17038: }
17039: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17040: $dom);
17041: if ($putresult eq 'ok') {
17042: my @items = @types;
17043: if ($newvals{'xml'}) {
17044: push(@items,'xmldc');
17045: }
17046: foreach my $item (@items) {
17047: if (exists($currautocreate{$item})) {
17048: if ($currautocreate{$item} ne $newvals{$item}) {
17049: $changes{$item} = 1;
17050: }
17051: } elsif ($newvals{$item}) {
17052: $changes{$item} = 1;
17053: }
17054: }
17055: if (keys(%changes) > 0) {
17056: my @offon = ('off','on');
17057: $resulttext = &mt('Changes made:').'<ul>';
17058: foreach my $item (@types) {
17059: if ($changes{$item}) {
17060: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17061: $resulttext .= '<li>'.
17062: &mt("$title{$item} set to [_1]$newtxt [_2]",
17063: '<b>','</b>').
17064: '</li>';
1.125 raeburn 17065: }
17066: }
17067: if ($changes{'xmldc'}) {
17068: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17069: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17070: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17071: }
17072: $resulttext .= '</ul>';
17073: } else {
17074: $resulttext = &mt('No changes made to auto-creation settings');
17075: }
17076: } else {
17077: $resulttext = '<span class="LC_error">'.
17078: &mt('An error occurred: [_1]',$putresult).'</span>';
17079: }
17080: return $resulttext;
17081: }
17082:
1.23 raeburn 17083: sub modify_directorysrch {
1.295 raeburn 17084: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17085: my ($resulttext,%changes);
17086: my %currdirsrch;
17087: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17088: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17089: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17090: }
17091: }
1.277 raeburn 17092: my %title = ( available => 'Institutional directory search available',
17093: localonly => 'Other domains can search institution',
17094: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17095: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17096: searchby => 'Search types',
17097: searchtypes => 'Search latitude');
17098: my @offon = ('off','on');
1.24 raeburn 17099: my @otherdoms = ('Yes','No');
1.23 raeburn 17100:
1.25 raeburn 17101: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17102: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17103: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17104:
1.44 raeburn 17105: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17106: if (keys(%{$usertypes}) == 0) {
17107: @cansearch = ('default');
17108: } else {
17109: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17110: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17111: if (!grep(/^\Q$type\E$/,@cansearch)) {
17112: push(@{$changes{'cansearch'}},$type);
17113: }
1.23 raeburn 17114: }
1.26 raeburn 17115: foreach my $type (@cansearch) {
17116: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17117: push(@{$changes{'cansearch'}},$type);
17118: }
1.23 raeburn 17119: }
1.26 raeburn 17120: } else {
17121: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17122: }
17123: }
17124:
17125: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17126: foreach my $by (@{$currdirsrch{'searchby'}}) {
17127: if (!grep(/^\Q$by\E$/,@searchby)) {
17128: push(@{$changes{'searchby'}},$by);
17129: }
17130: }
17131: foreach my $by (@searchby) {
17132: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17133: push(@{$changes{'searchby'}},$by);
17134: }
17135: }
17136: } else {
17137: push(@{$changes{'searchby'}},@searchby);
17138: }
1.25 raeburn 17139:
17140: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17141: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17142: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17143: push(@{$changes{'searchtypes'}},$type);
17144: }
17145: }
17146: foreach my $type (@searchtypes) {
17147: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17148: push(@{$changes{'searchtypes'}},$type);
17149: }
17150: }
17151: } else {
17152: if (exists($currdirsrch{'searchtypes'})) {
17153: foreach my $type (@searchtypes) {
17154: if ($type ne $currdirsrch{'searchtypes'}) {
17155: push(@{$changes{'searchtypes'}},$type);
17156: }
17157: }
17158: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17159: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17160: }
17161: } else {
17162: push(@{$changes{'searchtypes'}},@searchtypes);
17163: }
17164: }
17165:
1.23 raeburn 17166: my %dirsrch_hash = (
17167: directorysrch => { available => $env{'form.dirsrch_available'},
17168: cansearch => \@cansearch,
1.277 raeburn 17169: localonly => $env{'form.dirsrch_instlocalonly'},
17170: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17171: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17172: searchby => \@searchby,
1.25 raeburn 17173: searchtypes => \@searchtypes,
1.23 raeburn 17174: }
17175: );
17176: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17177: $dom);
17178: if ($putresult eq 'ok') {
17179: if (exists($currdirsrch{'available'})) {
17180: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17181: $changes{'available'} = 1;
17182: }
17183: } else {
17184: if ($env{'form.dirsrch_available'} eq '1') {
17185: $changes{'available'} = 1;
17186: }
17187: }
1.277 raeburn 17188: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17189: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17190: $changes{'lcavailable'} = 1;
17191: }
1.277 raeburn 17192: } else {
17193: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17194: $changes{'lcavailable'} = 1;
17195: }
17196: }
1.24 raeburn 17197: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17198: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17199: $changes{'localonly'} = 1;
17200: }
1.24 raeburn 17201: } else {
1.277 raeburn 17202: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17203: $changes{'localonly'} = 1;
17204: }
17205: }
1.277 raeburn 17206: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17207: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17208: $changes{'lclocalonly'} = 1;
17209: }
1.277 raeburn 17210: } else {
17211: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17212: $changes{'lclocalonly'} = 1;
17213: }
17214: }
1.23 raeburn 17215: if (keys(%changes) > 0) {
17216: $resulttext = &mt('Changes made:').'<ul>';
17217: if ($changes{'available'}) {
17218: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17219: }
1.277 raeburn 17220: if ($changes{'lcavailable'}) {
17221: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17222: }
1.24 raeburn 17223: if ($changes{'localonly'}) {
1.277 raeburn 17224: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17225: }
1.277 raeburn 17226: if ($changes{'lclocalonly'}) {
17227: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17228: }
1.23 raeburn 17229: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17230: my $chgtext;
1.26 raeburn 17231: if (ref($usertypes) eq 'HASH') {
17232: if (keys(%{$usertypes}) > 0) {
17233: foreach my $type (@{$types}) {
17234: if (grep(/^\Q$type\E$/,@cansearch)) {
17235: $chgtext .= $usertypes->{$type}.'; ';
17236: }
17237: }
17238: if (grep(/^default$/,@cansearch)) {
17239: $chgtext .= $othertitle;
17240: } else {
17241: $chgtext =~ s/\; $//;
17242: }
1.210 raeburn 17243: $resulttext .=
1.178 raeburn 17244: '<li>'.
17245: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17246: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17247: '</li>';
1.23 raeburn 17248: }
17249: }
17250: }
17251: if (ref($changes{'searchby'}) eq 'ARRAY') {
17252: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17253: my $chgtext;
17254: foreach my $type (@{$titleorder}) {
17255: if (grep(/^\Q$type\E$/,@searchby)) {
17256: if (defined($searchtitles->{$type})) {
17257: $chgtext .= $searchtitles->{$type}.'; ';
17258: }
17259: }
17260: }
17261: $chgtext =~ s/\; $//;
17262: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17263: }
1.25 raeburn 17264: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17265: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17266: my $chgtext;
17267: foreach my $type (@{$srchtypeorder}) {
17268: if (grep(/^\Q$type\E$/,@searchtypes)) {
17269: if (defined($srchtypes_desc->{$type})) {
17270: $chgtext .= $srchtypes_desc->{$type}.'; ';
17271: }
17272: }
17273: }
17274: $chgtext =~ s/\; $//;
1.178 raeburn 17275: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17276: }
17277: $resulttext .= '</ul>';
1.295 raeburn 17278: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17279: if (ref($lastactref) eq 'HASH') {
17280: $lastactref->{'directorysrch'} = 1;
17281: }
1.23 raeburn 17282: } else {
1.277 raeburn 17283: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17284: }
17285: } else {
17286: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17287: &mt('An error occurred: [_1]',$putresult).'</span>';
17288: }
17289: return $resulttext;
17290: }
17291:
1.28 raeburn 17292: sub modify_contacts {
1.205 raeburn 17293: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17294: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17295: if (ref($domconfig{'contacts'}) eq 'HASH') {
17296: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17297: $currsetting{$key} = $domconfig{'contacts'}{$key};
17298: }
17299: }
1.286 raeburn 17300: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17301: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17302: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17303: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17304: my @toggles = ('reporterrors','reportupdates','reportstatus');
17305: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17306: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17307: foreach my $type (@mailings) {
17308: @{$newsetting{$type}} =
17309: &Apache::loncommon::get_env_multiple('form.'.$type);
17310: foreach my $item (@contacts) {
17311: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17312: $contacts_hash{contacts}{$type}{$item} = 1;
17313: } else {
17314: $contacts_hash{contacts}{$type}{$item} = 0;
17315: }
1.289 raeburn 17316: }
1.28 raeburn 17317: $others{$type} = $env{'form.'.$type.'_others'};
17318: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17319: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17320: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17321: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17322: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17323: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17324: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17325: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17326: }
1.134 raeburn 17327: }
1.28 raeburn 17328: }
17329: foreach my $item (@contacts) {
17330: $to{$item} = $env{'form.'.$item};
17331: $contacts_hash{'contacts'}{$item} = $to{$item};
17332: }
1.203 raeburn 17333: foreach my $item (@toggles) {
17334: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17335: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17336: }
17337: }
1.340 raeburn 17338: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17339: foreach my $item (@lonstatus) {
17340: if ($item eq 'excluded') {
17341: my (%serverhomes,@excluded);
17342: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17343: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17344: if (@possexcluded) {
17345: foreach my $id (sort(@possexcluded)) {
17346: if ($serverhomes{$id}) {
17347: push(@excluded,$id);
17348: }
17349: }
17350: }
17351: if (@excluded) {
17352: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17353: }
17354: } elsif ($item eq 'weights') {
1.377 raeburn 17355: foreach my $type ('E','W','N','U') {
1.340 raeburn 17356: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17357: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17358: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17359: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17360: $env{'form.error'.$item.'_'.$type};
17361: }
17362: }
17363: }
17364: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17365: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17366: if ($env{'form.error'.$item} =~ /^\d+$/) {
17367: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17368: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17369: }
17370: }
17371: }
17372: }
1.286 raeburn 17373: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17374: foreach my $field (@{$fields}) {
17375: if (ref($possoptions->{$field}) eq 'ARRAY') {
17376: my $value = $env{'form.helpform_'.$field};
17377: $value =~ s/^\s+|\s+$//g;
17378: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17379: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17380: if ($field eq 'screenshot') {
17381: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17382: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17383: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17384: }
17385: }
17386: }
17387: }
17388: }
17389: }
1.315 raeburn 17390: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17391: my (@statuses,%usertypeshash,@overrides);
17392: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17393: @statuses = @{$types};
17394: if (ref($usertypes) eq 'HASH') {
17395: %usertypeshash = %{$usertypes};
17396: }
17397: }
17398: if (@statuses) {
17399: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17400: foreach my $type (@possoverrides) {
17401: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17402: push(@overrides,$type);
17403: }
17404: }
17405: if (@overrides) {
17406: foreach my $type (@overrides) {
17407: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17408: foreach my $item (@contacts) {
17409: if (grep(/^\Q$item\E$/,@standard)) {
17410: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17411: $newsetting{'override_'.$type}{$item} = 1;
17412: } else {
17413: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17414: $newsetting{'override_'.$type}{$item} = 0;
17415: }
17416: }
17417: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17418: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17419: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17420: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17421: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17422: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17423: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17424: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17425: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17426: }
1.425 raeburn 17427: }
1.315 raeburn 17428: }
17429: }
1.28 raeburn 17430: if (keys(%currsetting) > 0) {
17431: foreach my $item (@contacts) {
17432: if ($to{$item} ne $currsetting{$item}) {
17433: $changes{$item} = 1;
17434: }
17435: }
17436: foreach my $type (@mailings) {
17437: foreach my $item (@contacts) {
17438: if (ref($currsetting{$type}) eq 'HASH') {
17439: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17440: push(@{$changes{$type}},$item);
17441: }
17442: } else {
17443: push(@{$changes{$type}},@{$newsetting{$type}});
17444: }
17445: }
17446: if ($others{$type} ne $currsetting{$type}{'others'}) {
17447: push(@{$changes{$type}},'others');
17448: }
1.289 raeburn 17449: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17450: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17451: push(@{$changes{$type}},'bcc');
17452: }
1.286 raeburn 17453: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17454: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17455: push(@{$changes{$type}},'include');
17456: }
17457: }
17458: }
17459: if (ref($fields) eq 'ARRAY') {
17460: if (ref($currsetting{'helpform'}) eq 'HASH') {
17461: foreach my $field (@{$fields}) {
17462: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17463: push(@{$changes{'helpform'}},$field);
17464: }
17465: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17466: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17467: push(@{$changes{'helpform'}},'maxsize');
17468: }
17469: }
17470: }
17471: } else {
17472: foreach my $field (@{$fields}) {
17473: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17474: push(@{$changes{'helpform'}},$field);
17475: }
17476: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17477: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17478: push(@{$changes{'helpform'}},'maxsize');
17479: }
17480: }
17481: }
1.134 raeburn 17482: }
1.28 raeburn 17483: }
1.315 raeburn 17484: if (@statuses) {
1.425 raeburn 17485: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17486: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17487: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17488: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17489: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17490: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17491: push(@{$changes{'overrides'}},$key);
17492: last;
17493: }
17494: }
17495: } else {
17496: push(@{$changes{'overrides'}},$key);
17497: }
17498: }
17499: }
17500: foreach my $key (@overrides) {
17501: unless (exists($currsetting{'overrides'}{$key})) {
17502: push(@{$changes{'overrides'}},$key);
17503: }
17504: }
17505: } else {
17506: foreach my $key (@overrides) {
1.425 raeburn 17507: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17508: }
17509: }
17510: }
1.340 raeburn 17511: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17512: foreach my $key ('excluded','weights','threshold','sysmail') {
17513: if ($key eq 'excluded') {
17514: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17515: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17516: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17517: (@{$currsetting{'lonstatus'}{$key}})) {
17518: my @diffs =
17519: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17520: $currsetting{'lonstatus'}{$key});
17521: if (@diffs) {
17522: push(@{$changes{'lonstatus'}},$key);
17523: }
17524: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17525: push(@{$changes{'lonstatus'}},$key);
17526: }
17527: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17528: (@{$currsetting{'lonstatus'}{$key}})) {
17529: push(@{$changes{'lonstatus'}},$key);
17530: }
17531: } elsif ($key eq 'weights') {
17532: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17533: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17534: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17535: foreach my $type ('E','W','N','U') {
1.340 raeburn 17536: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17537: $currsetting{'lonstatus'}{$key}{$type}) {
17538: push(@{$changes{'lonstatus'}},$key);
17539: last;
17540: }
17541: }
17542: } else {
1.341 raeburn 17543: foreach my $type ('E','W','N','U') {
1.340 raeburn 17544: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17545: push(@{$changes{'lonstatus'}},$key);
17546: last;
17547: }
17548: }
17549: }
17550: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17551: foreach my $type ('E','W','N','U') {
1.340 raeburn 17552: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17553: push(@{$changes{'lonstatus'}},$key);
17554: last;
17555: }
17556: }
17557: }
17558: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17559: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17560: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17561: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17562: push(@{$changes{'lonstatus'}},$key);
17563: }
17564: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17565: push(@{$changes{'lonstatus'}},$key);
17566: }
17567: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17568: push(@{$changes{'lonstatus'}},$key);
17569: }
17570: }
17571: }
17572: } else {
17573: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17574: foreach my $key ('excluded','weights','threshold','sysmail') {
17575: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17576: push(@{$changes{'lonstatus'}},$key);
17577: }
17578: }
17579: }
17580: }
1.28 raeburn 17581: } else {
17582: my %default;
17583: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17584: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17585: $default{'errormail'} = 'adminemail';
17586: $default{'packagesmail'} = 'adminemail';
17587: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17588: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17589: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17590: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17591: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17592: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17593: foreach my $item (@contacts) {
17594: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17595: $changes{$item} = 1;
1.203 raeburn 17596: }
1.28 raeburn 17597: }
17598: foreach my $type (@mailings) {
17599: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17600: push(@{$changes{$type}},@{$newsetting{$type}});
17601: }
17602: if ($others{$type} ne '') {
17603: push(@{$changes{$type}},'others');
1.134 raeburn 17604: }
1.286 raeburn 17605: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17606: if ($bcc{$type} ne '') {
17607: push(@{$changes{$type}},'bcc');
17608: }
1.286 raeburn 17609: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17610: push(@{$changes{$type}},'include');
17611: }
1.134 raeburn 17612: }
1.28 raeburn 17613: }
1.286 raeburn 17614: if (ref($fields) eq 'ARRAY') {
17615: foreach my $field (@{$fields}) {
17616: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17617: push(@{$changes{'helpform'}},$field);
17618: }
17619: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17620: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17621: push(@{$changes{'helpform'}},'maxsize');
17622: }
17623: }
17624: }
1.289 raeburn 17625: }
1.340 raeburn 17626: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17627: foreach my $key ('excluded','weights','threshold','sysmail') {
17628: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17629: push(@{$changes{'lonstatus'}},$key);
17630: }
17631: }
17632: }
1.28 raeburn 17633: }
1.203 raeburn 17634: foreach my $item (@toggles) {
17635: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17636: $changes{$item} = 1;
17637: } elsif ((!$env{'form.'.$item}) &&
17638: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17639: $changes{$item} = 1;
17640: }
17641: }
1.28 raeburn 17642: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17643: $dom);
17644: if ($putresult eq 'ok') {
17645: if (keys(%changes) > 0) {
1.205 raeburn 17646: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17647: if (ref($lastactref) eq 'HASH') {
17648: $lastactref->{'domainconfig'} = 1;
17649: }
1.28 raeburn 17650: my ($titles,$short_titles) = &contact_titles();
17651: $resulttext = &mt('Changes made:').'<ul>';
17652: foreach my $item (@contacts) {
17653: if ($changes{$item}) {
17654: $resulttext .= '<li>'.$titles->{$item}.
17655: &mt(' set to: ').
17656: '<span class="LC_cusr_emph">'.
17657: $to{$item}.'</span></li>';
17658: }
17659: }
17660: foreach my $type (@mailings) {
17661: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17662: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17663: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17664: } else {
17665: $resulttext .= '<li>'.$titles->{$type}.': ';
17666: }
1.28 raeburn 17667: my @text;
17668: foreach my $item (@{$newsetting{$type}}) {
17669: push(@text,$short_titles->{$item});
17670: }
17671: if ($others{$type} ne '') {
17672: push(@text,$others{$type});
17673: }
1.286 raeburn 17674: if (@text) {
17675: $resulttext .= '<span class="LC_cusr_emph">'.
17676: join(', ',@text).'</span>';
17677: }
17678: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17679: if ($bcc{$type} ne '') {
1.286 raeburn 17680: my $bcctext;
17681: if (@text) {
1.289 raeburn 17682: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17683: } else {
17684: $bcctext = '(Bcc)';
17685: }
17686: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17687: } elsif (!@text) {
17688: $resulttext .= &mt('No one');
1.425 raeburn 17689: }
1.289 raeburn 17690: if ($includestr{$type} ne '') {
1.286 raeburn 17691: if ($includeloc{$type} eq 'b') {
17692: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17693: } elsif ($includeloc{$type} eq 's') {
17694: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17695: }
1.134 raeburn 17696: }
1.286 raeburn 17697: } elsif (!@text) {
17698: $resulttext .= &mt('No recipients');
1.134 raeburn 17699: }
17700: $resulttext .= '</li>';
1.28 raeburn 17701: }
17702: }
1.315 raeburn 17703: if (ref($changes{'overrides'}) eq 'ARRAY') {
17704: my @deletions;
17705: foreach my $type (@{$changes{'overrides'}}) {
17706: if ($usertypeshash{$type}) {
17707: if (grep(/^\Q$type\E/,@overrides)) {
17708: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17709: $usertypeshash{$type}).'<ul><li>';
17710: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17711: my @text;
17712: foreach my $item (@contacts) {
1.425 raeburn 17713: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17714: push(@text,$short_titles->{$item});
17715: }
17716: }
17717: if ($newsetting{'override_'.$type}{'others'} ne '') {
17718: push(@text,$newsetting{'override_'.$type}{'others'});
17719: }
1.425 raeburn 17720:
1.315 raeburn 17721: if (@text) {
17722: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17723: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17724: }
17725: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17726: my $bcctext;
17727: if (@text) {
17728: $bcctext = ' '.&mt('with Bcc to');
17729: } else {
17730: $bcctext = '(Bcc)';
17731: }
17732: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17733: } elsif (!@text) {
17734: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17735: }
17736: $resulttext .= '</li>';
17737: if ($newsetting{'override_'.$type}{'include'} ne '') {
17738: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17739: if ($loc eq 'b') {
17740: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17741: } elsif ($loc eq 's') {
17742: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17743: }
17744: }
17745: }
17746: $resulttext .= '</li></ul></li>';
17747: } else {
17748: push(@deletions,$usertypeshash{$type});
17749: }
17750: }
17751: }
17752: if (@deletions) {
17753: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17754: join(', ',@deletions)).'</li>';
17755: }
17756: }
1.203 raeburn 17757: my @offon = ('off','on');
1.340 raeburn 17758: my $corelink = &core_link_msu();
1.203 raeburn 17759: if ($changes{'reporterrors'}) {
17760: $resulttext .= '<li>'.
17761: &mt('E-mail error reports to [_1] set to "'.
17762: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17763: $corelink).
1.203 raeburn 17764: '</li>';
17765: }
17766: if ($changes{'reportupdates'}) {
17767: $resulttext .= '<li>'.
17768: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17769: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17770: $corelink).
1.203 raeburn 17771: '</li>';
17772: }
1.340 raeburn 17773: if ($changes{'reportstatus'}) {
17774: $resulttext .= '<li>'.
17775: &mt('E-mail status if errors above threshold to [_1] set to "'.
17776: $offon[$env{'form.reportstatus'}].'".',
17777: $corelink).
17778: '</li>';
17779: }
17780: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17781: $resulttext .= '<li>'.
17782: &mt('Nightly status check e-mail settings').':<ul>';
17783: my (%defval,%use_def,%shown);
17784: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17785: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17786: $defval{'weights'} =
1.341 raeburn 17787: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17788: $defval{'excluded'} = &mt('None');
17789: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17790: foreach my $item ('threshold','sysmail','weights','excluded') {
17791: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17792: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17793: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17794: } elsif ($item eq 'weights') {
17795: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17796: foreach my $type ('E','W','N','U') {
1.340 raeburn 17797: $shown{$item} .= $lonstatus_names->{$type}.'=';
17798: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17799: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17800: } else {
17801: $shown{$item} .= $lonstatus_defs->{$type};
17802: }
17803: $shown{$item} .= ', ';
17804: }
17805: $shown{$item} =~ s/, $//;
17806: } else {
17807: $shown{$item} = $defval{$item};
17808: }
17809: } elsif ($item eq 'excluded') {
17810: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17811: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17812: } else {
17813: $shown{$item} = $defval{$item};
17814: }
17815: }
17816: } else {
17817: $shown{$item} = $defval{$item};
17818: }
17819: }
17820: } else {
17821: foreach my $item ('threshold','weights','excluded','sysmail') {
17822: $shown{$item} = $defval{$item};
17823: }
17824: }
17825: foreach my $item ('threshold','weights','excluded','sysmail') {
17826: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17827: $shown{$item}).'</li>';
17828: }
17829: $resulttext .= '</ul></li>';
17830: }
1.286 raeburn 17831: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17832: my (@optional,@required,@unused,$maxsizechg);
17833: foreach my $field (@{$changes{'helpform'}}) {
17834: if ($field eq 'maxsize') {
17835: $maxsizechg = 1;
17836: next;
17837: }
17838: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17839: push(@optional,$field);
1.286 raeburn 17840: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17841: push(@unused,$field);
17842: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17843: push(@required,$field);
1.286 raeburn 17844: }
17845: }
17846: if (@optional) {
17847: $resulttext .= '<li>'.
17848: &mt('Help form fields changed to "Optional": [_1].',
17849: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17850: '</li>';
17851: }
17852: if (@required) {
17853: $resulttext .= '<li>'.
17854: &mt('Help form fields changed to "Required": [_1].',
17855: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17856: '</li>';
17857: }
17858: if (@unused) {
17859: $resulttext .= '<li>'.
17860: &mt('Help form fields changed to "Not shown": [_1].',
17861: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17862: '</li>';
17863: }
17864: if ($maxsizechg) {
17865: $resulttext .= '<li>'.
17866: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17867: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17868: '</li>';
17869: }
17870: }
1.28 raeburn 17871: $resulttext .= '</ul>';
17872: } else {
1.288 raeburn 17873: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17874: }
17875: } else {
17876: $resulttext = '<span class="LC_error">'.
17877: &mt('An error occurred: [_1].',$putresult).'</span>';
17878: }
17879: return $resulttext;
17880: }
17881:
1.357 raeburn 17882: sub modify_privacy {
1.427 raeburn 17883: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17884: my ($resulttext,%current,%changes);
17885: if (ref($domconfig{'privacy'}) eq 'HASH') {
17886: %current = %{$domconfig{'privacy'}};
17887: }
17888: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17889: my @items = ('domain','author','course','community');
17890: my %names = &Apache::lonlocal::texthash (
17891: domain => 'Assigned domain role(s)',
17892: author => 'Assigned co-author role(s)',
17893: course => 'Assigned course role(s)',
1.416 raeburn 17894: community => 'Assigned community role(s)',
1.357 raeburn 17895: );
17896: my %roles = &Apache::lonlocal::texthash (
17897: domain => 'Domain role',
17898: author => 'Co-author role',
17899: course => 'Course role',
17900: community => 'Community role',
17901: );
17902: my %titles = &Apache::lonlocal::texthash (
17903: approval => 'Approval for role in different domain',
17904: othdom => 'User information available in other domain',
17905: priv => 'Information viewable by privileged user in same domain',
17906: unpriv => 'Information viewable by unprivileged user in same domain',
17907: instdom => 'Other domain shares institution/provider',
17908: extdom => 'Other domain has different institution/provider',
17909: none => 'Not allowed',
17910: user => 'User authorizes',
17911: domain => 'Domain Coordinator authorizes',
17912: auto => 'Unrestricted',
1.418 raeburn 17913: notify => 'Notify when role needs authorization',
1.357 raeburn 17914: );
17915: my %fieldnames = &Apache::lonlocal::texthash (
17916: id => 'Student/Employee ID',
17917: permanentemail => 'E-mail address',
17918: lastname => 'Last Name',
17919: firstname => 'First Name',
17920: middlename => 'Middle Name',
17921: generation => 'Generation',
17922: );
17923: my ($othertitle,$usertypes,$types) =
17924: &Apache::loncommon::sorted_inst_types($dom);
17925: my (%by_ip,%by_location,@intdoms,@instdoms);
17926: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17927:
17928: my %privacyhash = (
17929: 'approval' => {
17930: instdom => {},
17931: extdom => {},
17932: },
17933: 'othdom' => {},
17934: 'priv' => {},
17935: 'unpriv' => {},
17936: );
17937: foreach my $item (@items) {
17938: if (@instdoms > 1) {
1.416 raeburn 17939: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17940: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17941: }
17942: if (ref($current{'approval'}) eq 'HASH') {
17943: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17944: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17945: $changes{'approval'} = 1;
17946: }
17947: }
17948: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17949: $changes{'approval'} = 1;
17950: }
17951: }
17952: if (keys(%by_location) > 0) {
17953: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17954: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17955: }
17956: if (ref($current{'approval'}) eq 'HASH') {
17957: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17958: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17959: $changes{'approval'} = 1;
17960: }
17961: }
17962: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17963: $changes{'approval'} = 1;
17964: }
17965: }
17966: foreach my $status ('priv','unpriv') {
17967: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17968: my @newvalues;
17969: foreach my $field (@possibles) {
17970: if (grep(/^\Q$field\E$/,@fields)) {
17971: $privacyhash{$status}{$item}{$field} = 1;
17972: push(@newvalues,$field);
17973: }
17974: }
17975: @newvalues = sort(@newvalues);
17976: if (ref($current{$status}) eq 'HASH') {
17977: if (ref($current{$status}{$item}) eq 'HASH') {
17978: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17979: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17980: if (@diffs > 0) {
17981: $changes{$status} = 1;
17982: }
17983: }
17984: } else {
17985: my @stdfields;
17986: foreach my $field (@fields) {
17987: if ($field eq 'id') {
17988: next if ($status eq 'unpriv');
17989: next if (($status eq 'priv') && ($item eq 'community'));
17990: }
17991: push(@stdfields,$field);
17992: }
17993: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17994: if (@diffs > 0) {
17995: $changes{$status} = 1;
17996: }
17997: }
17998: }
17999: }
18000: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
18001: my @statuses;
18002: if (ref($types) eq 'ARRAY') {
18003: @statuses = @{$types};
18004: }
18005: foreach my $type (@statuses,'default') {
18006: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18007: my @newvalues;
18008: foreach my $field (sort(@possfields)) {
18009: if (grep(/^\Q$field\E$/,@fields)) {
18010: $privacyhash{'othdom'}{$type}{$field} = 1;
18011: push(@newvalues,$field);
18012: }
18013: }
18014: @newvalues = sort(@newvalues);
18015: if (ref($current{'othdom'}) eq 'HASH') {
18016: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18017: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18018: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18019: if (@diffs > 0) {
18020: $changes{'othdom'} = 1;
18021: }
18022: }
18023: } else {
18024: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18025: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18026: if (@diffs > 0) {
18027: $changes{'othdom'} = 1;
18028: }
18029: }
18030: }
1.417 raeburn 18031: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18032: my %notify;
18033: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18034: if (exists($domcoords{$possdc})) {
18035: $notify{$possdc} = 1;
18036: }
18037: }
18038: my $notify = join(',',sort(keys(%notify)));
18039: if ($current{'notify'} ne $notify) {
18040: $changes{'notify'} = 1;
18041: }
18042: $privacyhash{'notify'} = $notify;
1.357 raeburn 18043: }
18044: my %confighash = (
18045: privacy => \%privacyhash,
18046: );
18047: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18048: if ($putresult eq 'ok') {
18049: if (keys(%changes) > 0) {
18050: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18051: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18052: if ($changes{$key}) {
18053: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18054: if ($key eq 'approval') {
18055: if (keys(%{$privacyhash{$key}{instdom}})) {
18056: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18057: foreach my $item (@items) {
18058: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18059: }
18060: $resulttext .= '</ul></li>';
18061: }
18062: if (keys(%{$privacyhash{$key}{extdom}})) {
18063: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18064: foreach my $item (@items) {
18065: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18066: }
18067: $resulttext .= '</ul></li>';
18068: }
1.417 raeburn 18069: } elsif ($key eq 'notify') {
18070: if ($privacyhash{$key}) {
18071: foreach my $dc (split(/,/,$privacyhash{$key})) {
18072: my ($dcname,$dcdom) = split(/:/,$dc);
18073: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18074: }
18075: } else {
18076: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18077: }
1.357 raeburn 18078: } elsif ($key eq 'othdom') {
18079: my @statuses;
18080: if (ref($types) eq 'ARRAY') {
18081: @statuses = @{$types};
18082: }
18083: if (ref($privacyhash{$key}) eq 'HASH') {
18084: foreach my $status (@statuses,'default') {
18085: if ($status eq 'default') {
18086: $resulttext .= '<li>'.$othertitle.': ';
18087: } elsif (ref($usertypes) eq 'HASH') {
18088: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18089: } else {
18090: next;
18091: }
18092: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18093: if (keys(%{$privacyhash{$key}{$status}})) {
18094: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18095: } else {
18096: $resulttext .= &mt('none');
18097: }
18098: }
18099: $resulttext .= '</li>';
18100: }
18101: }
18102: } else {
18103: foreach my $item (@items) {
18104: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18105: $resulttext .= '<li>'.$names{$item}.': ';
18106: if (keys(%{$privacyhash{$key}{$item}})) {
18107: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18108: } else {
18109: $resulttext .= &mt('none');
18110: }
18111: $resulttext .= '</li>';
18112: }
18113: }
18114: }
18115: $resulttext .= '</ul></li>';
18116: }
18117: }
1.421 raeburn 18118: $resulttext .= '</ul>';
1.427 raeburn 18119: if ($changes{'approval'}) {
18120: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18121: delete($domdefaults{'userapprovals'});
18122: if (ref($privacyhash{'approval'}) eq 'HASH') {
18123: foreach my $domtype ('instdom','extdom') {
18124: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18125: foreach my $roletype ('domain','author','course','community') {
18126: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18127: $domdefaults{'userapprovals'} = 1;
18128: last;
18129: }
18130: }
18131: }
18132: last if ($domdefaults{'userapprovals'});
18133: }
18134: }
18135: my $cachetime = 24*60*60;
18136: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18137: if (ref($lastactref) eq 'HASH') {
18138: $lastactref->{'domdefaults'} = 1;
18139: }
18140: }
1.357 raeburn 18141: } else {
18142: $resulttext = &mt('No changes made to user information settings');
18143: }
18144: } else {
18145: $resulttext = '<span class="LC_error">'.
18146: &mt('An error occurred: [_1]',$putresult).'</span>';
18147: }
18148: return $resulttext;
18149: }
18150:
1.354 raeburn 18151: sub modify_passwords {
18152: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18153: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18154: $updatedefaults,$updateconf);
1.354 raeburn 18155: my $customfn = 'resetpw.html';
18156: if (ref($domconfig{'passwords'}) eq 'HASH') {
18157: %current = %{$domconfig{'passwords'}};
18158: }
18159: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18160: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18161: if (ref($types) eq 'ARRAY') {
18162: @oktypes = @{$types};
18163: }
18164: push(@oktypes,'default');
18165:
18166: my %titles = &Apache::lonlocal::texthash (
18167: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18168: intauth_check => 'Check bcrypt cost if authenticated',
18169: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18170: permanent => 'Permanent e-mail address',
18171: critical => 'Critical notification address',
18172: notify => 'Notification address',
18173: min => 'Minimum password length',
18174: max => 'Maximum password length',
18175: chars => 'Required characters',
18176: expire => 'Password expiration (days)',
1.356 raeburn 18177: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18178: reset => 'Resetting Forgotten Password',
18179: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18180: rules => 'Rules for LON-CAPA Passwords',
18181: crsownerchg => 'Course Owner Changing Student Passwords',
18182: username => 'Username',
18183: email => 'E-mail address',
18184: );
18185:
18186: #
18187: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18188: #
18189: my (%curr_defaults,%save_defaults);
18190: if (ref($domconfig{'defaults'}) eq 'HASH') {
18191: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18192: if ($key =~ /^intauth_(cost|check|switch)$/) {
18193: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18194: } else {
18195: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18196: }
18197: }
18198: }
18199: my %staticdefaults = (
18200: 'resetlink' => 2,
18201: 'resetcase' => \@oktypes,
18202: 'resetprelink' => 'both',
18203: 'resetemail' => ['critical','notify','permanent'],
18204: 'intauth_cost' => 10,
18205: 'intauth_check' => 0,
18206: 'intauth_switch' => 0,
18207: );
1.365 raeburn 18208: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18209: foreach my $type (@oktypes) {
18210: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18211: }
18212: my $linklife = $env{'form.passwords_link'};
18213: $linklife =~ s/^\s+|\s+$//g;
18214: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18215: $newvalues{'resetlink'} = $linklife;
18216: if ($current{'resetlink'}) {
18217: if ($current{'resetlink'} ne $linklife) {
18218: $changes{'reset'} = 1;
18219: }
1.368 raeburn 18220: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18221: if ($staticdefaults{'resetlink'} ne $linklife) {
18222: $changes{'reset'} = 1;
18223: }
18224: }
18225: } elsif ($current{'resetlink'}) {
18226: $changes{'reset'} = 1;
18227: }
18228: my @casesens;
18229: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18230: foreach my $case (sort(@posscase)) {
18231: if (grep(/^\Q$case\E$/,@oktypes)) {
18232: push(@casesens,$case);
18233: }
18234: }
18235: $newvalues{'resetcase'} = \@casesens;
18236: if (ref($current{'resetcase'}) eq 'ARRAY') {
18237: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18238: if (@diffs > 0) {
18239: $changes{'reset'} = 1;
18240: }
1.368 raeburn 18241: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18242: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18243: if (@diffs > 0) {
18244: $changes{'reset'} = 1;
18245: }
18246: }
18247: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18248: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18249: if (exists($current{'resetprelink'})) {
18250: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18251: $changes{'reset'} = 1;
18252: }
1.368 raeburn 18253: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18254: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18255: $changes{'reset'} = 1;
18256: }
18257: }
18258: } elsif ($current{'resetprelink'}) {
18259: $changes{'reset'} = 1;
18260: }
18261: foreach my $type (@oktypes) {
18262: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18263: my @postlink;
18264: foreach my $item (sort(@possplink)) {
18265: if ($item =~ /^(email|username)$/) {
18266: push(@postlink,$item);
18267: }
18268: }
18269: $newvalues{'resetpostlink'}{$type} = \@postlink;
18270: unless ($changes{'reset'}) {
18271: if (ref($current{'resetpostlink'}) eq 'HASH') {
18272: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18273: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18274: if (@diffs > 0) {
18275: $changes{'reset'} = 1;
18276: }
18277: } else {
18278: $changes{'reset'} = 1;
18279: }
1.368 raeburn 18280: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18281: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18282: if (@diffs > 0) {
18283: $changes{'reset'} = 1;
18284: }
18285: }
18286: }
18287: }
18288: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18289: my @resetemail;
18290: foreach my $item (sort(@possemailsrc)) {
18291: if ($item =~ /^(permanent|critical|notify)$/) {
18292: push(@resetemail,$item);
18293: }
18294: }
18295: $newvalues{'resetemail'} = \@resetemail;
18296: unless ($changes{'reset'}) {
18297: if (ref($current{'resetemail'}) eq 'ARRAY') {
18298: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18299: if (@diffs > 0) {
18300: $changes{'reset'} = 1;
18301: }
1.368 raeburn 18302: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18303: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18304: if (@diffs > 0) {
18305: $changes{'reset'} = 1;
18306: }
18307: }
18308: }
18309: if ($env{'form.passwords_stdtext'} == 0) {
18310: $newvalues{'resetremove'} = 1;
18311: unless ($current{'resetremove'}) {
18312: $changes{'reset'} = 1;
18313: }
18314: } elsif ($current{'resetremove'}) {
18315: $changes{'reset'} = 1;
18316: }
18317: if ($env{'form.passwords_customfile.filename'} ne '') {
18318: my $servadm = $r->dir_config('lonAdmEMail');
18319: my ($configuserok,$author_ok,$switchserver) =
18320: &config_check($dom,$confname,$servadm);
18321: my $error;
18322: if ($configuserok eq 'ok') {
18323: if ($switchserver) {
18324: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18325: } else {
18326: if ($author_ok eq 'ok') {
1.421 raeburn 18327: my $modified = [];
1.354 raeburn 18328: my ($result,$customurl) =
1.421 raeburn 18329: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18330: $confname,'customtext/resetpw','','',$customfn,
18331: $modified);
1.354 raeburn 18332: if ($result eq 'ok') {
18333: $newvalues{'resetcustom'} = $customurl;
18334: $changes{'reset'} = 1;
1.421 raeburn 18335: &update_modify_urls($r,$modified);
1.354 raeburn 18336: } else {
18337: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18338: }
18339: } else {
18340: $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);
18341: }
18342: }
18343: } else {
18344: $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);
18345: }
18346: if ($error) {
18347: &Apache::lonnet::logthis($error);
18348: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18349: }
18350: } elsif ($current{'resetcustom'}) {
18351: if ($env{'form.passwords_custom_del'}) {
18352: $changes{'reset'} = 1;
18353: } else {
18354: $newvalues{'resetcustom'} = $current{'resetcustom'};
18355: }
18356: }
18357: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18358: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18359: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18360: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18361: $changes{'intauth'} = 1;
18362: }
18363: } else {
18364: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18365: }
18366: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18367: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18368: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18369: $changes{'intauth'} = 1;
18370: }
18371: } else {
18372: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18373: }
18374: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18375: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18376: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18377: $changes{'intauth'} = 1;
18378: }
18379: } else {
18380: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18381: }
18382: foreach my $item ('cost','check','switch') {
18383: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18384: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18385: $updatedefaults = 1;
18386: }
18387: }
1.405 raeburn 18388: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18389: my %crsownerchg = (
18390: by => [],
18391: for => [],
18392: );
18393: foreach my $item ('by','for') {
18394: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18395: foreach my $type (sort(@posstypes)) {
18396: if (grep(/^\Q$type\E$/,@oktypes)) {
18397: push(@{$crsownerchg{$item}},$type);
18398: }
18399: }
18400: }
18401: $newvalues{'crsownerchg'} = \%crsownerchg;
18402: if (ref($current{'crsownerchg'}) eq 'HASH') {
18403: foreach my $item ('by','for') {
18404: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18405: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18406: if (@diffs > 0) {
18407: $changes{'crsownerchg'} = 1;
18408: last;
18409: }
18410: }
18411: }
1.368 raeburn 18412: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18413: foreach my $item ('by','for') {
18414: if (@{$crsownerchg{$item}} > 0) {
18415: $changes{'crsownerchg'} = 1;
18416: last;
18417: }
1.354 raeburn 18418: }
18419: }
18420:
18421: my %confighash = (
18422: defaults => \%save_defaults,
18423: passwords => \%newvalues,
18424: );
18425: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18426:
18427: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18428: if ($putresult eq 'ok') {
18429: if (keys(%changes) > 0) {
18430: $resulttext = &mt('Changes made: ').'<ul>';
18431: foreach my $key ('reset','intauth','rules','crsownerchg') {
18432: if ($changes{$key}) {
1.355 raeburn 18433: unless ($key eq 'intauth') {
18434: $updateconf = 1;
18435: }
1.354 raeburn 18436: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18437: if ($key eq 'reset') {
18438: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18439: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18440: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18441: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18442: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18443: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18444: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18445: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18446: }
1.354 raeburn 18447: } else {
18448: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18449: }
18450: if ($confighash{'passwords'}{'resetlink'}) {
18451: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18452: } else {
18453: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18454: &mt('Will default to 2 hours').'</li>';
18455: }
18456: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18457: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18458: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18459: } else {
18460: my $casesens;
18461: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18462: if ($type eq 'default') {
18463: $casesens .= $othertitle.', ';
18464: } elsif ($usertypes->{$type} ne '') {
18465: $casesens .= $usertypes->{$type}.', ';
18466: }
18467: }
18468: $casesens =~ s/\Q, \E$//;
18469: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18470: }
18471: } else {
18472: $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>';
18473: }
18474: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18475: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18476: } else {
18477: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18478: }
18479: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18480: my $output;
18481: if (ref($types) eq 'ARRAY') {
18482: foreach my $type (@{$types}) {
18483: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18484: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18485: $output .= $usertypes->{$type}.' -- '.&mt('none');
18486: } else {
18487: $output .= $usertypes->{$type}.' -- '.
18488: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18489: }
18490: }
18491: }
18492: }
18493: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18494: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18495: $output .= $othertitle.' -- '.&mt('none');
18496: } else {
18497: $output .= $othertitle.' -- '.
18498: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18499: }
18500: }
18501: if ($output) {
18502: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18503: } else {
18504: $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>';
18505: }
18506: } else {
18507: $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>';
18508: }
18509: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18510: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18511: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18512: } else {
18513: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18514: }
18515: } else {
1.379 raeburn 18516: $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 18517: }
18518: if ($confighash{'passwords'}{'resetremove'}) {
18519: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18520: } else {
18521: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18522: }
18523: if ($confighash{'passwords'}{'resetcustom'}) {
18524: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18525: &mt('custom text'),600,500,undef,undef,
18526: undef,undef,'background-color:#ffffff');
18527: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18528: } else {
18529: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18530: }
18531: } elsif ($key eq 'intauth') {
18532: foreach my $item ('cost','switch','check') {
18533: my $value = $save_defaults{$key.'_'.$item};
18534: if ($item eq 'switch') {
18535: my %optiondesc = &Apache::lonlocal::texthash (
18536: 0 => 'No',
18537: 1 => 'Yes',
18538: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18539: );
18540: if ($value =~ /^(0|1|2)$/) {
18541: $value = $optiondesc{$value};
18542: } else {
18543: $value = &mt('none -- defaults to No');
18544: }
18545: } elsif ($item eq 'check') {
18546: my %optiondesc = &Apache::lonlocal::texthash (
18547: 0 => 'No',
18548: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18549: 2 => 'Yes, disallow login if stored cost is less than domain default',
18550: );
18551: if ($value =~ /^(0|1|2)$/) {
18552: $value = $optiondesc{$value};
18553: } else {
18554: $value = &mt('none -- defaults to No');
18555: }
18556: }
18557: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18558: }
18559: } elsif ($key eq 'rules') {
1.356 raeburn 18560: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18561: if ($confighash{'passwords'}{$rule} eq '') {
18562: if ($rule eq 'min') {
1.356 raeburn 18563: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18564: ' '.&mt('Default of [_1] will be used',
18565: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18566: } else {
18567: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18568: }
18569: } else {
18570: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18571: }
18572: }
1.370 raeburn 18573: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18574: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18575: my %rulenames = &Apache::lonlocal::texthash(
18576: uc => 'At least one upper case letter',
18577: lc => 'At least one lower case letter',
18578: num => 'At least one number',
18579: spec => 'At least one non-alphanumeric',
18580: );
18581: my $needed = '<ul><li>'.
18582: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18583: '</li></ul>';
1.370 raeburn 18584: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18585: } else {
18586: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18587: }
18588: } else {
18589: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18590: }
1.354 raeburn 18591: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18592: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18593: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18594: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18595: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18596: } else {
18597: my %crsownerstr;
18598: foreach my $item ('by','for') {
18599: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18600: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18601: if ($type eq 'default') {
18602: $crsownerstr{$item} .= $othertitle.', ';
18603: } elsif ($usertypes->{$type} ne '') {
18604: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18605: }
18606: }
18607: $crsownerstr{$item} =~ s/\Q, \E$//;
18608: }
18609: }
18610: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18611: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18612: }
1.354 raeburn 18613: } else {
1.359 raeburn 18614: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18615: }
18616: }
18617: $resulttext .= '</ul></li>';
18618: }
18619: }
18620: $resulttext .= '</ul>';
18621: } else {
18622: $resulttext = &mt('No changes made to password settings');
18623: }
1.355 raeburn 18624: my $cachetime = 24*60*60;
1.354 raeburn 18625: if ($updatedefaults) {
18626: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18627: if (ref($lastactref) eq 'HASH') {
18628: $lastactref->{'domdefaults'} = 1;
18629: }
18630: }
1.355 raeburn 18631: if ($updateconf) {
18632: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18633: if (ref($lastactref) eq 'HASH') {
18634: $lastactref->{'passwdconf'} = 1;
18635: }
18636: }
1.354 raeburn 18637: } else {
18638: $resulttext = '<span class="LC_error">'.
18639: &mt('An error occurred: [_1]',$putresult).'</span>';
18640: }
18641: if ($errors) {
18642: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18643: $errors.'</ul></p>';
18644: }
18645: return $resulttext;
18646: }
18647:
1.405 raeburn 18648: sub password_rule_changes {
18649: my ($prefix,$newvalues,$current,$changes) = @_;
18650: return unless ((ref($newvalues) eq 'HASH') &&
18651: (ref($current) eq 'HASH') &&
18652: (ref($changes) eq 'HASH'));
18653: my (@rules,%staticdefaults);
18654: if ($prefix eq 'passwords') {
18655: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18656: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18657: @rules = ('min','max');
18658: }
18659: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18660: foreach my $rule (@rules) {
18661: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18662: my $ruleok;
18663: if ($rule eq 'expire') {
18664: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18665: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18666: $ruleok = 1;
18667: }
18668: } elsif ($rule eq 'min') {
18669: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18670: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18671: $ruleok = 1;
18672: }
18673: }
18674: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18675: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18676: $ruleok = 1;
18677: }
18678: if ($ruleok) {
18679: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18680: if (exists($current->{$rule})) {
18681: if ($newvalues->{$rule} ne $current->{$rule}) {
18682: $changes->{'rules'} = 1;
18683: }
18684: } elsif ($rule eq 'min') {
18685: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18686: $changes->{'rules'} = 1;
18687: }
18688: } else {
18689: $changes->{'rules'} = 1;
18690: }
18691: } elsif (exists($current->{$rule})) {
18692: $changes->{'rules'} = 1;
18693: }
18694: }
18695: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18696: my @chars;
18697: foreach my $item (sort(@posschars)) {
18698: if ($item =~ /^(uc|lc|num|spec)$/) {
18699: push(@chars,$item);
18700: }
18701: }
18702: $newvalues->{'chars'} = \@chars;
18703: unless ($changes->{'rules'}) {
18704: if (ref($current->{'chars'}) eq 'ARRAY') {
18705: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18706: if (@diffs > 0) {
18707: $changes->{'rules'} = 1;
18708: }
18709: } else {
18710: if (@chars > 0) {
18711: $changes->{'rules'} = 1;
18712: }
18713: }
18714: }
18715: return;
18716: }
18717:
1.28 raeburn 18718: sub modify_usercreation {
1.27 raeburn 18719: my ($dom,%domconfig) = @_;
1.224 raeburn 18720: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18721: my $warningmsg;
1.27 raeburn 18722: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18723: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18724: if ($key eq 'cancreate') {
18725: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18726: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18727: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18728: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18729: } else {
1.224 raeburn 18730: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18731: }
18732: }
18733: }
18734: } elsif ($key eq 'email_rule') {
18735: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18736: } else {
18737: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18738: }
1.27 raeburn 18739: }
18740: }
18741: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18742: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18743: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18744: foreach my $item(@contexts) {
1.224 raeburn 18745: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18746: }
1.34 raeburn 18747: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18748: foreach my $item (@contexts) {
1.224 raeburn 18749: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18750: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18751: }
1.27 raeburn 18752: }
1.34 raeburn 18753: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18754: foreach my $item (@contexts) {
1.43 raeburn 18755: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18756: if ($cancreate{$item} ne 'any') {
18757: push(@{$changes{'cancreate'}},$item);
18758: }
18759: } else {
18760: if ($cancreate{$item} ne 'none') {
18761: push(@{$changes{'cancreate'}},$item);
18762: }
1.27 raeburn 18763: }
18764: }
18765: } else {
1.43 raeburn 18766: foreach my $item (@contexts) {
1.34 raeburn 18767: push(@{$changes{'cancreate'}},$item);
18768: }
1.27 raeburn 18769: }
1.34 raeburn 18770:
1.27 raeburn 18771: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18772: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18773: if (!grep(/^\Q$type\E$/,@username_rule)) {
18774: push(@{$changes{'username_rule'}},$type);
18775: }
18776: }
18777: foreach my $type (@username_rule) {
18778: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18779: push(@{$changes{'username_rule'}},$type);
18780: }
18781: }
18782: } else {
18783: push(@{$changes{'username_rule'}},@username_rule);
18784: }
18785:
1.32 raeburn 18786: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18787: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18788: if (!grep(/^\Q$type\E$/,@id_rule)) {
18789: push(@{$changes{'id_rule'}},$type);
18790: }
18791: }
18792: foreach my $type (@id_rule) {
18793: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18794: push(@{$changes{'id_rule'}},$type);
18795: }
18796: }
18797: } else {
18798: push(@{$changes{'id_rule'}},@id_rule);
18799: }
18800:
1.43 raeburn 18801: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18802: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18803: my %authhash;
1.43 raeburn 18804: foreach my $item (@authen_contexts) {
1.28 raeburn 18805: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18806: foreach my $auth (@authtypes) {
18807: if (grep(/^\Q$auth\E$/,@authallowed)) {
18808: $authhash{$item}{$auth} = 1;
18809: } else {
18810: $authhash{$item}{$auth} = 0;
18811: }
18812: }
18813: }
18814: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18815: foreach my $item (@authen_contexts) {
1.28 raeburn 18816: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18817: foreach my $auth (@authtypes) {
18818: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18819: push(@{$changes{'authtypes'}},$item);
18820: last;
18821: }
18822: }
18823: }
18824: }
18825: } else {
1.43 raeburn 18826: foreach my $item (@authen_contexts) {
1.28 raeburn 18827: push(@{$changes{'authtypes'}},$item);
18828: }
18829: }
18830:
1.224 raeburn 18831: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18832: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18833: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18834: $save_usercreate{'id_rule'} = \@id_rule;
18835: $save_usercreate{'username_rule'} = \@username_rule,
18836: $save_usercreate{'authtypes'} = \%authhash;
18837:
1.27 raeburn 18838: my %usercreation_hash = (
1.224 raeburn 18839: usercreation => \%save_usercreate,
18840: );
1.27 raeburn 18841:
18842: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18843: $dom);
1.50 raeburn 18844:
1.224 raeburn 18845: if ($putresult eq 'ok') {
18846: if (keys(%changes) > 0) {
18847: $resulttext = &mt('Changes made:').'<ul>';
18848: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18849: my %lt = &usercreation_types();
18850: foreach my $type (@{$changes{'cancreate'}}) {
18851: my $chgtext = $lt{$type}.', ';
18852: if ($cancreate{$type} eq 'none') {
18853: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18854: } elsif ($cancreate{$type} eq 'any') {
18855: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18856: } elsif ($cancreate{$type} eq 'official') {
18857: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18858: } elsif ($cancreate{$type} eq 'unofficial') {
18859: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18860: }
18861: $resulttext .= '<li>'.$chgtext.'</li>';
18862: }
18863: }
18864: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18865: my ($rules,$ruleorder) =
18866: &Apache::lonnet::inst_userrules($dom,'username');
18867: my $chgtext = '<ul>';
18868: foreach my $type (@username_rule) {
18869: if (ref($rules->{$type}) eq 'HASH') {
18870: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18871: }
18872: }
18873: $chgtext .= '</ul>';
18874: if (@username_rule > 0) {
18875: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18876: } else {
18877: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18878: }
18879: }
18880: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18881: my ($idrules,$idruleorder) =
18882: &Apache::lonnet::inst_userrules($dom,'id');
18883: my $chgtext = '<ul>';
18884: foreach my $type (@id_rule) {
18885: if (ref($idrules->{$type}) eq 'HASH') {
18886: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18887: }
18888: }
18889: $chgtext .= '</ul>';
18890: if (@id_rule > 0) {
18891: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18892: } else {
18893: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18894: }
18895: }
18896: my %authname = &authtype_names();
18897: my %context_title = &context_names();
18898: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18899: my $chgtext = '<ul>';
18900: foreach my $type (@{$changes{'authtypes'}}) {
18901: my @allowed;
18902: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18903: foreach my $auth (@authtypes) {
18904: if ($authhash{$type}{$auth}) {
18905: push(@allowed,$authname{$auth});
18906: }
18907: }
18908: if (@allowed > 0) {
18909: $chgtext .= join(', ',@allowed).'</li>';
18910: } else {
18911: $chgtext .= &mt('none').'</li>';
18912: }
18913: }
18914: $chgtext .= '</ul>';
18915: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18916: $resulttext .= '</li>';
18917: }
18918: $resulttext .= '</ul>';
18919: } else {
18920: $resulttext = &mt('No changes made to user creation settings');
18921: }
18922: } else {
18923: $resulttext = '<span class="LC_error">'.
18924: &mt('An error occurred: [_1]',$putresult).'</span>';
18925: }
18926: if ($warningmsg ne '') {
18927: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18928: }
18929: return $resulttext;
18930: }
18931:
18932: sub modify_selfcreation {
1.305 raeburn 18933: my ($dom,$lastactref,%domconfig) = @_;
18934: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18935: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18936: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18937: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18938: if (ref($typesref) eq 'ARRAY') {
18939: @types = @{$typesref};
18940: }
18941: if (ref($usertypesref) eq 'HASH') {
18942: %usertypes = %{$usertypesref};
1.228 raeburn 18943: }
1.303 raeburn 18944: $usertypes{'default'} = $othertitle;
1.224 raeburn 18945: #
18946: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18947: #
18948: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18949: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18950: if ($key eq 'cancreate') {
18951: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18952: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18953: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18954: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18955: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18956: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18957: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18958: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18959: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18960: } else {
18961: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18962: }
18963: }
18964: }
18965: } elsif ($key eq 'email_rule') {
18966: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18967: } else {
18968: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18969: }
18970: }
18971: }
18972: #
18973: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18974: #
18975: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18976: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18977: if ($key eq 'selfcreate') {
18978: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18979: } else {
18980: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18981: }
18982: }
18983: }
1.305 raeburn 18984: #
18985: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18986: #
18987: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18988: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18989: if ($key eq 'inststatusguest') {
18990: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18991: } else {
18992: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18993: }
18994: }
18995: }
1.224 raeburn 18996:
18997: my @contexts = ('selfcreate');
18998: @{$cancreate{'selfcreate'}} = ();
18999: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 19000: if (@types) {
19001: @{$cancreate{'statustocreate'}} = ();
19002: }
1.236 raeburn 19003: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 19004: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 19005: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19006: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19007: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19008: my %selfcreatetypes = (
19009: sso => 'users authenticated by institutional single sign on',
19010: login => 'users authenticated by institutional log-in',
1.303 raeburn 19011: email => 'users verified by e-mail',
1.50 raeburn 19012: );
1.224 raeburn 19013: #
19014: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19015: # is permitted.
19016: #
1.305 raeburn 19017: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19018:
1.305 raeburn 19019: my (@statuses,%email_rule);
1.228 raeburn 19020: foreach my $item ('login','sso','email') {
1.224 raeburn 19021: if ($item eq 'email') {
1.236 raeburn 19022: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19023: if (@types) {
19024: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19025: foreach my $status (@poss_statuses) {
19026: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19027: push(@statuses,$status);
19028: }
19029: }
19030: $save_inststatus{'inststatusguest'} = \@statuses;
19031: } else {
19032: push(@statuses,'default');
19033: }
19034: if (@statuses) {
19035: my %curr_rule;
19036: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19037: foreach my $type (@statuses) {
19038: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19039: }
1.305 raeburn 19040: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19041: foreach my $type (@statuses) {
19042: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19043: }
19044: }
19045: push(@{$cancreate{'selfcreate'}},'email');
19046: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19047: my %curremaildom;
19048: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19049: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19050: }
19051: foreach my $type (@statuses) {
19052: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19053: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19054: }
19055: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19056: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19057: }
19058: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19059: #
19060: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19061: #
19062: my $chosen = $1;
19063: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19064: my $emaildom;
19065: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19066: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19067: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19068: if (ref($curremaildom{$type}) eq 'HASH') {
19069: if (exists($curremaildom{$type}{$chosen})) {
19070: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19071: push(@{$changes{'cancreate'}},'emaildomain');
19072: }
19073: } elsif ($emaildom ne '') {
19074: push(@{$changes{'cancreate'}},'emaildomain');
19075: }
19076: } elsif ($emaildom ne '') {
19077: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19078: }
1.305 raeburn 19079: }
19080: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19081: } elsif ($chosen eq 'custom') {
19082: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19083: $email_rule{$type} = [];
19084: if (ref($emailrules) eq 'HASH') {
19085: foreach my $rule (@possemail_rules) {
19086: if (exists($emailrules->{$rule})) {
19087: push(@{$email_rule{$type}},$rule);
19088: }
19089: }
19090: }
19091: if (@{$email_rule{$type}}) {
19092: $cancreate{'emailoptions'}{$type} = 'custom';
19093: if (ref($curr_rule{$type}) eq 'ARRAY') {
19094: if (@{$curr_rule{$type}} > 0) {
19095: foreach my $rule (@{$curr_rule{$type}}) {
19096: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19097: push(@{$changes{'email_rule'}},$type);
19098: }
19099: }
19100: }
19101: foreach my $type (@{$email_rule{$type}}) {
19102: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19103: push(@{$changes{'email_rule'}},$type);
19104: }
19105: }
19106: } else {
19107: push(@{$changes{'email_rule'}},$type);
19108: }
19109: }
19110: } else {
19111: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19112: }
19113: }
19114: }
19115: if (@types) {
19116: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19117: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19118: if (@changed) {
19119: push(@{$changes{'inststatus'}},'inststatusguest');
19120: }
19121: } else {
19122: push(@{$changes{'inststatus'}},'inststatusguest');
19123: }
19124: }
19125: } else {
19126: delete($env{'form.cancreate_email'});
19127: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19128: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19129: push(@{$changes{'inststatus'}},'inststatusguest');
19130: }
19131: }
19132: }
19133: } else {
19134: $save_inststatus{'inststatusguest'} = [];
19135: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19136: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19137: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19138: }
19139: }
1.224 raeburn 19140: }
19141: } else {
19142: if ($env{'form.cancreate_'.$item}) {
19143: push(@{$cancreate{'selfcreate'}},$item);
19144: }
19145: }
19146: }
1.305 raeburn 19147: my (%userinfo,%savecaptcha);
1.224 raeburn 19148: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19149: #
1.228 raeburn 19150: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19151: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19152: #
1.236 raeburn 19153:
1.244 raeburn 19154: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19155: push(@contexts,'emailusername');
1.305 raeburn 19156: if (@statuses) {
19157: foreach my $type (@statuses) {
1.228 raeburn 19158: if (ref($infofields) eq 'ARRAY') {
19159: foreach my $field (@{$infofields}) {
19160: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19161: $cancreate{'emailusername'}{$type}{$field} = $1;
19162: }
19163: }
1.224 raeburn 19164: }
19165: }
19166: }
19167: #
19168: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19169: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19170: #
19171:
19172: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19173: @approvalnotify = sort(@approvalnotify);
19174: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19175: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19176: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19177: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19178: push(@{$changes{'cancreate'}},'notify');
19179: }
19180: } else {
19181: if ($cancreate{'notify'}{'approval'}) {
19182: push(@{$changes{'cancreate'}},'notify');
19183: }
19184: }
19185: } elsif ($cancreate{'notify'}{'approval'}) {
19186: push(@{$changes{'cancreate'}},'notify');
19187: }
19188:
19189: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19190: }
19191: #
1.236 raeburn 19192: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19193: # institutional log-in.
19194: #
19195: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19196: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19197: ($domdefaults{'auth_def'} eq 'localauth'))) {
19198: $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.').' '.
19199: &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.');
19200: }
19201: }
19202: my @fields = ('lastname','firstname','middlename','generation',
19203: 'permanentemail','id');
1.240 raeburn 19204: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19205: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19206: #
19207: # Where usernames may created for institutional log-in and/or institutional single sign on:
19208: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19209: # may self-create accounts
19210: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19211: # which the user may supply, if institutional data is unavailable.
19212: #
19213: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19214: if (@types) {
1.305 raeburn 19215: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19216: push(@contexts,'statustocreate');
1.303 raeburn 19217: foreach my $type (@types) {
1.224 raeburn 19218: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19219: foreach my $field (@fields) {
19220: if (grep(/^\Q$field\E$/,@modifiable)) {
19221: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19222: } else {
19223: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19224: }
19225: }
19226: }
19227: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19228: foreach my $type (@types) {
1.224 raeburn 19229: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19230: foreach my $field (@fields) {
19231: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19232: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19233: push(@{$changes{'selfcreate'}},$type);
19234: last;
19235: }
19236: }
19237: }
19238: }
19239: } else {
1.303 raeburn 19240: foreach my $type (@types) {
1.224 raeburn 19241: push(@{$changes{'selfcreate'}},$type);
19242: }
19243: }
19244: }
1.240 raeburn 19245: foreach my $field (@shibfields) {
19246: if ($env{'form.shibenv_'.$field} ne '') {
19247: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19248: }
19249: }
19250: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19251: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19252: foreach my $field (@shibfields) {
19253: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19254: push(@{$changes{'cancreate'}},'shibenv');
19255: }
19256: }
19257: } else {
19258: foreach my $field (@shibfields) {
19259: if ($env{'form.shibenv_'.$field}) {
19260: push(@{$changes{'cancreate'}},'shibenv');
19261: last;
19262: }
19263: }
19264: }
19265: }
1.224 raeburn 19266: }
19267: foreach my $item (@contexts) {
19268: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19269: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19270: if (ref($cancreate{$item}) eq 'ARRAY') {
19271: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19272: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19273: push(@{$changes{'cancreate'}},$item);
19274: }
19275: }
19276: }
19277: }
19278: if (ref($cancreate{$item}) eq 'ARRAY') {
19279: foreach my $type (@{$cancreate{$item}}) {
19280: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19281: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19282: push(@{$changes{'cancreate'}},$item);
19283: }
19284: }
19285: }
19286: }
19287: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19288: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19289: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19290: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19291: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19292: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19293: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19294: push(@{$changes{'cancreate'}},$item);
19295: }
19296: }
19297: }
1.305 raeburn 19298: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19299: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19300: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19301: push(@{$changes{'cancreate'}},$item);
19302: }
1.224 raeburn 19303: }
19304: }
19305: }
1.305 raeburn 19306: foreach my $type (keys(%{$cancreate{$item}})) {
19307: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19308: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19309: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19310: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19311: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19312: push(@{$changes{'cancreate'}},$item);
19313: }
19314: }
19315: } else {
19316: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19317: push(@{$changes{'cancreate'}},$item);
19318: }
19319: }
19320: }
1.305 raeburn 19321: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19322: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19323: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19324: push(@{$changes{'cancreate'}},$item);
19325: }
1.224 raeburn 19326: }
19327: }
19328: }
19329: }
19330: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19331: if (ref($cancreate{$item}) eq 'ARRAY') {
19332: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19333: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19334: push(@{$changes{'cancreate'}},$item);
19335: }
19336: }
1.305 raeburn 19337: }
19338: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19339: if (ref($cancreate{$item}) eq 'HASH') {
19340: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19341: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19342: }
19343: }
19344: } elsif ($item eq 'emailusername') {
1.228 raeburn 19345: if (ref($cancreate{$item}) eq 'HASH') {
19346: foreach my $type (keys(%{$cancreate{$item}})) {
19347: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19348: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19349: if ($cancreate{$item}{$type}{$field}) {
19350: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19351: push(@{$changes{'cancreate'}},$item);
19352: }
19353: last;
19354: }
19355: }
19356: }
19357: }
1.224 raeburn 19358: }
19359: }
19360: }
19361: #
19362: # Populate %save_usercreate hash with updates to self-creation configuration.
19363: #
19364: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19365: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19366: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19367: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19368: if (ref($cancreate{'notify'}) eq 'HASH') {
19369: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19370: }
1.236 raeburn 19371: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19372: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19373: }
1.303 raeburn 19374: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19375: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19376: }
1.305 raeburn 19377: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19378: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19379: }
1.303 raeburn 19380: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19381: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19382: }
1.224 raeburn 19383: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19384: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19385: }
1.240 raeburn 19386: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19387: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19388: }
1.224 raeburn 19389: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19390: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19391:
19392: my %userconfig_hash = (
19393: usercreation => \%save_usercreate,
19394: usermodification => \%save_usermodify,
1.305 raeburn 19395: inststatus => \%save_inststatus,
1.224 raeburn 19396: );
1.305 raeburn 19397:
1.224 raeburn 19398: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19399: $dom);
19400: #
1.305 raeburn 19401: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19402: #
1.27 raeburn 19403: if ($putresult eq 'ok') {
19404: if (keys(%changes) > 0) {
19405: $resulttext = &mt('Changes made:').'<ul>';
19406: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19407: my %lt = &selfcreation_types();
1.34 raeburn 19408: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19409: my $chgtext = '';
1.45 raeburn 19410: if ($type eq 'selfcreate') {
1.50 raeburn 19411: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19412: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19413: } else {
1.224 raeburn 19414: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19415: '<ul>';
1.50 raeburn 19416: foreach my $case (@{$cancreate{$type}}) {
19417: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19418: }
19419: $chgtext .= '</ul>';
1.100 raeburn 19420: if (ref($cancreate{$type}) eq 'ARRAY') {
19421: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19422: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19423: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19424: $chgtext .= '<span class="LC_warning">'.
19425: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19426: '</span><br />';
19427: }
19428: }
19429: }
19430: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19431: if (!@statuses) {
19432: $chgtext .= '<span class="LC_warning">'.
19433: &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.").
19434: '</span><br />';
1.303 raeburn 19435:
1.100 raeburn 19436: }
19437: }
19438: }
1.43 raeburn 19439: }
1.240 raeburn 19440: } elsif ($type eq 'shibenv') {
19441: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19442: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19443: } else {
19444: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19445: '<ul>';
19446: foreach my $field (@shibfields) {
19447: next if ($cancreate{$type}{$field} eq '');
19448: if ($field eq 'inststatus') {
19449: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19450: } else {
19451: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19452: }
19453: }
19454: $chgtext .= '</ul>';
1.303 raeburn 19455: }
1.93 raeburn 19456: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19457: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19458: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19459: if (@{$cancreate{'selfcreate'}} > 0) {
19460: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19461: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19462: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19463: $chgtext .= '<br />'.
19464: '<span class="LC_warning">'.
19465: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19466: '</span>';
19467: }
1.303 raeburn 19468: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19469: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19470: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19471: } else {
19472: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19473: }
19474: $chgtext .= '<ul>';
19475: foreach my $case (@{$cancreate{$type}}) {
19476: if ($case eq 'default') {
19477: $chgtext .= '<li>'.$othertitle.'</li>';
19478: } else {
1.303 raeburn 19479: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19480: }
19481: }
1.100 raeburn 19482: $chgtext .= '</ul>';
19483: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19484: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19485: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19486: '</span>';
1.100 raeburn 19487: }
19488: }
19489: } else {
19490: if (@{$cancreate{$type}} == 0) {
19491: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19492: } else {
19493: $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 19494: }
19495: }
1.303 raeburn 19496: $chgtext .= '<br />';
1.93 raeburn 19497: }
1.236 raeburn 19498: } elsif ($type eq 'selfcreateprocessing') {
19499: my %choices = &Apache::lonlocal::texthash (
19500: automatic => 'Automatic approval',
19501: approval => 'Queued for approval',
19502: );
1.305 raeburn 19503: if (@types) {
19504: if (@statuses) {
1.425 raeburn 19505: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19506: '<ul>';
1.305 raeburn 19507: foreach my $status (@statuses) {
19508: if ($status eq 'default') {
19509: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19510: } else {
1.305 raeburn 19511: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19512: }
19513: }
19514: $chgtext .= '</ul>';
19515: }
19516: } else {
19517: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19518: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19519: }
19520: } elsif ($type eq 'emailverified') {
19521: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19522: all => 'Same as e-mail',
19523: first => 'Omit @domain',
19524: free => 'Free to choose',
1.303 raeburn 19525: );
1.305 raeburn 19526: if (@types) {
19527: if (@statuses) {
1.303 raeburn 19528: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19529: '<ul>';
1.305 raeburn 19530: foreach my $status (@statuses) {
1.362 raeburn 19531: if ($status eq 'default') {
1.305 raeburn 19532: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19533: } else {
1.305 raeburn 19534: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19535: }
19536: }
19537: $chgtext .= '</ul>';
19538: }
19539: } else {
1.305 raeburn 19540: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19541: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19542: }
1.305 raeburn 19543: } elsif ($type eq 'emailoptions') {
19544: my %options = &Apache::lonlocal::texthash (
19545: any => 'Any e-mail',
19546: inst => 'Institutional only',
19547: noninst => 'Non-institutional only',
19548: custom => 'Custom restrictions',
19549: );
19550: if (@types) {
19551: if (@statuses) {
19552: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19553: '<ul>';
19554: foreach my $status (@statuses) {
19555: if ($type eq 'default') {
19556: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19557: } else {
19558: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19559: }
19560: }
1.305 raeburn 19561: $chgtext .= '</ul>';
19562: }
19563: } else {
19564: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19565: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19566: } else {
19567: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19568: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19569: }
1.305 raeburn 19570: }
19571: } elsif ($type eq 'emaildomain') {
19572: my $output;
19573: if (@statuses) {
19574: foreach my $type (@statuses) {
19575: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19576: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19577: if ($type eq 'default') {
19578: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19579: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19580: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19581: } else {
19582: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19583: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19584: }
1.303 raeburn 19585: } else {
1.305 raeburn 19586: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19587: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19588: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19589: } else {
19590: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19591: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19592: }
1.303 raeburn 19593: }
1.305 raeburn 19594: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19595: if ($type eq 'default') {
19596: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19597: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19598: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19599: } else {
19600: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19601: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19602: }
1.303 raeburn 19603: } else {
1.305 raeburn 19604: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19605: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19606: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19607: } else {
19608: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19609: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19610: }
1.303 raeburn 19611: }
19612: }
19613: }
19614: }
1.305 raeburn 19615: }
19616: if ($output ne '') {
19617: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19618: '<ul>'.$output.'</ul>';
1.236 raeburn 19619: }
1.165 raeburn 19620: } elsif ($type eq 'captcha') {
1.224 raeburn 19621: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19622: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19623: } else {
19624: my %captchas = &captcha_phrases();
1.224 raeburn 19625: if ($captchas{$savecaptcha{$type}}) {
19626: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19627: } else {
1.210 raeburn 19628: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19629: }
19630: }
19631: } elsif ($type eq 'recaptchakeys') {
19632: my ($privkey,$pubkey);
1.224 raeburn 19633: if (ref($savecaptcha{$type}) eq 'HASH') {
19634: $pubkey = $savecaptcha{$type}{'public'};
19635: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19636: }
19637: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19638: if (!$pubkey) {
19639: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19640: } else {
19641: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19642: }
19643: if (!$privkey) {
19644: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19645: } else {
19646: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19647: }
19648: $chgtext .= '</ul>';
1.269 raeburn 19649: } elsif ($type eq 'recaptchaversion') {
19650: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19651: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19652: }
1.224 raeburn 19653: } elsif ($type eq 'emailusername') {
19654: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19655: if (@statuses) {
19656: foreach my $type (@statuses) {
1.228 raeburn 19657: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19658: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19659: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19660: '<ul>';
19661: foreach my $field (@{$infofields}) {
19662: if ($cancreate{'emailusername'}{$type}{$field}) {
19663: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19664: }
19665: }
1.245 raeburn 19666: $chgtext .= '</ul>';
19667: } else {
1.303 raeburn 19668: $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 19669: }
19670: } else {
1.303 raeburn 19671: $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 19672: }
19673: }
19674: }
19675: }
19676: } elsif ($type eq 'notify') {
1.303 raeburn 19677: my $numapprove = 0;
1.224 raeburn 19678: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19679: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19680: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19681: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19682: $numapprove ++;
1.224 raeburn 19683: }
19684: }
1.43 raeburn 19685: }
1.303 raeburn 19686: unless ($numapprove) {
19687: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19688: }
1.34 raeburn 19689: }
1.224 raeburn 19690: if ($chgtext) {
19691: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19692: }
19693: }
19694: }
1.305 raeburn 19695: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19696: my ($emailrules,$emailruleorder) =
19697: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19698: foreach my $type (@{$changes{'email_rule'}}) {
19699: if (ref($email_rule{$type}) eq 'ARRAY') {
19700: my $chgtext = '<ul>';
19701: foreach my $rule (@{$email_rule{$type}}) {
19702: if (ref($emailrules->{$rule}) eq 'HASH') {
19703: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19704: }
19705: }
19706: $chgtext .= '</ul>';
1.310 raeburn 19707: my $typename;
1.305 raeburn 19708: if (@types) {
19709: if ($type eq 'default') {
19710: $typename = $othertitle;
19711: } else {
19712: $typename = $usertypes{$type};
1.425 raeburn 19713: }
1.305 raeburn 19714: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19715: }
19716: if (@{$email_rule{$type}} > 0) {
19717: $resulttext .= '<li>'.
19718: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19719: $usertypes{$type}).
19720: $chgtext.
19721: '</li>';
19722: } else {
19723: $resulttext .= '<li>'.
1.310 raeburn 19724: &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 19725: '</li>'.
1.310 raeburn 19726: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19727: }
1.43 raeburn 19728: }
19729: }
1.305 raeburn 19730: }
19731: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19732: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19733: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19734: my $chgtext = '<ul>';
19735: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19736: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19737: }
19738: $chgtext .= '</ul>';
19739: $resulttext .= '<li>'.
19740: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19741: $chgtext.
19742: '</li>';
19743: } else {
19744: $resulttext .= '<li>'.
19745: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19746: '</li>';
19747: }
1.43 raeburn 19748: }
19749: }
1.224 raeburn 19750: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19751: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19752: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19753: foreach my $type (@{$changes{'selfcreate'}}) {
19754: my $typename = $type;
1.303 raeburn 19755: if (keys(%usertypes) > 0) {
19756: if ($usertypes{$type} ne '') {
19757: $typename = $usertypes{$type};
1.224 raeburn 19758: }
19759: }
19760: my @modifiable;
19761: $resulttext .= '<li>'.
19762: &mt('Self-creation of account by users with status: [_1]',
19763: '<span class="LC_cusr_emph">'.$typename.'</span>').
19764: ' - '.&mt('modifiable fields (if institutional data blank): ');
19765: foreach my $field (@fields) {
19766: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19767: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19768: }
19769: }
1.224 raeburn 19770: if (@modifiable > 0) {
19771: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19772: } else {
1.224 raeburn 19773: $resulttext .= &mt('none');
1.43 raeburn 19774: }
1.224 raeburn 19775: $resulttext .= '</li>';
1.28 raeburn 19776: }
1.224 raeburn 19777: $resulttext .= '</ul></li>';
1.28 raeburn 19778: }
1.27 raeburn 19779: $resulttext .= '</ul>';
1.305 raeburn 19780: my $cachetime = 24*60*60;
19781: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19782: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19783: if (ref($lastactref) eq 'HASH') {
19784: $lastactref->{'domdefaults'} = 1;
19785: }
1.27 raeburn 19786: } else {
1.224 raeburn 19787: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19788: }
19789: } else {
19790: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19791: &mt('An error occurred: [_1]',$putresult).'</span>';
19792: }
1.43 raeburn 19793: if ($warningmsg ne '') {
19794: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19795: }
1.23 raeburn 19796: return $resulttext;
19797: }
19798:
1.165 raeburn 19799: sub process_captcha {
1.369 raeburn 19800: my ($container,$changes,$newsettings,$currsettings) = @_;
19801: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19802: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19803: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19804: $newsettings->{'captcha'} = 'original';
19805: }
1.369 raeburn 19806: my %current;
19807: if (ref($currsettings) eq 'HASH') {
19808: %current = %{$currsettings};
19809: }
19810: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19811: if ($container eq 'cancreate') {
1.169 raeburn 19812: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19813: push(@{$changes->{'cancreate'}},'captcha');
19814: } elsif (!defined($changes->{'cancreate'})) {
19815: $changes->{'cancreate'} = ['captcha'];
19816: }
1.368 raeburn 19817: } elsif ($container eq 'passwords') {
19818: $changes->{'reset'} = 1;
1.169 raeburn 19819: } else {
19820: $changes->{'captcha'} = 1;
1.165 raeburn 19821: }
19822: }
1.269 raeburn 19823: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19824: if ($newsettings->{'captcha'} eq 'recaptcha') {
19825: $newpub = $env{'form.'.$container.'_recaptchapub'};
19826: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19827: $newpub =~ s/[^\w\-]//g;
19828: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19829: $newsettings->{'recaptchakeys'} = {
19830: public => $newpub,
19831: private => $newpriv,
19832: };
1.269 raeburn 19833: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19834: $newversion =~ s/\D//g;
19835: if ($newversion ne '2') {
19836: $newversion = 1;
19837: }
19838: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19839: }
1.369 raeburn 19840: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19841: $currpub = $current{'recaptchakeys'}{'public'};
19842: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19843: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19844: $newsettings->{'recaptchakeys'} = {
19845: public => '',
19846: private => '',
19847: }
19848: }
1.165 raeburn 19849: }
1.369 raeburn 19850: if ($current{'captcha'} eq 'recaptcha') {
19851: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19852: if ($currversion ne '2') {
19853: $currversion = 1;
19854: }
19855: }
19856: if ($currversion ne $newversion) {
19857: if ($container eq 'cancreate') {
19858: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19859: push(@{$changes->{'cancreate'}},'recaptchaversion');
19860: } elsif (!defined($changes->{'cancreate'})) {
19861: $changes->{'cancreate'} = ['recaptchaversion'];
19862: }
1.368 raeburn 19863: } elsif ($container eq 'passwords') {
19864: $changes->{'reset'} = 1;
1.269 raeburn 19865: } else {
19866: $changes->{'recaptchaversion'} = 1;
19867: }
19868: }
1.165 raeburn 19869: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19870: if ($container eq 'cancreate') {
19871: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19872: push(@{$changes->{'cancreate'}},'recaptchakeys');
19873: } elsif (!defined($changes->{'cancreate'})) {
19874: $changes->{'cancreate'} = ['recaptchakeys'];
19875: }
1.368 raeburn 19876: } elsif ($container eq 'passwords') {
19877: $changes->{'reset'} = 1;
1.169 raeburn 19878: } else {
1.210 raeburn 19879: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19880: }
19881: }
19882: return;
19883: }
19884:
1.33 raeburn 19885: sub modify_usermodification {
19886: my ($dom,%domconfig) = @_;
1.224 raeburn 19887: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19888: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19889: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19890: if ($key eq 'selfcreate') {
19891: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19892: } else {
19893: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19894: }
1.33 raeburn 19895: }
19896: }
1.443 ! raeburn 19897: my @contexts = ('author','coauthor','course');
1.33 raeburn 19898: my %context_title = (
19899: author => 'In author context',
1.443 ! raeburn 19900: coauthor => 'As co-author manager',
1.33 raeburn 19901: course => 'In course context',
19902: );
19903: my @fields = ('lastname','firstname','middlename','generation',
19904: 'permanentemail','id');
19905: my %roles = (
19906: author => ['ca','aa'],
1.443 ! raeburn 19907: coauthor => ['ca','aa'],
1.33 raeburn 19908: course => ['st','ep','ta','in','cr'],
19909: );
19910: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19911: foreach my $context (@contexts) {
1.443 ! raeburn 19912: my $prefix = 'canmodify';
! 19913: if ($context eq 'coauthor') {
! 19914: $prefix = 'cacanmodify';
! 19915: }
1.33 raeburn 19916: foreach my $role (@{$roles{$context}}) {
1.443 ! raeburn 19917: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19918: foreach my $item (@fields) {
19919: if (grep(/^\Q$item\E$/,@modifiable)) {
19920: $modifyhash{$context}{$role}{$item} = 1;
19921: } else {
19922: $modifyhash{$context}{$role}{$item} = 0;
19923: }
19924: }
19925: }
19926: if (ref($curr_usermodification{$context}) eq 'HASH') {
19927: foreach my $role (@{$roles{$context}}) {
19928: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19929: foreach my $field (@fields) {
19930: if ($modifyhash{$context}{$role}{$field} ne
19931: $curr_usermodification{$context}{$role}{$field}) {
19932: push(@{$changes{$context}},$role);
19933: last;
19934: }
19935: }
19936: }
19937: }
19938: } else {
19939: foreach my $context (@contexts) {
19940: foreach my $role (@{$roles{$context}}) {
19941: push(@{$changes{$context}},$role);
19942: }
19943: }
19944: }
19945: }
19946: my %usermodification_hash = (
19947: usermodification => \%modifyhash,
19948: );
19949: my $putresult = &Apache::lonnet::put_dom('configuration',
19950: \%usermodification_hash,$dom);
19951: if ($putresult eq 'ok') {
19952: if (keys(%changes) > 0) {
19953: $resulttext = &mt('Changes made: ').'<ul>';
19954: foreach my $context (@contexts) {
19955: if (ref($changes{$context}) eq 'ARRAY') {
19956: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19957: if (ref($changes{$context}) eq 'ARRAY') {
19958: foreach my $role (@{$changes{$context}}) {
19959: my $rolename;
1.224 raeburn 19960: if ($role eq 'cr') {
19961: $rolename = &mt('Custom');
1.33 raeburn 19962: } else {
1.224 raeburn 19963: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19964: }
19965: my @modifiable;
1.224 raeburn 19966: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19967: foreach my $field (@fields) {
19968: if ($modifyhash{$context}{$role}{$field}) {
19969: push(@modifiable,$fieldtitles{$field});
19970: }
19971: }
19972: if (@modifiable > 0) {
19973: $resulttext .= join(', ',@modifiable);
19974: } else {
19975: $resulttext .= &mt('none');
19976: }
19977: $resulttext .= '</li>';
19978: }
19979: $resulttext .= '</ul></li>';
19980: }
19981: }
19982: }
19983: $resulttext .= '</ul>';
19984: } else {
19985: $resulttext = &mt('No changes made to user modification settings');
19986: }
19987: } else {
19988: $resulttext = '<span class="LC_error">'.
19989: &mt('An error occurred: [_1]',$putresult).'</span>';
19990: }
19991: return $resulttext;
19992: }
19993:
1.43 raeburn 19994: sub modify_defaults {
1.212 raeburn 19995: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19996: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19997: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19998: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19999: 'portal_def');
1.325 raeburn 20000: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 20001: foreach my $item (@items) {
20002: $newvalues{$item} = $env{'form.'.$item};
20003: if ($item eq 'auth_def') {
20004: if ($newvalues{$item} ne '') {
20005: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20006: push(@errors,$item);
20007: }
20008: }
20009: } elsif ($item eq 'lang_def') {
20010: if ($newvalues{$item} ne '') {
20011: if ($newvalues{$item} =~ /^(\w+)/) {
20012: my $langcode = $1;
1.103 raeburn 20013: if ($langcode ne 'x_chef') {
20014: if (code2language($langcode) eq '') {
20015: push(@errors,$item);
20016: }
1.43 raeburn 20017: }
20018: } else {
20019: push(@errors,$item);
20020: }
20021: }
1.54 raeburn 20022: } elsif ($item eq 'timezone_def') {
20023: if ($newvalues{$item} ne '') {
1.62 raeburn 20024: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20025: push(@errors,$item);
20026: }
20027: }
1.68 raeburn 20028: } elsif ($item eq 'datelocale_def') {
20029: if ($newvalues{$item} ne '') {
20030: my @datelocale_ids = DateTime::Locale->ids();
20031: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20032: push(@errors,$item);
20033: }
20034: }
1.141 raeburn 20035: } elsif ($item eq 'portal_def') {
20036: if ($newvalues{$item} ne '') {
1.414 raeburn 20037: 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])\/?$/) {
20038: foreach my $field ('email','web') {
20039: if ($env{'form.'.$item.'_'.$field}) {
20040: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20041: }
20042: }
20043: } else {
1.141 raeburn 20044: push(@errors,$item);
20045: }
20046: }
1.43 raeburn 20047: }
20048: if (grep(/^\Q$item\E$/,@errors)) {
20049: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20050: if ($item eq 'portal_def') {
20051: if ($domdefaults{$item}) {
20052: foreach my $field ('email','web') {
20053: if (exists($domdefaults{$item.'_'.$field})) {
20054: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20055: }
20056: }
20057: }
20058: }
1.43 raeburn 20059: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20060: $changes{$item} = 1;
20061: }
1.414 raeburn 20062: if ($item eq 'portal_def') {
20063: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20064: if ($newvalues{$item} eq '') {
1.414 raeburn 20065: foreach my $field ('email','web') {
20066: if (exists($domdefaults{$item.'_'.$field})) {
20067: delete($domdefaults{$item.'_'.$field});
20068: }
20069: }
20070: } else {
20071: unless ($changes{$item}) {
20072: foreach my $field ('email','web') {
20073: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20074: $changes{$item} = 1;
20075: last;
20076: }
20077: }
20078: }
20079: foreach my $field ('email','web') {
20080: if ($newvalues{$item.'_'.$field}) {
20081: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20082: } elsif (exists($domdefaults{$item.'_'.$field})) {
20083: delete($domdefaults{$item.'_'.$field});
20084: }
20085: }
20086: }
20087: }
20088: }
1.72 raeburn 20089: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20090: }
1.354 raeburn 20091: my %staticdefaults = (
20092: 'intauth_cost' => 10,
20093: 'intauth_check' => 0,
20094: 'intauth_switch' => 0,
20095: );
20096: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20097: if (exists($domdefaults{$item})) {
20098: $newvalues{$item} = $domdefaults{$item};
20099: } else {
20100: $newvalues{$item} = $staticdefaults{$item};
20101: }
20102: }
1.409 raeburn 20103: my ($unamemaprules,$ruleorder);
20104: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20105: if (@possunamemaprules) {
20106: ($unamemaprules,$ruleorder) =
20107: &Apache::lonnet::inst_userrules($dom,'unamemap');
20108: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20109: if (@{$ruleorder} > 0) {
20110: my %possrules;
20111: map { $possrules{$_} = 1; } @possunamemaprules;
20112: foreach my $rule (@{$ruleorder}) {
20113: if ($possrules{$rule}) {
20114: push(@{$newvalues{'unamemap_rule'}},$rule);
20115: }
20116: }
20117: }
20118: }
20119: }
20120: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20121: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20122: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20123: $newvalues{'unamemap_rule'});
20124: if (@rulediffs) {
20125: $changes{'unamemap_rule'} = 1;
20126: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20127: }
20128: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20129: $changes{'unamemap_rule'} = 1;
20130: delete($domdefaults{'unamemap_rule'});
20131: }
20132: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20133: if (@{$newvalues{'unamemap_rule'}} > 0) {
20134: $changes{'unamemap_rule'} = 1;
20135: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20136: }
20137: }
1.43 raeburn 20138: my %defaults_hash = (
1.72 raeburn 20139: defaults => \%newvalues,
20140: );
1.43 raeburn 20141: my $title = &defaults_titles();
1.236 raeburn 20142:
20143: my $currinststatus;
20144: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20145: $currinststatus = $domconfig{'inststatus'};
20146: } else {
20147: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20148: $currinststatus = {
20149: inststatustypes => $usertypes,
20150: inststatusorder => $types,
20151: inststatusguest => [],
20152: };
20153: }
20154: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20155: my @allpos;
20156: my %alltypes;
1.305 raeburn 20157: my @inststatusguest;
20158: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20159: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20160: unless (grep(/^\Q$type\E$/,@todelete)) {
20161: push(@inststatusguest,$type);
20162: }
20163: }
20164: }
20165: my ($currtitles,$currorder);
1.236 raeburn 20166: if (ref($currinststatus) eq 'HASH') {
20167: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20168: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20169: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20170: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20171: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20172: }
20173: }
20174: unless (grep(/^\Q$type\E$/,@todelete)) {
20175: my $position = $env{'form.inststatus_pos_'.$type};
20176: $position =~ s/\D+//g;
20177: $allpos[$position] = $type;
20178: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20179: $alltypes{$type} =~ s/`//g;
20180: }
20181: }
20182: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20183: $currtitles =~ s/,$//;
20184: }
20185: }
20186: if ($env{'form.addinststatus'}) {
20187: my $newtype = $env{'form.addinststatus'};
20188: $newtype =~ s/\W//g;
20189: unless (exists($alltypes{$newtype})) {
20190: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20191: $alltypes{$newtype} =~ s/`//g;
20192: my $position = $env{'form.addinststatus_pos'};
20193: $position =~ s/\D+//g;
20194: if ($position ne '') {
20195: $allpos[$position] = $newtype;
20196: }
20197: }
20198: }
1.305 raeburn 20199: my @orderedstatus;
1.236 raeburn 20200: foreach my $type (@allpos) {
20201: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20202: push(@orderedstatus,$type);
20203: }
20204: }
20205: foreach my $type (keys(%alltypes)) {
20206: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20207: delete($alltypes{$type});
20208: }
20209: }
20210: $defaults_hash{'inststatus'} = {
20211: inststatustypes => \%alltypes,
20212: inststatusorder => \@orderedstatus,
1.305 raeburn 20213: inststatusguest => \@inststatusguest,
1.236 raeburn 20214: };
20215: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20216: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20217: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20218: }
20219: }
20220: if ($currorder ne join(',',@orderedstatus)) {
20221: $changes{'inststatus'}{'inststatusorder'} = 1;
20222: }
20223: my $newtitles;
20224: foreach my $item (@orderedstatus) {
20225: $newtitles .= $alltypes{$item}.',';
20226: }
20227: $newtitles =~ s/,$//;
20228: if ($currtitles ne $newtitles) {
20229: $changes{'inststatus'}{'inststatustypes'} = 1;
20230: }
1.43 raeburn 20231: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20232: $dom);
20233: if ($putresult eq 'ok') {
20234: if (keys(%changes) > 0) {
20235: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20236: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20237: 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";
20238: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20239: if ($item eq 'inststatus') {
20240: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20241: if (@orderedstatus) {
1.236 raeburn 20242: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20243: foreach my $type (@orderedstatus) {
20244: $resulttext .= $alltypes{$type}.', ';
20245: }
20246: $resulttext =~ s/, $//;
20247: $resulttext .= '</li>';
1.305 raeburn 20248: } else {
1.425 raeburn 20249: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20250: }
20251: }
1.409 raeburn 20252: } elsif ($item eq 'unamemap_rule') {
20253: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20254: my @rulenames;
20255: if (ref($unamemaprules) eq 'HASH') {
20256: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20257: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20258: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20259: }
20260: }
20261: }
20262: if (@rulenames) {
20263: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20264: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20265: '</li>';
20266: } else {
20267: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20268: }
20269: } else {
20270: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20271: }
1.236 raeburn 20272: } else {
20273: my $value = $env{'form.'.$item};
20274: if ($value eq '') {
20275: $value = &mt('none');
20276: } elsif ($item eq 'auth_def') {
20277: my %authnames = &authtype_names();
20278: my %shortauth = (
20279: internal => 'int',
20280: krb4 => 'krb4',
20281: krb5 => 'krb5',
20282: localauth => 'loc',
1.325 raeburn 20283: lti => 'lti',
1.236 raeburn 20284: );
20285: $value = $authnames{$shortauth{$value}};
20286: }
20287: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20288: $mailmsgtext .= "$title->{$item} set to $value\n";
20289: if ($item eq 'portal_def') {
20290: if ($env{'form.'.$item} ne '') {
20291: foreach my $field ('email','web') {
20292: $value = $env{'form.'.$item.'_'.$field};
20293: if ($value) {
20294: $value = &mt('Yes');
20295: } else {
20296: $value = &mt('No');
20297: }
20298: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20299: }
20300: }
20301: }
1.43 raeburn 20302: }
20303: }
20304: $resulttext .= '</ul>';
20305: $mailmsgtext .= "\n";
20306: my $cachetime = 24*60*60;
1.72 raeburn 20307: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20308: if (ref($lastactref) eq 'HASH') {
20309: $lastactref->{'domdefaults'} = 1;
20310: }
1.68 raeburn 20311: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20312: my $notify = 1;
20313: if (ref($domconfig{'contacts'}) eq 'HASH') {
20314: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20315: $notify = 0;
20316: }
20317: }
20318: if ($notify) {
20319: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20320: "LON-CAPA Domain Settings Change - $dom",
20321: $mailmsgtext);
20322: }
1.54 raeburn 20323: }
1.43 raeburn 20324: } else {
1.54 raeburn 20325: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20326: }
20327: } else {
20328: $resulttext = '<span class="LC_error">'.
20329: &mt('An error occurred: [_1]',$putresult).'</span>';
20330: }
20331: if (@errors > 0) {
20332: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20333: foreach my $item (@errors) {
20334: $resulttext .= ' "'.$title->{$item}.'",';
20335: }
20336: $resulttext =~ s/,$//;
20337: }
20338: return $resulttext;
20339: }
20340:
1.46 raeburn 20341: sub modify_scantron {
1.205 raeburn 20342: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20343: my ($resulttext,%confhash,%changes,$errors);
20344: my $custom = 'custom.tab';
20345: my $default = 'default.tab';
20346: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20347: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20348: &config_check($dom,$confname,$servadm);
20349: if ($env{'form.scantronformat.filename'} ne '') {
20350: my $error;
20351: if ($configuserok eq 'ok') {
20352: if ($switchserver) {
1.130 raeburn 20353: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20354: } else {
20355: if ($author_ok eq 'ok') {
1.421 raeburn 20356: my $modified = [];
1.46 raeburn 20357: my ($result,$scantronurl) =
1.421 raeburn 20358: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20359: $confname,'scantron','','',$custom,
20360: $modified);
1.46 raeburn 20361: if ($result eq 'ok') {
20362: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20363: $changes{'scantronformat'} = 1;
1.421 raeburn 20364: &update_modify_urls($r,$modified);
1.46 raeburn 20365: } else {
20366: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20367: }
20368: } else {
20369: $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);
20370: }
20371: }
20372: } else {
20373: $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);
20374: }
20375: if ($error) {
20376: &Apache::lonnet::logthis($error);
20377: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20378: }
20379: }
1.48 raeburn 20380: if (ref($domconfig{'scantron'}) eq 'HASH') {
20381: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20382: if ($env{'form.scantronformat_del'}) {
20383: $confhash{'scantron'}{'scantronformat'} = '';
20384: $changes{'scantronformat'} = 1;
1.347 raeburn 20385: } else {
20386: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20387: }
20388: }
20389: }
1.347 raeburn 20390: my @options = ('hdr','pad','rem');
1.346 raeburn 20391: my @fields = &scantroncsv_fields();
20392: my %titles = &scantronconfig_titles();
1.347 raeburn 20393: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20394: my ($newdat,$currdat,%newcol,%currcol);
20395: if (grep(/^dat$/,@formats)) {
20396: $confhash{'scantron'}{config}{dat} = 1;
20397: $newdat = 1;
20398: } else {
20399: $newdat = 0;
20400: }
20401: if (grep(/^csv$/,@formats)) {
20402: my %bynum;
20403: foreach my $field (@fields) {
20404: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20405: my $posscol = $1;
20406: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20407: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20408: $bynum{$posscol} = $field;
20409: $newcol{$field} = $posscol;
20410: }
20411: }
20412: }
1.347 raeburn 20413: if (keys(%newcol)) {
20414: foreach my $option (@options) {
20415: if ($env{'form.scantroncsv_'.$option}) {
20416: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20417: }
20418: }
20419: }
1.346 raeburn 20420: }
20421: $currdat = 1;
20422: if (ref($domconfig{'scantron'}) eq 'HASH') {
20423: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20424: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20425: $currdat = 0;
20426: }
20427: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20428: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20429: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20430: }
1.346 raeburn 20431: }
20432: }
20433: }
20434: if ($currdat != $newdat) {
20435: $changes{'config'} = 1;
20436: } else {
20437: foreach my $field (@fields) {
20438: if ($currcol{$field} ne '') {
20439: if ($currcol{$field} ne $newcol{$field}) {
20440: $changes{'config'} = 1;
20441: last;
1.347 raeburn 20442: }
1.346 raeburn 20443: } elsif ($newcol{$field} ne '') {
20444: $changes{'config'} = 1;
20445: last;
20446: }
20447: }
20448: }
1.46 raeburn 20449: if (keys(%confhash) > 0) {
20450: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20451: $dom);
20452: if ($putresult eq 'ok') {
20453: if (keys(%changes) > 0) {
1.48 raeburn 20454: if (ref($confhash{'scantron'}) eq 'HASH') {
20455: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20456: if ($changes{'scantronformat'}) {
20457: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20458: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20459: } else {
20460: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20461: }
20462: }
1.347 raeburn 20463: if ($changes{'config'}) {
1.346 raeburn 20464: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20465: if ($confhash{'scantron'}{'config'}{'dat'}) {
20466: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20467: }
20468: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20469: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20470: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20471: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20472: foreach my $field (@fields) {
20473: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20474: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20475: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20476: }
20477: }
20478: $resulttext .= '</ul></li>';
20479: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20480: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20481: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20482: foreach my $option (@options) {
20483: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20484: $resulttext .= '<li>'.$titles{$option}.'</li>';
20485: }
20486: }
20487: $resulttext .= '</ul></li>';
20488: }
1.346 raeburn 20489: }
20490: }
20491: }
20492: }
20493: } else {
20494: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20495: }
1.46 raeburn 20496: }
1.48 raeburn 20497: $resulttext .= '</ul>';
20498: } else {
1.130 raeburn 20499: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20500: }
20501: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20502: if (ref($lastactref) eq 'HASH') {
20503: $lastactref->{'domainconfig'} = 1;
20504: }
1.46 raeburn 20505: } else {
1.346 raeburn 20506: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20507: }
20508: } else {
20509: $resulttext = '<span class="LC_error">'.
20510: &mt('An error occurred: [_1]',$putresult).'</span>';
20511: }
20512: } else {
1.130 raeburn 20513: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20514: }
20515: if ($errors) {
1.353 raeburn 20516: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20517: $errors.'</ul></p>';
1.46 raeburn 20518: }
20519: return $resulttext;
20520: }
20521:
1.48 raeburn 20522: sub modify_coursecategories {
1.239 raeburn 20523: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20524: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20525: $cathash);
1.48 raeburn 20526: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20527: my @catitems = ('unauth','auth');
20528: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20529: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20530: $cathash = $domconfig{'coursecategories'}{'cats'};
20531: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20532: $changes{'togglecats'} = 1;
20533: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20534: }
20535: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20536: $changes{'categorize'} = 1;
20537: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20538: }
1.120 raeburn 20539: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20540: $changes{'togglecatscomm'} = 1;
20541: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20542: }
20543: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20544: $changes{'categorizecomm'} = 1;
20545: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20546:
20547: }
20548: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20549: $changes{'togglecatsplace'} = 1;
20550: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20551: }
20552: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20553: $changes{'categorizeplace'} = 1;
20554: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20555: }
1.238 raeburn 20556: foreach my $item (@catitems) {
20557: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20558: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20559: $changes{$item} = 1;
20560: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20561: }
20562: }
20563: }
1.57 raeburn 20564: } else {
20565: $changes{'togglecats'} = 1;
20566: $changes{'categorize'} = 1;
1.124 raeburn 20567: $changes{'togglecatscomm'} = 1;
20568: $changes{'categorizecomm'} = 1;
1.272 raeburn 20569: $changes{'togglecatsplace'} = 1;
20570: $changes{'categorizeplace'} = 1;
1.87 raeburn 20571: $domconfig{'coursecategories'} = {
20572: togglecats => $env{'form.togglecats'},
20573: categorize => $env{'form.categorize'},
1.124 raeburn 20574: togglecatscomm => $env{'form.togglecatscomm'},
20575: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20576: togglecatsplace => $env{'form.togglecatsplace'},
20577: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20578: };
1.238 raeburn 20579: foreach my $item (@catitems) {
20580: if ($env{'form.coursecat_'.$item} ne 'std') {
20581: $changes{$item} = 1;
20582: }
20583: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20584: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20585: }
20586: }
1.57 raeburn 20587: }
20588: if (ref($cathash) eq 'HASH') {
20589: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20590: push (@deletecategory,'instcode::0');
20591: }
1.120 raeburn 20592: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20593: push(@deletecategory,'communities::0');
20594: }
1.272 raeburn 20595: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20596: push(@deletecategory,'placement::0');
20597: }
1.48 raeburn 20598: }
1.57 raeburn 20599: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20600: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20601: if (@deletecategory > 0) {
20602: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20603: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20604: foreach my $item (@deletecategory) {
1.57 raeburn 20605: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20606: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20607: $deletions{$item} = 1;
1.57 raeburn 20608: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20609: }
20610: }
20611: }
1.57 raeburn 20612: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20613: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20614: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20615: $reorderings{$item} = 1;
1.57 raeburn 20616: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20617: }
20618: if ($env{'form.addcategory_name_'.$item} ne '') {
20619: my $newcat = $env{'form.addcategory_name_'.$item};
20620: my $newdepth = $depth+1;
20621: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20622: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20623: $adds{$newitem} = 1;
20624: }
20625: if ($env{'form.subcat_'.$item} ne '') {
20626: my $newcat = $env{'form.subcat_'.$item};
20627: my $newdepth = $depth+1;
20628: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20629: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20630: $adds{$newitem} = 1;
20631: }
20632: }
20633: }
20634: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20635: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20636: my $newitem = 'instcode::0';
1.57 raeburn 20637: if ($cathash->{$newitem} eq '') {
20638: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20639: $adds{$newitem} = 1;
20640: }
20641: } else {
20642: my $newitem = 'instcode::0';
1.57 raeburn 20643: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20644: $adds{$newitem} = 1;
20645: }
20646: }
1.120 raeburn 20647: if ($env{'form.communities'} eq '1') {
20648: if (ref($cathash) eq 'HASH') {
20649: my $newitem = 'communities::0';
20650: if ($cathash->{$newitem} eq '') {
20651: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20652: $adds{$newitem} = 1;
20653: }
20654: } else {
20655: my $newitem = 'communities::0';
20656: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20657: $adds{$newitem} = 1;
20658: }
20659: }
1.272 raeburn 20660: if ($env{'form.placement'} eq '1') {
20661: if (ref($cathash) eq 'HASH') {
20662: my $newitem = 'placement::0';
20663: if ($cathash->{$newitem} eq '') {
20664: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20665: $adds{$newitem} = 1;
20666: }
20667: } else {
20668: my $newitem = 'placement::0';
20669: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20670: $adds{$newitem} = 1;
20671: }
20672: }
1.48 raeburn 20673: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20674: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20675: ($env{'form.addcategory_name'} ne 'communities') &&
20676: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20677: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20678: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20679: $adds{$newitem} = 1;
20680: }
1.48 raeburn 20681: }
1.57 raeburn 20682: my $putresult;
1.48 raeburn 20683: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20684: if (keys(%deletions) > 0) {
20685: foreach my $key (keys(%deletions)) {
20686: if ($predelallitems{$key} ne '') {
20687: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20688: }
20689: }
20690: }
20691: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20692: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20693: if (ref($chkcats[0]) eq 'ARRAY') {
20694: my $depth = 0;
20695: my $chg = 0;
20696: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20697: my $name = $chkcats[0][$i];
20698: my $item;
20699: if ($name eq '') {
20700: $chg ++;
20701: } else {
20702: $item = &escape($name).'::0';
20703: if ($chg) {
1.57 raeburn 20704: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20705: }
20706: $depth ++;
1.57 raeburn 20707: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20708: $depth --;
20709: }
20710: }
20711: }
1.57 raeburn 20712: }
20713: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20714: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20715: if ($putresult eq 'ok') {
1.57 raeburn 20716: my %title = (
1.120 raeburn 20717: togglecats => 'Show/Hide a course in catalog',
20718: categorize => 'Assign a category to a course',
20719: togglecatscomm => 'Show/Hide a community in catalog',
20720: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20721: );
20722: my %level = (
1.120 raeburn 20723: dom => 'set in Domain ("Modify Course/Community")',
20724: crs => 'set in Course ("Course Configuration")',
20725: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20726: none => 'No catalog',
20727: std => 'Standard catalog',
20728: domonly => 'Domain-only catalog',
20729: codesrch => 'Code search form',
1.57 raeburn 20730: );
1.48 raeburn 20731: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20732: if ($changes{'togglecats'}) {
20733: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20734: }
20735: if ($changes{'categorize'}) {
20736: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20737: }
1.120 raeburn 20738: if ($changes{'togglecatscomm'}) {
20739: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20740: }
20741: if ($changes{'categorizecomm'}) {
20742: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20743: }
1.238 raeburn 20744: if ($changes{'unauth'}) {
20745: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20746: }
20747: if ($changes{'auth'}) {
20748: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20749: }
1.57 raeburn 20750: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20751: my $cathash;
20752: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20753: $cathash = $domconfig{'coursecategories'}{'cats'};
20754: } else {
20755: $cathash = {};
20756: }
20757: my (@cats,@trails,%allitems);
20758: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20759: if (keys(%deletions) > 0) {
20760: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20761: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20762: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20763: }
20764: $resulttext .= '</ul></li>';
20765: }
20766: if (keys(%reorderings) > 0) {
20767: my %sort_by_trail;
20768: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20769: foreach my $key (keys(%reorderings)) {
20770: if ($allitems{$key} ne '') {
20771: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20772: }
1.48 raeburn 20773: }
1.57 raeburn 20774: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20775: $resulttext .= '<li>'.$trails[$trail].'</li>';
20776: }
20777: $resulttext .= '</ul></li>';
1.48 raeburn 20778: }
1.57 raeburn 20779: if (keys(%adds) > 0) {
20780: my %sort_by_trail;
20781: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20782: foreach my $key (keys(%adds)) {
20783: if ($allitems{$key} ne '') {
20784: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20785: }
20786: }
20787: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20788: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20789: }
1.57 raeburn 20790: $resulttext .= '</ul></li>';
1.48 raeburn 20791: }
1.364 raeburn 20792: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20793: if (ref($lastactref) eq 'HASH') {
20794: $lastactref->{'cats'} = 1;
20795: }
1.48 raeburn 20796: }
20797: $resulttext .= '</ul>';
1.239 raeburn 20798: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20799: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20800: if ($changes{'auth'}) {
20801: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20802: }
20803: if ($changes{'unauth'}) {
20804: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20805: }
20806: my $cachetime = 24*60*60;
20807: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20808: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20809: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20810: }
20811: }
1.48 raeburn 20812: } else {
20813: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20814: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20815: }
20816: } else {
1.120 raeburn 20817: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20818: }
20819: return $resulttext;
20820: }
20821:
1.69 raeburn 20822: sub modify_serverstatuses {
20823: my ($dom,%domconfig) = @_;
20824: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20825: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20826: %currserverstatus = %{$domconfig{'serverstatuses'}};
20827: }
20828: my @pages = &serverstatus_pages();
20829: foreach my $type (@pages) {
20830: $newserverstatus{$type}{'namedusers'} = '';
20831: $newserverstatus{$type}{'machines'} = '';
20832: if (defined($env{'form.'.$type.'_namedusers'})) {
20833: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20834: my @okusers;
20835: foreach my $user (@users) {
20836: my ($uname,$udom) = split(/:/,$user);
20837: if (($udom =~ /^$match_domain$/) &&
20838: (&Apache::lonnet::domain($udom)) &&
20839: ($uname =~ /^$match_username$/)) {
20840: if (!grep(/^\Q$user\E/,@okusers)) {
20841: push(@okusers,$user);
20842: }
20843: }
20844: }
20845: if (@okusers > 0) {
20846: @okusers = sort(@okusers);
20847: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20848: }
20849: }
20850: if (defined($env{'form.'.$type.'_machines'})) {
20851: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20852: my @okmachines;
20853: foreach my $ip (@machines) {
20854: my @parts = split(/\./,$ip);
20855: next if (@parts < 4);
20856: my $badip = 0;
20857: for (my $i=0; $i<4; $i++) {
20858: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20859: $badip = 1;
20860: last;
20861: }
20862: }
20863: if (!$badip) {
20864: push(@okmachines,$ip);
20865: }
20866: }
20867: @okmachines = sort(@okmachines);
20868: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20869: }
20870: }
20871: my %serverstatushash = (
20872: serverstatuses => \%newserverstatus,
20873: );
20874: foreach my $type (@pages) {
1.83 raeburn 20875: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20876: my (@current,@new);
1.83 raeburn 20877: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20878: if ($currserverstatus{$type}{$setting} ne '') {
20879: @current = split(/,/,$currserverstatus{$type}{$setting});
20880: }
20881: }
20882: if ($newserverstatus{$type}{$setting} ne '') {
20883: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20884: }
20885: if (@current > 0) {
20886: if (@new > 0) {
20887: foreach my $item (@current) {
20888: if (!grep(/^\Q$item\E$/,@new)) {
20889: $changes{$type}{$setting} = 1;
1.82 raeburn 20890: last;
20891: }
20892: }
1.84 raeburn 20893: foreach my $item (@new) {
20894: if (!grep(/^\Q$item\E$/,@current)) {
20895: $changes{$type}{$setting} = 1;
20896: last;
1.82 raeburn 20897: }
20898: }
20899: } else {
1.83 raeburn 20900: $changes{$type}{$setting} = 1;
1.69 raeburn 20901: }
1.83 raeburn 20902: } elsif (@new > 0) {
20903: $changes{$type}{$setting} = 1;
1.69 raeburn 20904: }
20905: }
20906: }
20907: if (keys(%changes) > 0) {
1.81 raeburn 20908: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20909: my $putresult = &Apache::lonnet::put_dom('configuration',
20910: \%serverstatushash,$dom);
20911: if ($putresult eq 'ok') {
20912: $resulttext .= &mt('Changes made:').'<ul>';
20913: foreach my $type (@pages) {
1.84 raeburn 20914: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20915: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20916: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20917: if ($newserverstatus{$type}{'namedusers'} eq '') {
20918: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20919: } else {
20920: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20921: }
1.84 raeburn 20922: }
20923: if ($changes{$type}{'machines'}) {
1.69 raeburn 20924: if ($newserverstatus{$type}{'machines'} eq '') {
20925: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20926: } else {
20927: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20928: }
20929:
20930: }
20931: $resulttext .= '</ul></li>';
20932: }
20933: }
20934: $resulttext .= '</ul>';
20935: } else {
20936: $resulttext = '<span class="LC_error">'.
20937: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20938:
20939: }
20940: } else {
20941: $resulttext = &mt('No changes made to access to server status pages');
20942: }
20943: return $resulttext;
20944: }
20945:
1.118 jms 20946: sub modify_helpsettings {
1.285 raeburn 20947: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20948: my ($resulttext,$errors,%changes,%helphash);
20949: my %defaultchecked = ('submitbugs' => 'on');
20950: my @offon = ('off','on');
1.118 jms 20951: my @toggles = ('submitbugs');
1.285 raeburn 20952: my %current = ('submitbugs' => '',
20953: 'adhoc' => {},
20954: );
1.118 jms 20955: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20956: %current = %{$domconfig{'helpsettings'}};
20957: }
1.285 raeburn 20958: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20959: foreach my $item (@toggles) {
20960: if ($defaultchecked{$item} eq 'on') {
20961: if ($current{$item} eq '') {
20962: if ($env{'form.'.$item} eq '0') {
20963: $changes{$item} = 1;
20964: }
20965: } elsif ($current{$item} ne $env{'form.'.$item}) {
20966: $changes{$item} = 1;
20967: }
20968: } elsif ($defaultchecked{$item} eq 'off') {
20969: if ($current{$item} eq '') {
20970: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20971: $changes{$item} = 1;
20972: }
1.282 raeburn 20973: } elsif ($current{$item} ne $env{'form.'.$item}) {
20974: $changes{$item} = 1;
20975: }
20976: }
20977: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20978: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20979: }
20980: }
1.285 raeburn 20981: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20982: my $confname = $dom.'-domainconfig';
20983: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20984: my (@allpos,%newsettings,%changedprivs,$newrole);
20985: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20986: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20987: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20988: my %lt = &Apache::lonlocal::texthash(
20989: s => 'system',
20990: d => 'domain',
20991: order => 'Display order',
20992: access => 'Role usage',
1.291 raeburn 20993: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20994: dh => 'All with domain helpdesk role',
20995: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20996: none => 'None',
20997: status => 'Determined based on institutional status',
20998: inc => 'Include all, but exclude specific personnel',
20999: exc => 'Exclude all, but include specific personnel',
21000: );
21001: for (my $num=0; $num<=$maxnum; $num++) {
21002: my ($prefix,$identifier,$rolename,%curr);
21003: if ($num == $maxnum) {
21004: next unless ($env{'form.newcusthelp'} == $maxnum);
21005: $identifier = 'custhelp'.$num;
21006: $prefix = 'helproles_'.$num;
21007: $rolename = $env{'form.custhelpname'.$num};
21008: $rolename=~s/[^A-Za-z0-9]//gs;
21009: next if ($rolename eq '');
21010: next if (exists($existing{'rolesdef_'.$rolename}));
21011: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21012: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21013: $newprivs{'c'},$confname,$dom);
21014: if ($result ne 'ok') {
21015: $errors .= '<li><span class="LC_error">'.
21016: &mt('An error occurred storing the new custom role: [_1]',
21017: $result).'</span></li>';
21018: next;
21019: } else {
21020: $changedprivs{$rolename} = \%newprivs;
21021: $newrole = $rolename;
21022: }
21023: } else {
21024: $prefix = 'helproles_'.$num;
21025: $rolename = $env{'form.'.$prefix};
21026: next if ($rolename eq '');
21027: next unless (exists($existing{'rolesdef_'.$rolename}));
21028: $identifier = 'custhelp'.$num;
21029: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21030: my %currprivs;
1.289 raeburn 21031: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21032: split(/\_/,$existing{'rolesdef_'.$rolename});
21033: foreach my $level ('c','d','s') {
21034: if ($newprivs{$level} ne $currprivs{$level}) {
21035: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21036: $newprivs{'c'},$confname,$dom);
21037: if ($result ne 'ok') {
21038: $errors .= '<li><span class="LC_error">'.
21039: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21040: $rolename,$result).'</span></li>';
21041: } else {
21042: $changedprivs{$rolename} = \%newprivs;
21043: }
21044: last;
21045: }
21046: }
21047: if (ref($current{'adhoc'}) eq 'HASH') {
21048: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21049: %curr = %{$current{'adhoc'}{$rolename}};
21050: }
21051: }
21052: }
21053: my $newpos = $env{'form.'.$prefix.'_pos'};
21054: $newpos =~ s/\D+//g;
21055: $allpos[$newpos] = $rolename;
21056: my $newdesc = $env{'form.'.$prefix.'_desc'};
21057: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21058: if ($curr{'desc'}) {
21059: if ($curr{'desc'} ne $newdesc) {
21060: $changes{'customrole'}{$rolename}{'desc'} = 1;
21061: $newsettings{$rolename}{'desc'} = $newdesc;
21062: }
21063: } elsif ($newdesc ne '') {
21064: $changes{'customrole'}{$rolename}{'desc'} = 1;
21065: $newsettings{$rolename}{'desc'} = $newdesc;
21066: }
21067: my $access = $env{'form.'.$prefix.'_access'};
21068: if (grep(/^\Q$access\E$/,@accesstypes)) {
21069: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21070: if ($access eq 'status') {
21071: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21072: if (scalar(@statuses) == 0) {
1.289 raeburn 21073: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21074: } else {
21075: my (@shownstatus,$numtypes);
21076: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21077: if (ref($types) eq 'ARRAY') {
21078: $numtypes = scalar(@{$types});
21079: foreach my $type (sort(@statuses)) {
21080: if ($type eq 'default') {
21081: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21082: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21083: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21084: push(@shownstatus,$usertypes->{$type});
21085: }
21086: }
21087: }
21088: if (grep(/^default$/,@statuses)) {
21089: push(@shownstatus,$othertitle);
21090: }
21091: if (scalar(@shownstatus) == 1+$numtypes) {
21092: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21093: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21094: } else {
21095: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21096: if (ref($curr{'status'}) eq 'ARRAY') {
21097: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21098: if (@diffs) {
21099: $changes{'customrole'}{$rolename}{$access} = 1;
21100: }
21101: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21102: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21103: }
1.166 raeburn 21104: }
21105: }
1.285 raeburn 21106: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21107: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21108: my @newspecstaff;
21109: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21110: foreach my $person (sort(@personnel)) {
21111: if ($domhelpdesk{$person}) {
21112: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21113: }
21114: }
21115: if (ref($curr{$access}) eq 'ARRAY') {
21116: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21117: if (@diffs) {
21118: $changes{'customrole'}{$rolename}{$access} = 1;
21119: }
21120: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21121: $changes{'customrole'}{$rolename}{$access} = 1;
21122: }
21123: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21124: my ($uname,$udom) = split(/:/,$person);
21125: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21126: }
21127: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21128: }
1.285 raeburn 21129: } else {
21130: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21131: }
21132: unless ($curr{'access'} eq $access) {
21133: $changes{'customrole'}{$rolename}{'access'} = 1;
21134: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21135: }
21136: }
1.285 raeburn 21137: if (@allpos > 0) {
21138: my $idx = 0;
21139: foreach my $rolename (@allpos) {
21140: if ($rolename ne '') {
21141: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21142: if (ref($current{'adhoc'}) eq 'HASH') {
21143: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21144: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21145: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21146: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21147: }
21148: }
1.282 raeburn 21149: }
1.285 raeburn 21150: $idx ++;
1.166 raeburn 21151: }
21152: }
1.118 jms 21153: }
1.123 jms 21154: my $putresult;
21155: if (keys(%changes) > 0) {
1.166 raeburn 21156: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21157: if ($putresult eq 'ok') {
1.285 raeburn 21158: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21159: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21160: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21161: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21162: }
21163: }
21164: my $cachetime = 24*60*60;
21165: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21166: if (ref($lastactref) eq 'HASH') {
21167: $lastactref->{'domdefaults'} = 1;
21168: }
21169: } else {
21170: $errors .= '<li><span class="LC_error">'.
21171: &mt('An error occurred storing the settings: [_1]',
21172: $putresult).'</span></li>';
21173: }
21174: }
21175: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21176: $resulttext = &mt('Changes made:').'<ul>';
21177: my (%shownprivs,@levelorder);
21178: @levelorder = ('c','d','s');
21179: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21180: foreach my $item (sort(keys(%changes))) {
21181: if ($item eq 'submitbugs') {
21182: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21183: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21184: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21185: } elsif ($item eq 'customrole') {
21186: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21187: my @keyorder = ('order','desc','access','status','exc','inc');
21188: my %keytext = &Apache::lonlocal::texthash(
21189: order => 'Order',
21190: desc => 'Role description',
21191: access => 'Role usage',
1.300 droeschl 21192: status => 'Allowed institutional types',
1.285 raeburn 21193: exc => 'Allowed personnel',
21194: inc => 'Disallowed personnel',
21195: );
1.282 raeburn 21196: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21197: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21198: if ($role eq $newrole) {
21199: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21200: $role).'<ul>';
21201: } else {
21202: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21203: $role).'<ul>';
21204: }
21205: foreach my $key (@keyorder) {
21206: if ($changes{'customrole'}{$role}{$key}) {
21207: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21208: $keytext{$key},$newsettings{$role}{$key}).
21209: '</li>';
21210: }
21211: }
21212: if (ref($changedprivs{$role}) eq 'HASH') {
21213: $shownprivs{$role} = 1;
21214: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21215: foreach my $level (@levelorder) {
21216: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21217: next if ($item eq '');
21218: my ($priv) = split(/\&/,$item,2);
21219: if (&Apache::lonnet::plaintext($priv)) {
21220: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21221: unless ($level eq 'c') {
21222: $resulttext .= ' ('.$lt{$level}.')';
21223: }
21224: $resulttext .= '</li>';
21225: }
21226: }
21227: }
21228: $resulttext .= '</ul>';
21229: }
21230: $resulttext .= '</ul></li>';
21231: }
21232: }
21233: }
21234: }
21235: }
21236: }
21237: if (keys(%changedprivs)) {
21238: foreach my $role (sort(keys(%changedprivs))) {
21239: unless ($shownprivs{$role}) {
21240: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21241: $role).'<ul>'.
21242: '<li>'.&mt('Privileges set to :').'<ul>';
21243: foreach my $level (@levelorder) {
21244: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21245: next if ($item eq '');
21246: my ($priv) = split(/\&/,$item,2);
21247: if (&Apache::lonnet::plaintext($priv)) {
21248: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21249: unless ($level eq 'c') {
21250: $resulttext .= ' ('.$lt{$level}.')';
21251: }
21252: $resulttext .= '</li>';
21253: }
1.282 raeburn 21254: }
21255: }
1.285 raeburn 21256: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21257: }
21258: }
21259: }
1.285 raeburn 21260: $resulttext .= '</ul>';
21261: } else {
21262: $resulttext = &mt('No changes made to help settings');
1.118 jms 21263: }
21264: if ($errors) {
1.168 raeburn 21265: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21266: $errors.'</ul>';
1.118 jms 21267: }
21268: return $resulttext;
21269: }
21270:
1.121 raeburn 21271: sub modify_coursedefaults {
1.212 raeburn 21272: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21273: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21274: my %defaultchecked = (
21275: 'canuse_pdfforms' => 'off',
21276: 'uselcmath' => 'on',
1.398 raeburn 21277: 'usejsme' => 'on',
21278: 'inline_chem' => 'on',
1.404 raeburn 21279: 'ltiauth' => 'off',
1.257 raeburn 21280: );
1.404 raeburn 21281: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21282: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21283: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21284: 'coursequota_official','coursequota_unofficial','coursequota_community',
21285: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21286: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21287: 'mysqltables_placement');
1.271 raeburn 21288: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21289: my %staticdefaults = (
21290: anonsurvey_threshold => 10,
21291: uploadquota => 500,
1.428 raeburn 21292: coursequota => 20,
1.257 raeburn 21293: postsubmit => 60,
1.276 raeburn 21294: mysqltables => 172800,
1.422 raeburn 21295: domexttool => 1,
1.432 raeburn 21296: crsauthor => 1,
1.438 raeburn 21297: crseditors => ['edit','xml'],
1.198 raeburn 21298: );
1.314 raeburn 21299: my %texoptions = (
21300: MathJax => 'MathJax',
21301: mimetex => &mt('Convert to Images'),
21302: tth => &mt('TeX to HTML'),
21303: );
1.438 raeburn 21304:
21305: my @editors = ('edit','xml','daxe');
21306: my %editornames = &crseditor_titles();
21307:
1.121 raeburn 21308: $defaultshash{'coursedefaults'} = {};
21309:
21310: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21311: if ($domconfig{'coursedefaults'} eq '') {
21312: $domconfig{'coursedefaults'} = {};
21313: }
21314: }
21315:
21316: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21317: foreach my $item (@toggles) {
21318: if ($defaultchecked{$item} eq 'on') {
21319: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21320: ($env{'form.'.$item} eq '0')) {
21321: $changes{$item} = 1;
1.192 raeburn 21322: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21323: $changes{$item} = 1;
21324: }
21325: } elsif ($defaultchecked{$item} eq 'off') {
21326: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21327: ($env{'form.'.$item} eq '1')) {
21328: $changes{$item} = 1;
21329: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21330: $changes{$item} = 1;
21331: }
21332: }
21333: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21334: }
1.198 raeburn 21335: foreach my $item (@numbers) {
21336: my ($currdef,$newdef);
1.208 raeburn 21337: $newdef = $env{'form.'.$item};
1.198 raeburn 21338: if ($item eq 'anonsurvey_threshold') {
21339: $currdef = $domconfig{'coursedefaults'}{$item};
21340: $newdef =~ s/\D//g;
21341: if ($newdef eq '' || $newdef < 1) {
21342: $newdef = 1;
21343: }
21344: $defaultshash{'coursedefaults'}{$item} = $newdef;
21345: } else {
1.428 raeburn 21346: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21347: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21348: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21349: }
21350: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21351: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21352: }
21353: if ($currdef ne $newdef) {
21354: if ($item eq 'anonsurvey_threshold') {
21355: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21356: $changes{$item} = 1;
21357: }
1.428 raeburn 21358: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21359: my $setting = $1;
1.276 raeburn 21360: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21361: $changes{$setting} = 1;
1.198 raeburn 21362: }
21363: }
1.139 raeburn 21364: }
21365: }
1.314 raeburn 21366: my $texengine;
21367: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21368: $texengine = $env{'form.texengine'};
1.349 raeburn 21369: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21370: if ($currdef eq '') {
21371: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21372: $changes{'texengine'} = 1;
21373: }
1.349 raeburn 21374: } elsif ($currdef ne $texengine) {
1.314 raeburn 21375: $changes{'texengine'} = 1;
21376: }
21377: }
21378: if ($texengine ne '') {
21379: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21380: }
1.264 raeburn 21381: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21382: my @currclonecode;
21383: if (ref($currclone) eq 'HASH') {
21384: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21385: @currclonecode = @{$currclone->{'instcode'}};
21386: }
21387: }
21388: my $newclone;
1.289 raeburn 21389: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21390: $newclone = $env{'form.canclone'};
21391: }
21392: if ($newclone eq 'instcode') {
21393: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21394: my (%codedefaults,@code_order,@clonecode);
21395: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21396: \@code_order);
21397: foreach my $item (@code_order) {
21398: if (grep(/^\Q$item\E$/,@newcodes)) {
21399: push(@clonecode,$item);
21400: }
21401: }
21402: if (@clonecode) {
21403: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21404: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21405: if (@diffs) {
21406: $changes{'canclone'} = 1;
21407: }
21408: } else {
21409: $newclone eq '';
21410: }
21411: } elsif ($newclone ne '') {
1.289 raeburn 21412: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21413: }
1.264 raeburn 21414: if ($newclone ne $currclone) {
21415: $changes{'canclone'} = 1;
21416: }
1.257 raeburn 21417: my %credits;
21418: foreach my $type (@types) {
21419: unless ($type eq 'community') {
21420: $credits{$type} = $env{'form.'.$type.'_credits'};
21421: $credits{$type} =~ s/[^\d.]+//g;
21422: }
21423: }
21424: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21425: ($env{'form.coursecredits'} eq '1')) {
21426: $changes{'coursecredits'} = 1;
21427: foreach my $type (keys(%credits)) {
21428: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21429: }
21430: } else {
1.289 raeburn 21431: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21432: foreach my $type (@types) {
21433: unless ($type eq 'community') {
1.289 raeburn 21434: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21435: $changes{'coursecredits'} = 1;
21436: }
21437: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21438: }
21439: }
21440: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21441: foreach my $type (@types) {
21442: unless ($type eq 'community') {
21443: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21444: $changes{'coursecredits'} = 1;
21445: last;
21446: }
21447: }
21448: }
21449: }
21450: }
21451: if ($env{'form.postsubmit'} eq '1') {
21452: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21453: my %currtimeout;
21454: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21455: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21456: $changes{'postsubmit'} = 1;
21457: }
21458: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21459: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21460: }
21461: } else {
21462: $changes{'postsubmit'} = 1;
21463: }
21464: foreach my $type (@types) {
21465: my $timeout = $env{'form.'.$type.'_timeout'};
21466: $timeout =~ s/\D//g;
21467: if ($timeout == $staticdefaults{'postsubmit'}) {
21468: $timeout = '';
21469: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21470: $timeout = '0';
21471: }
21472: unless ($timeout eq '') {
21473: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21474: }
21475: if (exists($currtimeout{$type})) {
21476: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21477: $changes{'postsubmit'} = 1;
1.257 raeburn 21478: }
21479: } elsif ($timeout ne '') {
21480: $changes{'postsubmit'} = 1;
21481: }
21482: }
21483: } else {
21484: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21485: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21486: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21487: $changes{'postsubmit'} = 1;
21488: }
21489: } else {
21490: $changes{'postsubmit'} = 1;
21491: }
1.192 raeburn 21492: }
1.438 raeburn 21493: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21494: %posscrseditors);
1.422 raeburn 21495: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21496: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21497: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21498: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21499: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21500: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21501: } else {
21502: foreach my $type (@types) {
21503: if ($staticdefaults{'domexttool'}) {
21504: $olddomexttool{$type} = 1;
21505: } else {
21506: $olddomexttool{$type} = 0;
21507: }
21508: }
21509: }
21510: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21511: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21512: } else {
21513: foreach my $type (@types) {
21514: if ($staticdefaults{'exttool'}) {
21515: $oldexttool{$type} = 1;
21516: } else {
21517: $oldexttool{$type} = 0;
21518: }
21519: }
21520: }
1.432 raeburn 21521: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21522: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21523: } else {
21524: foreach my $type (@types) {
21525: if ($staticdefaults{'crsauthor'}) {
21526: $oldcrsauthor{$type} = 1;
21527: } else {
21528: $oldcrsauthor{$type} = 0;
21529: }
21530: }
21531: }
1.438 raeburn 21532: my @newcrseditors = ();
21533: foreach my $editor (@editors) {
21534: if ($posscrseditors{$editor}) {
21535: push(@newcrseditors,$editor);
21536: }
21537: }
21538: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21539: my @diffs =
21540: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21541: \@newcrseditors);
21542: if (@diffs) {
21543: $changes{'crseditors'} = 1;
21544: }
21545: } else {
21546: my @diffs =
21547: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21548: \@newcrseditors);
21549: unless (@diffs == 0) {
21550: $changes{'crseditors'} = 1;
21551: }
21552: }
1.422 raeburn 21553: foreach my $type (@types) {
21554: unless ($newdomexttool{$type}) {
21555: $newdomexttool{$type} = 0;
21556: }
21557: unless ($newexttool{$type}) {
21558: $newexttool{$type} = 0;
21559: }
1.432 raeburn 21560: unless ($newcrsauthor{$type}) {
21561: $newcrsauthor{$type} = 0;
21562: }
1.422 raeburn 21563: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21564: $changes{'domexttool'} = 1;
21565: }
21566: if ($newexttool{$type} != $oldexttool{$type}) {
21567: $changes{'exttool'} = 1;
21568: }
1.432 raeburn 21569: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21570: $changes{'crsauthor'} = 1;
21571: }
1.422 raeburn 21572: }
21573: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21574: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21575: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21576: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21577: }
21578: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21579: $dom);
21580: if ($putresult eq 'ok') {
21581: if (keys(%changes) > 0) {
1.213 raeburn 21582: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21583: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21584: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21585: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21586: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21587: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21588: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21589: 'ltiauth') {
1.257 raeburn 21590: if ($changes{$item}) {
21591: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21592: }
1.289 raeburn 21593: }
1.192 raeburn 21594: if ($changes{'coursecredits'}) {
21595: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21596: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21597: $domdefaults{$type.'credits'} =
21598: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21599: }
21600: }
21601: }
21602: if ($changes{'postsubmit'}) {
21603: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21604: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21605: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21606: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21607: $domdefaults{$type.'postsubtimeout'} =
21608: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21609: }
21610: }
1.192 raeburn 21611: }
21612: }
1.198 raeburn 21613: if ($changes{'uploadquota'}) {
21614: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21615: foreach my $type (@types) {
21616: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21617: }
21618: }
21619: }
1.428 raeburn 21620: if ($changes{'coursequota'}) {
21621: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21622: foreach my $type (@types) {
21623: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21624: }
21625: }
21626: }
1.264 raeburn 21627: if ($changes{'canclone'}) {
21628: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21629: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21630: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21631: if (@clonecodes) {
21632: $domdefaults{'canclone'} = join('+',@clonecodes);
21633: }
21634: }
21635: } else {
21636: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21637: }
21638: }
1.422 raeburn 21639: if ($changes{'domexttool'}) {
21640: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21641: foreach my $type (@types) {
21642: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21643: }
21644: }
21645: }
21646: if ($changes{'exttool'}) {
21647: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21648: foreach my $type (@types) {
21649: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21650: }
21651: }
21652: }
1.432 raeburn 21653: if ($changes{'crsauthor'}) {
21654: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21655: foreach my $type (@types) {
21656: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21657: }
21658: }
21659: }
1.438 raeburn 21660: if ($changes{'crseditors'}) {
21661: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21662: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21663: }
21664: }
1.121 raeburn 21665: my $cachetime = 24*60*60;
21666: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21667: if (ref($lastactref) eq 'HASH') {
21668: $lastactref->{'domdefaults'} = 1;
21669: }
1.121 raeburn 21670: }
21671: $resulttext = &mt('Changes made:').'<ul>';
21672: foreach my $item (sort(keys(%changes))) {
21673: if ($item eq 'canuse_pdfforms') {
21674: if ($env{'form.'.$item} eq '1') {
21675: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21676: } else {
21677: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21678: }
1.257 raeburn 21679: } elsif ($item eq 'uselcmath') {
21680: if ($env{'form.'.$item} eq '1') {
21681: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21682: } else {
21683: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21684: }
21685: } elsif ($item eq 'usejsme') {
21686: if ($env{'form.'.$item} eq '1') {
21687: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21688: } else {
1.289 raeburn 21689: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21690: }
1.398 raeburn 21691: } elsif ($item eq 'inline_chem') {
21692: if ($env{'form.'.$item} eq '1') {
21693: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21694: } else {
21695: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21696: }
1.314 raeburn 21697: } elsif ($item eq 'texengine') {
21698: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21699: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21700: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21701: }
1.139 raeburn 21702: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21703: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21704: } elsif ($item eq 'uploadquota') {
21705: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21706: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21707: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21708: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21709: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21710: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21711: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21712: '</ul>'.
21713: '</li>';
21714: } else {
21715: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21716: }
1.428 raeburn 21717: } elsif ($item eq 'coursequota') {
21718: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21719: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21720: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21721: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21722: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21723: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21724: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21725: '</ul>'.
21726: '</li>';
21727: } else {
21728: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21729: }
1.276 raeburn 21730: } elsif ($item eq 'mysqltables') {
21731: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21732: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21733: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21734: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21735: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21736: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21737: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21738: '</ul>'.
21739: '</li>';
21740: } else {
21741: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21742: }
1.257 raeburn 21743: } elsif ($item eq 'postsubmit') {
21744: if ($domdefaults{'postsubmit'} eq 'off') {
21745: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21746: } else {
21747: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21748: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21749: $resulttext .= &mt('durations:').'<ul>';
21750: foreach my $type (@types) {
21751: $resulttext .= '<li>';
21752: my $timeout;
21753: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21754: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21755: }
21756: my $display;
21757: if ($timeout eq '0') {
21758: $display = &mt('unlimited');
21759: } elsif ($timeout eq '') {
21760: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21761: } else {
21762: $display = &mt('[quant,_1,second]',$timeout);
21763: }
21764: if ($type eq 'community') {
21765: $resulttext .= &mt('Communities');
21766: } elsif ($type eq 'official') {
21767: $resulttext .= &mt('Official courses');
21768: } elsif ($type eq 'unofficial') {
21769: $resulttext .= &mt('Unofficial courses');
21770: } elsif ($type eq 'textbook') {
21771: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21772: } elsif ($type eq 'placement') {
21773: $resulttext .= &mt('Placement tests');
1.257 raeburn 21774: }
21775: $resulttext .= ' -- '.$display.'</li>';
21776: }
21777: $resulttext .= '</ul>';
21778: }
1.289 raeburn 21779: $resulttext .= '</li>';
1.257 raeburn 21780: }
1.192 raeburn 21781: } elsif ($item eq 'coursecredits') {
21782: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21783: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21784: ($domdefaults{'unofficialcredits'} eq '') &&
21785: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21786: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21787: } else {
21788: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21789: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21790: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21791: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21792: '</ul>'.
21793: '</li>';
21794: }
21795: } else {
21796: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21797: }
1.264 raeburn 21798: } elsif ($item eq 'canclone') {
21799: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21800: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21801: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21802: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21803: }
21804: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21805: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21806: } else {
1.289 raeburn 21807: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21808: }
1.404 raeburn 21809: } elsif ($item eq 'ltiauth') {
21810: if ($env{'form.'.$item} eq '1') {
21811: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21812: } else {
21813: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21814: }
1.432 raeburn 21815: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21816: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21817: my %status = (
21818: domexttool => {
21819: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21820: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21821: },
21822: exttool => {
21823: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21824: default => &mt('External Tools can not be defined in any course types, by default'),
21825: },
21826: crsauthor => {
21827: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21828: default => &mt('Standard Problems can be created within any course type, by default'),
21829: },
21830: );
21831:
21832: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21833: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21834: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21835: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21836: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21837: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21838: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21839: '</ul>'.
21840: '</li>';
21841: } else {
1.432 raeburn 21842: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21843: }
1.438 raeburn 21844: } elsif ($item eq 'crseditors') {
21845: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21846: my $shown;
21847: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21848: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21849: } else {
21850: $shown = &mt('None');
21851: }
21852: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21853: }
1.140 raeburn 21854: }
1.121 raeburn 21855: }
21856: $resulttext .= '</ul>';
21857: } else {
21858: $resulttext = &mt('No changes made to course defaults');
21859: }
21860: } else {
21861: $resulttext = '<span class="LC_error">'.
21862: &mt('An error occurred: [_1]',$putresult).'</span>';
21863: }
21864: return $resulttext;
21865: }
21866:
1.231 raeburn 21867: sub modify_selfenrollment {
21868: my ($dom,$lastactref,%domconfig) = @_;
21869: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21870: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21871: my %titles = &tool_titles();
1.232 raeburn 21872: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21873: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21874: $ordered{'default'} = ['types','registered','approval','limit'];
21875:
21876: my (%roles,%shown,%toplevel);
21877: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21878:
21879: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21880: if ($domconfig{'selfenrollment'} eq '') {
21881: $domconfig{'selfenrollment'} = {};
21882: }
21883: }
21884: %toplevel = (
21885: admin => 'Configuration Rights',
21886: default => 'Default settings',
21887: validation => 'Validation of self-enrollment requests',
21888: );
1.233 raeburn 21889: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21890:
21891: if (ref($ordered{'admin'}) eq 'ARRAY') {
21892: foreach my $item (@{$ordered{'admin'}}) {
21893: foreach my $type (@types) {
21894: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21895: $selfenrollhash{'admin'}{$type}{$item} = 1;
21896: } else {
21897: $selfenrollhash{'admin'}{$type}{$item} = 0;
21898: }
21899: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21900: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21901: if ($selfenrollhash{'admin'}{$type}{$item} ne
21902: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21903: push(@{$changes{'admin'}{$type}},$item);
21904: }
21905: } else {
21906: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21907: push(@{$changes{'admin'}{$type}},$item);
21908: }
21909: }
21910: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21911: push(@{$changes{'admin'}{$type}},$item);
21912: }
21913: }
21914: }
21915: }
21916:
21917: foreach my $item (@{$ordered{'default'}}) {
21918: foreach my $type (@types) {
21919: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21920: if ($item eq 'types') {
21921: unless (($value eq 'all') || ($value eq 'dom')) {
21922: $value = '';
21923: }
21924: } elsif ($item eq 'registered') {
21925: unless ($value eq '1') {
21926: $value = 0;
21927: }
21928: } elsif ($item eq 'approval') {
21929: unless ($value =~ /^[012]$/) {
21930: $value = 0;
21931: }
21932: } else {
21933: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21934: $value = 'none';
21935: }
21936: }
21937: $selfenrollhash{'default'}{$type}{$item} = $value;
21938: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21939: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21940: if ($selfenrollhash{'default'}{$type}{$item} ne
21941: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21942: push(@{$changes{'default'}{$type}},$item);
21943: }
21944: } else {
21945: push(@{$changes{'default'}{$type}},$item);
21946: }
21947: } else {
21948: push(@{$changes{'default'}{$type}},$item);
21949: }
21950: if ($item eq 'limit') {
21951: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21952: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21953: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21954: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21955: }
21956: } else {
21957: $selfenrollhash{'default'}{$type}{'cap'} = '';
21958: }
21959: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21960: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21961: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21962: push(@{$changes{'default'}{$type}},'cap');
21963: }
21964: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21965: push(@{$changes{'default'}{$type}},'cap');
21966: }
21967: }
21968: }
21969: }
21970:
21971: foreach my $item (@{$itemsref}) {
21972: if ($item eq 'fields') {
21973: my @changed;
21974: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21975: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21976: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21977: }
21978: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21979: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21980: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21981: $domconfig{'selfenrollment'}{'validation'}{$item});
21982: } else {
21983: @changed = @{$selfenrollhash{'validation'}{$item}};
21984: }
21985: } else {
21986: @changed = @{$selfenrollhash{'validation'}{$item}};
21987: }
21988: if (@changed) {
21989: if ($selfenrollhash{'validation'}{$item}) {
21990: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21991: } else {
21992: $changes{'validation'}{$item} = &mt('None');
21993: }
21994: }
21995: } else {
21996: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21997: if ($item eq 'markup') {
21998: if ($env{'form.selfenroll_validation_'.$item}) {
21999: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
22000: }
22001: }
22002: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
22003: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
22004: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
22005: }
22006: }
22007: }
22008: }
22009:
22010: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
22011: $dom);
22012: if ($putresult eq 'ok') {
22013: if (keys(%changes) > 0) {
22014: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22015: $resulttext = &mt('Changes made:').'<ul>';
22016: foreach my $key ('admin','default','validation') {
22017: if (ref($changes{$key}) eq 'HASH') {
22018: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22019: if ($key eq 'validation') {
22020: foreach my $item (@{$itemsref}) {
22021: if (exists($changes{$key}{$item})) {
22022: if ($item eq 'markup') {
22023: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22024: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22025: } else {
22026: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22027: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22028: }
22029: }
22030: }
22031: } else {
22032: foreach my $type (@types) {
22033: if ($type eq 'community') {
22034: $roles{'1'} = &mt('Community personnel');
22035: } else {
22036: $roles{'1'} = &mt('Course personnel');
22037: }
22038: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22039: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22040: if ($key eq 'admin') {
22041: my @mgrdc = ();
22042: if (ref($ordered{$key}) eq 'ARRAY') {
22043: foreach my $item (@{$ordered{'admin'}}) {
22044: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22045: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22046: push(@mgrdc,$item);
22047: }
22048: }
22049: }
22050: if (@mgrdc) {
22051: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22052: } else {
22053: delete($domdefaults{$type.'selfenrolladmdc'});
22054: }
22055: }
22056: } else {
22057: if (ref($ordered{$key}) eq 'ARRAY') {
22058: foreach my $item (@{$ordered{$key}}) {
22059: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22060: $domdefaults{$type.'selfenroll'.$item} =
22061: $selfenrollhash{$key}{$type}{$item};
22062: }
22063: }
22064: }
22065: }
22066: }
1.231 raeburn 22067: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22068: foreach my $item (@{$ordered{$key}}) {
22069: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22070: $resulttext .= '<li>';
22071: if ($key eq 'admin') {
22072: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22073: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22074: } else {
22075: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22076: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22077: }
22078: $resulttext .= '</li>';
22079: }
22080: }
22081: $resulttext .= '</ul></li>';
22082: }
22083: }
22084: $resulttext .= '</ul></li>';
22085: }
22086: }
1.305 raeburn 22087: }
22088: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22089: my $cachetime = 24*60*60;
22090: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22091: if (ref($lastactref) eq 'HASH') {
22092: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22093: }
1.231 raeburn 22094: }
22095: $resulttext .= '</ul>';
22096: } else {
22097: $resulttext = &mt('No changes made to self-enrollment settings');
22098: }
22099: } else {
22100: $resulttext = '<span class="LC_error">'.
22101: &mt('An error occurred: [_1]',$putresult).'</span>';
22102: }
22103: return $resulttext;
22104: }
22105:
1.373 raeburn 22106: sub modify_wafproxy {
22107: my ($dom,$action,$lastactref,%domconfig) = @_;
22108: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22109: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22110: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22111: foreach my $server (sort(keys(%servers))) {
22112: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22113: if ($serverhome eq $server) {
22114: my $serverdom = &Apache::lonnet::host_domain($server);
22115: if ($serverdom eq $dom) {
22116: $canset{$server} = 1;
22117: }
22118: }
22119: }
1.381 raeburn 22120: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22121: %{$values{$dom}} = ();
22122: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22123: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22124: }
1.388 raeburn 22125: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22126: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22127: }
1.382 raeburn 22128: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22129: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22130: }
22131: }
1.373 raeburn 22132: my $output;
22133: if (keys(%canset)) {
22134: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22135: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22136: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22137: if ($env{'form.wafproxy_'.$dom}) {
22138: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22139: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22140: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22141: $changes{'alias'} = 1;
22142: }
1.388 raeburn 22143: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22144: $wafproxy{'saml'}{$key} = 1;
22145: }
22146: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22147: $changes{'saml'} = 1;
22148: }
1.381 raeburn 22149: } else {
22150: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22151: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22152: if ($curralias{$key}) {
22153: $changes{'alias'} = 1;
22154: }
1.388 raeburn 22155: if ($currsaml{$key}) {
22156: $changes{'saml'} = 1;
22157: }
1.373 raeburn 22158: }
22159: if ($wafproxy{'alias'}{$key} eq '') {
22160: if ($curralias{$key}) {
22161: $expirecache{$key} = 1;
22162: }
22163: delete($wafproxy{'alias'}{$key});
22164: }
1.388 raeburn 22165: if ($wafproxy{'saml'}{$key} eq '') {
22166: if ($currsaml{$key}) {
22167: $expiresaml{$key} = 1;
22168: }
22169: delete($wafproxy{'saml'}{$key});
22170: }
1.373 raeburn 22171: }
22172: unless (keys(%{$wafproxy{'alias'}})) {
22173: delete($wafproxy{'alias'});
22174: }
1.388 raeburn 22175: unless (keys(%{$wafproxy{'saml'}})) {
22176: delete($wafproxy{'saml'});
22177: }
22178: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22179: my %warn = (
22180: trusted => 'trusted IP range(s)',
1.381 raeburn 22181: vpnint => 'internal IP range(s) for VPN sessions(s)',
22182: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22183: );
1.382 raeburn 22184: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22185: my $possible = $env{'form.wafproxy_'.$item};
22186: $possible =~ s/^\s+|\s+$//g;
22187: if ($possible ne '') {
1.381 raeburn 22188: if ($item eq 'remoteip') {
22189: if ($possible =~ /^[mhn]$/) {
22190: $wafproxy{$item} = $possible;
22191: }
22192: } elsif ($item eq 'ipheader') {
22193: if ($wafproxy{'remoteip'} eq 'h') {
22194: $wafproxy{$item} = $possible;
22195: }
1.382 raeburn 22196: } elsif ($item eq 'sslopt') {
22197: if ($possible =~ /^0|1$/) {
22198: $wafproxy{$item} = $possible;
22199: }
1.373 raeburn 22200: } else {
22201: my (@ok,$count);
1.381 raeburn 22202: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22203: unless ($env{'form.wafproxy_vpnaccess'}) {
22204: $possible = '';
22205: }
22206: } elsif ($item eq 'trusted') {
22207: unless ($wafproxy{'remoteip'} eq 'h') {
22208: $possible = '';
22209: }
22210: }
22211: unless ($possible eq '') {
22212: $possible =~ s/[\r\n]+/\s/g;
22213: $possible =~ s/\s*-\s*/-/g;
22214: $possible =~ s/\s+/,/g;
1.393 raeburn 22215: $possible =~ s/,+/,/g;
1.381 raeburn 22216: }
1.373 raeburn 22217: $count = 0;
1.381 raeburn 22218: if ($possible ne '') {
1.373 raeburn 22219: foreach my $poss (split(/\,/,$possible)) {
22220: $count ++;
1.393 raeburn 22221: $poss = &validate_ip_pattern($poss);
22222: if ($poss ne '') {
1.373 raeburn 22223: push(@ok,$poss);
22224: }
22225: }
22226: my $diff = $count - scalar(@ok);
22227: if ($diff) {
22228: push(@warnings,'<li>'.
22229: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22230: $diff,$warn{$item}).
22231: '</li>');
22232: }
1.393 raeburn 22233: if (@ok) {
22234: my @cidr_list;
22235: foreach my $item (@ok) {
22236: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22237: }
22238: $wafproxy{$item} = join(',',@cidr_list);
22239: }
1.373 raeburn 22240: }
22241: }
1.381 raeburn 22242: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22243: $changes{$item} = 1;
22244: }
1.381 raeburn 22245: } elsif ($currvalue{$item}) {
22246: $changes{$item} = 1;
1.425 raeburn 22247: }
1.381 raeburn 22248: }
22249: } else {
22250: if (keys(%curralias)) {
22251: $changes{'alias'} = 1;
1.388 raeburn 22252: }
22253: if (keys(%currsaml)) {
22254: $changes{'saml'} = 1;
1.425 raeburn 22255: }
1.381 raeburn 22256: if (keys(%currvalue)) {
22257: foreach my $key (keys(%currvalue)) {
22258: $changes{$key} = 1;
1.373 raeburn 22259: }
22260: }
22261: }
22262: if (keys(%changes)) {
22263: my %defaultshash = (
22264: wafproxy => \%wafproxy,
1.425 raeburn 22265: );
1.373 raeburn 22266: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22267: $dom);
22268: if ($putresult eq 'ok') {
22269: my $cachetime = 24*60*60;
22270: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22271: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22272: if ($changes{$item}) {
22273: unless ($updatedomdefs) {
22274: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22275: $updatedomdefs = 1;
22276: }
22277: if ($wafproxy{$item}) {
22278: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22279: } elsif (exists($domdefaults{'waf_'.$item})) {
22280: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22281: }
1.373 raeburn 22282: }
22283: }
22284: if ($updatedomdefs) {
22285: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22286: if (ref($lastactref) eq 'HASH') {
22287: $lastactref->{'domdefaults'} = 1;
22288: }
22289: }
22290: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22291: my %updates = %expirecache;
22292: foreach my $key (keys(%expirecache)) {
22293: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22294: }
22295: if (ref($wafproxy{'alias'}) eq 'HASH') {
22296: my $cachetime = 24*60*60;
22297: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22298: $updates{$key} = 1;
22299: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22300: $cachetime);
22301: }
22302: }
22303: if (ref($lastactref) eq 'HASH') {
22304: $lastactref->{'proxyalias'} = \%updates;
22305: }
22306: }
1.388 raeburn 22307: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22308: my %samlupdates = %expiresaml;
22309: foreach my $key (keys(%expiresaml)) {
22310: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22311: }
22312: if (ref($wafproxy{'saml'}) eq 'HASH') {
22313: my $cachetime = 24*60*60;
22314: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22315: $samlupdates{$key} = 1;
22316: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22317: $cachetime);
22318: }
22319: }
22320: if (ref($lastactref) eq 'HASH') {
22321: $lastactref->{'proxysaml'} = \%samlupdates;
22322: }
22323: }
1.373 raeburn 22324: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22325: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22326: if ($changes{$item}) {
22327: if ($item eq 'alias') {
22328: my $numaliased = 0;
22329: if (ref($wafproxy{'alias'}) eq 'HASH') {
22330: my $shown;
22331: if (keys(%{$wafproxy{'alias'}})) {
22332: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22333: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22334: &Apache::lonnet::hostname($server),
22335: $wafproxy{'alias'}{$server}).'</li>';
22336: $numaliased ++;
22337: }
22338: if ($numaliased) {
22339: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22340: '<ul>'.$shown.'</ul>').'</li>';
22341: }
22342: }
22343: }
22344: unless ($numaliased) {
22345: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22346: }
1.388 raeburn 22347: } elsif ($item eq 'saml') {
1.425 raeburn 22348: my $shown;
1.388 raeburn 22349: if (ref($wafproxy{'saml'}) eq 'HASH') {
22350: if (keys(%{$wafproxy{'saml'}})) {
22351: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22352: }
22353: }
22354: if ($shown) {
1.396 raeburn 22355: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22356: $shown).'</li>';
22357: } else {
1.396 raeburn 22358: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22359: }
1.373 raeburn 22360: } else {
1.381 raeburn 22361: if ($item eq 'remoteip') {
22362: my %ip_methods = &remoteip_methods();
22363: if ($wafproxy{$item} =~ /^[mh]$/) {
22364: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22365: $ip_methods{$wafproxy{$item}}).'</li>';
22366: } else {
22367: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22368: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22369: '</li>';
22370: } else {
22371: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22372: }
22373: }
22374: } elsif ($item eq 'ipheader') {
1.373 raeburn 22375: if ($wafproxy{$item}) {
1.381 raeburn 22376: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22377: $wafproxy{$item}).'</li>';
22378: } else {
1.381 raeburn 22379: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22380: }
22381: } elsif ($item eq 'trusted') {
22382: if ($wafproxy{$item}) {
1.381 raeburn 22383: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22384: $wafproxy{$item}).'</li>';
22385: } else {
22386: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22387: }
1.381 raeburn 22388: } elsif ($item eq 'vpnint') {
22389: if ($wafproxy{$item}) {
22390: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22391: $wafproxy{$item}).'</li>';
22392: } else {
22393: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22394: }
22395: } elsif ($item eq 'vpnext') {
1.373 raeburn 22396: if ($wafproxy{$item}) {
1.381 raeburn 22397: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22398: $wafproxy{$item}).'</li>';
22399: } else {
1.381 raeburn 22400: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22401: }
1.382 raeburn 22402: } elsif ($item eq 'sslopt') {
22403: if ($wafproxy{$item}) {
22404: $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>';
22405: } else {
22406: $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>';
22407: }
1.373 raeburn 22408: }
22409: }
22410: }
22411: }
1.420 raeburn 22412: $output .= '</ul>';
1.373 raeburn 22413: } else {
22414: $output = '<span class="LC_error">'.
22415: &mt('An error occurred: [_1]',$putresult).'</span>';
22416: }
22417: } elsif (keys(%canset)) {
22418: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22419: }
22420: if (@warnings) {
22421: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22422: join("\n",@warnings).'</ul>';
22423: }
22424: return $output;
22425: }
22426:
22427: sub validate_ip_pattern {
22428: my ($pattern) = @_;
22429: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22430: my ($start,$end) = ($1,$2);
22431: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22432: if (($start !~ m{/}) && ($end !~ m{/})) {
22433: return $start.'-'.$end;
22434: }
22435: }
22436: } elsif ($pattern ne '') {
22437: $pattern = &Net::CIDR::cidrvalidate($pattern);
22438: if ($pattern ne '') {
22439: return $pattern;
1.373 raeburn 22440: }
22441: }
1.393 raeburn 22442: return;
1.373 raeburn 22443: }
22444:
1.137 raeburn 22445: sub modify_usersessions {
1.212 raeburn 22446: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22447: my @hostingtypes = ('version','excludedomain','includedomain');
22448: my @offloadtypes = ('primary','default');
22449: my %types = (
22450: remote => \@hostingtypes,
22451: hosted => \@hostingtypes,
22452: spares => \@offloadtypes,
22453: );
22454: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22455: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22456: my (%by_ip,%by_location,@intdoms,@instdoms);
22457: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22458: my @locations = sort(keys(%by_location));
1.137 raeburn 22459: my (%defaultshash,%changes);
22460: foreach my $prefix (@prefixes) {
22461: $defaultshash{'usersessions'}{$prefix} = {};
22462: }
1.212 raeburn 22463: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22464: my $resulttext;
1.138 raeburn 22465: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22466: foreach my $prefix (@prefixes) {
1.145 raeburn 22467: next if ($prefix eq 'spares');
22468: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22469: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22470: if ($type eq 'version') {
22471: my $value = $env{'form.'.$prefix.'_'.$type};
22472: my $okvalue;
22473: if ($value ne '') {
22474: if (grep(/^\Q$value\E$/,@lcversions)) {
22475: $okvalue = $value;
22476: }
22477: }
22478: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22479: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22480: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22481: if ($inuse == 0) {
22482: $changes{$prefix}{$type} = 1;
22483: } else {
22484: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22485: $changes{$prefix}{$type} = 1;
22486: }
22487: if ($okvalue ne '') {
22488: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22489: }
22490: }
22491: } else {
22492: if (($inuse == 1) && ($okvalue ne '')) {
22493: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22494: $changes{$prefix}{$type} = 1;
22495: }
22496: }
22497: } else {
22498: if (($inuse == 1) && ($okvalue ne '')) {
22499: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22500: $changes{$prefix}{$type} = 1;
22501: }
22502: }
22503: } else {
22504: if (($inuse == 1) && ($okvalue ne '')) {
22505: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22506: $changes{$prefix}{$type} = 1;
22507: }
22508: }
22509: } else {
22510: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22511: my @okvals;
22512: foreach my $val (@vals) {
1.138 raeburn 22513: if ($val =~ /:/) {
22514: my @items = split(/:/,$val);
22515: foreach my $item (@items) {
22516: if (ref($by_location{$item}) eq 'ARRAY') {
22517: push(@okvals,$item);
22518: }
22519: }
22520: } else {
22521: if (ref($by_location{$val}) eq 'ARRAY') {
22522: push(@okvals,$val);
22523: }
1.137 raeburn 22524: }
22525: }
22526: @okvals = sort(@okvals);
22527: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22528: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22529: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22530: if ($inuse == 0) {
22531: $changes{$prefix}{$type} = 1;
22532: } else {
22533: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22534: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22535: if (@changed > 0) {
22536: $changes{$prefix}{$type} = 1;
22537: }
22538: }
22539: } else {
22540: if ($inuse == 1) {
22541: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22542: $changes{$prefix}{$type} = 1;
22543: }
22544: }
22545: } else {
22546: if ($inuse == 1) {
22547: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22548: $changes{$prefix}{$type} = 1;
22549: }
22550: }
22551: } else {
22552: if ($inuse == 1) {
22553: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22554: $changes{$prefix}{$type} = 1;
22555: }
22556: }
22557: }
22558: }
22559: }
1.145 raeburn 22560:
22561: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22562: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22563: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22564: my $savespares;
22565:
22566: foreach my $lonhost (sort(keys(%servers))) {
22567: my $serverhomeID =
22568: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22569: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22570: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22571: my %spareschg;
22572: foreach my $type (@{$types{'spares'}}) {
22573: my @okspares;
22574: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22575: foreach my $server (@checked) {
1.152 raeburn 22576: if (&Apache::lonnet::hostname($server) ne '') {
22577: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22578: unless (grep(/^\Q$server\E$/,@okspares)) {
22579: push(@okspares,$server);
22580: }
1.145 raeburn 22581: }
22582: }
22583: }
22584: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22585: my $newspare;
1.152 raeburn 22586: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22587: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22588: $newspare = $new;
22589: }
22590: }
1.152 raeburn 22591: my @spares;
22592: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22593: @spares = sort(@okspares,$newspare);
22594: } else {
22595: @spares = sort(@okspares);
22596: }
22597: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22598: if (ref($spareid{$lonhost}) eq 'HASH') {
22599: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22600: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22601: if (@diffs > 0) {
22602: $spareschg{$type} = 1;
22603: }
22604: }
22605: }
22606: }
22607: if (keys(%spareschg) > 0) {
22608: $changes{'spares'}{$lonhost} = \%spareschg;
22609: }
22610: }
1.261 raeburn 22611: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22612: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22613: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22614: my @okoffload;
22615: if (@offloadnow) {
22616: foreach my $server (@offloadnow) {
22617: if (&Apache::lonnet::hostname($server) ne '') {
22618: unless (grep(/^\Q$server\E$/,@okoffload)) {
22619: push(@okoffload,$server);
22620: }
22621: }
22622: }
22623: if (@okoffload) {
22624: foreach my $lonhost (@okoffload) {
22625: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22626: }
22627: }
22628: }
1.371 raeburn 22629: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22630: my @okoffloadoth;
22631: if (@offloadoth) {
22632: foreach my $server (@offloadoth) {
22633: if (&Apache::lonnet::hostname($server) ne '') {
22634: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22635: push(@okoffloadoth,$server);
22636: }
22637: }
22638: }
22639: if (@okoffloadoth) {
22640: foreach my $lonhost (@okoffloadoth) {
22641: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22642: }
22643: }
22644: }
1.145 raeburn 22645: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22646: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22647: if (ref($changes{'spares'}) eq 'HASH') {
22648: if (keys(%{$changes{'spares'}}) > 0) {
22649: $savespares = 1;
22650: }
22651: }
22652: } else {
22653: $savespares = 1;
22654: }
1.371 raeburn 22655: foreach my $offload ('offloadnow','offloadoth') {
22656: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22657: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22658: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22659: $changes{$offload} = 1;
22660: last;
22661: }
1.261 raeburn 22662: }
1.371 raeburn 22663: unless ($changes{$offload}) {
22664: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22665: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22666: $changes{$offload} = 1;
22667: last;
22668: }
1.261 raeburn 22669: }
22670: }
1.371 raeburn 22671: } else {
22672: if (($offload eq 'offloadnow') && (@okoffload)) {
22673: $changes{'offloadnow'} = 1;
22674: }
22675: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22676: $changes{'offloadoth'} = 1;
22677: }
1.425 raeburn 22678: }
1.371 raeburn 22679: }
22680: } else {
22681: if (@okoffload) {
1.261 raeburn 22682: $changes{'offloadnow'} = 1;
22683: }
1.371 raeburn 22684: if (@okoffloadoth) {
22685: $changes{'offloadoth'} = 1;
22686: }
1.145 raeburn 22687: }
1.147 raeburn 22688: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22689: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22690: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22691: $dom);
22692: if ($putresult eq 'ok') {
22693: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22694: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22695: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22696: }
22697: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22698: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22699: }
1.261 raeburn 22700: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22701: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22702: }
1.371 raeburn 22703: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22704: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22705: }
1.137 raeburn 22706: }
22707: my $cachetime = 24*60*60;
22708: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22709: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22710: if (ref($lastactref) eq 'HASH') {
22711: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22712: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22713: }
1.147 raeburn 22714: if (keys(%changes) > 0) {
22715: my %lt = &usersession_titles();
22716: $resulttext = &mt('Changes made:').'<ul>';
22717: foreach my $prefix (@prefixes) {
22718: if (ref($changes{$prefix}) eq 'HASH') {
22719: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22720: if ($prefix eq 'spares') {
22721: if (ref($changes{$prefix}) eq 'HASH') {
22722: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22723: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22724: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22725: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22726: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22727: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22728: foreach my $type (@{$types{$prefix}}) {
22729: if ($changes{$prefix}{$lonhost}{$type}) {
22730: my $offloadto = &mt('None');
22731: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22732: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22733: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22734: }
1.145 raeburn 22735: }
1.147 raeburn 22736: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22737: }
1.137 raeburn 22738: }
22739: }
1.147 raeburn 22740: $resulttext .= '</li>';
1.137 raeburn 22741: }
22742: }
1.147 raeburn 22743: } else {
22744: foreach my $type (@{$types{$prefix}}) {
22745: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22746: my ($newvalue,$notinuse);
1.147 raeburn 22747: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22748: if (ref($defaultshash{'usersessions'}{$prefix})) {
22749: if ($type eq 'version') {
22750: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22751: } else {
22752: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22753: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22754: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22755: }
22756: } else {
22757: $notinuse = 1;
1.147 raeburn 22758: }
1.145 raeburn 22759: }
22760: }
22761: }
1.147 raeburn 22762: if ($newvalue eq '') {
22763: if ($type eq 'version') {
22764: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22765: } elsif ($notinuse) {
22766: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22767: } else {
22768: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22769: }
1.145 raeburn 22770: } else {
1.147 raeburn 22771: if ($type eq 'version') {
1.344 raeburn 22772: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22773: }
22774: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22775: }
1.137 raeburn 22776: }
22777: }
22778: }
1.147 raeburn 22779: $resulttext .= '</ul>';
1.137 raeburn 22780: }
22781: }
1.261 raeburn 22782: if ($changes{'offloadnow'}) {
22783: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22784: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22785: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22786: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22787: $resulttext .= '<li>'.$lonhost.'</li>';
22788: }
22789: $resulttext .= '</ul>';
22790: } else {
1.371 raeburn 22791: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22792: }
22793: } else {
22794: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22795: }
22796: }
22797: if ($changes{'offloadoth'}) {
22798: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22799: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22800: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22801: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22802: $resulttext .= '<li>'.$lonhost.'</li>';
22803: }
22804: $resulttext .= '</ul>';
22805: } else {
22806: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22807: }
22808: } else {
1.371 raeburn 22809: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22810: }
22811: }
1.147 raeburn 22812: $resulttext .= '</ul>';
22813: } else {
22814: $resulttext = $nochgmsg;
1.137 raeburn 22815: }
22816: } else {
22817: $resulttext = '<span class="LC_error">'.
22818: &mt('An error occurred: [_1]',$putresult).'</span>';
22819: }
22820: } else {
1.147 raeburn 22821: $resulttext = $nochgmsg;
1.137 raeburn 22822: }
22823: return $resulttext;
22824: }
22825:
1.275 raeburn 22826: sub modify_ssl {
22827: my ($dom,$lastactref,%domconfig) = @_;
22828: my (%by_ip,%by_location,@intdoms,@instdoms);
22829: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22830: my @locations = sort(keys(%by_location));
22831: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22832: my (%defaultshash,%changes);
22833: my $action = 'ssl';
1.293 raeburn 22834: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22835: foreach my $prefix (@prefixes) {
22836: $defaultshash{$action}{$prefix} = {};
22837: }
22838: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22839: my $resulttext;
22840: my %iphost = &Apache::lonnet::get_iphost();
22841: my @reptypes = ('certreq','nocertreq');
22842: my @connecttypes = ('dom','intdom','other');
22843: my %types = (
1.293 raeburn 22844: connto => \@connecttypes,
22845: connfrom => \@connecttypes,
22846: replication => \@reptypes,
1.275 raeburn 22847: );
22848: foreach my $prefix (sort(keys(%types))) {
22849: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22850: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22851: my $value = 'yes';
22852: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22853: $value = $env{'form.'.$prefix.'_'.$type};
22854: }
1.335 raeburn 22855: if (ref($domconfig{$action}) eq 'HASH') {
22856: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22857: if ($domconfig{$action}{$prefix}{$type} ne '') {
22858: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22859: $changes{$prefix}{$type} = 1;
22860: }
22861: $defaultshash{$action}{$prefix}{$type} = $value;
22862: } else {
22863: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22864: $changes{$prefix}{$type} = 1;
22865: }
22866: } else {
22867: $defaultshash{$action}{$prefix}{$type} = $value;
22868: $changes{$prefix}{$type} = 1;
22869: }
22870: } else {
22871: $defaultshash{$action}{$prefix}{$type} = $value;
22872: $changes{$prefix}{$type} = 1;
22873: }
22874: if (($type eq 'dom') && (keys(%servers) == 1)) {
22875: delete($changes{$prefix}{$type});
22876: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22877: delete($changes{$prefix}{$type});
22878: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22879: delete($changes{$prefix}{$type});
22880: }
22881: } elsif ($prefix eq 'replication') {
22882: if (@locations > 0) {
22883: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22884: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22885: my @okvals;
22886: foreach my $val (@vals) {
22887: if ($val =~ /:/) {
22888: my @items = split(/:/,$val);
22889: foreach my $item (@items) {
22890: if (ref($by_location{$item}) eq 'ARRAY') {
22891: push(@okvals,$item);
22892: }
22893: }
22894: } else {
22895: if (ref($by_location{$val}) eq 'ARRAY') {
22896: push(@okvals,$val);
22897: }
22898: }
22899: }
22900: @okvals = sort(@okvals);
22901: if (ref($domconfig{$action}) eq 'HASH') {
22902: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22903: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22904: if ($inuse == 0) {
22905: $changes{$prefix}{$type} = 1;
22906: } else {
22907: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22908: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22909: if (@changed > 0) {
22910: $changes{$prefix}{$type} = 1;
22911: }
22912: }
22913: } else {
22914: if ($inuse == 1) {
22915: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22916: $changes{$prefix}{$type} = 1;
22917: }
22918: }
22919: } else {
22920: if ($inuse == 1) {
22921: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22922: $changes{$prefix}{$type} = 1;
22923: }
22924: }
22925: } else {
22926: if ($inuse == 1) {
22927: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22928: $changes{$prefix}{$type} = 1;
22929: }
22930: }
22931: }
22932: }
22933: }
22934: }
1.336 raeburn 22935: if (keys(%changes)) {
22936: foreach my $prefix (keys(%changes)) {
22937: if (ref($changes{$prefix}) eq 'HASH') {
22938: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22939: delete($changes{$prefix});
22940: }
22941: } else {
22942: delete($changes{$prefix});
22943: }
22944: }
22945: }
1.275 raeburn 22946: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22947: if (keys(%changes) > 0) {
22948: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22949: $dom);
22950: if ($putresult eq 'ok') {
22951: if (ref($defaultshash{$action}) eq 'HASH') {
22952: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22953: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22954: }
1.293 raeburn 22955: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22956: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22957: }
22958: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22959: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22960: }
22961: }
22962: my $cachetime = 24*60*60;
22963: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22964: if (ref($lastactref) eq 'HASH') {
22965: $lastactref->{'domdefaults'} = 1;
22966: }
22967: if (keys(%changes) > 0) {
22968: my %titles = &ssl_titles();
22969: $resulttext = &mt('Changes made:').'<ul>';
22970: foreach my $prefix (@prefixes) {
22971: if (ref($changes{$prefix}) eq 'HASH') {
22972: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22973: foreach my $type (@{$types{$prefix}}) {
22974: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22975: my ($newvalue,$notinuse);
1.275 raeburn 22976: if (ref($defaultshash{$action}) eq 'HASH') {
22977: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22978: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22979: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22980: } else {
22981: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22982: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22983: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22984: }
22985: } else {
22986: $notinuse = 1;
1.275 raeburn 22987: }
22988: }
22989: }
1.344 raeburn 22990: if ($notinuse) {
22991: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22992: } elsif ($newvalue eq '') {
1.275 raeburn 22993: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22994: } else {
22995: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22996: }
22997: }
22998: }
22999: }
23000: $resulttext .= '</ul>';
23001: }
23002: }
23003: } else {
23004: $resulttext = $nochgmsg;
23005: }
23006: } else {
23007: $resulttext = '<span class="LC_error">'.
23008: &mt('An error occurred: [_1]',$putresult).'</span>';
23009: }
23010: } else {
23011: $resulttext = $nochgmsg;
23012: }
23013: return $resulttext;
23014: }
23015:
1.279 raeburn 23016: sub modify_trust {
23017: my ($dom,$lastactref,%domconfig) = @_;
23018: my (%by_ip,%by_location,@intdoms,@instdoms);
23019: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23020: my @locations = sort(keys(%by_location));
23021: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23022: my @types = ('exc','inc');
23023: my (%defaultshash,%changes);
23024: foreach my $prefix (@prefixes) {
23025: $defaultshash{'trust'}{$prefix} = {};
23026: }
23027: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23028: my $resulttext;
23029: foreach my $prefix (@prefixes) {
23030: foreach my $type (@types) {
23031: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23032: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23033: my @okvals;
23034: foreach my $val (@vals) {
23035: if ($val =~ /:/) {
23036: my @items = split(/:/,$val);
23037: foreach my $item (@items) {
23038: if (ref($by_location{$item}) eq 'ARRAY') {
23039: push(@okvals,$item);
23040: }
23041: }
23042: } else {
23043: if (ref($by_location{$val}) eq 'ARRAY') {
23044: push(@okvals,$val);
23045: }
23046: }
23047: }
23048: @okvals = sort(@okvals);
23049: if (ref($domconfig{'trust'}) eq 'HASH') {
23050: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23051: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23052: if ($inuse == 0) {
23053: $changes{$prefix}{$type} = 1;
23054: } else {
23055: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23056: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23057: if (@changed > 0) {
23058: $changes{$prefix}{$type} = 1;
23059: }
23060: }
23061: } else {
23062: if ($inuse == 1) {
23063: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23064: $changes{$prefix}{$type} = 1;
23065: }
23066: }
23067: } else {
23068: if ($inuse == 1) {
23069: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23070: $changes{$prefix}{$type} = 1;
23071: }
23072: }
23073: } else {
23074: if ($inuse == 1) {
23075: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23076: $changes{$prefix}{$type} = 1;
23077: }
23078: }
23079: }
23080: }
23081: my $nochgmsg = &mt('No changes made to trust settings.');
23082: if (keys(%changes) > 0) {
23083: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23084: $dom);
23085: if ($putresult eq 'ok') {
23086: if (ref($defaultshash{'trust'}) eq 'HASH') {
23087: foreach my $prefix (@prefixes) {
23088: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23089: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23090: }
23091: }
23092: }
23093: my $cachetime = 24*60*60;
23094: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23095: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23096: if (ref($lastactref) eq 'HASH') {
23097: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23098: $lastactref->{'trust'} = 1;
1.279 raeburn 23099: }
23100: if (keys(%changes) > 0) {
23101: my %lt = &trust_titles();
23102: $resulttext = &mt('Changes made:').'<ul>';
23103: foreach my $prefix (@prefixes) {
23104: if (ref($changes{$prefix}) eq 'HASH') {
23105: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23106: foreach my $type (@types) {
23107: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23108: my ($newvalue,$notinuse);
1.279 raeburn 23109: if (ref($defaultshash{'trust'}) eq 'HASH') {
23110: if (ref($defaultshash{'trust'}{$prefix})) {
23111: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23112: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23113: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23114: }
1.344 raeburn 23115: } else {
23116: $notinuse = 1;
1.279 raeburn 23117: }
23118: }
23119: }
1.344 raeburn 23120: if ($notinuse) {
23121: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23122: } elsif ($newvalue eq '') {
1.279 raeburn 23123: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23124: } else {
23125: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23126: }
23127: }
23128: }
23129: $resulttext .= '</ul>';
23130: }
23131: }
23132: $resulttext .= '</ul>';
23133: } else {
23134: $resulttext = $nochgmsg;
23135: }
23136: } else {
23137: $resulttext = '<span class="LC_error">'.
23138: &mt('An error occurred: [_1]',$putresult).'</span>';
23139: }
23140: } else {
23141: $resulttext = $nochgmsg;
23142: }
23143: return $resulttext;
23144: }
23145:
1.150 raeburn 23146: sub modify_loadbalancing {
23147: my ($dom,%domconfig) = @_;
23148: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23149: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23150: my ($othertitle,$usertypes,$types) =
23151: &Apache::loncommon::sorted_inst_types($dom);
23152: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23153: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23154: my @sparestypes = ('primary','default');
23155: my %typetitles = &sparestype_titles();
23156: my $resulttext;
1.342 raeburn 23157: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23158: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23159: %existing = %{$domconfig{'loadbalancing'}};
23160: }
23161: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23162: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23163: my ($saveloadbalancing,%defaultshash,%changes);
23164: my ($alltypes,$othertypes,$titles) =
23165: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23166: my %ruletitles = &offloadtype_text();
23167: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23168: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23169: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23170: if ($balancer eq '') {
23171: next;
23172: }
1.210 raeburn 23173: if (!exists($servers{$balancer})) {
1.171 raeburn 23174: if (exists($currbalancer{$balancer})) {
23175: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23176: }
1.171 raeburn 23177: next;
23178: }
23179: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23180: push(@{$changes{'delete'}},$balancer);
23181: next;
23182: }
23183: if (!exists($currbalancer{$balancer})) {
23184: push(@{$changes{'add'}},$balancer);
23185: }
23186: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23187: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23188: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23189: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23190: $saveloadbalancing = 1;
23191: }
23192: foreach my $sparetype (@sparestypes) {
23193: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23194: my @offloadto;
23195: foreach my $target (@targets) {
23196: if (($servers{$target}) && ($target ne $balancer)) {
23197: if ($sparetype eq 'default') {
23198: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23199: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23200: }
23201: }
1.171 raeburn 23202: unless(grep(/^\Q$target\E$/,@offloadto)) {
23203: push(@offloadto,$target);
23204: }
1.150 raeburn 23205: }
23206: }
1.284 raeburn 23207: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23208: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23209: push(@offloadto,$balancer);
23210: }
23211: }
23212: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23213: }
1.342 raeburn 23214: if ($env{'form.loadbalancing_cookie_'.$i}) {
23215: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23216: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23217: unless ($currcookies{$balancer}) {
23218: $changes{'curr'}{$balancer}{'cookie'} = 1;
23219: }
23220: }
23221: } elsif (exists($currbalancer{$balancer})) {
23222: if ($currcookies{$balancer}) {
23223: $changes{'curr'}{$balancer}{'cookie'} = 1;
23224: }
23225: }
1.171 raeburn 23226: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23227: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23228: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23229: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23230: if (@targetdiffs > 0) {
1.171 raeburn 23231: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23232: }
1.171 raeburn 23233: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23234: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23235: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23236: }
23237: }
23238: }
23239: } else {
1.171 raeburn 23240: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23241: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23242: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23243: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23244: $changes{'curr'}{$balancer}{'targets'} = 1;
23245: }
1.150 raeburn 23246: }
23247: }
1.210 raeburn 23248: }
1.150 raeburn 23249: }
23250: my $ishomedom;
1.171 raeburn 23251: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23252: $ishomedom = 1;
1.150 raeburn 23253: }
23254: if (ref($alltypes) eq 'ARRAY') {
23255: foreach my $type (@{$alltypes}) {
23256: my $rule;
1.210 raeburn 23257: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23258: (!$ishomedom)) {
1.171 raeburn 23259: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23260: }
23261: if ($rule eq 'specific') {
1.255 raeburn 23262: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23263: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23264: $rule = $specifiedhost;
23265: }
1.150 raeburn 23266: }
1.171 raeburn 23267: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23268: if (ref($currrules{$balancer}) eq 'HASH') {
23269: if ($rule ne $currrules{$balancer}{$type}) {
23270: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23271: }
23272: } elsif ($rule ne '') {
1.171 raeburn 23273: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23274: }
23275: }
23276: }
1.171 raeburn 23277: }
23278: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23279: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23280: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23281: $defaultshash{'loadbalancing'} = {};
23282: }
23283: my $putresult = &Apache::lonnet::put_dom('configuration',
23284: \%defaultshash,$dom);
23285: if ($putresult eq 'ok') {
23286: if (keys(%changes) > 0) {
1.252 raeburn 23287: my %toupdate;
1.171 raeburn 23288: if (ref($changes{'delete'}) eq 'ARRAY') {
23289: foreach my $balancer (sort(@{$changes{'delete'}})) {
23290: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23291: $toupdate{$balancer} = 1;
1.150 raeburn 23292: }
1.171 raeburn 23293: }
23294: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23295: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23296: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23297: $toupdate{$balancer} = 1;
1.171 raeburn 23298: }
23299: }
23300: if (ref($changes{'curr'}) eq 'HASH') {
23301: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23302: $toupdate{$balancer} = 1;
1.171 raeburn 23303: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23304: if ($changes{'curr'}{$balancer}{'targets'}) {
23305: my %offloadstr;
23306: foreach my $sparetype (@sparestypes) {
23307: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23308: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23309: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23310: }
23311: }
1.150 raeburn 23312: }
1.171 raeburn 23313: if (keys(%offloadstr) == 0) {
23314: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23315: } else {
1.171 raeburn 23316: my $showoffload;
23317: foreach my $sparetype (@sparestypes) {
23318: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23319: if (defined($offloadstr{$sparetype})) {
23320: $showoffload .= $offloadstr{$sparetype};
23321: } else {
23322: $showoffload .= &mt('None');
23323: }
23324: $showoffload .= (' 'x3);
23325: }
23326: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23327: }
23328: }
23329: }
1.171 raeburn 23330: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23331: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23332: foreach my $type (@{$alltypes}) {
23333: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23334: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23335: my $balancetext;
23336: if ($rule eq '') {
23337: $balancetext = $ruletitles{'default'};
1.209 raeburn 23338: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23339: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23340: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23341: foreach my $sparetype (@sparestypes) {
23342: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23343: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23344: }
23345: }
1.253 raeburn 23346: foreach my $item (@{$alltypes}) {
23347: next if ($item =~ /^_LC_ipchange/);
23348: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23349: if ($hasrule eq 'homeserver') {
23350: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23351: } else {
23352: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23353: if ($servers{$hasrule}) {
23354: $toupdate{$hasrule} = 1;
23355: }
23356: }
23357: }
23358: }
1.254 raeburn 23359: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23360: $balancetext = $ruletitles{$rule};
23361: } else {
23362: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23363: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23364: if ($receiver) {
23365: $toupdate{$receiver};
23366: }
23367: }
23368: } else {
23369: $balancetext = $ruletitles{$rule};
1.252 raeburn 23370: }
1.171 raeburn 23371: } else {
23372: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23373: }
1.210 raeburn 23374: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23375: }
23376: }
23377: }
23378: }
1.342 raeburn 23379: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23380: if ($currcookies{$balancer}) {
23381: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23382: $balancer).'</li>';
23383: } else {
23384: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23385: $balancer).'</li>';
23386: }
1.342 raeburn 23387: }
1.375 raeburn 23388: }
23389: }
23390: if (keys(%toupdate)) {
23391: my %thismachine;
23392: my $updatedhere;
23393: my $cachetime = 60*60*24;
23394: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23395: foreach my $lonhost (keys(%toupdate)) {
23396: if ($thismachine{$lonhost}) {
23397: unless ($updatedhere) {
23398: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23399: $defaultshash{'loadbalancing'},
23400: $cachetime);
23401: $updatedhere = 1;
1.252 raeburn 23402: }
1.375 raeburn 23403: } else {
23404: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23405: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23406: }
1.150 raeburn 23407: }
1.171 raeburn 23408: }
23409: if ($resulttext ne '') {
23410: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23411: } else {
23412: $resulttext = $nochgmsg;
23413: }
23414: } else {
1.171 raeburn 23415: $resulttext = $nochgmsg;
1.150 raeburn 23416: }
23417: } else {
1.171 raeburn 23418: $resulttext = '<span class="LC_error">'.
23419: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23420: }
23421: } else {
1.171 raeburn 23422: $resulttext = $nochgmsg;
1.150 raeburn 23423: }
23424: return $resulttext;
23425: }
23426:
1.48 raeburn 23427: sub recurse_check {
23428: my ($chkcats,$categories,$depth,$name) = @_;
23429: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23430: my $chg = 0;
23431: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23432: my $category = $chkcats->[$depth]{$name}[$j];
23433: my $item;
23434: if ($category eq '') {
23435: $chg ++;
23436: } else {
23437: my $deeper = $depth + 1;
23438: $item = &escape($category).':'.&escape($name).':'.$depth;
23439: if ($chg) {
23440: $categories->{$item} -= $chg;
23441: }
23442: &recurse_check($chkcats,$categories,$deeper,$category);
23443: $deeper --;
23444: }
23445: }
23446: }
23447: return;
23448: }
23449:
23450: sub recurse_cat_deletes {
23451: my ($item,$coursecategories,$deletions) = @_;
23452: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23453: my $subdepth = $depth + 1;
23454: if (ref($coursecategories) eq 'HASH') {
23455: foreach my $subitem (keys(%{$coursecategories})) {
23456: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23457: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23458: delete($coursecategories->{$subitem});
23459: $deletions->{$subitem} = 1;
23460: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23461: }
1.48 raeburn 23462: }
23463: }
23464: return;
23465: }
23466:
1.125 raeburn 23467: sub active_dc_picker {
1.191 raeburn 23468: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23469: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23470: my @domcoord = keys(%domcoords);
23471: if (keys(%currhash)) {
23472: foreach my $dc (keys(%currhash)) {
23473: unless (exists($domcoords{$dc})) {
23474: push(@domcoord,$dc);
23475: }
23476: }
23477: }
23478: @domcoord = sort(@domcoord);
1.210 raeburn 23479: my $numdcs = scalar(@domcoord);
1.191 raeburn 23480: my $rows = 0;
23481: my $table;
1.125 raeburn 23482: if ($numdcs > 1) {
1.191 raeburn 23483: $table = '<table>';
23484: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23485: my $rem = $i%($numinrow);
23486: if ($rem == 0) {
23487: if ($i > 0) {
1.191 raeburn 23488: $table .= '</tr>';
1.125 raeburn 23489: }
1.191 raeburn 23490: $table .= '<tr>';
23491: $rows ++;
1.125 raeburn 23492: }
1.191 raeburn 23493: my $check = '';
23494: if ($inputtype eq 'radio') {
23495: if (keys(%currhash) == 0) {
23496: if (!$i) {
23497: $check = ' checked="checked"';
23498: }
23499: } elsif (exists($currhash{$domcoord[$i]})) {
23500: $check = ' checked="checked"';
23501: }
23502: } else {
23503: if (exists($currhash{$domcoord[$i]})) {
23504: $check = ' checked="checked"';
1.125 raeburn 23505: }
23506: }
1.191 raeburn 23507: if ($i == @domcoord - 1) {
1.125 raeburn 23508: my $colsleft = $numinrow - $rem;
23509: if ($colsleft > 1) {
1.191 raeburn 23510: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23511: } else {
1.191 raeburn 23512: $table .= '<td class="LC_left_item">';
1.125 raeburn 23513: }
23514: } else {
1.191 raeburn 23515: $table .= '<td class="LC_left_item">';
23516: }
23517: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23518: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23519: $table .= '<span class="LC_nobreak"><label>'.
23520: '<input type="'.$inputtype.'" name="'.$name.'"'.
23521: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23522: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23523: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23524: }
1.219 raeburn 23525: $table .= '</label></span></td>';
1.191 raeburn 23526: }
23527: $table .= '</tr></table>';
23528: } elsif ($numdcs == 1) {
1.219 raeburn 23529: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23530: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23531: if ($inputtype eq 'radio') {
1.247 raeburn 23532: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23533: if ($user ne $dcname.':'.$dcdom) {
23534: $table .= ' ('.$dcname.':'.$dcdom.')';
23535: }
1.191 raeburn 23536: } else {
23537: my $check;
23538: if (exists($currhash{$domcoord[0]})) {
23539: $check = ' checked="checked"';
1.125 raeburn 23540: }
1.247 raeburn 23541: $table = '<span class="LC_nobreak"><label>'.
23542: '<input type="checkbox" name="'.$name.'" '.
23543: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23544: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23545: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23546: }
1.220 raeburn 23547: $table .= '</label></span>';
1.191 raeburn 23548: $rows ++;
1.125 raeburn 23549: }
23550: }
1.191 raeburn 23551: return ($numdcs,$table,$rows);
1.125 raeburn 23552: }
23553:
1.137 raeburn 23554: sub usersession_titles {
23555: return &Apache::lonlocal::texthash(
23556: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23557: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23558: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23559: version => 'LON-CAPA version requirement',
1.138 raeburn 23560: excludedomain => 'Allow all, but exclude specific domains',
23561: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23562: primary => 'Primary (checked first)',
1.154 raeburn 23563: default => 'Default',
1.137 raeburn 23564: );
23565: }
23566:
1.152 raeburn 23567: sub id_for_thisdom {
23568: my (%servers) = @_;
23569: my %altids;
23570: foreach my $server (keys(%servers)) {
23571: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23572: if ($serverhome ne $server) {
23573: $altids{$serverhome} = $server;
23574: }
23575: }
23576: return %altids;
23577: }
23578:
1.150 raeburn 23579: sub count_servers {
23580: my ($currbalancer,%servers) = @_;
23581: my (@spares,$numspares);
23582: foreach my $lonhost (sort(keys(%servers))) {
23583: next if ($currbalancer eq $lonhost);
23584: push(@spares,$lonhost);
23585: }
23586: if ($currbalancer) {
23587: $numspares = scalar(@spares);
23588: } else {
23589: $numspares = scalar(@spares) - 1;
23590: }
23591: return ($numspares,@spares);
23592: }
23593:
23594: sub lonbalance_targets_js {
1.171 raeburn 23595: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23596: my $select = &mt('Select');
23597: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23598: if (ref($servers) eq 'HASH') {
23599: $alltargets = join("','",sort(keys(%{$servers})));
23600: my @homedoms;
23601: foreach my $server (sort(keys(%{$servers}))) {
23602: if (&Apache::lonnet::host_domain($server) eq $dom) {
23603: push(@homedoms,'1');
23604: } else {
23605: push(@homedoms,'0');
23606: }
23607: }
23608: $allishome = join("','",@homedoms);
23609: }
23610: if (ref($types) eq 'ARRAY') {
23611: if (@{$types} > 0) {
23612: @alltypes = @{$types};
23613: }
23614: }
23615: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23616: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23617: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23618: if (ref($settings) eq 'HASH') {
23619: %existing = %{$settings};
23620: }
23621: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23622: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23623: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23624: return <<"END";
23625:
23626: <script type="text/javascript">
23627: // <![CDATA[
23628:
1.171 raeburn 23629: currBalancers = new Array('$balancers');
23630:
23631: function toggleTargets(balnum) {
23632: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23633: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23634: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23635: var prevbalancer = prevhostitem.value;
23636: var baltotal = document.getElementById('loadbalancing_total').value;
23637: prevhostitem.value = balancer;
23638: if (prevbalancer != '') {
23639: var prevIdx = currBalancers.indexOf(prevbalancer);
23640: if (prevIdx != -1) {
23641: currBalancers.splice(prevIdx,1);
23642: }
23643: }
1.150 raeburn 23644: if (balancer == '') {
1.171 raeburn 23645: hideSpares(balnum);
1.150 raeburn 23646: } else {
1.171 raeburn 23647: var currIdx = currBalancers.indexOf(balancer);
23648: if (currIdx == -1) {
23649: currBalancers.push(balancer);
23650: }
1.150 raeburn 23651: var homedoms = new Array('$allishome');
1.171 raeburn 23652: var ishomedom = homedoms[lonhostitem.selectedIndex];
23653: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23654: }
1.171 raeburn 23655: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23656: return;
23657: }
23658:
1.171 raeburn 23659: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23660: var alltargets = new Array('$alltargets');
23661: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23662: var offloadtypes = new Array('primary','default');
23663:
1.171 raeburn 23664: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23665: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23666:
1.151 raeburn 23667: for (var i=0; i<offloadtypes.length; i++) {
23668: var count = 0;
23669: for (var j=0; j<alltargets.length; j++) {
23670: if (alltargets[j] != balancer) {
1.171 raeburn 23671: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23672: item.value = alltargets[j];
23673: item.style.textAlign='left';
23674: item.style.textFace='normal';
23675: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23676: if (currBalancers.indexOf(alltargets[j]) == -1) {
23677: item.disabled = '';
23678: } else {
23679: item.disabled = 'disabled';
23680: item.checked = false;
23681: }
1.151 raeburn 23682: count ++;
23683: }
1.150 raeburn 23684: }
23685: }
1.151 raeburn 23686: for (var k=0; k<insttypes.length; k++) {
23687: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23688: if (ishomedom == 1) {
1.171 raeburn 23689: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23690: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23691: } else {
1.171 raeburn 23692: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23693: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23694: }
23695: } else {
1.171 raeburn 23696: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23697: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23698: }
1.151 raeburn 23699: if ((insttypes[k] != '_LC_external') &&
23700: ((insttypes[k] != '_LC_internetdom') ||
23701: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23702: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23703: item.options.length = 0;
23704: item.options[0] = new Option("","",true,true);
1.210 raeburn 23705: var idx = 0;
1.151 raeburn 23706: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23707: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23708: idx ++;
23709: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23710: }
23711: }
23712: }
23713: }
23714: return;
23715: }
23716:
1.171 raeburn 23717: function hideSpares(balnum) {
1.150 raeburn 23718: var alltargets = new Array('$alltargets');
23719: var insttypes = new Array('$allinsttypes');
23720: var offloadtypes = new Array('primary','default');
23721:
1.171 raeburn 23722: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23723: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23724:
23725: var total = alltargets.length - 1;
23726: for (var i=0; i<offloadtypes; i++) {
23727: for (var j=0; j<total; j++) {
1.171 raeburn 23728: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23729: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23730: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23731: }
1.150 raeburn 23732: }
23733: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23734: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23735: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23736: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23737: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23738: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23739: }
23740: }
23741: return;
23742: }
23743:
1.171 raeburn 23744: function checkOffloads(item,balnum,type) {
1.150 raeburn 23745: var alltargets = new Array('$alltargets');
23746: var offloadtypes = new Array('primary','default');
23747: if (item.checked) {
23748: var total = alltargets.length - 1;
23749: var other;
23750: if (type == offloadtypes[0]) {
1.151 raeburn 23751: other = offloadtypes[1];
1.150 raeburn 23752: } else {
1.151 raeburn 23753: other = offloadtypes[0];
1.150 raeburn 23754: }
23755: for (var i=0; i<total; i++) {
1.171 raeburn 23756: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23757: if (server == item.value) {
1.171 raeburn 23758: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23759: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23760: }
23761: }
23762: }
23763: }
23764: return;
23765: }
23766:
1.171 raeburn 23767: function singleServerToggle(balnum,type) {
23768: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23769: if (offloadtoSelIdx == 0) {
1.171 raeburn 23770: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23771: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23772:
23773: } else {
1.171 raeburn 23774: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23775: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23776: }
23777: return;
23778: }
23779:
1.171 raeburn 23780: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23781: if (type == '_LC_external') {
1.171 raeburn 23782: return;
1.150 raeburn 23783: }
1.171 raeburn 23784: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23785: for (var i=0; i<typesRules.length; i++) {
23786: if (formname.elements[typesRules[i]].checked) {
23787: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23788: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23789: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23790: } else {
1.171 raeburn 23791: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23792: }
23793: }
23794: }
23795: return;
23796: }
23797:
23798: function balancerDeleteChange(balnum) {
23799: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23800: var baltotal = document.getElementById('loadbalancing_total').value;
23801: var addtarget;
23802: var removetarget;
23803: var action = 'delete';
23804: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23805: var lonhost = hostitem.value;
23806: var currIdx = currBalancers.indexOf(lonhost);
23807: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23808: if (currIdx != -1) {
23809: currBalancers.splice(currIdx,1);
23810: }
23811: addtarget = lonhost;
23812: } else {
23813: if (currIdx == -1) {
23814: currBalancers.push(lonhost);
23815: }
23816: removetarget = lonhost;
23817: action = 'undelete';
23818: }
23819: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23820: }
23821: return;
23822: }
23823:
23824: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23825: if (baltotal > 1) {
23826: var offloadtypes = new Array('primary','default');
23827: var alltargets = new Array('$alltargets');
23828: var insttypes = new Array('$allinsttypes');
23829: for (var i=0; i<baltotal; i++) {
23830: if (i != balnum) {
23831: for (var j=0; j<offloadtypes.length; j++) {
23832: var total = alltargets.length - 1;
23833: for (var k=0; k<total; k++) {
23834: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23835: var server = serveritem.value;
23836: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23837: if (server == addtarget) {
23838: serveritem.disabled = '';
23839: }
23840: }
23841: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23842: if (server == removetarget) {
23843: serveritem.disabled = 'disabled';
23844: serveritem.checked = false;
23845: }
23846: }
23847: }
23848: }
23849: for (var j=0; j<insttypes.length; j++) {
23850: if (insttypes[j] != '_LC_external') {
23851: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23852: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23853: var currSel = singleserver.selectedIndex;
23854: var currVal = singleserver.options[currSel].value;
23855: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23856: var numoptions = singleserver.options.length;
23857: var needsnew = 1;
23858: for (var k=0; k<numoptions; k++) {
23859: if (singleserver.options[k] == addtarget) {
23860: needsnew = 0;
23861: break;
23862: }
23863: }
23864: if (needsnew == 1) {
23865: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23866: }
23867: }
23868: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23869: singleserver.options.length = 0;
23870: if ((currVal) && (currVal != removetarget)) {
23871: singleserver.options[0] = new Option("","",false,false);
23872: } else {
23873: singleserver.options[0] = new Option("","",true,true);
23874: }
23875: var idx = 0;
23876: for (var m=0; m<alltargets.length; m++) {
23877: if (currBalancers.indexOf(alltargets[m]) == -1) {
23878: idx ++;
23879: if (currVal == alltargets[m]) {
23880: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23881: } else {
23882: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23883: }
23884: }
23885: }
23886: }
23887: }
23888: }
23889: }
1.150 raeburn 23890: }
23891: }
23892: }
23893: return;
23894: }
23895:
1.152 raeburn 23896: // ]]>
23897: </script>
23898:
23899: END
23900: }
23901:
23902: sub new_spares_js {
23903: my @sparestypes = ('primary','default');
23904: my $types = join("','",@sparestypes);
23905: my $select = &mt('Select');
23906: return <<"END";
23907:
23908: <script type="text/javascript">
23909: // <![CDATA[
23910:
23911: function updateNewSpares(formname,lonhost) {
23912: var types = new Array('$types');
23913: var include = new Array();
23914: var exclude = new Array();
23915: for (var i=0; i<types.length; i++) {
23916: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23917: for (var j=0; j<spareboxes.length; j++) {
23918: if (formname.elements[spareboxes[j]].checked) {
23919: exclude.push(formname.elements[spareboxes[j]].value);
23920: } else {
23921: include.push(formname.elements[spareboxes[j]].value);
23922: }
23923: }
23924: }
23925: for (var i=0; i<types.length; i++) {
23926: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23927: var selIdx = newSpare.selectedIndex;
23928: var currnew = newSpare.options[selIdx].value;
23929: var okSpares = new Array();
23930: for (var j=0; j<newSpare.options.length; j++) {
23931: var possible = newSpare.options[j].value;
23932: if (possible != '') {
23933: if (exclude.indexOf(possible) == -1) {
23934: okSpares.push(possible);
23935: } else {
23936: if (currnew == possible) {
23937: selIdx = 0;
23938: }
23939: }
23940: }
23941: }
23942: for (var k=0; k<include.length; k++) {
23943: if (okSpares.indexOf(include[k]) == -1) {
23944: okSpares.push(include[k]);
23945: }
23946: }
23947: okSpares.sort();
23948: newSpare.options.length = 0;
23949: if (selIdx == 0) {
23950: newSpare.options[0] = new Option("$select","",true,true);
23951: } else {
23952: newSpare.options[0] = new Option("$select","",false,false);
23953: }
23954: for (var m=0; m<okSpares.length; m++) {
23955: var idx = m+1;
23956: var selThis = 0;
23957: if (selIdx != 0) {
23958: if (okSpares[m] == currnew) {
23959: selThis = 1;
23960: }
23961: }
23962: if (selThis == 1) {
23963: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23964: } else {
23965: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23966: }
23967: }
23968: }
23969: return;
23970: }
23971:
23972: function checkNewSpares(lonhost,type) {
23973: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23974: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23975: if (chosen != '') {
1.152 raeburn 23976: var othertype;
23977: var othernewSpare;
23978: if (type == 'primary') {
23979: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23980: }
23981: if (type == 'default') {
23982: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23983: }
23984: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23985: othernewSpare.selectedIndex = 0;
23986: }
23987: }
23988: return;
23989: }
23990:
23991: // ]]>
23992: </script>
23993:
23994: END
23995:
23996: }
23997:
23998: sub common_domprefs_js {
23999: return <<"END";
24000:
24001: <script type="text/javascript">
24002: // <![CDATA[
24003:
1.150 raeburn 24004: function getIndicesByName(formname,item) {
1.152 raeburn 24005: var group = new Array();
1.150 raeburn 24006: for (var i=0;i<formname.elements.length;i++) {
24007: if (formname.elements[i].name == item) {
1.152 raeburn 24008: group.push(formname.elements[i].id);
1.150 raeburn 24009: }
24010: }
1.152 raeburn 24011: return group;
1.150 raeburn 24012: }
24013:
24014: // ]]>
24015: </script>
24016:
24017: END
1.152 raeburn 24018:
1.150 raeburn 24019: }
24020:
1.165 raeburn 24021: sub recaptcha_js {
24022: my %lt = &captcha_phrases();
24023: return <<"END";
24024:
24025: <script type="text/javascript">
24026: // <![CDATA[
24027:
24028: function updateCaptcha(caller,context) {
24029: var privitem;
24030: var pubitem;
24031: var privtext;
24032: var pubtext;
1.269 raeburn 24033: var versionitem;
24034: var versiontext;
1.165 raeburn 24035: if (document.getElementById(context+'_recaptchapub')) {
24036: pubitem = document.getElementById(context+'_recaptchapub');
24037: } else {
24038: return;
24039: }
24040: if (document.getElementById(context+'_recaptchapriv')) {
24041: privitem = document.getElementById(context+'_recaptchapriv');
24042: } else {
24043: return;
24044: }
24045: if (document.getElementById(context+'_recaptchapubtxt')) {
24046: pubtext = document.getElementById(context+'_recaptchapubtxt');
24047: } else {
24048: return;
24049: }
24050: if (document.getElementById(context+'_recaptchaprivtxt')) {
24051: privtext = document.getElementById(context+'_recaptchaprivtxt');
24052: } else {
24053: return;
24054: }
1.269 raeburn 24055: if (document.getElementById(context+'_recaptchaversion')) {
24056: versionitem = document.getElementById(context+'_recaptchaversion');
24057: } else {
24058: return;
24059: }
24060: if (document.getElementById(context+'_recaptchavertxt')) {
24061: versiontext = document.getElementById(context+'_recaptchavertxt');
24062: } else {
24063: return;
24064: }
1.165 raeburn 24065: if (caller.checked) {
24066: if (caller.value == 'recaptcha') {
24067: pubitem.type = 'text';
24068: privitem.type = 'text';
24069: pubitem.size = '40';
24070: privitem.size = '40';
24071: pubtext.innerHTML = "$lt{'pub'}";
24072: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24073: versionitem.type = 'text';
24074: versionitem.size = '3';
1.289 raeburn 24075: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24076: } else {
24077: pubitem.type = 'hidden';
24078: privitem.type = 'hidden';
1.269 raeburn 24079: versionitem.type = 'hidden';
1.165 raeburn 24080: pubtext.innerHTML = '';
24081: privtext.innerHTML = '';
1.269 raeburn 24082: versiontext.innerHTML = '';
1.165 raeburn 24083: }
24084: }
24085: return;
24086: }
24087:
24088: // ]]>
24089: </script>
24090:
24091: END
24092:
24093: }
24094:
1.236 raeburn 24095: sub toggle_display_js {
1.192 raeburn 24096: return <<"END";
24097:
24098: <script type="text/javascript">
24099: // <![CDATA[
24100:
1.236 raeburn 24101: function toggleDisplay(domForm,caller) {
24102: if (document.getElementById(caller)) {
24103: var divitem = document.getElementById(caller);
24104: var optionsElement = domForm.coursecredits;
1.264 raeburn 24105: var checkval = 1;
24106: var dispval = 'block';
1.303 raeburn 24107: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24108: if (caller == 'emailoptions') {
1.372 raeburn 24109: optionsElement = domForm.cancreate_email;
1.236 raeburn 24110: }
1.257 raeburn 24111: if (caller == 'studentsubmission') {
24112: optionsElement = domForm.postsubmit;
24113: }
1.264 raeburn 24114: if (caller == 'cloneinstcode') {
24115: optionsElement = domForm.canclone;
24116: checkval = 'instcode';
24117: }
1.303 raeburn 24118: if (selfcreateRegExp.test(caller)) {
24119: optionsElement = domForm.elements[caller];
24120: checkval = 'other';
24121: dispval = 'inline'
24122: }
1.236 raeburn 24123: if (optionsElement.length) {
1.192 raeburn 24124: var currval;
1.236 raeburn 24125: for (var i=0; i<optionsElement.length; i++) {
24126: if (optionsElement[i].checked) {
24127: currval = optionsElement[i].value;
1.192 raeburn 24128: }
24129: }
1.264 raeburn 24130: if (currval == checkval) {
24131: divitem.style.display = dispval;
1.192 raeburn 24132: } else {
1.236 raeburn 24133: divitem.style.display = 'none';
1.192 raeburn 24134: }
24135: }
24136: }
24137: return;
24138: }
24139:
24140: // ]]>
24141: </script>
24142:
24143: END
24144:
24145: }
24146:
1.165 raeburn 24147: sub captcha_phrases {
24148: return &Apache::lonlocal::texthash (
24149: priv => 'Private key',
24150: pub => 'Public key',
24151: original => 'original (CAPTCHA)',
24152: recaptcha => 'successor (ReCAPTCHA)',
24153: notused => 'unused',
1.289 raeburn 24154: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24155: );
24156: }
24157:
1.205 raeburn 24158: sub devalidate_remote_domconfs {
1.212 raeburn 24159: my ($dom,$cachekeys) = @_;
24160: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24161: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24162: my %thismachine;
24163: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24164: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24165: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24166: 'ipaccess','trust');
1.386 raeburn 24167: my %cache_by_lonhost;
24168: if (exists($cachekeys->{'samllanding'})) {
24169: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24170: my %landing = %{$cachekeys->{'samllanding'}};
24171: my %domservers = &Apache::lonnet::get_servers($dom);
24172: if (keys(%domservers)) {
24173: foreach my $server (keys(%domservers)) {
24174: my @cached;
24175: next if ($thismachine{$server});
24176: if ($landing{$server}) {
24177: push(@cached,&escape('samllanding').':'.&escape($server));
24178: }
24179: if (@cached) {
24180: $cache_by_lonhost{$server} = \@cached;
24181: }
24182: }
24183: }
24184: }
24185: }
1.260 raeburn 24186: if (keys(%servers)) {
1.205 raeburn 24187: foreach my $server (keys(%servers)) {
24188: next if ($thismachine{$server});
1.212 raeburn 24189: my @cached;
24190: foreach my $name (@posscached) {
24191: if ($cachekeys->{$name}) {
1.388 raeburn 24192: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24193: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24194: foreach my $key (keys(%{$cachekeys->{$name}})) {
24195: push(@cached,&escape($name).':'.&escape($key));
24196: }
24197: }
24198: } else {
24199: push(@cached,&escape($name).':'.&escape($dom));
24200: }
1.212 raeburn 24201: }
24202: }
1.386 raeburn 24203: if ((exists($cache_by_lonhost{$server})) &&
24204: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24205: push(@cached,@{$cache_by_lonhost{$server}});
24206: }
1.212 raeburn 24207: if (@cached) {
24208: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24209: }
1.205 raeburn 24210: }
24211: }
24212: return;
24213: }
24214:
1.3 raeburn 24215: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>