Annotation of loncom/interface/domainprefs.pm, revision 1.446
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.446 ! raeburn 4: # $Id: domainprefs.pm,v 1.445 2024/10/12 01:42:29 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');
1.445 raeburn 2024: my @images = ();
1.6 raeburn 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}->{'font'} ne '') {
2033: $designs{'font'} = $settings->{$role}->{'font'};
2034: $is_custom{'font'} = 1;
2035: }
1.97 tempelho 2036: if ($settings->{$role}->{'fontmenu'} ne '') {
2037: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2038: $is_custom{'fontmenu'} = 1;
2039: }
1.6 raeburn 2040: foreach my $item (@bgs) {
2041: if ($settings->{$role}->{$item} ne '') {
2042: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2043: $is_custom{$item} = 1;
2044: }
2045: }
2046: foreach my $item (@links) {
2047: if ($settings->{$role}->{$item} ne '') {
2048: $designs{'links'}{$item} = $settings->{$role}->{$item};
2049: $is_custom{$item} = 1;
2050: }
2051: }
2052: }
2053: } else {
1.97 tempelho 2054: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2055: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2056: $is_custom{'fontmenu'} = 1;
2057: }
1.6 raeburn 2058: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2059: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2060: $is_custom{'font'} = 1;
2061: }
2062: foreach my $item (@bgs) {
2063: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2064: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2065: $is_custom{$item} = 1;
2066:
2067: }
2068: }
2069: foreach my $item (@links) {
2070: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2071: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2072: $is_custom{$item} = 1;
2073: }
2074: }
2075: }
2076: my $itemcount = 1;
1.30 raeburn 2077: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2078: $datatable .= '</tr></table></td></tr>';
2079: return $datatable;
2080: }
2081:
1.200 raeburn 2082: sub role_defaults {
2083: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2084: my %defaults;
2085: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2086: return %defaults;
2087: }
2088: my %defaultdesign = %Apache::loncommon::defaultdesign;
2089: if ($role eq 'login') {
2090: %defaults = (
2091: font => $defaultdesign{$role.'.font'},
2092: );
2093: if (ref($logintext) eq 'ARRAY') {
2094: foreach my $item (@{$logintext}) {
2095: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2096: }
2097: }
2098: foreach my $item (@{$images}) {
2099: $defaults{'showlogo'}{$item} = 1;
2100: }
2101: } else {
2102: %defaults = (
2103: font => $defaultdesign{$role.'.font'},
2104: fontmenu => $defaultdesign{$role.'.fontmenu'},
2105: );
2106: }
2107: foreach my $item (@{$bgs}) {
2108: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2109: }
2110: foreach my $item (@{$links}) {
2111: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2112: }
2113: foreach my $item (@{$images}) {
2114: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2115: }
2116: return %defaults;
2117: }
2118:
1.6 raeburn 2119: sub display_color_options {
1.9 raeburn 2120: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2121: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2122: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2123: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2124: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2125: '<td>'.$choices->{'font'}.'</td>';
2126: if (!$is_custom->{'font'}) {
1.329 raeburn 2127: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2128: } else {
2129: $datatable .= '<td> </td>';
2130: }
1.174 foxr 2131: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2132:
1.8 raeburn 2133: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2134: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2135: ' value="'.$current_color.'" /> '.
1.329 raeburn 2136: ' </span></td></tr>';
1.107 raeburn 2137: unless ($role eq 'login') {
2138: $datatable .= '<tr'.$css_class.'>'.
2139: '<td>'.$choices->{'fontmenu'}.'</td>';
2140: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2141: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2142: } else {
2143: $datatable .= '<td> </td>';
2144: }
1.202 raeburn 2145: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2146: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2147: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2148: '<input class="colorchooser" type="text" size="10" name="'
2149: .$role.'_fontmenu"'.
2150: ' value="'.$current_color.'" /> '.
1.329 raeburn 2151: ' </span></td></tr>';
1.97 tempelho 2152: }
1.9 raeburn 2153: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2154: foreach my $img (@{$images}) {
1.18 albertel 2155: $itemcount ++;
1.6 raeburn 2156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2157: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2158: '<td>'.$choices->{$img};
1.402 raeburn 2159: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2160: if ($role eq 'login') {
2161: if ($img eq 'login') {
2162: $login_hdr_pick =
1.135 bisitz 2163: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2164: $logincolors =
2165: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2166: $designs,$defaults);
1.402 raeburn 2167: } else {
2168: if ($img ne 'domlogo') {
2169: $datatable.= &logo_display_options($img,$defaults,$designs);
2170: }
2171: if (ref($designs->{'alttext'}) eq 'HASH') {
2172: $alttext = $designs->{'alttext'}{$img};
2173: }
1.70 raeburn 2174: }
2175: }
2176: $datatable .= '</td>';
1.6 raeburn 2177: if ($designs->{$img} ne '') {
2178: $imgfile = $designs->{$img};
1.18 albertel 2179: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2180: } else {
2181: $imgfile = $defaults->{$img};
2182: }
2183: if ($imgfile) {
1.9 raeburn 2184: my ($showfile,$fullsize);
2185: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2186: my $urldir = $1;
2187: my $filename = $2;
2188: my @info = &Apache::lonnet::stat_file($designs->{$img});
2189: if (@info) {
2190: my $thumbfile = 'tn-'.$filename;
2191: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2192: if (@thumb) {
2193: $showfile = $urldir.'/'.$thumbfile;
2194: } else {
2195: $showfile = $imgfile;
2196: }
2197: } else {
2198: $showfile = '';
2199: }
2200: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2201: $showfile = $imgfile;
1.6 raeburn 2202: my $imgdir = $1;
2203: my $filename = $2;
1.159 raeburn 2204: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2205: $showfile = "/$imgdir/tn-".$filename;
2206: } else {
1.159 raeburn 2207: my $input = $londocroot.$imgfile;
2208: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2209: if (!-e $output) {
1.9 raeburn 2210: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2211: my ($fullwidth,$fullheight) = &check_dimensions($input);
2212: if ($fullwidth ne '' && $fullheight ne '') {
2213: if ($fullwidth > $width && $fullheight > $height) {
2214: my $size = $width.'x'.$height;
1.316 raeburn 2215: my @args = ('convert','-sample',$size,$input,$output);
2216: system({$args[0]} @args);
1.159 raeburn 2217: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2218: }
2219: }
1.6 raeburn 2220: }
2221: }
1.16 raeburn 2222: }
1.6 raeburn 2223: if ($showfile) {
1.40 raeburn 2224: if ($showfile =~ m{^/(adm|res)/}) {
2225: if ($showfile =~ m{^/res/}) {
2226: my $local_showfile =
2227: &Apache::lonnet::filelocation('',$showfile);
2228: &Apache::lonnet::repcopy($local_showfile);
2229: }
2230: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2231: }
2232: if ($imgfile) {
2233: if ($imgfile =~ m{^/(adm|res)/}) {
2234: if ($imgfile =~ m{^/res/}) {
2235: my $local_imgfile =
2236: &Apache::lonnet::filelocation('',$imgfile);
2237: &Apache::lonnet::repcopy($local_imgfile);
2238: }
2239: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2240: } else {
2241: $fullsize = $imgfile;
2242: }
2243: }
1.41 raeburn 2244: $datatable .= '<td>';
2245: if ($img eq 'login') {
1.135 bisitz 2246: $datatable .= $login_hdr_pick;
2247: }
1.41 raeburn 2248: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2249: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2250: } else {
1.201 raeburn 2251: $datatable .= '<td> </td><td class="LC_left_item">'.
2252: &mt('Upload:').'<br />';
1.6 raeburn 2253: }
2254: } else {
1.201 raeburn 2255: $datatable .= '<td> </td><td class="LC_left_item">'.
2256: &mt('Upload:').'<br />';
1.6 raeburn 2257: }
1.9 raeburn 2258: if ($switchserver) {
2259: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2260: } else {
1.135 bisitz 2261: if ($img ne 'login') { # suppress file selection for Log-in header
2262: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2263: }
1.9 raeburn 2264: }
1.402 raeburn 2265: if (($role eq 'login') && ($img ne 'login')) {
2266: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2267: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2268: '</label></span>';
2269: }
1.9 raeburn 2270: $datatable .= '</td></tr>';
1.6 raeburn 2271: }
2272: $itemcount ++;
2273: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2274: $datatable .= '<tr'.$css_class.'>'.
2275: '<td>'.$choices->{'bgs'}.'</td>';
2276: my $bgs_def;
2277: foreach my $item (@{$bgs}) {
2278: if (!$is_custom->{$item}) {
1.329 raeburn 2279: $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 2280: }
2281: }
2282: if ($bgs_def) {
1.8 raeburn 2283: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2284: } else {
2285: $datatable .= '<td> </td>';
2286: }
2287: $datatable .= '<td class="LC_right_item">'.
2288: '<table border="0"><tr>';
1.174 foxr 2289:
1.6 raeburn 2290: foreach my $item (@{$bgs}) {
1.306 raeburn 2291: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2292: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2293: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2294: $datatable .= ' ';
1.6 raeburn 2295: }
1.174 foxr 2296: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2297: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2298: }
2299: $datatable .= '</tr></table></td></tr>';
2300: $itemcount ++;
2301: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2302: $datatable .= '<tr'.$css_class.'>'.
2303: '<td>'.$choices->{'links'}.'</td>';
2304: my $links_def;
2305: foreach my $item (@{$links}) {
2306: if (!$is_custom->{$item}) {
1.329 raeburn 2307: $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 2308: }
2309: }
2310: if ($links_def) {
1.8 raeburn 2311: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2312: } else {
2313: $datatable .= '<td> </td>';
2314: }
2315: $datatable .= '<td class="LC_right_item">'.
2316: '<table border="0"><tr>';
2317: foreach my $item (@{$links}) {
1.234 raeburn 2318: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2319: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2320: if ($designs->{'links'}{$item}) {
1.174 foxr 2321: $datatable.=' ';
1.6 raeburn 2322: }
1.174 foxr 2323: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2324: '" /></td>';
2325: }
1.30 raeburn 2326: $$rowtotal += $itemcount;
1.3 raeburn 2327: return $datatable;
2328: }
2329:
1.70 raeburn 2330: sub logo_display_options {
2331: my ($img,$defaults,$designs) = @_;
2332: my $checkedon;
2333: if (ref($defaults) eq 'HASH') {
2334: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2335: if ($defaults->{'showlogo'}{$img}) {
2336: $checkedon = 'checked="checked" ';
2337: }
2338: }
2339: }
2340: if (ref($designs) eq 'HASH') {
2341: if (ref($designs->{'showlogo'}) eq 'HASH') {
2342: if (defined($designs->{'showlogo'}{$img})) {
2343: if ($designs->{'showlogo'}{$img} == 0) {
2344: $checkedon = '';
2345: } elsif ($designs->{'showlogo'}{$img} == 1) {
2346: $checkedon = 'checked="checked" ';
2347: }
2348: }
2349: }
2350: }
2351: return '<br /><label> <input type="checkbox" name="'.
2352: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2353: &mt('show').'</label>'."\n";
2354: }
2355:
1.41 raeburn 2356: sub login_header_options {
1.135 bisitz 2357: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2358: my $output = '';
1.41 raeburn 2359: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2360: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2361: if (!$is_custom->{'textcol'}) {
2362: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2363: ' ';
2364: }
2365: if (!$is_custom->{'bgcol'}) {
2366: $output .= $choices->{'bgcol'}.': '.
2367: '<span id="css_'.$role.'_font" style="background-color: '.
2368: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2369: }
2370: $output .= '<br />';
2371: }
2372: $output .='<br />';
2373: return $output;
2374: }
2375:
2376: sub login_text_colors {
1.201 raeburn 2377: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2378: my $color_menu = '<table border="0"><tr>';
2379: foreach my $item (@{$logintext}) {
1.306 raeburn 2380: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2381: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2382: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2383: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2384: }
2385: $color_menu .= '</tr></table><br />';
2386: return $color_menu;
2387: }
2388:
2389: sub image_changes {
2390: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2391: my $output;
1.135 bisitz 2392: if ($img eq 'login') {
1.331 raeburn 2393: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2394: } elsif (!$is_custom) {
1.70 raeburn 2395: if ($img ne 'domlogo') {
1.331 raeburn 2396: $output = &mt('Default image:').'<br />';
1.41 raeburn 2397: } else {
1.331 raeburn 2398: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2399: }
2400: }
1.331 raeburn 2401: if ($img ne 'login') {
1.135 bisitz 2402: if ($img_import) {
2403: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2404: }
2405: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2406: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2407: if ($is_custom) {
2408: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2409: '<input type="checkbox" name="'.
2410: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2411: '</label> '.&mt('Replace:').'</span><br />';
2412: } else {
1.306 raeburn 2413: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2414: }
1.41 raeburn 2415: }
2416: return $output;
2417: }
2418:
1.3 raeburn 2419: sub print_quotas {
1.86 raeburn 2420: my ($dom,$settings,$rowtotal,$action) = @_;
2421: my $context;
2422: if ($action eq 'quotas') {
2423: $context = 'tools';
2424: } else {
2425: $context = $action;
2426: }
1.429 raeburn 2427: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2428: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2429: my $typecount = 0;
1.101 raeburn 2430: my ($css_class,%titles);
1.86 raeburn 2431: if ($context eq 'requestcourses') {
1.325 raeburn 2432: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2433: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2434: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2435: %titles = &courserequest_titles();
1.163 raeburn 2436: } elsif ($context eq 'requestauthor') {
2437: @usertools = ('author');
2438: @options = ('norequest','approval','automatic');
1.210 raeburn 2439: %titles = &authorrequest_titles();
1.86 raeburn 2440: } else {
1.430 raeburn 2441: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2442: %titles = &tool_titles();
1.86 raeburn 2443: }
1.26 raeburn 2444: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2445: foreach my $type (@{$types}) {
1.429 raeburn 2446: my $currdefquota;
1.163 raeburn 2447: unless (($context eq 'requestcourses') ||
2448: ($context eq 'requestauthor')) {
1.86 raeburn 2449: if (ref($settings) eq 'HASH') {
2450: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2451: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2452: } else {
2453: $currdefquota = $settings->{$type};
2454: }
1.78 raeburn 2455: }
1.72 raeburn 2456: }
1.3 raeburn 2457: if (defined($usertypes->{$type})) {
2458: $typecount ++;
2459: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2460: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2461: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2462: '<td class="LC_left_item">';
1.101 raeburn 2463: if ($context eq 'requestcourses') {
2464: $datatable .= '<table><tr>';
2465: }
2466: my %cell;
1.72 raeburn 2467: foreach my $item (@usertools) {
1.101 raeburn 2468: if ($context eq 'requestcourses') {
2469: my ($curroption,$currlimit);
2470: if (ref($settings) eq 'HASH') {
2471: if (ref($settings->{$item}) eq 'HASH') {
2472: $curroption = $settings->{$item}->{$type};
2473: if ($curroption =~ /^autolimit=(\d*)$/) {
2474: $currlimit = $1;
2475: }
2476: }
2477: }
2478: if (!$curroption) {
2479: $curroption = 'norequest';
2480: }
2481: $datatable .= '<th>'.$titles{$item}.'</th>';
2482: foreach my $option (@options) {
2483: my $val = $option;
2484: if ($option eq 'norequest') {
2485: $val = 0;
2486: }
2487: if ($option eq 'validate') {
2488: my $canvalidate = 0;
2489: if (ref($validations{$item}) eq 'HASH') {
2490: if ($validations{$item}{$type}) {
2491: $canvalidate = 1;
2492: }
2493: }
2494: next if (!$canvalidate);
2495: }
2496: my $checked = '';
2497: if ($option eq $curroption) {
2498: $checked = ' checked="checked"';
2499: } elsif ($option eq 'autolimit') {
2500: if ($curroption =~ /^autolimit/) {
2501: $checked = ' checked="checked"';
2502: }
2503: }
2504: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2505: '<input type="radio" name="crsreq_'.$item.
2506: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2507: $titles{$option}.'</label>';
1.101 raeburn 2508: if ($option eq 'autolimit') {
1.127 raeburn 2509: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2510: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2511: 'value="'.$currlimit.'" />';
1.101 raeburn 2512: }
1.127 raeburn 2513: $cell{$item} .= '</span> ';
1.103 raeburn 2514: if ($option eq 'autolimit') {
1.127 raeburn 2515: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2516: }
1.101 raeburn 2517: }
1.163 raeburn 2518: } elsif ($context eq 'requestauthor') {
2519: my $curroption;
2520: if (ref($settings) eq 'HASH') {
2521: $curroption = $settings->{$type};
2522: }
2523: if (!$curroption) {
2524: $curroption = 'norequest';
2525: }
2526: foreach my $option (@options) {
2527: my $val = $option;
2528: if ($option eq 'norequest') {
2529: $val = 0;
2530: }
2531: my $checked = '';
2532: if ($option eq $curroption) {
2533: $checked = ' checked="checked"';
2534: }
2535: $datatable .= '<span class="LC_nobreak"><label>'.
2536: '<input type="radio" name="authorreq_'.$type.
2537: '" value="'.$val.'"'.$checked.' />'.
2538: $titles{$option}.'</label></span> ';
2539: }
1.101 raeburn 2540: } else {
2541: my $checked = 'checked="checked" ';
1.413 raeburn 2542: if ($item eq 'timezone') {
2543: $checked = '';
2544: }
1.101 raeburn 2545: if (ref($settings) eq 'HASH') {
2546: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2547: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2548: $checked = '';
2549: } elsif ($settings->{$item}->{$type} == 1) {
2550: $checked = 'checked="checked" ';
2551: }
1.78 raeburn 2552: }
1.72 raeburn 2553: }
1.101 raeburn 2554: $datatable .= '<span class="LC_nobreak"><label>'.
2555: '<input type="checkbox" name="'.$context.'_'.$item.
2556: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2557: '</label></span> ';
1.72 raeburn 2558: }
1.101 raeburn 2559: }
2560: if ($context eq 'requestcourses') {
2561: $datatable .= '</tr><tr>';
2562: foreach my $item (@usertools) {
1.106 raeburn 2563: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2564: }
2565: $datatable .= '</tr></table>';
1.72 raeburn 2566: }
1.86 raeburn 2567: $datatable .= '</td>';
1.163 raeburn 2568: unless (($context eq 'requestcourses') ||
2569: ($context eq 'requestauthor')) {
1.86 raeburn 2570: $datatable .=
1.197 raeburn 2571: '<td class="LC_right_item">'.
1.429 raeburn 2572: '<span class="LC_nobreak">'.
1.3 raeburn 2573: '<input type="text" name="quota_'.$type.
1.72 raeburn 2574: '" value="'.$currdefquota.
1.197 raeburn 2575: '" size="5" /></span></td>';
1.86 raeburn 2576: }
2577: $datatable .= '</tr>';
1.3 raeburn 2578: }
2579: }
2580: }
1.163 raeburn 2581: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2582: $defaultquota = '20';
2583: if (ref($settings) eq 'HASH') {
2584: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2585: $defaultquota = $settings->{'defaultquota'}->{'default'};
2586: } elsif (defined($settings->{'default'})) {
2587: $defaultquota = $settings->{'default'};
2588: }
1.3 raeburn 2589: }
2590: }
2591: $typecount ++;
2592: $css_class = $typecount%2?' class="LC_odd_row"':'';
2593: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2594: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2595: '<td class="LC_left_item">';
1.101 raeburn 2596: if ($context eq 'requestcourses') {
2597: $datatable .= '<table><tr>';
2598: }
2599: my %defcell;
1.72 raeburn 2600: foreach my $item (@usertools) {
1.101 raeburn 2601: if ($context eq 'requestcourses') {
2602: my ($curroption,$currlimit);
2603: if (ref($settings) eq 'HASH') {
2604: if (ref($settings->{$item}) eq 'HASH') {
2605: $curroption = $settings->{$item}->{'default'};
2606: if ($curroption =~ /^autolimit=(\d*)$/) {
2607: $currlimit = $1;
2608: }
2609: }
2610: }
2611: if (!$curroption) {
2612: $curroption = 'norequest';
2613: }
2614: $datatable .= '<th>'.$titles{$item}.'</th>';
2615: foreach my $option (@options) {
2616: my $val = $option;
2617: if ($option eq 'norequest') {
2618: $val = 0;
2619: }
2620: if ($option eq 'validate') {
2621: my $canvalidate = 0;
2622: if (ref($validations{$item}) eq 'HASH') {
2623: if ($validations{$item}{'default'}) {
2624: $canvalidate = 1;
2625: }
2626: }
2627: next if (!$canvalidate);
2628: }
2629: my $checked = '';
2630: if ($option eq $curroption) {
2631: $checked = ' checked="checked"';
2632: } elsif ($option eq 'autolimit') {
2633: if ($curroption =~ /^autolimit/) {
2634: $checked = ' checked="checked"';
2635: }
2636: }
2637: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2638: '<input type="radio" name="crsreq_'.$item.
2639: '_default" value="'.$val.'"'.$checked.' />'.
2640: $titles{$option}.'</label>';
2641: if ($option eq 'autolimit') {
1.127 raeburn 2642: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2643: $item.'_limit_default" size="1" '.
2644: 'value="'.$currlimit.'" />';
2645: }
1.127 raeburn 2646: $defcell{$item} .= '</span> ';
1.104 raeburn 2647: if ($option eq 'autolimit') {
1.127 raeburn 2648: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2649: }
1.101 raeburn 2650: }
1.163 raeburn 2651: } elsif ($context eq 'requestauthor') {
2652: my $curroption;
2653: if (ref($settings) eq 'HASH') {
1.172 raeburn 2654: $curroption = $settings->{'default'};
1.163 raeburn 2655: }
2656: if (!$curroption) {
2657: $curroption = 'norequest';
2658: }
2659: foreach my $option (@options) {
2660: my $val = $option;
2661: if ($option eq 'norequest') {
2662: $val = 0;
2663: }
2664: my $checked = '';
2665: if ($option eq $curroption) {
2666: $checked = ' checked="checked"';
2667: }
2668: $datatable .= '<span class="LC_nobreak"><label>'.
2669: '<input type="radio" name="authorreq_default"'.
2670: ' value="'.$val.'"'.$checked.' />'.
2671: $titles{$option}.'</label></span> ';
2672: }
1.101 raeburn 2673: } else {
2674: my $checked = 'checked="checked" ';
2675: if (ref($settings) eq 'HASH') {
2676: if (ref($settings->{$item}) eq 'HASH') {
2677: if ($settings->{$item}->{'default'} == 0) {
2678: $checked = '';
2679: } elsif ($settings->{$item}->{'default'} == 1) {
2680: $checked = 'checked="checked" ';
2681: }
1.78 raeburn 2682: }
1.72 raeburn 2683: }
1.101 raeburn 2684: $datatable .= '<span class="LC_nobreak"><label>'.
2685: '<input type="checkbox" name="'.$context.'_'.$item.
2686: '" value="default" '.$checked.'/>'.$titles{$item}.
2687: '</label></span> ';
2688: }
2689: }
2690: if ($context eq 'requestcourses') {
2691: $datatable .= '</tr><tr>';
2692: foreach my $item (@usertools) {
1.106 raeburn 2693: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2694: }
1.101 raeburn 2695: $datatable .= '</tr></table>';
1.72 raeburn 2696: }
1.86 raeburn 2697: $datatable .= '</td>';
1.163 raeburn 2698: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2699: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2700: '<span class="LC_nobreak">'.
1.86 raeburn 2701: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2702: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2703: }
2704: $datatable .= '</tr>';
1.72 raeburn 2705: $typecount ++;
2706: $css_class = $typecount%2?' class="LC_odd_row"':'';
2707: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2708: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2709: if ($context eq 'requestcourses') {
1.109 raeburn 2710: $datatable .= &mt('(overrides affiliation, if set)').
2711: '</td>'.
2712: '<td class="LC_left_item">'.
2713: '<table><tr>';
1.101 raeburn 2714: } else {
1.109 raeburn 2715: $datatable .= &mt('(overrides affiliation, if checked)').
2716: '</td>'.
2717: '<td class="LC_left_item" colspan="2">'.
2718: '<br />';
1.101 raeburn 2719: }
2720: my %advcell;
1.72 raeburn 2721: foreach my $item (@usertools) {
1.101 raeburn 2722: if ($context eq 'requestcourses') {
2723: my ($curroption,$currlimit);
2724: if (ref($settings) eq 'HASH') {
2725: if (ref($settings->{$item}) eq 'HASH') {
2726: $curroption = $settings->{$item}->{'_LC_adv'};
2727: if ($curroption =~ /^autolimit=(\d*)$/) {
2728: $currlimit = $1;
2729: }
2730: }
2731: }
2732: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2733: my $checked = '';
2734: if ($curroption eq '') {
2735: $checked = ' checked="checked"';
2736: }
2737: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2738: '<input type="radio" name="crsreq_'.$item.
2739: '__LC_adv" value=""'.$checked.' />'.
2740: &mt('No override set').'</label></span> ';
1.101 raeburn 2741: foreach my $option (@options) {
2742: my $val = $option;
2743: if ($option eq 'norequest') {
2744: $val = 0;
2745: }
2746: if ($option eq 'validate') {
2747: my $canvalidate = 0;
2748: if (ref($validations{$item}) eq 'HASH') {
2749: if ($validations{$item}{'_LC_adv'}) {
2750: $canvalidate = 1;
2751: }
2752: }
2753: next if (!$canvalidate);
2754: }
2755: my $checked = '';
1.104 raeburn 2756: if ($val eq $curroption) {
1.101 raeburn 2757: $checked = ' checked="checked"';
2758: } elsif ($option eq 'autolimit') {
2759: if ($curroption =~ /^autolimit/) {
2760: $checked = ' checked="checked"';
2761: }
2762: }
2763: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2764: '<input type="radio" name="crsreq_'.$item.
2765: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2766: $titles{$option}.'</label>';
2767: if ($option eq 'autolimit') {
1.127 raeburn 2768: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2769: $item.'_limit__LC_adv" size="1" '.
2770: 'value="'.$currlimit.'" />';
2771: }
1.127 raeburn 2772: $advcell{$item} .= '</span> ';
1.104 raeburn 2773: if ($option eq 'autolimit') {
1.127 raeburn 2774: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2775: }
1.101 raeburn 2776: }
1.163 raeburn 2777: } elsif ($context eq 'requestauthor') {
2778: my $curroption;
2779: if (ref($settings) eq 'HASH') {
2780: $curroption = $settings->{'_LC_adv'};
2781: }
2782: my $checked = '';
2783: if ($curroption eq '') {
2784: $checked = ' checked="checked"';
2785: }
2786: $datatable .= '<span class="LC_nobreak"><label>'.
2787: '<input type="radio" name="authorreq__LC_adv"'.
2788: ' value=""'.$checked.' />'.
2789: &mt('No override set').'</label></span> ';
2790: foreach my $option (@options) {
2791: my $val = $option;
2792: if ($option eq 'norequest') {
2793: $val = 0;
2794: }
2795: my $checked = '';
2796: if ($val eq $curroption) {
2797: $checked = ' checked="checked"';
2798: }
2799: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2800: '<input type="radio" name="authorreq__LC_adv"'.
2801: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2802: $titles{$option}.'</label></span> ';
2803: }
1.101 raeburn 2804: } else {
2805: my $checked = 'checked="checked" ';
2806: if (ref($settings) eq 'HASH') {
2807: if (ref($settings->{$item}) eq 'HASH') {
2808: if ($settings->{$item}->{'_LC_adv'} == 0) {
2809: $checked = '';
2810: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2811: $checked = 'checked="checked" ';
2812: }
1.79 raeburn 2813: }
1.72 raeburn 2814: }
1.101 raeburn 2815: $datatable .= '<span class="LC_nobreak"><label>'.
2816: '<input type="checkbox" name="'.$context.'_'.$item.
2817: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2818: '</label></span> ';
2819: }
2820: }
2821: if ($context eq 'requestcourses') {
2822: $datatable .= '</tr><tr>';
2823: foreach my $item (@usertools) {
1.106 raeburn 2824: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2825: }
1.101 raeburn 2826: $datatable .= '</tr></table>';
1.72 raeburn 2827: }
1.98 raeburn 2828: $datatable .= '</td></tr>';
1.30 raeburn 2829: $$rowtotal += $typecount;
1.3 raeburn 2830: return $datatable;
2831: }
2832:
1.163 raeburn 2833: sub print_requestmail {
1.305 raeburn 2834: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2835: my ($now,$datatable,%currapp);
1.102 raeburn 2836: $now = time;
2837: if (ref($settings) eq 'HASH') {
2838: if (ref($settings->{'notify'}) eq 'HASH') {
2839: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2840: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2841: }
2842: }
2843: }
1.191 raeburn 2844: my $numinrow = 2;
1.224 raeburn 2845: my $css_class;
1.305 raeburn 2846: if ($$rowtotal%2) {
2847: $css_class = 'LC_odd_row';
2848: }
2849: if ($customcss) {
2850: $css_class .= " $customcss";
2851: }
2852: $css_class =~ s/^\s+//;
2853: if ($css_class) {
2854: $css_class = ' class="'.$css_class.'"';
2855: }
2856: if ($rowstyle) {
2857: $css_class .= ' style="'.$rowstyle.'"';
2858: }
1.163 raeburn 2859: my $text;
2860: if ($action eq 'requestcourses') {
2861: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2862: } elsif ($action eq 'requestauthor') {
2863: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2864: } else {
1.224 raeburn 2865: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2866: }
1.224 raeburn 2867: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2868: ' <td>'.$text.'</td>'.
1.102 raeburn 2869: ' <td class="LC_left_item">';
1.191 raeburn 2870: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2871: $action.'notifyapproval',%currapp);
1.191 raeburn 2872: if ($numdc > 0) {
2873: $datatable .= $table;
1.102 raeburn 2874: } else {
2875: $datatable .= &mt('There are no active Domain Coordinators');
2876: }
2877: $datatable .='</td></tr>';
2878: return $datatable;
2879: }
2880:
1.216 raeburn 2881: sub print_studentcode {
2882: my ($settings,$rowtotal) = @_;
2883: my $rownum = 0;
1.218 raeburn 2884: my ($output,%current);
1.325 raeburn 2885: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2886: if (ref($settings) eq 'HASH') {
2887: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2888: foreach my $type (@crstypes) {
2889: $current{$type} = $settings->{'uniquecode'}{$type};
2890: }
1.218 raeburn 2891: }
2892: }
2893: $output .= '<tr>'.
2894: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2895: '<td class="LC_left_item">';
2896: foreach my $type (@crstypes) {
2897: my $check = ' ';
2898: if ($current{$type}) {
2899: $check = ' checked="checked" ';
2900: }
2901: $output .= '<span class="LC_nobreak"><label>'.
2902: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2903: &mt($type).'</label></span>'.(' 'x2).' ';
2904: }
2905: $output .= '</td></tr>';
2906: $$rowtotal ++;
2907: return $output;
1.216 raeburn 2908: }
2909:
2910: sub print_textbookcourses {
1.242 raeburn 2911: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2912: my $rownum = 0;
2913: my $css_class;
2914: my $itemcount = 1;
2915: my $maxnum = 0;
2916: my $bookshash;
2917: if (ref($settings) eq 'HASH') {
1.242 raeburn 2918: $bookshash = $settings->{$type};
1.216 raeburn 2919: }
2920: my %ordered;
2921: if (ref($bookshash) eq 'HASH') {
2922: foreach my $item (keys(%{$bookshash})) {
2923: if (ref($bookshash->{$item}) eq 'HASH') {
2924: my $num = $bookshash->{$item}{'order'};
2925: $ordered{$num} = $item;
2926: }
2927: }
2928: }
2929: my $confname = $dom.'-domainconfig';
2930: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2931: my $maxnum = scalar(keys(%ordered));
2932: my $datatable;
1.216 raeburn 2933: if (keys(%ordered)) {
2934: my @items = sort { $a <=> $b } keys(%ordered);
2935: for (my $i=0; $i<@items; $i++) {
2936: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2937: my $key = $ordered{$items[$i]};
2938: my %coursehash=&Apache::lonnet::coursedescription($key);
2939: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2940: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2941: if (ref($bookshash->{$key}) eq 'HASH') {
2942: $subject = $bookshash->{$key}->{'subject'};
2943: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2944: if ($type eq 'textbooks') {
1.243 raeburn 2945: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2946: $author = $bookshash->{$key}->{'author'};
2947: $image = $bookshash->{$key}->{'image'};
2948: if ($image ne '') {
2949: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2950: my $imagethumb = "$path/tn-".$imagefile;
2951: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2952: }
1.216 raeburn 2953: }
2954: }
1.242 raeburn 2955: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2956: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2957: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2958: for (my $k=0; $k<=$maxnum; $k++) {
2959: my $vpos = $k+1;
2960: my $selstr;
2961: if ($k == $i) {
2962: $selstr = ' selected="selected" ';
2963: }
2964: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2965: }
2966: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2967: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2968: &mt('Delete?').'</label></span></td>'.
2969: '<td colspan="2">'.
1.242 raeburn 2970: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2971: (' 'x2).
1.242 raeburn 2972: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2973: if ($type eq 'textbooks') {
2974: $datatable .= (' 'x2).
1.243 raeburn 2975: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2976: (' 'x2).
1.242 raeburn 2977: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2978: (' 'x2).
2979: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2980: if ($image) {
1.267 raeburn 2981: $datatable .= $imgsrc.
1.242 raeburn 2982: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2983: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2984: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2985: }
2986: if ($switchserver) {
2987: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2988: } else {
2989: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2990: }
1.216 raeburn 2991: }
1.242 raeburn 2992: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2993: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2994: $coursetitle.'</span></td></tr>'."\n";
2995: $itemcount ++;
2996: }
2997: }
2998: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 2999: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3000: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3001: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3002: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3003: for (my $k=0; $k<$maxnum+1; $k++) {
3004: my $vpos = $k+1;
3005: my $selstr;
3006: if ($k == $maxnum) {
3007: $selstr = ' selected="selected" ';
3008: }
3009: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3010: }
3011: $datatable .= '</select> '."\n".
1.334 raeburn 3012: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3013: '<td colspan="2">'.
1.242 raeburn 3014: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3015: (' 'x2).
1.242 raeburn 3016: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3017: (' 'x2);
3018: if ($type eq 'textbooks') {
1.243 raeburn 3019: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3020: (' 'x2).
3021: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3022: (' 'x2).
3023: '<span class="LC_nobreak">'.&mt('Image:').' ';
3024: if ($switchserver) {
3025: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3026: } else {
3027: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3028: }
1.334 raeburn 3029: $datatable .= '</span>'."\n";
1.216 raeburn 3030: }
1.334 raeburn 3031: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3032: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3033: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3034: &Apache::loncommon::selectcourse_link
1.334 raeburn 3035: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3036: '</span></td>'."\n".
3037: '</tr>'."\n";
3038: $itemcount ++;
3039: return $datatable;
3040: }
3041:
1.217 raeburn 3042: sub textbookcourses_javascript {
1.242 raeburn 3043: my ($settings) = @_;
3044: return unless(ref($settings) eq 'HASH');
3045: my (%ordered,%total,%jstext);
3046: foreach my $type ('textbooks','templates') {
3047: $total{$type} = 0;
3048: if (ref($settings->{$type}) eq 'HASH') {
3049: foreach my $item (keys(%{$settings->{$type}})) {
3050: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3051: my $num = $settings->{$type}->{$item}{'order'};
3052: $ordered{$type}{$num} = $item;
3053: }
3054: }
3055: $total{$type} = scalar(keys(%{$settings->{$type}}));
3056: }
3057: my @jsarray = ();
3058: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3059: push(@jsarray,$ordered{$type}{$item});
3060: }
3061: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3062: }
3063: return <<"ENDSCRIPT";
3064: <script type="text/javascript">
3065: // <![CDATA[
1.242 raeburn 3066: function reorderBooks(form,item,caller) {
1.217 raeburn 3067: var changedVal;
1.242 raeburn 3068: $jstext{'textbooks'};
3069: $jstext{'templates'};
3070: var newpos;
3071: var maxh;
3072: if (caller == 'textbooks') {
3073: newpos = 'textbooks_addbook_pos';
3074: maxh = 1 + $total{'textbooks'};
3075: } else {
3076: newpos = 'templates_addbook_pos';
3077: maxh = 1 + $total{'templates'};
3078: }
1.217 raeburn 3079: var current = new Array;
3080: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3081: if (item == newpos) {
3082: changedVal = newitemVal;
3083: } else {
3084: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3085: current[newitemVal] = newpos;
3086: }
1.242 raeburn 3087: if (caller == 'textbooks') {
3088: for (var i=0; i<textbooks.length; i++) {
3089: var elementName = 'textbooks_'+textbooks[i];
3090: if (elementName != item) {
3091: if (form.elements[elementName]) {
3092: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3093: current[currVal] = elementName;
3094: }
3095: }
3096: }
3097: }
3098: if (caller == 'templates') {
3099: for (var i=0; i<templates.length; i++) {
3100: var elementName = 'templates_'+templates[i];
3101: if (elementName != item) {
3102: if (form.elements[elementName]) {
3103: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3104: current[currVal] = elementName;
3105: }
1.217 raeburn 3106: }
3107: }
3108: }
3109: var oldVal;
3110: for (var j=0; j<maxh; j++) {
3111: if (current[j] == undefined) {
3112: oldVal = j;
3113: }
3114: }
3115: if (oldVal < changedVal) {
3116: for (var k=oldVal+1; k<=changedVal ; k++) {
3117: var elementName = current[k];
3118: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3119: }
3120: } else {
3121: for (var k=changedVal; k<oldVal; k++) {
3122: var elementName = current[k];
3123: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3124: }
3125: }
3126: return;
3127: }
3128:
3129: // ]]>
3130: </script>
3131:
3132: ENDSCRIPT
3133: }
3134:
1.267 raeburn 3135: sub ltitools_javascript {
3136: my ($settings) = @_;
1.319 raeburn 3137: my $togglejs = <itools_toggle_js();
3138: unless (ref($settings) eq 'HASH') {
3139: return $togglejs;
3140: }
1.267 raeburn 3141: my (%ordered,$total,%jstext);
3142: $total = 0;
3143: foreach my $item (keys(%{$settings})) {
3144: if (ref($settings->{$item}) eq 'HASH') {
3145: my $num = $settings->{$item}{'order'};
3146: $ordered{$num} = $item;
3147: }
3148: }
3149: $total = scalar(keys(%{$settings}));
3150: my @jsarray = ();
3151: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3152: push(@jsarray,$ordered{$item});
3153: }
3154: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3155: return <<"ENDSCRIPT";
3156: <script type="text/javascript">
3157: // <![CDATA[
1.319 raeburn 3158: function reorderLTITools(form,item) {
1.267 raeburn 3159: var changedVal;
3160: $jstext
3161: var newpos = 'ltitools_add_pos';
3162: var maxh = 1 + $total;
3163: var current = new Array;
3164: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3165: if (item == newpos) {
3166: changedVal = newitemVal;
3167: } else {
3168: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3169: current[newitemVal] = newpos;
3170: }
3171: for (var i=0; i<ltitools.length; i++) {
3172: var elementName = 'ltitools_'+ltitools[i];
3173: if (elementName != item) {
3174: if (form.elements[elementName]) {
3175: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3176: current[currVal] = elementName;
3177: }
3178: }
3179: }
3180: var oldVal;
3181: for (var j=0; j<maxh; j++) {
3182: if (current[j] == undefined) {
3183: oldVal = j;
3184: }
3185: }
3186: if (oldVal < changedVal) {
3187: for (var k=oldVal+1; k<=changedVal ; k++) {
3188: var elementName = current[k];
3189: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3190: }
3191: } else {
3192: for (var k=changedVal; k<oldVal; k++) {
3193: var elementName = current[k];
3194: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3195: }
3196: }
3197: return;
3198: }
3199:
3200: // ]]>
3201: </script>
3202:
1.319 raeburn 3203: $togglejs
3204:
3205: ENDSCRIPT
3206: }
3207:
3208: sub ltitools_toggle_js {
3209: return <<"ENDSCRIPT";
3210: <script type="text/javascript">
3211: // <![CDATA[
3212:
3213: function toggleLTITools(form,setting,item) {
3214: var radioname = '';
3215: var divid = '';
3216: if ((setting == 'passback') || (setting == 'roster')) {
3217: radioname = 'ltitools_'+setting+'_'+item;
3218: divid = 'ltitools_'+setting+'time_'+item;
3219: var num = form.elements[radioname].length;
3220: if (num) {
3221: var setvis = '';
3222: for (var i=0; i<num; i++) {
3223: if (form.elements[radioname][i].checked) {
3224: if (form.elements[radioname][i].value == '1') {
3225: if (document.getElementById(divid)) {
3226: document.getElementById(divid).style.display = 'inline-block';
3227: }
3228: setvis = 1;
3229: }
3230: break;
3231: }
3232: }
3233: }
3234: if (!setvis) {
3235: if (document.getElementById(divid)) {
3236: document.getElementById(divid).style.display = 'none';
3237: }
3238: }
3239: }
1.324 raeburn 3240: if (setting == 'user') {
3241: divid = 'ltitools_'+setting+'_div_'+item;
3242: var checkid = 'ltitools_'+setting+'_field_'+item;
3243: if (document.getElementById(divid)) {
3244: if (document.getElementById(checkid)) {
3245: if (document.getElementById(checkid).checked) {
3246: document.getElementById(divid).style.display = 'inline-block';
3247: } else {
3248: document.getElementById(divid).style.display = 'none';
3249: }
3250: }
3251: }
3252: }
1.319 raeburn 3253: return;
3254: }
3255: // ]]>
3256: </script>
3257:
1.267 raeburn 3258: ENDSCRIPT
3259: }
3260:
1.381 raeburn 3261: sub wafproxy_javascript {
3262: my ($dom) = @_;
3263: return <<"ENDSCRIPT";
3264: <script type="text/javascript">
3265: // <![CDATA[
3266: function updateWAF() {
3267: if (document.getElementById('wafproxy_remoteip')) {
3268: var wafremote = 0;
3269: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3270: wafremote = 1;
3271: }
3272: var fields = new Array('header','trust');
3273: for (var i=0; i<fields.length; i++) {
3274: if (document.getElementById('wafproxy_'+fields[i])) {
3275: if (wafremote == 1) {
3276: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3277: }
3278: else {
3279: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3280: }
3281: }
3282: }
3283: if (document.getElementById('wafproxyranges_$dom')) {
3284: if (wafremote == 1) {
3285: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3286: } else {
3287: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3288: if (document.display.wafproxy_vpnaccess[i].checked) {
3289: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3290: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3291: }
3292: }
3293: }
3294: }
3295: }
3296: }
3297: return;
3298: }
3299:
3300: function checkWAF() {
3301: if (document.getElementById('wafproxy_remoteip')) {
3302: var wafvpn = 0;
3303: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3304: if (document.display.wafproxy_vpnaccess[i].checked) {
3305: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3306: wafvpn = 1;
3307: }
3308: break;
3309: }
3310: }
3311: var vpn = new Array('vpnint','vpnext');
3312: for (var i=0; i<vpn.length; i++) {
3313: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3314: if (wafvpn == 1) {
3315: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3316: }
3317: else {
3318: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3319: }
3320: }
3321: }
3322: if (document.getElementById('wafproxyranges_$dom')) {
3323: if (wafvpn == 1) {
3324: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3325: }
3326: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3327: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3328: }
3329: }
3330: }
3331: return;
3332: }
3333:
3334: function toggleWAF() {
3335: if (document.getElementById('wafproxy_table')) {
3336: var wafproxy = 0;
3337: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3338: if (document.display.wafproxy_${dom}[i].checked) {
3339: if (document.display.wafproxy_${dom}[i].value == 1) {
3340: wafproxy = 1;
3341: break;
3342: }
3343: }
3344: }
3345: if (wafproxy == 1) {
3346: document.getElementById('wafproxy_table').style.display='inline';
3347: }
3348: else {
3349: document.getElementById('wafproxy_table').style.display='none';
3350: }
3351: if (document.getElementById('wafproxyrow_${dom}')) {
3352: if (wafproxy == 1) {
3353: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3354: }
3355: else {
3356: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3357: }
3358: }
3359: if (document.getElementById('nowafproxyrow_$dom')) {
3360: if (wafproxy == 1) {
3361: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3362: }
3363: else {
3364: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3365: }
3366: }
3367: }
3368: return;
3369: }
3370: // ]]>
3371: </script>
3372:
3373: ENDSCRIPT
3374: }
3375:
1.372 raeburn 3376: sub proctoring_javascript {
3377: my ($settings) = @_;
3378: my (%ordered,$total,%jstext);
3379: $total = 0;
3380: if (ref($settings) eq 'HASH') {
3381: foreach my $item (keys(%{$settings})) {
3382: if (ref($settings->{$item}) eq 'HASH') {
3383: my $num = $settings->{$item}{'order'};
3384: $ordered{$num} = $item;
3385: }
3386: }
3387: $total = scalar(keys(%{$settings}));
3388: } else {
3389: %ordered = (
3390: 0 => 'proctorio',
3391: 1 => 'examity',
3392: );
3393: $total = 2;
3394: }
3395: my @jsarray = ();
3396: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3397: push(@jsarray,$ordered{$item});
3398: }
3399: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3400: return <<"ENDSCRIPT";
3401: <script type="text/javascript">
3402: // <![CDATA[
3403: function reorderProctoring(form,item) {
3404: var changedVal;
3405: $jstext
3406: var maxh = $total;
3407: var current = new Array;
3408: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3409: for (var i=0; i<proctors.length; i++) {
3410: var elementName = 'proctoring_pos_'+proctors[i];
3411: if (elementName != item) {
3412: if (form.elements[elementName]) {
3413: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3414: current[currVal] = elementName;
3415: }
3416: }
3417: }
3418: var oldVal;
3419: for (var j=0; j<maxh; j++) {
3420: if (current[j] == undefined) {
3421: oldVal = j;
3422: }
3423: }
3424: if (oldVal < changedVal) {
3425: for (var k=oldVal+1; k<=changedVal ; k++) {
3426: var elementName = current[k];
3427: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3428: }
3429: } else {
3430: for (var k=changedVal; k<oldVal; k++) {
3431: var elementName = current[k];
3432: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3433: }
3434: }
3435: return;
3436: }
3437:
3438: function toggleProctoring(form,item) {
3439: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3440: if (fieldsets.length) {
3441: var radioname = 'proctoring_available_'+item;
3442: var num = form.elements[radioname].length;
3443: if (num) {
3444: var setvis = '';
3445: for (var i=0; i<num; i++) {
3446: if (form.elements[radioname][i].checked) {
3447: if (form.elements[radioname][i].value == '1') {
3448: setvis = 1;
3449: break;
3450: }
3451: }
3452: }
3453: for (var j=0; j<fieldsets.length; j++) {
3454: if (setvis) {
3455: fieldsets[j].style.display = 'block';
3456: } else {
3457: fieldsets[j].style.display = 'none';
3458: }
3459: }
3460: }
3461: }
3462: return;
3463: }
3464:
3465: // ]]>
3466: </script>
3467:
3468: ENDSCRIPT
3469: }
3470:
3471:
1.320 raeburn 3472: sub lti_javascript {
1.405 raeburn 3473: my ($dom,$settings) = @_;
3474: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3475: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3476: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3477: return $togglejs.'
3478: <script type="text/javascript">
3479: // <![CDATA[
3480:
3481: '.$linkprot_js.'
3482:
3483: // ]]>
3484: </script>
3485: ';
1.320 raeburn 3486: }
3487: my (%ordered,$total,%jstext);
1.390 raeburn 3488: $total = scalar(keys(%{$settings}));
1.320 raeburn 3489: foreach my $item (keys(%{$settings})) {
3490: if (ref($settings->{$item}) eq 'HASH') {
3491: my $num = $settings->{$item}{'order'};
1.390 raeburn 3492: if ($num eq '') {
3493: $num = $total - 1;
3494: }
1.320 raeburn 3495: $ordered{$num} = $item;
3496: }
3497: }
3498: my @jsarray = ();
3499: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3500: push(@jsarray,$ordered{$item});
3501: }
3502: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3503: return <<"ENDSCRIPT";
3504: <script type="text/javascript">
3505: // <![CDATA[
3506: function reorderLTI(form,item) {
3507: var changedVal;
3508: $jstext
3509: var newpos = 'lti_pos_add';
3510: var maxh = 1 + $total;
3511: var current = new Array;
3512: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3513: if (item == newpos) {
3514: changedVal = newitemVal;
3515: } else {
3516: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3517: current[newitemVal] = newpos;
3518: }
3519: for (var i=0; i<lti.length; i++) {
3520: var elementName = 'lti_pos_'+lti[i];
3521: if (elementName != item) {
3522: if (form.elements[elementName]) {
3523: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3524: current[currVal] = elementName;
3525: }
3526: }
3527: }
3528: var oldVal;
3529: for (var j=0; j<maxh; j++) {
3530: if (current[j] == undefined) {
3531: oldVal = j;
3532: }
3533: }
3534: if (oldVal < changedVal) {
3535: for (var k=oldVal+1; k<=changedVal ; k++) {
3536: var elementName = current[k];
3537: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3538: }
3539: } else {
3540: for (var k=changedVal; k<oldVal; k++) {
3541: var elementName = current[k];
3542: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3543: }
3544: }
3545: return;
3546: }
1.406 raeburn 3547:
3548: $linkprot_js
3549:
1.320 raeburn 3550: // ]]>
3551: </script>
3552:
3553: $togglejs
3554:
3555: ENDSCRIPT
3556: }
3557:
3558: sub lti_toggle_js {
1.405 raeburn 3559: my ($dom) = @_;
1.325 raeburn 3560: my %lcauthparmtext = &Apache::lonlocal::texthash (
3561: localauth => 'Local auth argument',
3562: krb => 'Kerberos domain',
3563: );
1.391 raeburn 3564: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3565: &js_escape(\$crsincalert);
1.405 raeburn 3566: my %servers = &Apache::lonnet::get_servers($dom,'library');
3567: my $primary = &Apache::lonnet::domain($dom,'primary');
3568: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3569: return <<"ENDSCRIPT";
3570: <script type="text/javascript">
3571: // <![CDATA[
3572:
3573: function toggleLTI(form,setting,item) {
1.391 raeburn 3574: if ((setting == 'requser') || (setting == 'crsinc')) {
3575: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3576: var setvis = '';
3577: var radioname = 'lti_requser_'+item;
3578: var num = form.elements[radioname].length;
3579: if (num) {
3580: for (var i=0; i<num; i++) {
3581: if (form.elements[radioname][i].checked) {
3582: if (form.elements[radioname][i].value == '1') {
3583: setvis = 1;
3584: break;
3585: }
3586: }
3587: }
3588: }
3589: if (usrfieldsets.length) {
3590: for (var j=0; j<usrfieldsets.length; j++) {
3591: if (setvis) {
3592: usrfieldsets[j].style.display = 'block';
3593: } else {
3594: usrfieldsets[j].style.display = 'none';
3595: }
3596: }
3597: }
3598: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3599: if (crsfieldsets.length) {
3600: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3601: var num = form.elements[radioname].length;
3602: if (num) {
1.391 raeburn 3603: var crsvis = '';
1.345 raeburn 3604: for (var i=0; i<num; i++) {
3605: if (form.elements[radioname][i].checked) {
3606: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3607: if (setvis == '') {
3608: if (setting == 'crsinc'){
3609: alert("$crsincalert");
3610: form.elements[radioname][0].checked = true;
3611: }
3612: } else {
3613: crsvis = 1;
3614: }
3615: break;
1.345 raeburn 3616: }
3617: }
3618: }
1.391 raeburn 3619: setvis = crsvis;
3620: }
3621: for (var j=0; j<crsfieldsets.length; j++) {
3622: if (setvis) {
3623: crsfieldsets[j].style.display = 'block';
3624: } else {
3625: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3626: }
3627: }
3628: }
1.363 raeburn 3629: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3630: var radioname = '';
3631: var divid = '';
3632: if (setting == 'user') {
3633: radioname = 'lti_mapuser_'+item;
3634: divid = 'lti_userfield_'+item;
1.343 raeburn 3635: } else if (setting == 'crs') {
1.320 raeburn 3636: radioname = 'lti_mapcrs_'+item;
3637: divid = 'lti_crsfield_'+item;
1.363 raeburn 3638: } else if (setting == 'callback') {
3639: radioname = 'lti_callback_'+item;
3640: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3641: } else {
1.351 raeburn 3642: radioname = 'lti_passback_'+item;
1.337 raeburn 3643: divid = 'lti_passback_'+item;
1.320 raeburn 3644: }
3645: var num = form.elements[radioname].length;
3646: if (num) {
3647: var setvis = '';
3648: for (var i=0; i<num; i++) {
3649: if (form.elements[radioname][i].checked) {
1.363 raeburn 3650: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3651: if (form.elements[radioname][i].value == '1') {
3652: if (document.getElementById(divid)) {
3653: document.getElementById(divid).style.display = 'inline-block';
3654: }
3655: setvis = 1;
3656: break;
3657: }
3658: } else {
3659: if (form.elements[radioname][i].value == 'other') {
3660: if (document.getElementById(divid)) {
3661: document.getElementById(divid).style.display = 'inline-block';
3662: }
3663: setvis = 1;
3664: break;
1.320 raeburn 3665: }
3666: }
1.425 raeburn 3667: }
1.320 raeburn 3668: }
3669: if (!setvis) {
3670: if (document.getElementById(divid)) {
3671: document.getElementById(divid).style.display = 'none';
3672: }
3673: }
3674: }
3675: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3676: var numsec = form.elements['lti_crssec_'+item].length;
3677: if (numsec) {
3678: var setvis = '';
3679: for (var i=0; i<numsec; i++) {
3680: if (form.elements['lti_crssec_'+item][i].checked) {
3681: if (form.elements['lti_crssec_'+item][i].value == '1') {
3682: if (document.getElementById('lti_crssecfield_'+item)) {
3683: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3684: setvis = 1;
3685: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3686: if (numsrcsec) {
3687: var setsrcvis = '';
3688: for (var j=0; j<numsrcsec; j++) {
3689: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3690: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3691: if (document.getElementById('lti_secsrcfield_'+item)) {
3692: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3693: setsrcvis = 1;
3694: }
3695: }
3696: }
3697: }
3698: if (!setsrcvis) {
3699: if (document.getElementById('lti_secsrcfield_'+item)) {
3700: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3701: }
3702: }
3703: }
3704: }
3705: }
3706: }
3707: }
3708: if (!setvis) {
3709: if (document.getElementById('lti_crssecfield_'+item)) {
3710: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3711: }
3712: if (document.getElementById('lti_secsrcfield_'+item)) {
3713: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3714: }
3715: }
3716: }
1.325 raeburn 3717: } else if (setting == 'lcauth') {
3718: var numauth = form.elements['lti_lcauth_'+item].length;
3719: if (numauth) {
3720: for (var i=0; i<numauth; i++) {
3721: if (form.elements['lti_lcauth_'+item][i].checked) {
3722: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3723: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3724: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3725: } else {
3726: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3727: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3728: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3729: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3730: } else {
3731: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3732: }
3733: }
3734: }
3735: }
3736: }
3737: }
3738: }
1.326 raeburn 3739: } else if (setting == 'lcmenu') {
3740: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3741: var divid = 'lti_menufield_'+item;
3742: var setvis = '';
3743: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3744: var radioname = menus[i];
1.326 raeburn 3745: var num = form.elements[radioname].length;
3746: if (num) {
3747: for (var j=0; j<num; j++) {
3748: if (form.elements[radioname][j].checked) {
3749: if (form.elements[radioname][j].value == '1') {
3750: if (document.getElementById(divid)) {
3751: document.getElementById(divid).style.display = 'inline-block';
3752: }
3753: setvis = 1;
3754: break;
3755: }
3756: }
3757: }
3758: }
3759: if (setvis == 1) {
3760: break;
3761: }
3762: }
3763: if (!setvis) {
3764: if (document.getElementById(divid)) {
3765: document.getElementById(divid).style.display = 'none';
3766: }
3767: }
1.320 raeburn 3768: }
3769: return;
3770: }
1.405 raeburn 3771:
1.320 raeburn 3772: // ]]>
3773: </script>
3774:
3775: ENDSCRIPT
3776: }
3777:
1.385 raeburn 3778: sub autoupdate_javascript {
3779: return <<"ENDSCRIPT";
3780: <script type="text/javascript">
3781: // <![CDATA[
3782: function toggleLastActiveDays(form) {
3783: var radioname = 'lastactive';
3784: var divid = 'lastactive_div';
3785: var num = form.elements[radioname].length;
3786: if (num) {
3787: var setvis = '';
3788: for (var i=0; i<num; i++) {
3789: if (form.elements[radioname][i].checked) {
3790: if (form.elements[radioname][i].value == '1') {
3791: if (document.getElementById(divid)) {
3792: document.getElementById(divid).style.display = 'inline-block';
3793: }
3794: setvis = 1;
3795: }
3796: break;
3797: }
3798: }
3799: if (!setvis) {
3800: if (document.getElementById(divid)) {
3801: document.getElementById(divid).style.display = 'none';
3802: }
3803: }
3804: }
3805: return;
3806: }
3807: // ]]>
3808: </script>
3809:
3810: ENDSCRIPT
3811: }
3812:
1.399 raeburn 3813: sub autoenroll_javascript {
3814: return <<"ENDSCRIPT";
3815: <script type="text/javascript">
3816: // <![CDATA[
3817: function toggleFailsafe(form) {
3818: var radioname = 'autoenroll_failsafe';
3819: var divid = 'autoenroll_failsafe_div';
3820: var num = form.elements[radioname].length;
3821: if (num) {
3822: var setvis = '';
3823: for (var i=0; i<num; i++) {
3824: if (form.elements[radioname][i].checked) {
3825: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3826: if (document.getElementById(divid)) {
3827: document.getElementById(divid).style.display = 'inline-block';
3828: }
3829: setvis = 1;
3830: }
3831: break;
3832: }
3833: }
3834: if (!setvis) {
3835: if (document.getElementById(divid)) {
3836: document.getElementById(divid).style.display = 'none';
3837: }
3838: }
3839: }
3840: return;
3841: }
3842: // ]]>
3843: </script>
3844:
3845: ENDSCRIPT
3846: }
3847:
1.386 raeburn 3848: sub saml_javascript {
3849: return <<"ENDSCRIPT";
3850: <script type="text/javascript">
3851: // <![CDATA[
1.425 raeburn 3852: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3853: var radioname = 'saml_'+hostid;
3854: var tablecellon = 'samloptionson_'+hostid;
3855: var tablecelloff = 'samloptionsoff_'+hostid;
3856: var num = form.elements[radioname].length;
3857: if (num) {
1.425 raeburn 3858: var setvis = '';
1.386 raeburn 3859: for (var i=0; i<num; i++) {
3860: if (form.elements[radioname][i].checked) {
1.425 raeburn 3861: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3862: if (document.getElementById(tablecellon)) {
3863: document.getElementById(tablecellon).style.display='';
3864: }
3865: if (document.getElementById(tablecelloff)) {
3866: document.getElementById(tablecelloff).style.display='none';
3867: }
3868: setvis = 1;
3869: }
3870: break;
3871: }
3872: }
3873: if (!setvis) {
3874: if (document.getElementById(tablecellon)) {
3875: document.getElementById(tablecellon).style.display='none';
3876: }
3877: if (document.getElementById(tablecelloff)) {
3878: document.getElementById(tablecelloff).style.display='';
3879: }
3880: }
3881: }
3882: return;
3883: }
3884: // ]]>
3885: </script>
3886:
3887: ENDSCRIPT
3888: }
3889:
1.394 raeburn 3890: sub ipaccess_javascript {
3891: my ($settings) = @_;
3892: my (%ordered,$total,%jstext);
3893: $total = 0;
3894: if (ref($settings) eq 'HASH') {
3895: foreach my $item (keys(%{$settings})) {
3896: if (ref($settings->{$item}) eq 'HASH') {
3897: my $num = $settings->{$item}{'order'};
3898: $ordered{$num} = $item;
3899: }
3900: }
3901: $total = scalar(keys(%{$settings}));
3902: }
3903: my @jsarray = ();
3904: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3905: push(@jsarray,$ordered{$item});
3906: }
3907: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3908: return <<"ENDSCRIPT";
3909: <script type="text/javascript">
3910: // <![CDATA[
3911: function reorderIPaccess(form,item) {
3912: var changedVal;
3913: $jstext
3914: var newpos = 'ipaccess_pos_add';
3915: var maxh = 1 + $total;
3916: var current = new Array;
3917: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3918: if (item == newpos) {
3919: changedVal = newitemVal;
3920: } else {
3921: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3922: current[newitemVal] = newpos;
3923: }
3924: for (var i=0; i<ipaccess.length; i++) {
3925: var elementName = 'ipaccess_pos_'+ipaccess[i];
3926: if (elementName != item) {
3927: if (form.elements[elementName]) {
3928: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3929: current[currVal] = elementName;
3930: }
3931: }
3932: }
3933: var oldVal;
3934: for (var j=0; j<maxh; j++) {
3935: if (current[j] == undefined) {
3936: oldVal = j;
3937: }
3938: }
3939: if (oldVal < changedVal) {
3940: for (var k=oldVal+1; k<=changedVal ; k++) {
3941: var elementName = current[k];
3942: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3943: }
3944: } else {
3945: for (var k=changedVal; k<oldVal; k++) {
3946: var elementName = current[k];
3947: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3948: }
3949: }
3950: return;
3951: }
3952: // ]]>
3953: </script>
3954:
3955: ENDSCRIPT
3956: }
3957:
1.429 raeburn 3958: sub authordefaults_javascript {
3959: my %alert = &Apache::lonlocal::texthash (
3960: reqd => 'Warning: at least one editor needs to be available.',
3961: rest => 'Unchecking this editor disallowed while others unchecked.',
3962: );
3963: &js_escape(\%alert);
3964: return <<"ENDSCRIPT";
3965: <script type="text/javascript">
3966: // <![CDATA[
3967:
3968: function checkEditors(form,checkbox,current) {
3969: if (form.elements[checkbox].length != undefined) {
3970: var count = 0;
3971: for (var i=0; i<form.elements[checkbox].length; i++) {
3972: if (form.elements[checkbox][i].checked) {
3973: count ++;
3974: }
3975: }
3976: if (count == 0) {
3977: if (current.type =='radio') {
3978: current.checked = true;
3979: alert('$alert{reqd}\\n$alert{rest}');
3980: }
3981: }
3982: }
3983: return;
3984: }
3985: // ]]>
3986: </script>
3987:
3988: ENDSCRIPT
3989: }
3990:
1.3 raeburn 3991: sub print_autoenroll {
1.30 raeburn 3992: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3993: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3994: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3995: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3996: $failsafesty = 'none';
3997: %failsafechecked = (
3998: off => ' checked="checked"',
3999: );
1.3 raeburn 4000: if (ref($settings) eq 'HASH') {
4001: if (exists($settings->{'run'})) {
4002: if ($settings->{'run'} eq '0') {
4003: $runoff = ' checked="checked" ';
4004: $runon = ' ';
4005: } else {
4006: $runon = ' checked="checked" ';
4007: $runoff = ' ';
4008: }
4009: } else {
4010: if ($autorun) {
4011: $runon = ' checked="checked" ';
4012: $runoff = ' ';
4013: } else {
4014: $runoff = ' checked="checked" ';
4015: $runon = ' ';
4016: }
4017: }
1.129 raeburn 4018: if (exists($settings->{'co-owners'})) {
4019: if ($settings->{'co-owners'} eq '0') {
4020: $coownersoff = ' checked="checked" ';
4021: $coownerson = ' ';
4022: } else {
4023: $coownerson = ' checked="checked" ';
4024: $coownersoff = ' ';
4025: }
4026: } else {
4027: $coownersoff = ' checked="checked" ';
4028: $coownerson = ' ';
4029: }
1.3 raeburn 4030: if (exists($settings->{'sender_domain'})) {
4031: $defdom = $settings->{'sender_domain'};
4032: }
1.399 raeburn 4033: if (exists($settings->{'failsafe'})) {
4034: $failsafe = $settings->{'failsafe'};
4035: if ($failsafe eq 'zero') {
1.400 raeburn 4036: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4037: $failsafechecked{'off'} = '';
4038: $failsafesty = 'inline-block';
4039: } elsif ($failsafe eq 'any') {
4040: $failsafechecked{'any'} = ' checked="checked"';
4041: $failsafechecked{'off'} = '';
4042: }
4043: $autofailsafe = $settings->{'autofailsafe'};
4044: } elsif (exists($settings->{'autofailsafe'})) {
4045: $autofailsafe = $settings->{'autofailsafe'};
4046: if ($autofailsafe ne '') {
4047: $failsafechecked{'zero'} = ' checked="checked"';
4048: $failsafe = 'zero';
1.400 raeburn 4049: $failsafechecked{'off'} = '';
1.399 raeburn 4050: }
1.274 raeburn 4051: }
1.14 raeburn 4052: } else {
4053: if ($autorun) {
4054: $runon = ' checked="checked" ';
4055: $runoff = ' ';
4056: } else {
4057: $runoff = ' checked="checked" ';
4058: $runon = ' ';
4059: }
1.3 raeburn 4060: }
4061: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4062: my $notif_sender;
4063: if (ref($settings) eq 'HASH') {
4064: $notif_sender = $settings->{'sender_uname'};
4065: }
1.3 raeburn 4066: my $datatable='<tr class="LC_odd_row">'.
4067: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4068: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4069: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4070: $runon.' value="1" />'.&mt('Yes').'</label> '.
4071: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4072: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4073: '</tr><tr>'.
4074: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4075: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4076: &mt('username').': '.
4077: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4078: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4079: ': '.$domform.'</span></td></tr>'.
4080: '<tr class="LC_odd_row">'.
4081: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4082: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4083: '<input type="radio" name="autoassign_coowners"'.
4084: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4085: '<label><input type="radio" name="autoassign_coowners"'.
4086: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4087: '</tr><tr>'.
4088: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4089: '<td class="LC_left_item"><span class="LC_nobreak">'.
4090: '<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> '.
4091: '<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 />'.
4092: '<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 4093: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4094: '<span class="LC_nobreak">'.
4095: &mt('Threshold for number of students in section to drop: [_1]',
4096: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4097: '</span></div></td></tr>';
1.274 raeburn 4098: $$rowtotal += 4;
1.3 raeburn 4099: return $datatable;
4100: }
4101:
4102: sub print_autoupdate {
1.30 raeburn 4103: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4104: my ($enable,$datatable);
1.3 raeburn 4105: if ($position eq 'top') {
1.385 raeburn 4106: my %choices = &Apache::lonlocal::texthash (
4107: run => 'Auto-update active?',
4108: classlists => 'Update information in classlists?',
4109: unexpired => 'Skip updates for users without active or future roles?',
4110: lastactive => 'Skip updates for inactive users?',
4111: );
4112: my $itemcount = 0;
1.3 raeburn 4113: my $updateon = ' ';
4114: my $updateoff = ' checked="checked" ';
4115: if (ref($settings) eq 'HASH') {
4116: if ($settings->{'run'} eq '1') {
4117: $updateon = $updateoff;
4118: $updateoff = ' ';
4119: }
4120: }
1.385 raeburn 4121: $enable = '<tr class="LC_odd_row">'.
4122: '<td>'.$choices{'run'}.'</td>'.
4123: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4124: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4125: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4126: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4127: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4128: '</tr>';
1.385 raeburn 4129: my @toggles = ('classlists','unexpired');
4130: my %defaultchecked = ('classlists' => 'off',
4131: 'unexpired' => 'off'
4132: );
4133: $$rowtotal ++;
4134: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4135: \%choices,$itemcount,'','','left','no');
4136: $datatable = $enable.$datatable;
4137: $$rowtotal += $itemcount;
4138: my $lastactiveon = ' ';
4139: my $lastactiveoff = ' checked="checked" ';
4140: my $lastactivestyle = 'none';
4141: my $lastactivedays;
4142: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4143: if (ref($settings) eq 'HASH') {
4144: if ($settings->{'lastactive'} =~ /^\d+$/) {
4145: $lastactiveon = $lastactiveoff;
4146: $lastactiveoff = ' ';
4147: $lastactivestyle = 'inline-block';
4148: $lastactivedays = $settings->{'lastactive'};
4149: }
4150: }
4151: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4152: $datatable .= '<tr'.$css_class.'>'.
4153: '<td>'.$choices{'lastactive'}.'</td>'.
4154: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4155: '<input type="radio" name="lastactive"'.
4156: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4157: ' <label>'.
4158: '<input type="radio" name="lastactive"'.
4159: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4160: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4161: ': '.&mt('inactive = no activity in last [_1] days',
4162: '<input type="text" size="5" name="lastactivedays" value="'.
4163: $lastactivedays.'" />').
4164: '</span></td>'.
4165: '</tr>';
4166: $$rowtotal ++;
1.131 raeburn 4167: } elsif ($position eq 'middle') {
4168: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4169: my $numinrow = 3;
4170: my $locknamesettings;
4171: $datatable .= &insttypes_row($settings,$types,$usertypes,
4172: $dom,$numinrow,$othertitle,
1.305 raeburn 4173: 'lockablenames',$rowtotal);
1.131 raeburn 4174: $$rowtotal ++;
1.3 raeburn 4175: } else {
1.44 raeburn 4176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4177: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4178: 'permanentemail','id');
1.33 raeburn 4179: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4180: my $numrows = 0;
1.26 raeburn 4181: if (ref($types) eq 'ARRAY') {
4182: if (@{$types} > 0) {
4183: $datatable =
4184: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4185: \@fields,$types,\$numrows);
1.30 raeburn 4186: $$rowtotal += @{$types};
1.26 raeburn 4187: }
1.3 raeburn 4188: }
4189: $datatable .=
4190: &usertype_update_row($settings,{'default' => $othertitle},
4191: \%fieldtitles,\@fields,['default'],
4192: \$numrows);
1.30 raeburn 4193: $$rowtotal ++;
1.3 raeburn 4194: }
4195: return $datatable;
4196: }
4197:
1.125 raeburn 4198: sub print_autocreate {
4199: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4200: my (%createon,%createoff,%currhash);
1.125 raeburn 4201: my @types = ('xml','req');
4202: if (ref($settings) eq 'HASH') {
4203: foreach my $item (@types) {
4204: $createoff{$item} = ' checked="checked" ';
4205: $createon{$item} = ' ';
4206: if (exists($settings->{$item})) {
4207: if ($settings->{$item}) {
4208: $createon{$item} = ' checked="checked" ';
4209: $createoff{$item} = ' ';
4210: }
4211: }
4212: }
1.210 raeburn 4213: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4214: $currhash{$settings->{'xmldc'}} = 1;
4215: }
1.125 raeburn 4216: } else {
4217: foreach my $item (@types) {
4218: $createoff{$item} = ' checked="checked" ';
4219: $createon{$item} = ' ';
4220: }
4221: }
4222: $$rowtotal += 2;
1.191 raeburn 4223: my $numinrow = 2;
1.125 raeburn 4224: my $datatable='<tr class="LC_odd_row">'.
4225: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4226: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4227: '<input type="radio" name="autocreate_xml"'.
4228: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4229: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4230: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4231: '</td></tr><tr>'.
4232: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4234: '<input type="radio" name="autocreate_req"'.
4235: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4236: '<label><input type="radio" name="autocreate_req"'.
4237: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4238: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4239: 'autocreate_xmldc',%currhash);
1.247 raeburn 4240: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4241: if ($numdc > 1) {
1.247 raeburn 4242: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4243: '</td><td class="LC_left_item">';
1.125 raeburn 4244: } else {
1.247 raeburn 4245: $datatable .= &mt('Course creation processed as:').
4246: '</td><td class="LC_right_item">';
1.125 raeburn 4247: }
1.247 raeburn 4248: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4249: $$rowtotal += $rows;
1.125 raeburn 4250: return $datatable;
4251: }
4252:
1.23 raeburn 4253: sub print_directorysrch {
1.277 raeburn 4254: my ($position,$dom,$settings,$rowtotal) = @_;
4255: my $datatable;
4256: if ($position eq 'top') {
4257: my $instsrchon = ' ';
4258: my $instsrchoff = ' checked="checked" ';
4259: my ($exacton,$containson,$beginson);
4260: my $instlocalon = ' ';
4261: my $instlocaloff = ' checked="checked" ';
4262: if (ref($settings) eq 'HASH') {
4263: if ($settings->{'available'} eq '1') {
4264: $instsrchon = $instsrchoff;
4265: $instsrchoff = ' ';
4266: }
4267: if ($settings->{'localonly'} eq '1') {
4268: $instlocalon = $instlocaloff;
4269: $instlocaloff = ' ';
4270: }
4271: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4272: foreach my $type (@{$settings->{'searchtypes'}}) {
4273: if ($type eq 'exact') {
4274: $exacton = ' checked="checked" ';
4275: } elsif ($type eq 'contains') {
4276: $containson = ' checked="checked" ';
4277: } elsif ($type eq 'begins') {
4278: $beginson = ' checked="checked" ';
4279: }
4280: }
4281: } else {
4282: if ($settings->{'searchtypes'} eq 'exact') {
4283: $exacton = ' checked="checked" ';
4284: } elsif ($settings->{'searchtypes'} eq 'contains') {
4285: $containson = ' checked="checked" ';
4286: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4287: $exacton = ' checked="checked" ';
4288: $containson = ' checked="checked" ';
4289: }
4290: }
1.277 raeburn 4291: }
4292: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4293: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4294:
4295: my $numinrow = 4;
4296: my $cansrchrow = 0;
4297: $datatable='<tr class="LC_odd_row">'.
4298: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4299: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4300: '<input type="radio" name="dirsrch_available"'.
4301: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4302: '<label><input type="radio" name="dirsrch_available"'.
4303: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4304: '</tr><tr>'.
4305: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4306: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4307: '<input type="radio" name="dirsrch_instlocalonly"'.
4308: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4309: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4310: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4311: '</tr>';
4312: $$rowtotal += 2;
4313: if (ref($usertypes) eq 'HASH') {
4314: if (keys(%{$usertypes}) > 0) {
4315: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4316: $numinrow,$othertitle,'cansearch',
4317: $rowtotal);
1.277 raeburn 4318: $cansrchrow = 1;
1.25 raeburn 4319: }
1.23 raeburn 4320: }
1.277 raeburn 4321: if ($cansrchrow) {
4322: $$rowtotal ++;
4323: $datatable .= '<tr>';
4324: } else {
4325: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4326: }
1.277 raeburn 4327: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4328: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4329: foreach my $title (@{$titleorder}) {
4330: if (defined($searchtitles->{$title})) {
4331: my $check = ' ';
4332: if (ref($settings) eq 'HASH') {
4333: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4334: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4335: $check = ' checked="checked" ';
4336: }
1.39 raeburn 4337: }
1.25 raeburn 4338: }
1.277 raeburn 4339: $datatable .= '<td class="LC_left_item">'.
4340: '<span class="LC_nobreak"><label>'.
4341: '<input type="checkbox" name="searchby" '.
4342: 'value="'.$title.'"'.$check.'/>'.
4343: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4344: }
4345: }
1.277 raeburn 4346: $datatable .= '</tr></table></td></tr>';
4347: $$rowtotal ++;
4348: if ($cansrchrow) {
4349: $datatable .= '<tr class="LC_odd_row">';
4350: } else {
4351: $datatable .= '<tr>';
4352: }
4353: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4354: '<td class="LC_left_item" colspan="2">'.
4355: '<span class="LC_nobreak"><label>'.
4356: '<input type="checkbox" name="searchtypes" '.
4357: $exacton.' value="exact" />'.&mt('Exact match').
4358: '</label> '.
4359: '<label><input type="checkbox" name="searchtypes" '.
4360: $beginson.' value="begins" />'.&mt('Begins with').
4361: '</label> '.
4362: '<label><input type="checkbox" name="searchtypes" '.
4363: $containson.' value="contains" />'.&mt('Contains').
4364: '</label></span></td></tr>';
4365: $$rowtotal ++;
1.26 raeburn 4366: } else {
1.277 raeburn 4367: my $domsrchon = ' checked="checked" ';
4368: my $domsrchoff = ' ';
4369: my $domlocalon = ' ';
4370: my $domlocaloff = ' checked="checked" ';
4371: if (ref($settings) eq 'HASH') {
4372: if ($settings->{'lclocalonly'} eq '1') {
4373: $domlocalon = $domlocaloff;
4374: $domlocaloff = ' ';
4375: }
4376: if ($settings->{'lcavailable'} eq '0') {
4377: $domsrchoff = $domsrchon;
4378: $domsrchon = ' ';
4379: }
4380: }
4381: $datatable='<tr class="LC_odd_row">'.
4382: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4383: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4384: '<input type="radio" name="dirsrch_domavailable"'.
4385: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4386: '<label><input type="radio" name="dirsrch_domavailable"'.
4387: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4388: '</tr><tr>'.
4389: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4390: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4391: '<input type="radio" name="dirsrch_domlocalonly"'.
4392: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4393: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4394: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4395: '</tr>';
4396: $$rowtotal += 2;
1.26 raeburn 4397: }
1.25 raeburn 4398: return $datatable;
4399: }
4400:
1.28 raeburn 4401: sub print_contacts {
1.286 raeburn 4402: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4403: my $datatable;
4404: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4405: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4406: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4407: if ($position eq 'top') {
4408: if (ref($settings) eq 'HASH') {
4409: foreach my $item (@contacts) {
4410: if (exists($settings->{$item})) {
4411: $to{$item} = $settings->{$item};
4412: }
4413: }
4414: }
4415: } elsif ($position eq 'middle') {
4416: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4417: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4418: foreach my $type (@mailings) {
4419: $otheremails{$type} = '';
4420: }
1.340 raeburn 4421: } elsif ($position eq 'lower') {
4422: if (ref($settings) eq 'HASH') {
4423: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4424: %lonstatus = %{$settings->{'lonstatus'}};
4425: }
4426: }
1.286 raeburn 4427: } else {
4428: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4429: foreach my $type (@mailings) {
4430: $otheremails{$type} = '';
4431: }
1.286 raeburn 4432: $bccemails{'helpdeskmail'} = '';
4433: $bccemails{'otherdomsmail'} = '';
4434: $includestr{'helpdeskmail'} = '';
4435: $includestr{'otherdomsmail'} = '';
4436: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4437: }
1.28 raeburn 4438: if (ref($settings) eq 'HASH') {
1.340 raeburn 4439: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4440: foreach my $type (@mailings) {
4441: if (exists($settings->{$type})) {
4442: if (ref($settings->{$type}) eq 'HASH') {
4443: foreach my $item (@contacts) {
4444: if ($settings->{$type}{$item}) {
4445: $checked{$type}{$item} = ' checked="checked" ';
4446: }
4447: }
4448: $otheremails{$type} = $settings->{$type}{'others'};
4449: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4450: $bccemails{$type} = $settings->{$type}{'bcc'};
4451: if ($settings->{$type}{'include'} ne '') {
4452: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4453: $includestr{$type} = &unescape($includestr{$type});
4454: }
4455: }
4456: }
4457: } elsif ($type eq 'lonstatusmail') {
4458: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4459: }
1.28 raeburn 4460: }
4461: }
1.286 raeburn 4462: if ($position eq 'bottom') {
4463: foreach my $type (@mailings) {
4464: $bccemails{$type} = $settings->{$type}{'bcc'};
4465: if ($settings->{$type}{'include'} ne '') {
4466: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4467: $includestr{$type} = &unescape($includestr{$type});
4468: }
4469: }
4470: if (ref($settings->{'helpform'}) eq 'HASH') {
4471: if (ref($fields) eq 'ARRAY') {
4472: foreach my $field (@{$fields}) {
4473: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4474: }
1.286 raeburn 4475: }
4476: if (exists($settings->{'helpform'}{'maxsize'})) {
4477: $maxsize = $settings->{'helpform'}{'maxsize'};
4478: } else {
1.289 raeburn 4479: $maxsize = '1.0';
1.286 raeburn 4480: }
4481: } else {
4482: if (ref($fields) eq 'ARRAY') {
4483: foreach my $field (@{$fields}) {
4484: $currfield{$field} = 'yes';
1.134 raeburn 4485: }
1.28 raeburn 4486: }
1.286 raeburn 4487: $maxsize = '1.0';
1.28 raeburn 4488: }
4489: }
4490: } else {
1.286 raeburn 4491: if ($position eq 'top') {
4492: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4493: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4494: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4495: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4496: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4497: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4498: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4499: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4500: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4501: } elsif ($position eq 'bottom') {
4502: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4503: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4504: if (ref($fields) eq 'ARRAY') {
4505: foreach my $field (@{$fields}) {
4506: $currfield{$field} = 'yes';
4507: }
4508: }
4509: $maxsize = '1.0';
4510: }
1.28 raeburn 4511: }
4512: my ($titles,$short_titles) = &contact_titles();
4513: my $rownum = 0;
4514: my $css_class;
1.286 raeburn 4515: if ($position eq 'top') {
4516: foreach my $item (@contacts) {
4517: $css_class = $rownum%2?' class="LC_odd_row"':'';
4518: $datatable .= '<tr'.$css_class.'>'.
4519: '<td><span class="LC_nobreak">'.$titles->{$item}.
4520: '</span></td><td class="LC_right_item">'.
4521: '<input type="text" name="'.$item.'" value="'.
4522: $to{$item}.'" /></td></tr>';
4523: $rownum ++;
4524: }
1.315 raeburn 4525: } elsif ($position eq 'bottom') {
4526: $css_class = $rownum%2?' class="LC_odd_row"':'';
4527: $datatable .= '<tr'.$css_class.'>'.
4528: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4529: &mt('(e-mail, subject, and description always shown)').
4530: '</td><td class="LC_left_item">';
4531: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4532: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4533: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4534: foreach my $field (@{$fields}) {
4535: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4536: if (($field eq 'screenshot') || ($field eq 'cc')) {
4537: $datatable .= ' '.&mt('(logged-in users)');
4538: }
4539: $datatable .='</td><td>';
4540: my $clickaction;
4541: if ($field eq 'screenshot') {
4542: $clickaction = ' onclick="screenshotSize(this);"';
4543: }
4544: if (ref($possoptions->{$field}) eq 'ARRAY') {
4545: foreach my $option (@{$possoptions->{$field}}) {
4546: my $checked;
4547: if ($currfield{$field} eq $option) {
4548: $checked = ' checked="checked"';
4549: }
4550: $datatable .= '<span class="LC_nobreak"><label>'.
4551: '<input type="radio" name="helpform_'.$field.'" '.
4552: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4553: '</label></span>'.(' 'x2);
4554: }
4555: }
4556: if ($field eq 'screenshot') {
4557: my $display;
4558: if ($currfield{$field} eq 'no') {
4559: $display = ' style="display:none"';
4560: }
1.334 raeburn 4561: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4562: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4563: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4564: }
4565: $datatable .= '</td></tr>';
4566: }
4567: $datatable .= '</table>';
4568: }
4569: $datatable .= '</td></tr>'."\n";
4570: $rownum ++;
4571: }
1.340 raeburn 4572: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4573: foreach my $type (@mailings) {
4574: $css_class = $rownum%2?' class="LC_odd_row"':'';
4575: $datatable .= '<tr'.$css_class.'>'.
4576: '<td><span class="LC_nobreak">'.
4577: $titles->{$type}.': </span></td>'.
4578: '<td class="LC_left_item">';
4579: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4580: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4581: }
4582: $datatable .= '<span class="LC_nobreak">';
4583: foreach my $item (@contacts) {
4584: $datatable .= '<label>'.
4585: '<input type="checkbox" name="'.$type.'"'.
4586: $checked{$type}{$item}.
4587: ' value="'.$item.'" />'.$short_titles->{$item}.
4588: '</label> ';
4589: }
4590: $datatable .= '</span><br />'.&mt('Others').': '.
4591: '<input type="text" name="'.$type.'_others" '.
4592: 'value="'.$otheremails{$type}.'" />';
4593: my %locchecked;
4594: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4595: foreach my $loc ('s','b') {
4596: if ($includeloc{$type} eq $loc) {
4597: $locchecked{$loc} = ' checked="checked"';
4598: last;
4599: }
4600: }
4601: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4602: '<input type="text" name="'.$type.'_bcc" '.
4603: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4604: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4605: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4606: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4607: '<span class="LC_nobreak">'.&mt('Location:').' '.
4608: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4609: (' 'x2).
4610: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4611: '</span></fieldset>';
4612: }
4613: $datatable .= '</td></tr>'."\n";
4614: $rownum ++;
4615: }
1.28 raeburn 4616: }
1.286 raeburn 4617: if ($position eq 'middle') {
4618: my %choices;
1.340 raeburn 4619: my $corelink = &core_link_msu();
4620: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4621: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4622: $corelink);
4623: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4624: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4625: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4626: 'reportupdates' => 'on',
4627: 'reportstatus' => 'on');
1.286 raeburn 4628: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4629: \%choices,$rownum);
4630: $datatable .= $reports;
1.340 raeburn 4631: } elsif ($position eq 'lower') {
1.378 raeburn 4632: my (%current,%excluded,%weights);
1.340 raeburn 4633: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4634: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4635: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4636: } else {
1.378 raeburn 4637: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4638: }
4639: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4640: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4641: } else {
1.378 raeburn 4642: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4643: }
4644: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4645: foreach my $type ('E','W','N','U') {
1.340 raeburn 4646: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4647: $weights{$type} = $lonstatus{'weights'}{$type};
4648: } else {
4649: $weights{$type} = $defaults->{$type};
4650: }
4651: }
4652: } else {
1.341 raeburn 4653: foreach my $type ('E','W','N','U') {
1.340 raeburn 4654: $weights{$type} = $defaults->{$type};
4655: }
4656: }
4657: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4658: if (@{$lonstatus{'excluded'}} > 0) {
4659: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4660: }
4661: }
1.425 raeburn 4662: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4663: $css_class = $rownum%2?' class="LC_odd_row"':'';
4664: $datatable .= '<tr'.$css_class.'>'.
4665: '<td class="LC_left_item"><span class="LC_nobreak">'.
4666: $titles->{$item}.
4667: '</span></td><td class="LC_left_item">'.
4668: '<input type="text" name="'.$item.'" value="'.
4669: $current{$item}.'" size="5" /></td></tr>';
4670: $rownum ++;
4671: }
1.340 raeburn 4672: $css_class = $rownum%2?' class="LC_odd_row"':'';
4673: $datatable .= '<tr'.$css_class.'>'.
4674: '<td class="LC_left_item">'.
4675: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4676: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4677: foreach my $type ('E','W','N','U') {
1.340 raeburn 4678: $datatable .= '<td>'.$names->{$type}.'<br />'.
4679: '<input type="text" name="errorweights_'.$type.'" value="'.
4680: $weights{$type}.'" size="5" /></td>';
4681: }
4682: $datatable .= '</tr></table></tr>';
4683: $rownum ++;
4684: $css_class = $rownum%2?' class="LC_odd_row"':'';
4685: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4686: $titles->{'errorexcluded'}.'</td>'.
4687: '<td class="LC_left_item"><table>';
4688: my $numinrow = 4;
4689: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4690: for (my $i=0; $i<@ids; $i++) {
4691: my $rem = $i%($numinrow);
4692: if ($rem == 0) {
4693: if ($i > 0) {
4694: $datatable .= '</tr>';
4695: }
4696: $datatable .= '<tr>';
4697: }
4698: my $check;
4699: if ($excluded{$ids[$i]}) {
4700: $check = ' checked="checked" ';
4701: }
4702: $datatable .= '<td class="LC_left_item">'.
4703: '<span class="LC_nobreak"><label>'.
4704: '<input type="checkbox" name="errorexcluded" '.
4705: 'value="'.$ids[$i].'"'.$check.' />'.
4706: $ids[$i].'</label></span></td>';
4707: }
4708: my $colsleft = $numinrow - @ids%($numinrow);
4709: if ($colsleft > 1 ) {
4710: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4711: ' </td>';
4712: } elsif ($colsleft == 1) {
4713: $datatable .= '<td class="LC_left_item"> </td>';
4714: }
4715: $datatable .= '</tr></table></td></tr>';
4716: $rownum ++;
1.286 raeburn 4717: } elsif ($position eq 'bottom') {
1.315 raeburn 4718: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4719: my (@posstypes,%usertypeshash);
4720: if (ref($types) eq 'ARRAY') {
4721: @posstypes = @{$types};
4722: }
4723: if (@posstypes) {
4724: if (ref($usertypes) eq 'HASH') {
4725: %usertypeshash = %{$usertypes};
4726: }
4727: my @overridden;
4728: my $numinrow = 4;
4729: if (ref($settings) eq 'HASH') {
4730: if (ref($settings->{'overrides'}) eq 'HASH') {
4731: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4732: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4733: push(@overridden,$key);
4734: foreach my $item (@contacts) {
4735: if ($settings->{'overrides'}{$key}{$item}) {
4736: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4737: }
4738: }
4739: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4740: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4741: $includeloc{'override_'.$key} = '';
4742: $includestr{'override_'.$key} = '';
4743: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4744: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4745: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4746: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4747: }
1.286 raeburn 4748: }
4749: }
4750: }
1.315 raeburn 4751: }
4752: my $customclass = 'LC_helpdesk_override';
4753: my $optionsprefix = 'LC_options_helpdesk_';
4754:
4755: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4756: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4757: $numinrow,$othertitle,'overrides',
4758: \$rownum,$onclicktypes,$customclass);
4759: $rownum ++;
4760: $usertypeshash{'default'} = $othertitle;
4761: foreach my $status (@posstypes) {
4762: my $css_class;
4763: if ($rownum%2) {
4764: $css_class = 'LC_odd_row ';
4765: }
4766: $css_class .= $customclass;
4767: my $rowid = $optionsprefix.$status;
4768: my $hidden = 1;
4769: my $currstyle = 'display:none';
4770: if (grep(/^\Q$status\E$/,@overridden)) {
4771: $currstyle = 'display:table-row';
4772: $hidden = 0;
4773: }
4774: my $key = 'override_'.$status;
4775: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4776: $includeloc{$key},$includestr{$key},$status,$rowid,
4777: $usertypeshash{$status},$css_class,$currstyle,
4778: \@contacts,$short_titles);
4779: unless ($hidden) {
4780: $rownum ++;
1.286 raeburn 4781: }
4782: }
1.134 raeburn 4783: }
1.28 raeburn 4784: }
1.30 raeburn 4785: $$rowtotal += $rownum;
1.28 raeburn 4786: return $datatable;
4787: }
4788:
1.340 raeburn 4789: sub core_link_msu {
4790: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4791: &mt('LON-CAPA core group - MSU'),600,500);
4792: }
4793:
1.315 raeburn 4794: sub overridden_helpdesk {
4795: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4796: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4797: my $class = 'LC_left_item';
4798: if ($css_class) {
4799: $css_class = ' class="'.$css_class.'"';
4800: }
4801: if ($rowid) {
4802: $rowid = ' id="'.$rowid.'"';
4803: }
4804: if ($rowstyle) {
4805: $rowstyle = ' style="'.$rowstyle.'"';
4806: }
4807: my ($output,$description);
4808: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4809: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4810: "<td>$description</td>\n".
4811: '<td class="'.$class.'" colspan="2">'.
4812: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4813: '<span class="LC_nobreak">';
4814: if (ref($contacts) eq 'ARRAY') {
4815: foreach my $item (@{$contacts}) {
4816: my $check;
4817: if (ref($checked) eq 'HASH') {
4818: $check = $checked->{$item};
4819: }
4820: my $title;
4821: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4822: $title = $short_titles->{$item};
1.315 raeburn 4823: }
4824: $output .= '<label>'.
4825: '<input type="checkbox" name="override_'.$type.'"'.$check.
4826: ' value="'.$item.'" />'.$title.'</label> ';
4827: }
4828: }
4829: $output .= '</span><br />'.&mt('Others').': '.
4830: '<input type="text" name="override_'.$type.'_others" '.
4831: 'value="'.$otheremails.'" />';
4832: my %locchecked;
4833: foreach my $loc ('s','b') {
4834: if ($includeloc eq $loc) {
4835: $locchecked{$loc} = ' checked="checked"';
4836: last;
4837: }
4838: }
4839: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4840: '<input type="text" name="override_'.$type.'_bcc" '.
4841: 'value="'.$bccemails.'" /></fieldset>'.
4842: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4843: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4844: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4845: '<span class="LC_nobreak">'.&mt('Location:').' '.
4846: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4847: (' 'x2).
4848: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4849: '</span></fieldset>'.
4850: '</td></tr>'."\n";
4851: return $output;
4852: }
4853:
1.286 raeburn 4854: sub contacts_javascript {
4855: return <<"ENDSCRIPT";
4856:
4857: <script type="text/javascript">
4858: // <![CDATA[
4859:
4860: function screenshotSize(field) {
4861: if (document.getElementById('help_screenshotsize')) {
4862: if (field.value == 'no') {
1.289 raeburn 4863: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4864: } else {
4865: document.getElementById('help_screenshotsize').style.display="";
4866: }
4867: }
4868: return;
4869: }
4870:
1.315 raeburn 4871: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4872: if (form.elements[checkbox].length != undefined) {
4873: var count = 0;
4874: if (docount) {
4875: for (var i=0; i<form.elements[checkbox].length; i++) {
4876: if (form.elements[checkbox][i].checked) {
4877: count ++;
4878: }
4879: }
4880: }
4881: for (var i=0; i<form.elements[checkbox].length; i++) {
4882: var type = form.elements[checkbox][i].value;
4883: if (document.getElementById(prefix+type)) {
4884: if (form.elements[checkbox][i].checked) {
4885: document.getElementById(prefix+type).style.display = 'table-row';
4886: if (count % 2 == 1) {
4887: document.getElementById(prefix+type).className = target+' LC_odd_row';
4888: } else {
4889: document.getElementById(prefix+type).className = target;
4890: }
4891: count ++;
4892: } else {
4893: document.getElementById(prefix+type).style.display = 'none';
4894: }
4895: }
4896: }
4897: }
4898: return;
4899: }
4900:
1.286 raeburn 4901: // ]]>
4902: </script>
4903:
4904: ENDSCRIPT
4905: }
4906:
1.118 jms 4907: sub print_helpsettings {
1.282 raeburn 4908: my ($position,$dom,$settings,$rowtotal) = @_;
4909: my $confname = $dom.'-domainconfig';
1.285 raeburn 4910: my $formname = 'display';
1.168 raeburn 4911: my ($datatable,$itemcount);
1.282 raeburn 4912: if ($position eq 'top') {
4913: $itemcount = 1;
4914: my (%choices,%defaultchecked,@toggles);
4915: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4916: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4917: &mt('LON-CAPA bug tracker'),600,500));
4918: %defaultchecked = ('submitbugs' => 'on');
4919: @toggles = ('submitbugs');
4920: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4921: \%choices,$itemcount);
4922: $$rowtotal ++;
4923: } else {
4924: my $css_class;
4925: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4926: my (%customroles,%ordered,%current);
1.301 raeburn 4927: if (ref($settings) eq 'HASH') {
4928: if (ref($settings->{'adhoc'}) eq 'HASH') {
4929: %current = %{$settings->{'adhoc'}};
4930: }
1.285 raeburn 4931: }
4932: my $count = 0;
4933: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4934: if ($key=~/^rolesdef\_(\w+)$/) {
4935: my $rolename = $1;
1.285 raeburn 4936: my (%privs,$order);
1.282 raeburn 4937: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4938: $customroles{$rolename} = \%privs;
1.285 raeburn 4939: if (ref($current{$rolename}) eq 'HASH') {
4940: $order = $current{$rolename}{'order'};
4941: }
4942: if ($order eq '') {
4943: $order = $count;
4944: }
4945: $ordered{$order} = $rolename;
4946: $count++;
4947: }
4948: }
4949: my $maxnum = scalar(keys(%ordered));
4950: my @roles_by_num = ();
4951: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4952: push(@roles_by_num,$item);
4953: }
4954: my $context = 'domprefs';
4955: my $crstype = 'Course';
4956: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4957: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4958: my ($numstatustypes,@jsarray);
4959: if (ref($types) eq 'ARRAY') {
4960: if (@{$types} > 0) {
4961: $numstatustypes = scalar(@{$types});
4962: push(@accesstypes,'status');
4963: @jsarray = ('bystatus');
1.282 raeburn 4964: }
4965: }
1.290 raeburn 4966: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4967: if (keys(%domhelpdesk)) {
4968: push(@accesstypes,('inc','exc'));
4969: push(@jsarray,('notinc','notexc'));
4970: }
4971: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4972: my $context = 'domprefs';
4973: my $crstype = 'Course';
1.285 raeburn 4974: my $prefix = 'helproles_';
4975: my $add_class = 'LC_hidden';
4976: foreach my $num (@roles_by_num) {
4977: my $role = $ordered{$num};
4978: my ($desc,$access,@statuses);
4979: if (ref($current{$role}) eq 'HASH') {
4980: $desc = $current{$role}{'desc'};
4981: $access = $current{$role}{'access'};
4982: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4983: @statuses = @{$current{$role}{'insttypes'}};
4984: }
4985: }
4986: if ($desc eq '') {
4987: $desc = $role;
4988: }
4989: my $identifier = 'custhelp'.$num;
1.282 raeburn 4990: my %full=();
4991: my %levels= (
4992: course => {},
4993: domain => {},
4994: system => {},
4995: );
4996: my %levelscurrent=(
4997: course => {},
4998: domain => {},
4999: system => {},
5000: );
5001: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5002: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5003: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5004: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5005: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5006: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5007: for (my $k=0; $k<=$maxnum; $k++) {
5008: my $vpos = $k+1;
5009: my $selstr;
5010: if ($k == $num) {
5011: $selstr = ' selected="selected" ';
5012: }
5013: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5014: }
5015: $datatable .= '</select>'.(' 'x2).
5016: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5017: '</td>'.
5018: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5019: &mt('Name shown to users:').
5020: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5021: '</fieldset>'.
5022: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5023: $othertitle,$usertypes,$types,\%domhelpdesk).
5024: '<fieldset>'.
5025: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5026: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5027: \%levelscurrent,$identifier,
5028: 'LC_hidden',$prefix.$num.'_privs').
5029: '</fieldset></td>';
1.282 raeburn 5030: $itemcount ++;
5031: }
5032: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5033: my $newcust = 'custhelp'.$count;
5034: my (%privs,%levelscurrent);
5035: my %full=();
5036: my %levels= (
5037: course => {},
5038: domain => {},
5039: system => {},
5040: );
5041: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5042: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5043: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5044: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5045: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5046: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5047: for (my $k=0; $k<$maxnum+1; $k++) {
5048: my $vpos = $k+1;
5049: my $selstr;
5050: if ($k == $maxnum) {
5051: $selstr = ' selected="selected" ';
5052: }
5053: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5054: }
5055: $datatable .= '</select> '."\n".
1.282 raeburn 5056: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5057: '</label></span></td>'.
1.285 raeburn 5058: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5059: '<span class="LC_nobreak">'.
5060: &mt('Internal name:').
5061: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5062: '</span>'.(' 'x4).
5063: '<span class="LC_nobreak">'.
5064: &mt('Name shown to users:').
5065: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5066: '</span></fieldset>'.
5067: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5068: $usertypes,$types,\%domhelpdesk).
5069: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5070: &Apache::lonuserutils::custom_role_header($context,$crstype,
5071: \@templateroles,$newcust).
5072: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5073: \%levelscurrent,$newcust).
1.334 raeburn 5074: '</fieldset>'.
5075: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5076: '</td></tr>';
1.282 raeburn 5077: $count ++;
5078: $$rowtotal += $count;
5079: }
1.166 raeburn 5080: return $datatable;
1.121 raeburn 5081: }
5082:
1.285 raeburn 5083: sub adhocbutton {
5084: my ($prefix,$num,$field,$visibility) = @_;
5085: my %lt = &Apache::lonlocal::texthash(
5086: show => 'Show details',
5087: hide => 'Hide details',
5088: );
5089: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5090: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5091: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5092: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5093: }
5094:
5095: sub helpsettings_javascript {
5096: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5097: return unless(ref($roles_by_num) eq 'ARRAY');
5098: my %html_js_lt = &Apache::lonlocal::texthash(
5099: show => 'Show details',
5100: hide => 'Hide details',
5101: );
5102: &html_escape(\%html_js_lt);
5103: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5104: return <<"ENDSCRIPT";
5105: <script type="text/javascript">
5106: // <![CDATA[
5107:
5108: function reorderHelpRoles(form,item) {
5109: var changedVal;
5110: $jstext
5111: var newpos = 'helproles_${total}_pos';
5112: var maxh = 1 + $total;
5113: var current = new Array();
5114: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5115: if (item == newpos) {
5116: changedVal = newitemVal;
5117: } else {
5118: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5119: current[newitemVal] = newpos;
5120: }
5121: for (var i=0; i<helproles.length; i++) {
5122: var elementName = 'helproles_'+helproles[i]+'_pos';
5123: if (elementName != item) {
5124: if (form.elements[elementName]) {
5125: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5126: current[currVal] = elementName;
5127: }
5128: }
5129: }
5130: var oldVal;
5131: for (var j=0; j<maxh; j++) {
5132: if (current[j] == undefined) {
5133: oldVal = j;
5134: }
5135: }
5136: if (oldVal < changedVal) {
5137: for (var k=oldVal+1; k<=changedVal ; k++) {
5138: var elementName = current[k];
5139: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5140: }
5141: } else {
5142: for (var k=changedVal; k<oldVal; k++) {
5143: var elementName = current[k];
5144: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5145: }
5146: }
5147: return;
5148: }
5149:
5150: function helpdeskAccess(num) {
5151: var curraccess = null;
5152: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5153: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5154: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5155: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5156: }
5157: }
5158: }
5159: var shown = Array();
5160: var hidden = Array();
5161: if (curraccess == 'none') {
5162: hidden = Array('$hiddenstr');
5163: } else {
5164: if (curraccess == 'status') {
5165: shown = Array('bystatus');
5166: hidden = Array('notinc','notexc');
5167: } else {
5168: if (curraccess == 'exc') {
5169: shown = Array('notexc');
5170: hidden = Array('notinc','bystatus');
5171: }
5172: if (curraccess == 'inc') {
5173: shown = Array('notinc');
5174: hidden = Array('notexc','bystatus');
5175: }
1.293 raeburn 5176: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5177: hidden = Array('notinc','notexc','bystatus');
5178: }
5179: }
5180: }
5181: if (hidden.length > 0) {
5182: for (var i=0; i<hidden.length; i++) {
5183: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5184: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5185: }
5186: }
5187: }
5188: if (shown.length > 0) {
5189: for (var i=0; i<shown.length; i++) {
5190: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5191: if (shown[i] == 'privs') {
5192: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5193: } else {
5194: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5195: }
5196: }
5197: }
5198: }
5199: return;
5200: }
5201:
5202: function toggleHelpdeskItem(num,field) {
5203: if (document.getElementById('helproles_'+num+'_'+field)) {
5204: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5205: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5206: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5207: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5208: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5209: }
5210: } else {
5211: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5212: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5213: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5214: }
5215: }
5216: }
5217: return;
5218: }
5219:
5220: // ]]>
5221: </script>
5222:
5223: ENDSCRIPT
5224: }
5225:
5226: sub helpdeskroles_access {
5227: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5228: $usertypes,$types,$domhelpdesk) = @_;
5229: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5230: my %lt = &Apache::lonlocal::texthash(
5231: 'rou' => 'Role usage',
5232: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5233: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5234: 'dh' => 'All with domain helpdesk role',
5235: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5236: 'none' => 'None',
5237: 'status' => 'Determined based on institutional status',
5238: 'inc' => 'Include all, but exclude specific personnel',
5239: 'exc' => 'Exclude all, but include specific personnel',
5240: );
5241: my %usecheck = (
5242: all => ' checked="checked"',
5243: );
5244: my %displaydiv = (
5245: status => 'none',
5246: inc => 'none',
5247: exc => 'none',
5248: priv => 'block',
5249: );
5250: my $output;
5251: if (ref($current) eq 'HASH') {
5252: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5253: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5254: $usecheck{$current->{access}} = $usecheck{'all'};
5255: delete($usecheck{'all'});
5256: if ($current->{access} =~ /^(status|inc|exc)$/) {
5257: my $access = $1;
5258: $displaydiv{$access} = 'inline';
5259: } elsif ($current->{access} eq 'none') {
5260: $displaydiv{'priv'} = 'none';
5261: }
5262: }
5263: }
5264: }
5265: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5266: '<p>'.$lt{'whi'}.'</p>';
5267: foreach my $access (@{$accesstypes}) {
5268: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5269: ' onclick="helpdeskAccess('."'$num'".');" />'.
5270: $lt{$access}.'</label>';
5271: if ($access eq 'status') {
5272: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5273: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5274: $othertitle,$usertypes,$types).
5275: '</div>';
5276: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5277: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5278: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5279: '</div>';
5280: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5281: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5282: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5283: '</div>';
5284: }
5285: $output .= '</p>';
5286: }
5287: $output .= '</fieldset>';
5288: return $output;
5289: }
5290:
1.121 raeburn 5291: sub radiobutton_prefs {
1.192 raeburn 5292: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5293: $additional,$align,$firstval) = @_;
1.121 raeburn 5294: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5295: (ref($choices) eq 'HASH'));
5296:
1.170 raeburn 5297: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5298:
5299: foreach my $item (@{$toggles}) {
5300: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5301: $checkedon{$item} = ' checked="checked" ';
5302: $checkedoff{$item} = ' ';
1.121 raeburn 5303: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5304: $checkedoff{$item} = ' checked="checked" ';
5305: $checkedon{$item} = ' ';
5306: }
5307: }
5308: if (ref($settings) eq 'HASH') {
1.121 raeburn 5309: foreach my $item (@{$toggles}) {
1.118 jms 5310: if ($settings->{$item} eq '1') {
5311: $checkedon{$item} = ' checked="checked" ';
5312: $checkedoff{$item} = ' ';
5313: } elsif ($settings->{$item} eq '0') {
5314: $checkedoff{$item} = ' checked="checked" ';
5315: $checkedon{$item} = ' ';
5316: }
5317: }
1.121 raeburn 5318: }
1.192 raeburn 5319: if ($onclick) {
5320: $onclick = ' onclick="'.$onclick.'"';
5321: }
1.121 raeburn 5322: foreach my $item (@{$toggles}) {
1.118 jms 5323: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5324: $datatable .=
1.306 raeburn 5325: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5326: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5327: '</span></td>';
5328: if ($align eq 'left') {
5329: $datatable .= '<td class="LC_left_item">';
5330: } else {
5331: $datatable .= '<td class="LC_right_item">';
5332: }
1.385 raeburn 5333: $datatable .= '<span class="LC_nobreak">';
5334: if ($firstval eq 'no') {
5335: $datatable .=
5336: '<label><input type="radio" name="'.
5337: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5338: '</label> <label><input type="radio" name="'.$item.'" '.
5339: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5340: } else {
5341: $datatable .=
5342: '<label><input type="radio" name="'.
5343: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5344: '</label> <label><input type="radio" name="'.$item.'" '.
5345: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5346: }
5347: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5348: $itemcount ++;
1.121 raeburn 5349: }
5350: return ($datatable,$itemcount);
5351: }
5352:
1.267 raeburn 5353: sub print_ltitools {
1.421 raeburn 5354: my ($position,$dom,$settings,$rowtotal) = @_;
5355: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5356: if (ref($settings) eq 'HASH') {
1.421 raeburn 5357: if ($position eq 'top') {
5358: if (exists($settings->{'encrypt'})) {
5359: if (ref($settings->{'encrypt'}) eq 'HASH') {
5360: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5361: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5362: }
5363: }
1.267 raeburn 5364: }
1.421 raeburn 5365: if (exists($settings->{'private'})) {
5366: if (ref($settings->{'private'}) eq 'HASH') {
5367: if (ref($settings->{'private'}) eq 'HASH') {
5368: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5369: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5370: }
5371: }
5372: }
5373: }
1.421 raeburn 5374: } elsif ($position eq 'middle') {
5375: if (exists($settings->{'rules'})) {
5376: if (ref($settings->{'rules'}) eq 'HASH') {
5377: %rules = %{$settings->{'rules'}};
1.273 raeburn 5378: }
5379: }
1.421 raeburn 5380: } else {
5381: foreach my $key ('encrypt','private','rules') {
5382: if (exists($settings->{$key})) {
5383: delete($settings->{$key});
1.267 raeburn 5384: }
5385: }
5386: }
5387: }
1.421 raeburn 5388: my $datatable;
5389: my $itemcount = 1;
5390: if ($position eq 'top') {
5391: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5392: } elsif ($position eq 'middle') {
5393: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5394: $$rowtotal += $itemcount;
5395: } else {
5396: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5397: }
5398: return $datatable;
5399: }
5400:
5401: sub ltitools_names {
5402: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5403: 'title' => 'Title',
5404: 'version' => 'Version',
5405: 'msgtype' => 'Message Type',
1.323 raeburn 5406: 'sigmethod' => 'Signature Method',
1.296 raeburn 5407: 'url' => 'URL',
5408: 'key' => 'Key',
1.322 raeburn 5409: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5410: 'secret' => 'Secret',
1.425 raeburn 5411: 'icon' => 'Icon',
1.324 raeburn 5412: 'user' => 'User',
1.296 raeburn 5413: 'fullname' => 'Full Name',
5414: 'firstname' => 'First Name',
5415: 'lastname' => 'Last Name',
5416: 'email' => 'E-mail',
5417: 'roles' => 'Role',
1.298 raeburn 5418: 'window' => 'Window',
5419: 'tab' => 'Tab',
1.296 raeburn 5420: 'iframe' => 'iFrame',
5421: 'height' => 'Height',
5422: 'width' => 'Width',
5423: 'linktext' => 'Default Link Text',
5424: 'explanation' => 'Default Explanation',
5425: 'passback' => 'Tool can return grades:',
5426: 'roster' => 'Tool can retrieve roster:',
5427: 'crstarget' => 'Display target',
5428: 'crslabel' => 'Course label',
1.425 raeburn 5429: 'crstitle' => 'Course title',
1.296 raeburn 5430: 'crslinktext' => 'Link Text',
5431: 'crsexplanation' => 'Explanation',
1.318 raeburn 5432: 'crsappend' => 'Provider URL',
1.267 raeburn 5433: );
5434: return %lt;
5435: }
5436:
1.421 raeburn 5437: sub secrets_form {
5438: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5439: my @ids=&Apache::lonnet::current_machine_ids();
5440: my %servers = &Apache::lonnet::get_servers($dom,'library');
5441: my $primary = &Apache::lonnet::domain($dom,'primary');
5442: my ($css_class,$extra,$numshown,$itemcount,$output);
5443: $itemcount = 0;
5444: foreach my $hostid (sort(keys(%servers))) {
5445: my ($showextra,$divsty,$switch);
5446: if ($hostid eq $primary) {
5447: if ($context eq 'ltisec') {
5448: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5449: $showextra = 1;
5450: }
5451: if ($encrypt->{'ltisec_crslinkprot'}) {
5452: $showextra = 1;
5453: }
5454: } else {
5455: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5456: $showextra = 1;
5457: }
5458: }
5459: unless (grep(/^\Q$hostid\E$/,@ids)) {
5460: $switch = 1;
5461: }
5462: if ($showextra) {
5463: $numshown ++;
5464: $divsty = 'display:inline-block';
5465: } else {
5466: $divsty = 'display:none';
5467: }
5468: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5469: '<legend>'.$hostid.'</legend>';
5470: if ($switch) {
5471: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5472: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5473: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5474: if (exists($privkeys->{$hostid})) {
5475: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5476: '<span class="LC_nobreak">'.
5477: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5478: '<span class="LC_nobreak">'.&mt('Change?').
5479: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5480: (' 'x2).
5481: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5482: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5483: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5484: '</span></div>';
5485: } else {
5486: $extra .= '<span class="LC_nobreak">'.
5487: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5488: '</span>'."\n";
5489: }
5490: } elsif (exists($privkeys->{$hostid})) {
5491: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5492: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5493: '<span class="LC_nobreak">'.&mt('Change?').
5494: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5495: (' 'x2).
5496: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5497: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5498: '<span class="LC_nobreak">'.&mt('New Key').':'.
5499: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5500: '<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>'.
5501: '</span></div>';
5502: } else {
5503: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5504: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5505: '<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>';
5506: }
5507: $extra .= '</fieldset>';
5508: }
5509: }
5510: my (%choices,@toggles,%defaultchecked);
5511: if ($context eq 'ltisec') {
5512: %choices = &Apache::lonlocal::texthash (
5513: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5514: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5515: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5516: );
5517: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5518: %defaultchecked = (
5519: 'ltisec_crslinkprot' => 'off',
5520: 'ltisec_domlinkprot' => 'off',
5521: 'ltisec_consumers' => 'off',
5522: );
5523: } else {
5524: %choices = &Apache::lonlocal::texthash (
5525: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5526: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5527: );
5528: @toggles = qw(toolsec_crs toolsec_dom);
5529: %defaultchecked = (
5530: 'toolsec_crs' => 'off',
5531: 'toolsec_dom' => 'off',
5532: );
5533: }
5534: my ($onclick,$itemcount);
5535: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5536: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5537: \%choices,$itemcount,$onclick,'','left','no');
5538:
5539: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5540: my $noprivkeysty = 'display:inline-block';
5541: if ($numshown) {
5542: $noprivkeysty = 'display:none';
5543: }
5544: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5545: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5546: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5547: $extra.
5548: '</td></tr>';
5549: $itemcount ++;
5550: $$rowtotal += $itemcount;
5551: return $output;
5552: }
5553:
1.372 raeburn 5554: sub print_proctoring {
5555: my ($dom,$settings,$rowtotal) = @_;
5556: my $itemcount = 1;
5557: my (%ordered,%providernames,%current,%currentdef);
5558: my $confname = $dom.'-domainconfig';
5559: my $switchserver = &check_switchserver($dom,$confname);
5560: if (ref($settings) eq 'HASH') {
5561: foreach my $item (keys(%{$settings})) {
5562: if (ref($settings->{$item}) eq 'HASH') {
5563: my $num = $settings->{$item}{'order'};
5564: $ordered{$num} = $item;
5565: }
5566: }
5567: } else {
5568: %ordered = (
5569: 1 => 'proctorio',
5570: 2 => 'examity',
5571: );
5572: }
5573: %providernames = &proctoring_providernames();
5574: my $maxnum = scalar(keys(%ordered));
5575: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5576: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5577: if (ref($requref) eq 'HASH') {
5578: %requserfields = %{$requref};
5579: }
5580: if (ref($opturef) eq 'HASH') {
5581: %optuserfields = %{$opturef};
5582: }
5583: if (ref($defref) eq 'HASH') {
5584: %defaults = %{$defref};
5585: }
5586: if (ref($extref) eq 'HASH') {
5587: %extended = %{$extref};
5588: }
5589: if (ref($crsref) eq 'HASH') {
5590: %crsconf = %{$crsref};
5591: }
5592: if (ref($rolesref) eq 'ARRAY') {
5593: @courseroles = @{$rolesref};
5594: }
5595: if (ref($ltiref) eq 'ARRAY') {
5596: @ltiroles = @{$ltiref};
5597: }
5598: my $datatable;
5599: my $css_class;
5600: if (keys(%ordered)) {
5601: my @items = sort { $a <=> $b } keys(%ordered);
5602: for (my $i=0; $i<@items; $i++) {
5603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5604: my $provider = $ordered{$items[$i]};
5605: my $optionsty = 'none';
5606: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5607: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5608: if (ref($settings) eq 'HASH') {
5609: if (ref($settings->{$provider}) eq 'HASH') {
5610: %current = %{$settings->{$provider}};
5611: if ($current{'available'}) {
5612: $optionsty = 'block';
5613: $available = 1;
5614: }
5615: if ($current{'lifetime'} =~ /^\d+$/) {
5616: $lifetime = $current{'lifetime'};
5617: }
5618: if ($current{'version'} =~ /^\d+\.\d+$/) {
5619: $version = $current{'version'};
5620: }
5621: if ($current{'image'} ne '') {
5622: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5623: }
5624: if (ref($current{'fields'}) eq 'ARRAY') {
5625: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5626: }
5627: $userincdom = $current{'incdom'};
5628: if (ref($current{'roles'}) eq 'HASH') {
5629: %rolemaps = %{$current{'roles'}};
5630: $checkedfields{'roles'} = 1;
5631: }
5632: if (ref($current{'defaults'}) eq 'ARRAY') {
5633: foreach my $val (@{$current{'defaults'}}) {
5634: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5635: $inuse{$val} = 1;
5636: } else {
5637: foreach my $poss (keys(%{$extended{$provider}})) {
5638: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5639: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5640: $inuse{$poss} = $val;
5641: last;
5642: }
5643: }
5644: }
5645: }
5646: }
5647: } elsif (ref($current{'defaults'}) eq 'HASH') {
5648: foreach my $key (keys(%{$current{'defaults'}})) {
5649: my $currval = $current{'defaults'}{$key};
5650: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5651: $inuse{$key} = 1;
5652: } else {
5653: my $match;
5654: foreach my $poss (keys(%{$extended{$provider}})) {
5655: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5656: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5657: $inuse{$poss} = $key;
5658: last;
5659: }
5660: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5661: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5662: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5663: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5664: $currentdef{$inner} = $currval;
5665: $match = 1;
5666: last;
5667: }
5668: } elsif ($inner eq $key) {
5669: $currentdef{$key} = $currval;
5670: $match = 1;
5671: last;
5672: }
5673: }
5674: }
5675: last if ($match);
5676: }
5677: }
5678: }
5679: }
5680: if (ref($current{'crsconf'}) eq 'ARRAY') {
5681: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5682: }
5683: }
5684: }
5685: my %lt = &proctoring_titles($provider);
5686: my %fieldtitles = &proctoring_fieldtitles($provider);
5687: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5688: my %checkedavailable = (
5689: yes => '',
5690: no => ' checked="checked"',
5691: );
5692: if ($available) {
5693: $checkedavailable{'yes'} = $checkedavailable{'no'};
5694: $checkedavailable{'no'} = '';
5695: }
5696: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5697: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5698: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5699: for (my $k=0; $k<$maxnum; $k++) {
5700: my $vpos = $k+1;
5701: my $selstr;
5702: if ($k == $i) {
5703: $selstr = ' selected="selected" ';
5704: }
5705: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5706: }
5707: if ($version eq '') {
5708: if ($provider eq 'proctorio') {
5709: $version = '1.0';
5710: } elsif ($provider eq 'examity') {
5711: $version = '1.1';
5712: }
5713: }
5714: if ($lifetime eq '') {
5715: $lifetime = '300';
5716: }
5717: $datatable .=
5718: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5719: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5720: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5721: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5722: '</td>'.
5723: '<td colspan="2">'.
5724: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5725: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5726: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5727: (' 'x2).
5728: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5729: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5730: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5731: (' 'x2).
5732: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5733: '<br />'.
5734: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5735: '<br />'.
5736: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5737: (' 'x2).
5738: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5739: '<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";
5740: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5741: if ($imgsrc) {
5742: $datatable .= $imgsrc.
5743: '<label><input type="checkbox" name="proctoring_image_del"'.
5744: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5745: '<span class="LC_nobreak"> '.&mt('Replace:');
5746: }
5747: $datatable .= ' ';
5748: if ($switchserver) {
5749: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5750: } else {
5751: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5752: }
5753: unless ($imgsrc) {
5754: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5755: }
5756: $datatable .= '</fieldset>'."\n";
5757: if (ref($requserfields{$provider}) eq 'ARRAY') {
5758: if (@{$requserfields{$provider}} > 0) {
5759: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5760: foreach my $field (@{$requserfields{$provider}}) {
5761: $datatable .= '<span class="LC_nobreak">'.
5762: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5763: $lt{$field}.'</label>';
5764: if ($field eq 'user') {
5765: my $seluserdom = '';
5766: my $unseluserdom = ' selected="selected"';
5767: if ($userincdom) {
5768: $seluserdom = $unseluserdom;
5769: $unseluserdom = '';
5770: }
5771: $datatable .= ': '.
5772: '<select name="proctoring_userincdom_'.$provider.'">'.
5773: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5774: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5775: '</select> ';
5776: } else {
5777: $datatable .= ' ';
5778: if ($field eq 'roles') {
5779: $showroles = 1;
5780: }
5781: }
5782: $datatable .= '</span> ';
5783: }
5784: }
5785: $datatable .= '</fieldset>'."\n";
5786: }
5787: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5788: if (@{$optuserfields{$provider}} > 0) {
5789: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5790: foreach my $field (@{$optuserfields{$provider}}) {
5791: my $checked;
5792: if ($checkedfields{$field}) {
5793: $checked = ' checked="checked"';
5794: }
5795: $datatable .= '<span class="LC_nobreak">'.
5796: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5797: }
5798: $datatable .= '</fieldset>'."\n";
5799: }
5800: }
5801: if (ref($defaults{$provider}) eq 'ARRAY') {
5802: if (@{$defaults{$provider}}) {
5803: my (%options,@selectboxes);
5804: if (ref($extended{$provider}) eq 'HASH') {
5805: %options = %{$extended{$provider}};
5806: }
5807: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5808: my ($rem,$numinrow,$dropdowns);
5809: if ($provider eq 'proctorio') {
5810: $datatable .= '<table>';
5811: $numinrow = 4;
5812: }
5813: my $i = 0;
5814: foreach my $field (@{$defaults{$provider}}) {
5815: my $checked;
5816: if ($inuse{$field}) {
5817: $checked = ' checked="checked"';
5818: }
5819: if ($provider eq 'examity') {
5820: if ($field eq 'display') {
5821: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5822: foreach my $option ('iframe','tab','window') {
5823: my $checkdisp;
5824: if ($currentdef{'target'} eq $option) {
5825: $checkdisp = ' checked="checked"';
5826: }
5827: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5828: $fieldtitles{$option}.'</label>'.(' 'x2);
5829: }
5830: $datatable .= (' 'x4);
5831: foreach my $dimen ('width','height') {
5832: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5833: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5834: 'value="'.$currentdef{$dimen}.'" /></label>'.
5835: (' 'x2);
5836: }
5837: $datatable .= '</span><br />'.
5838: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5839: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5840: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5841: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5842: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5843: $currentdef{'explanation'}.
5844: '</textarea></div><div style=""></div><br />';
5845: }
5846: } else {
5847: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5848: my ($output,$selnone);
5849: unless ($checked) {
5850: $selnone = ' selected="selected"';
5851: }
5852: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5853: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5854: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5855: foreach my $option (@{$options{$field}}) {
5856: my $sel;
5857: if ($inuse{$field} eq $option) {
5858: $sel = ' selected="selected"';
5859: }
5860: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5861: }
5862: $output .= '</select></span>';
5863: push(@selectboxes,$output);
5864: } else {
5865: $rem = $i%($numinrow);
5866: if ($rem == 0) {
5867: if ($i > 0) {
5868: $datatable .= '</tr>';
5869: }
5870: $datatable .= '<tr>';
5871: }
5872: $datatable .= '<td class="LC_left_item">'.
5873: '<span class="LC_nobreak">'.
5874: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5875: $fieldtitles{$field}.'</label></span></td>';
5876: $i++;
5877: }
5878: }
5879: }
5880: if ($provider eq 'proctorio') {
5881: if ($numinrow) {
5882: $rem = $i%$numinrow;
5883: }
5884: my $colsleft = $numinrow - $rem;
5885: if ($colsleft > 1) {
5886: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5887: } else {
5888: $datatable .= '<td class="LC_left_item">';
5889: }
5890: $datatable .= ' '.
5891: '</td></tr></table>';
5892: if (@selectboxes) {
5893: $datatable .= '<hr /><table>';
5894: $numinrow = 2;
5895: for (my $i=0; $i<@selectboxes; $i++) {
5896: $rem = $i%($numinrow);
5897: if ($rem == 0) {
5898: if ($i > 0) {
5899: $datatable .= '</tr>';
5900: }
5901: $datatable .= '<tr>';
5902: }
5903: $datatable .= '<td class="LC_left_item">'.
5904: $selectboxes[$i].'</td>';
5905: }
5906: if ($numinrow) {
5907: $rem = $i%$numinrow;
5908: }
5909: $colsleft = $numinrow - $rem;
5910: if ($colsleft > 1) {
5911: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5912: } else {
5913: $datatable .= '<td class="LC_left_item">';
5914: }
5915: $datatable .= ' '.
5916: '</td></tr></table>';
5917: }
5918: }
5919: $datatable .= '</fieldset>';
5920: }
5921: if (ref($crsconf{$provider}) eq 'ARRAY') {
5922: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5923: '<legend>'.&mt('Configurable in course').'</legend>';
5924: my ($rem,$numinrow);
5925: if ($provider eq 'proctorio') {
5926: $datatable .= '<table>';
5927: $numinrow = 4;
5928: }
5929: my $i = 0;
5930: foreach my $item (@{$crsconf{$provider}}) {
5931: my $name;
5932: if ($provider eq 'examity') {
5933: $name = $lt{'crs'.$item};
5934: } elsif ($provider eq 'proctorio') {
5935: $name = $fieldtitles{$item};
5936: $rem = $i%($numinrow);
5937: if ($rem == 0) {
5938: if ($i > 0) {
5939: $datatable .= '</tr>';
5940: }
5941: $datatable .= '<tr>';
5942: }
5943: $datatable .= '<td class="LC_left_item>';
5944: }
5945: my $checked;
5946: if ($crsconfig{$item}) {
5947: $checked = ' checked="checked"';
5948: }
5949: $datatable .= '<span class="LC_nobreak"><label>'.
5950: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5951: $name.'</label></span>';
5952: if ($provider eq 'examity') {
5953: $datatable .= ' ';
5954: }
5955: $datatable .= "\n";
5956: $i++;
5957: }
5958: if ($provider eq 'proctorio') {
5959: if ($numinrow) {
5960: $rem = $i%$numinrow;
5961: }
5962: my $colsleft = $numinrow - $rem;
5963: if ($colsleft > 1) {
5964: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5965: } else {
5966: $datatable .= '<td class="LC_left_item">';
5967: }
5968: $datatable .= ' '.
5969: '</td></tr></table>';
5970: }
5971: $datatable .= '</fieldset>';
5972: }
5973: if ($showroles) {
5974: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5975: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5976: foreach my $role (@courseroles) {
5977: my ($selected,$selectnone);
5978: if (!$rolemaps{$role}) {
5979: $selectnone = ' selected="selected"';
5980: }
5981: $datatable .= '<td style="text-align: center">'.
5982: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5983: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5984: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5985: foreach my $ltirole (@ltiroles) {
5986: unless ($selectnone) {
5987: if ($rolemaps{$role} eq $ltirole) {
5988: $selected = ' selected="selected"';
5989: } else {
5990: $selected = '';
5991: }
5992: }
5993: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5994: }
5995: $datatable .= '</select></td>';
5996: }
5997: $datatable .= '</tr></table></fieldset>'.
5998: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5999: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6000: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6001: '<tr><td></td><td>lms</td>'.
6002: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6003: ' value="Loncapa" disabled="disabled"/></td></tr>';
6004: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6005: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6006: my %custom = %{$settings->{$provider}->{'custom'}};
6007: if (keys(%custom) > 0) {
6008: foreach my $key (sort(keys(%custom))) {
6009: next if ($key eq 'lms');
6010: $datatable .= '<tr><td><span class="LC_nobreak">'.
6011: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6012: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6013: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6014: ' value="'.$custom{$key}.'" /></td></tr>';
6015: }
6016: }
6017: }
6018: $datatable .= '<tr><td><span class="LC_nobreak">'.
6019: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6020: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6021: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6022: '</table></fieldset></td></tr>'."\n";
6023: }
6024: $datatable .= '</td></tr>';
6025: }
6026: $itemcount ++;
6027: }
6028: }
6029: return $datatable;
6030: }
6031:
6032: sub proctoring_data {
6033: my $requserfields = {
6034: proctorio => ['user'],
6035: examity => ['roles','user'],
6036: };
6037: my $optuserfields = {
6038: proctorio => ['fullname'],
6039: examity => ['fullname','firstname','lastname','email'],
6040: };
6041: my $defaults = {
6042: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6043: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6044: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6045: 'closetabs','onescreen','print','downloads','cache','rightclick',
6046: 'reentry','calculator','whiteboard'],
6047: examity => ['display'],
6048: };
6049: my $extended = {
6050: proctorio => {
6051: verifyid => ['verifyidauto','verifyidlive'],
6052: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6053: tabslinks => ['notabs','linksonly'],
6054: reentry => ['noreentry','agentreentry'],
6055: calculator => ['calculatorbasic','calculatorsci'],
6056: },
6057: examity => {
6058: display => {
6059: target => ['iframe','tab','window'],
6060: width => '',
6061: height => '',
6062: linktext => '',
6063: explanation => '',
6064: },
6065: },
6066: };
6067: my $crsconf = {
6068: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6069: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6070: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6071: 'closetabs','onescreen','print','downloads','cache','rightclick',
6072: 'reentry','calculator','whiteboard'],
6073: examity => ['label','title','target','linktext','explanation','append'],
6074: };
6075: my $courseroles = ['cc','in','ta','ep','st'];
6076: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6077: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6078: }
6079:
6080: sub proctoring_titles {
6081: my ($item) = @_;
6082: my (%common_lt,%custom_lt);
6083: %common_lt = &Apache::lonlocal::texthash (
6084: 'avai' => 'Available?',
6085: 'base' => 'Basic Settings',
6086: 'requ' => 'User data required to be sent on launch',
6087: 'optu' => 'User data optionally sent on launch',
6088: 'udsl' => 'User data sent on launch',
6089: 'defa' => 'Defaults for items configurable in course',
6090: 'sigmethod' => 'Signature Method',
6091: 'key' => 'Key',
6092: 'lifetime' => 'Nonce lifetime (s)',
6093: 'secret' => 'Secret',
6094: 'icon' => 'Icon',
6095: 'fullname' => 'Full Name',
6096: 'visible' => 'Visible input',
6097: 'username' => 'username',
6098: 'user' => 'User',
6099: );
6100: if ($item eq 'proctorio') {
6101: %custom_lt = &Apache::lonlocal::texthash (
6102: 'version' => 'OAuth version',
6103: 'url' => 'API URL',
6104: 'uname:dom' => 'username-domain',
6105: );
6106: } elsif ($item eq 'examity') {
6107: %custom_lt = &Apache::lonlocal::texthash (
6108: 'version' => 'LTI Version',
6109: 'url' => 'URL',
6110: 'uname:dom' => 'username:domain',
6111: 'msgtype' => 'Message Type',
6112: 'firstname' => 'First Name',
6113: 'lastname' => 'Last Name',
6114: 'email' => 'E-mail',
6115: 'roles' => 'Role',
6116: 'crstarget' => 'Display target',
6117: 'crslabel' => 'Course label',
6118: 'crstitle' => 'Course title',
6119: 'crslinktext' => 'Link Text',
6120: 'crsexplanation' => 'Explanation',
6121: 'crsappend' => 'Provider URL',
6122: );
6123: }
6124: my %lt = (%common_lt,%custom_lt);
6125: return %lt;
6126: }
6127:
6128: sub proctoring_fieldtitles {
6129: my ($item) = @_;
6130: if ($item eq 'proctorio') {
6131: return &Apache::lonlocal::texthash (
6132: 'recordvideo' => 'Record video',
6133: 'recordaudio' => 'Record audio',
6134: 'recordscreen' => 'Record screen',
6135: 'recordwebtraffic' => 'Record web traffic',
6136: 'recordroomstart' => 'Record room scan',
6137: 'verifyvideo' => 'Verify webcam',
6138: 'verifyaudio' => 'Verify microphone',
6139: 'verifydesktop' => 'Verify desktop recording',
6140: 'verifyid' => 'Photo ID verification',
6141: 'verifysignature' => 'Require signature',
6142: 'fullscreen' => 'Fullscreen',
6143: 'clipboard' => 'Disable copy/paste',
6144: 'tabslinks' => 'New tabs/windows',
6145: 'closetabs' => 'Close other tabs',
6146: 'onescreen' => 'Limit to single screen',
6147: 'print' => 'Disable Printing',
6148: 'downloads' => 'Disable Downloads',
6149: 'cache' => 'Empty cache after exam',
6150: 'rightclick' => 'Disable right click',
6151: 'reentry' => 'Re-entry to exam',
6152: 'calculator' => 'Onscreen calculator',
6153: 'whiteboard' => 'Onscreen whiteboard',
6154: 'verifyidauto' => 'Automated verification',
6155: 'verifyidlive' => 'Live agent verification',
6156: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6157: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6158: 'fullscreensever' => 'Forced, navigation away ends exam',
6159: 'notabs' => 'Disaallowed',
6160: 'linksonly' => 'Allowed from links in exam',
6161: 'noreentry' => 'Disallowed',
6162: 'agentreentry' => 'Agent required for re-entry',
6163: 'calculatorbasic' => 'Basic',
6164: 'calculatorsci' => 'Scientific',
6165: );
6166: } elsif ($item eq 'examity') {
6167: return &Apache::lonlocal::texthash (
6168: 'target' => 'Display target',
6169: 'window' => 'Window',
6170: 'tab' => 'Tab',
6171: 'iframe' => 'iFrame',
6172: 'height' => 'Height (pixels)',
6173: 'width' => 'Width (pixels)',
6174: 'linktext' => 'Default Link Text',
6175: 'explanation' => 'Default Explanation',
6176: 'append' => 'Provider URL',
6177: );
6178: }
6179: }
6180:
6181: sub proctoring_providernames {
6182: return (
6183: proctorio => 'Proctorio',
6184: examity => 'Examity',
6185: );
6186: }
6187:
1.320 raeburn 6188: sub print_lti {
1.405 raeburn 6189: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6190: my $itemcount = 1;
1.405 raeburn 6191: my ($datatable,$css_class);
1.434 raeburn 6192: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6193: if (ref($settings) eq 'HASH') {
1.405 raeburn 6194: if ($position eq 'top') {
6195: if (exists($settings->{'encrypt'})) {
6196: if (ref($settings->{'encrypt'}) eq 'HASH') {
6197: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6198: if ($key eq 'consumers') {
6199: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6200: } else {
6201: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6202: }
6203: }
6204: }
6205: }
6206: if (exists($settings->{'private'})) {
6207: if (ref($settings->{'private'}) eq 'HASH') {
6208: if (ref($settings->{'private'}) eq 'HASH') {
6209: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6210: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6211: }
6212: }
6213: }
6214: }
1.434 raeburn 6215: } elsif ($position eq 'upper') {
1.405 raeburn 6216: if (exists($settings->{'rules'})) {
6217: if (ref($settings->{'rules'}) eq 'HASH') {
6218: %rules = %{$settings->{'rules'}};
6219: }
6220: }
1.434 raeburn 6221: } elsif ($position eq 'middle') {
6222: if (exists($settings->{'suggested'})) {
6223: if (ref($settings->{'suggested'}) eq 'HASH') {
6224: %suggestions = %{$settings->{'suggested'}};
6225: }
6226: }
1.405 raeburn 6227: } elsif ($position eq 'lower') {
6228: if (exists($settings->{'linkprot'})) {
6229: if (ref($settings->{'linkprot'}) eq 'HASH') {
6230: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6231: if ($linkprot{'lock'}) {
6232: delete($linkprot{'lock'});
6233: }
1.405 raeburn 6234: }
6235: }
6236: } else {
1.434 raeburn 6237: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6238: if (exists($settings->{$key})) {
6239: delete($settings->{$key});
1.390 raeburn 6240: }
1.320 raeburn 6241: }
6242: }
6243: }
1.405 raeburn 6244: if ($position eq 'top') {
1.421 raeburn 6245: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6246: } elsif ($position eq 'upper') {
6247: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6248: $$rowtotal += $itemcount;
1.421 raeburn 6249: } elsif ($position eq 'middle') {
1.434 raeburn 6250: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6251: $$rowtotal += $itemcount;
6252: } elsif ($position eq 'lower') {
1.434 raeburn 6253: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6254: } else {
1.424 raeburn 6255: my ($switchserver,$switchmessage);
6256: $switchserver = &check_switchserver($dom);
6257: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6258: my $maxnum = 0;
6259: my %ordered;
6260: if (ref($settings) eq 'HASH') {
6261: foreach my $item (keys(%{$settings})) {
6262: if (ref($settings->{$item}) eq 'HASH') {
6263: my $num = $settings->{$item}{'order'};
6264: if ($num eq '') {
6265: $num = scalar(keys(%{$settings}));
6266: }
6267: $ordered{$num} = $item;
1.405 raeburn 6268: }
1.352 raeburn 6269: }
1.405 raeburn 6270: }
6271: $maxnum = scalar(keys(%ordered));
6272: my %lt = <i_names();
6273: if (keys(%ordered)) {
6274: my @items = sort { $a <=> $b } keys(%ordered);
6275: for (my $i=0; $i<@items; $i++) {
6276: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6277: my $item = $ordered{$items[$i]};
1.424 raeburn 6278: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6279: if (ref($settings->{$item}) eq 'HASH') {
6280: $key = $settings->{$item}->{'key'};
1.424 raeburn 6281: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6282: $lifetime = $settings->{$item}->{'lifetime'};
6283: $consumer = $settings->{$item}->{'consumer'};
6284: $requser = $settings->{$item}->{'requser'};
6285: $crsinc = $settings->{$item}->{'crsinc'};
6286: $current = $settings->{$item};
6287: }
6288: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6289: my %checkedrequser = (
6290: yes => ' checked="checked"',
6291: no => '',
6292: );
6293: if (!$requser) {
6294: $checkedrequser{'no'} = $checkedrequser{'yes'};
6295: $checkedrequser{'yes'} = '';
6296: }
6297: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6298: my %checkedcrsinc = (
1.391 raeburn 6299: yes => ' checked="checked"',
6300: no => '',
1.405 raeburn 6301: );
6302: if (!$crsinc) {
6303: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6304: $checkedcrsinc{'yes'} = '';
6305: }
6306: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6307: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6308: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6309: for (my $k=0; $k<=$maxnum; $k++) {
6310: my $vpos = $k+1;
6311: my $selstr;
6312: if ($k == $i) {
6313: $selstr = ' selected="selected" ';
6314: }
6315: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6316: }
1.405 raeburn 6317: $datatable .= '</select>'.(' 'x2).
6318: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6319: &mt('Delete?').'</label></span></td>'.
6320: '<td colspan="2">'.
6321: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6322: '<span class="LC_nobreak">'.$lt{'consumer'}.
6323: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6324: (' 'x2).
6325: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6326: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6327: (' 'x2).
6328: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6329: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6330: if ($key ne '') {
6331: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6332: if ($switchserver) {
6333: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6334: } else {
6335: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6336: }
6337: $datatable .= '</span> '.(' 'x2);
6338: } elsif (!$switchserver) {
6339: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6340: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6341: '</span> '.(' 'x2);
6342: }
6343: if ($switchserver) {
6344: if ($usable ne '') {
6345: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6346: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6347: '<span class="LC_nobreak">'.&mt('Change secret?').
6348: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6349: (' 'x2).
6350: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6351: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6352: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6353: '</div>';
6354: } elsif ($key eq '') {
6355: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6356: } else {
6357: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6358: }
6359: } else {
6360: if ($usable ne '') {
6361: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6362: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6363: '<span class="LC_nobreak">'.&mt('Change?').
6364: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6365: (' 'x2).
6366: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6367: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6368: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6369: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6370: '<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>';
6371: } else {
6372: $datatable .=
6373: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6374: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6375: '<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>';
6376: }
6377: }
1.425 raeburn 6378: $datatable .= '<br /><br />'.
1.405 raeburn 6379: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6380: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6381: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6382: '<br /><br />'.
6383: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6384: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6385: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6386: (' 'x4).
6387: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6388: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6389: $itemcount ++;
1.320 raeburn 6390: }
6391: }
1.405 raeburn 6392: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6393: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6394: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6395: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6396: '<select name="lti_pos_add"'.$chgstr.'>';
6397: for (my $k=0; $k<$maxnum+1; $k++) {
6398: my $vpos = $k+1;
6399: my $selstr;
6400: if ($k == $maxnum) {
6401: $selstr = ' selected="selected" ';
6402: }
6403: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6404: }
1.405 raeburn 6405: $datatable .= '</select> '."\n".
6406: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6407: '<td colspan="2">'.
6408: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6409: '<span class="LC_nobreak">'.$lt{'consumer'}.
6410: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6411: (' 'x2).
6412: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6413: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6414: (' 'x2).
1.424 raeburn 6415: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6416: if ($switchserver) {
6417: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6418: } else {
6419: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6420: (' 'x2).
6421: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6422: '<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";
6423: }
6424: $datatable .= '<br /><br />'.
1.405 raeburn 6425: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6426: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6427: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6428: '<br /><br />'.
6429: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6430: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6431: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6432: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6433: '</td>'."\n".
6434: '</tr>'."\n";
6435: $itemcount ++;
1.320 raeburn 6436: }
1.405 raeburn 6437: $$rowtotal += $itemcount;
6438: return $datatable;
1.320 raeburn 6439: }
6440:
6441: sub lti_names {
6442: my %lt = &Apache::lonlocal::texthash(
6443: 'version' => 'LTI Version',
6444: 'url' => 'URL',
6445: 'key' => 'Key',
1.322 raeburn 6446: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6447: 'consumer' => 'Consumer',
1.320 raeburn 6448: 'secret' => 'Secret',
1.345 raeburn 6449: 'requser' => "User's identity sent",
1.391 raeburn 6450: 'crsinc' => "Course's identity sent",
1.320 raeburn 6451: 'email' => 'Email address',
6452: 'sourcedid' => 'User ID',
6453: 'other' => 'Other',
6454: 'passback' => 'Can return grades to Consumer:',
6455: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6456: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6457: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6458: );
6459: return %lt;
6460: }
6461:
6462: sub lti_options {
1.325 raeburn 6463: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6464: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6465: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6466: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6467: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6468: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6469: $checked{'mapcrstype'} = {};
6470: $checked{'makeuser'} = {};
6471: $checked{'selfenroll'} = {};
6472: $checked{'crssec'} = {};
6473: $checked{'crssecsrc'} = {};
1.325 raeburn 6474: $checked{'lcauth'} = {};
1.326 raeburn 6475: $checked{'menuitem'} = {};
1.325 raeburn 6476: if ($num eq 'add') {
6477: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6478: }
1.320 raeburn 6479: my $userfieldsty = 'none';
6480: my $crsfieldsty = 'none';
6481: my $crssecfieldsty = 'none';
6482: my $secsrcfieldsty = 'none';
1.363 raeburn 6483: my $callbacksty = 'none';
1.337 raeburn 6484: my $passbacksty = 'none';
1.345 raeburn 6485: my $optionsty = 'block';
1.391 raeburn 6486: my $crssty = 'block';
1.325 raeburn 6487: my $lcauthparm;
6488: my $lcauthparmstyle = 'display:none';
6489: my $lcauthparmtext;
1.326 raeburn 6490: my $menusty;
1.325 raeburn 6491: my $numinrow = 4;
1.326 raeburn 6492: my %menutitles = <imenu_titles();
1.320 raeburn 6493:
6494: if (ref($current) eq 'HASH') {
1.345 raeburn 6495: if (!$current->{'requser'}) {
6496: $optionsty = 'none';
1.391 raeburn 6497: $crssty = 'none';
6498: } elsif (!$current->{'crsinc'}) {
6499: $crssty = 'none';
1.345 raeburn 6500: }
1.320 raeburn 6501: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6502: $checked{'mapuser'}{'sourcedid'} = '';
6503: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6504: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6505: } else {
6506: $checked{'mapuser'}{'other'} = ' checked="checked"';
6507: $userfield = $current->{'mapuser'};
6508: $userfieldsty = 'inline-block';
6509: }
6510: }
6511: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6512: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6513: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6514: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6515: } else {
6516: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6517: $cidfield = $current->{'mapcrs'};
6518: $crsfieldsty = 'inline-block';
6519: }
6520: }
6521: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6522: foreach my $type (@{$current->{'mapcrstype'}}) {
6523: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6524: }
6525: }
1.392 raeburn 6526: if (!$current->{'storecrs'}) {
6527: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6528: $checked{'storecrs'}{'Y'} = '';
6529: }
1.345 raeburn 6530: if ($current->{'makecrs'}) {
1.320 raeburn 6531: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6532: }
1.320 raeburn 6533: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6534: foreach my $role (@{$current->{'makeuser'}}) {
6535: $checked{'makeuser'}{$role} = ' checked="checked"';
6536: }
6537: }
1.325 raeburn 6538: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6539: $checked{'lcauth'}{$1} = ' checked="checked"';
6540: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6541: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6542: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6543: if ($current->{'lcauth'} eq 'localauth') {
6544: $lcauthparmtext = &mt('Local auth argument');
6545: } else {
6546: $lcauthparmtext = &mt('Kerberos domain');
6547: }
6548: }
6549: }
1.320 raeburn 6550: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6551: foreach my $role (@{$current->{'selfenroll'}}) {
6552: $checked{'selfenroll'}{$role} = ' checked="checked"';
6553: }
6554: }
6555: if (ref($current->{'maproles'}) eq 'HASH') {
6556: %rolemaps = %{$current->{'maproles'}};
6557: }
6558: if ($current->{'section'} ne '') {
1.425 raeburn 6559: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6560: $crssecfieldsty = 'inline-block';
6561: if ($current->{'section'} eq 'course_section_sourcedid') {
6562: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6563: } else {
6564: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6565: $crssecsrc = $current->{'section'};
6566: $secsrcfieldsty = 'inline-block';
6567: }
6568: } else {
6569: $checked{'crssec'}{'N'} = ' checked="checked"';
6570: }
1.363 raeburn 6571: if ($current->{'callback'} ne '') {
6572: $callback = $current->{'callback'};
6573: $checked{'callback'}{'Y'} = ' checked="checked"';
6574: $callbacksty = 'inline-block';
6575: } else {
6576: $checked{'callback'}{'N'} = ' checked="checked"';
6577: }
1.326 raeburn 6578: if ($current->{'topmenu'}) {
6579: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6580: } else {
6581: $checked{'topmenu'}{'N'} = ' checked="checked"';
6582: }
6583: if ($current->{'inlinemenu'}) {
6584: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6585: } else {
6586: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6587: }
6588: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6589: $menusty = 'inline-block';
6590: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6591: foreach my $item (@{$current->{'lcmenu'}}) {
6592: if (exists($menutitles{$item})) {
6593: $checked{'menuitem'}{$item} = ' checked="checked"';
6594: }
6595: }
6596: }
6597: } else {
6598: $menusty = 'none';
6599: }
1.320 raeburn 6600: } else {
6601: $checked{'makecrs'}{'N'} = ' checked="checked"';
6602: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6603: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6604: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6605: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6606: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6607: $menusty = 'inline-block';
1.320 raeburn 6608: }
1.325 raeburn 6609: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6610: my %coursetypetitles = &Apache::lonlocal::texthash (
6611: official => 'Official',
6612: unofficial => 'Unofficial',
6613: community => 'Community',
6614: textbook => 'Textbook',
6615: placement => 'Placement Test',
1.325 raeburn 6616: lti => 'LTI Provider',
1.320 raeburn 6617: );
1.325 raeburn 6618: my @authtypes = ('internal','krb4','krb5','localauth');
6619: my %shortauth = (
6620: internal => 'int',
6621: krb4 => 'krb4',
6622: krb5 => 'krb5',
6623: localauth => 'loc'
6624: );
6625: my %authnames = &authtype_names();
1.320 raeburn 6626: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6627: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6628: my @courseroles = ('cc','in','ta','ep','st');
6629: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6630: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6631: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6632: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6633: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6634: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6635: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6636: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6637: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6638: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6639: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6640: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6641: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6642: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6643: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6644: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6645: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6646: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6647: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6648: foreach my $option ('sourcedid','email','other') {
6649: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6650: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6651: ($option eq 'other' ? '' : (' 'x2) );
6652: }
6653: $output .= '</span></div>'.
6654: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6655: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6656: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6657: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6658: foreach my $ltirole (@ltiroles) {
6659: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6660: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6661: }
6662: $output .= '</fieldset>'.
1.391 raeburn 6663: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6664: '<table>'.
6665: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6666: '</table>'.
6667: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6668: '<td class="LC_left_item">';
6669: foreach my $auth ('lti',@authtypes) {
6670: my $authtext;
6671: if ($auth eq 'lti') {
6672: $authtext = &mt('None');
6673: } else {
6674: $authtext = $authnames{$shortauth{$auth}};
6675: }
6676: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6677: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6678: $authtext.'</label></span> ';
6679: }
6680: $output .= '</td></tr>'.
6681: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6682: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6683: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6684: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6685: '</table></fieldset>'.
1.391 raeburn 6686: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6687: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6688: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6689: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6690: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6691: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6692: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6693: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6694: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6695: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6696: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6697: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6698: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6699: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6700: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6701: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6702: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6703: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6704: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6705: (' 'x2);
6706: }
6707: $output .= '</span></div></fieldset>'.
6708: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6709: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6710: &mt('Unique course identifier').': ';
6711: foreach my $option ('course_offering_sourcedid','context_id','other') {
6712: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6713: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6714: ($option eq 'other' ? '' : (' 'x2) );
6715: }
1.334 raeburn 6716: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6717: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6718: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6719: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6720: foreach my $type (@coursetypes) {
6721: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6722: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6723: (' 'x2);
6724: }
1.392 raeburn 6725: $output .= '</span><br /><br />'.
6726: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6727: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6728: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6729: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6730: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6731: '</fieldset>'.
1.391 raeburn 6732: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6733: foreach my $ltirole (@lticourseroles) {
6734: my ($selected,$selectnone);
6735: if ($rolemaps{$ltirole} eq '') {
6736: $selectnone = ' selected="selected"';
6737: }
6738: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6739: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6740: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6741: foreach my $role (@courseroles) {
6742: unless ($selectnone) {
6743: if ($rolemaps{$ltirole} eq $role) {
6744: $selected = ' selected="selected"';
6745: } else {
6746: $selected = '';
6747: }
6748: }
6749: $output .= '<option value="'.$role.'"'.$selected.'>'.
6750: &Apache::lonnet::plaintext($role,'Course').
6751: '</option>';
6752: }
6753: $output .= '</select></td>';
6754: }
6755: $output .= '</tr></table></fieldset>'.
6756: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6757: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6758: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6759: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6760: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6761: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6762: '</fieldset>'.
1.391 raeburn 6763: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6764: foreach my $lticrsrole (@lticourseroles) {
6765: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6766: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6767: }
6768: $output .= '</fieldset>'.
1.391 raeburn 6769: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6770: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6771: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6772: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6773: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6774: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6775: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6776: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6777: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6778: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6779: &mt('Standard field').'</label>'.(' 'x2).
6780: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6781: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6782: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6783: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6784: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6785: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6786: foreach my $extra ('roster','passback') {
1.320 raeburn 6787: my $checkedon = '';
6788: my $checkedoff = ' checked="checked"';
1.337 raeburn 6789: if ($extra eq 'passback') {
6790: $pb1p1chk = ' checked="checked"';
6791: $pb1p0chk = '';
1.425 raeburn 6792: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6793: } else {
1.425 raeburn 6794: $onclickpb = '';
1.337 raeburn 6795: }
1.320 raeburn 6796: if (ref($current) eq 'HASH') {
6797: if (($current->{$extra})) {
6798: $checkedon = $checkedoff;
6799: $checkedoff = '';
1.337 raeburn 6800: if ($extra eq 'passback') {
6801: $passbacksty = 'inline-block';
6802: }
6803: if ($current->{'passbackformat'} eq '1.0') {
6804: $pb1p0chk = ' checked="checked"';
6805: $pb1p1chk = '';
6806: }
1.320 raeburn 6807: }
6808: }
6809: $output .= $lt{$extra}.' '.
1.337 raeburn 6810: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6811: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6812: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6813: &mt('Yes').'</label><br />';
6814: }
1.337 raeburn 6815: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6816: '<span class="LC_nobreak">'.&mt('Grade format').
6817: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6818: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6819: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6820: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6821: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6822: $output .= '</span></div></fieldset>';
1.320 raeburn 6823: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6824: #
6825: # $output .= '</fieldset>'.
6826: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6827: return $output;
6828: }
6829:
1.326 raeburn 6830: sub ltimenu_titles {
6831: return &Apache::lonlocal::texthash(
6832: fullname => 'Full name',
6833: coursetitle => 'Course title',
6834: role => 'Role',
6835: logout => 'Logout',
6836: grades => 'Grades',
6837: );
6838: }
6839:
1.434 raeburn 6840: sub linkprot_suggestions {
6841: my ($suggested,$itemcount) = @_;
6842: my $count = 0;
6843: my $next = 1;
6844: my %lt = &Apache::lonlocal::texthash(
6845: 'name' => 'Suggested Launcher',
6846: 'info' => 'Recommendations',
6847: );
6848: my ($datatable,$css_class,$dest);
6849: if (ref($suggested) eq 'HASH') {
6850: my @current = sort { $a <=> $b } keys(%{$suggested});
6851: $next += $current[-1];
6852: for (my $i=0; $i<@current; $i++) {
6853: my $num = $current[$i];
6854: my %values;
6855: if (ref($suggested->{$num}) eq 'HASH') {
6856: %values = %{$suggested->{$num}};
6857: } else {
6858: next;
6859: }
6860: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6861: $datatable .=
6862: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6863: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6864: &mt('Delete?').'</label></span></td><td>'."\n".
6865: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6866: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6867: '</fieldset></div>'.
6868: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6869: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6870: '</fieldset></div>'.
6871: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6872: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6873: $$itemcount ++;
6874: }
6875: }
6876: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6877: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6878: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6879: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6880: '<td>'."\n".
6881: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6882: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6883: '</fieldset></div>'.
6884: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6885: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6886: '</fieldset></div>'.
6887: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6888: '</td></tr>'."\n";
6889: return $datatable;
6890: }
6891:
1.121 raeburn 6892: sub print_coursedefaults {
1.139 raeburn 6893: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6894: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6895: my $itemcount = 1;
1.192 raeburn 6896: my %choices = &Apache::lonlocal::texthash (
6897: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6898: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6899: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6900: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6901: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6902: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6903: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6904: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6905: texengine => 'Default method to display mathematics',
1.257 raeburn 6906: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6907: canclone => "People who may clone a course (besides course's owner and coordinators)",
6908: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6909: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6910: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6911: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6912: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6913: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6914: );
1.198 raeburn 6915: my %staticdefaults = (
6916: anonsurvey_threshold => 10,
6917: uploadquota => 500,
1.428 raeburn 6918: coursequota => 20,
1.257 raeburn 6919: postsubmit => 60,
1.276 raeburn 6920: mysqltables => 172800,
1.422 raeburn 6921: domexttool => 1,
6922: exttool => 0,
1.432 raeburn 6923: crsauthor => 1,
1.438 raeburn 6924: crseditors => ['edit','xml'],
1.198 raeburn 6925: );
1.139 raeburn 6926: if ($position eq 'top') {
1.257 raeburn 6927: %defaultchecked = (
6928: 'canuse_pdfforms' => 'off',
6929: 'uselcmath' => 'on',
6930: 'usejsme' => 'on',
1.398 raeburn 6931: 'inline_chem' => 'on',
1.289 raeburn 6932: 'canclone' => 'none',
1.257 raeburn 6933: );
1.398 raeburn 6934: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6935: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6936: if (ref($settings) eq 'HASH') {
6937: if ($settings->{'texengine'}) {
6938: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6939: $deftex = $settings->{'texengine'};
6940: }
6941: }
6942: }
6943: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6944: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6945: '<span class="LC_nobreak">'.$choices{'texengine'}.
6946: '</span></td><td class="LC_right_item">'.
6947: '<select name="texengine">'."\n";
6948: my %texoptions = (
6949: MathJax => 'MathJax',
6950: mimetex => &mt('Convert to Images'),
6951: tth => &mt('TeX to HTML'),
6952: );
6953: foreach my $renderer ('MathJax','mimetex','tth') {
6954: my $selected = '';
6955: if ($renderer eq $deftex) {
6956: $selected = ' selected="selected"';
6957: }
6958: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6959: }
6960: $mathdisp .= '</select></td></tr>'."\n";
6961: $itemcount ++;
1.139 raeburn 6962: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6963: \%choices,$itemcount);
1.314 raeburn 6964: $datatable = $mathdisp.$datatable;
1.264 raeburn 6965: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6966: $datatable .=
1.306 raeburn 6967: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6968: '<span class="LC_nobreak">'.$choices{'canclone'}.
6969: '</span></td><td class="LC_left_item">';
6970: my $currcanclone = 'none';
6971: my $onclick;
6972: my @cloneoptions = ('none','domain');
1.380 raeburn 6973: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6974: none => 'No additional course requesters',
6975: domain => "Any course requester in course's domain",
6976: instcode => 'Course requests for official courses ...',
6977: );
6978: my (%codedefaults,@code_order,@posscodes);
6979: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6980: \@code_order) eq 'ok') {
6981: if (@code_order > 0) {
6982: push(@cloneoptions,'instcode');
6983: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6984: }
6985: }
6986: if (ref($settings) eq 'HASH') {
6987: if ($settings->{'canclone'}) {
6988: if (ref($settings->{'canclone'}) eq 'HASH') {
6989: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6990: if (@code_order > 0) {
6991: $currcanclone = 'instcode';
6992: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6993: }
6994: }
6995: } elsif ($settings->{'canclone'} eq 'domain') {
6996: $currcanclone = $settings->{'canclone'};
6997: }
6998: }
1.289 raeburn 6999: }
1.264 raeburn 7000: foreach my $option (@cloneoptions) {
7001: my ($checked,$additional);
7002: if ($currcanclone eq $option) {
7003: $checked = ' checked="checked"';
7004: }
7005: if ($option eq 'instcode') {
7006: if (@code_order) {
7007: my $show = 'none';
7008: if ($checked) {
7009: $show = 'block';
7010: }
1.317 raeburn 7011: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7012: &mt('Institutional codes for new and cloned course have identical:').
7013: '<br />';
7014: foreach my $item (@code_order) {
7015: my $codechk;
7016: if ($checked) {
7017: if (grep(/^\Q$item\E$/,@posscodes)) {
7018: $codechk = ' checked="checked"';
7019: }
7020: }
7021: $additional .= '<label>'.
7022: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7023: $item.'</label>';
7024: }
7025: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7026: }
7027: }
7028: $datatable .=
7029: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7030: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7031: '</label> '.$additional.'</span><br />';
7032: }
7033: $datatable .= '</td>'.
7034: '</tr>';
7035: $itemcount ++;
1.139 raeburn 7036: } else {
7037: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7038: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7039: %deftimeout,%currmysql);
1.192 raeburn 7040: my $currusecredits = 0;
1.257 raeburn 7041: my $postsubmitclient = 1;
1.405 raeburn 7042: my $ltiauth = 0;
1.422 raeburn 7043: my %domexttool;
7044: my %exttool;
1.432 raeburn 7045: my %crsauthor;
1.438 raeburn 7046: my %crseditors;
1.271 raeburn 7047: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7048: if (ref($settings) eq 'HASH') {
1.404 raeburn 7049: if ($settings->{'ltiauth'}) {
7050: $ltiauth = 1;
1.405 raeburn 7051: }
1.422 raeburn 7052: if (ref($settings->{'domexttool'}) eq 'HASH') {
7053: foreach my $type (@types) {
7054: if ($settings->{'domexttool'}->{$type}) {
7055: $domexttool{$type} = ' checked="checked"';
7056: }
7057: }
7058: } else {
7059: foreach my $type (@types) {
7060: if ($staticdefaults{'domexttool'}) {
7061: $domexttool{$type} = ' checked="checked"';
7062: }
7063: }
7064: }
7065: if (ref($settings->{'exttool'}) eq 'HASH') {
7066: foreach my $type (@types) {
7067: if ($settings->{'exttool'}->{$type}) {
7068: $exttool{$type} = ' checked="checked"';
7069: }
7070: }
7071: }
1.432 raeburn 7072: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7073: foreach my $type (@types) {
7074: if ($settings->{'crsauthor'}->{$type}) {
7075: $crsauthor{$type} = ' checked="checked"';
7076: }
7077: }
7078: } else {
7079: foreach my $type (@types) {
7080: if ($staticdefaults{'crsauthor'}) {
7081: $crsauthor{$type} = ' checked="checked"';
7082: }
7083: }
7084: }
1.438 raeburn 7085: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7086: foreach my $editor (@{$settings->{'crseditors'}}) {
7087: $crseditors{$editor} = ' checked="checked"';
7088: }
7089: } else {
7090: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7091: $crseditors{$editor} = ' checked="checked"';
7092: }
7093: }
1.139 raeburn 7094: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7095: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7096: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7097: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7098: }
7099: }
1.428 raeburn 7100: if (ref($settings->{'coursequota'}) eq 'HASH') {
7101: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7102: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7103: }
7104: }
1.192 raeburn 7105: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7106: foreach my $type (@types) {
7107: next if ($type eq 'community');
7108: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7109: if ($defcredits{$type} ne '') {
7110: $currusecredits = 1;
7111: }
7112: }
7113: }
7114: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7115: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7116: $postsubmitclient = 0;
7117: foreach my $type (@types) {
7118: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7119: }
7120: } else {
7121: foreach my $type (@types) {
7122: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7123: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7124: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7125: } else {
7126: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7127: }
7128: } else {
7129: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7130: }
7131: }
7132: }
7133: } else {
7134: foreach my $type (@types) {
7135: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7136: }
7137: }
1.276 raeburn 7138: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7139: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7140: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7141: }
7142: } else {
7143: foreach my $type (@types) {
7144: $currmysql{$type} = $staticdefaults{'mysqltables'};
7145: }
7146: }
1.258 raeburn 7147: } else {
7148: foreach my $type (@types) {
7149: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7150: if ($staticdefaults{'domexttool'}) {
7151: $domexttool{$type} = ' checked="checked"';
7152: }
1.432 raeburn 7153: if ($staticdefaults{'crsauthor'}) {
7154: $crsauthor{$type} = ' checked="checked"';
7155: }
1.258 raeburn 7156: }
1.438 raeburn 7157: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7158: $crseditors{$editor} = ' checked="checked"';
7159: }
1.139 raeburn 7160: }
7161: if (!$currdefresponder) {
1.198 raeburn 7162: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7163: } elsif ($currdefresponder < 1) {
7164: $currdefresponder = 1;
7165: }
1.198 raeburn 7166: foreach my $type (@types) {
7167: if ($curruploadquota{$type} eq '') {
7168: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7169: }
1.428 raeburn 7170: if ($currcoursequota{$type} eq '') {
7171: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7172: }
1.198 raeburn 7173: }
1.139 raeburn 7174: $datatable .=
1.192 raeburn 7175: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7176: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7177: '</span></td>'.
7178: '<td class="LC_right_item"><span class="LC_nobreak">'.
7179: '<input type="text" name="anonsurvey_threshold"'.
7180: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7181: '</td></tr>'."\n";
7182: $itemcount ++;
7183: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7184: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7185: $choices{'uploadquota'}.
7186: '</span></td>'.
1.306 raeburn 7187: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7188: '<table><tr>';
1.198 raeburn 7189: foreach my $type (@types) {
1.306 raeburn 7190: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7191: '<input type="text" name="uploadquota_'.$type.'"'.
7192: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7193: }
7194: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7195: $itemcount ++;
1.428 raeburn 7196: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7197: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7198: $choices{'coursequota'}.
7199: '</span></td>'.
7200: '<td style="text-align: right" class="LC_right_item">'.
7201: '<table><tr>';
7202: foreach my $type (@types) {
7203: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7204: '<input type="text" name="coursequota_'.$type.'"'.
7205: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7206: }
7207: $datatable .= '</tr></table></td></tr>'."\n";
7208: $itemcount ++;
1.236 raeburn 7209: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7210: my $display = 'none';
1.192 raeburn 7211: if ($currusecredits) {
7212: $display = 'block';
7213: }
7214: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7215: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7216: foreach my $type (@types) {
7217: next if ($type eq 'community');
1.306 raeburn 7218: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7219: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7220: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7221: }
7222: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7223: %defaultchecked = ('coursecredits' => 'off');
7224: @toggles = ('coursecredits');
7225: my $current = {
7226: 'coursecredits' => $currusecredits,
7227: };
7228: (my $table,$itemcount) =
7229: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7230: \%choices,$itemcount,$onclick,$additional,'left');
7231: $datatable .= $table;
7232: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7233: my $display = 'none';
7234: if ($postsubmitclient) {
7235: $display = 'block';
7236: }
7237: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7238: &mt('Number of seconds submit is disabled').'<br />'.
7239: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7240: '<table><tr>';
1.257 raeburn 7241: foreach my $type (@types) {
1.306 raeburn 7242: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7243: '<input type="text" name="'.$type.'_timeout" value="'.
7244: $deftimeout{$type}.'" size="5" /></td>';
7245: }
7246: $additional .= '</tr></table></div>'."\n";
7247: %defaultchecked = ('postsubmit' => 'on');
7248: @toggles = ('postsubmit');
1.280 raeburn 7249: $current = {
7250: 'postsubmit' => $postsubmitclient,
7251: };
1.257 raeburn 7252: ($table,$itemcount) =
7253: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7254: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7255: $datatable .= $table;
1.276 raeburn 7256: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7257: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7258: $choices{'mysqltables'}.
7259: '</span></td>'.
1.306 raeburn 7260: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7261: '<table><tr>';
7262: foreach my $type (@types) {
1.306 raeburn 7263: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7264: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7265: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7266: }
7267: $datatable .= '</tr></table></td></tr>'."\n";
7268: $itemcount ++;
1.404 raeburn 7269: %defaultchecked = ('ltiauth' => 'off');
7270: @toggles = ('ltiauth');
7271: $current = {
7272: 'ltiauth' => $ltiauth,
7273: };
7274: ($table,$itemcount) =
7275: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7276: \%choices,$itemcount,undef,undef,'left');
7277: $datatable .= $table;
1.422 raeburn 7278: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7279: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7280: $choices{'domexttool'}.
7281: '</span></td>'.
7282: '<td style="text-align: right" class="LC_right_item">'.
7283: '<table><tr>';
7284: foreach my $type (@types) {
7285: $datatable .= '<td style="text-align: left">'.
7286: '<span class="LC_nobreak">'.
1.438 raeburn 7287: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7288: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7289: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7290: }
7291: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7292: $itemcount ++;
1.422 raeburn 7293: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7294: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7295: $choices{'exttool'}.
7296: '</span></td>'.
7297: '<td style="text-align: right" class="LC_right_item">'.
7298: '<table><tr>';
7299: foreach my $type (@types) {
7300: $datatable .= '<td style="text-align: left">'.
7301: '<span class="LC_nobreak">'.
1.438 raeburn 7302: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7303: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7304: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7305: }
7306: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7307: $itemcount ++;
7308: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7309: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7310: $choices{'crsauthor'}.
7311: '</span></td>'.
7312: '<td style="text-align: right" class="LC_right_item">'.
7313: '<table><tr>';
7314: foreach my $type (@types) {
7315: $datatable .= '<td style="text-align: left">'.
7316: '<span class="LC_nobreak">'.
1.438 raeburn 7317: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7318: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7319: &mt($type).'</label></span></td>'."\n";
7320: }
7321: $datatable .= '</tr></table></td></tr>'."\n";
7322: $itemcount ++;
7323: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7324: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7325: $choices{'crseditors'}.
7326: '</span></td>'.
7327: '<td style="text-align: right" class="LC_right_item">'.
7328: '<table><tr>';
7329: my @editors = ('edit','xml','daxe');
7330: my %editornames = &crseditor_titles();
7331: foreach my $editor (@editors) {
7332: $datatable .= '<td style="text-align: left">'.
7333: '<span class="LC_nobreak">'.
7334: '<label><input type="checkbox" name="crseditors"'.
7335: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7336: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7337: }
7338: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7339: }
1.192 raeburn 7340: $$rowtotal += $itemcount;
1.121 raeburn 7341: return $datatable;
1.118 jms 7342: }
7343:
1.438 raeburn 7344: sub crseditor_titles {
7345: return &Apache::lonlocal::texthash(
7346: edit => 'Standard editor (Edit)',
7347: xml => 'Text editor (EditXML)',
7348: daxe => 'Daxe editor (Daxe)',
7349: );
7350: }
7351:
1.429 raeburn 7352: sub print_authordefaults {
7353: my ($position,$dom,$settings,$rowtotal) = @_;
7354: my ($css_class,$datatable,%checkedon,%checkedoff);
7355: my $itemcount = 1;
7356: my %titles = &authordefaults_titles();
7357: if ($position eq 'top') {
7358: my %defaultchecked = (
7359: 'nocodemirror' => 'off',
1.437 raeburn 7360: 'daxecollapse' => 'off',
1.429 raeburn 7361: 'domcoordacc' => 'on',
7362: );
1.437 raeburn 7363: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7364: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7365: \%titles,$itemcount);
7366: my %staticdefaults = (
7367: 'copyright' => 'default',
7368: 'sourceavail' => 'closed',
7369: );
7370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7371: my %currrights;
7372: foreach my $item ('copyright','sourceavail') {
7373: $currrights{$item} = $staticdefaults{$item};
7374: if (ref($settings) eq 'HASH') {
7375: if (exists($settings->{$item})) {
7376: $currrights{$item} = $settings->{$item};
7377: }
7378: }
7379: }
7380: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7381: '<span class="LC_nobreak">'.$titles{'copyright'}.
7382: '</span></td><td class="LC_right_item">'.
7383: &selectbox('copyright',$currrights{'copyright'},'',
7384: \&Apache::loncommon::copyrightdescription,
7385: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7386: '</td></tr>'."\n";
7387: $itemcount ++;
7388: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7389: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7390: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7391: '</span></td><td class="LC_right_item">'.
7392: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7393: \&Apache::loncommon::source_copyrightdescription,
7394: (&Apache::loncommon::source_copyrightids)).
7395: '</td></tr>'."\n";
7396: } else {
7397: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7398: my $curreditors;
7399: my %staticdefaults = (
7400: editors => ['edit','xml'],
7401: authorquota => 500,
7402: webdav => 0,
7403: );
7404: my $curreditors = $staticdefaults{'editors'};
7405: if ((ref($settings) eq 'HASH') &&
7406: (ref($settings->{'editors'}) eq 'ARRAY')) {
7407: $curreditors = $settings->{'editors'};
7408: } else {
7409: $curreditors = $staticdefaults{'editors'};
7410: }
7411: my @editors = ('edit','xml','daxe');
7412: $datatable = '<tr'.$css_class.'>'."\n".
7413: '<td>'.$titles{'editors'}.'</td>'."\n".
7414: '<td class="LC_left_item">'."\n".
7415: '<span class="LC_nobreak">';
7416: foreach my $editor (@editors) {
7417: my $checked;
7418: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7419: $checked = ' checked="checked"';
7420: }
7421: $datatable .= '<label>'.
7422: '<input type="checkbox" name="author_editors" '.
7423: $checked.' value="'.$editor.'" '.
7424: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7425: $titles{$editor}.'</label> ';
7426: }
7427: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7428: $itemcount ++;
7429: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7430: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7431: my @insttypes;
7432: if (ref($types) eq 'ARRAY') {
7433: @insttypes = @{$types};
7434: }
7435: my $typecount = 0;
7436: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7437: my @items = ('webdav','authorquota');
7438: my %quotas;
7439: if (ref($domconf{'quotas'}) eq 'HASH') {
7440: %quotas = %{$domconf{'quotas'}};
7441: foreach my $item (@items) {
7442: if (ref($quotas{$item}) eq 'HASH') {
7443: foreach my $type (@insttypes,'default') {
7444: if ($item eq 'authorquota') {
7445: if ($quotas{$item}{$type} !~ /^\d+$/) {
7446: $quotas{$item}{$type} = $staticdefaults{$item};
7447: }
7448: } elsif ($item eq 'webdav') {
7449: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7450: $quotas{$item}{$type} = $staticdefaults{$item};
7451: }
7452: }
7453: }
7454: } else {
7455: foreach my $type (@insttypes,'default') {
7456: $quotas{$item}{$type} = $staticdefaults{$item};
7457: }
7458: }
7459: }
7460: } else {
7461: foreach my $item (@items) {
7462: foreach my $type (@insttypes,'default') {
7463: $quotas{$item}{$type} = $staticdefaults{$item};
7464: }
7465: }
7466: }
7467: if (ref($usertypes) eq 'HASH') {
7468: my $numinrow = 4;
7469: my $onclick = '';
7470: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7471: $numinrow,$othertitle,'authorquota',
7472: \$itemcount,$onclick);
7473: $itemcount ++;
7474: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7475: $numinrow,$othertitle,'webdav',
7476: \$itemcount);
7477: $itemcount ++;
7478: }
7479: my $checkedno = ' checked="checked"';
7480: my ($checkedon,$checkedoff);
7481: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7482: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7483: if ($quotas{'webdav'}{'_LC_adv'}) {
7484: $checkedon = $checkedno;
7485: } else {
7486: $checkedoff = $checkedno;
7487: }
7488: undef($checkedno);
7489: }
7490: }
7491: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7492: $datatable .= '<tr'.$css_class.'>'.
7493: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7494: $titles{'webdav_LC_adv_over'}.
7495: '</td>'.
7496: '<td class="LC_left_item">';
7497: foreach my $option ('none','off','on') {
7498: my ($text,$val,$checked);
7499: if ($option eq 'none') {
7500: $text = $titles{'none'};
7501: $val = '';
7502: $checked = $checkedno;
7503: } elsif ($option eq 'off') {
7504: $text = $titles{'overoff'};
7505: $val = 0;
7506: $checked = $checkedoff;
7507: } elsif ($option eq 'on') {
7508: $text = $titles{'overon'};
7509: $val = 1;
7510: $checked = $checkedon;
1.436 raeburn 7511: }
1.429 raeburn 7512: $datatable .= '<span class="LC_nobreak"><label>'.
7513: '<input type="radio" name="webdav_LC_adv"'.
7514: ' value="'.$val.'"'.$checked.' />'.
7515: $text.'</label></span> ';
7516: }
7517: $datatable .= '</td></tr>';
7518: $itemcount ++;
1.440 raeburn 7519: my %defchecked = (
7520: 'archive' => 'off',
7521: );
7522: my @toggles = ('archive');
7523: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7524: {'archive' => 'off'},
7525: \%titles,$itemcount);
7526: $datatable .= $archive."\n";
7527: $itemcount ++;
1.429 raeburn 7528: }
7529: $$rowtotal += $itemcount;
7530: return $datatable;
7531: }
7532:
7533: sub authordefaults_titles {
7534: return &Apache::lonlocal::texthash(
7535: copyright => 'Copyright/Distribution',
7536: sourceavail => ' Source Available',
7537: editors => 'Available Editors',
7538: webdav => 'WebDAV',
7539: authorquota => 'Authoring Space quotas (MB)',
7540: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7541: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7542: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7543: edit => 'Standard editor (Edit)',
7544: xml => 'Text editor (EditXML)',
7545: daxe => 'Daxe editor (Daxe)',
7546: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7547: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7548: none => 'No override set',
7549: overon => 'Override -- webDAV on',
1.436 raeburn 7550: overoff => 'Override -- webDAV off',
1.440 raeburn 7551: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7552: );
7553: }
7554:
7555: sub selectbox {
7556: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7557: my $selout = '<select name="'.$name.'">';
7558: foreach my $id (@idlist) {
7559: $selout.='<option value="'.$id.'"';
7560: if ($id eq $value) {
7561: $selout.=' selected="selected"';
7562: }
7563: if ($readonly) {
7564: $selout .= ' disabled="disabled"';
7565: }
7566: $selout.='>'.&{$functionref}($id).'</option>';
7567: }
7568: $selout.='</select>';
7569: return $selout;
7570: }
7571:
1.231 raeburn 7572: sub print_selfenrollment {
7573: my ($position,$dom,$settings,$rowtotal) = @_;
7574: my ($css_class,$datatable);
7575: my $itemcount = 1;
1.271 raeburn 7576: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7577: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7578: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7579: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7580: my @rows;
7581: my $key;
7582: if ($position eq 'top') {
7583: $key = 'admin';
7584: if (ref($rowsref) eq 'ARRAY') {
7585: @rows = @{$rowsref};
7586: }
7587: } elsif ($position eq 'middle') {
7588: $key = 'default';
7589: @rows = ('types','registered','approval','limit');
7590: }
7591: foreach my $row (@rows) {
7592: if (defined($titlesref->{$row})) {
7593: $itemcount ++;
7594: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7595: $datatable .= '<tr'.$css_class.'>'.
7596: '<td>'.$titlesref->{$row}.'</td>'.
7597: '<td class="LC_left_item">'.
7598: '<table><tr>';
7599: my (%current,%currentcap);
7600: if (ref($settings) eq 'HASH') {
7601: if (ref($settings->{$key}) eq 'HASH') {
7602: foreach my $type (@types) {
7603: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7604: $current{$type} = $settings->{$key}->{$type}->{$row};
7605: }
7606: if (($row eq 'limit') && ($key eq 'default')) {
7607: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7608: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7609: }
7610: }
7611: }
7612: }
7613: }
7614: my %roles = (
7615: '0' => &Apache::lonnet::plaintext('dc'),
7616: );
7617:
7618: foreach my $type (@types) {
7619: unless (($row eq 'registered') && ($key eq 'default')) {
7620: $datatable .= '<th>'.&mt($type).'</th>';
7621: }
7622: }
7623: unless (($row eq 'registered') && ($key eq 'default')) {
7624: $datatable .= '</tr><tr>';
7625: }
7626: foreach my $type (@types) {
7627: if ($type eq 'community') {
7628: $roles{'1'} = &mt('Community personnel');
7629: } else {
7630: $roles{'1'} = &mt('Course personnel');
7631: }
7632: $datatable .= '<td style="vertical-align: top">';
7633: if ($position eq 'top') {
7634: my %checked;
7635: if ($current{$type} eq '0') {
7636: $checked{'0'} = ' checked="checked"';
7637: } else {
7638: $checked{'1'} = ' checked="checked"';
7639: }
7640: foreach my $role ('1','0') {
7641: $datatable .= '<span class="LC_nobreak"><label>'.
7642: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7643: 'value="'.$role.'"'.$checked{$role}.' />'.
7644: $roles{$role}.'</label></span> ';
7645: }
7646: } else {
7647: if ($row eq 'types') {
7648: my %checked;
7649: if ($current{$type} =~ /^(all|dom)$/) {
7650: $checked{$1} = ' checked="checked"';
7651: } else {
7652: $checked{''} = ' checked="checked"';
7653: }
7654: foreach my $val ('','dom','all') {
7655: $datatable .= '<span class="LC_nobreak"><label>'.
7656: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7657: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7658: }
7659: } elsif ($row eq 'registered') {
7660: my %checked;
7661: if ($current{$type} eq '1') {
7662: $checked{'1'} = ' checked="checked"';
7663: } else {
7664: $checked{'0'} = ' checked="checked"';
7665: }
7666: foreach my $val ('0','1') {
7667: $datatable .= '<span class="LC_nobreak"><label>'.
7668: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7669: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7670: }
7671: } elsif ($row eq 'approval') {
7672: my %checked;
7673: if ($current{$type} =~ /^([12])$/) {
7674: $checked{$1} = ' checked="checked"';
7675: } else {
7676: $checked{'0'} = ' checked="checked"';
7677: }
7678: for my $val (0..2) {
7679: $datatable .= '<span class="LC_nobreak"><label>'.
7680: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7681: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7682: }
7683: } elsif ($row eq 'limit') {
7684: my %checked;
7685: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7686: $checked{$1} = ' checked="checked"';
7687: } else {
7688: $checked{'none'} = ' checked="checked"';
7689: }
7690: my $cap;
7691: if ($currentcap{$type} =~ /^\d+$/) {
7692: $cap = $currentcap{$type};
7693: }
7694: foreach my $val ('none','allstudents','selfenrolled') {
7695: $datatable .= '<span class="LC_nobreak"><label>'.
7696: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7697: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7698: }
7699: $datatable .= '<br />'.
7700: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7701: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7702: '</span>';
7703: }
7704: }
7705: $datatable .= '</td>';
7706: }
7707: $datatable .= '</tr>';
7708: }
7709: $datatable .= '</table></td></tr>';
7710: }
7711: } elsif ($position eq 'bottom') {
1.235 raeburn 7712: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7713: }
7714: $$rowtotal += $itemcount;
7715: return $datatable;
7716: }
7717:
7718: sub print_validation_rows {
7719: my ($caller,$dom,$settings,$rowtotal) = @_;
7720: my ($itemsref,$namesref,$fieldsref);
7721: if ($caller eq 'selfenroll') {
7722: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7723: } elsif ($caller eq 'requestcourses') {
7724: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7725: }
7726: my %currvalidation;
7727: if (ref($settings) eq 'HASH') {
7728: if (ref($settings->{'validation'}) eq 'HASH') {
7729: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7730: }
1.235 raeburn 7731: }
7732: my $datatable;
7733: my $itemcount = 0;
7734: foreach my $item (@{$itemsref}) {
7735: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7736: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7737: $namesref->{$item}.
7738: '</span></td>'.
7739: '<td class="LC_left_item">';
7740: if (($item eq 'url') || ($item eq 'button')) {
7741: $datatable .= '<span class="LC_nobreak">'.
7742: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7743: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7744: } elsif ($item eq 'fields') {
7745: my @currfields;
7746: if (ref($currvalidation{$item}) eq 'ARRAY') {
7747: @currfields = @{$currvalidation{$item}};
7748: }
7749: foreach my $field (@{$fieldsref}) {
7750: my $check = '';
7751: if (grep(/^\Q$field\E$/,@currfields)) {
7752: $check = ' checked="checked"';
7753: }
7754: $datatable .= '<span class="LC_nobreak"><label>'.
7755: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7756: ' value="'.$field.'"'.$check.' />'.$field.
7757: '</label></span> ';
7758: }
7759: } elsif ($item eq 'markup') {
1.334 raeburn 7760: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7761: $currvalidation{$item}.
1.231 raeburn 7762: '</textarea>';
1.235 raeburn 7763: }
7764: $datatable .= '</td></tr>'."\n";
7765: if (ref($rowtotal)) {
1.231 raeburn 7766: $itemcount ++;
7767: }
7768: }
1.235 raeburn 7769: if ($caller eq 'requestcourses') {
7770: my %currhash;
1.248 raeburn 7771: if (ref($settings) eq 'HASH') {
7772: if (ref($settings->{'validation'}) eq 'HASH') {
7773: if ($settings->{'validation'}{'dc'} ne '') {
7774: $currhash{$settings->{'validation'}{'dc'}} = 1;
7775: }
1.235 raeburn 7776: }
7777: }
7778: my $numinrow = 2;
7779: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7780: 'validationdc',%currhash);
1.247 raeburn 7781: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7782: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7783: if ($numdc > 1) {
1.247 raeburn 7784: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7785: } else {
1.247 raeburn 7786: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7787: }
1.247 raeburn 7788: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7789: $itemcount ++;
7790: }
7791: if (ref($rowtotal)) {
7792: $$rowtotal += $itemcount;
7793: }
1.231 raeburn 7794: return $datatable;
7795: }
7796:
1.357 raeburn 7797: sub print_privacy {
7798: my ($position,$dom,$settings,$rowtotal) = @_;
7799: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7800: my $itemcount = 0;
1.417 raeburn 7801: if ($position eq 'top') {
7802: $numinrow = 2;
7803: } else {
1.357 raeburn 7804: @items = ('domain','author','course','community');
7805: %names = &Apache::lonlocal::texthash (
7806: domain => 'Assigned domain role(s)',
7807: author => 'Assigned co-author role(s)',
7808: course => 'Assigned course role(s)',
1.416 raeburn 7809: community => 'Assigned community role(s)',
1.357 raeburn 7810: );
7811: $numinrow = 4;
7812: ($othertitle,$usertypes,$types) =
7813: &Apache::loncommon::sorted_inst_types($dom);
7814: }
7815: if (($position eq 'top') || ($position eq 'middle')) {
7816: my (%by_ip,%by_location,@intdoms,@instdoms);
7817: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7818: if ($position eq 'top') {
7819: my %curr;
7820: my @options = ('none','user','domain','auto');
7821: my %titles = &Apache::lonlocal::texthash (
7822: none => 'Not allowed',
7823: user => 'User authorizes',
7824: domain => 'DC authorizes',
7825: auto => 'Unrestricted',
7826: instdom => 'Other domain shares institution/provider',
7827: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7828: notify => 'Notify when role needs authorization',
1.357 raeburn 7829: );
7830: my %names = &Apache::lonlocal::texthash (
7831: domain => 'Domain role',
7832: author => 'Co-author role',
7833: course => 'Course role',
7834: community => 'Community role',
7835: );
7836: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7837: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7838: foreach my $domtype ('instdom','extdom') {
7839: my (%checked,$skip);
7840: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7841: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7842: '<td class="LC_left_item">';
7843: if ($domtype eq 'instdom') {
7844: unless (@instdoms > 1) {
7845: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7846: $skip = 1;
7847: }
7848: } elsif ($domtype eq 'extdom') {
7849: if (keys(%by_location) == 0) {
7850: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7851: $skip = 1;
7852: }
7853: }
7854: unless ($skip) {
7855: foreach my $roletype ('domain','author','course','community') {
7856: $checked{'auto'} = ' checked="checked"';
7857: if (ref($settings) eq 'HASH') {
7858: if (ref($settings->{approval}) eq 'HASH') {
7859: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7860: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7861: $checked{$1} = ' checked="checked"';
7862: $checked{'auto'} = '';
7863: }
7864: }
7865: }
7866: }
7867: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7868: foreach my $option (@options) {
7869: $datatable .= '<span class="LC_nobreak"><label>'.
7870: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7871: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7872: '</label></span> ';
7873: }
7874: $datatable .= '</fieldset>';
7875: }
7876: }
7877: $datatable .= '</td></tr>';
7878: $itemcount ++;
7879: }
1.417 raeburn 7880: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7881: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7882: '<td class="LC_left_item">';
7883: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7884: my %curr;
7885: if (ref($settings) eq 'HASH') {
7886: if ($settings->{'notify'} ne '') {
7887: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7888: }
7889: }
7890: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7891: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7892: 'privacy_notify',%curr);
7893: if ($numdc > 0) {
7894: $datatable .= $table;
7895: } else {
7896: $datatable .= &mt('There are no active Domain Coordinators');
7897: }
7898: } else {
7899: $datatable .= &mt('Nothing to set here, as there are no other domains');
7900: }
7901: $datatable .='</td></tr>';
1.357 raeburn 7902: } elsif ($position eq 'middle') {
7903: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7904: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7905: foreach my $item (@{$types}) {
7906: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7907: $numinrow,$itemcount,'','','','','',
7908: '',$usertypes->{$item});
7909: $itemcount ++;
7910: }
7911: }
7912: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7913: $numinrow,$itemcount,'','','','','',
7914: '',$othertitle);
7915: $itemcount ++;
7916: } else {
1.360 raeburn 7917: my (@insttypes,%insttitles);
7918: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7919: @insttypes = @{$types};
7920: %insttitles = %{$usertypes};
7921: }
7922: foreach my $item (@insttypes,'default') {
7923: my $title;
7924: if ($item eq 'default') {
7925: $title = $othertitle;
7926: } else {
7927: $title = $insttitles{$item};
7928: }
7929: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7930: $datatable .= '<tr'.$css_class.'>'.
7931: '<td class="LC_left_item">'.$title.'</td>'.
7932: '<td class="LC_left_item">'.
7933: &mt('Nothing to set here, as there are no other domains').
7934: '</td></tr>';
7935: $itemcount ++;
7936: }
1.357 raeburn 7937: }
7938: }
7939: } else {
7940: my $prefix;
7941: if ($position eq 'lower') {
7942: $prefix = 'priv';
7943: } else {
7944: $prefix = 'unpriv';
7945: }
7946: foreach my $item (@items) {
7947: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7948: $numinrow,$itemcount,'','','','','',
7949: '',$names{$item});
7950: $itemcount ++;
7951: }
7952: }
7953: if (ref($rowtotal)) {
7954: $$rowtotal += $itemcount;
7955: }
7956: return $datatable;
7957: }
7958:
1.354 raeburn 7959: sub print_passwords {
7960: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7961: my ($datatable,$css_class);
7962: my $itemcount = 0;
7963: my %titles = &Apache::lonlocal::texthash (
7964: captcha => '"Forgot Password" CAPTCHA validation',
7965: link => 'Reset link expiration (hours)',
7966: case => 'Case-sensitive usernames/e-mail',
7967: prelink => 'Information required (form 1)',
7968: postlink => 'Information required (form 2)',
7969: emailsrc => 'LON-CAPA e-mail address type(s)',
7970: customtext => 'Domain specific text (HTML)',
7971: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7972: intauth_check => 'Check bcrypt cost if authenticated',
7973: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7974: permanent => 'Permanent e-mail address',
7975: critical => 'Critical notification address',
7976: notify => 'Notification address',
7977: min => 'Minimum password length',
7978: max => 'Maximum password length',
7979: chars => 'Required characters',
7980: expire => 'Password expiration (days)',
1.356 raeburn 7981: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7982: );
7983: if ($position eq 'top') {
7984: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7985: my $shownlinklife = 2;
7986: my $prelink = 'both';
7987: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7988: if (ref($settings) eq 'HASH') {
7989: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7990: $shownlinklife = $settings->{resetlink};
7991: }
7992: if (ref($settings->{resetcase}) eq 'ARRAY') {
7993: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7994: }
7995: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7996: $prelink = $settings->{resetprelink};
7997: }
7998: if (ref($settings->{resetpostlink}) eq 'HASH') {
7999: %postlink = %{$settings->{resetpostlink}};
8000: }
8001: if (ref($settings->{resetemail}) eq 'ARRAY') {
8002: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8003: }
8004: if ($settings->{resetremove}) {
8005: $nostdtext = 1;
8006: }
8007: if ($settings->{resetcustom}) {
8008: $customurl = $settings->{resetcustom};
8009: }
8010: } else {
8011: if (ref($types) eq 'ARRAY') {
8012: foreach my $item (@{$types}) {
8013: $casesens{$item} = 1;
8014: $postlink{$item} = ['username','email'];
8015: }
8016: }
8017: $casesens{'default'} = 1;
8018: $postlink{'default'} = ['username','email'];
8019: $prelink = 'both';
8020: %emailsrc = (
8021: permanent => 1,
8022: critical => 1,
8023: notify => 1,
8024: );
8025: }
8026: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8027: $itemcount ++;
8028: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8029: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8030: '<td class="LC_left_item">'.
8031: '<input type="textbox" value="'.$shownlinklife.'" '.
8032: 'name="passwords_link" size="3" /></td></tr>';
8033: $itemcount ++;
8034: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8035: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8036: '<td class="LC_left_item">';
8037: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8038: foreach my $item (@{$types}) {
8039: my $checkedcase;
8040: if ($casesens{$item}) {
8041: $checkedcase = ' checked="checked"';
8042: }
8043: $datatable .= '<span class="LC_nobreak"><label>'.
8044: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8045: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8046: '</span> ';
1.354 raeburn 8047: }
8048: }
8049: my $checkedcase;
8050: if ($casesens{'default'}) {
8051: $checkedcase = ' checked="checked"';
8052: }
8053: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8054: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8055: $othertitle.'</label></span></td>';
8056: $itemcount ++;
8057: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8058: my %checkedpre = (
8059: both => ' checked="checked"',
8060: either => '',
8061: );
8062: if ($prelink eq 'either') {
8063: $checkedpre{either} = ' checked="checked"';
8064: $checkedpre{both} = '';
8065: }
8066: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8067: '<td class="LC_left_item"><span class="LC_nobreak">'.
8068: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8069: &mt('Both username and e-mail address').'</label></span> '.
8070: '<span class="LC_nobreak"><label>'.
8071: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8072: &mt('Either username or e-mail address').'</label></span></td></tr>';
8073: $itemcount ++;
8074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8076: '<td class="LC_left_item">';
8077: my %postlinked;
8078: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8079: foreach my $item (@{$types}) {
8080: undef(%postlinked);
8081: $datatable .= '<fieldset style="display: inline-block;">'.
8082: '<legend>'.$usertypes->{$item}.'</legend>';
8083: if (ref($postlink{$item}) eq 'ARRAY') {
8084: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8085: }
8086: foreach my $field ('email','username') {
8087: my $checked;
8088: if ($postlinked{$field}) {
8089: $checked = ' checked="checked"';
8090: }
8091: $datatable .= '<span class="LC_nobreak"><label>'.
8092: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8093: $field.'"'.$checked.' />'.$field.'</label>'.
8094: '<span> ';
8095: }
8096: $datatable .= '</fieldset>';
8097: }
8098: }
8099: if (ref($postlink{'default'}) eq 'ARRAY') {
8100: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8101: }
8102: $datatable .= '<fieldset style="display: inline-block;">'.
8103: '<legend>'.$othertitle.'</legend>';
8104: foreach my $field ('email','username') {
8105: my $checked;
8106: if ($postlinked{$field}) {
8107: $checked = ' checked="checked"';
8108: }
8109: $datatable .= '<span class="LC_nobreak"><label>'.
8110: '<input type="checkbox" name="passwords_postlink_default" value="'.
8111: $field.'"'.$checked.' />'.$field.'</label>'.
8112: '<span> ';
8113: }
8114: $datatable .= '</fieldset></td></tr>';
8115: $itemcount ++;
8116: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8117: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8118: '<td class="LC_left_item">';
8119: foreach my $type ('permanent','critical','notify') {
8120: my $checkedemail;
8121: if ($emailsrc{$type}) {
8122: $checkedemail = ' checked="checked"';
8123: }
8124: $datatable .= '<span class="LC_nobreak"><label>'.
8125: '<input type="checkbox" name="passwords_emailsrc" value="'.
8126: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8127: '<span> ';
8128: }
8129: $datatable .= '</td></tr>';
8130: $itemcount ++;
8131: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8132: my $switchserver = &check_switchserver($dom,$confname);
8133: my ($showstd,$noshowstd);
8134: if ($nostdtext) {
8135: $noshowstd = ' checked="checked"';
8136: } else {
8137: $showstd = ' checked="checked"';
8138: }
8139: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8140: '<td class="LC_left_item"><span class="LC_nobreak">'.
8141: &mt('Retain standard text:').
8142: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8143: &mt('Yes').'</label>'.' '.
8144: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8145: &mt('No').'</label></span><br />'.
8146: '<span class="LC_fontsize_small">'.
8147: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8148: &mt('Include custom text:');
8149: if ($customurl) {
1.369 raeburn 8150: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8151: undef,undef,undef,undef,'background-color:#ffffff');
8152: $datatable .= '<span class="LC_nobreak"> '.$link.
8153: '<label><input type="checkbox" name="passwords_custom_del"'.
8154: ' value="1" />'.&mt('Delete?').'</label></span>'.
8155: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8156: }
8157: if ($switchserver) {
8158: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8159: } else {
8160: $datatable .='<span class="LC_nobreak"> '.
8161: '<input type="file" name="passwords_customfile" /></span>';
8162: }
8163: $datatable .= '</td></tr>';
8164: } elsif ($position eq 'middle') {
8165: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8166: my @items = ('intauth_cost','intauth_check','intauth_switch');
8167: my %defaults;
8168: if (ref($domconf{'defaults'}) eq 'HASH') {
8169: %defaults = %{$domconf{'defaults'}};
8170: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8171: $defaults{'intauth_cost'} = 10;
8172: }
8173: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8174: $defaults{'intauth_check'} = 0;
8175: }
8176: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8177: $defaults{'intauth_switch'} = 0;
8178: }
8179: } else {
8180: %defaults = (
8181: 'intauth_cost' => 10,
8182: 'intauth_check' => 0,
8183: 'intauth_switch' => 0,
8184: );
8185: }
8186: foreach my $item (@items) {
8187: if ($itemcount%2) {
8188: $css_class = '';
8189: } else {
8190: $css_class = ' class="LC_odd_row" ';
8191: }
8192: $datatable .= '<tr'.$css_class.'>'.
8193: '<td><span class="LC_nobreak">'.$titles{$item}.
8194: '</span></td><td class="LC_left_item" colspan="3">';
8195: if ($item eq 'intauth_switch') {
8196: my @options = (0,1,2);
8197: my %optiondesc = &Apache::lonlocal::texthash (
8198: 0 => 'No',
8199: 1 => 'Yes',
8200: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8201: );
8202: $datatable .= '<table width="100%">';
8203: foreach my $option (@options) {
8204: my $checked = ' ';
8205: if ($defaults{$item} eq $option) {
8206: $checked = ' checked="checked"';
8207: }
8208: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8209: '<label><input type="radio" name="'.$item.
8210: '" value="'.$option.'"'.$checked.' />'.
8211: $optiondesc{$option}.'</label></span></td></tr>';
8212: }
8213: $datatable .= '</table>';
8214: } elsif ($item eq 'intauth_check') {
8215: my @options = (0,1,2);
8216: my %optiondesc = &Apache::lonlocal::texthash (
8217: 0 => 'No',
8218: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8219: 2 => 'Yes, disallow login if stored cost is less than domain default',
8220: );
8221: $datatable .= '<table width="100%">';
8222: foreach my $option (@options) {
8223: my $checked = ' ';
8224: my $onclick;
8225: if ($defaults{$item} eq $option) {
8226: $checked = ' checked="checked"';
8227: }
8228: if ($option == 2) {
8229: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8230: }
8231: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8232: '<label><input type="radio" name="'.$item.
8233: '" value="'.$option.'"'.$checked.$onclick.' />'.
8234: $optiondesc{$option}.'</label></span></td></tr>';
8235: }
8236: $datatable .= '</table>';
8237: } else {
8238: $datatable .= '<input type="text" name="'.$item.'" value="'.
8239: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8240: }
8241: $datatable .= '</td></tr>';
8242: $itemcount ++;
8243: }
8244: } elsif ($position eq 'lower') {
1.405 raeburn 8245: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8246: } else {
1.359 raeburn 8247: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8248: my %ownerchg = (
8249: by => {},
8250: for => {},
8251: );
8252: my %ownertitles = &Apache::lonlocal::texthash (
8253: by => 'Course owner status(es) allowed',
8254: for => 'Student status(es) allowed',
8255: );
1.354 raeburn 8256: if (ref($settings) eq 'HASH') {
1.359 raeburn 8257: if (ref($settings->{crsownerchg}) eq 'HASH') {
8258: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8259: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8260: }
8261: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8262: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8263: }
1.354 raeburn 8264: }
8265: }
8266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8267: $datatable .= '<tr '.$css_class.'>'.
8268: '<td>'.
8269: &mt('Requirements').'<ul>'.
1.359 raeburn 8270: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8271: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8272: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8273: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8274: '</ul>'.
8275: '</td>'.
1.359 raeburn 8276: '<td class="LC_left_item">';
8277: foreach my $item ('by','for') {
8278: $datatable .= '<fieldset style="display: inline-block;">'.
8279: '<legend>'.$ownertitles{$item}.'</legend>';
8280: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8281: foreach my $type (@{$types}) {
8282: my $checked;
8283: if ($ownerchg{$item}{$type}) {
8284: $checked = ' checked="checked"';
8285: }
8286: $datatable .= '<span class="LC_nobreak"><label>'.
8287: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8288: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8289: '</span> ';
1.359 raeburn 8290: }
8291: }
8292: my $checked;
8293: if ($ownerchg{$item}{'default'}) {
8294: $checked = ' checked="checked"';
8295: }
8296: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8297: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8298: $othertitle.'</label></span></fieldset>';
8299: }
8300: $datatable .= '</td></tr>';
1.354 raeburn 8301: }
8302: return $datatable;
8303: }
8304:
1.405 raeburn 8305: sub password_rules {
8306: my ($prefix,$itemcountref,$settings) = @_;
8307: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8308: my %titles;
8309: if ($prefix eq 'passwords') {
8310: %titles = &Apache::lonlocal::texthash (
8311: min => 'Minimum password length',
8312: max => 'Maximum password length',
8313: chars => 'Required characters',
8314: );
1.421 raeburn 8315: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8316: %titles = &Apache::lonlocal::texthash (
8317: min => 'Minimum secret length',
8318: max => 'Maximum secret length',
8319: chars => 'Required characters',
8320: );
8321: }
8322: $min = $Apache::lonnet::passwdmin;
8323: my $datatable;
8324: my $itemcount;
8325: if (ref($itemcountref)) {
8326: $itemcount = $$itemcountref;
8327: }
8328: if (ref($settings) eq 'HASH') {
8329: if ($settings->{min}) {
8330: $min = $settings->{min};
8331: }
8332: if ($settings->{max}) {
8333: $max = $settings->{max};
8334: }
8335: if (ref($settings->{chars}) eq 'ARRAY') {
8336: map { $chars{$_} = 1; } (@{$settings->{chars}});
8337: }
1.425 raeburn 8338: if ($prefix eq 'passwords') {
1.405 raeburn 8339: if ($settings->{expire}) {
8340: $expire = $settings->{expire};
8341: }
8342: if ($settings->{numsaved}) {
8343: $numsaved = $settings->{numsaved};
8344: }
8345: }
8346: }
8347: my %rulenames = &Apache::lonlocal::texthash(
8348: uc => 'At least one upper case letter',
8349: lc => 'At least one lower case letter',
8350: num => 'At least one number',
8351: spec => 'At least one non-alphanumeric',
8352: );
8353: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8354: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8355: '<td class="LC_left_item"><span class="LC_nobreak">'.
8356: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8357: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8358: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8359: '</span></td></tr>';
8360: $itemcount ++;
8361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8362: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8363: '<td class="LC_left_item"><span class="LC_nobreak">'.
8364: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8365: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8366: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8367: '</span></td></tr>';
8368: $itemcount ++;
8369: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8370: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8371: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8372: '</span></td>';
8373: my $numinrow = 2;
8374: my @possrules = ('uc','lc','num','spec');
8375: $datatable .= '<td class="LC_left_item"><table>';
8376: for (my $i=0; $i<@possrules; $i++) {
8377: my ($rem,$checked);
8378: if ($chars{$possrules[$i]}) {
8379: $checked = ' checked="checked"';
8380: }
8381: $rem = $i%($numinrow);
8382: if ($rem == 0) {
8383: if ($i > 0) {
8384: $datatable .= '</tr>';
8385: }
8386: $datatable .= '<tr>';
8387: }
8388: $datatable .= '<td><span class="LC_nobreak"><label>'.
8389: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8390: $rulenames{$possrules[$i]}.'</label></span></td>';
8391: }
8392: my $rem = @possrules%($numinrow);
8393: my $colsleft = $numinrow - $rem;
8394: if ($colsleft > 1 ) {
8395: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8396: ' </td>';
8397: } elsif ($colsleft == 1) {
8398: $datatable .= '<td class="LC_left_item"> </td>';
8399: }
8400: $datatable .='</table></td></tr>';
8401: $itemcount ++;
8402: if ($prefix eq 'passwords') {
8403: $titles{'expire'} = &mt('Password expiration (days)');
8404: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8405: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8406: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8407: '<td class="LC_left_item"><span class="LC_nobreak">'.
8408: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8409: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8410: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8411: '</span></td></tr>';
8412: $itemcount ++;
8413: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8414: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8415: '<td class="LC_left_item"><span class="LC_nobreak">'.
8416: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8417: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8418: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8419: '</span></td></tr>';
8420: $itemcount ++;
8421: }
8422: if (ref($itemcountref)) {
8423: $$itemcountref += $itemcount;
8424: }
8425: return $datatable;
8426: }
8427:
1.373 raeburn 8428: sub print_wafproxy {
8429: my ($position,$dom,$settings,$rowtotal) = @_;
8430: my $css_class;
8431: my $itemcount = 0;
8432: my $datatable;
8433: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8434: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8435: my %lt = &wafproxy_titles();
1.373 raeburn 8436: foreach my $server (sort(keys(%servers))) {
8437: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8438: next if ($serverhome eq '');
1.373 raeburn 8439: my $serverdom;
8440: if ($serverhome ne $server) {
8441: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8442: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8443: $othercontrol{$server} = $serverdom;
8444: }
1.373 raeburn 8445: } else {
8446: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8447: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8448: if ($serverdom ne $dom) {
8449: $othercontrol{$server} = $serverdom;
8450: } else {
8451: $setdom = 1;
8452: if (ref($settings) eq 'HASH') {
8453: if (ref($settings->{'alias'}) eq 'HASH') {
8454: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8455: if ($aliases{$dom} ne '') {
8456: $showdom = 1;
8457: }
1.373 raeburn 8458: }
1.388 raeburn 8459: if (ref($settings->{'saml'}) eq 'HASH') {
8460: $saml{$dom} = $settings->{'saml'};
8461: }
1.373 raeburn 8462: }
8463: }
8464: }
8465: }
1.381 raeburn 8466: if ($setdom) {
8467: %{$values{$dom}} = ();
8468: if (ref($settings) eq 'HASH') {
8469: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8470: $values{$dom}{$item} = $settings->{$item};
8471: }
8472: }
8473: }
1.373 raeburn 8474: if (keys(%othercontrol)) {
8475: %otherdoms = reverse(%othercontrol);
8476: foreach my $domain (keys(%otherdoms)) {
8477: %{$values{$domain}} = ();
8478: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8479: if (ref($config{'wafproxy'}) eq 'HASH') {
8480: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8481: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8482: $saml{$domain} = $config{'wafproxy'}{'saml'};
8483: }
1.383 raeburn 8484: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8485: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8486: }
8487: }
8488: }
8489: }
8490: if ($position eq 'top') {
8491: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8492: my %aliasinfo;
1.373 raeburn 8493: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8494: $itemcount ++;
8495: my $dom_in_effect;
8496: my $aliasrows = '<tr>'.
1.383 raeburn 8497: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8498: &mt('Hostname').': '.
8499: '<span class="LC_nobreak LC_cusr_emph">'.
8500: &Apache::lonnet::hostname($server).
8501: '</span></td><td> </td>';
1.373 raeburn 8502: if ($othercontrol{$server}) {
1.381 raeburn 8503: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8504: my ($current,$forsaml);
1.383 raeburn 8505: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8506: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8507: }
1.388 raeburn 8508: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8509: if ($saml{$dom_in_effect}{$server}) {
8510: $forsaml = 1;
8511: }
8512: }
1.383 raeburn 8513: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8514: &mt('Alias').': ';
1.373 raeburn 8515: if ($current) {
1.381 raeburn 8516: $aliasrows .= $current;
1.388 raeburn 8517: if ($forsaml) {
1.396 raeburn 8518: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8519: }
1.373 raeburn 8520: } else {
1.383 raeburn 8521: $aliasrows .= &mt('None');
1.373 raeburn 8522: }
1.383 raeburn 8523: $aliasrows .= ' <span class="LC_small">('.
8524: &mt('controlled by domain: [_1]',
8525: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8526: } else {
1.381 raeburn 8527: $dom_in_effect = $dom;
1.388 raeburn 8528: my ($current,$samlon,$samloff);
8529: $samloff = ' checked="checked"';
1.373 raeburn 8530: if (ref($aliases{$dom}) eq 'HASH') {
8531: if ($aliases{$dom}{$server}) {
8532: $current = $aliases{$dom}{$server};
8533: }
8534: }
1.388 raeburn 8535: if (ref($saml{$dom}) eq 'HASH') {
8536: if ($saml{$dom}{$server}) {
8537: $samlon = $samloff;
8538: undef($samloff);
8539: }
8540: }
1.383 raeburn 8541: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8542: &mt('Alias').': '.
1.381 raeburn 8543: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8544: 'value="'.$current.'" size="30" />'.
8545: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8546: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8547: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8548: &mt('No').'</label> <label>'.
1.388 raeburn 8549: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8550: &mt('Yes').'</label></span>'.
1.425 raeburn 8551: '</td>';
1.381 raeburn 8552: }
8553: $aliasrows .= '</tr>';
8554: $aliasinfo{$dom_in_effect} .= $aliasrows;
8555: }
8556: if ($aliasinfo{$dom}) {
8557: my ($onclick,$wafon,$wafoff,$showtable);
8558: $onclick = ' onclick="javascript:toggleWAF();"';
8559: $wafoff = ' checked="checked"';
8560: $showtable = ' style="display:none";';
8561: if ($showdom) {
8562: $wafon = $wafoff;
8563: $wafoff = '';
8564: $showtable = ' style="display:inline;"';
8565: }
8566: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8567: $datatable = '<tr'.$css_class.'>'.
8568: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8569: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8570: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8571: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8572: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8573: &mt('No').'</label></span></td>'.
8574: '<td class="LC_left_item">'.
8575: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8576: '</table></td></tr>';
8577: $itemcount++;
8578: }
1.383 raeburn 8579: if (keys(%otherdoms)) {
8580: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8581: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8582: $datatable .= '<tr'.$css_class.'>'.
8583: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8584: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8585: '</table></td></tr>';
1.381 raeburn 8586: $itemcount++;
1.373 raeburn 8587: }
8588: }
8589: } else {
1.383 raeburn 8590: my %ip_methods = &remoteip_methods();
1.373 raeburn 8591: if ($setdom) {
8592: $itemcount ++;
8593: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8594: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8595: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8596: $wafstyle = ' style="display:none;"';
8597: $nowafstyle = ' style="display:table-row;"';
8598: $currwafdisplay = ' style="display: none"';
8599: $wafrangestyle = ' style="display: none"';
8600: $curr_remotip = 'n';
1.382 raeburn 8601: $ssltossl = ' checked="checked"';
1.381 raeburn 8602: if ($showdom) {
8603: $wafstyle = ' style="display:table-row;"';
8604: $nowafstyle = ' style="display:none;"';
8605: if (keys(%{$values{$dom}})) {
8606: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8607: $curr_remotip = $values{$dom}{remoteip};
8608: }
8609: if ($curr_remotip eq 'h') {
8610: $currwafdisplay = ' style="display:table-row"';
8611: $wafrangestyle = ' style="display:inline-block;"';
8612: }
1.382 raeburn 8613: if ($values{$dom}{'sslopt'}) {
8614: $alltossl = ' checked="checked"';
8615: $ssltossl = '';
8616: }
1.381 raeburn 8617: }
8618: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8619: $vpndircheck = ' checked="checked"';
8620: $currwafvpn = ' style="display:table-row;"';
8621: $wafrangestyle = ' style="display:inline-block;"';
8622: } else {
8623: $vpnaliascheck = ' checked="checked"';
8624: $currwafvpn = ' style="display:none;"';
8625: }
8626: }
8627: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8628: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8629: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8630: '</tr>'.
8631: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8632: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8633: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8634: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8635: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8636: '<td class="LC_left_item"><table>'.
8637: '<tr>'.
8638: '<td valign="top">'.$lt{'remoteip'}.': '.
8639: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8640: foreach my $option ('m','h','n') {
8641: my $sel;
8642: if ($option eq $curr_remotip) {
8643: $sel = ' selected="selected"';
8644: }
8645: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8646: $ip_methods{$option}.'</option>';
8647: }
8648: $datatable .= '</select></td></tr>'."\n".
8649: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8650: $lt{'ipheader'}.': '.
8651: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8652: 'name="wafproxy_ipheader" />'.
8653: '</td></tr>'."\n".
8654: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8655: $lt{'trusted'}.':<br />'.
1.381 raeburn 8656: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8657: $values{$dom}{'trusted'}.'</textarea>'.
8658: '</td></tr>'."\n".
8659: '<tr><td><hr /></td></tr>'."\n".
8660: '<tr>'.
8661: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8662: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8663: $lt{'vpndirect'}.'</label>'.(' 'x2).
8664: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8665: $lt{'vpnaliased'}.'</label></span></td></tr>';
8666: foreach my $item ('vpnint','vpnext') {
8667: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8668: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8669: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8670: $values{$dom}{$item}.'</textarea>'.
8671: '</td></tr>'."\n";
1.373 raeburn 8672: }
1.382 raeburn 8673: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8674: '<tr>'.
8675: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8676: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8677: $lt{'alltossl'}.'</label>'.(' 'x2).
8678: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8679: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8680: '</table></td></tr>';
1.373 raeburn 8681: }
8682: if (keys(%otherdoms)) {
8683: foreach my $domain (sort(keys(%otherdoms))) {
8684: $itemcount ++;
8685: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8686: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8687: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8688: '<td class="LC_left_item"><table>';
1.382 raeburn 8689: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8690: my $showval = &mt('None');
1.382 raeburn 8691: if ($item eq 'ssl') {
8692: $showval = $lt{'ssltossl'};
8693: }
1.373 raeburn 8694: if ($values{$domain}{$item}) {
1.381 raeburn 8695: $showval = $values{$domain}{$item};
1.382 raeburn 8696: if ($item eq 'ssl') {
8697: $showval = $lt{'alltossl'};
1.383 raeburn 8698: } elsif ($item eq 'remoteip') {
8699: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8700: }
1.373 raeburn 8701: }
8702: $datatable .= '<tr>'.
8703: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8704: }
1.381 raeburn 8705: $datatable .= '</table></td></tr>';
1.373 raeburn 8706: }
8707: }
8708: }
8709: $$rowtotal += $itemcount;
8710: return $datatable;
8711: }
8712:
8713: sub wafproxy_titles {
8714: return &Apache::lonlocal::texthash(
1.381 raeburn 8715: remoteip => "Method for determining user's IP",
8716: ipheader => 'Request header containing remote IP',
8717: trusted => 'Trusted IP range(s)',
8718: vpnaccess => 'Access from institutional VPN',
8719: vpndirect => 'via regular hostname (no WAF)',
8720: vpnaliased => 'via aliased hostname (WAF)',
8721: vpnint => 'Internal IP Range(s) for VPN sessions',
8722: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8723: sslopt => 'Forwarding http/https',
1.381 raeburn 8724: alltossl => 'WAF forwards both http and https requests to https',
8725: ssltossl => 'WAF forwards http requests to http and https to https',
8726: );
8727: }
8728:
8729: sub remoteip_methods {
8730: return &Apache::lonlocal::texthash(
8731: m => 'Use Apache mod_remoteip',
8732: h => 'Use headers parsed by LON-CAPA',
8733: n => 'Not in use',
1.373 raeburn 8734: );
8735: }
8736:
1.137 raeburn 8737: sub print_usersessions {
8738: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8739: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8740: my (%by_ip,%by_location,@intdoms,@instdoms);
8741: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8742:
8743: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8744: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8745: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8746: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8747: if ($position eq 'top') {
1.152 raeburn 8748: if (keys(%serverhomes) > 1) {
1.145 raeburn 8749: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8750: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8751: if (ref($settings) eq 'HASH') {
8752: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8753: $curroffloadnow = $settings->{'offloadnow'};
8754: }
1.371 raeburn 8755: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8756: $curroffloadoth = $settings->{'offloadoth'};
8757: }
1.261 raeburn 8758: }
1.371 raeburn 8759: my $other_insts = scalar(keys(%by_location));
8760: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8761: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8762: } else {
1.140 raeburn 8763: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8764: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8765: '</td></tr>';
1.140 raeburn 8766: }
1.137 raeburn 8767: } else {
1.279 raeburn 8768: my %titles = &usersession_titles();
8769: my ($prefix,@types);
8770: if ($position eq 'bottom') {
8771: $prefix = 'remote';
8772: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8773: } else {
1.279 raeburn 8774: $prefix = 'hosted';
8775: @types = ('excludedomain','includedomain');
8776: }
8777: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8778: }
8779: $$rowtotal += $itemcount;
8780: return $datatable;
8781: }
8782:
8783: sub rules_by_location {
8784: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8785: my ($datatable,$itemcount,$css_class);
8786: if (keys(%{$by_location}) == 0) {
8787: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8788: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8789: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8790: '</td></tr>';
8791: $itemcount = 1;
8792: } else {
8793: $itemcount = 0;
8794: my $numinrow = 5;
8795: my (%current,%checkedon,%checkedoff);
8796: my @locations = sort(keys(%{$by_location}));
8797: foreach my $type (@{$types}) {
8798: $checkedon{$type} = '';
8799: $checkedoff{$type} = ' checked="checked"';
8800: }
8801: if (ref($settings) eq 'HASH') {
8802: if (ref($settings->{$prefix}) eq 'HASH') {
8803: foreach my $key (keys(%{$settings->{$prefix}})) {
8804: $current{$key} = $settings->{$prefix}{$key};
8805: if ($key eq 'version') {
8806: if ($current{$key} ne '') {
1.145 raeburn 8807: $checkedon{$key} = ' checked="checked"';
8808: $checkedoff{$key} = '';
8809: }
1.279 raeburn 8810: } elsif (ref($current{$key}) eq 'ARRAY') {
8811: $checkedon{$key} = ' checked="checked"';
8812: $checkedoff{$key} = '';
1.137 raeburn 8813: }
8814: }
8815: }
1.279 raeburn 8816: }
8817: foreach my $type (@{$types}) {
8818: next if ($type ne 'version' && !@locations);
8819: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8820: $datatable .= '<tr'.$css_class.'>
8821: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8822: <span class="LC_nobreak">
8823: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8824: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8825: if ($type eq 'version') {
8826: my @lcversions = &Apache::lonnet::all_loncaparevs();
8827: my $selector = '<select name="'.$prefix.'_version">';
8828: foreach my $version (@lcversions) {
8829: my $selected = '';
8830: if ($current{'version'} eq $version) {
8831: $selected = ' selected="selected"';
1.145 raeburn 8832: }
1.279 raeburn 8833: $selector .= ' <option value="'.$version.'"'.
8834: $selected.'>'.$version.'</option>';
8835: }
8836: $selector .= '</select> ';
8837: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8838: } else {
8839: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8840: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8841: ' />'.(' 'x2).
8842: '<input type="button" value="'.&mt('uncheck all').'" '.
8843: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8844: "\n".
8845: '</div><div><table>';
8846: my $rem;
8847: for (my $i=0; $i<@locations; $i++) {
8848: my ($showloc,$value,$checkedtype);
8849: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8850: my $ip = $by_location->{$locations[$i]}->[0];
8851: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8852: $value = join(':',@{$by_ip->{$ip}});
8853: $showloc = join(', ',@{$by_ip->{$ip}});
8854: if (ref($current{$type}) eq 'ARRAY') {
8855: foreach my $loc (@{$by_ip->{$ip}}) {
8856: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8857: $checkedtype = ' checked="checked"';
8858: last;
1.145 raeburn 8859: }
1.138 raeburn 8860: }
8861: }
8862: }
1.137 raeburn 8863: }
1.279 raeburn 8864: $rem = $i%($numinrow);
8865: if ($rem == 0) {
8866: if ($i > 0) {
8867: $datatable .= '</tr>';
8868: }
8869: $datatable .= '<tr>';
8870: }
8871: $datatable .= '<td class="LC_left_item">'.
8872: '<span class="LC_nobreak"><label>'.
8873: '<input type="checkbox" name="'.$prefix.'_'.$type.
8874: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8875: '</label></span></td>';
8876: }
8877: $rem = @locations%($numinrow);
8878: my $colsleft = $numinrow - $rem;
8879: if ($colsleft > 1 ) {
8880: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8881: ' </td>';
8882: } elsif ($colsleft == 1) {
8883: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8884: }
1.279 raeburn 8885: $datatable .= '</tr></table>';
1.137 raeburn 8886: }
1.279 raeburn 8887: $datatable .= '</td></tr>';
8888: $itemcount ++;
1.137 raeburn 8889: }
8890: }
1.279 raeburn 8891: return ($datatable,$itemcount);
1.137 raeburn 8892: }
8893:
1.275 raeburn 8894: sub print_ssl {
8895: my ($position,$dom,$settings,$rowtotal) = @_;
8896: my ($css_class,$datatable);
8897: my $itemcount = 1;
8898: if ($position eq 'top') {
1.281 raeburn 8899: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8900: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8901: my $same_institution;
8902: if ($intdom ne '') {
8903: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8904: if (ref($internet_names) eq 'ARRAY') {
8905: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8906: $same_institution = 1;
8907: }
8908: }
8909: }
1.275 raeburn 8910: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8911: $datatable = '<tr'.$css_class.'><td colspan="2">';
8912: if ($same_institution) {
8913: my %domservers = &Apache::lonnet::get_servers($dom);
8914: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8915: } else {
8916: $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.");
8917: }
8918: $datatable .= '</td></tr>';
1.275 raeburn 8919: $itemcount ++;
8920: } else {
8921: my %titles = &ssl_titles();
8922: my (%by_ip,%by_location,@intdoms,@instdoms);
8923: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8924: my @alldoms = &Apache::lonnet::all_domains();
8925: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8926: my @domservers = &Apache::lonnet::get_servers($dom);
8927: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8928: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8929: if (($position eq 'connto') || ($position eq 'connfrom')) {
8930: my $legacy;
8931: unless (ref($settings) eq 'HASH') {
8932: my $name;
8933: if ($position eq 'connto') {
8934: $name = 'loncAllowInsecure';
8935: } else {
8936: $name = 'londAllowInsecure';
8937: }
8938: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8939: my @ids=&Apache::lonnet::current_machine_ids();
8940: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8941: my %what = (
8942: $name => 1,
8943: );
8944: my ($result,$returnhash) =
8945: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8946: if ($result eq 'ok') {
8947: if (ref($returnhash) eq 'HASH') {
8948: $legacy = $returnhash->{$name};
8949: }
8950: }
8951: } else {
8952: $legacy = $Apache::lonnet::perlvar{$name};
8953: }
8954: }
1.275 raeburn 8955: foreach my $type ('dom','intdom','other') {
8956: my %checked;
8957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8958: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8959: '<td class="LC_right_item">';
8960: my $skip;
8961: if ($type eq 'dom') {
8962: unless (keys(%servers) > 1) {
8963: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8964: $skip = 1;
8965: }
8966: }
8967: if ($type eq 'intdom') {
8968: unless (@instdoms > 1) {
8969: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8970: $skip = 1;
8971: }
8972: } elsif ($type eq 'other') {
8973: if (keys(%by_location) == 0) {
8974: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8975: $skip = 1;
8976: }
8977: }
8978: unless ($skip) {
8979: $checked{'yes'} = ' checked="checked"';
8980: if (ref($settings) eq 'HASH') {
1.293 raeburn 8981: if (ref($settings->{$position}) eq 'HASH') {
8982: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8983: $checked{$1} = $checked{'yes'};
8984: delete($checked{'yes'});
8985: }
8986: }
1.293 raeburn 8987: } else {
8988: if ($legacy == 0) {
8989: $checked{'req'} = $checked{'yes'};
8990: delete($checked{'yes'});
8991: }
1.275 raeburn 8992: }
8993: foreach my $option ('no','yes','req') {
8994: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8995: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8996: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8997: '</label></span>'.(' 'x2);
8998: }
8999: }
9000: $datatable .= '</td></tr>';
9001: $itemcount ++;
9002: }
9003: } else {
9004: my $prefix = 'replication';
9005: my @types = ('certreq','nocertreq');
1.279 raeburn 9006: if (keys(%by_location) == 0) {
9007: $datatable .= '<tr'.$css_class.'><td>'.
9008: &mt('Nothing to set here, as there are no other institutions').
9009: '</td></tr>';
9010: $itemcount ++;
1.275 raeburn 9011: } else {
1.279 raeburn 9012: ($datatable,$itemcount) =
9013: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9014: }
9015: }
9016: }
9017: $$rowtotal += $itemcount;
9018: return $datatable;
9019: }
9020:
9021: sub ssl_titles {
9022: return &Apache::lonlocal::texthash (
9023: dom => 'LON-CAPA servers/VMs from same domain',
9024: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9025: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9026: connto => 'Connections to other servers',
9027: connfrom => 'Connections from other servers',
1.275 raeburn 9028: replication => 'Replicating content to other institutions',
9029: certreq => 'Client certificate required, but specific domains exempt',
9030: nocertreq => 'No client certificate required, except for specific domains',
9031: no => 'SSL not used',
9032: yes => 'SSL Optional (used if available)',
9033: req => 'SSL Required',
9034: );
1.279 raeburn 9035: }
9036:
9037: sub print_trust {
9038: my ($prefix,$dom,$settings,$rowtotal) = @_;
9039: my ($css_class,$datatable,%checked,%choices);
9040: my (%by_ip,%by_location,@intdoms,@instdoms);
9041: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9042: my $itemcount = 1;
9043: my %titles = &trust_titles();
9044: my @types = ('exc','inc');
9045: if ($prefix eq 'top') {
9046: $prefix = 'content';
9047: } elsif ($prefix eq 'bottom') {
9048: $prefix = 'msg';
9049: }
9050: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9051: $$rowtotal += $itemcount;
9052: return $datatable;
9053: }
9054:
9055: sub trust_titles {
9056: return &Apache::lonlocal::texthash(
9057: content => "Access to this domain's content by others",
9058: shared => "Access to other domain's content by this domain",
9059: enroll => "Enrollment in this domain's courses by others",
9060: othcoau => "Co-author roles in this domain for others",
9061: coaurem => "Co-author roles for this domain's users elsewhere",
9062: domroles => "Domain roles in this domain assignable to others",
9063: catalog => "Course Catalog for this domain displayed elsewhere",
9064: reqcrs => "Requests for creation of courses in this domain by others",
9065: msg => "Users in other domains can send messages to this domain",
9066: exc => "Allow all, but exclude specific domains",
9067: inc => "Deny all, but include specific domains",
9068: );
1.275 raeburn 9069: }
9070:
1.138 raeburn 9071: sub build_location_hashes {
1.275 raeburn 9072: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9073: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9074: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9075: my %iphost = &Apache::lonnet::get_iphost();
9076: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9077: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9078: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9079: foreach my $id (@{$iphost{$primary_ip}}) {
9080: my $intdom = &Apache::lonnet::internet_dom($id);
9081: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9082: push(@{$intdoms},$intdom);
9083: }
9084: }
9085: }
9086: foreach my $ip (keys(%iphost)) {
9087: if (ref($iphost{$ip}) eq 'ARRAY') {
9088: foreach my $id (@{$iphost{$ip}}) {
9089: my $location = &Apache::lonnet::internet_dom($id);
9090: if ($location) {
1.275 raeburn 9091: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9092: my $dom = &Apache::lonnet::host_domain($id);
9093: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9094: push(@{$instdoms},$dom);
9095: }
9096: next;
9097: }
1.138 raeburn 9098: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9099: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9100: push(@{$by_ip->{$ip}},$location);
9101: }
9102: } else {
9103: $by_ip->{$ip} = [$location];
9104: }
9105: }
9106: }
9107: }
9108: }
9109: foreach my $ip (sort(keys(%{$by_ip}))) {
9110: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9111: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9112: my $first = $by_ip->{$ip}->[0];
9113: if (ref($by_location->{$first}) eq 'ARRAY') {
9114: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9115: push(@{$by_location->{$first}},$ip);
9116: }
9117: } else {
9118: $by_location->{$first} = [$ip];
9119: }
9120: }
9121: }
9122: return;
9123: }
9124:
1.145 raeburn 9125: sub current_offloads_to {
9126: my ($dom,$settings,$servers) = @_;
9127: my (%spareid,%otherdomconfigs);
1.152 raeburn 9128: if (ref($servers) eq 'HASH') {
1.145 raeburn 9129: foreach my $lonhost (sort(keys(%{$servers}))) {
9130: my $gotspares;
1.152 raeburn 9131: if (ref($settings) eq 'HASH') {
9132: if (ref($settings->{'spares'}) eq 'HASH') {
9133: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9134: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9135: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9136: $gotspares = 1;
9137: }
1.145 raeburn 9138: }
9139: }
9140: unless ($gotspares) {
9141: my $gotspares;
9142: my $serverhomeID =
9143: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9144: my $serverhomedom =
9145: &Apache::lonnet::host_domain($serverhomeID);
9146: if ($serverhomedom ne $dom) {
9147: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9148: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9149: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9150: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9151: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9152: $gotspares = 1;
9153: }
9154: }
9155: } else {
9156: $otherdomconfigs{$serverhomedom} =
9157: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9158: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9159: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9160: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9161: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9162: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9163: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9164: $gotspares = 1;
9165: }
9166: }
9167: }
9168: }
9169: }
9170: }
9171: }
9172: unless ($gotspares) {
9173: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9174: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9175: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9176: } else {
9177: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9178: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9179: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9180: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9181: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9182: } else {
1.150 raeburn 9183: my %what = (
9184: spareid => 1,
9185: );
9186: my ($result,$returnhash) =
9187: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9188: if ($result eq 'ok') {
9189: if (ref($returnhash) eq 'HASH') {
9190: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9191: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9192: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9193: }
9194: }
1.145 raeburn 9195: }
9196: }
9197: }
9198: }
9199: }
9200: }
9201: return %spareid;
9202: }
9203:
9204: sub spares_row {
1.371 raeburn 9205: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9206: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9207: my $css_class;
9208: my $numinrow = 4;
9209: my $itemcount = 1;
9210: my $datatable;
1.152 raeburn 9211: my %typetitles = &sparestype_titles();
9212: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9213: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9214: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9215: my ($othercontrol,$serverdom);
9216: if ($serverhome ne $server) {
9217: $serverdom = &Apache::lonnet::host_domain($serverhome);
9218: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9219: } else {
9220: $serverdom = &Apache::lonnet::host_domain($server);
9221: if ($serverdom ne $dom) {
9222: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9223: }
9224: }
9225: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9226: my ($checkednow,$checkedoth);
1.261 raeburn 9227: if (ref($curroffloadnow) eq 'HASH') {
9228: if ($curroffloadnow->{$server}) {
9229: $checkednow = ' checked="checked"';
9230: }
9231: }
1.371 raeburn 9232: if (ref($curroffloadoth) eq 'HASH') {
9233: if ($curroffloadoth->{$server}) {
9234: $checkedoth = ' checked="checked"';
9235: }
9236: }
1.145 raeburn 9237: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9238: $datatable .= '<tr'.$css_class.'>
9239: <td rowspan="2">
1.183 bisitz 9240: <span class="LC_nobreak">'.
9241: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9242: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9243: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9244: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9245: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9246: "\n";
1.371 raeburn 9247: if ($other_insts) {
9248: $datatable .= '<br />'.
9249: '<span class="LC_nobreak">'."\n".
9250: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9251: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9252: "\n";
9253: }
1.145 raeburn 9254: my (%current,%canselect);
1.152 raeburn 9255: my @choices =
9256: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9257: foreach my $type ('primary','default') {
9258: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9259: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9260: my @spares = @{$spareid->{$server}{$type}};
9261: if (@spares > 0) {
1.152 raeburn 9262: if ($othercontrol) {
9263: $current{$type} = join(', ',@spares);
9264: } else {
9265: $current{$type} .= '<table>';
9266: my $numspares = scalar(@spares);
9267: for (my $i=0; $i<@spares; $i++) {
9268: my $rem = $i%($numinrow);
9269: if ($rem == 0) {
9270: if ($i > 0) {
9271: $current{$type} .= '</tr>';
9272: }
9273: $current{$type} .= '<tr>';
1.145 raeburn 9274: }
1.152 raeburn 9275: $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'".');" /> '.
9276: $spareid->{$server}{$type}[$i].
9277: '</label></td>'."\n";
9278: }
9279: my $rem = @spares%($numinrow);
9280: my $colsleft = $numinrow - $rem;
9281: if ($colsleft > 1 ) {
9282: $current{$type} .= '<td colspan="'.$colsleft.
9283: '" class="LC_left_item">'.
9284: ' </td>';
9285: } elsif ($colsleft == 1) {
9286: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9287: }
1.152 raeburn 9288: $current{$type} .= '</tr></table>';
1.150 raeburn 9289: }
1.145 raeburn 9290: }
9291: }
9292: if ($current{$type} eq '') {
9293: $current{$type} = &mt('None specified');
9294: }
1.152 raeburn 9295: if ($othercontrol) {
9296: if ($type eq 'primary') {
9297: $canselect{$type} = $othercontrol;
9298: }
9299: } else {
9300: $canselect{$type} =
9301: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9302: '<select name="newspare_'.$type.'_'.$server.'" '.
9303: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9304: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9305: if (@choices > 0) {
9306: foreach my $lonhost (@choices) {
9307: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9308: }
9309: }
9310: $canselect{$type} .= '</select>'."\n";
9311: }
9312: } else {
9313: $current{$type} = &mt('Could not be determined');
9314: if ($type eq 'primary') {
9315: $canselect{$type} = $othercontrol;
9316: }
1.145 raeburn 9317: }
1.152 raeburn 9318: if ($type eq 'default') {
9319: $datatable .= '<tr'.$css_class.'>';
9320: }
9321: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9322: '<td>'.$current{$type}.'</td>'."\n".
9323: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9324: }
9325: $itemcount ++;
9326: }
9327: }
9328: $$rowtotal += $itemcount;
9329: return $datatable;
9330: }
9331:
1.152 raeburn 9332: sub possible_newspares {
9333: my ($server,$currspares,$serverhomes,$altids) = @_;
9334: my $serverhostname = &Apache::lonnet::hostname($server);
9335: my %excluded;
9336: if ($serverhostname ne '') {
9337: %excluded = (
9338: $serverhostname => 1,
9339: );
9340: }
9341: if (ref($currspares) eq 'HASH') {
9342: foreach my $type (keys(%{$currspares})) {
9343: if (ref($currspares->{$type}) eq 'ARRAY') {
9344: if (@{$currspares->{$type}} > 0) {
9345: foreach my $curr (@{$currspares->{$type}}) {
9346: my $hostname = &Apache::lonnet::hostname($curr);
9347: $excluded{$hostname} = 1;
9348: }
9349: }
9350: }
9351: }
9352: }
9353: my @choices;
9354: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9355: if (keys(%{$serverhomes}) > 1) {
9356: foreach my $name (sort(keys(%{$serverhomes}))) {
9357: unless ($excluded{$name}) {
9358: if (exists($altids->{$serverhomes->{$name}})) {
9359: push(@choices,$altids->{$serverhomes->{$name}});
9360: } else {
9361: push(@choices,$serverhomes->{$name});
1.145 raeburn 9362: }
9363: }
9364: }
9365: }
9366: }
1.152 raeburn 9367: return sort(@choices);
1.145 raeburn 9368: }
9369:
1.150 raeburn 9370: sub print_loadbalancing {
9371: my ($dom,$settings,$rowtotal) = @_;
9372: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9373: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9374: my $numinrow = 1;
9375: my $datatable;
9376: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9377: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9378: if (ref($settings) eq 'HASH') {
9379: %existing = %{$settings};
9380: }
9381: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9382: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9383: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9384: } else {
9385: return;
9386: }
9387: my ($othertitle,$usertypes,$types) =
9388: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9389: my $rownum = 8;
1.150 raeburn 9390: if (ref($types) eq 'ARRAY') {
9391: $rownum += scalar(@{$types});
9392: }
1.171 raeburn 9393: my @css_class = ('LC_odd_row','LC_even_row');
9394: my $balnum = 0;
9395: my $islast;
9396: my (@toshow,$disabledtext);
9397: if (keys(%currbalancer) > 0) {
9398: @toshow = sort(keys(%currbalancer));
9399: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9400: push(@toshow,'');
9401: }
9402: } else {
9403: @toshow = ('');
9404: $disabledtext = &mt('No existing load balancer');
9405: }
9406: foreach my $lonhost (@toshow) {
9407: if ($balnum == scalar(@toshow)-1) {
9408: $islast = 1;
9409: } else {
9410: $islast = 0;
9411: }
9412: my $cssidx = $balnum%2;
9413: my $targets_div_style = 'display: none';
9414: my $disabled_div_style = 'display: block';
9415: my $homedom_div_style = 'display: none';
9416: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9417: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9418: '<p>';
9419: if ($lonhost eq '') {
1.210 raeburn 9420: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9421: if (keys(%currbalancer) > 0) {
9422: $datatable .= &mt('Add balancer:');
9423: } else {
9424: $datatable .= &mt('Enable balancer:');
9425: }
9426: $datatable .= ' '.
9427: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9428: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9429: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9430: '<option value="" selected="selected">'.&mt('None').
9431: '</option>'."\n";
9432: foreach my $server (sort(keys(%servers))) {
9433: next if ($currbalancer{$server});
9434: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9435: }
1.210 raeburn 9436: $datatable .=
1.171 raeburn 9437: '</select>'."\n".
9438: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9439: } else {
9440: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9441: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9442: &mt('Stop balancing').'</label>'.
9443: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9444: $targets_div_style = 'display: block';
9445: $disabled_div_style = 'display: none';
9446: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9447: $homedom_div_style = 'display: block';
9448: }
9449: }
1.306 raeburn 9450: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9451: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9452: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9453: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9454: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9455: my @sparestypes = ('primary','default');
9456: my %typetitles = &sparestype_titles();
1.284 raeburn 9457: my %hostherechecked = (
9458: no => ' checked="checked"',
9459: );
1.342 raeburn 9460: my %balcookiechecked = (
1.425 raeburn 9461: no => ' checked="checked"',
1.342 raeburn 9462: );
1.171 raeburn 9463: foreach my $sparetype (@sparestypes) {
9464: my $targettable;
9465: for (my $i=0; $i<$numspares; $i++) {
9466: my $checked;
9467: if (ref($currtargets{$lonhost}) eq 'HASH') {
9468: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9469: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9470: $checked = ' checked="checked"';
9471: }
9472: }
9473: }
9474: my ($chkboxval,$disabled);
9475: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9476: $chkboxval = $spares[$i];
9477: }
9478: if (exists($currbalancer{$spares[$i]})) {
9479: $disabled = ' disabled="disabled"';
9480: }
1.210 raeburn 9481: $targettable .=
1.253 raeburn 9482: '<td><span class="LC_nobreak"><label>'.
9483: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9484: $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 9485: '</span></label></span></td>';
1.171 raeburn 9486: my $rem = $i%($numinrow);
9487: if ($rem == 0) {
9488: if (($i > 0) && ($i < $numspares-1)) {
9489: $targettable .= '</tr>';
9490: }
9491: if ($i < $numspares-1) {
9492: $targettable .= '<tr>';
1.150 raeburn 9493: }
9494: }
9495: }
1.171 raeburn 9496: if ($targettable ne '') {
9497: my $rem = $numspares%($numinrow);
9498: my $colsleft = $numinrow - $rem;
9499: if ($colsleft > 1 ) {
9500: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9501: ' </td>';
9502: } elsif ($colsleft == 1) {
9503: $targettable .= '<td class="LC_left_item"> </td>';
9504: }
9505: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9506: '<table><tr>'.$targettable.'</tr></table><br />';
9507: }
1.284 raeburn 9508: $hostherechecked{$sparetype} = '';
9509: if (ref($currtargets{$lonhost}) eq 'HASH') {
9510: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9511: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9512: $hostherechecked{$sparetype} = ' checked="checked"';
9513: $hostherechecked{'no'} = '';
9514: }
9515: }
9516: }
9517: }
1.342 raeburn 9518: if ($currcookies{$lonhost}) {
9519: %balcookiechecked = (
9520: yes => ' checked="checked"',
9521: );
9522: }
1.284 raeburn 9523: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9524: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9525: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9526: foreach my $sparetype (@sparestypes) {
9527: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9528: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9529: '</i></label><br />';
1.171 raeburn 9530: }
1.342 raeburn 9531: $datatable .= &mt('Use balancer cookie').'<br />'.
9532: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9533: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9534: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9535: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9536: '</div></td></tr>'.
1.171 raeburn 9537: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9538: $othertitle,$usertypes,$types,\%servers,
9539: \%currbalancer,$lonhost,
9540: $targets_div_style,$homedom_div_style,
9541: $css_class[$cssidx],$balnum,$islast);
9542: $$rowtotal += $rownum;
9543: $balnum ++;
9544: }
9545: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9546: return $datatable;
9547: }
9548:
9549: sub get_loadbalancers_config {
1.342 raeburn 9550: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9551: return unless ((ref($servers) eq 'HASH') &&
9552: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9553: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9554: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9555: if (keys(%{$existing}) > 0) {
9556: my $oldlonhost;
9557: foreach my $key (sort(keys(%{$existing}))) {
9558: if ($key eq 'lonhost') {
9559: $oldlonhost = $existing->{'lonhost'};
9560: $currbalancer->{$oldlonhost} = 1;
9561: } elsif ($key eq 'targets') {
9562: if ($oldlonhost) {
9563: $currtargets->{$oldlonhost} = $existing->{'targets'};
9564: }
9565: } elsif ($key eq 'rules') {
9566: if ($oldlonhost) {
9567: $currrules->{$oldlonhost} = $existing->{'rules'};
9568: }
9569: } elsif (ref($existing->{$key}) eq 'HASH') {
9570: $currbalancer->{$key} = 1;
9571: $currtargets->{$key} = $existing->{$key}{'targets'};
9572: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9573: if ($existing->{$key}{'cookie'}) {
9574: $currcookies->{$key} = 1;
9575: }
1.150 raeburn 9576: }
9577: }
1.171 raeburn 9578: } else {
9579: my ($balancerref,$targetsref) =
9580: &Apache::lonnet::get_lonbalancer_config($servers);
9581: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9582: foreach my $server (sort(keys(%{$balancerref}))) {
9583: $currbalancer->{$server} = 1;
9584: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9585: }
9586: }
9587: }
1.171 raeburn 9588: return;
1.150 raeburn 9589: }
9590:
9591: sub loadbalancing_rules {
9592: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9593: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9594: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9595: my $output;
1.171 raeburn 9596: my $num = 0;
1.210 raeburn 9597: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9598: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9599: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9600: foreach my $type (@{$alltypes}) {
1.171 raeburn 9601: $num ++;
1.150 raeburn 9602: my $current;
9603: if (ref($currrules) eq 'HASH') {
9604: $current = $currrules->{$type};
9605: }
1.253 raeburn 9606: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9607: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9608: $current = '';
9609: }
9610: }
9611: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9612: $servers,$currbalancer,$lonhost,$dom,
9613: $targets_div_style,$homedom_div_style,
9614: $css_class,$balnum,$num,$islast);
1.150 raeburn 9615: }
9616: }
9617: return $output;
9618: }
9619:
9620: sub loadbalancing_titles {
9621: my ($dom,$intdom,$usertypes,$types) = @_;
9622: my %othertypes = (
9623: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9624: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9625: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9626: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9627: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9628: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9629: );
1.209 raeburn 9630: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9631: my @available;
1.150 raeburn 9632: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9633: @available = @{$types};
1.150 raeburn 9634: }
1.302 raeburn 9635: unless (grep(/^default$/,@available)) {
9636: push(@available,'default');
9637: }
9638: unshift(@alltypes,@available);
1.150 raeburn 9639: my %titles;
9640: foreach my $type (@alltypes) {
9641: if ($type =~ /^_LC_/) {
9642: $titles{$type} = $othertypes{$type};
9643: } elsif ($type eq 'default') {
9644: $titles{$type} = &mt('All users from [_1]',$dom);
9645: if (ref($types) eq 'ARRAY') {
9646: if (@{$types} > 0) {
9647: $titles{$type} = &mt('Other users from [_1]',$dom);
9648: }
9649: }
9650: } elsif (ref($usertypes) eq 'HASH') {
9651: $titles{$type} = $usertypes->{$type};
9652: }
9653: }
9654: return (\@alltypes,\%othertypes,\%titles);
9655: }
9656:
9657: sub loadbalance_rule_row {
1.171 raeburn 9658: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9659: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9660: my @rulenames;
1.150 raeburn 9661: my %ruletitles = &offloadtype_text();
1.209 raeburn 9662: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9663: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9664: } else {
1.209 raeburn 9665: @rulenames = ('default','homeserver');
9666: if ($type eq '_LC_external') {
9667: push(@rulenames,'externalbalancer');
9668: } else {
9669: push(@rulenames,'specific');
9670: }
9671: push(@rulenames,'none');
1.150 raeburn 9672: }
9673: my $style = $targets_div_style;
1.253 raeburn 9674: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9675: $style = $homedom_div_style;
9676: }
1.171 raeburn 9677: my $space;
9678: if ($islast && $num == 1) {
1.317 raeburn 9679: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9680: }
1.210 raeburn 9681: my $output =
1.306 raeburn 9682: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9683: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9684: '<td valaign="top">'.$space.
9685: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9686: for (my $i=0; $i<@rulenames; $i++) {
9687: my $rule = $rulenames[$i];
9688: my ($checked,$extra);
9689: if ($rulenames[$i] eq 'default') {
9690: $rule = '';
9691: }
9692: if ($rulenames[$i] eq 'specific') {
9693: if (ref($servers) eq 'HASH') {
9694: my $default;
9695: if (($current ne '') && (exists($servers->{$current}))) {
9696: $checked = ' checked="checked"';
9697: }
9698: unless ($checked) {
9699: $default = ' selected="selected"';
9700: }
1.210 raeburn 9701: $extra =
1.171 raeburn 9702: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9703: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9704: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9705: '<option value=""'.$default.'></option>'."\n";
9706: foreach my $server (sort(keys(%{$servers}))) {
9707: if (ref($currbalancer) eq 'HASH') {
9708: next if (exists($currbalancer->{$server}));
9709: }
1.150 raeburn 9710: my $selected;
1.171 raeburn 9711: if ($server eq $current) {
1.150 raeburn 9712: $selected = ' selected="selected"';
9713: }
1.171 raeburn 9714: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9715: }
9716: $extra .= '</select>';
9717: }
9718: } elsif ($rule eq $current) {
9719: $checked = ' checked="checked"';
9720: }
9721: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9722: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9723: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9724: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9725: ')"'.$checked.' /> ';
9726: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9727: $output .= $ruletitles{'particular'};
9728: } else {
9729: $output .= $ruletitles{$rulenames[$i]};
9730: }
9731: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9732: }
9733: $output .= '</div></td></tr>'."\n";
9734: return $output;
9735: }
9736:
9737: sub offloadtype_text {
9738: my %ruletitles = &Apache::lonlocal::texthash (
9739: 'default' => 'Offloads to default destinations',
9740: 'homeserver' => "Offloads to user's home server",
9741: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9742: 'specific' => 'Offloads to specific server',
1.161 raeburn 9743: 'none' => 'No offload',
1.209 raeburn 9744: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9745: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9746: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9747: );
9748: return %ruletitles;
9749: }
9750:
9751: sub sparestype_titles {
9752: my %typestitles = &Apache::lonlocal::texthash (
9753: 'primary' => 'primary',
9754: 'default' => 'default',
9755: );
9756: return %typestitles;
9757: }
9758:
1.28 raeburn 9759: sub contact_titles {
9760: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9761: 'supportemail' => 'Support E-mail address',
9762: 'adminemail' => 'Default Server Admin E-mail address',
9763: 'errormail' => 'Error reports to be e-mailed to',
9764: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9765: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9766: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9767: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9768: 'requestsmail' => 'E-mail from course requests requiring approval',
9769: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9770: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9771: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9772: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9773: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9774: 'errorweights' => 'Weights used to compute error count',
9775: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9776: );
9777: my %short_titles = &Apache::lonlocal::texthash (
9778: adminemail => 'Admin E-mail address',
9779: supportemail => 'Support E-mail',
9780: );
9781: return (\%titles,\%short_titles);
9782: }
9783:
1.286 raeburn 9784: sub helpform_fields {
9785: my %titles = &Apache::lonlocal::texthash (
9786: 'username' => 'Name',
9787: 'user' => 'Username/domain',
9788: 'phone' => 'Phone',
9789: 'cc' => 'Cc e-mail',
9790: 'course' => 'Course Details',
9791: 'section' => 'Sections',
1.289 raeburn 9792: 'screenshot' => 'File upload',
1.286 raeburn 9793: );
9794: my @fields = ('username','phone','user','course','section','cc','screenshot');
9795: my %possoptions = (
9796: username => ['yes','no','req'],
1.289 raeburn 9797: phone => ['yes','no','req'],
1.286 raeburn 9798: user => ['yes','no'],
1.289 raeburn 9799: cc => ['yes','no'],
1.286 raeburn 9800: course => ['yes','no'],
9801: section => ['yes','no'],
9802: screenshot => ['yes','no'],
9803: );
9804: my %fieldoptions = &Apache::lonlocal::texthash (
9805: 'yes' => 'Optional',
9806: 'req' => 'Required',
9807: 'no' => "Not shown",
9808: );
9809: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9810: }
9811:
1.72 raeburn 9812: sub tool_titles {
9813: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9814: aboutme => 'Personal web page',
1.86 raeburn 9815: blog => 'Blog',
9816: portfolio => 'Portfolio',
1.430 raeburn 9817: portaccess => 'Share portfolio files',
1.413 raeburn 9818: timezone => 'Can set time zone',
1.88 bisitz 9819: official => 'Official courses (with institutional codes)',
9820: unofficial => 'Unofficial courses',
1.98 raeburn 9821: community => 'Communities',
1.216 raeburn 9822: textbook => 'Textbook courses',
1.271 raeburn 9823: placement => 'Placement tests',
1.86 raeburn 9824: );
1.72 raeburn 9825: return %titles;
9826: }
9827:
1.101 raeburn 9828: sub courserequest_titles {
9829: my %titles = &Apache::lonlocal::texthash (
9830: official => 'Official',
9831: unofficial => 'Unofficial',
9832: community => 'Communities',
1.216 raeburn 9833: textbook => 'Textbook',
1.271 raeburn 9834: placement => 'Placement tests',
1.325 raeburn 9835: lti => 'LTI Provider',
1.101 raeburn 9836: norequest => 'Not allowed',
1.325 raeburn 9837: approval => 'Approval by DC',
1.101 raeburn 9838: validate => 'With validation',
9839: autolimit => 'Numerical limit',
1.103 raeburn 9840: unlimited => '(blank for unlimited)',
1.101 raeburn 9841: );
9842: return %titles;
9843: }
9844:
1.163 raeburn 9845: sub authorrequest_titles {
9846: my %titles = &Apache::lonlocal::texthash (
9847: norequest => 'Not allowed',
9848: approval => 'Approval by Dom. Coord.',
9849: automatic => 'Automatic approval',
9850: );
9851: return %titles;
1.210 raeburn 9852: }
1.163 raeburn 9853:
1.101 raeburn 9854: sub courserequest_conditions {
9855: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9856: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9857: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9858: );
9859: return %conditions;
9860: }
9861:
9862:
1.27 raeburn 9863: sub print_usercreation {
1.30 raeburn 9864: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9865: my $numinrow = 4;
1.28 raeburn 9866: my $datatable;
9867: if ($position eq 'top') {
1.30 raeburn 9868: $$rowtotal ++;
1.34 raeburn 9869: my $rowcount = 0;
1.32 raeburn 9870: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9871: if (ref($rules) eq 'HASH') {
9872: if (keys(%{$rules}) > 0) {
1.32 raeburn 9873: $datatable .= &user_formats_row('username',$settings,$rules,
9874: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9875: $$rowtotal ++;
1.32 raeburn 9876: $rowcount ++;
9877: }
9878: }
9879: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9880: if (ref($idrules) eq 'HASH') {
9881: if (keys(%{$idrules}) > 0) {
9882: $datatable .= &user_formats_row('id',$settings,$idrules,
9883: $idruleorder,$numinrow,$rowcount);
9884: $$rowtotal ++;
9885: $rowcount ++;
1.28 raeburn 9886: }
9887: }
1.39 raeburn 9888: if ($rowcount == 0) {
9889: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9890: $$rowtotal ++;
9891: $rowcount ++;
9892: }
1.34 raeburn 9893: } elsif ($position eq 'middle') {
1.224 raeburn 9894: my @creators = ('author','course','requestcrs');
1.37 raeburn 9895: my ($rules,$ruleorder) =
9896: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9897: my %lt = &usercreation_types();
9898: my %checked;
9899: if (ref($settings) eq 'HASH') {
9900: if (ref($settings->{'cancreate'}) eq 'HASH') {
9901: foreach my $item (@creators) {
9902: $checked{$item} = $settings->{'cancreate'}{$item};
9903: }
9904: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9905: foreach my $item (@creators) {
9906: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9907: $checked{$item} = 'none';
9908: }
9909: }
9910: }
9911: }
9912: my $rownum = 0;
9913: foreach my $item (@creators) {
9914: $rownum ++;
1.224 raeburn 9915: if ($checked{$item} eq '') {
9916: $checked{$item} = 'any';
1.34 raeburn 9917: }
9918: my $css_class;
9919: if ($rownum%2) {
9920: $css_class = '';
9921: } else {
9922: $css_class = ' class="LC_odd_row" ';
9923: }
9924: $datatable .= '<tr'.$css_class.'>'.
9925: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9926: '</span></td><td style="text-align: right">';
1.224 raeburn 9927: my @options = ('any');
9928: if (ref($rules) eq 'HASH') {
9929: if (keys(%{$rules}) > 0) {
9930: push(@options,('official','unofficial'));
1.37 raeburn 9931: }
9932: }
1.224 raeburn 9933: push(@options,'none');
1.37 raeburn 9934: foreach my $option (@options) {
1.50 raeburn 9935: my $type = 'radio';
1.34 raeburn 9936: my $check = ' ';
1.224 raeburn 9937: if ($checked{$item} eq $option) {
9938: $check = ' checked="checked" ';
1.34 raeburn 9939: }
9940: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9941: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9942: $item.'" value="'.$option.'"'.$check.'/> '.
9943: $lt{$option}.'</label> </span>';
9944: }
9945: $datatable .= '</td></tr>';
9946: }
1.28 raeburn 9947: } else {
9948: my @contexts = ('author','course','domain');
1.325 raeburn 9949: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9950: my %checked;
9951: if (ref($settings) eq 'HASH') {
9952: if (ref($settings->{'authtypes'}) eq 'HASH') {
9953: foreach my $item (@contexts) {
9954: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9955: foreach my $auth (@authtypes) {
9956: if ($settings->{'authtypes'}{$item}{$auth}) {
9957: $checked{$item}{$auth} = ' checked="checked" ';
9958: }
9959: }
9960: }
9961: }
1.27 raeburn 9962: }
1.35 raeburn 9963: } else {
9964: foreach my $item (@contexts) {
1.36 raeburn 9965: foreach my $auth (@authtypes) {
1.35 raeburn 9966: $checked{$item}{$auth} = ' checked="checked" ';
9967: }
9968: }
1.27 raeburn 9969: }
1.28 raeburn 9970: my %title = &context_names();
9971: my %authname = &authtype_names();
9972: my $rownum = 0;
9973: my $css_class;
9974: foreach my $item (@contexts) {
9975: if ($rownum%2) {
9976: $css_class = '';
9977: } else {
9978: $css_class = ' class="LC_odd_row" ';
9979: }
1.30 raeburn 9980: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9981: '<td>'.$title{$item}.
9982: '</td><td class="LC_left_item">'.
9983: '<span class="LC_nobreak">';
9984: foreach my $auth (@authtypes) {
9985: $datatable .= '<label>'.
9986: '<input type="checkbox" name="'.$item.'_auth" '.
9987: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9988: $authname{$auth}.'</label> ';
9989: }
9990: $datatable .= '</span></td></tr>';
9991: $rownum ++;
1.27 raeburn 9992: }
1.30 raeburn 9993: $$rowtotal += $rownum;
1.27 raeburn 9994: }
9995: return $datatable;
9996: }
9997:
1.224 raeburn 9998: sub print_selfcreation {
9999: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10000: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10001: $emaildomain,$datatable);
1.224 raeburn 10002: if (ref($settings) eq 'HASH') {
10003: if (ref($settings->{'cancreate'}) eq 'HASH') {
10004: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10005: if (ref($createsettings) eq 'HASH') {
10006: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10007: @selfcreate = @{$createsettings->{'selfcreate'}};
10008: } elsif ($createsettings->{'selfcreate'} ne '') {
10009: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10010: @selfcreate = ('email','login','sso');
10011: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10012: @selfcreate = ($createsettings->{'selfcreate'});
10013: }
10014: }
10015: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10016: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10017: }
1.305 raeburn 10018: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10019: $emailoptions = $createsettings->{'emailoptions'};
10020: }
1.303 raeburn 10021: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10022: $emailverified = $createsettings->{'emailverified'};
10023: }
10024: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10025: $emaildomain = $createsettings->{'emaildomain'};
10026: }
1.224 raeburn 10027: }
10028: }
10029: }
10030: my %radiohash;
10031: my $numinrow = 4;
10032: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10033: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10034: if ($position eq 'top') {
10035: my %choices = &Apache::lonlocal::texthash (
10036: cancreate_login => 'Institutional Login',
10037: cancreate_sso => 'Institutional Single Sign On',
10038: );
10039: my @toggles = sort(keys(%choices));
10040: my %defaultchecked = (
10041: 'cancreate_login' => 'off',
10042: 'cancreate_sso' => 'off',
10043: );
1.228 raeburn 10044: my ($onclick,$itemcount);
1.224 raeburn 10045: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10046: \%choices,$itemcount,$onclick);
1.228 raeburn 10047: $$rowtotal += $itemcount;
1.425 raeburn 10048:
1.224 raeburn 10049: if (ref($usertypes) eq 'HASH') {
10050: if (keys(%{$usertypes}) > 0) {
10051: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10052: $dom,$numinrow,$othertitle,
1.305 raeburn 10053: 'statustocreate',$rowtotal);
1.224 raeburn 10054: $$rowtotal ++;
10055: }
10056: }
1.240 raeburn 10057: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10058: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10059: $fieldtitles{'inststatus'} = &mt('Institutional status');
10060: my $rem;
10061: my $numperrow = 2;
10062: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10063: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10064: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10065: '<td class="LC_left_item">'."\n".
1.334 raeburn 10066: '<table>'."\n";
1.240 raeburn 10067: for (my $i=0; $i<@fields; $i++) {
10068: $rem = $i%($numperrow);
10069: if ($rem == 0) {
10070: if ($i > 0) {
10071: $datatable .= '</tr>';
10072: }
10073: $datatable .= '<tr>';
10074: }
10075: my $currval;
1.248 raeburn 10076: if (ref($createsettings) eq 'HASH') {
10077: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10078: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10079: }
1.240 raeburn 10080: }
10081: $datatable .= '<td class="LC_left_item">'.
10082: '<span class="LC_nobreak">'.
10083: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10084: 'value="'.$currval.'" size="10" /> '.
10085: $fieldtitles{$fields[$i]}.'</span></td>';
10086: }
10087: my $colsleft = $numperrow - $rem;
10088: if ($colsleft > 1 ) {
10089: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10090: ' </td>';
10091: } elsif ($colsleft == 1) {
10092: $datatable .= '<td class="LC_left_item"> </td>';
10093: }
10094: $datatable .= '</tr></table></td></tr>';
10095: $$rowtotal ++;
1.224 raeburn 10096: } elsif ($position eq 'middle') {
10097: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10098: my @posstypes;
1.224 raeburn 10099: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10100: @posstypes = @{$types};
10101: }
10102: unless (grep(/^default$/,@posstypes)) {
10103: push(@posstypes,'default');
10104: }
10105: my %usertypeshash;
10106: if (ref($usertypes) eq 'HASH') {
10107: %usertypeshash = %{$usertypes};
10108: }
10109: $usertypeshash{'default'} = $othertitle;
10110: foreach my $status (@posstypes) {
10111: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10112: $numinrow,$$rowtotal,\%usertypeshash);
10113: $$rowtotal ++;
1.224 raeburn 10114: }
10115: } else {
1.236 raeburn 10116: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10117: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10118: );
10119: my @toggles = sort(keys(%choices));
10120: my %defaultchecked = (
10121: 'cancreate_email' => 'off',
10122: );
1.305 raeburn 10123: my $customclass = 'LC_selfcreate_email';
10124: my $classprefix = 'LC_canmodify_emailusername_';
10125: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10126: my $display = 'none';
1.305 raeburn 10127: my $rowstyle = 'display:none';
1.236 raeburn 10128: if (grep(/^\Qemail\E$/,@selfcreate)) {
10129: $display = 'block';
1.305 raeburn 10130: $rowstyle = 'display:table-row';
1.236 raeburn 10131: }
1.305 raeburn 10132: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10133: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10134: \%choices,$$rowtotal,$onclick);
10135: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10136: $rowstyle);
10137: $$rowtotal ++;
10138: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10139: $rowstyle);
10140: $$rowtotal ++;
10141: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10142: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10143: my ($emailrules,$emailruleorder) =
10144: &Apache::lonnet::inst_userrules($dom,'email');
10145: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10146: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10147: if (ref($types) eq 'ARRAY') {
10148: @posstypes = @{$types};
10149: }
10150: if (@posstypes) {
10151: unless (grep(/^default$/,@posstypes)) {
10152: push(@posstypes,'default');
1.302 raeburn 10153: }
10154: if (ref($usertypes) eq 'HASH') {
10155: %usertypeshash = %{$usertypes};
10156: }
1.305 raeburn 10157: my $currassign;
10158: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10159: $currassign = {
10160: selfassign => $domdefaults{'inststatusguest'},
10161: };
10162: @ordered = @{$domdefaults{'inststatusguest'}};
10163: } else {
10164: $currassign = { selfassign => [] };
10165: }
10166: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10167: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10168: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10169: $numinrow,$othertitle,'selfassign',
10170: $rowtotal,$onclicktypes,$customclass,
10171: $rowstyle);
10172: $$rowtotal ++;
1.302 raeburn 10173: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10174: foreach my $status (@posstypes) {
10175: my $css_class;
10176: if ($$rowtotal%2) {
10177: $css_class = 'LC_odd_row ';
10178: }
10179: $css_class .= $customclass;
10180: my $rowid = $optionsprefix.$status;
10181: my $hidden = 1;
10182: my $currstyle = 'display:none';
10183: if (grep(/^\Q$status\E$/,@ordered)) {
10184: $currstyle = $rowstyle;
1.425 raeburn 10185: $hidden = 0;
1.305 raeburn 10186: }
10187: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10188: $emailrules,$emailruleorder,$settings,$status,$rowid,
10189: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10190: unless ($hidden) {
10191: $$rowtotal ++;
10192: }
1.224 raeburn 10193: }
1.302 raeburn 10194: } else {
1.305 raeburn 10195: my $css_class;
10196: if ($$rowtotal%2) {
10197: $css_class = 'LC_odd_row ';
10198: }
10199: $css_class .= $customclass;
1.302 raeburn 10200: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10201: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10202: $emailrules,$emailruleorder,$settings,'default','',
10203: $othertitle,$css_class,$rowstyle,$intdom);
10204: $$rowtotal ++;
1.224 raeburn 10205: }
10206: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10207: $numinrow = 1;
1.305 raeburn 10208: if (@posstypes) {
10209: foreach my $status (@posstypes) {
10210: my $rowid = $classprefix.$status;
10211: my $datarowstyle = 'display:none';
1.425 raeburn 10212: if (grep(/^\Q$status\E$/,@ordered)) {
10213: $datarowstyle = $rowstyle;
1.305 raeburn 10214: }
10215: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10216: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10217: $infotitles,$rowid,$customclass,$datarowstyle);
10218: unless ($datarowstyle eq 'display:none') {
10219: $$rowtotal ++;
10220: }
1.224 raeburn 10221: }
1.305 raeburn 10222: } else {
10223: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10224: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10225: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10226: }
10227: }
10228: return $datatable;
10229: }
10230:
1.305 raeburn 10231: sub selfcreate_javascript {
10232: return <<"ENDSCRIPT";
10233:
10234: <script type="text/javascript">
10235: // <![CDATA[
10236:
10237: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10238: var x = document.getElementsByClassName(target);
10239: var insttypes = 0;
10240: var insttypeRegExp = new RegExp(prefix);
10241: if ((x.length != undefined) && (x.length > 0)) {
10242: if (form.elements[radio].length != undefined) {
10243: for (var i=0; i<form.elements[radio].length; i++) {
10244: if (form.elements[radio][i].checked) {
10245: if (form.elements[radio][i].value == 1) {
10246: for (var j=0; j<x.length; j++) {
10247: if (x[j].id == 'undefined') {
10248: x[j].style.display = 'table-row';
10249: } else if (insttypeRegExp.test(x[j].id)) {
10250: insttypes ++;
10251: } else {
10252: x[j].style.display = 'table-row';
10253: }
10254: }
10255: } else {
10256: for (var j=0; j<x.length; j++) {
10257: x[j].style.display = 'none';
10258: }
1.236 raeburn 10259: }
1.305 raeburn 10260: break;
10261: }
10262: }
10263: if (insttypes > 0) {
10264: toggleDataRow(form,checkbox,target,altprefix);
10265: toggleDataRow(form,checkbox,target,prefix,1);
10266: }
10267: }
10268: }
10269: return;
10270: }
10271:
10272: function toggleDataRow(form,checkbox,target,prefix,docount) {
10273: if (form.elements[checkbox].length != undefined) {
10274: var count = 0;
10275: if (docount) {
10276: for (var i=0; i<form.elements[checkbox].length; i++) {
10277: if (form.elements[checkbox][i].checked) {
10278: count ++;
1.236 raeburn 10279: }
1.305 raeburn 10280: }
10281: }
10282: for (var i=0; i<form.elements[checkbox].length; i++) {
10283: var type = form.elements[checkbox][i].value;
10284: if (document.getElementById(prefix+type)) {
10285: if (form.elements[checkbox][i].checked) {
10286: document.getElementById(prefix+type).style.display = 'table-row';
10287: if (count % 2 == 1) {
10288: document.getElementById(prefix+type).className = target+' LC_odd_row';
10289: } else {
10290: document.getElementById(prefix+type).className = target;
1.236 raeburn 10291: }
1.305 raeburn 10292: count ++;
1.236 raeburn 10293: } else {
1.305 raeburn 10294: document.getElementById(prefix+type).style.display = 'none';
10295: }
10296: }
10297: }
10298: }
10299: return;
10300: }
10301:
10302: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10303: var caller = radio+'_'+status;
10304: if (form.elements[caller].length != undefined) {
10305: for (var i=0; i<form.elements[caller].length; i++) {
10306: if (form.elements[caller][i].checked) {
10307: if (document.getElementById(altprefix+'_inst_'+status)) {
10308: var curr = form.elements[caller][i].value;
10309: if (prefix) {
10310: document.getElementById(prefix+'_'+status).style.display = 'none';
10311: }
10312: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10313: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10314: if (curr == 'custom') {
1.425 raeburn 10315: if (prefix) {
1.305 raeburn 10316: document.getElementById(prefix+'_'+status).style.display = 'inline';
10317: }
10318: } else if (curr == 'inst') {
10319: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10320: } else if (curr == 'noninst') {
10321: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10322: }
1.305 raeburn 10323: break;
1.236 raeburn 10324: }
10325: }
10326: }
10327: }
10328: }
10329:
1.305 raeburn 10330: // ]]>
10331: </script>
10332:
10333: ENDSCRIPT
10334: }
10335:
10336: sub noninst_users {
10337: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10338: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10339: my $class = 'LC_left_item';
10340: if ($css_class) {
1.425 raeburn 10341: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10342: }
10343: if ($rowid) {
10344: $rowid = ' id="'.$rowid.'"';
10345: }
10346: if ($rowstyle) {
10347: $rowstyle = ' style="'.$rowstyle.'"';
10348: }
10349: my ($output,$description);
10350: if ($type eq 'default') {
10351: $description = &mt('Requests for: [_1]',$typetitle);
10352: } else {
10353: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10354: }
10355: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10356: "<td>$description</td>\n".
1.305 raeburn 10357: '<td class="'.$class.'" colspan="2">'.
10358: '<table><tr>';
1.425 raeburn 10359: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10360: approve => 'Processing',
10361: email => 'E-mail',
10362: username => 'Username',
10363: );
10364: foreach my $item ('approve','email','username') {
10365: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10366: }
1.305 raeburn 10367: $output .= '</tr><tr>';
10368: foreach my $item ('approve','email','username') {
1.306 raeburn 10369: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10370: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10371: if ($item eq 'approve') {
10372: %choices = &Apache::lonlocal::texthash (
10373: automatic => 'Automatically approved',
10374: approval => 'Queued for approval',
10375: );
10376: @options = ('automatic','approval');
10377: $hashref = $processing;
10378: $defoption = 'automatic';
10379: $name = 'cancreate_emailprocess_'.$type;
10380: } elsif ($item eq 'email') {
10381: %choices = &Apache::lonlocal::texthash (
10382: any => 'Any e-mail',
10383: inst => 'Institutional only',
10384: noninst => 'Non-institutional only',
10385: custom => 'Custom restrictions',
10386: );
10387: @options = ('any','inst','noninst');
10388: my $showcustom;
10389: if (ref($emailrules) eq 'HASH') {
10390: if (keys(%{$emailrules}) > 0) {
10391: push(@options,'custom');
10392: $showcustom = 'cancreate_emailrule';
10393: if (ref($settings) eq 'HASH') {
10394: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10395: foreach my $rule (@{$settings->{'email_rule'}}) {
10396: if (exists($emailrules->{$rule})) {
10397: $hascustom ++;
10398: }
10399: }
10400: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10401: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10402: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10403: if (exists($emailrules->{$rule})) {
10404: $hascustom ++;
10405: }
10406: }
10407: }
10408: }
10409: }
10410: }
10411: }
10412: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10413: "'cancreate_emaildomain','$type'".');"';
10414: $hashref = $emailoptions;
10415: $defoption = 'any';
10416: $name = 'cancreate_emailoptions_'.$type;
10417: } elsif ($item eq 'username') {
10418: %choices = &Apache::lonlocal::texthash (
10419: all => 'Same as e-mail',
10420: first => 'Omit @domain',
10421: free => 'Free to choose',
10422: );
10423: @options = ('all','first','free');
10424: $hashref = $emailverified;
10425: $defoption = 'all';
10426: $name = 'cancreate_usernameoptions_'.$type;
10427: }
10428: foreach my $option (@options) {
10429: my $checked;
10430: if (ref($hashref) eq 'HASH') {
10431: if ($type eq '') {
10432: if (!exists($hashref->{'default'})) {
10433: if ($option eq $defoption) {
10434: $checked = ' checked="checked"';
10435: }
10436: } else {
10437: if ($hashref->{'default'} eq $option) {
10438: $checked = ' checked="checked"';
10439: }
1.303 raeburn 10440: }
10441: } else {
1.305 raeburn 10442: if (!exists($hashref->{$type})) {
10443: if ($option eq $defoption) {
10444: $checked = ' checked="checked"';
10445: }
10446: } else {
10447: if ($hashref->{$type} eq $option) {
10448: $checked = ' checked="checked"';
10449: }
1.303 raeburn 10450: }
10451: }
1.305 raeburn 10452: } elsif (($item eq 'email') && ($hascustom)) {
10453: if ($option eq 'custom') {
10454: $checked = ' checked="checked"';
10455: }
10456: } elsif ($option eq $defoption) {
10457: $checked = ' checked="checked"';
10458: }
10459: $output .= '<span class="LC_nobreak"><label>'.
10460: '<input type="radio" name="'.$name.'"'.
10461: $checked.' value="'.$option.'"'.$onclick.' />'.
10462: $choices{$option}.'</label></span><br />';
10463: if ($item eq 'email') {
10464: if ($option eq 'custom') {
10465: my $id = 'cancreate_emailrule_'.$type;
10466: my $display = 'none';
10467: if ($checked) {
10468: $display = 'inline';
1.303 raeburn 10469: }
1.305 raeburn 10470: my $numinrow = 2;
10471: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10472: '<legend>'.&mt('Disallow').'</legend><table>'.
10473: &user_formats_row('email',$settings,$emailrules,
10474: $emailruleorder,$numinrow,'',$type);
10475: '</table></fieldset>';
10476: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10477: my %text = &Apache::lonlocal::texthash (
10478: inst => 'must end:',
10479: noninst => 'cannot end:',
10480: );
10481: my $value;
10482: if (ref($emaildomain) eq 'HASH') {
10483: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10484: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10485: }
10486: }
1.305 raeburn 10487: if ($value eq '') {
10488: $value = '@'.$intdom;
10489: }
10490: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10491: my $display = 'none';
10492: if ($checked) {
10493: $display = 'inline';
10494: }
10495: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10496: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10497: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10498: '</div>';
1.303 raeburn 10499: }
10500: }
10501: }
1.305 raeburn 10502: $output .= '</td>'."\n";
1.303 raeburn 10503: }
1.305 raeburn 10504: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10505: return $output;
10506: }
10507:
1.165 raeburn 10508: sub captcha_choice {
1.305 raeburn 10509: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10510: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10511: $vertext,$currver);
1.165 raeburn 10512: my %lt = &captcha_phrases();
10513: $keyentry = 'hidden';
1.354 raeburn 10514: my $colspan=2;
1.165 raeburn 10515: if ($context eq 'cancreate') {
1.224 raeburn 10516: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10517: } elsif ($context eq 'login') {
10518: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10519: } elsif ($context eq 'passwords') {
10520: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10521: $colspan=1;
1.165 raeburn 10522: }
10523: if (ref($settings) eq 'HASH') {
10524: if ($settings->{'captcha'}) {
10525: $checked{$settings->{'captcha'}} = ' checked="checked"';
10526: } else {
10527: $checked{'original'} = ' checked="checked"';
10528: }
10529: if ($settings->{'captcha'} eq 'recaptcha') {
10530: $pubtext = $lt{'pub'};
10531: $privtext = $lt{'priv'};
10532: $keyentry = 'text';
1.269 raeburn 10533: $vertext = $lt{'ver'};
10534: $currver = $settings->{'recaptchaversion'};
10535: if ($currver ne '2') {
10536: $currver = 1;
10537: }
1.165 raeburn 10538: }
10539: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10540: $currpub = $settings->{'recaptchakeys'}{'public'};
10541: $currpriv = $settings->{'recaptchakeys'}{'private'};
10542: }
10543: } else {
10544: $checked{'original'} = ' checked="checked"';
10545: }
1.305 raeburn 10546: my $css_class;
10547: if ($itemcount%2) {
10548: $css_class = 'LC_odd_row';
10549: }
10550: if ($customcss) {
10551: $css_class .= " $customcss";
10552: }
10553: $css_class =~ s/^\s+//;
10554: if ($css_class) {
10555: $css_class = ' class="'.$css_class.'"';
10556: }
10557: if ($rowstyle) {
10558: $css_class .= ' style="'.$rowstyle.'"';
10559: }
1.169 raeburn 10560: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10561: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10562: '<table><tr><td>'."\n";
10563: foreach my $option ('original','recaptcha','notused') {
10564: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10565: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10566: $lt{$option}.'</label></span>';
10567: unless ($option eq 'notused') {
10568: $output .= (' 'x2)."\n";
10569: }
10570: }
10571: #
10572: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10573: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10574: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10575: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10576: #
1.165 raeburn 10577: $output .= '</td></tr>'."\n".
1.305 raeburn 10578: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10579: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10580: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10581: $currpub.'" size="40" /></span><br />'."\n".
10582: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10583: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10584: $currpriv.'" size="40" /></span><br />'.
10585: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10586: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10587: $currver.'" size="3" /></span><br />'.
10588: '</td></tr></table>'."\n".
1.165 raeburn 10589: '</td></tr>';
10590: return $output;
10591: }
10592:
1.32 raeburn 10593: sub user_formats_row {
1.305 raeburn 10594: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10595: my $output;
10596: my %text = (
10597: 'username' => 'new usernames',
10598: 'id' => 'IDs',
10599: );
1.409 raeburn 10600: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10601: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10602: $output = '<tr '.$css_class.'>'.
10603: '<td><span class="LC_nobreak">'.
10604: &mt("Format rules to check for $text{$type}: ").
10605: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10606: }
1.27 raeburn 10607: my $rem;
10608: if (ref($ruleorder) eq 'ARRAY') {
10609: for (my $i=0; $i<@{$ruleorder}; $i++) {
10610: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10611: my $rem = $i%($numinrow);
10612: if ($rem == 0) {
10613: if ($i > 0) {
10614: $output .= '</tr>';
10615: }
10616: $output .= '<tr>';
10617: }
10618: my $check = ' ';
1.39 raeburn 10619: if (ref($settings) eq 'HASH') {
10620: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10621: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10622: $check = ' checked="checked" ';
10623: }
1.305 raeburn 10624: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10625: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10626: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10627: $check = ' checked="checked" ';
10628: }
10629: }
1.27 raeburn 10630: }
10631: }
1.305 raeburn 10632: my $name = $type.'_rule';
10633: if ($type eq 'email') {
10634: $name .= '_'.$status;
10635: }
1.27 raeburn 10636: $output .= '<td class="LC_left_item">'.
10637: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10638: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10639: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10640: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10641: }
10642: }
10643: $rem = @{$ruleorder}%($numinrow);
10644: }
1.305 raeburn 10645: my $colsleft;
10646: if ($rem) {
10647: $colsleft = $numinrow - $rem;
10648: }
1.27 raeburn 10649: if ($colsleft > 1 ) {
10650: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10651: ' </td>';
10652: } elsif ($colsleft == 1) {
10653: $output .= '<td class="LC_left_item"> </td>';
10654: }
1.409 raeburn 10655: $output .= '</tr>';
10656: unless (($type eq 'email') || ($type eq 'unamemap')) {
10657: $output .= '</table></td></tr>';
1.305 raeburn 10658: }
1.27 raeburn 10659: return $output;
10660: }
10661:
1.34 raeburn 10662: sub usercreation_types {
10663: my %lt = &Apache::lonlocal::texthash (
10664: author => 'When adding a co-author',
10665: course => 'When adding a user to a course',
1.100 raeburn 10666: requestcrs => 'When requesting a course',
1.34 raeburn 10667: any => 'Any',
10668: official => 'Institutional only ',
10669: unofficial => 'Non-institutional only',
10670: none => 'None',
10671: );
10672: return %lt;
1.48 raeburn 10673: }
1.34 raeburn 10674:
1.224 raeburn 10675: sub selfcreation_types {
10676: my %lt = &Apache::lonlocal::texthash (
10677: selfcreate => 'User creates own account',
10678: any => 'Any',
10679: official => 'Institutional only ',
10680: unofficial => 'Non-institutional only',
10681: email => 'E-mail address',
10682: login => 'Institutional Login',
10683: sso => 'SSO',
10684: );
10685: }
10686:
1.28 raeburn 10687: sub authtype_names {
10688: my %lt = &Apache::lonlocal::texthash(
10689: int => 'Internal',
10690: krb4 => 'Kerberos 4',
10691: krb5 => 'Kerberos 5',
10692: loc => 'Local',
1.325 raeburn 10693: lti => 'LTI',
1.28 raeburn 10694: );
10695: return %lt;
10696: }
10697:
10698: sub context_names {
10699: my %context_title = &Apache::lonlocal::texthash(
10700: author => 'Creating users when an Author',
10701: course => 'Creating users when in a course',
10702: domain => 'Creating users when a Domain Coordinator',
10703: );
10704: return %context_title;
10705: }
10706:
1.33 raeburn 10707: sub print_usermodification {
10708: my ($position,$dom,$settings,$rowtotal) = @_;
10709: my $numinrow = 4;
10710: my ($context,$datatable,$rowcount);
10711: if ($position eq 'top') {
10712: $rowcount = 0;
10713: $context = 'author';
10714: foreach my $role ('ca','aa') {
10715: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10716: $numinrow,$rowcount);
10717: $$rowtotal ++;
10718: $rowcount ++;
10719: }
1.443 raeburn 10720: } elsif ($position eq 'middle') {
10721: $rowcount = 0;
10722: $context = 'coauthor';
10723: foreach my $role ('ca','aa') {
10724: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10725: $numinrow,$rowcount);
10726: $$rowtotal ++;
10727: $rowcount ++;
10728: }
1.230 raeburn 10729: } elsif ($position eq 'bottom') {
1.33 raeburn 10730: $context = 'course';
10731: $rowcount = 0;
10732: foreach my $role ('st','ep','ta','in','cr') {
10733: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10734: $numinrow,$rowcount);
10735: $$rowtotal ++;
10736: $rowcount ++;
10737: }
10738: }
10739: return $datatable;
10740: }
10741:
1.43 raeburn 10742: sub print_defaults {
1.236 raeburn 10743: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10744: my $rownum = 0;
1.294 raeburn 10745: my ($datatable,$css_class,$titles);
10746: unless ($position eq 'bottom') {
10747: $titles = &defaults_titles($dom);
10748: }
1.236 raeburn 10749: if ($position eq 'top') {
10750: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10751: 'datelocale_def','portal_def');
10752: my %defaults;
10753: if (ref($settings) eq 'HASH') {
10754: %defaults = %{$settings};
1.43 raeburn 10755: } else {
1.236 raeburn 10756: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10757: foreach my $item (@items) {
10758: $defaults{$item} = $domdefaults{$item};
10759: }
1.43 raeburn 10760: }
1.236 raeburn 10761: foreach my $item (@items) {
10762: if ($rownum%2) {
10763: $css_class = '';
10764: } else {
10765: $css_class = ' class="LC_odd_row" ';
10766: }
10767: $datatable .= '<tr'.$css_class.'>'.
10768: '<td><span class="LC_nobreak">'.$titles->{$item}.
10769: '</span></td><td class="LC_right_item" colspan="3">';
10770: if ($item eq 'auth_def') {
1.325 raeburn 10771: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10772: my %shortauth = (
10773: internal => 'int',
10774: krb4 => 'krb4',
10775: krb5 => 'krb5',
1.325 raeburn 10776: localauth => 'loc',
10777: lti => 'lti',
1.236 raeburn 10778: );
10779: my %authnames = &authtype_names();
10780: foreach my $auth (@authtypes) {
10781: my $checked = ' ';
10782: if ($defaults{$item} eq $auth) {
10783: $checked = ' checked="checked" ';
10784: }
10785: $datatable .= '<label><input type="radio" name="'.$item.
10786: '" value="'.$auth.'"'.$checked.'/>'.
10787: $authnames{$shortauth{$auth}}.'</label> ';
10788: }
10789: } elsif ($item eq 'timezone_def') {
10790: my $includeempty = 1;
10791: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10792: } elsif ($item eq 'datelocale_def') {
10793: my $includeempty = 1;
10794: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10795: } elsif ($item eq 'lang_def') {
1.263 raeburn 10796: my $includeempty = 1;
10797: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10798: } elsif ($item eq 'portal_def') {
10799: $datatable .= '<input type="text" name="'.$item.'" value="'.
10800: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10801: my $portalsty = 'none';
10802: if ($defaults{$item}) {
10803: $portalsty = 'block';
10804: }
10805: foreach my $field ('email','web') {
10806: my $checkedoff = ' checked="checked"';
10807: my $checkedon;
10808: if ($defaults{$item.'_'.$field}) {
10809: $checkedon = $checkedoff;
10810: $checkedoff = '';
1.425 raeburn 10811: }
1.414 raeburn 10812: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10813: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10814: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10815: (' 'x2).
10816: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10817: '</div>';
10818: }
1.236 raeburn 10819: } else {
1.414 raeburn 10820: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10821: }
1.236 raeburn 10822: $datatable .= '</td></tr>';
10823: $rownum ++;
10824: }
1.409 raeburn 10825: } elsif ($position eq 'middle') {
1.294 raeburn 10826: my %defaults;
10827: if (ref($settings) eq 'HASH') {
1.354 raeburn 10828: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10829: my $maxnum = @{$settings->{'inststatusorder'}};
10830: for (my $i=0; $i<$maxnum; $i++) {
10831: $css_class = $rownum%2?' class="LC_odd_row"':'';
10832: my $item = $settings->{'inststatusorder'}->[$i];
10833: my $title = $settings->{'inststatustypes'}->{$item};
10834: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10835: $datatable .= '<tr'.$css_class.'>'.
10836: '<td><span class="LC_nobreak">'.
10837: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10838: for (my $k=0; $k<=$maxnum; $k++) {
10839: my $vpos = $k+1;
10840: my $selstr;
10841: if ($k == $i) {
10842: $selstr = ' selected="selected" ';
10843: }
10844: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10845: }
10846: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10847: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10848: &mt('delete').'</span></td>'.
1.380 raeburn 10849: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10850: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10851: '</span></td></tr>';
10852: }
10853: $css_class = $rownum%2?' class="LC_odd_row"':'';
10854: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10855: $datatable .= '<tr '.$css_class.'>'.
10856: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10857: for (my $k=0; $k<=$maxnum; $k++) {
10858: my $vpos = $k+1;
10859: my $selstr;
10860: if ($k == $maxnum) {
10861: $selstr = ' selected="selected" ';
10862: }
10863: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10864: }
10865: $datatable .= '</select> '.&mt('Internal ID:').
10866: '<input type="text" size="10" name="addinststatus" value="" />'.
10867: ' '.&mt('(new)').
10868: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10869: &mt('Name displayed').':'.
1.354 raeburn 10870: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10871: '</tr>'."\n";
10872: $rownum ++;
1.294 raeburn 10873: }
1.354 raeburn 10874: }
1.409 raeburn 10875: } else {
10876: my ($unamemaprules,$ruleorder) =
10877: &Apache::lonnet::inst_userrules($dom,'unamemap');
10878: $css_class = $rownum%2?' class="LC_odd_row"':'';
10879: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10880: my $numinrow = 2;
10881: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10882: &user_formats_row('unamemap',$settings,$unamemaprules,
10883: $ruleorder,$numinrow).
10884: '</table></td></tr>';
10885: }
10886: if ($datatable eq '') {
10887: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10888: &mt('No rules set for domain in customized localenroll.pm').
10889: '</td></tr>';
10890: }
1.354 raeburn 10891: }
10892: $$rowtotal += $rownum;
1.43 raeburn 10893: return $datatable;
10894: }
10895:
1.168 raeburn 10896: sub get_languages_hash {
10897: my %langchoices;
10898: foreach my $id (&Apache::loncommon::languageids()) {
10899: my $code = &Apache::loncommon::supportedlanguagecode($id);
10900: if ($code ne '') {
10901: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10902: }
10903: }
10904: return %langchoices;
10905: }
10906:
1.43 raeburn 10907: sub defaults_titles {
1.141 raeburn 10908: my ($dom) = @_;
1.43 raeburn 10909: my %titles = &Apache::lonlocal::texthash (
10910: 'auth_def' => 'Default authentication type',
10911: 'auth_arg_def' => 'Default authentication argument',
10912: 'lang_def' => 'Default language',
1.54 raeburn 10913: 'timezone_def' => 'Default timezone',
1.68 raeburn 10914: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10915: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10916: 'email' => 'Email links use portal URL',
10917: 'web' => 'Public web links use portal URL',
1.294 raeburn 10918: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10919: 'intauth_check' => 'Check bcrypt cost if authenticated',
10920: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10921: );
1.141 raeburn 10922: if ($dom) {
10923: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10924: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10925: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10926: $protocol = 'http' if ($protocol ne 'https');
10927: if ($uint_dom) {
10928: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10929: $uint_dom);
10930: }
10931: }
1.43 raeburn 10932: return (\%titles);
10933: }
10934:
1.346 raeburn 10935: sub print_scantron {
10936: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10937: if ($position eq 'top') {
10938: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10939: } else {
10940: return &print_scantronconfig($dom,$settings,\$rowtotal);
10941: }
10942: }
10943:
10944: sub scantron_javascript {
10945: return <<"ENDSCRIPT";
10946:
10947: <script type="text/javascript">
10948: // <![CDATA[
10949:
10950: function toggleScantron(form) {
1.347 raeburn 10951: var csvfieldset = new Array();
1.346 raeburn 10952: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10953: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10954: }
10955: if (document.getElementById('scantroncsv_options')) {
10956: csvfieldset.push(document.getElementById('scantroncsv_options'));
10957: }
10958: if (csvfieldset.length) {
1.346 raeburn 10959: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10960: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10961: if (scantroncsv.checked) {
1.347 raeburn 10962: for (var i=0; i<csvfieldset.length; i++) {
10963: csvfieldset[i].style.display = 'block';
10964: }
1.346 raeburn 10965: } else {
1.347 raeburn 10966: for (var i=0; i<csvfieldset.length; i++) {
10967: csvfieldset[i].style.display = 'none';
10968: }
1.346 raeburn 10969: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10970: if (csvselects.length) {
10971: for (var j=0; j<csvselects.length; j++) {
10972: csvselects[j].selectedIndex = 0;
10973: }
10974: }
10975: }
10976: }
10977: }
10978: return;
10979: }
10980: // ]]>
10981: </script>
10982:
10983: ENDSCRIPT
10984:
10985: }
10986:
1.46 raeburn 10987: sub print_scantronformat {
10988: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10989: my $itemcount = 1;
1.60 raeburn 10990: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10991: %confhash);
1.46 raeburn 10992: my $switchserver = &check_switchserver($dom,$confname);
10993: my %lt = &Apache::lonlocal::texthash (
1.95 www 10994: default => 'Default bubblesheet format file error',
10995: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10996: );
10997: my %scantronfiles = (
10998: default => 'default.tab',
10999: custom => 'custom.tab',
11000: );
11001: foreach my $key (keys(%scantronfiles)) {
11002: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11003: .$scantronfiles{$key};
11004: }
11005: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11006: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11007: if (!$switchserver) {
11008: my $servadm = $r->dir_config('lonAdmEMail');
11009: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11010: if ($configuserok eq 'ok') {
11011: if ($author_ok eq 'ok') {
11012: my %legacyfile = (
1.346 raeburn 11013: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11014: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11015: );
11016: my %md5chk;
11017: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11018: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11019: chomp($md5chk{$type});
1.46 raeburn 11020: }
11021: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11022: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11023: ($scantronurls{$type},my $error) =
1.46 raeburn 11024: &legacy_scantronformat($r,$dom,$confname,
11025: $type,$legacyfile{$type},
11026: $scantronurls{$type},
11027: $scantronfiles{$type});
1.60 raeburn 11028: if ($error ne '') {
11029: $error{$type} = $error;
11030: }
11031: }
11032: if (keys(%error) == 0) {
11033: $is_custom = 1;
1.346 raeburn 11034: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11035: $scantronurls{'custom'};
1.346 raeburn 11036: my $putresult =
1.60 raeburn 11037: &Apache::lonnet::put_dom('configuration',
11038: \%confhash,$dom);
11039: if ($putresult ne 'ok') {
1.346 raeburn 11040: $error{'custom'} =
1.60 raeburn 11041: '<span class="LC_error">'.
11042: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11043: }
1.46 raeburn 11044: }
11045: } else {
1.60 raeburn 11046: ($scantronurls{'default'},my $error) =
1.46 raeburn 11047: &legacy_scantronformat($r,$dom,$confname,
11048: 'default',$legacyfile{'default'},
11049: $scantronurls{'default'},
11050: $scantronfiles{'default'});
1.60 raeburn 11051: if ($error eq '') {
11052: $confhash{'scantron'}{'scantronformat'} = '';
11053: my $putresult =
11054: &Apache::lonnet::put_dom('configuration',
11055: \%confhash,$dom);
11056: if ($putresult ne 'ok') {
11057: $error{'default'} =
11058: '<span class="LC_error">'.
11059: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11060: }
11061: } else {
11062: $error{'default'} = $error;
11063: }
1.46 raeburn 11064: }
11065: }
11066: }
11067: } else {
1.95 www 11068: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11069: }
11070: }
11071: if (ref($settings) eq 'HASH') {
11072: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11073: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11074: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11075: $scantronurl = '';
11076: } else {
11077: $scantronurl = $settings->{'scantronformat'};
11078: }
11079: $is_custom = 1;
11080: } else {
11081: $scantronurl = $scantronurls{'default'};
11082: }
11083: } else {
1.60 raeburn 11084: if ($is_custom) {
11085: $scantronurl = $scantronurls{'custom'};
11086: } else {
11087: $scantronurl = $scantronurls{'default'};
11088: }
1.46 raeburn 11089: }
11090: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11091: $datatable .= '<tr'.$css_class.'>';
11092: if (!$is_custom) {
1.65 raeburn 11093: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11094: '<span class="LC_nobreak">';
1.46 raeburn 11095: if ($scantronurl) {
1.199 raeburn 11096: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11097: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11098: } else {
11099: $datatable = &mt('File unavailable for display');
11100: }
1.65 raeburn 11101: $datatable .= '</span></td>';
1.60 raeburn 11102: if (keys(%error) == 0) {
1.306 raeburn 11103: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11104: if (!$switchserver) {
11105: $datatable .= &mt('Upload:').'<br />';
11106: }
11107: } else {
11108: my $errorstr;
11109: foreach my $key (sort(keys(%error))) {
11110: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11111: }
11112: $datatable .= '<td>'.$errorstr;
11113: }
1.46 raeburn 11114: } else {
11115: if (keys(%error) > 0) {
11116: my $errorstr;
11117: foreach my $key (sort(keys(%error))) {
11118: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11119: }
1.60 raeburn 11120: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11121: } elsif ($scantronurl) {
1.199 raeburn 11122: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11123: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11124: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11125: $link.
11126: '<label><input type="checkbox" name="scantronformat_del"'.
11127: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11128: '<td><span class="LC_nobreak"> '.
11129: &mt('Replace:').'</span><br />';
1.46 raeburn 11130: }
11131: }
11132: if (keys(%error) == 0) {
11133: if ($switchserver) {
11134: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11135: } else {
1.65 raeburn 11136: $datatable .='<span class="LC_nobreak"> '.
11137: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11138: }
11139: }
11140: $datatable .= '</td></tr>';
11141: $$rowtotal ++;
11142: return $datatable;
11143: }
11144:
11145: sub legacy_scantronformat {
11146: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11147: my ($url,$error);
11148: my @statinfo = &Apache::lonnet::stat_file($newurl);
11149: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11150: my $modified = [];
1.46 raeburn 11151: (my $result,$url) =
1.421 raeburn 11152: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11153: 'scantron','','',$newfile,$modified);
11154: if ($result eq 'ok') {
11155: &update_modify_urls($r,$modified);
11156: } else {
1.130 raeburn 11157: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11158: }
11159: }
11160: return ($url,$error);
11161: }
1.43 raeburn 11162:
1.346 raeburn 11163: sub print_scantronconfig {
11164: my ($dom,$settings,$rowtotal) = @_;
11165: my $itemcount = 2;
11166: my $is_checked = ' checked="checked"';
1.347 raeburn 11167: my %optionson = (
11168: hdr => ' checked="checked"',
11169: pad => ' checked="checked"',
11170: rem => ' checked="checked"',
11171: );
11172: my %optionsoff = (
11173: hdr => '',
11174: pad => '',
11175: rem => '',
11176: );
1.346 raeburn 11177: my $currcsvsty = 'none';
1.347 raeburn 11178: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11179: my @fields = &scantroncsv_fields();
11180: my %titles = &scantronconfig_titles();
11181: if (ref($settings) eq 'HASH') {
11182: if (ref($settings->{config}) eq 'HASH') {
11183: if ($settings->{config}->{dat}) {
11184: $checked{'dat'} = $is_checked;
11185: }
11186: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11187: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11188: %csvfields = %{$settings->{config}->{csv}->{fields}};
11189: if (keys(%csvfields) > 0) {
11190: $checked{'csv'} = $is_checked;
11191: $currcsvsty = 'block';
11192: }
11193: }
11194: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11195: %csvoptions = %{$settings->{config}->{csv}->{options}};
11196: foreach my $option (keys(%optionson)) {
11197: unless ($csvoptions{$option}) {
11198: $optionsoff{$option} = $optionson{$option};
11199: $optionson{$option} = '';
11200: }
11201: }
1.346 raeburn 11202: }
11203: }
11204: } else {
11205: $checked{'dat'} = $is_checked;
11206: }
11207: } else {
11208: $checked{'dat'} = $is_checked;
11209: }
11210: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11211: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11212: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11213: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11214: foreach my $item ('dat','csv') {
11215: my $id;
11216: if ($item eq 'csv') {
11217: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11218: }
1.346 raeburn 11219: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11220: $titles{$item}.'</label>'.(' 'x3);
11221: if ($item eq 'csv') {
11222: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11223: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11224: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11225: foreach my $col (@fields) {
11226: my $selnone;
11227: if ($csvfields{$col} eq '') {
11228: $selnone = ' selected="selected"';
11229: }
11230: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11231: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11232: '<option value=""'.$selnone.'></option>';
11233: for (my $i=0; $i<20; $i++) {
11234: my $shown = $i+1;
11235: my $sel;
11236: unless ($selnone) {
11237: if (exists($csvfields{$col})) {
11238: if ($csvfields{$col} == $i) {
11239: $sel = ' selected="selected"';
11240: }
11241: }
11242: }
11243: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11244: }
11245: $datatable .= '</select></td></tr>';
11246: }
1.347 raeburn 11247: $datatable .= '</table></fieldset>'.
11248: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11249: '<legend>'.&mt('CSV Options').'</legend>';
11250: foreach my $option ('hdr','pad','rem') {
11251: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11252: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11253: &mt('Yes').'</label>'.(' 'x2)."\n".
11254: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11255: }
11256: $datatable .= '</fieldset>';
1.346 raeburn 11257: $itemcount ++;
11258: }
11259: }
11260: $datatable .= '</td></tr>';
11261: $$rowtotal ++;
11262: return $datatable;
11263: }
11264:
11265: sub scantronconfig_titles {
11266: return &Apache::lonlocal::texthash(
11267: dat => 'Standard format (.dat)',
11268: csv => 'Comma separated values (.csv)',
1.347 raeburn 11269: hdr => 'Remove first line in file (contains column titles)',
11270: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11271: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11272: CODE => 'CODE',
11273: ID => 'Student ID',
11274: PaperID => 'Paper ID',
11275: FirstName => 'First Name',
11276: LastName => 'Last Name',
11277: FirstQuestion => 'First Question Response',
11278: Section => 'Section',
11279: );
11280: }
11281:
11282: sub scantroncsv_fields {
11283: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11284: }
11285:
1.49 raeburn 11286: sub print_coursecategories {
1.57 raeburn 11287: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11288: my $datatable;
11289: if ($position eq 'top') {
1.238 raeburn 11290: my (%checked);
11291: my @catitems = ('unauth','auth');
11292: my @cattypes = ('std','domonly','codesrch','none');
11293: $checked{'unauth'} = 'std';
11294: $checked{'auth'} = 'std';
11295: if (ref($settings) eq 'HASH') {
11296: foreach my $type (@cattypes) {
11297: if ($type eq $settings->{'unauth'}) {
11298: $checked{'unauth'} = $type;
11299: }
11300: if ($type eq $settings->{'auth'}) {
11301: $checked{'auth'} = $type;
11302: }
11303: }
11304: }
11305: my %lt = &Apache::lonlocal::texthash (
11306: unauth => 'Catalog type for unauthenticated users',
11307: auth => 'Catalog type for authenticated users',
11308: none => 'No catalog',
11309: std => 'Standard catalog',
11310: domonly => 'Domain-only catalog',
11311: codesrch => "Code search form",
11312: );
11313: my $itemcount = 0;
11314: foreach my $item (@catitems) {
11315: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11316: $datatable .= '<tr '.$css_class.'>'.
11317: '<td>'.$lt{$item}.'</td>'.
11318: '<td class="LC_right_item"><span class="LC_nobreak">';
11319: foreach my $type (@cattypes) {
11320: my $ischecked;
11321: if ($checked{$item} eq $type) {
11322: $ischecked=' checked="checked"';
11323: }
11324: $datatable .= '<label>'.
11325: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11326: ' />'.$lt{$type}.'</label> ';
11327: }
1.327 raeburn 11328: $datatable .= '</span></td></tr>';
1.238 raeburn 11329: $itemcount ++;
11330: }
11331: $$rowtotal += $itemcount;
11332: } elsif ($position eq 'middle') {
1.57 raeburn 11333: my $toggle_cats_crs = ' ';
11334: my $toggle_cats_dom = ' checked="checked" ';
11335: my $can_cat_crs = ' ';
11336: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11337: my $toggle_catscomm_comm = ' ';
11338: my $toggle_catscomm_dom = ' checked="checked" ';
11339: my $can_catcomm_comm = ' ';
11340: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11341: my $toggle_catsplace_place = ' ';
11342: my $toggle_catsplace_dom = ' checked="checked" ';
11343: my $can_catplace_place = ' ';
11344: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11345:
1.57 raeburn 11346: if (ref($settings) eq 'HASH') {
11347: if ($settings->{'togglecats'} eq 'crs') {
11348: $toggle_cats_crs = $toggle_cats_dom;
11349: $toggle_cats_dom = ' ';
11350: }
11351: if ($settings->{'categorize'} eq 'crs') {
11352: $can_cat_crs = $can_cat_dom;
11353: $can_cat_dom = ' ';
11354: }
1.120 raeburn 11355: if ($settings->{'togglecatscomm'} eq 'comm') {
11356: $toggle_catscomm_comm = $toggle_catscomm_dom;
11357: $toggle_catscomm_dom = ' ';
11358: }
11359: if ($settings->{'categorizecomm'} eq 'comm') {
11360: $can_catcomm_comm = $can_catcomm_dom;
11361: $can_catcomm_dom = ' ';
11362: }
1.272 raeburn 11363: if ($settings->{'togglecatsplace'} eq 'place') {
11364: $toggle_catsplace_place = $toggle_catsplace_dom;
11365: $toggle_catsplace_dom = ' ';
11366: }
11367: if ($settings->{'categorizeplace'} eq 'place') {
11368: $can_catplace_place = $can_catplace_dom;
11369: $can_catplace_dom = ' ';
11370: }
1.57 raeburn 11371: }
11372: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11373: togglecats => 'Show/Hide a course in catalog',
11374: togglecatscomm => 'Show/Hide a community in catalog',
11375: togglecatsplace => 'Show/Hide a placement test in catalog',
11376: categorize => 'Assign a category to a course',
11377: categorizecomm => 'Assign a category to a community',
11378: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11379: );
11380: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11381: dom => 'Set in Domain',
11382: crs => 'Set in Course',
11383: comm => 'Set in Community',
11384: place => 'Set in Placement Test',
1.57 raeburn 11385: );
11386: $datatable = '<tr class="LC_odd_row">'.
11387: '<td>'.$title{'togglecats'}.'</td>'.
11388: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11389: '<input type="radio" name="togglecats"'.
11390: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11391: '<label><input type="radio" name="togglecats"'.
11392: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11393: '</tr><tr>'.
11394: '<td>'.$title{'categorize'}.'</td>'.
11395: '<td class="LC_right_item"><span class="LC_nobreak">'.
11396: '<label><input type="radio" name="categorize"'.
11397: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11398: '<label><input type="radio" name="categorize"'.
11399: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11400: '</tr><tr class="LC_odd_row">'.
11401: '<td>'.$title{'togglecatscomm'}.'</td>'.
11402: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11403: '<input type="radio" name="togglecatscomm"'.
11404: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11405: '<label><input type="radio" name="togglecatscomm"'.
11406: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11407: '</tr><tr>'.
11408: '<td>'.$title{'categorizecomm'}.'</td>'.
11409: '<td class="LC_right_item"><span class="LC_nobreak">'.
11410: '<label><input type="radio" name="categorizecomm"'.
11411: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11412: '<label><input type="radio" name="categorizecomm"'.
11413: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11414: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11415: '<td>'.$title{'togglecatsplace'}.'</td>'.
11416: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11417: '<input type="radio" name="togglecatsplace"'.
11418: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11419: '<label><input type="radio" name="togglecatscomm"'.
11420: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11421: '</tr><tr>'.
11422: '<td>'.$title{'categorizeplace'}.'</td>'.
11423: '<td class="LC_right_item"><span class="LC_nobreak">'.
11424: '<label><input type="radio" name="categorizeplace"'.
11425: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11426: '<label><input type="radio" name="categorizeplace"'.
11427: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11428: '</tr>';
1.272 raeburn 11429: $$rowtotal += 6;
1.57 raeburn 11430: } else {
11431: my $css_class;
11432: my $itemcount = 1;
11433: my $cathash;
11434: if (ref($settings) eq 'HASH') {
11435: $cathash = $settings->{'cats'};
11436: }
11437: if (ref($cathash) eq 'HASH') {
11438: my (@cats,@trails,%allitems,%idx,@jsarray);
11439: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11440: \%allitems,\%idx,\@jsarray);
11441: my $maxdepth = scalar(@cats);
11442: my $colattrib = '';
11443: if ($maxdepth > 2) {
11444: $colattrib = ' colspan="2" ';
11445: }
11446: my @path;
11447: if (@cats > 0) {
11448: if (ref($cats[0]) eq 'ARRAY') {
11449: my $numtop = @{$cats[0]};
11450: my $maxnum = $numtop;
1.120 raeburn 11451: my %default_names = (
11452: instcode => &mt('Official courses'),
11453: communities => &mt('Communities'),
1.272 raeburn 11454: placement => &mt('Placement Tests'),
1.120 raeburn 11455: );
11456:
11457: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11458: ($cathash->{'instcode::0'} eq '') ||
11459: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11460: ($cathash->{'communities::0'} eq '') ||
11461: (!grep(/^placement$/,@{$cats[0]})) ||
11462: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11463: $maxnum ++;
11464: }
11465: my $lastidx;
11466: for (my $i=0; $i<$numtop; $i++) {
11467: my $parent = $cats[0][$i];
11468: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11469: my $item = &escape($parent).'::0';
11470: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11471: $lastidx = $idx{$item};
11472: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11473: .'<select name="'.$item.'"'.$chgstr.'>';
11474: for (my $k=0; $k<=$maxnum; $k++) {
11475: my $vpos = $k+1;
11476: my $selstr;
11477: if ($k == $i) {
11478: $selstr = ' selected="selected" ';
11479: }
11480: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11481: }
1.214 raeburn 11482: $datatable .= '</select></span></td><td>';
1.272 raeburn 11483: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11484: $datatable .= '<span class="LC_nobreak">'
11485: .$default_names{$parent}.'</span>';
11486: if ($parent eq 'instcode') {
11487: $datatable .= '<br /><span class="LC_nobreak">('
11488: .&mt('with institutional codes')
11489: .')</span></td><td'.$colattrib.'>';
11490: } else {
11491: $datatable .= '<table><tr><td>';
11492: }
11493: $datatable .= '<span class="LC_nobreak">'
11494: .'<label><input type="radio" name="'
11495: .$parent.'" value="1" checked="checked" />'
11496: .&mt('Display').'</label>';
11497: if ($parent eq 'instcode') {
11498: $datatable .= ' ';
11499: } else {
11500: $datatable .= '</span></td></tr><tr><td>'
11501: .'<span class="LC_nobreak">';
11502: }
11503: $datatable .= '<label><input type="radio" name="'
11504: .$parent.'" value="0" />'
11505: .&mt('Do not display').'</label></span>';
1.272 raeburn 11506: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11507: $datatable .= '</td></tr></table>';
11508: }
11509: $datatable .= '</td>';
1.57 raeburn 11510: } else {
11511: $datatable .= $parent
1.214 raeburn 11512: .' <span class="LC_nobreak"><label>'
11513: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11514: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11515: }
11516: my $depth = 1;
11517: push(@path,$parent);
11518: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11519: pop(@path);
11520: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11521: $itemcount ++;
11522: }
1.48 raeburn 11523: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11524: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11525: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11526: for (my $k=0; $k<=$maxnum; $k++) {
11527: my $vpos = $k+1;
11528: my $selstr;
1.57 raeburn 11529: if ($k == $numtop) {
1.48 raeburn 11530: $selstr = ' selected="selected" ';
11531: }
11532: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11533: }
1.59 bisitz 11534: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11535: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11536: .'</tr>'."\n";
1.48 raeburn 11537: $itemcount ++;
1.272 raeburn 11538: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11539: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11541: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11542: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11543: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11544: for (my $k=0; $k<=$maxnum; $k++) {
11545: my $vpos = $k+1;
11546: my $selstr;
11547: if ($k == $maxnum) {
11548: $selstr = ' selected="selected" ';
11549: }
11550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11551: }
1.120 raeburn 11552: $datatable .= '</select></span></td>'.
11553: '<td><span class="LC_nobreak">'.
11554: $default_names{$default}.'</span>';
11555: if ($default eq 'instcode') {
11556: $datatable .= '<br /><span class="LC_nobreak">('
11557: .&mt('with institutional codes').')</span>';
11558: }
11559: $datatable .= '</td>'
11560: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11561: .&mt('Display').'</label> '
11562: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11563: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11564: }
11565: }
11566: }
1.57 raeburn 11567: } else {
11568: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11569: }
11570: } else {
1.327 raeburn 11571: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11572: .&initialize_categories($itemcount);
1.48 raeburn 11573: }
1.57 raeburn 11574: $$rowtotal += $itemcount;
1.48 raeburn 11575: }
11576: return $datatable;
11577: }
11578:
1.69 raeburn 11579: sub print_serverstatuses {
11580: my ($dom,$settings,$rowtotal) = @_;
11581: my $datatable;
11582: my @pages = &serverstatus_pages();
11583: my (%namedaccess,%machineaccess);
11584: foreach my $type (@pages) {
11585: $namedaccess{$type} = '';
11586: $machineaccess{$type}= '';
11587: }
11588: if (ref($settings) eq 'HASH') {
11589: foreach my $type (@pages) {
11590: if (exists($settings->{$type})) {
11591: if (ref($settings->{$type}) eq 'HASH') {
11592: foreach my $key (keys(%{$settings->{$type}})) {
11593: if ($key eq 'namedusers') {
11594: $namedaccess{$type} = $settings->{$type}->{$key};
11595: } elsif ($key eq 'machines') {
11596: $machineaccess{$type} = $settings->{$type}->{$key};
11597: }
11598: }
11599: }
11600: }
11601: }
11602: }
1.81 raeburn 11603: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11604: my $rownum = 0;
11605: my $css_class;
11606: foreach my $type (@pages) {
11607: $rownum ++;
11608: $css_class = $rownum%2?' class="LC_odd_row"':'';
11609: $datatable .= '<tr'.$css_class.'>'.
11610: '<td><span class="LC_nobreak">'.
11611: $titles->{$type}.'</span></td>'.
11612: '<td class="LC_left_item">'.
11613: '<input type="text" name="'.$type.'_namedusers" '.
11614: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11615: '<td class="LC_right_item">'.
11616: '<span class="LC_nobreak">'.
11617: '<input type="text" name="'.$type.'_machines" '.
11618: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11619: '</span></td></tr>'."\n";
1.69 raeburn 11620: }
11621: $$rowtotal += $rownum;
11622: return $datatable;
11623: }
11624:
11625: sub serverstatus_pages {
11626: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11627: 'checksums','clusterstatus','certstatus','metadata_keywords',
11628: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11629: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11630: }
11631:
1.236 raeburn 11632: sub defaults_javascript {
11633: my ($settings) = @_;
1.354 raeburn 11634: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11635: my $portal_js = <<"ENDPORTAL";
11636:
11637: function portalExtras(caller) {
11638: var x = caller.value;
11639: var y = new Array('email','web');
1.425 raeburn 11640: for (var i=0; i<y.length; i++) {
1.414 raeburn 11641: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11642: var z = document.getElementById('portal_def_'+y[i]+'_div');
11643: if (x.length > 0) {
11644: z.style.display = 'block';
11645: } else {
11646: z.style.display = 'none';
11647: }
11648: }
11649: }
11650: }
11651: ENDPORTAL
1.236 raeburn 11652: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11653: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11654: if ($maxnum eq '') {
11655: $maxnum = 0;
11656: }
11657: $maxnum ++;
1.249 raeburn 11658: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11659: return <<"ENDSCRIPT";
11660: <script type="text/javascript">
11661: // <![CDATA[
11662: function reorderTypes(form,caller) {
11663: var changedVal;
11664: $jstext
11665: var newpos = 'addinststatus_pos';
11666: var current = new Array;
11667: var maxh = $maxnum;
11668: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11669: var oldVal;
11670: if (caller == newpos) {
11671: changedVal = newitemVal;
11672: } else {
11673: var curritem = 'inststatus_pos_'+caller;
11674: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11675: current[newitemVal] = newpos;
11676: }
11677: for (var i=0; i<inststatuses.length; i++) {
11678: if (inststatuses[i] != caller) {
11679: var elementName = 'inststatus_pos_'+inststatuses[i];
11680: if (form.elements[elementName]) {
11681: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11682: current[currVal] = elementName;
11683: }
11684: }
11685: }
11686: for (var j=0; j<maxh; j++) {
11687: if (current[j] == undefined) {
11688: oldVal = j;
11689: }
11690: }
11691: if (oldVal < changedVal) {
11692: for (var k=oldVal+1; k<=changedVal ; k++) {
11693: var elementName = current[k];
11694: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11695: }
11696: } else {
11697: for (var k=changedVal; k<oldVal; k++) {
11698: var elementName = current[k];
11699: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11700: }
11701: }
11702: return;
11703: }
11704:
1.414 raeburn 11705: $portal_js
11706:
11707: // ]]>
11708: </script>
11709:
11710: ENDSCRIPT
11711: } else {
11712: return <<"ENDSCRIPT";
11713: <script type="text/javascript">
11714: // <![CDATA[
11715: $portal_js
1.236 raeburn 11716: // ]]>
11717: </script>
11718:
11719: ENDSCRIPT
11720: }
1.354 raeburn 11721: return;
11722: }
11723:
11724: sub passwords_javascript {
1.405 raeburn 11725: my ($prefix) = @_;
11726: my %intalert;
11727: if ($prefix eq 'passwords') {
11728: %intalert = &Apache::lonlocal::texthash (
11729: 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.',
11730: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11731: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11732: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11733: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11734: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11735: );
1.421 raeburn 11736: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11737: %intalert = &Apache::lonlocal::texthash (
11738: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11739: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11740: );
11741: }
1.365 raeburn 11742: &js_escape(\%intalert);
11743: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11744: my $intauthjs;
1.405 raeburn 11745: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11746:
11747: function warnIntAuth(field) {
11748: if (field.name == 'intauth_check') {
11749: if (field.value == '2') {
1.365 raeburn 11750: alert('$intalert{authcheck}');
1.354 raeburn 11751: }
11752: }
11753: if (field.name == 'intauth_cost') {
11754: field.value.replace(/\s/g,'');
11755: if (field.value != '') {
11756: var regexdigit=/^\\d+\$/;
11757: if (!regexdigit.test(field.value)) {
1.365 raeburn 11758: alert('$intalert{authcost}');
11759: }
11760: }
11761: }
11762: return;
11763: }
11764:
1.405 raeburn 11765: ENDSCRIPT
11766:
11767: }
11768:
11769: $intauthjs .= <<"ENDSCRIPT";
11770:
11771: function warnInt$prefix(field) {
1.365 raeburn 11772: field.value.replace(/^\s+/,'');
11773: field.value.replace(/\s+\$/,'');
11774: var regexdigit=/^\\d+\$/;
1.408 raeburn 11775: if (field.name == '${prefix}_min') {
1.365 raeburn 11776: if (field.value == '') {
11777: alert('$intalert{passmin}');
11778: field.value = '$defmin';
11779: } else {
11780: if (!regexdigit.test(field.value)) {
11781: alert('$intalert{passmin}');
11782: field.value = '$defmin';
11783: }
1.366 raeburn 11784: var minval = parseInt(field.value,10);
1.365 raeburn 11785: if (minval < $defmin) {
11786: alert('$intalert{passmin}');
11787: field.value = '$defmin';
11788: }
11789: }
11790: } else {
11791: if (field.value == '0') {
11792: field.value = '';
11793: }
11794: if (field.value != '') {
1.408 raeburn 11795: if (field.name == '${prefix}_expire') {
1.365 raeburn 11796: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11797: if (!regexpposnum.test(field.value)) {
11798: alert('$intalert{passexp}');
11799: field.value = '';
11800: } else {
11801: var expval = parseFloat(field.value);
11802: if (expval == 0) {
11803: alert('$intalert{passexp}');
11804: field.value = '';
11805: }
11806: }
11807: } else {
11808: if (!regexdigit.test(field.value)) {
1.408 raeburn 11809: if (field.name == '${prefix}_max') {
1.365 raeburn 11810: alert('$intalert{passmax}');
11811: } else {
1.408 raeburn 11812: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11813: alert('$intalert{passnum}');
11814: }
11815: }
1.370 raeburn 11816: field.value = '';
1.365 raeburn 11817: }
1.354 raeburn 11818: }
11819: }
11820: }
11821: return;
11822: }
11823:
11824: ENDSCRIPT
11825: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11826: }
11827:
1.49 raeburn 11828: sub coursecategories_javascript {
11829: my ($settings) = @_;
1.57 raeburn 11830: my ($output,$jstext,$cathash);
1.49 raeburn 11831: if (ref($settings) eq 'HASH') {
1.57 raeburn 11832: $cathash = $settings->{'cats'};
11833: }
11834: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11835: my (@cats,@jsarray,%idx);
1.57 raeburn 11836: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11837: if (@jsarray > 0) {
11838: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11839: for (my $i=0; $i<@jsarray; $i++) {
11840: if (ref($jsarray[$i]) eq 'ARRAY') {
11841: my $catstr = join('","',@{$jsarray[$i]});
11842: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11843: }
11844: }
11845: }
11846: } else {
11847: $jstext = ' var categories = Array(1);'."\n".
11848: ' categories[0] = Array("instcode_pos");'."\n";
11849: }
1.237 bisitz 11850: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11851: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11852: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11853: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11854: &js_escape(\$instcode_reserved);
11855: &js_escape(\$communities_reserved);
1.272 raeburn 11856: &js_escape(\$placement_reserved);
1.265 damieng 11857: &js_escape(\$choose_again);
1.49 raeburn 11858: $output = <<"ENDSCRIPT";
11859: <script type="text/javascript">
1.109 raeburn 11860: // <![CDATA[
1.49 raeburn 11861: function reorderCats(form,parent,item,idx) {
11862: var changedVal;
11863: $jstext
11864: var newpos = 'addcategory_pos';
11865: if (parent == '') {
11866: var has_instcode = 0;
11867: var maxtop = categories[idx].length;
11868: for (var j=0; j<maxtop; j++) {
11869: if (categories[idx][j] == 'instcode::0') {
11870: has_instcode == 1;
11871: }
11872: }
11873: if (has_instcode == 0) {
11874: categories[idx][maxtop] = 'instcode_pos';
11875: }
11876: } else {
11877: newpos += '_'+parent;
11878: }
11879: var maxh = 1 + categories[idx].length;
11880: var current = new Array;
11881: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11882: if (item == newpos) {
11883: changedVal = newitemVal;
11884: } else {
11885: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11886: current[newitemVal] = newpos;
11887: }
11888: for (var i=0; i<categories[idx].length; i++) {
11889: var elementName = categories[idx][i];
11890: if (elementName != item) {
11891: if (form.elements[elementName]) {
11892: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11893: current[currVal] = elementName;
11894: }
11895: }
11896: }
11897: var oldVal;
11898: for (var j=0; j<maxh; j++) {
11899: if (current[j] == undefined) {
11900: oldVal = j;
11901: }
11902: }
11903: if (oldVal < changedVal) {
11904: for (var k=oldVal+1; k<=changedVal ; k++) {
11905: var elementName = current[k];
11906: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11907: }
11908: } else {
11909: for (var k=changedVal; k<oldVal; k++) {
11910: var elementName = current[k];
11911: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11912: }
11913: }
11914: return;
11915: }
1.120 raeburn 11916:
11917: function categoryCheck(form) {
11918: if (form.elements['addcategory_name'].value == 'instcode') {
11919: alert('$instcode_reserved\\n$choose_again');
11920: return false;
11921: }
11922: if (form.elements['addcategory_name'].value == 'communities') {
11923: alert('$communities_reserved\\n$choose_again');
11924: return false;
11925: }
1.272 raeburn 11926: if (form.elements['addcategory_name'].value == 'placement') {
11927: alert('$placement_reserved\\n$choose_again');
11928: return false;
11929: }
1.120 raeburn 11930: return true;
11931: }
11932:
1.109 raeburn 11933: // ]]>
1.49 raeburn 11934: </script>
11935:
11936: ENDSCRIPT
11937: return $output;
11938: }
11939:
1.48 raeburn 11940: sub initialize_categories {
11941: my ($itemcount) = @_;
1.120 raeburn 11942: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11943: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11944: instcode => 'Official courses (with institutional codes)',
11945: communities => 'Communities',
1.272 raeburn 11946: placement => 'Placement Tests',
1.120 raeburn 11947: );
1.328 raeburn 11948: my %selnum = (
11949: instcode => '0',
11950: communities => '1',
11951: placement => '2',
11952: );
11953: my %selected;
1.272 raeburn 11954: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11955: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11956: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11957: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11958: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11959: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11960: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11961: .'<option value="0"'.$selected{'0'}.'>1</option>'
11962: .'<option value="1"'.$selected{'1'}.'>2</option>'
11963: .'<option value="2"'.$selected{'2'}.'>3</option>'
11964: .'<option value="3">4</option></select> '
1.120 raeburn 11965: .$default_names{$default}
11966: .'</span></td><td><span class="LC_nobreak">'
11967: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11968: .&mt('Display').'</label> <label>'
11969: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11970: .'</label></span></td></tr>';
1.120 raeburn 11971: $itemcount ++;
11972: }
1.48 raeburn 11973: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11974: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11975: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11976: .'<select name="addcategory_pos"'.$chgstr.'>'
11977: .'<option value="0">1</option>'
11978: .'<option value="1">2</option>'
1.328 raeburn 11979: .'<option value="2">3</option>'
11980: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11981: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11982: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11983: .'</td></tr>';
1.48 raeburn 11984: return $datatable;
11985: }
11986:
11987: sub build_category_rows {
1.49 raeburn 11988: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11989: my ($text,$name,$item,$chgstr);
1.48 raeburn 11990: if (ref($cats) eq 'ARRAY') {
11991: my $maxdepth = scalar(@{$cats});
11992: if (ref($cats->[$depth]) eq 'HASH') {
11993: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11994: my $numchildren = @{$cats->[$depth]{$parent}};
11995: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11996: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11997: my ($idxnum,$parent_name,$parent_item);
11998: my $higher = $depth - 1;
11999: if ($higher == 0) {
12000: $parent_name = &escape($parent).'::'.$higher;
12001: } else {
12002: if (ref($path) eq 'ARRAY') {
12003: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12004: }
12005: }
12006: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12007: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12008: if ($j < $numchildren) {
1.48 raeburn 12009: $name = $cats->[$depth]{$parent}[$j];
12010: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12011: $idxnum = $idx->{$item};
12012: } else {
12013: $name = $parent_name;
12014: $item = $parent_item;
1.48 raeburn 12015: }
1.49 raeburn 12016: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12017: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12018: for (my $i=0; $i<=$numchildren; $i++) {
12019: my $vpos = $i+1;
12020: my $selstr;
12021: if ($j == $i) {
12022: $selstr = ' selected="selected" ';
12023: }
12024: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12025: }
12026: $text .= '</select> ';
12027: if ($j < $numchildren) {
12028: my $deeper = $depth+1;
12029: $text .= $name.' '
12030: .'<label><input type="checkbox" name="deletecategory" value="'
12031: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12032: if(ref($path) eq 'ARRAY') {
12033: push(@{$path},$name);
1.49 raeburn 12034: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12035: pop(@{$path});
12036: }
12037: } else {
1.330 raeburn 12038: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12039: if ($j == $numchildren) {
12040: $text .= $name;
12041: } else {
12042: $text .= $item;
12043: }
12044: $text .= '" value="" />';
12045: }
12046: $text .= '</td></tr>';
12047: }
12048: $text .= '</table></td>';
12049: } else {
12050: my $higher = $depth-1;
12051: if ($higher == 0) {
12052: $name = &escape($parent).'::'.$higher;
12053: } else {
12054: if (ref($path) eq 'ARRAY') {
12055: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12056: }
12057: }
12058: my $colspan;
12059: if ($parent ne 'instcode') {
12060: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12061: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12062: }
12063: }
12064: }
12065: }
12066: return $text;
12067: }
12068:
1.33 raeburn 12069: sub modifiable_userdata_row {
1.305 raeburn 12070: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12071: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12072: my ($role,$rolename,$statustype);
12073: $role = $item;
1.224 raeburn 12074: if ($context eq 'cancreate') {
1.305 raeburn 12075: if ($item =~ /^(emailusername)_(.+)$/) {
12076: $role = $1;
12077: $statustype = $2;
1.228 raeburn 12078: if (ref($usertypes) eq 'HASH') {
12079: if ($usertypes->{$statustype}) {
12080: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12081: } else {
12082: $rolename = &mt('Data provided by user');
12083: }
12084: }
1.224 raeburn 12085: }
12086: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12087: if (ref($usertypes) eq 'HASH') {
12088: $rolename = $usertypes->{$role};
12089: } else {
12090: $rolename = $role;
12091: }
1.325 raeburn 12092: } elsif ($context eq 'lti') {
12093: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12094: } elsif ($context eq 'privacy') {
12095: $rolename = $itemdesc;
1.33 raeburn 12096: } else {
1.63 raeburn 12097: if ($role eq 'cr') {
12098: $rolename = &mt('Custom role');
12099: } else {
12100: $rolename = &Apache::lonnet::plaintext($role);
12101: }
1.33 raeburn 12102: }
1.224 raeburn 12103: my (@fields,%fieldtitles);
12104: if (ref($fieldsref) eq 'ARRAY') {
12105: @fields = @{$fieldsref};
12106: } else {
12107: @fields = ('lastname','firstname','middlename','generation',
12108: 'permanentemail','id');
12109: }
12110: if ((ref($titlesref) eq 'HASH')) {
12111: %fieldtitles = %{$titlesref};
12112: } else {
12113: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12114: }
1.33 raeburn 12115: my $output;
1.305 raeburn 12116: my $css_class;
12117: if ($rowcount%2) {
12118: $css_class = 'LC_odd_row';
12119: }
12120: if ($customcss) {
12121: $css_class .= " $customcss";
12122: }
12123: $css_class =~ s/^\s+//;
12124: if ($css_class) {
12125: $css_class = ' class="'.$css_class.'"';
12126: }
12127: if ($rowstyle) {
12128: $css_class .= ' style="'.$rowstyle.'"';
12129: }
12130: if ($rowid) {
12131: $rowid = ' id="'.$rowid.'"';
12132: }
12133: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12134: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12135: '<td class="LC_left_item" colspan="2"><table>';
12136: my $rem;
12137: my %checks;
12138: if (ref($settings) eq 'HASH') {
1.325 raeburn 12139: my $hashref;
12140: if ($context eq 'lti') {
12141: if (ref($settings) eq 'HASH') {
12142: $hashref = $settings->{'instdata'};
12143: }
1.357 raeburn 12144: } elsif ($context eq 'privacy') {
12145: my ($key,$inner) = split(/_/,$role);
12146: if (ref($settings) eq 'HASH') {
12147: if (ref($settings->{$key}) eq 'HASH') {
12148: $hashref = $settings->{$key}->{$inner};
12149: }
12150: }
1.325 raeburn 12151: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12152: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.325 raeburn 12153: $hashref = $settings->{'lti_instdata'};
12154: }
12155: if ($role eq 'emailusername') {
12156: if ($statustype) {
12157: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12158: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12159: }
1.325 raeburn 12160: }
12161: }
12162: }
1.425 raeburn 12163: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12164: foreach my $field (@fields) {
12165: if ($hashref->{$field}) {
12166: if ($role eq 'emailusername') {
12167: $checks{$field} = $hashref->{$field};
12168: } else {
12169: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12170: }
12171: }
12172: }
12173: }
12174: }
1.305 raeburn 12175: my $total = scalar(@fields);
12176: for (my $i=0; $i<$total; $i++) {
12177: $rem = $i%($numinrow);
1.33 raeburn 12178: if ($rem == 0) {
12179: if ($i > 0) {
12180: $output .= '</tr>';
12181: }
12182: $output .= '<tr>';
12183: }
12184: my $check = ' ';
1.228 raeburn 12185: unless ($role eq 'emailusername') {
12186: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12187: $check = $checks{$fields[$i]};
1.357 raeburn 12188: } elsif ($context eq 'privacy') {
12189: if ($role =~ /^priv_(domain|course)$/) {
12190: if (ref($settings) ne 'HASH') {
12191: $check = ' checked="checked" ';
12192: }
12193: } elsif ($role =~ /^priv_(author|community)$/) {
12194: if (ref($settings) ne 'HASH') {
12195: unless ($fields[$i] eq 'id') {
12196: $check = ' checked="checked" ';
12197: }
12198: }
12199: } elsif ($role =~ /^(unpriv|othdom)_/) {
12200: if (ref($settings) ne 'HASH') {
12201: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12202: $check = ' checked="checked" ';
12203: }
12204: }
12205: }
1.325 raeburn 12206: } elsif ($context ne 'lti') {
1.228 raeburn 12207: if ($role eq 'st') {
12208: if (ref($settings) ne 'HASH') {
12209: $check = ' checked="checked" ';
12210: }
1.33 raeburn 12211: }
12212: }
12213: }
12214: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12215: '<span class="LC_nobreak">';
1.325 raeburn 12216: my $prefix = 'canmodify';
1.228 raeburn 12217: if ($role eq 'emailusername') {
12218: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12219: $checks{$fields[$i]} = 'omit';
12220: }
12221: foreach my $option ('required','optional','omit') {
12222: my $checked='';
12223: if ($checks{$fields[$i]} eq $option) {
12224: $checked='checked="checked" ';
12225: }
12226: $output .= '<label>'.
1.325 raeburn 12227: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12228: &mt($option).'</label>'.(' ' x2);
12229: }
12230: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12231: } else {
1.325 raeburn 12232: if ($context eq 'lti') {
12233: $prefix = 'lti';
1.443 raeburn 12234: } elsif ($context eq 'coauthor') {
12235: $prefix = 'cacanmodify';
1.357 raeburn 12236: } elsif ($context eq 'privacy') {
12237: $prefix = 'privacy';
1.325 raeburn 12238: }
1.228 raeburn 12239: $output .= '<label>'.
1.325 raeburn 12240: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12241: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12242: '</label>';
12243: }
12244: $output .= '</span></td>';
1.33 raeburn 12245: }
1.305 raeburn 12246: $rem = $total%$numinrow;
12247: my $colsleft;
12248: if ($rem) {
12249: $colsleft = $numinrow - $rem;
12250: }
12251: if ($colsleft > 1) {
1.33 raeburn 12252: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12253: ' </td>';
12254: } elsif ($colsleft == 1) {
12255: $output .= '<td class="LC_left_item"> </td>';
12256: }
12257: $output .= '</tr></table></td></tr>';
12258: return $output;
12259: }
1.28 raeburn 12260:
1.93 raeburn 12261: sub insttypes_row {
1.305 raeburn 12262: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12263: $customcss,$rowstyle) = @_;
1.93 raeburn 12264: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12265: cansearch => 'Users allowed to search',
1.93 raeburn 12266: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12267: lockablenames => 'User preference to lock name',
12268: selfassign => 'Self-reportable affiliations',
12269: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12270: webdav => 'WebDAV access available',
12271: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12272: );
1.429 raeburn 12273: my ($showdom,$defaultquota);
1.93 raeburn 12274: if ($context eq 'cansearch') {
12275: $showdom = ' ('.$dom.')';
1.429 raeburn 12276: } elsif ($context eq 'authorquota') {
12277: $defaultquota = 500;
1.93 raeburn 12278: }
1.165 raeburn 12279: my $class = 'LC_left_item';
12280: if ($context eq 'statustocreate') {
12281: $class = 'LC_right_item';
12282: }
1.305 raeburn 12283: my $css_class;
12284: if ($$rowtotal%2) {
12285: $css_class = 'LC_odd_row';
12286: }
12287: if ($customcss) {
12288: $css_class .= ' '.$customcss;
12289: }
12290: $css_class =~ s/^\s+//;
12291: if ($css_class) {
12292: $css_class = ' class="'.$css_class.'"';
12293: }
12294: if ($rowstyle) {
12295: $css_class .= ' style="'.$rowstyle.'"';
12296: }
12297: if ($onclick) {
12298: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12299: }
12300: my $output = '<tr'.$css_class.'>'.
12301: '<td>'.$lt{$context}.$showdom.
12302: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12303: my $rem;
12304: if (ref($types) eq 'ARRAY') {
12305: for (my $i=0; $i<@{$types}; $i++) {
12306: if (defined($usertypes->{$types->[$i]})) {
12307: my $rem = $i%($numinrow);
12308: if ($rem == 0) {
12309: if ($i > 0) {
12310: $output .= '</tr>';
12311: }
12312: $output .= '<tr>';
1.23 raeburn 12313: }
1.429 raeburn 12314: if ($context eq 'authorquota') {
12315: my $currquota;
12316: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12317: $currquota = $settings->{$context}->{$types->[$i]};
12318: } else {
12319: $currquota = $defaultquota;
12320: }
12321: $output .= '<td class="LC_left_item">'."\n".
12322: '<label><span class="LC_nobreak">'."\n".
12323: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12324: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12325: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12326: '</label></td>';
12327: } else {
12328: my $check = ' ';
12329: if (ref($settings) eq 'HASH') {
12330: if (ref($settings->{$context}) eq 'ARRAY') {
12331: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12332: $check = ' checked="checked" ';
12333: }
12334: } elsif (ref($settings->{$context}) eq 'HASH') {
12335: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12336: $check = ' checked="checked" ';
12337: } elsif ($context eq 'webdav') {
12338: if ($settings->{$context}->{$types->[$i]}) {
12339: $check = ' checked="checked" ';
12340: }
12341: }
12342: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12343: $check = ' checked="checked" ';
12344: }
1.26 raeburn 12345: }
1.429 raeburn 12346: $output .= '<td class="LC_left_item">'.
12347: '<span class="LC_nobreak"><label>'.
12348: '<input type="checkbox" name="'.$context.'" '.
12349: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12350: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12351: }
12352: }
12353: }
1.26 raeburn 12354: $rem = @{$types}%($numinrow);
1.23 raeburn 12355: }
12356: my $colsleft = $numinrow - $rem;
1.315 raeburn 12357: if ($context eq 'overrides') {
12358: if ($colsleft > 1) {
12359: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12360: } else {
12361: $output .= '<td class="LC_left_item">';
12362: }
1.425 raeburn 12363: $output .= ' ';
1.23 raeburn 12364: } else {
1.334 raeburn 12365: if ($rem == 0) {
1.315 raeburn 12366: $output .= '<tr>';
12367: }
12368: if ($colsleft > 1) {
12369: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12370: } else {
12371: $output .= '<td class="LC_left_item">';
12372: }
1.429 raeburn 12373: if ($context eq 'authorquota') {
12374: my $currquota = 500;
12375: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12376: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12377: $currquota = $settings->{$context}{'default'};
12378: }
12379: }
12380: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12381: '<input type="text" name="'.$context.'_default" '.
12382: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12383: '</label>';
12384: } else {
12385: my $defcheck = ' ';
12386: if (ref($settings) eq 'HASH') {
12387: if (ref($settings->{$context}) eq 'ARRAY') {
12388: if (grep(/^default$/,@{$settings->{$context}})) {
12389: $defcheck = ' checked="checked" ';
12390: }
12391: } elsif (ref($settings->{$context}) eq 'HASH') {
12392: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12393: $defcheck = ' checked="checked" ';
12394: } elsif ($context eq 'webdav') {
12395: if ($settings->{$context}->{'default'}) {
12396: $defcheck = ' checked="checked" ';
12397: }
12398: }
12399: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12400: $defcheck = ' checked="checked" ';
12401: }
1.99 raeburn 12402: }
1.429 raeburn 12403: $output .= '<span class="LC_nobreak"><label>'.
12404: '<input type="checkbox" name="'.$context.'" '.
12405: 'value="default"'.$defcheck.$onclick.'/>'.
12406: $othertitle.'</label></span>';
1.26 raeburn 12407: }
1.23 raeburn 12408: }
1.315 raeburn 12409: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12410: return $output;
1.23 raeburn 12411: }
12412:
12413: sub sorted_searchtitles {
12414: my %searchtitles = &Apache::lonlocal::texthash(
12415: 'uname' => 'username',
12416: 'lastname' => 'last name',
12417: 'lastfirst' => 'last name, first name',
12418: );
12419: my @titleorder = ('uname','lastname','lastfirst');
12420: return (\%searchtitles,\@titleorder);
12421: }
12422:
1.25 raeburn 12423: sub sorted_searchtypes {
12424: my %srchtypes_desc = (
12425: exact => 'is exact match',
12426: contains => 'contains ..',
12427: begins => 'begins with ..',
12428: );
12429: my @srchtypeorder = ('exact','begins','contains');
12430: return (\%srchtypes_desc,\@srchtypeorder);
12431: }
12432:
1.3 raeburn 12433: sub usertype_update_row {
12434: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12435: my $datatable;
12436: my $numinrow = 4;
12437: foreach my $type (@{$types}) {
12438: if (defined($usertypes->{$type})) {
12439: $$rownums ++;
12440: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12441: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12442: '</td><td class="LC_left_item"><table>';
12443: for (my $i=0; $i<@{$fields}; $i++) {
12444: my $rem = $i%($numinrow);
12445: if ($rem == 0) {
12446: if ($i > 0) {
12447: $datatable .= '</tr>';
12448: }
12449: $datatable .= '<tr>';
12450: }
12451: my $check = ' ';
1.39 raeburn 12452: if (ref($settings) eq 'HASH') {
12453: if (ref($settings->{'fields'}) eq 'HASH') {
12454: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12455: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12456: $check = ' checked="checked" ';
12457: }
1.3 raeburn 12458: }
12459: }
12460: }
12461:
12462: if ($i == @{$fields}-1) {
12463: my $colsleft = $numinrow - $rem;
12464: if ($colsleft > 1) {
12465: $datatable .= '<td colspan="'.$colsleft.'">';
12466: } else {
12467: $datatable .= '<td>';
12468: }
12469: } else {
12470: $datatable .= '<td>';
12471: }
1.8 raeburn 12472: $datatable .= '<span class="LC_nobreak"><label>'.
12473: '<input type="checkbox" name="updateable_'.$type.
12474: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12475: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12476: }
12477: $datatable .= '</tr></table></td></tr>';
12478: }
12479: }
12480: return $datatable;
1.1 raeburn 12481: }
12482:
12483: sub modify_login {
1.205 raeburn 12484: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12485: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12486: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12487: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12488: %title = ( coursecatalog => 'Display course catalog',
12489: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12490: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12491: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12492: loginheader => 'Log-in box header',
12493: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12494: @offon = ('off','on');
1.112 raeburn 12495: if (ref($domconfig{login}) eq 'HASH') {
12496: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12497: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12498: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12499: }
12500: }
1.386 raeburn 12501: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12502: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12503: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12504: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12505: $saml{$lonhost} = 1;
12506: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12507: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12508: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12509: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12510: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12511: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12512: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12513: }
12514: }
12515: }
1.112 raeburn 12516: }
1.9 raeburn 12517: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12518: \%domconfig,\%loginhash);
1.188 raeburn 12519: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12520: foreach my $item (@toggles) {
12521: $loginhash{login}{$item} = $env{'form.'.$item};
12522: }
1.41 raeburn 12523: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12524: if (ref($colchanges{'login'}) eq 'HASH') {
12525: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12526: \%loginhash);
12527: }
1.110 raeburn 12528:
1.149 raeburn 12529: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12530: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12531: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12532: if (keys(%servers) > 1) {
12533: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12534: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12535: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12536: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12537: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12538: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12539: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12540: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12541: $changes{'loginvia'}{$lonhost} = 1;
12542: } else {
12543: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12544: $changes{'loginvia'}{$lonhost} = 1;
12545: }
12546: } else {
12547: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12548: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12549: $changes{'loginvia'}{$lonhost} = 1;
12550: }
12551: }
12552: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12553: foreach my $item (@loginvia_attribs) {
12554: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12555: }
12556: } else {
12557: foreach my $item (@loginvia_attribs) {
12558: my $new = $env{'form.'.$lonhost.'_'.$item};
12559: if (($item eq 'serverpath') && ($new eq 'custom')) {
12560: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12561: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12562: $new = '/';
12563: }
12564: }
12565: if (($item eq 'custompath') &&
12566: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12567: $new = '';
12568: }
12569: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12570: $changes{'loginvia'}{$lonhost} = 1;
12571: }
12572: if ($item eq 'exempt') {
1.256 raeburn 12573: $new = &check_exempt_addresses($new);
1.128 raeburn 12574: }
12575: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12576: }
12577: }
1.112 raeburn 12578: } else {
1.128 raeburn 12579: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12580: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12581: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12582: foreach my $item (@loginvia_attribs) {
12583: my $new = $env{'form.'.$lonhost.'_'.$item};
12584: if (($item eq 'serverpath') && ($new eq 'custom')) {
12585: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12586: $new = '/';
12587: }
12588: }
12589: if (($item eq 'custompath') &&
12590: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12591: $new = '';
12592: }
12593: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12594: }
1.110 raeburn 12595: }
12596: }
12597: }
12598: }
1.119 raeburn 12599:
1.168 raeburn 12600: my $servadm = $r->dir_config('lonAdmEMail');
12601: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12602: if (ref($domconfig{'login'}) eq 'HASH') {
12603: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12604: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12605: if ($lang eq 'nolang') {
12606: push(@currlangs,$lang);
12607: } elsif (defined($langchoices{$lang})) {
12608: push(@currlangs,$lang);
12609: } else {
12610: next;
12611: }
12612: }
12613: }
12614: }
12615: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12616: if (@currlangs > 0) {
12617: foreach my $lang (@currlangs) {
12618: if (grep(/^\Q$lang\E$/,@delurls)) {
12619: $changes{'helpurl'}{$lang} = 1;
12620: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12621: $changes{'helpurl'}{$lang} = 1;
12622: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12623: push(@newlangs,$lang);
12624: } else {
12625: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12626: }
12627: }
12628: }
12629: unless (grep(/^nolang$/,@currlangs)) {
12630: if ($env{'form.loginhelpurl_nolang.filename'}) {
12631: $changes{'helpurl'}{'nolang'} = 1;
12632: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12633: push(@newlangs,'nolang');
12634: }
12635: }
12636: if ($env{'form.loginhelpurl_add_lang'}) {
12637: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12638: ($env{'form.loginhelpurl_add_file.filename'})) {
12639: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12640: $addedfile = $env{'form.loginhelpurl_add_lang'};
12641: }
12642: }
12643: if ((@newlangs > 0) || ($addedfile)) {
12644: my $error;
12645: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12646: if ($configuserok eq 'ok') {
12647: if ($switchserver) {
12648: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12649: } elsif ($author_ok eq 'ok') {
12650: my @allnew = @newlangs;
12651: if ($addedfile ne '') {
12652: push(@allnew,$addedfile);
12653: }
1.421 raeburn 12654: my $modified = [];
1.168 raeburn 12655: foreach my $lang (@allnew) {
12656: my $formelem = 'loginhelpurl_'.$lang;
12657: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12658: $formelem = 'loginhelpurl_add_file';
12659: }
1.425 raeburn 12660: (my $result,$newurl{$lang}) =
1.421 raeburn 12661: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12662: "help/$lang",'','',$newfile{$lang},
12663: $modified);
1.168 raeburn 12664: if ($result eq 'ok') {
12665: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12666: $changes{'helpurl'}{$lang} = 1;
12667: } else {
12668: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12669: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12670: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12671: (!grep(/^\Q$lang\E$/,@delurls))) {
12672: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12673: }
12674: }
12675: }
1.421 raeburn 12676: &update_modify_urls($r,$modified);
1.168 raeburn 12677: } else {
12678: $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);
12679: }
12680: } else {
12681: $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);
12682: }
12683: if ($error) {
12684: &Apache::lonnet::logthis($error);
12685: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12686: }
12687: }
1.256 raeburn 12688:
12689: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12690: if (ref($domconfig{'login'}) eq 'HASH') {
12691: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12692: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12693: if ($domservers{$lonhost}) {
12694: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12695: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12696: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12697: }
12698: }
12699: }
12700: }
12701: }
12702: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12703: foreach my $lonhost (sort(keys(%domservers))) {
12704: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12705: $changes{'headtag'}{$lonhost} = 1;
12706: } else {
12707: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12708: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12709: }
12710: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12711: push(@newhosts,$lonhost);
12712: } elsif ($currheadtagurls{$lonhost}) {
12713: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12714: if ($currexempt{$lonhost}) {
1.289 raeburn 12715: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12716: $changes{'headtag'}{$lonhost} = 1;
12717: }
12718: } elsif ($possexempt{$lonhost}) {
12719: $changes{'headtag'}{$lonhost} = 1;
12720: }
12721: if ($possexempt{$lonhost}) {
12722: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12723: }
12724: }
12725: }
12726: }
12727: if (@newhosts) {
12728: my $error;
12729: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12730: if ($configuserok eq 'ok') {
12731: if ($switchserver) {
12732: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12733: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12734: my $modified = [];
1.256 raeburn 12735: foreach my $lonhost (@newhosts) {
12736: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12737: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12738: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12739: "login/headtag/$lonhost",'','',
12740: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12741: $modified);
1.256 raeburn 12742: if ($result eq 'ok') {
12743: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12744: $changes{'headtag'}{$lonhost} = 1;
12745: if ($possexempt{$lonhost}) {
12746: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12747: }
12748: } else {
12749: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12750: $newheadtagurls{$lonhost},$result);
12751: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12752: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12753: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12754: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12755: }
12756: }
12757: }
1.421 raeburn 12758: &update_modify_urls($r,$modified);
1.256 raeburn 12759: } else {
12760: $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);
12761: }
12762: } else {
12763: $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);
12764: }
12765: if ($error) {
12766: &Apache::lonnet::logthis($error);
12767: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12768: }
12769: }
1.386 raeburn 12770: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12771: my @newsamlimgs;
12772: foreach my $lonhost (keys(%domservers)) {
12773: if ($env{'form.saml_'.$lonhost}) {
12774: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12775: push(@newsamlimgs,$lonhost);
12776: }
1.412 raeburn 12777: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12778: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12779: }
12780: if ($saml{$lonhost}) {
1.412 raeburn 12781: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12782: $env{'form.saml_window_'.$lonhost} = '';
12783: }
1.386 raeburn 12784: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12785: #FIXME Need to obsolete published image
12786: delete($currsaml{$lonhost}{'img'});
12787: $changes{'saml'}{$lonhost} = 1;
12788: }
12789: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12790: $changes{'saml'}{$lonhost} = 1;
12791: }
12792: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12793: $changes{'saml'}{$lonhost} = 1;
12794: }
12795: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12796: $changes{'saml'}{$lonhost} = 1;
12797: }
12798: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12799: $changes{'saml'}{$lonhost} = 1;
12800: }
1.412 raeburn 12801: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12802: $changes{'saml'}{$lonhost} = 1;
12803: }
1.386 raeburn 12804: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12805: $changes{'saml'}{$lonhost} = 1;
12806: }
12807: } else {
12808: $changes{'saml'}{$lonhost} = 1;
12809: }
1.412 raeburn 12810: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12811: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12812: }
12813: } else {
1.425 raeburn 12814: if ($saml{$lonhost}) {
1.389 raeburn 12815: $changes{'saml'}{$lonhost} = 1;
12816: delete($currsaml{$lonhost});
12817: }
1.386 raeburn 12818: }
12819: }
12820: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12821: unless (exists($domservers{$posshost})) {
12822: delete($currsaml{$posshost});
1.386 raeburn 12823: }
12824: }
12825: %{$loginhash{'login'}{'saml'}} = %currsaml;
12826: if (@newsamlimgs) {
12827: my $error;
12828: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12829: if ($configuserok eq 'ok') {
12830: if ($switchserver) {
12831: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12832: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12833: my $modified = [];
1.386 raeburn 12834: foreach my $lonhost (@newsamlimgs) {
12835: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12836: my ($result,$imgurl) =
1.421 raeburn 12837: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12838: "login/saml/$lonhost",'','',
12839: $env{'form.saml_img_'.$lonhost.'.filename'},
12840: $modified);
1.386 raeburn 12841: if ($result eq 'ok') {
12842: $currsaml{$lonhost}{'img'} = $imgurl;
12843: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12844: $changes{'saml'}{$lonhost} = 1;
12845: } else {
12846: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12847: $lonhost,$result);
12848: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12849: }
12850: }
1.421 raeburn 12851: &update_modify_urls($r,$modified);
1.386 raeburn 12852: } else {
12853: $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);
12854: }
12855: } else {
12856: $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);
12857: }
12858: if ($error) {
12859: &Apache::lonnet::logthis($error);
12860: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12861: }
12862: }
1.169 raeburn 12863: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12864:
12865: my $defaulthelpfile = '/adm/loginproblems.html';
12866: my $defaulttext = &mt('Default in use');
12867:
1.1 raeburn 12868: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12869: $dom);
12870: if ($putresult eq 'ok') {
1.188 raeburn 12871: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12872: my %defaultchecked = (
12873: 'coursecatalog' => 'on',
1.188 raeburn 12874: 'helpdesk' => 'on',
1.42 raeburn 12875: 'adminmail' => 'off',
1.43 raeburn 12876: 'newuser' => 'off',
1.42 raeburn 12877: );
1.55 raeburn 12878: if (ref($domconfig{'login'}) eq 'HASH') {
12879: foreach my $item (@toggles) {
12880: if ($defaultchecked{$item} eq 'on') {
12881: if (($domconfig{'login'}{$item} eq '0') &&
12882: ($env{'form.'.$item} eq '1')) {
12883: $changes{$item} = 1;
12884: } elsif (($domconfig{'login'}{$item} eq '' ||
12885: $domconfig{'login'}{$item} eq '1') &&
12886: ($env{'form.'.$item} eq '0')) {
12887: $changes{$item} = 1;
12888: }
12889: } elsif ($defaultchecked{$item} eq 'off') {
12890: if (($domconfig{'login'}{$item} eq '1') &&
12891: ($env{'form.'.$item} eq '0')) {
12892: $changes{$item} = 1;
12893: } elsif (($domconfig{'login'}{$item} eq '' ||
12894: $domconfig{'login'}{$item} eq '0') &&
12895: ($env{'form.'.$item} eq '1')) {
12896: $changes{$item} = 1;
12897: }
1.42 raeburn 12898: }
12899: }
1.41 raeburn 12900: }
1.6 raeburn 12901: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12902: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12903: if (exists($changes{'saml'})) {
12904: my $hostid_in_use;
12905: my @hosts = &Apache::lonnet::current_machine_ids();
12906: if (@hosts > 1) {
12907: foreach my $hostid (@hosts) {
12908: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12909: $hostid_in_use = $hostid;
12910: last;
12911: }
12912: }
12913: } else {
12914: $hostid_in_use = $r->dir_config('lonHostID');
12915: }
12916: if (($hostid_in_use) &&
12917: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12918: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12919: }
12920: if (ref($lastactref) eq 'HASH') {
12921: if (ref($changes{'saml'}) eq 'HASH') {
12922: my %updates;
12923: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12924: $lastactref->{'samllanding'} = \%updates;
12925: }
12926: }
12927: }
1.212 raeburn 12928: if (ref($lastactref) eq 'HASH') {
12929: $lastactref->{'domainconfig'} = 1;
12930: }
1.1 raeburn 12931: $resulttext = &mt('Changes made:').'<ul>';
12932: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12933: if ($item eq 'loginvia') {
1.112 raeburn 12934: if (ref($changes{$item}) eq 'HASH') {
12935: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12936: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12937: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12938: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12939: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12940: $protocol = 'http' if ($protocol ne 'https');
12941: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12942:
12943: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12944: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12945: } else {
12946: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12947: }
12948: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12949: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12950: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12951: }
12952: $resulttext .= '</li>';
12953: } else {
12954: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12955: }
1.112 raeburn 12956: } else {
1.128 raeburn 12957: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12958: }
12959: }
1.128 raeburn 12960: $resulttext .= '</ul></li>';
1.112 raeburn 12961: }
1.168 raeburn 12962: } elsif ($item eq 'helpurl') {
12963: if (ref($changes{$item}) eq 'HASH') {
12964: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12965: if (grep(/^\Q$lang\E$/,@delurls)) {
12966: my ($chg,$link);
12967: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12968: if ($lang eq 'nolang') {
12969: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12970: } else {
12971: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12972: }
12973: $resulttext .= '<li>'.$chg.'</li>';
12974: } else {
12975: my $chg;
12976: if ($lang eq 'nolang') {
12977: $chg = &mt('custom log-in help file for no preferred language');
12978: } else {
12979: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12980: }
12981: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12982: $loginhash{'login'}{'helpurl'}{$lang}.
12983: '?inhibitmenu=yes',$chg,600,500).
12984: '</li>';
12985: }
12986: }
12987: }
1.256 raeburn 12988: } elsif ($item eq 'headtag') {
12989: if (ref($changes{$item}) eq 'HASH') {
12990: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12991: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12992: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12993: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12994: $resulttext .= '<li><a href="'.
12995: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
12996: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
12997: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
12998: if ($possexempt{$lonhost}) {
12999: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
13000: } else {
13001: $resulttext .= &mt('included for any client IP');
13002: }
13003: $resulttext .= '</li>';
13004: }
13005: }
13006: }
1.386 raeburn 13007: } elsif ($item eq 'saml') {
13008: if (ref($changes{$item}) eq 'HASH') {
13009: my %notlt = (
13010: text => 'Text for log-in by SSO',
13011: img => 'SSO button image',
13012: alt => 'Alt text for button image',
13013: url => 'SSO URL',
13014: title => 'Tooltip for SSO link',
1.412 raeburn 13015: window => 'Pop-up window if iframe',
1.386 raeburn 13016: notsso => 'Text for non-SSO log-in',
13017: );
13018: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13019: if (ref($currsaml{$lonhost}) eq 'HASH') {
13020: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13021: '<ul>';
1.412 raeburn 13022: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13023: if ($currsaml{$lonhost}{$key} eq '') {
13024: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13025: } else {
13026: my $value = "'$currsaml{$lonhost}{$key}'";
13027: if ($key eq 'img') {
13028: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13029: } elsif ($key eq 'window') {
13030: $value = 'On';
1.386 raeburn 13031: }
13032: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13033: $value).'</li>';
13034: }
13035: }
13036: $resulttext .= '</ul></li>';
13037: } else {
13038: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13039: }
13040: }
13041: }
1.169 raeburn 13042: } elsif ($item eq 'captcha') {
13043: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13044: my $chgtxt;
1.169 raeburn 13045: if ($loginhash{'login'}{$item} eq 'notused') {
13046: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13047: } else {
13048: my %captchas = &captcha_phrases();
13049: if ($captchas{$loginhash{'login'}{$item}}) {
13050: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13051: } else {
13052: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13053: }
13054: }
13055: $resulttext .= '<li>'.$chgtxt.'</li>';
13056: }
13057: } elsif ($item eq 'recaptchakeys') {
13058: if (ref($loginhash{'login'}) eq 'HASH') {
13059: my ($privkey,$pubkey);
13060: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13061: $pubkey = $loginhash{'login'}{$item}{'public'};
13062: $privkey = $loginhash{'login'}{$item}{'private'};
13063: }
13064: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13065: if (!$pubkey) {
13066: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13067: } else {
13068: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13069: }
13070: if (!$privkey) {
13071: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13072: } else {
1.251 raeburn 13073: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13074: }
13075: $chgtxt .= '</ul>';
13076: $resulttext .= '<li>'.$chgtxt.'</li>';
13077: }
1.269 raeburn 13078: } elsif ($item eq 'recaptchaversion') {
13079: if (ref($loginhash{'login'}) eq 'HASH') {
13080: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13081: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13082: '</li>';
13083: }
13084: }
1.41 raeburn 13085: } else {
13086: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13087: }
1.1 raeburn 13088: }
1.6 raeburn 13089: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13090: } else {
13091: $resulttext = &mt('No changes made to log-in page settings');
13092: }
13093: } else {
1.11 albertel 13094: $resulttext = '<span class="LC_error">'.
13095: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13096: }
1.6 raeburn 13097: if ($errors) {
1.9 raeburn 13098: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13099: $errors.'</ul>';
13100: }
13101: return $resulttext;
13102: }
13103:
1.256 raeburn 13104: sub check_exempt_addresses {
13105: my ($iplist) = @_;
13106: $iplist =~ s/^\s+//;
13107: $iplist =~ s/\s+$//;
13108: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13109: my (@okips,$new);
13110: foreach my $ip (@poss_ips) {
13111: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13112: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13113: push(@okips,$ip);
13114: }
13115: }
13116: }
13117: if (@okips > 0) {
13118: $new = join(',',@okips);
13119: } else {
13120: $new = '';
13121: }
13122: return $new;
13123: }
13124:
1.6 raeburn 13125: sub color_font_choices {
13126: my %choices =
13127: &Apache::lonlocal::texthash (
13128: bgs => "Background colors",
13129: links => "Link colors",
1.55 raeburn 13130: images => "Images",
1.6 raeburn 13131: font => "Font color",
1.201 raeburn 13132: fontmenu => "Font menu",
1.76 raeburn 13133: pgbg => "Page",
1.6 raeburn 13134: tabbg => "Header",
13135: sidebg => "Border",
13136: link => "Link",
13137: alink => "Active link",
13138: vlink => "Visited link",
13139: );
13140: return %choices;
13141: }
13142:
1.394 raeburn 13143: sub modify_ipaccess {
13144: my ($dom,$lastactref,%domconfig) = @_;
13145: my (@allpos,%changes,%confhash,$errors,$resulttext);
13146: my (@items,%deletions,%itemids,@warnings);
13147: my ($typeorder,$types) = &commblocktype_text();
13148: if ($env{'form.ipaccess_add'}) {
13149: my $name = $env{'form.ipaccess_name_add'};
13150: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13151: if ($newid) {
13152: $itemids{'add'} = $newid;
13153: push(@items,'add');
13154: $changes{$newid} = 1;
13155: } else {
13156: $error = &mt('Failed to acquire unique ID for new IP access control item');
13157: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13158: }
13159: }
13160: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13161: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13162: if (@todelete) {
13163: map { $deletions{$_} = 1; } @todelete;
13164: }
13165: my $maxnum = $env{'form.ipaccess_maxnum'};
13166: for (my $i=0; $i<$maxnum; $i++) {
13167: my $itemid = $env{'form.ipaccess_id_'.$i};
13168: $itemid =~ s/\D+//g;
13169: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13170: if ($deletions{$itemid}) {
13171: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13172: } else {
13173: push(@items,$i);
13174: $itemids{$i} = $itemid;
13175: }
13176: }
13177: }
13178: }
13179: foreach my $idx (@items) {
13180: my $itemid = $itemids{$idx};
13181: next unless ($itemid);
1.446 ! raeburn 13182: my ($position,%current);
! 13183: if ($idx eq 'add') {
! 13184: $position = $env{'form.ipaccess_pos_add'};
! 13185: } else {
! 13186: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13187: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13188: %current = %{$domconfig{'ipaccess'}{$itemid}};
13189: }
13190: }
13191: $position =~ s/\D+//g;
13192: if ($position ne '') {
13193: $allpos[$position] = $itemid;
13194: }
13195: my $name = $env{'form.ipaccess_name_'.$idx};
13196: $name =~ s/^\s+|\s+$//g;
13197: $confhash{$itemid}{'name'} = $name;
13198: my $possrange = $env{'form.ipaccess_range_'.$idx};
13199: $possrange =~ s/^\s+|\s+$//g;
13200: unless ($possrange eq '') {
13201: $possrange =~ s/[\r\n]+/\s/g;
13202: $possrange =~ s/\s*-\s*/-/g;
13203: $possrange =~ s/\s+/,/g;
13204: $possrange =~ s/,+/,/g;
13205: if ($possrange ne '') {
13206: my (@ok,$count);
1.425 raeburn 13207: $count = 0;
1.394 raeburn 13208: foreach my $poss (split(/\,/,$possrange)) {
13209: $count ++;
13210: $poss = &validate_ip_pattern($poss);
13211: if ($poss ne '') {
13212: push(@ok,$poss);
13213: }
13214: }
13215: my $diff = $count - scalar(@ok);
13216: if ($diff) {
13217: $errors .= '<li><span class="LC_error">'.
13218: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13219: $diff,$name).
13220: '</span></li>';
13221: }
13222: if (@ok) {
13223: my @cidr_list;
13224: foreach my $item (@ok) {
13225: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13226: }
13227: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13228: }
13229: }
13230: }
13231: foreach my $field ('name','ip') {
13232: unless (($idx eq 'add') || ($changes{$itemid})) {
13233: if ($current{$field} ne $confhash{$itemid}{$field}) {
13234: $changes{$itemid} = 1;
13235: last;
13236: }
13237: }
13238: }
13239: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13240:
1.394 raeburn 13241: my %commblocks;
1.425 raeburn 13242: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13243: foreach my $type (@{$typeorder}) {
13244: if ($commblocks{$type}) {
13245: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13246: }
13247: unless (($idx eq 'add') || ($changes{$itemid})) {
13248: if (ref($current{'commblocks'}) eq 'HASH') {
13249: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13250: $changes{$itemid} = 1;
13251: }
13252: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13253: $changes{$itemid} = 1;
13254: }
13255: }
13256: }
13257: $confhash{$itemid}{'courses'} = {};
13258: my %crsdeletions;
13259: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13260: if (@delcrs) {
13261: map { $crsdeletions{$_} = 1; } @delcrs;
13262: }
13263: if (ref($current{'courses'}) eq 'HASH') {
13264: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13265: if ($crsdeletions{$cid}) {
13266: $changes{$itemid} = 1;
13267: } else {
13268: $confhash{$itemid}{'courses'}{$cid} = 1;
13269: }
13270: }
13271: }
13272: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13273: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13274: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13275: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13276: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13277: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13278: $errors .= '<li><span class="LC_error">'.
13279: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13280: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13281: '</span></li>';
13282: } else {
13283: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13284: $changes{$itemid} = 1;
13285: }
13286: }
13287: }
13288: if (@allpos > 0) {
13289: my $idx = 0;
13290: foreach my $itemid (@allpos) {
13291: if ($itemid ne '') {
13292: $confhash{$itemid}{'order'} = $idx;
13293: unless ($changes{$itemid}) {
13294: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13295: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13296: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13297: $changes{$itemid} = 1;
13298: }
13299: }
13300: }
13301: }
13302: $idx ++;
13303: }
13304: }
13305: }
13306: if (keys(%changes)) {
13307: my %defaultshash = (
13308: ipaccess => \%confhash,
13309: );
13310: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13311: $dom);
13312: if ($putresult eq 'ok') {
13313: my $cachetime = 1800;
13314: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13315: if (ref($lastactref) eq 'HASH') {
13316: $lastactref->{'ipaccess'} = 1;
13317: }
13318: $resulttext = &mt('Changes made:').'<ul>';
13319: my %bynum;
13320: foreach my $itemid (sort(keys(%changes))) {
13321: if (ref($confhash{$itemid}) eq 'HASH') {
13322: my $position = $confhash{$itemid}{'order'};
13323: if ($position =~ /^\d+$/) {
13324: $bynum{$position} = $itemid;
13325: }
13326: }
13327: }
13328: if (keys(%deletions)) {
13329: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13330: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13331: }
13332: }
13333: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13334: my $itemid = $bynum{$pos};
13335: if (ref($confhash{$itemid}) eq 'HASH') {
13336: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13337: my $position = $pos + 1;
13338: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13339: if ($confhash{$itemid}{'ip'} eq '') {
13340: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13341: } else {
13342: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13343: }
13344: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13345: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13346: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13347: '</li>';
13348: } else {
13349: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13350: }
13351: if (keys(%{$confhash{$itemid}{'courses'}})) {
13352: my @courses;
13353: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13354: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13355: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13356: }
13357: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13358: join('</li><li>',@courses).'</li></ul>';
13359: } else {
13360: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13361: }
1.395 raeburn 13362: $resulttext .= '</ul></li>';
1.394 raeburn 13363: }
13364: }
1.395 raeburn 13365: $resulttext .= '</ul>';
1.394 raeburn 13366: } else {
13367: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13368: }
13369: } else {
13370: $resulttext = &mt('No changes made');
13371: }
13372: if ($errors) {
13373: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13374: $errors.'</ul></p>';
13375: }
13376: return $resulttext;
13377: }
13378:
13379: sub get_ipaccess_id {
13380: my ($domain,$location) = @_;
13381: # get lock on ipaccess db
13382: my $lockhash = {
13383: lock => $env{'user.name'}.
13384: ':'.$env{'user.domain'},
13385: };
13386: my $tries = 0;
13387: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13388: my ($id,$error);
13389:
13390: while (($gotlock ne 'ok') && ($tries<10)) {
13391: $tries ++;
13392: sleep (0.1);
13393: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13394: }
13395: if ($gotlock eq 'ok') {
13396: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13397: if ($currids{'lock'}) {
13398: delete($currids{'lock'});
13399: if (keys(%currids)) {
13400: my @curr = sort { $a <=> $b } keys(%currids);
13401: if ($curr[-1] =~ /^\d+$/) {
13402: $id = 1 + $curr[-1];
13403: }
13404: } else {
13405: $id = 1;
13406: }
13407: if ($id) {
13408: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13409: $error = 'nostore';
13410: }
13411: } else {
13412: $error = 'nonumber';
13413: }
13414: }
13415: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13416: } else {
13417: $error = 'nolock';
13418: }
13419: return ($id,$error);
13420: }
13421:
1.429 raeburn 13422: sub modify_authordefaults {
13423: my ($dom,$lastactref,%domconfig) = @_;
13424: #
13425: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13426: #
13427: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13428: if (ref($domconfig{'quotas'}) eq 'HASH') {
13429: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13430: if ($key =~ /^webdav|authorquota$/) {
13431: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13432: } else {
13433: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13434: }
13435: }
13436: }
13437: my %staticdefaults = (
13438: 'copyright' => 'default',
13439: 'sourceavail' => 'closed',
13440: 'nocodemirror' => 'off',
1.437 raeburn 13441: 'daxecollapse' => 'off',
1.429 raeburn 13442: 'domcoordacc' => 'on',
1.439 raeburn 13443: 'editors' => ['edit','xml'],
1.429 raeburn 13444: 'authorquota' => 500,
13445: 'webdav' => 0,
1.440 raeburn 13446: 'archive' => 'off',
1.429 raeburn 13447: );
13448: my %titles = &authordefaults_titles();
1.440 raeburn 13449: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13450: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13451: $confhash{$item} = $env{'form.'.$item};
13452: }
13453: }
13454: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13455: $confhash{'copyright'} = $1;
13456: }
13457: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13458: $confhash{'sourceavail'} = $1;
13459: }
13460: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13461: my @okeditors = ('edit','xml','daxe');
13462: my @editors;
13463: foreach my $item (@posseditors) {
13464: if (grep(/^\Q$item\E$/,@okeditors)) {
13465: push(@editors,$item);
13466: }
13467: }
13468: $confhash{'editors'} = \@editors;
1.436 raeburn 13469:
1.429 raeburn 13470: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13471: my @insttypes;
13472: if (ref($types) eq 'ARRAY') {
13473: @insttypes = @{$types};
13474: }
13475: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13476: my %webdav;
13477: map { $webdav{$_} = 1; } @webdavon;
13478: foreach my $type (@insttypes,'default') {
13479: my $possquota = $env{'form.authorquota_'.$type};
13480: if ($possquota =~ /^\d+$/) {
13481: $save_quotas{'authorquota'}{$type} = $possquota;
13482: }
13483: if ($webdav{$type}) {
13484: $save_quotas{'webdav'}{$type} = 1;
13485: } else {
13486: $save_quotas{'webdav'}{$type} = 0;
13487: }
13488: }
13489: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13490: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13491: }
13492: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13493: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13494: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13495: $changes{$item} = 1;
13496: }
13497: }
13498: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13499: my @diffs =
1.429 raeburn 13500: &Apache::loncommon::compare_arrays($confhash{'editors'},
13501: $domconfig{'authordefaults'}{'editors'});
13502: unless (@diffs == 0) {
13503: $changes{'editors'} = 1;
13504: }
13505: } else {
13506: my @diffs =
13507: &Apache::loncommon::compare_arrays($confhash{'editors'},
13508: $staticdefaults{'editors'});
13509: unless (@diffs == 0) {
13510: $changes{'editors'} = 1;
13511: }
13512: }
13513: } else {
13514: my @offon = ('off','on');
1.440 raeburn 13515: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13516: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13517: $changes{$item} = 1;
13518: }
13519: }
13520: foreach my $item ('copyright','sourceavail') {
13521: if ($confhash{$item} ne $staticdefaults{$item}) {
13522: $changes{$item} = 1;
13523: }
13524: }
1.439 raeburn 13525: my @diffs =
13526: &Apache::loncommon::compare_arrays($confhash{'editors'},
13527: $staticdefaults{'editors'});
13528: unless (@diffs == 0) {
13529: $changes{'editors'} = 1;
13530: }
1.429 raeburn 13531: }
13532: foreach my $key ('authorquota','webdav') {
13533: if (ref($curr_quotas{$key}) eq 'HASH') {
13534: foreach my $type (@insttypes,'default') {
13535: if (exists($save_quotas{$key}{$type})) {
13536: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13537: $changes{$key}{$type} = 1;
13538: }
13539: } elsif (exists($curr_quotas{$key}{$type})) {
13540: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13541: } else {
13542: $save_quotas{$key}{$type} = $staticdefaults{$key};
13543: }
13544: }
13545: } else {
13546: foreach my $type (@insttypes,'default') {
13547: if (exists($save_quotas{$key}{$type})) {
13548: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13549: $changes{$key}{$type} = 1;
13550: }
13551: } else {
13552: $save_quotas{$key}{$type} = $staticdefaults{$key};
13553: }
13554: }
13555: }
13556: }
13557: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13558: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13559: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13560: $changes{'webdav_LC_adv'} = 1;
13561: }
13562: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13563: $changes{'webdav_LC_adv'} = 1;
13564: }
13565: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13566: $changes{'webdav_LC_adv'} = 1;
13567: }
13568: my %confighash = (
13569: quotas => \%save_quotas,
13570: authordefaults => \%confhash,
13571: );
13572: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13573: $dom);
13574: my $resulttext;
13575: if ($putresult eq 'ok') {
13576: if (keys(%changes)) {
1.431 raeburn 13577: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13578: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13579: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13580: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13581: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13582: }
13583: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13584: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13585: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13586: }
13587: }
13588: $resulttext = &mt('Changes made:').'<ul>';
13589: my $authoroverride;
1.437 raeburn 13590: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13591: if (exists($changes{$key})) {
1.431 raeburn 13592: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13593: my $shown;
13594: unless ($authoroverride) {
13595: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13596: $authoroverride = 1;
13597: }
1.437 raeburn 13598: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13599: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13600: } elsif ($key eq 'copyright') {
13601: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13602: } elsif ($key eq 'sourceavail') {
13603: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13604: }
1.436 raeburn 13605: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13606: }
13607: }
13608: if ($authoroverride) {
13609: $resulttext .= '</ul></li>';
13610: }
13611: my $domcoordoverride;
1.440 raeburn 13612: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13613: if (exists($changes{$key})) {
13614: my $shown;
13615: unless ($domcoordoverride) {
13616: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13617: $domcoordoverride = 1;
13618: }
13619: if ($key eq 'editors') {
1.431 raeburn 13620: if (ref($confhash{'editors'}) eq 'ARRAY') {
13621: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13622: if (@{$confhash{'editors'}}) {
13623: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13624: } else {
13625: $shown = &mt('None');
13626: }
1.429 raeburn 13627: }
13628: } elsif ($key eq 'authorquota') {
13629: foreach my $type (@insttypes) {
13630: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13631: }
13632: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13633: } elsif ($key eq 'webdav') {
13634: foreach my $type (@insttypes) {
13635: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13636: }
13637: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13638: } elsif ($key eq 'webdav_LC_adv') {
13639: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13640: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13641: } else {
13642: $shown = $titles{'none'};
13643: }
1.440 raeburn 13644: } elsif ($key eq 'archive') {
1.441 raeburn 13645: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13646: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13647: }
13648: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13649: }
1.429 raeburn 13650: }
13651: if ($domcoordoverride) {
13652: $resulttext .= '</ul></li>';
13653: }
1.439 raeburn 13654: $resulttext .= '</ul>';
1.431 raeburn 13655: my $cachetime = 24*60*60;
13656: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13657: if (ref($lastactref) eq 'HASH') {
13658: $lastactref->{'domdefaults'} = 1;
13659: }
1.429 raeburn 13660: } else {
13661: $resulttext = &mt('No changes made to Authoring Space defaults');
13662: }
13663: }
13664: return $resulttext;
13665: }
13666:
1.6 raeburn 13667: sub modify_rolecolors {
1.205 raeburn 13668: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13669: my ($resulttext,%rolehash);
13670: $rolehash{'rolecolors'} = {};
1.55 raeburn 13671: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13672: if ($domconfig{'rolecolors'} eq '') {
13673: $domconfig{'rolecolors'} = {};
13674: }
13675: }
1.9 raeburn 13676: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13677: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13678: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13679: $dom);
13680: if ($putresult eq 'ok') {
13681: if (keys(%changes) > 0) {
1.41 raeburn 13682: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13683: if (ref($lastactref) eq 'HASH') {
13684: $lastactref->{'domainconfig'} = 1;
13685: }
1.6 raeburn 13686: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13687: $rolehash{'rolecolors'});
13688: } else {
13689: $resulttext = &mt('No changes made to default color schemes');
13690: }
13691: } else {
1.11 albertel 13692: $resulttext = '<span class="LC_error">'.
13693: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13694: }
13695: if ($errors) {
13696: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13697: $errors.'</ul>';
13698: }
13699: return $resulttext;
13700: }
13701:
13702: sub modify_colors {
1.9 raeburn 13703: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13704: my (%changes,%choices);
1.51 raeburn 13705: my @bgs;
1.6 raeburn 13706: my @links = ('link','alink','vlink');
1.41 raeburn 13707: my @logintext;
1.6 raeburn 13708: my @images;
13709: my $servadm = $r->dir_config('lonAdmEMail');
13710: my $errors;
1.200 raeburn 13711: my %defaults;
1.6 raeburn 13712: foreach my $role (@{$roles}) {
13713: if ($role eq 'login') {
1.12 raeburn 13714: %choices = &login_choices();
1.41 raeburn 13715: @logintext = ('textcol','bgcol');
1.12 raeburn 13716: } else {
13717: %choices = &color_font_choices();
13718: }
13719: if ($role eq 'login') {
1.41 raeburn 13720: @images = ('img','logo','domlogo','login');
1.51 raeburn 13721: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13722: } else {
1.445 raeburn 13723: @images = ();
1.200 raeburn 13724: @bgs = ('pgbg','tabbg','sidebg');
13725: }
13726: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13727: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13728: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13729: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13730: }
13731: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13732: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13733: }
13734: if ($role eq 'login') {
13735: foreach my $item (@logintext) {
1.234 raeburn 13736: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13737: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13738: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13739: }
13740: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13741: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13742: }
13743: }
13744: } else {
1.234 raeburn 13745: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13746: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13747: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13748: }
1.445 raeburn 13749: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13750: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13751: }
1.6 raeburn 13752: }
1.200 raeburn 13753: foreach my $item (@bgs) {
1.234 raeburn 13754: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13755: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13756: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13757: }
13758: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13759: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13760: }
13761: }
13762: foreach my $item (@links) {
1.234 raeburn 13763: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13764: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13765: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13766: }
13767: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13768: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13769: }
1.6 raeburn 13770: }
1.46 raeburn 13771: my ($configuserok,$author_ok,$switchserver) =
13772: &config_check($dom,$confname,$servadm);
1.9 raeburn 13773: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13774: if (ref($domconfig->{$role}) ne 'HASH') {
13775: $domconfig->{$role} = {};
13776: }
1.8 raeburn 13777: foreach my $img (@images) {
1.402 raeburn 13778: if ($role eq 'login') {
13779: if (($img eq 'img') || ($img eq 'logo')) {
13780: if (defined($env{'form.login_showlogo_'.$img})) {
13781: $confhash->{$role}{'showlogo'}{$img} = 1;
13782: } else {
13783: $confhash->{$role}{'showlogo'}{$img} = 0;
13784: }
13785: }
13786: if ($env{'form.login_alt_'.$img} ne '') {
13787: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13788: }
1.402 raeburn 13789: }
1.18 albertel 13790: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13791: && !defined($domconfig->{$role}{$img})
13792: && !$env{'form.'.$role.'_del_'.$img}
13793: && $env{'form.'.$role.'_import_'.$img}) {
13794: # import the old configured image from the .tab setting
13795: # if they haven't provided a new one
13796: $domconfig->{$role}{$img} =
13797: $env{'form.'.$role.'_import_'.$img};
13798: }
1.6 raeburn 13799: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13800: my $error;
1.6 raeburn 13801: if ($configuserok eq 'ok') {
1.9 raeburn 13802: if ($switchserver) {
1.12 raeburn 13803: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13804: } else {
13805: if ($author_ok eq 'ok') {
1.421 raeburn 13806: my $modified = [];
1.9 raeburn 13807: my ($result,$logourl) =
1.421 raeburn 13808: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13809: $dom,$confname,$img,$width,$height,
13810: '',$modified);
1.9 raeburn 13811: if ($result eq 'ok') {
13812: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13813: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13814: &update_modify_urls($r,$modified);
1.9 raeburn 13815: } else {
1.12 raeburn 13816: $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 13817: }
13818: } else {
1.46 raeburn 13819: $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 13820: }
13821: }
13822: } else {
1.46 raeburn 13823: $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 13824: }
13825: if ($error) {
1.8 raeburn 13826: &Apache::lonnet::logthis($error);
1.11 albertel 13827: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13828: }
13829: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13830: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13831: my $error;
13832: if ($configuserok eq 'ok') {
13833: # is confname an author?
13834: if ($switchserver eq '') {
13835: if ($author_ok eq 'ok') {
1.421 raeburn 13836: my $modified = [];
1.9 raeburn 13837: my ($result,$logourl) =
1.421 raeburn 13838: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13839: $dom,$confname,$img,$width,$height,
13840: '',$modified);
1.9 raeburn 13841: if ($result eq 'ok') {
13842: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13843: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13844: &update_modify_urls($r,$modified);
1.9 raeburn 13845: }
13846: }
13847: }
13848: }
1.6 raeburn 13849: }
13850: }
13851: }
13852: if (ref($domconfig) eq 'HASH') {
13853: if (ref($domconfig->{$role}) eq 'HASH') {
13854: foreach my $img (@images) {
13855: if ($domconfig->{$role}{$img} ne '') {
13856: if ($env{'form.'.$role.'_del_'.$img}) {
13857: $confhash->{$role}{$img} = '';
1.12 raeburn 13858: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13859: } else {
1.9 raeburn 13860: if ($confhash->{$role}{$img} eq '') {
13861: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13862: }
1.6 raeburn 13863: }
13864: } else {
13865: if ($env{'form.'.$role.'_del_'.$img}) {
13866: $confhash->{$role}{$img} = '';
1.12 raeburn 13867: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13868: }
13869: }
1.402 raeburn 13870: if ($role eq 'login') {
13871: if (($img eq 'logo') || ($img eq 'img')) {
13872: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13873: if ($confhash->{$role}{'showlogo'}{$img} ne
13874: $domconfig->{$role}{'showlogo'}{$img}) {
13875: $changes{$role}{'showlogo'}{$img} = 1;
13876: }
13877: } else {
13878: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13879: $changes{$role}{'showlogo'}{$img} = 1;
13880: }
1.70 raeburn 13881: }
1.402 raeburn 13882: }
13883: if ($img ne 'login') {
13884: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13885: if ($confhash->{$role}{'alttext'}{$img} ne
13886: $domconfig->{$role}{'alttext'}{$img}) {
13887: $changes{$role}{'alttext'}{$img} = 1;
13888: }
13889: } else {
13890: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13891: $changes{$role}{'alttext'}{$img} = 1;
13892: }
1.70 raeburn 13893: }
13894: }
13895: }
13896: }
1.6 raeburn 13897: if ($domconfig->{$role}{'font'} ne '') {
13898: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13899: $changes{$role}{'font'} = 1;
13900: }
13901: } else {
13902: if ($confhash->{$role}{'font'}) {
13903: $changes{$role}{'font'} = 1;
13904: }
13905: }
1.107 raeburn 13906: if ($role ne 'login') {
13907: if ($domconfig->{$role}{'fontmenu'} ne '') {
13908: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13909: $changes{$role}{'fontmenu'} = 1;
13910: }
13911: } else {
13912: if ($confhash->{$role}{'fontmenu'}) {
13913: $changes{$role}{'fontmenu'} = 1;
13914: }
1.97 tempelho 13915: }
13916: }
1.6 raeburn 13917: foreach my $item (@bgs) {
13918: if ($domconfig->{$role}{$item} ne '') {
13919: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13920: $changes{$role}{'bgs'}{$item} = 1;
13921: }
13922: } else {
13923: if ($confhash->{$role}{$item}) {
13924: $changes{$role}{'bgs'}{$item} = 1;
13925: }
13926: }
13927: }
13928: foreach my $item (@links) {
13929: if ($domconfig->{$role}{$item} ne '') {
13930: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13931: $changes{$role}{'links'}{$item} = 1;
13932: }
13933: } else {
13934: if ($confhash->{$role}{$item}) {
13935: $changes{$role}{'links'}{$item} = 1;
13936: }
13937: }
13938: }
1.41 raeburn 13939: foreach my $item (@logintext) {
13940: if ($domconfig->{$role}{$item} ne '') {
13941: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13942: $changes{$role}{'logintext'}{$item} = 1;
13943: }
13944: } else {
13945: if ($confhash->{$role}{$item}) {
13946: $changes{$role}{'logintext'}{$item} = 1;
13947: }
13948: }
13949: }
1.6 raeburn 13950: } else {
13951: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13952: \@logintext,$confhash,\%changes);
1.6 raeburn 13953: }
13954: } else {
13955: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13956: \@logintext,$confhash,\%changes);
1.6 raeburn 13957: }
13958: }
13959: return ($errors,%changes);
13960: }
13961:
1.46 raeburn 13962: sub config_check {
13963: my ($dom,$confname,$servadm) = @_;
13964: my ($configuserok,$author_ok,$switchserver,%currroles);
13965: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13966: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13967: $confname,$servadm);
13968: if ($configuserok eq 'ok') {
13969: $switchserver = &check_switchserver($dom,$confname);
13970: if ($switchserver eq '') {
13971: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13972: }
13973: }
13974: return ($configuserok,$author_ok,$switchserver);
13975: }
13976:
1.6 raeburn 13977: sub default_change_checker {
1.41 raeburn 13978: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13979: foreach my $item (@{$links}) {
13980: if ($confhash->{$role}{$item}) {
13981: $changes->{$role}{'links'}{$item} = 1;
13982: }
13983: }
13984: foreach my $item (@{$bgs}) {
13985: if ($confhash->{$role}{$item}) {
13986: $changes->{$role}{'bgs'}{$item} = 1;
13987: }
13988: }
1.41 raeburn 13989: foreach my $item (@{$logintext}) {
13990: if ($confhash->{$role}{$item}) {
13991: $changes->{$role}{'logintext'}{$item} = 1;
13992: }
13993: }
1.6 raeburn 13994: foreach my $img (@{$images}) {
13995: if ($env{'form.'.$role.'_del_'.$img}) {
13996: $confhash->{$role}{$img} = '';
1.12 raeburn 13997: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 13998: }
1.70 raeburn 13999: if ($role eq 'login') {
14000: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
14001: $changes->{$role}{'showlogo'}{$img} = 1;
14002: }
1.402 raeburn 14003: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
14004: if ($confhash->{$role}{'alttext'}{$img} ne '') {
14005: $changes->{$role}{'alttext'}{$img} = 1;
14006: }
14007: }
1.70 raeburn 14008: }
1.6 raeburn 14009: }
14010: if ($confhash->{$role}{'font'}) {
14011: $changes->{$role}{'font'} = 1;
14012: }
1.48 raeburn 14013: }
1.6 raeburn 14014:
14015: sub display_colorchgs {
14016: my ($dom,$changes,$roles,$confhash) = @_;
14017: my (%choices,$resulttext);
14018: if (!grep(/^login$/,@{$roles})) {
14019: $resulttext = &mt('Changes made:').'<br />';
14020: }
14021: foreach my $role (@{$roles}) {
14022: if ($role eq 'login') {
14023: %choices = &login_choices();
14024: } else {
14025: %choices = &color_font_choices();
14026: }
14027: if (ref($changes->{$role}) eq 'HASH') {
14028: if ($role ne 'login') {
14029: $resulttext .= '<h4>'.&mt($role).'</h4>';
14030: }
14031: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14032: if ($role ne 'login') {
14033: $resulttext .= '<ul>';
14034: }
14035: if (ref($changes->{$role}{$key}) eq 'HASH') {
14036: if ($role ne 'login') {
14037: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14038: }
14039: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14040: if (($role eq 'login') && ($key eq 'showlogo')) {
14041: if ($confhash->{$role}{$key}{$item}) {
14042: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14043: } else {
14044: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14045: }
1.402 raeburn 14046: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14047: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14048: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14049: $confhash->{$role}{$key}{$item}).'</li>';
14050: } else {
14051: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14052: }
1.70 raeburn 14053: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14054: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14055: } else {
1.12 raeburn 14056: my $newitem = $confhash->{$role}{$item};
14057: if ($key eq 'images') {
1.306 raeburn 14058: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14059: }
14060: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14061: }
14062: }
14063: if ($role ne 'login') {
14064: $resulttext .= '</ul></li>';
14065: }
14066: } else {
14067: if ($confhash->{$role}{$key} eq '') {
14068: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14069: } else {
14070: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14071: }
14072: }
14073: if ($role ne 'login') {
14074: $resulttext .= '</ul>';
14075: }
14076: }
14077: }
14078: }
1.3 raeburn 14079: return $resulttext;
1.1 raeburn 14080: }
14081:
1.9 raeburn 14082: sub thumb_dimensions {
14083: return ('200','50');
14084: }
14085:
1.16 raeburn 14086: sub check_dimensions {
14087: my ($inputfile) = @_;
14088: my ($fullwidth,$fullheight);
14089: if ($inputfile =~ m|^[/\w.\-]+$|) {
14090: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14091: my $imageinfo = <PIPE>;
14092: if (!close(PIPE)) {
14093: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14094: }
14095: chomp($imageinfo);
14096: my ($fullsize) =
1.21 raeburn 14097: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14098: if ($fullsize) {
14099: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14100: }
14101: }
14102: }
14103: return ($fullwidth,$fullheight);
14104: }
14105:
1.9 raeburn 14106: sub check_configuser {
14107: my ($uhome,$dom,$confname,$servadm) = @_;
14108: my ($configuserok,%currroles);
14109: if ($uhome eq 'no_host') {
14110: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14111: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14112: $configuserok =
14113: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14114: $configpass,'','','','','',undef,$servadm);
14115: } else {
14116: $configuserok = 'ok';
14117: %currroles =
14118: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14119: }
14120: return ($configuserok,%currroles);
14121: }
14122:
14123: sub check_authorstatus {
14124: my ($dom,$confname,%currroles) = @_;
14125: my $author_ok;
1.40 raeburn 14126: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14127: my $start = time;
14128: my $end = 0;
14129: $author_ok =
14130: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14131: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14132: } else {
14133: $author_ok = 'ok';
14134: }
14135: return $author_ok;
14136: }
14137:
1.421 raeburn 14138: sub update_modify_urls {
14139: my ($r,$modified) = @_;
14140: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14141: push(@{$modified_urls},$modified);
14142: unless ($registered_cleanup) {
14143: my $handlers = $r->get_handlers('PerlCleanupHandler');
14144: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14145: $registered_cleanup=1;
1.9 raeburn 14146: }
14147: }
1.155 raeburn 14148: }
14149:
14150: sub notifysubscribed {
14151: foreach my $targetsource (@{$modified_urls}){
14152: next unless (ref($targetsource) eq 'ARRAY');
14153: my ($target,$source)=@{$targetsource};
14154: if ($source ne '') {
1.316 raeburn 14155: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14156: print $logfh "\nCleanup phase: Notifications\n";
14157: my @subscribed=&subscribed_hosts($target);
14158: foreach my $subhost (@subscribed) {
14159: print $logfh "\nNotifying host ".$subhost.':';
14160: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14161: print $logfh $reply;
14162: }
14163: my @subscribedmeta=&subscribed_hosts("$target.meta");
14164: foreach my $subhost (@subscribedmeta) {
14165: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14166: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14167: $subhost);
14168: print $logfh $reply;
14169: }
14170: print $logfh "\n============ Done ============\n";
1.160 raeburn 14171: close($logfh);
1.155 raeburn 14172: }
14173: }
14174: }
14175: return OK;
14176: }
14177:
14178: sub subscribed_hosts {
14179: my ($target) = @_;
14180: my @subscribed;
1.316 raeburn 14181: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14182: while (my $subline=<$fh>) {
14183: if ($subline =~ /^($match_lonid):/) {
14184: my $host = $1;
14185: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14186: unless (grep(/^\Q$host\E$/,@subscribed)) {
14187: push(@subscribed,$host);
14188: }
14189: }
14190: }
14191: }
14192: }
14193: return @subscribed;
1.9 raeburn 14194: }
14195:
14196: sub check_switchserver {
14197: my ($dom,$confname) = @_;
1.424 raeburn 14198: my ($allowed,$switchserver,$home);
14199: if ($confname eq '') {
1.9 raeburn 14200: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14201: } else {
14202: $home = &Apache::lonnet::homeserver($confname,$dom);
14203: if ($home eq 'no_host') {
14204: $home = &Apache::lonnet::domain($dom,'primary');
14205: }
1.9 raeburn 14206: }
14207: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14208: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14209: if (!$allowed) {
1.426 raeburn 14210: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14211: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14212: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14213: }
14214: return $switchserver;
14215: }
14216:
1.1 raeburn 14217: sub modify_quotas {
1.216 raeburn 14218: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14219: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14220: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14221: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14222: $validationfieldsref);
1.86 raeburn 14223: if ($action eq 'quotas') {
1.429 raeburn 14224: $context = 'tools';
1.163 raeburn 14225: } else {
1.86 raeburn 14226: $context = $action;
14227: }
14228: if ($context eq 'requestcourses') {
1.325 raeburn 14229: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14230: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14231: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14232: %titles = &courserequest_titles();
14233: $toolregexp = join('|',@usertools);
14234: %conditions = &courserequest_conditions();
1.216 raeburn 14235: $confname = $dom.'-domainconfig';
14236: my $servadm = $r->dir_config('lonAdmEMail');
14237: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14238: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14239: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14240: } elsif ($context eq 'requestauthor') {
14241: @usertools = ('author');
14242: %titles = &authorrequest_titles();
1.86 raeburn 14243: } else {
1.430 raeburn 14244: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14245: %titles = &tool_titles();
1.86 raeburn 14246: }
1.212 raeburn 14247: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14249: foreach my $key (keys(%env)) {
1.101 raeburn 14250: if ($context eq 'requestcourses') {
14251: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14252: my $item = $1;
14253: my $type = $2;
14254: if ($type =~ /^limit_(.+)/) {
14255: $limithash{$item}{$1} = $env{$key};
14256: } else {
14257: $confhash{$item}{$type} = $env{$key};
14258: }
14259: }
1.163 raeburn 14260: } elsif ($context eq 'requestauthor') {
14261: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14262: $confhash{$1} = $env{$key};
14263: }
1.101 raeburn 14264: } else {
1.86 raeburn 14265: if ($key =~ /^form\.quota_(.+)$/) {
14266: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14267: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14268: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14269: }
1.72 raeburn 14270: }
14271: }
1.163 raeburn 14272: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14273: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14274: @approvalnotify = sort(@approvalnotify);
14275: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14276: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14277: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14278: foreach my $type (@hasuniquecode) {
14279: if (grep(/^\Q$type\E$/,@crstypes)) {
14280: $confhash{'uniquecode'}{$type} = 1;
14281: }
1.216 raeburn 14282: }
1.242 raeburn 14283: my (%newbook,%allpos);
1.216 raeburn 14284: if ($context eq 'requestcourses') {
1.242 raeburn 14285: foreach my $type ('textbooks','templates') {
14286: @{$allpos{$type}} = ();
14287: my $invalid;
14288: if ($type eq 'textbooks') {
14289: $invalid = &mt('Invalid LON-CAPA course for textbook');
14290: } else {
14291: $invalid = &mt('Invalid LON-CAPA course for template');
14292: }
14293: if ($env{'form.'.$type.'_addbook'}) {
14294: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14295: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14296: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14297: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14298: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14299: } else {
14300: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14301: my $position = $env{'form.'.$type.'_addbook_pos'};
14302: $position =~ s/\D+//g;
14303: if ($position ne '') {
14304: $allpos{$type}[$position] = $newbook{$type};
14305: }
1.216 raeburn 14306: }
1.242 raeburn 14307: } else {
14308: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14309: }
14310: }
1.242 raeburn 14311: }
1.216 raeburn 14312: }
1.102 raeburn 14313: if (ref($domconfig{$action}) eq 'HASH') {
14314: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14315: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14316: $changes{'notify'}{'approval'} = 1;
14317: }
14318: } else {
1.144 raeburn 14319: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14320: $changes{'notify'}{'approval'} = 1;
14321: }
14322: }
1.218 raeburn 14323: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14324: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14325: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14326: unless ($confhash{'uniquecode'}{$crstype}) {
14327: $changes{'uniquecode'} = 1;
14328: }
14329: }
14330: unless ($changes{'uniquecode'}) {
14331: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14332: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14333: $changes{'uniquecode'} = 1;
14334: }
14335: }
14336: }
14337: } else {
14338: $changes{'uniquecode'} = 1;
14339: }
14340: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14341: $changes{'uniquecode'} = 1;
1.216 raeburn 14342: }
14343: if ($context eq 'requestcourses') {
1.242 raeburn 14344: foreach my $type ('textbooks','templates') {
14345: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14346: my %deletions;
14347: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14348: if (@todelete) {
14349: map { $deletions{$_} = 1; } @todelete;
14350: }
14351: my %imgdeletions;
14352: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14353: if (@todeleteimages) {
14354: map { $imgdeletions{$_} = 1; } @todeleteimages;
14355: }
14356: my $maxnum = $env{'form.'.$type.'_maxnum'};
14357: for (my $i=0; $i<=$maxnum; $i++) {
14358: my $itemid = $env{'form.'.$type.'_id_'.$i};
14359: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14360: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14361: if ($deletions{$key}) {
14362: if ($domconfig{$action}{$type}{$key}{'image'}) {
14363: #FIXME need to obsolete item in RES space
14364: }
14365: next;
14366: } else {
14367: my $newpos = $env{'form.'.$itemid};
14368: $newpos =~ s/\D+//g;
1.243 raeburn 14369: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14370: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14371: ($type eq 'templates'));
1.242 raeburn 14372: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14373: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14374: $changes{$type}{$key} = 1;
14375: }
14376: }
14377: $allpos{$type}[$newpos] = $key;
14378: }
14379: if ($imgdeletions{$key}) {
14380: $changes{$type}{$key} = 1;
1.216 raeburn 14381: #FIXME need to obsolete item in RES space
1.242 raeburn 14382: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14383: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14384: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14385: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14386: } else {
14387: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14388: $cdom,$cnum,$type,$configuserok,
14389: $switchserver,$author_ok);
14390: if ($imgurl) {
14391: $confhash{$type}{$key}{'image'} = $imgurl;
14392: $changes{$type}{$key} = 1;
14393: }
14394: if ($error) {
14395: &Apache::lonnet::logthis($error);
14396: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14397: }
14398: }
1.242 raeburn 14399: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14400: $confhash{$type}{$key}{'image'} =
14401: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14402: }
14403: }
14404: }
14405: }
14406: }
14407: }
1.102 raeburn 14408: } else {
1.144 raeburn 14409: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14410: $changes{'notify'}{'approval'} = 1;
14411: }
1.218 raeburn 14412: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14413: $changes{'uniquecode'} = 1;
14414: }
14415: }
14416: if ($context eq 'requestcourses') {
1.242 raeburn 14417: foreach my $type ('textbooks','templates') {
14418: if ($newbook{$type}) {
14419: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14420: foreach my $item ('subject','title','publisher','author') {
14421: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14422: ($type eq 'template'));
1.242 raeburn 14423: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14424: if ($env{'form.'.$type.'_addbook_'.$item}) {
14425: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14426: }
14427: }
14428: if ($type eq 'textbooks') {
14429: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14430: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14431: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14432: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14433: } else {
14434: my ($imageurl,$error) =
14435: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14436: $configuserok,$switchserver,$author_ok);
14437: if ($imageurl) {
14438: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14439: }
14440: if ($error) {
14441: &Apache::lonnet::logthis($error);
14442: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14443: }
1.242 raeburn 14444: }
14445: }
1.216 raeburn 14446: }
14447: }
1.242 raeburn 14448: if (@{$allpos{$type}} > 0) {
14449: my $idx = 0;
14450: foreach my $item (@{$allpos{$type}}) {
14451: if ($item ne '') {
14452: $confhash{$type}{$item}{'order'} = $idx;
14453: if (ref($domconfig{$action}) eq 'HASH') {
14454: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14455: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14456: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14457: $changes{$type}{$item} = 1;
14458: }
1.216 raeburn 14459: }
14460: }
14461: }
1.242 raeburn 14462: $idx ++;
1.216 raeburn 14463: }
14464: }
14465: }
14466: }
1.235 raeburn 14467: if (ref($validationitemsref) eq 'ARRAY') {
14468: foreach my $item (@{$validationitemsref}) {
14469: if ($item eq 'fields') {
14470: my @changed;
14471: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14472: if (@{$confhash{'validation'}{$item}} > 0) {
14473: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14474: }
1.266 raeburn 14475: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14476: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14477: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14478: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14479: $domconfig{'requestcourses'}{'validation'}{$item});
14480: } else {
14481: @changed = @{$confhash{'validation'}{$item}};
14482: }
1.235 raeburn 14483: } else {
14484: @changed = @{$confhash{'validation'}{$item}};
14485: }
14486: } else {
14487: @changed = @{$confhash{'validation'}{$item}};
14488: }
14489: if (@changed) {
14490: if ($confhash{'validation'}{$item}) {
14491: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14492: } else {
14493: $changes{'validation'}{$item} = &mt('None');
14494: }
14495: }
14496: } else {
14497: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14498: if ($item eq 'markup') {
14499: if ($env{'form.requestcourses_validation_'.$item}) {
14500: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14501: }
14502: }
1.266 raeburn 14503: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14504: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14505: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14506: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14507: }
14508: } else {
14509: if ($confhash{'validation'}{$item} ne '') {
14510: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14511: }
1.235 raeburn 14512: }
14513: } else {
14514: if ($confhash{'validation'}{$item} ne '') {
14515: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14516: }
14517: }
14518: }
14519: }
14520: }
14521: if ($env{'form.validationdc'}) {
14522: my $newval = $env{'form.validationdc'};
1.285 raeburn 14523: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14524: if (exists($domcoords{$newval})) {
14525: $confhash{'validation'}{'dc'} = $newval;
14526: }
14527: }
14528: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14529: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14530: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14531: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14532: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14533: if ($confhash{'validation'}{'dc'} eq '') {
14534: $changes{'validation'}{'dc'} = &mt('None');
14535: } else {
14536: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14537: }
1.235 raeburn 14538: }
1.266 raeburn 14539: } elsif ($confhash{'validation'}{'dc'} ne '') {
14540: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14541: }
14542: } elsif ($confhash{'validation'}{'dc'} ne '') {
14543: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14544: }
14545: } elsif ($confhash{'validation'}{'dc'} ne '') {
14546: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14547: }
1.266 raeburn 14548: } else {
14549: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14550: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14551: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14552: $changes{'validation'}{'dc'} = &mt('None');
14553: }
14554: }
1.235 raeburn 14555: }
14556: }
1.102 raeburn 14557: }
14558: } else {
1.86 raeburn 14559: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14560: }
1.72 raeburn 14561: foreach my $item (@usertools) {
14562: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14563: my $unset;
1.101 raeburn 14564: if ($context eq 'requestcourses') {
1.104 raeburn 14565: $unset = '0';
14566: if ($type eq '_LC_adv') {
14567: $unset = '';
14568: }
1.101 raeburn 14569: if ($confhash{$item}{$type} eq 'autolimit') {
14570: $confhash{$item}{$type} .= '=';
14571: unless ($limithash{$item}{$type} =~ /\D/) {
14572: $confhash{$item}{$type} .= $limithash{$item}{$type};
14573: }
14574: }
1.163 raeburn 14575: } elsif ($context eq 'requestauthor') {
14576: $unset = '0';
14577: if ($type eq '_LC_adv') {
14578: $unset = '';
14579: }
1.72 raeburn 14580: } else {
1.101 raeburn 14581: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14582: $confhash{$item}{$type} = 1;
14583: } else {
14584: $confhash{$item}{$type} = 0;
14585: }
1.72 raeburn 14586: }
1.86 raeburn 14587: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14588: if ($action eq 'requestauthor') {
14589: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14590: $changes{$type} = 1;
14591: }
14592: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14593: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14594: $changes{$item}{$type} = 1;
14595: }
14596: } else {
14597: if ($context eq 'requestcourses') {
1.104 raeburn 14598: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14599: $changes{$item}{$type} = 1;
14600: }
14601: } else {
14602: if (!$confhash{$item}{$type}) {
14603: $changes{$item}{$type} = 1;
14604: }
14605: }
14606: }
14607: } else {
14608: if ($context eq 'requestcourses') {
1.104 raeburn 14609: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14610: $changes{$item}{$type} = 1;
14611: }
1.163 raeburn 14612: } elsif ($context eq 'requestauthor') {
14613: if ($confhash{$type} ne $unset) {
14614: $changes{$type} = 1;
14615: }
1.72 raeburn 14616: } else {
14617: if (!$confhash{$item}{$type}) {
14618: $changes{$item}{$type} = 1;
14619: }
14620: }
14621: }
1.1 raeburn 14622: }
14623: }
1.163 raeburn 14624: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14625: if (ref($domconfig{'quotas'}) eq 'HASH') {
14626: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14627: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14628: if (exists($confhash{'defaultquota'}{$key})) {
14629: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14630: $changes{'defaultquota'}{$key} = 1;
14631: }
14632: } else {
14633: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14634: }
14635: }
1.86 raeburn 14636: } else {
14637: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14638: if (exists($confhash{'defaultquota'}{$key})) {
14639: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14640: $changes{'defaultquota'}{$key} = 1;
14641: }
14642: } else {
14643: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14644: }
1.1 raeburn 14645: }
14646: }
1.197 raeburn 14647: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14648: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14649: }
14650: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14651: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14652: }
1.1 raeburn 14653: }
1.86 raeburn 14654: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14655: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14656: if (ref($domconfig{'quotas'}) eq 'HASH') {
14657: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14658: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14659: $changes{'defaultquota'}{$key} = 1;
14660: }
14661: } else {
14662: if (!exists($domconfig{'quotas'}{$key})) {
14663: $changes{'defaultquota'}{$key} = 1;
14664: }
1.72 raeburn 14665: }
14666: } else {
1.86 raeburn 14667: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14668: }
1.1 raeburn 14669: }
14670: }
14671: }
1.72 raeburn 14672:
1.163 raeburn 14673: if ($context eq 'requestauthor') {
14674: $domdefaults{'requestauthor'} = \%confhash;
14675: } else {
14676: foreach my $key (keys(%confhash)) {
1.242 raeburn 14677: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14678: $domdefaults{$key} = $confhash{$key};
14679: }
1.163 raeburn 14680: }
1.72 raeburn 14681: }
1.163 raeburn 14682:
1.1 raeburn 14683: my %quotahash = (
1.86 raeburn 14684: $action => { %confhash }
1.1 raeburn 14685: );
14686: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14687: $dom);
14688: if ($putresult eq 'ok') {
14689: if (keys(%changes) > 0) {
1.72 raeburn 14690: my $cachetime = 24*60*60;
14691: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14692: if (ref($lastactref) eq 'HASH') {
14693: $lastactref->{'domdefaults'} = 1;
14694: }
1.1 raeburn 14695: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14696: unless (($context eq 'requestcourses') ||
1.163 raeburn 14697: ($context eq 'requestauthor')) {
1.86 raeburn 14698: if (ref($changes{'defaultquota'}) eq 'HASH') {
14699: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14700: foreach my $type (@{$types},'default') {
14701: if (defined($changes{'defaultquota'}{$type})) {
14702: my $typetitle = $usertypes->{$type};
14703: if ($type eq 'default') {
14704: $typetitle = $othertitle;
14705: }
1.213 raeburn 14706: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14707: }
14708: }
1.86 raeburn 14709: $resulttext .= '</ul></li>';
1.72 raeburn 14710: }
14711: }
1.80 raeburn 14712: my %newenv;
1.72 raeburn 14713: foreach my $item (@usertools) {
1.163 raeburn 14714: my (%haschgs,%inconf);
14715: if ($context eq 'requestauthor') {
14716: %haschgs = %changes;
1.210 raeburn 14717: %inconf = %confhash;
1.163 raeburn 14718: } else {
14719: if (ref($changes{$item}) eq 'HASH') {
14720: %haschgs = %{$changes{$item}};
14721: }
14722: if (ref($confhash{$item}) eq 'HASH') {
14723: %inconf = %{$confhash{$item}};
14724: }
14725: }
14726: if (keys(%haschgs) > 0) {
1.80 raeburn 14727: my $newacc =
14728: &Apache::lonnet::usertools_access($env{'user.name'},
14729: $env{'user.domain'},
1.86 raeburn 14730: $item,'reload',$context);
1.210 raeburn 14731: if (($context eq 'requestcourses') ||
1.163 raeburn 14732: ($context eq 'requestauthor')) {
1.108 raeburn 14733: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14734: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14735: }
14736: } else {
14737: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14738: $newenv{'environment.availabletools.'.$item} = $newacc;
14739: }
1.80 raeburn 14740: }
1.163 raeburn 14741: unless ($context eq 'requestauthor') {
14742: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14743: }
1.72 raeburn 14744: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14745: if ($haschgs{$type}) {
1.72 raeburn 14746: my $typetitle = $usertypes->{$type};
14747: if ($type eq 'default') {
14748: $typetitle = $othertitle;
14749: } elsif ($type eq '_LC_adv') {
14750: $typetitle = 'LON-CAPA Advanced Users';
14751: }
1.163 raeburn 14752: if ($inconf{$type}) {
1.101 raeburn 14753: if ($context eq 'requestcourses') {
14754: my $cond;
1.163 raeburn 14755: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14756: if ($1 eq '') {
14757: $cond = &mt('(Automatic processing of any request).');
14758: } else {
14759: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14760: }
14761: } else {
1.163 raeburn 14762: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14763: }
14764: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14765: } elsif ($context eq 'requestauthor') {
14766: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14767: $titles{$inconf{$type}},$typetitle);
14768:
1.101 raeburn 14769: } else {
14770: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14771: }
1.72 raeburn 14772: } else {
1.104 raeburn 14773: if ($type eq '_LC_adv') {
1.163 raeburn 14774: if ($inconf{$type} eq '0') {
1.104 raeburn 14775: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14776: } else {
14777: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14778: }
14779: } else {
14780: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14781: }
1.72 raeburn 14782: }
14783: }
1.26 raeburn 14784: }
1.163 raeburn 14785: unless ($context eq 'requestauthor') {
14786: $resulttext .= '</ul></li>';
14787: }
1.26 raeburn 14788: }
1.1 raeburn 14789: }
1.163 raeburn 14790: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14791: if (ref($changes{'notify'}) eq 'HASH') {
14792: if ($changes{'notify'}{'approval'}) {
14793: if (ref($confhash{'notify'}) eq 'HASH') {
14794: if ($confhash{'notify'}{'approval'}) {
14795: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14796: } else {
1.163 raeburn 14797: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14798: }
14799: }
14800: }
14801: }
14802: }
1.216 raeburn 14803: if ($action eq 'requestcourses') {
14804: my @offon = ('off','on');
14805: if ($changes{'uniquecode'}) {
1.218 raeburn 14806: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14807: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14808: $resulttext .= '<li>'.
14809: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14810: '</li>';
14811: } else {
14812: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14813: '</li>';
14814: }
1.216 raeburn 14815: }
1.242 raeburn 14816: foreach my $type ('textbooks','templates') {
14817: if (ref($changes{$type}) eq 'HASH') {
14818: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14819: foreach my $key (sort(keys(%{$changes{$type}}))) {
14820: my %coursehash = &Apache::lonnet::coursedescription($key);
14821: my $coursetitle = $coursehash{'description'};
14822: my $position = $confhash{$type}{$key}{'order'} + 1;
14823: $resulttext .= '<li>';
1.243 raeburn 14824: foreach my $item ('subject','title','publisher','author') {
14825: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14826: ($type eq 'templates'));
1.242 raeburn 14827: my $name = $item.':';
14828: $name =~ s/^(\w)/\U$1/;
14829: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14830: }
14831: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14832: if ($type eq 'textbooks') {
14833: if ($confhash{$type}{$key}{'image'}) {
14834: $resulttext .= ' '.&mt('Image: [_1]',
14835: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14836: ' alt="Textbook cover" />').'<br />';
14837: }
14838: }
14839: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14840: }
1.242 raeburn 14841: $resulttext .= '</ul></li>';
1.216 raeburn 14842: }
14843: }
1.235 raeburn 14844: if (ref($changes{'validation'}) eq 'HASH') {
14845: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14846: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14847: foreach my $item (@{$validationitemsref}) {
14848: if (exists($changes{'validation'}{$item})) {
14849: if ($item eq 'markup') {
14850: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14851: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14852: } else {
14853: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14854: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14855: }
14856: }
14857: }
14858: if (exists($changes{'validation'}{'dc'})) {
14859: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14860: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14861: }
1.442 raeburn 14862: $resulttext .= '</ul></li>';
1.235 raeburn 14863: }
14864: }
1.216 raeburn 14865: }
1.1 raeburn 14866: $resulttext .= '</ul>';
1.80 raeburn 14867: if (keys(%newenv)) {
14868: &Apache::lonnet::appenv(\%newenv);
14869: }
1.1 raeburn 14870: } else {
1.86 raeburn 14871: if ($context eq 'requestcourses') {
14872: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14873: } elsif ($context eq 'requestauthor') {
14874: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14875: } else {
1.90 weissno 14876: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14877: }
1.1 raeburn 14878: }
14879: } else {
1.11 albertel 14880: $resulttext = '<span class="LC_error">'.
14881: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14882: }
1.216 raeburn 14883: if ($errors) {
14884: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14885: '<ul>'.$errors.'</ul></p>';
14886: }
1.3 raeburn 14887: return $resulttext;
1.1 raeburn 14888: }
14889:
1.216 raeburn 14890: sub process_textbook_image {
1.242 raeburn 14891: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14892: my $filename = $env{'form.'.$caller.'.filename'};
14893: my ($error,$url);
14894: my ($width,$height) = (50,50);
14895: if ($configuserok eq 'ok') {
14896: if ($switchserver) {
14897: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14898: $switchserver);
14899: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14900: my $modified = [];
1.216 raeburn 14901: my ($result,$imageurl) =
1.421 raeburn 14902: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14903: "$type/$cdom/$cnum/cover",$width,$height,
14904: '',$modified);
1.216 raeburn 14905: if ($result eq 'ok') {
14906: $url = $imageurl;
1.421 raeburn 14907: &update_modify_urls($r,$modified);
1.216 raeburn 14908: } else {
14909: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14910: }
14911: } else {
14912: $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);
14913: }
14914: } else {
14915: $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);
14916: }
14917: return ($url,$error);
14918: }
14919:
1.267 raeburn 14920: sub modify_ltitools {
14921: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14922: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14923: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14924:
1.267 raeburn 14925: my $confname = $dom.'-domainconfig';
14926: my $servadm = $r->dir_config('lonAdmEMail');
14927: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14928:
14929: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14930: my $toolserror =
14931: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14932: $lastactref,$configuserok,$switchserver,$author_ok);
14933:
14934: my $home = &Apache::lonnet::domain($dom,'primary');
14935: unless (($home eq 'no_host') || ($home eq '')) {
14936: my @ids=&Apache::lonnet::current_machine_ids();
14937: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14938: }
14939:
14940: if (keys(%ltitoolschg)) {
14941: foreach my $id (keys(%ltitoolschg)) {
14942: if (ref($ltitoolschg{$id}) eq 'HASH') {
14943: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14944: if (($inner eq 'secret') || ($inner eq 'key')) {
14945: if ($is_home) {
14946: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14947: }
14948: }
14949: }
1.267 raeburn 14950: }
1.421 raeburn 14951: }
14952: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14953: if (keys(%ltitoolschg)) {
14954: %newltitools = %ltitoolschg;
14955: }
14956: }
14957: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14958: foreach my $id (%{$domconfig{'ltitools'}}) {
14959: next if ($id !~ /^\d+$/);
14960: unless (exists($ltitoolschg{$id})) {
14961: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14962: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14963: if (($inner eq 'secret') || ($inner eq 'key')) {
14964: if ($is_home) {
14965: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14966: }
14967: } else {
14968: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14969: }
14970: }
14971: } else {
14972: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14973: }
1.421 raeburn 14974: }
14975: }
14976: }
14977: if ($toolserror) {
14978: $errors = '<li>'.$toolserror.'</li>';
14979: }
14980: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14981: $resulttext = &mt('No changes made.');
14982: if ($errors) {
14983: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14984: $errors.'</ul>';
14985: }
14986: return $resulttext;
14987: }
14988: my %ltitoolshash = (
14989: $action => { %newltitools }
14990: );
14991: if (keys(%secchanges)) {
14992: $ltitoolshash{'toolsec'} = \%newtoolsec;
14993: }
14994: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
14995: if ($putresult eq 'ok') {
14996: my %keystore;
14997: if ($is_home) {
14998: my %toolsenchash = (
14999: $action => { %newtoolsenc }
15000: );
15001: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 15002: my $cachetime = 24*60*60;
15003: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 15004: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
15005: }
15006: $resulttext = &mt('Changes made:').'<ul>';
15007: if (keys(%secchanges) > 0) {
1.423 raeburn 15008: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15009: }
15010: if (keys(%ltitoolschg) > 0) {
15011: $resulttext .= $ltitoolsoutput;
15012: }
1.423 raeburn 15013: my $cachetime = 24*60*60;
15014: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15015: if (ref($lastactref) eq 'HASH') {
15016: $lastactref->{'ltitools'} = 1;
15017: }
1.421 raeburn 15018: } else {
15019: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15020: }
15021: if ($errors) {
15022: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15023: $errors.'</ul></p>';
15024: }
15025: return $resulttext;
15026: }
15027:
15028: sub fetch_secrets {
15029: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15030: my %keyset;
15031: %{$currsec} = ();
15032: $newsec->{'private'}{'keys'} = [];
15033: $newsec->{'encrypt'} = {};
15034: $newsec->{'rules'} = {};
15035: if ($context eq 'ltisec') {
15036: $newsec->{'linkprot'} = {};
15037: }
15038: if (ref($domconfig->{$context}) eq 'HASH') {
15039: %{$currsec} = %{$domconfig->{$context}};
15040: if ($context eq 'ltisec') {
15041: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15042: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15043: unless ($id =~ /^\d+$/) {
15044: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15045: }
1.267 raeburn 15046: }
15047: }
1.421 raeburn 15048: }
15049: if (ref($currsec->{'private'}) eq 'HASH') {
15050: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15051: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15052: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15053: }
1.421 raeburn 15054: }
15055: }
15056: my @items= ('crs','dom');
15057: if ($context eq 'ltisec') {
15058: push(@items,'consumers');
15059: }
15060: foreach my $item (@items) {
15061: my $formelement;
15062: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15063: $formelement = 'form.'.$context.'_'.$item;
15064: } else {
15065: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15066: }
15067: if ($env{$formelement}) {
15068: $newsec->{'encrypt'}{$item} = 1;
15069: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15070: unless ($currsec->{'encrypt'}{$item}) {
15071: $secchanges->{'encrypt'} = 1;
15072: }
15073: } else {
15074: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15075: }
1.421 raeburn 15076: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15077: if ($currsec->{'encrypt'}{$item}) {
15078: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15079: }
1.421 raeburn 15080: }
15081: }
15082: my $secrets;
15083: if ($context eq 'ltisec') {
15084: $secrets = 'ltisecrets';
15085: } else {
15086: $secrets = 'toolsecrets';
15087: }
15088: unless (exists($currsec->{'rules'})) {
15089: $currsec->{'rules'} = {};
15090: }
15091: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15092:
15093: my @ids=&Apache::lonnet::current_machine_ids();
15094: my %servers = &Apache::lonnet::get_servers($dom,'library');
15095:
15096: foreach my $hostid (keys(%servers)) {
15097: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15098: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15099: if (exists($env{$keyitem})) {
15100: $env{$keyitem} =~ s/(`)/'/g;
15101: if ($keyset{$hostid}) {
15102: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15103: if ($env{$keyitem} ne '') {
15104: $secchanges->{'private'} = 1;
15105: $newkeyset->{$hostid} = $env{$keyitem};
15106: }
1.296 raeburn 15107: }
1.421 raeburn 15108: } elsif ($env{$keyitem} ne '') {
15109: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15110: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15111: }
1.421 raeburn 15112: $secchanges->{'private'} = 1;
15113: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15114: }
15115: }
1.421 raeburn 15116: }
15117: }
15118: }
15119:
15120: sub store_security {
1.424 raeburn 15121: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15122: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15123: (ref($keystore) eq 'HASH'));
15124: if (keys(%{$secchanges})) {
15125: if ($secchanges->{'private'}) {
15126: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15127: foreach my $hostid (keys(%{$newkeyset})) {
15128: my $storehash = {
15129: key => $newkeyset->{$hostid},
15130: who => $env{'user.name'}.':'.$env{'user.domain'},
15131: };
15132: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15133: $dom,$hostid);
15134: }
15135: }
15136: }
15137: }
15138:
15139: sub lti_security_results {
1.423 raeburn 15140: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15141: my $output;
1.423 raeburn 15142: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15143: my $needs_update;
1.421 raeburn 15144: foreach my $item (keys(%{$secchanges})) {
15145: if ($item eq 'encrypt') {
1.423 raeburn 15146: $needs_update = 1;
1.421 raeburn 15147: my %encrypted;
15148: if ($context eq 'lti') {
15149: %encrypted = (
15150: crs => {
15151: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15152: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15153: },
15154: dom => {
15155: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15156: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15157: },
15158: consumers => {
15159: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15160: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15161: },
15162: );
1.267 raeburn 15163: } else {
1.421 raeburn 15164: %encrypted = (
15165: crs => {
15166: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15167: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15168: },
15169: dom => {
15170: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15171: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15172: },
15173: );
15174: }
15175: my @types= ('crs','dom');
15176: if ($context eq 'lti') {
1.423 raeburn 15177: foreach my $type (@types) {
15178: undef($domdefaults{'linkprotenc_'.$type});
15179: }
1.421 raeburn 15180: push(@types,'consumers');
1.423 raeburn 15181: undef($domdefaults{'ltienc_consumers'});
15182: } elsif ($context eq 'ltitools') {
15183: foreach my $type (@types) {
15184: undef($domdefaults{'toolenc_'.$type});
15185: }
1.267 raeburn 15186: }
1.421 raeburn 15187: foreach my $type (@types) {
15188: my $shown = $encrypted{$type}{'off'};
15189: if (ref($newsec->{$item}) eq 'HASH') {
15190: if ($newsec->{$item}{$type}) {
1.423 raeburn 15191: if ($context eq 'lti') {
15192: if ($type eq 'consumers') {
15193: $domdefaults{'ltienc_consumers'} = 1;
15194: } else {
15195: $domdefaults{'linkprotenc_'.$type} = 1;
15196: }
15197: } elsif ($context eq 'ltitools') {
15198: $domdefaults{'toolenc_'.$type} = 1;
15199: }
1.421 raeburn 15200: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15201: }
1.267 raeburn 15202: }
1.421 raeburn 15203: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15204: }
1.421 raeburn 15205: } elsif ($item eq 'rules') {
15206: my %titles = &Apache::lonlocal::texthash(
15207: min => 'Minimum password length',
15208: max => 'Maximum password length',
15209: chars => 'Required characters',
15210: );
15211: foreach my $rule ('min','max') {
15212: if ($newsec->{rules}{$rule} eq '') {
15213: if ($rule eq 'min') {
15214: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15215: ' '.&mt('Default of [_1] will be used',
15216: $Apache::lonnet::passwdmin).'</li>';
15217: } else {
15218: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15219: }
15220: } else {
15221: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15222: }
15223: }
15224: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15225: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15226: my %rulenames = &Apache::lonlocal::texthash(
15227: uc => 'At least one upper case letter',
15228: lc => 'At least one lower case letter',
15229: num => 'At least one number',
15230: spec => 'At least one non-alphanumeric',
15231: );
15232: my $needed = '<ul><li>'.
15233: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15234: '</li></ul>';
15235: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15236: } else {
15237: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15238: }
1.421 raeburn 15239: } else {
15240: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15241: }
1.421 raeburn 15242: } elsif ($item eq 'private') {
1.423 raeburn 15243: $needs_update = 1;
15244: if ($context eq 'lti') {
15245: undef($domdefaults{'ltiprivhosts'});
15246: } elsif ($context eq 'ltitools') {
15247: undef($domdefaults{'toolprivhosts'});
15248: }
1.421 raeburn 15249: if (keys(%{$newkeyset})) {
1.423 raeburn 15250: my @privhosts;
1.421 raeburn 15251: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15252: if ($keystore->{$hostid} eq 'ok') {
15253: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15254: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15255: push(@privhosts,$hostid);
15256: }
15257: }
15258: }
15259: if (@privhosts) {
15260: if ($context eq 'lti') {
15261: $domdefaults{'ltiprivhosts'} = \@privhosts;
15262: } elsif ($context eq 'ltitools') {
15263: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15264: }
15265: }
15266: }
1.421 raeburn 15267: } elsif ($item eq 'linkprot') {
15268: next;
1.434 raeburn 15269: } elsif ($item eq 'suggested') {
15270: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15271: (ref($newsec->{'suggested'}) eq 'HASH')) {
15272: my $suggestions;
15273: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15274: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15275: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15276: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15277: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15278: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15279: '</li>';
15280: } else {
15281: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15282: $newsec->{'suggested'}->{$id}).'</li>';
15283: }
15284: }
15285: if ($suggestions) {
15286: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15287: '<ul>'.$suggestions.'</ul>'.
15288: '</li>';
15289: }
15290: }
1.267 raeburn 15291: }
15292: }
1.423 raeburn 15293: if ($needs_update) {
15294: my $cachetime = 24*60*60;
15295: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15296: }
1.421 raeburn 15297: return $output;
15298: }
15299:
15300: sub modify_proctoring {
15301: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15302: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15303: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15304: my $confname = $dom.'-domainconfig';
15305: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15306: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15307: my %providernames = &proctoring_providernames();
15308: my $maxnum = scalar(keys(%providernames));
15309:
15310: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15311: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15312: if (ref($requref) eq 'HASH') {
15313: %requserfields = %{$requref};
15314: }
15315: if (ref($opturef) eq 'HASH') {
15316: %optuserfields = %{$opturef};
15317: }
15318: if (ref($defref) eq 'HASH') {
15319: %defaults = %{$defref};
15320: }
15321: if (ref($extref) eq 'HASH') {
15322: %extended = %{$extref};
15323: }
15324: if (ref($crsref) eq 'HASH') {
15325: %crsconf = %{$crsref};
15326: }
15327: if (ref($rolesref) eq 'ARRAY') {
15328: @courseroles = @{$rolesref};
15329: }
15330: if (ref($ltiref) eq 'ARRAY') {
15331: @ltiroles = @{$ltiref};
15332: }
15333:
15334: if (ref($domconfig{$action}) eq 'HASH') {
15335: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15336: if (@todeleteimages) {
15337: map { $imgdeletions{$_} = 1; } @todeleteimages;
15338: }
15339: }
15340: my %customadds;
15341: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15342: if (@newcustom) {
15343: map { $customadds{$_} = 1; } @newcustom;
15344: }
15345: foreach my $provider (sort(keys(%providernames))) {
15346: $confhash{$provider} = {};
15347: my $pos = $env{'form.proctoring_pos_'.$provider};
15348: $pos =~ s/\D+//g;
15349: $allpos[$pos] = $provider;
15350: my (%current,%currentenc);
15351: my $showroles = 0;
15352: if (ref($domconfig{$action}) eq 'HASH') {
15353: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15354: %current = %{$domconfig{$action}{$provider}};
15355: foreach my $item ('key','secret') {
15356: $currentenc{$item} = $current{$item};
15357: delete($current{$item});
15358: }
15359: }
15360: }
15361: if ($env{'form.proctoring_available_'.$provider}) {
15362: $confhash{$provider}{'available'} = 1;
15363: unless ($current{'available'}) {
15364: $changes{$provider} = 1;
15365: }
15366: } else {
15367: %{$confhash{$provider}} = %current;
15368: %{$encconfhash{$provider}} = %currentenc;
15369: $confhash{$provider}{'available'} = 0;
15370: if ($current{'available'}) {
15371: $changes{$provider} = 1;
15372: }
15373: }
15374: if ($confhash{$provider}{'available'}) {
15375: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15376: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15377: if ($field eq 'lifetime') {
15378: if ($possval =~ /^\d+$/) {
15379: $confhash{$provider}{$field} = $possval;
15380: }
15381: } elsif ($field eq 'version') {
15382: if ($possval =~ /^\d+\.\d+$/) {
15383: $confhash{$provider}{$field} = $possval;
15384: }
15385: } elsif ($field eq 'sigmethod') {
15386: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15387: $confhash{$provider}{$field} = $possval;
15388: }
15389: } elsif ($field eq 'url') {
15390: $confhash{$provider}{$field} = $possval;
15391: } elsif (($field eq 'key') || ($field eq 'secret')) {
15392: $encconfhash{$provider}{$field} = $possval;
15393: unless ($currentenc{$field} eq $possval) {
15394: $changes{$provider} = 1;
15395: }
15396: }
15397: unless (($field eq 'key') || ($field eq 'secret')) {
15398: unless ($current{$field} eq $confhash{$provider}{$field}) {
15399: $changes{$provider} = 1;
15400: }
15401: }
15402: }
15403: if ($imgdeletions{$provider}) {
15404: $changes{$provider} = 1;
15405: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15406: my ($imageurl,$error) =
15407: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15408: $configuserok,$switchserver,$author_ok);
15409: if ($imageurl) {
15410: $confhash{$provider}{'image'} = $imageurl;
15411: $changes{$provider} = 1;
15412: }
15413: if ($error) {
15414: &Apache::lonnet::logthis($error);
15415: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15416: }
15417: } elsif (exists($current{'image'})) {
15418: $confhash{$provider}{'image'} = $current{'image'};
15419: }
15420: if (ref($requserfields{$provider}) eq 'ARRAY') {
15421: if (@{$requserfields{$provider}} > 0) {
15422: if (grep(/^user$/,@{$requserfields{$provider}})) {
15423: if ($env{'form.proctoring_userincdom_'.$provider}) {
15424: $confhash{$provider}{'incdom'} = 1;
15425: }
15426: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15427: $changes{$provider} = 1;
15428: }
15429: }
15430: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15431: $showroles = 1;
15432: }
15433: }
15434: }
15435: $confhash{$provider}{'fields'} = [];
15436: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15437: if (@{$optuserfields{$provider}} > 0) {
15438: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15439: foreach my $field (@{$optuserfields{$provider}}) {
15440: if (grep(/^\Q$field\E$/,@optfields)) {
15441: push(@{$confhash{$provider}{'fields'}},$field);
15442: }
15443: }
15444: }
15445: if (ref($current{'fields'}) eq 'ARRAY') {
15446: unless ($changes{$provider}) {
15447: my @new = sort(@{$confhash{$provider}{'fields'}});
15448: my @old = sort(@{$current{'fields'}});
15449: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15450: if (@diffs) {
15451: $changes{$provider} = 1;
15452: }
15453: }
15454: } elsif (@{$confhash{$provider}{'fields'}}) {
15455: $changes{$provider} = 1;
15456: }
15457: }
15458: if (ref($defaults{$provider}) eq 'ARRAY') {
15459: if (@{$defaults{$provider}} > 0) {
15460: my %options;
15461: if (ref($extended{$provider}) eq 'HASH') {
15462: %options = %{$extended{$provider}};
15463: }
15464: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15465: foreach my $field (@{$defaults{$provider}}) {
15466: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15467: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15468: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15469: push(@{$confhash{$provider}{'defaults'}},$poss);
15470: }
15471: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15472: foreach my $inner (keys(%{$options{$field}})) {
15473: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15474: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15475: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15476: $confhash{$provider}{'defaults'}{$inner} = $poss;
15477: }
15478: } else {
15479: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15480: }
15481: }
15482: } else {
15483: if (grep(/^\Q$field\E$/,@checked)) {
15484: push(@{$confhash{$provider}{'defaults'}},$field);
15485: }
15486: }
15487: }
15488: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15489: if (ref($current{'defaults'}) eq 'ARRAY') {
15490: unless ($changes{$provider}) {
15491: my @new = sort(@{$confhash{$provider}{'defaults'}});
15492: my @old = sort(@{$current{'defaults'}});
15493: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15494: if (@diffs) {
15495: $changes{$provider} = 1;
15496: }
15497: }
15498: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15499: if (@{$current{'defaults'}}) {
15500: $changes{$provider} = 1;
15501: }
15502: }
15503: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15504: if (ref($current{'defaults'}) eq 'HASH') {
15505: unless ($changes{$provider}) {
15506: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15507: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15508: $changes{$provider} = 1;
15509: last;
15510: }
15511: }
15512: }
15513: unless ($changes{$provider}) {
15514: foreach my $key (keys(%{$current{'defaults'}})) {
15515: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15516: $changes{$provider} = 1;
15517: last;
15518: }
15519: }
15520: }
15521: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15522: $changes{$provider} = 1;
15523: }
15524: }
15525: }
15526: }
15527: if (ref($crsconf{$provider}) eq 'ARRAY') {
15528: if (@{$crsconf{$provider}} > 0) {
15529: $confhash{$provider}{'crsconf'} = [];
15530: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15531: foreach my $crsfield (@{$crsconf{$provider}}) {
15532: if (grep(/^\Q$crsfield\E$/,@checked)) {
15533: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15534: }
15535: }
15536: if (ref($current{'crsconf'}) eq 'ARRAY') {
15537: unless ($changes{$provider}) {
15538: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15539: my @old = sort(@{$current{'crsconf'}});
15540: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15541: if (@diffs) {
15542: $changes{$provider} = 1;
15543: }
15544: }
15545: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15546: $changes{$provider} = 1;
15547: }
15548: }
15549: }
15550: if ($showroles) {
15551: $confhash{$provider}{'roles'} = {};
15552: foreach my $role (@courseroles) {
15553: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15554: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15555: $confhash{$provider}{'roles'}{$role} = $poss;
15556: }
15557: }
15558: unless ($changes{$provider}) {
15559: if (ref($current{'roles'}) eq 'HASH') {
15560: foreach my $role (keys(%{$current{'roles'}})) {
15561: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15562: $changes{$provider} = 1;
15563: last
15564: }
15565: }
15566: unless ($changes{$provider}) {
15567: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15568: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15569: $changes{$provider} = 1;
15570: last;
15571: }
15572: }
15573: }
15574: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15575: $changes{$provider} = 1;
15576: }
15577: }
15578: }
15579: if (ref($current{'custom'}) eq 'HASH') {
15580: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15581: foreach my $key (keys(%{$current{'custom'}})) {
15582: if (grep(/^\Q$key\E$/,@customdels)) {
15583: $changes{$provider} = 1;
15584: } else {
15585: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15586: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15587: $changes{$provider} = 1;
15588: }
15589: }
15590: }
15591: }
15592: if ($customadds{$provider}) {
15593: my $name = $env{'form.proctoring_custom_name_'.$provider};
15594: $name =~ s/(`)/'/g;
15595: $name =~ s/^\s+//;
15596: $name =~ s/\s+$//;
15597: my $value = $env{'form.proctoring_custom_value_'.$provider};
15598: $value =~ s/(`)/'/g;
15599: $value =~ s/^\s+//;
15600: $value =~ s/\s+$//;
15601: if ($name ne '') {
15602: $confhash{$provider}{'custom'}{$name} = $value;
15603: $changes{$provider} = 1;
15604: }
15605: }
15606: }
15607: }
15608: if (@allpos > 0) {
15609: my $idx = 0;
15610: foreach my $provider (@allpos) {
15611: if ($provider ne '') {
15612: $confhash{$provider}{'order'} = $idx;
15613: unless ($changes{$provider}) {
15614: if (ref($domconfig{$action}) eq 'HASH') {
15615: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15616: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15617: $changes{$provider} = 1;
15618: }
15619: }
15620: }
15621: }
15622: $idx ++;
15623: }
15624: }
15625: }
15626: my %proc_hash = (
15627: $action => { %confhash }
15628: );
15629: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15630: $dom);
15631: if ($putresult eq 'ok') {
15632: my %proc_enchash = (
15633: $action => { %encconfhash }
15634: );
1.384 raeburn 15635: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15636: if (keys(%changes) > 0) {
15637: my $cachetime = 24*60*60;
15638: my %procall = %confhash;
15639: foreach my $provider (keys(%procall)) {
15640: if (ref($encconfhash{$provider}) eq 'HASH') {
15641: foreach my $key ('key','secret') {
15642: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15643: }
15644: }
15645: }
15646: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15647: if (ref($lastactref) eq 'HASH') {
15648: $lastactref->{'proctoring'} = 1;
15649: }
15650: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15651: my %bynum;
15652: foreach my $provider (sort(keys(%changes))) {
15653: my $position = $confhash{$provider}{'order'};
15654: $bynum{$position} = $provider;
15655: }
15656: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15657: my $provider = $bynum{$pos};
15658: my %lt = &proctoring_titles($provider);
15659: my %fieldtitles = &proctoring_fieldtitles($provider);
15660: if (!$confhash{$provider}{'available'}) {
15661: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15662: } else {
15663: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15664: if ($confhash{$provider}{'image'}) {
15665: $resulttext .= ' '.
15666: '<img src="'.$confhash{$provider}{'image'}.'"'.
15667: ' alt="'.&mt('Proctoring icon').'" />';
15668: }
15669: $resulttext .= '<ul>';
15670: my $position = $pos + 1;
15671: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15672: foreach my $key ('version','sigmethod','url','lifetime') {
15673: if ($confhash{$provider}{$key} ne '') {
15674: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15675: }
15676: }
15677: if ($encconfhash{$provider}{'key'} ne '') {
15678: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15679: }
15680: if ($encconfhash{$provider}{'secret'} ne '') {
15681: $resulttext .= '<li>'.$lt{'secret'}.': ';
15682: my $num = length($encconfhash{$provider}{'secret'});
15683: $resulttext .= ('*'x$num).'</li>';
15684: }
15685: my (@fields,$showroles);
15686: if (ref($requserfields{$provider}) eq 'ARRAY') {
15687: push(@fields,@{$requserfields{$provider}});
15688: }
15689: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15690: push(@fields,@{$confhash{$provider}{'fields'}});
15691: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15692: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15693: }
15694: if (@fields) {
15695: if (grep(/^roles$/,@fields)) {
15696: $showroles = 1;
15697: }
15698: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15699: join('", "', map { $lt{$_}; } @fields).'"</li>';
15700: }
15701: if (ref($requserfields{$provider}) eq 'ARRAY') {
15702: if (grep(/^user$/,@{$requserfields{$provider}})) {
15703: if ($confhash{$provider}{'incdom'}) {
15704: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15705: } else {
15706: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15707: }
15708: }
15709: }
15710: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15711: if (@{$confhash{$provider}{'defaults'}} > 0) {
15712: $resulttext .= '<li>'.$lt{'defa'};
15713: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15714: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15715: }
15716: $resulttext =~ s/,$//;
15717: $resulttext .= '</li>';
15718: }
15719: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15720: if (keys(%{$confhash{$provider}{'defaults'}})) {
15721: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15722: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15723: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15724: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15725: }
15726: }
15727: $resulttext .= '</ul></li>';
15728: }
15729: }
15730: if (ref($crsconf{$provider}) eq 'ARRAY') {
15731: if (@{$crsconf{$provider}} > 0) {
15732: $resulttext .= '<li>'.&mt('Configurable in course:');
15733: my $numconfig = 0;
15734: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15735: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15736: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15737: $numconfig ++;
15738: if ($provider eq 'examity') {
15739: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15740: } else {
15741: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15742: }
15743: }
15744: $resulttext =~ s/,$//;
15745: }
15746: }
15747: if (!$numconfig) {
15748: $resulttext .= ' '.&mt('None');
15749: }
15750: $resulttext .= '</li>';
15751: }
15752: }
15753: if ($showroles) {
15754: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15755: my $rolemaps;
15756: foreach my $role (@courseroles) {
15757: if ($confhash{$provider}{'roles'}{$role}) {
15758: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15759: $confhash{$provider}{'roles'}{$role}.',';
15760: }
15761: }
15762: if ($rolemaps) {
15763: $rolemaps =~ s/,$//;
15764: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15765: }
15766: }
15767: }
15768: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15769: my $customlist;
15770: if (keys(%{$confhash{$provider}{'custom'}})) {
15771: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15772: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15773: }
15774: $customlist =~ s/,$//;
15775: }
15776: if ($customlist) {
15777: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15778: }
15779: }
15780: $resulttext .= '</ul></li>';
15781: }
15782: }
15783: $resulttext .= '</ul>';
15784: } else {
15785: $resulttext = &mt('No changes made.');
15786: }
15787: } else {
15788: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15789: }
15790: if ($errors) {
15791: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15792: $errors.'</ul>';
15793: }
15794: return $resulttext;
15795: }
15796:
15797: sub process_proctoring_image {
15798: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15799: my $filename = $env{'form.'.$caller.'.filename'};
15800: my ($error,$url);
15801: my ($width,$height) = (21,21);
15802: if ($configuserok eq 'ok') {
15803: if ($switchserver) {
15804: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15805: $switchserver);
15806: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15807: my $modified = [];
1.372 raeburn 15808: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15809: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15810: "proctoring/$provider/icon",$width,$height,
15811: '',$modified);
1.372 raeburn 15812: if ($result eq 'ok') {
15813: if ($madethumb) {
15814: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15815: my $imagethumb = "$path/tn-".$imagefile;
15816: $url = $imagethumb;
15817: } else {
15818: $url = $imageurl;
15819: }
1.421 raeburn 15820: &update_modify_urls($r,$modified);
1.372 raeburn 15821: } else {
15822: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15823: }
15824: } else {
15825: $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);
15826: }
15827: } else {
15828: $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);
15829: }
15830: return ($url,$error);
15831: }
15832:
1.320 raeburn 15833: sub modify_lti {
15834: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15835: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15836: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15837: my (%posslti,%posslticrs,%posscrstype);
15838: my @courseroles = ('cc','in','ta','ep','st');
15839: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15840: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15841: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15842: my %coursetypetitles = &Apache::lonlocal::texthash (
15843: official => 'Official',
15844: unofficial => 'Unofficial',
15845: community => 'Community',
15846: textbook => 'Textbook',
15847: placement => 'Placement Test',
1.392 raeburn 15848: lti => 'LTI Provider',
1.320 raeburn 15849: );
1.325 raeburn 15850: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15851: my %lt = <i_names();
15852: map { $posslti{$_} = 1; } @ltiroles;
15853: map { $posslticrs{$_} = 1; } @lticourseroles;
15854: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15855:
1.326 raeburn 15856: my %menutitles = <imenu_titles();
1.421 raeburn 15857: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15858:
1.421 raeburn 15859: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15860:
1.406 raeburn 15861: my (%linkprotchg,$linkprotoutput,$is_home);
15862: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15863: \%linkprotchg,'domain');
15864: my $home = &Apache::lonnet::domain($dom,'primary');
15865: unless (($home eq 'no_host') || ($home eq '')) {
15866: my @ids=&Apache::lonnet::current_machine_ids();
15867: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15868: }
15869:
15870: if (keys(%linkprotchg)) {
15871: $secchanges{'linkprot'} = 1;
15872: my %oldlinkprot;
15873: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15874: %oldlinkprot = %{$currltisec{'linkprot'}};
15875: }
15876: foreach my $id (keys(%linkprotchg)) {
15877: if (ref($linkprotchg{$id}) eq 'HASH') {
15878: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15879: if (($inner eq 'secret') || ($inner eq 'key')) {
15880: if ($is_home) {
15881: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15882: }
15883: }
15884: }
15885: } else {
15886: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15887: }
15888: }
15889: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15890: if (keys(%linkprotchg)) {
15891: %{$newltisec{'linkprot'}} = %linkprotchg;
15892: }
15893: }
15894: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15895: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15896: next if ($id !~ /^\d+$/);
15897: unless (exists($linkprotchg{$id})) {
15898: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15899: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15900: if (($inner eq 'secret') || ($inner eq 'key')) {
15901: if ($is_home) {
15902: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15903: }
15904: } else {
15905: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15906: }
15907: }
15908: } else {
15909: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15910: }
15911: }
15912: }
15913: }
15914: if ($proterror) {
15915: $errors .= '<li>'.$proterror.'</li>';
15916: }
1.434 raeburn 15917:
15918: my (%delsuggested,%suggids,@suggested);;
15919: if (ref($currltisec{'suggested'}) eq 'HASH') {
15920: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15921: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15922: for (my $i=0; $i<$maxnum; $i++) {
15923: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15924: $itemid =~ s/\D+//g;
15925: if ($itemid) {
15926: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15927: push(@suggested,$i);
15928: $suggids{$i} = $itemid;
15929: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15930: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15931: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15932: }
15933: } else {
15934: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15935: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15936: } else {
15937: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15938: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15939: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15940: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15941: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15942: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15943: $secchanges{'suggested'}{$itemid} = 1;
15944: }
15945: }
15946: }
15947: }
15948: }
15949: }
15950: }
15951: foreach my $key (keys(%delsuggested)) {
15952: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15953: $secchanges{'suggested'}{$key} = 1;
15954: }
15955: if (($env{'form.linkprot_suggested_add'}) &&
15956: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15957: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15958: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15959: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15960: if ($newsuggid) {
15961: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15962: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15963: $secchanges{'suggested'}{$newsuggid} = 1;
15964: } else {
15965: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15966: if ($errormsg) {
15967: $error .= ' ('.$errormsg.')';
15968: }
15969: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15970: }
15971: }
1.320 raeburn 15972: my (@items,%deletions,%itemids);
15973: if ($env{'form.lti_add'}) {
15974: my $consumer = $env{'form.lti_consumer_add'};
15975: $consumer =~ s/(`)/'/g;
1.434 raeburn 15976: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15977: if ($newid) {
15978: $itemids{'add'} = $newid;
15979: push(@items,'add');
15980: $changes{$newid} = 1;
15981: } else {
15982: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15983: if ($errormsg) {
15984: $error .= ' ('.$errormsg.')';
15985: }
1.320 raeburn 15986: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15987: }
15988: }
15989: if (ref($domconfig{$action}) eq 'HASH') {
15990: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15991: if (@todelete) {
15992: map { $deletions{$_} = 1; } @todelete;
15993: }
15994: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 15995: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 15996: my $itemid = $env{'form.lti_id_'.$i};
15997: $itemid =~ s/\D+//g;
15998: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
15999: if ($deletions{$itemid}) {
16000: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16001: } else {
1.390 raeburn 16002: push(@items,$i);
16003: $itemids{$i} = $itemid;
1.320 raeburn 16004: }
16005: }
16006: }
16007: }
1.424 raeburn 16008: my (%keystore,$secstored);
16009: if ($is_home) {
16010: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16011: }
16012:
16013: my ($cipher,$privnum);
16014: if ((@items > 0) && ($is_home)) {
16015: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16016: $newltisec{'encrypt'},$keystore{$home});
16017: }
1.320 raeburn 16018: foreach my $idx (@items) {
16019: my $itemid = $itemids{$idx};
16020: next unless ($itemid);
1.424 raeburn 16021: my %currlti;
16022: unless ($idx eq 'add') {
16023: if (ref($domconfig{$action}) eq 'HASH') {
16024: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16025: %currlti = %{$domconfig{$action}{$itemid}};
16026: }
16027: }
16028: }
1.390 raeburn 16029: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16030: $position =~ s/\D+//g;
16031: if ($position ne '') {
16032: $allpos[$position] = $itemid;
16033: }
1.424 raeburn 16034: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16035: my $formitem = 'form.lti_'.$item.'_'.$idx;
16036: $env{$formitem} =~ s/(`)/'/g;
16037: if ($item eq 'lifetime') {
16038: $env{$formitem} =~ s/[^\d.]//g;
16039: }
16040: if ($env{$formitem} ne '') {
1.424 raeburn 16041: $confhash{$itemid}{$item} = $env{$formitem};
16042: unless (($idx eq 'add') || ($changes{$itemid})) {
16043: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16044: $changes{$itemid} = 1;
1.320 raeburn 16045: }
16046: }
16047: }
16048: }
16049: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16050: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16051: }
1.345 raeburn 16052: if ($confhash{$itemid}{'requser'}) {
16053: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16054: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16055: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16056: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16057: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16058: my $mapuser = $env{'form.lti_customuser_'.$idx};
16059: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16060: $mapuser =~ s/^\s+|\s+$//g;
16061: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16062: }
16063: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16064: my @makeuser;
16065: foreach my $ltirole (sort(@possmakeuser)) {
16066: if ($posslti{$ltirole}) {
16067: push(@makeuser,$ltirole);
16068: }
16069: }
16070: $confhash{$itemid}{'makeuser'} = \@makeuser;
16071: if (@makeuser) {
16072: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16073: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16074: $confhash{$itemid}{'lcauth'} = $lcauth;
16075: if ($lcauth ne 'internal') {
16076: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16077: $lcauthparm =~ s/^(\s+|\s+)$//g;
16078: $lcauthparm =~ s/`//g;
16079: if ($lcauthparm ne '') {
16080: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16081: }
16082: }
16083: } else {
16084: $confhash{$itemid}{'lcauth'} = 'lti';
16085: }
1.320 raeburn 16086: }
1.345 raeburn 16087: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16088: if (@possinstdata) {
16089: foreach my $field (@possinstdata) {
16090: if (exists($fieldtitles{$field})) {
16091: push(@{$confhash{$itemid}{'instdata'}});
1.325 raeburn 16092: }
16093: }
16094: }
1.363 raeburn 16095: if ($env{'form.lti_callback_'.$idx}) {
16096: if ($env{'form.lti_callbackparam_'.$idx}) {
16097: my $callback = $env{'form.lti_callbackparam_'.$idx};
16098: $callback =~ s/^\s+|\s+$//g;
16099: $confhash{$itemid}{'callback'} = $callback;
16100: }
16101: }
1.391 raeburn 16102: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16103: if ($env{'form.lti_'.$field.'_'.$idx}) {
16104: $confhash{$itemid}{$field} = 1;
16105: }
1.320 raeburn 16106: }
1.345 raeburn 16107: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16108: $confhash{$itemid}{lcmenu} = [];
16109: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16110: foreach my $field (@possmenu) {
16111: if (exists($menutitles{$field})) {
16112: if ($field eq 'grades') {
16113: next unless ($env{'form.lti_inlinemenu_'.$idx});
16114: }
16115: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16116: }
16117: }
16118: }
1.391 raeburn 16119: if ($confhash{$itemid}{'crsinc'}) {
16120: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16121: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16122: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16123: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16124: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16125: $mapcrs =~ s/(`)/'/g;
16126: $mapcrs =~ s/^\s+|\s+$//g;
16127: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16128: }
16129: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16130: my @crstypes;
16131: foreach my $type (sort(@posstypes)) {
16132: if ($posscrstype{$type}) {
16133: push(@crstypes,$type);
16134: }
16135: }
16136: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16137: if ($env{'form.lti_storecrs_'.$idx}) {
16138: $confhash{$itemid}{'storecrs'} = 1;
16139: }
1.391 raeburn 16140: if ($env{'form.lti_makecrs_'.$idx}) {
16141: $confhash{$itemid}{'makecrs'} = 1;
16142: }
16143: foreach my $ltirole (@lticourseroles) {
16144: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16145: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16146: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16147: }
16148: }
16149: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16150: my @selfenroll;
16151: foreach my $type (sort(@possenroll)) {
16152: if ($posslticrs{$type}) {
16153: push(@selfenroll,$type);
16154: }
16155: }
16156: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16157: if ($env{'form.lti_crssec_'.$idx}) {
16158: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16159: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16160: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16161: my $section = $env{'form.lti_customsection_'.$idx};
16162: $section =~ s/(`)/'/g;
16163: $section =~ s/^\s+|\s+$//g;
16164: if ($section ne '') {
16165: $confhash{$itemid}{'section'} = $section;
16166: }
16167: }
16168: }
16169: foreach my $field ('passback','roster') {
16170: if ($env{'form.lti_'.$field.'_'.$idx}) {
16171: $confhash{$itemid}{$field} = 1;
16172: }
16173: }
16174: if ($env{'form.lti_passback_'.$idx}) {
16175: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16176: $confhash{$itemid}{'passbackformat'} = '1.0';
16177: } else {
16178: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16179: }
16180: }
1.391 raeburn 16181: }
16182: unless (($idx eq 'add') || ($changes{$itemid})) {
16183: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16184: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16185: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16186: $changes{$itemid} = 1;
16187: }
1.345 raeburn 16188: }
16189: unless ($changes{$itemid}) {
1.424 raeburn 16190: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16191: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16192: $changes{$itemid} = 1;
16193: }
16194: }
1.345 raeburn 16195: }
1.391 raeburn 16196: foreach my $field ('mapcrstype','selfenroll') {
16197: unless ($changes{$itemid}) {
1.424 raeburn 16198: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16199: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16200: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16201: $confhash{$itemid}{$field});
16202: if (@diffs) {
16203: $changes{$itemid} = 1;
16204: }
1.424 raeburn 16205: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16206: $changes{$itemid} = 1;
16207: }
16208: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16209: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16210: $changes{$itemid} = 1;
16211: }
16212: }
1.391 raeburn 16213: }
16214: }
16215: unless ($changes{$itemid}) {
1.424 raeburn 16216: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16217: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16218: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16219: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16220: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16221: $changes{$itemid} = 1;
16222: last;
16223: }
16224: }
1.391 raeburn 16225: unless ($changes{$itemid}) {
16226: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16227: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16228: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16229: $changes{$itemid} = 1;
16230: last;
16231: }
16232: }
16233: }
1.424 raeburn 16234: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16235: $changes{$itemid} = 1;
1.345 raeburn 16236: }
1.391 raeburn 16237: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16238: unless ($changes{$itemid}) {
16239: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16240: $changes{$itemid} = 1;
16241: }
16242: }
16243: }
16244: }
16245: }
16246: unless ($changes{$itemid}) {
16247: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16248: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16249: $changes{$itemid} = 1;
1.320 raeburn 16250: }
1.391 raeburn 16251: }
16252: unless ($changes{$itemid}) {
16253: foreach my $field ('makeuser','lcmenu') {
1.424 raeburn 16254: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16255: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16256: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16257: $confhash{$itemid}{$field});
16258: if (@diffs) {
16259: $changes{$itemid} = 1;
16260: }
1.424 raeburn 16261: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16262: $changes{$itemid} = 1;
16263: }
16264: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16265: if (@{$confhash{$itemid}{$field}} > 0) {
16266: $changes{$itemid} = 1;
16267: }
1.345 raeburn 16268: }
1.320 raeburn 16269: }
16270: }
16271: }
16272: }
16273: }
1.424 raeburn 16274: if ($is_home) {
16275: my $keyitem = 'form.lti_key_'.$idx;
16276: $env{$keyitem} =~ s/(`)/'/g;
16277: if ($env{$keyitem} ne '') {
16278: $ltienc{$itemid}{'key'} = $env{$keyitem};
16279: unless ($changes{$itemid}) {
16280: if ($currlti{'key'} ne $env{$keyitem}) {
16281: $changes{$itemid} = 1;
16282: }
16283: }
16284: }
16285: my $secretitem = 'form.lti_secret_'.$idx;
16286: $env{$secretitem} =~ s/(`)/'/g;
16287: if ($currlti{'usable'}) {
16288: if ($env{'form.lti_changesecret_'.$idx}) {
16289: if ($env{$secretitem} ne '') {
16290: if ($privnum && $cipher) {
16291: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16292: $confhash{$itemid}{'cipher'} = $privnum;
16293: } else {
16294: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16295: }
16296: $changes{$itemid} = 1;
16297: }
16298: } else {
16299: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16300: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16301: }
16302: if (ref($ltienc{$itemid}) eq 'HASH') {
16303: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16304: $confhash{$itemid}{'usable'} = 1;
16305: }
16306: }
16307: } elsif ($env{$secretitem} ne '') {
16308: if ($privnum && $cipher) {
16309: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16310: $confhash{$itemid}{'cipher'} = $privnum;
16311: } else {
16312: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16313: }
16314: if (ref($ltienc{$itemid}) eq 'HASH') {
16315: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16316: $confhash{$itemid}{'usable'} = 1;
16317: }
16318: }
16319: $changes{$itemid} = 1;
16320: }
16321: }
16322: unless ($changes{$itemid}) {
16323: foreach my $key (keys(%currlti)) {
16324: if (ref($currlti{$key}) eq 'HASH') {
16325: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16326: foreach my $innerkey (keys(%{$currlti{$key}})) {
16327: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16328: $changes{$itemid} = 1;
16329: last;
16330: }
16331: }
16332: } elsif (keys(%{$currlti{$key}}) > 0) {
16333: $changes{$itemid} = 1;
16334: }
16335: }
16336: last if ($changes{$itemid});
16337: }
16338: }
1.320 raeburn 16339: }
16340: if (@allpos > 0) {
16341: my $idx = 0;
16342: foreach my $itemid (@allpos) {
16343: if ($itemid ne '') {
16344: $confhash{$itemid}{'order'} = $idx;
16345: if (ref($domconfig{$action}) eq 'HASH') {
16346: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16347: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16348: $changes{$itemid} = 1;
16349: }
16350: }
16351: }
16352: $idx ++;
16353: }
16354: }
16355: }
1.424 raeburn 16356:
16357: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16358: return &mt('No changes made.');
16359: }
16360:
1.320 raeburn 16361: my %ltihash = (
1.405 raeburn 16362: $action => { %confhash }
16363: );
1.424 raeburn 16364: my %ltienchash;
16365:
16366: if ($is_home) {
16367: %ltienchash = (
16368: $action => { %ltienc }
16369: );
16370: }
1.405 raeburn 16371: if (keys(%secchanges)) {
16372: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16373: if ($secchanges{'linkprot'}) {
16374: if ($is_home) {
16375: $ltienchash{'linkprot'} = \%newltienc;
16376: }
16377: }
1.405 raeburn 16378: }
16379: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16380: if ($putresult eq 'ok') {
1.424 raeburn 16381: if (keys(%ltienchash)) {
16382: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16383: }
16384: $resulttext = &mt('Changes made:').'<ul>';
16385: if (keys(%secchanges) > 0) {
1.423 raeburn 16386: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16387: if (exists($secchanges{'linkprot'})) {
16388: $resulttext .= $linkprotoutput;
1.405 raeburn 16389: }
16390: }
1.320 raeburn 16391: if (keys(%changes) > 0) {
16392: my $cachetime = 24*60*60;
1.424 raeburn 16393: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16394: if (ref($lastactref) eq 'HASH') {
16395: $lastactref->{'lti'} = 1;
16396: }
16397: my %bynum;
16398: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16399: if (ref($confhash{$itemid}) eq 'HASH') {
16400: my $position = $confhash{$itemid}{'order'};
16401: $bynum{$position} = $itemid;
16402: }
1.320 raeburn 16403: }
16404: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16405: my $itemid = $bynum{$pos};
1.424 raeburn 16406: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16407: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16408: my $position = $pos + 1;
16409: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16410: foreach my $item ('version','lifetime') {
16411: if ($confhash{$itemid}{$item} ne '') {
16412: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16413: }
16414: }
1.424 raeburn 16415: if ($ltienc{$itemid}{'key'} ne '') {
16416: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16417: }
1.424 raeburn 16418: if ($ltienc{$itemid}{'secret'} ne '') {
16419: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16420: }
1.345 raeburn 16421: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16422: if ($confhash{$itemid}{'callback'}) {
16423: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16424: } else {
1.392 raeburn 16425: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16426: }
1.345 raeburn 16427: if ($confhash{$itemid}{'mapuser'}) {
16428: my $shownmapuser;
16429: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16430: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16431: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16432: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16433: } else {
16434: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16435: }
1.345 raeburn 16436: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16437: }
1.345 raeburn 16438: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16439: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16440: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16441: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16442: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16443: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16444: } else {
16445: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16446: $confhash{$itemid}{'lcauth'});
16447: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16448: $resulttext .= '; '.&mt('a randomly generated password will be created');
16449: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16450: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16451: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16452: }
16453: } else {
16454: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16455: }
16456: }
16457: $resulttext .= '</li>';
16458: } else {
16459: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16460: }
1.320 raeburn 16461: }
1.345 raeburn 16462: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16463: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16464: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16465: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16466: } else {
1.345 raeburn 16467: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1.325 raeburn 16468: }
1.320 raeburn 16469: }
1.391 raeburn 16470: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16471: $resulttext .= '<li>'.$lt{$item}.': ';
16472: if ($confhash{$itemid}{$item}) {
16473: $resulttext .= &mt('Yes');
16474: } else {
16475: $resulttext .= &mt('No');
1.337 raeburn 16476: }
1.345 raeburn 16477: $resulttext .= '</li>';
1.320 raeburn 16478: }
1.345 raeburn 16479: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16480: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16481: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16482: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16483: } else {
16484: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16485: }
16486: }
16487: if ($confhash{$itemid}{'crsinc'}) {
16488: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16489: my $rolemaps;
16490: foreach my $role (@ltiroles) {
16491: if ($confhash{$itemid}{'maproles'}{$role}) {
16492: $rolemaps .= (' 'x2).$role.'='.
16493: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16494: 'Course').',';
16495: }
16496: }
16497: if ($rolemaps) {
16498: $rolemaps =~ s/,$//;
16499: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16500: }
16501: }
16502: if ($confhash{$itemid}{'mapcrs'}) {
16503: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16504: }
16505: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16506: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16507: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16508: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16509: '</li>';
16510: } else {
16511: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16512: }
16513: }
1.392 raeburn 16514: if ($confhash{$itemid}{'storecrs'}) {
16515: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16516: }
1.391 raeburn 16517: if ($confhash{$itemid}{'makecrs'}) {
16518: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16519: } else {
16520: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16521: }
16522: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16523: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16524: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16525: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16526: '</li>';
16527: } else {
16528: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16529: }
16530: }
16531: if ($confhash{$itemid}{'section'}) {
16532: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16533: $resulttext .= '<li>'.&mt('User section from standard field:').
16534: ' (course_section_sourcedid)'.'</li>';
16535: } else {
16536: $resulttext .= '<li>'.&mt('User section from:').' '.
16537: $confhash{$itemid}{'section'}.'</li>';
16538: }
1.345 raeburn 16539: } else {
1.391 raeburn 16540: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16541: }
16542: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16543: $resulttext .= '<li>'.$lt{$item}.': ';
16544: if ($confhash{$itemid}{$item}) {
16545: $resulttext .= &mt('Yes');
16546: if ($item eq 'passback') {
16547: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16548: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16549: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16550: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16551: }
16552: }
16553: } else {
16554: $resulttext .= &mt('No');
16555: }
16556: $resulttext .= '</li>';
16557: }
16558: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16559: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16560: $resulttext .= '<li>'.&mt('Menu items:').' '.
16561: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16562: } else {
16563: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16564: }
1.345 raeburn 16565: }
1.326 raeburn 16566: }
16567: }
1.320 raeburn 16568: $resulttext .= '</ul></li>';
16569: }
16570: }
1.424 raeburn 16571: if (keys(%deletions)) {
16572: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16573: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16574: }
16575: }
1.320 raeburn 16576: }
1.405 raeburn 16577: $resulttext .= '</ul>';
1.424 raeburn 16578: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16579: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16580: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16581: $lastactref->{'domdefaults'} = 1;
16582: }
16583: }
1.320 raeburn 16584: } else {
16585: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16586: }
16587: if ($errors) {
16588: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16589: $errors.'</ul>';
16590: }
16591: return $resulttext;
16592: }
16593:
1.424 raeburn 16594: sub get_priv_creds {
16595: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16596: my ($needenc,$cipher,$privnum);
16597: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16598: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16599: $needenc = $encrypt->{'consumers'}
16600: } else {
16601: $needenc = $domdefs{'ltienc_consumers'};
16602: }
16603: if ($needenc) {
16604: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16605: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16606: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16607: my $privkey = $privhash{'key'};
16608: $privnum = $privhash{'version'};
16609: if (($privnum) && ($privkey ne '')) {
16610: $cipher = Crypt::CBC->new({'key' => $privkey,
16611: 'cipher' => 'DES'});
16612: }
16613: }
16614: }
16615: return ($cipher,$privnum);
16616: }
16617:
1.320 raeburn 16618: sub get_lti_id {
1.434 raeburn 16619: my ($domain,$consumer,$dbname) = @_;
16620: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16621: return ('','invalid db');
16622: }
16623: # get lock on db
1.320 raeburn 16624: my $lockhash = {
16625: lock => $env{'user.name'}.
16626: ':'.$env{'user.domain'},
16627: };
16628: my $tries = 0;
1.434 raeburn 16629: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16630: my ($id,$error);
16631:
16632: while (($gotlock ne 'ok') && ($tries<10)) {
16633: $tries ++;
16634: sleep (0.1);
1.434 raeburn 16635: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16636: }
16637: if ($gotlock eq 'ok') {
1.434 raeburn 16638: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16639: if ($currids{'lock'}) {
16640: delete($currids{'lock'});
16641: if (keys(%currids)) {
16642: my @curr = sort { $a <=> $b } keys(%currids);
16643: if ($curr[-1] =~ /^\d+$/) {
16644: $id = 1 + $curr[-1];
16645: }
16646: } else {
16647: $id = 1;
16648: }
16649: if ($id) {
1.434 raeburn 16650: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16651: $error = 'nostore';
16652: }
16653: } else {
16654: $error = 'nonumber';
16655: }
16656: }
1.434 raeburn 16657: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16658: } else {
16659: $error = 'nolock';
16660: }
16661: return ($id,$error);
16662: }
16663:
1.3 raeburn 16664: sub modify_autoenroll {
1.205 raeburn 16665: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16666: my ($resulttext,%changes);
16667: my %currautoenroll;
16668: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16669: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16670: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16671: }
16672: }
16673: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16674: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16675: sender => 'Sender for notification messages',
1.274 raeburn 16676: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16677: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16678: my @offon = ('off','on');
1.17 raeburn 16679: my $sender_uname = $env{'form.sender_uname'};
16680: my $sender_domain = $env{'form.sender_domain'};
16681: if ($sender_domain eq '') {
16682: $sender_uname = '';
16683: } elsif ($sender_uname eq '') {
16684: $sender_domain = '';
16685: }
1.129 raeburn 16686: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16687: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16688: $autofailsafe =~ s{^\s+|\s+$}{}g;
16689: if ($autofailsafe =~ /\D/) {
16690: undef($autofailsafe);
16691: }
1.274 raeburn 16692: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16693: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16694: $failsafe = 'off';
1.400 raeburn 16695: undef($autofailsafe);
1.274 raeburn 16696: }
1.1 raeburn 16697: my %autoenrollhash = (
1.129 raeburn 16698: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16699: 'sender_uname' => $sender_uname,
16700: 'sender_domain' => $sender_domain,
16701: 'co-owners' => $coowners,
1.399 raeburn 16702: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16703: 'failsafe' => $failsafe,
1.1 raeburn 16704: }
16705: );
1.4 raeburn 16706: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16707: $dom);
1.1 raeburn 16708: if ($putresult eq 'ok') {
16709: if (exists($currautoenroll{'run'})) {
16710: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16711: $changes{'run'} = 1;
16712: }
16713: } elsif ($autorun) {
16714: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16715: $changes{'run'} = 1;
1.1 raeburn 16716: }
16717: }
1.17 raeburn 16718: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16719: $changes{'sender'} = 1;
16720: }
1.17 raeburn 16721: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16722: $changes{'sender'} = 1;
16723: }
1.129 raeburn 16724: if ($currautoenroll{'co-owners'} ne '') {
16725: if ($currautoenroll{'co-owners'} ne $coowners) {
16726: $changes{'coowners'} = 1;
16727: }
16728: } elsif ($coowners) {
16729: $changes{'coowners'} = 1;
1.274 raeburn 16730: }
1.399 raeburn 16731: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16732: $changes{'autofailsafe'} = 1;
16733: }
1.399 raeburn 16734: if ($currautoenroll{'failsafe'} ne $failsafe) {
16735: $changes{'failsafe'} = 1;
16736: }
1.1 raeburn 16737: if (keys(%changes) > 0) {
16738: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16739: if ($changes{'run'}) {
1.1 raeburn 16740: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16741: }
16742: if ($changes{'sender'}) {
1.17 raeburn 16743: if ($sender_uname eq '' || $sender_domain eq '') {
16744: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16745: } else {
16746: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16747: }
1.1 raeburn 16748: }
1.129 raeburn 16749: if ($changes{'coowners'}) {
16750: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16751: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16752: if (ref($lastactref) eq 'HASH') {
16753: $lastactref->{'domainconfig'} = 1;
16754: }
1.129 raeburn 16755: }
1.274 raeburn 16756: if ($changes{'autofailsafe'}) {
1.399 raeburn 16757: if ($autofailsafe ne '') {
16758: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16759: } else {
1.399 raeburn 16760: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16761: }
1.399 raeburn 16762: }
16763: if ($changes{'failsafe'}) {
16764: if ($failsafe eq 'off') {
16765: unless ($changes{'autofailsafe'}) {
16766: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16767: }
16768: } elsif ($failsafe eq 'zero') {
16769: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16770: } else {
16771: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16772: }
16773: }
16774: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16775: &Apache::lonnet::get_domain_defaults($dom,1);
16776: if (ref($lastactref) eq 'HASH') {
16777: $lastactref->{'domdefaults'} = 1;
16778: }
16779: }
1.1 raeburn 16780: $resulttext .= '</ul>';
16781: } else {
16782: $resulttext = &mt('No changes made to auto-enrollment settings');
16783: }
16784: } else {
1.11 albertel 16785: $resulttext = '<span class="LC_error">'.
16786: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16787: }
1.3 raeburn 16788: return $resulttext;
1.1 raeburn 16789: }
16790:
16791: sub modify_autoupdate {
1.3 raeburn 16792: my ($dom,%domconfig) = @_;
1.1 raeburn 16793: my ($resulttext,%currautoupdate,%fields,%changes);
16794: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16795: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16796: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16797: }
16798: }
16799: my @offon = ('off','on');
16800: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16801: run => 'Auto-update:',
16802: classlists => 'Updates to user information in classlists?',
16803: unexpired => 'Skip updates for users without active or future roles?',
16804: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16805: );
1.44 raeburn 16806: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16807: my %fieldtitles = &Apache::lonlocal::texthash (
16808: id => 'Student/Employee ID',
1.20 raeburn 16809: permanentemail => 'E-mail address',
1.1 raeburn 16810: lastname => 'Last Name',
16811: firstname => 'First Name',
16812: middlename => 'Middle Name',
1.132 raeburn 16813: generation => 'Generation',
1.1 raeburn 16814: );
1.142 raeburn 16815: $othertitle = &mt('All users');
1.1 raeburn 16816: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16817: $othertitle = &mt('Other users');
1.1 raeburn 16818: }
16819: foreach my $key (keys(%env)) {
16820: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16821: my ($usertype,$item) = ($1,$2);
16822: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16823: if ($usertype eq 'default') {
16824: push(@{$fields{$1}},$2);
16825: } elsif (ref($types) eq 'ARRAY') {
16826: if (grep(/^\Q$usertype\E$/,@{$types})) {
16827: push(@{$fields{$1}},$2);
16828: }
16829: }
16830: }
1.1 raeburn 16831: }
16832: }
1.131 raeburn 16833: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16834: @lockablenames = sort(@lockablenames);
16835: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16836: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16837: if (@changed) {
16838: $changes{'lockablenames'} = 1;
16839: }
16840: } else {
16841: if (@lockablenames) {
16842: $changes{'lockablenames'} = 1;
16843: }
16844: }
1.1 raeburn 16845: my %updatehash = (
16846: autoupdate => { run => $env{'form.autoupdate_run'},
16847: classlists => $env{'form.classlists'},
1.385 raeburn 16848: unexpired => $env{'form.unexpired'},
1.1 raeburn 16849: fields => {%fields},
1.131 raeburn 16850: lockablenames => \@lockablenames,
1.1 raeburn 16851: }
16852: );
1.385 raeburn 16853: my $lastactivedays;
16854: if ($env{'form.lastactive'}) {
16855: $lastactivedays = $env{'form.lastactivedays'};
16856: $lastactivedays =~ s/^\s+|\s+$//g;
16857: unless ($lastactivedays =~ /^\d+$/) {
16858: undef($lastactivedays);
16859: $env{'form.lastactive'} = 0;
16860: }
16861: }
16862: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16863: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16864: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16865: if (exists($updatehash{autoupdate}{$key})) {
16866: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16867: $changes{$key} = 1;
16868: }
16869: }
16870: } elsif ($key eq 'fields') {
16871: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16872: foreach my $item (@{$types},'default') {
1.1 raeburn 16873: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16874: my $change = 0;
16875: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16876: if (!exists($fields{$item})) {
16877: $change = 1;
1.132 raeburn 16878: last;
1.1 raeburn 16879: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16880: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16881: $change = 1;
1.132 raeburn 16882: last;
1.1 raeburn 16883: }
16884: }
16885: }
16886: if ($change) {
16887: push(@{$changes{$key}},$item);
16888: }
1.26 raeburn 16889: }
1.1 raeburn 16890: }
16891: }
1.131 raeburn 16892: } elsif ($key eq 'lockablenames') {
16893: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16894: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16895: if (@changed) {
16896: $changes{'lockablenames'} = 1;
16897: }
16898: } else {
16899: if (@lockablenames) {
16900: $changes{'lockablenames'} = 1;
16901: }
16902: }
16903: }
16904: }
16905: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16906: if (@lockablenames) {
16907: $changes{'lockablenames'} = 1;
1.1 raeburn 16908: }
16909: }
1.385 raeburn 16910: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16911: if ($updatehash{'autoupdate'}{'unexpired'}) {
16912: $changes{'unexpired'} = 1;
16913: }
16914: }
16915: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16916: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16917: $changes{'lastactive'} = 1;
16918: }
16919: }
1.26 raeburn 16920: foreach my $item (@{$types},'default') {
16921: if (defined($fields{$item})) {
16922: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16923: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16924: my $change = 0;
16925: if (ref($fields{$item}) eq 'ARRAY') {
16926: foreach my $type (@{$fields{$item}}) {
16927: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16928: $change = 1;
16929: last;
16930: }
16931: }
16932: }
16933: if ($change) {
16934: push(@{$changes{'fields'}},$item);
16935: }
16936: } else {
1.26 raeburn 16937: push(@{$changes{'fields'}},$item);
16938: }
16939: } else {
16940: push(@{$changes{'fields'}},$item);
1.1 raeburn 16941: }
16942: }
16943: }
16944: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16945: $dom);
16946: if ($putresult eq 'ok') {
16947: if (keys(%changes) > 0) {
16948: $resulttext = &mt('Changes made:').'<ul>';
16949: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16950: if ($key eq 'lockablenames') {
16951: $resulttext .= '<li>';
16952: if (@lockablenames) {
16953: $usertypes->{'default'} = $othertitle;
16954: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16955: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16956: } else {
16957: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16958: }
16959: $resulttext .= '</li>';
16960: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16961: foreach my $item (@{$changes{$key}}) {
16962: my @newvalues;
16963: foreach my $type (@{$fields{$item}}) {
16964: push(@newvalues,$fieldtitles{$type});
16965: }
1.3 raeburn 16966: my $newvaluestr;
16967: if (@newvalues > 0) {
16968: $newvaluestr = join(', ',@newvalues);
16969: } else {
16970: $newvaluestr = &mt('none');
1.6 raeburn 16971: }
1.1 raeburn 16972: if ($item eq 'default') {
1.26 raeburn 16973: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16974: } else {
1.26 raeburn 16975: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16976: }
16977: }
16978: } else {
16979: my $newvalue;
16980: if ($key eq 'run') {
16981: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16982: } elsif ($key eq 'lastactive') {
16983: $newvalue = $offon[$env{'form.lastactive'}];
16984: unless ($lastactivedays eq '') {
16985: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16986: }
1.1 raeburn 16987: } else {
16988: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16989: }
1.1 raeburn 16990: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16991: }
16992: }
16993: $resulttext .= '</ul>';
16994: } else {
1.3 raeburn 16995: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 16996: }
16997: } else {
1.11 albertel 16998: $resulttext = '<span class="LC_error">'.
16999: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17000: }
1.3 raeburn 17001: return $resulttext;
1.1 raeburn 17002: }
17003:
1.125 raeburn 17004: sub modify_autocreate {
17005: my ($dom,%domconfig) = @_;
17006: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17007: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17008: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17009: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17010: }
17011: }
17012: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17013: req => 'Auto-creation of validated requests for official courses',
17014: xmldc => 'Identity of course creator of courses from XML files',
17015: );
17016: my @types = ('xml','req');
17017: foreach my $item (@types) {
17018: $newvals{$item} = $env{'form.autocreate_'.$item};
17019: $newvals{$item} =~ s/\D//g;
17020: $newvals{$item} = 0 if ($newvals{$item} eq '');
17021: }
17022: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17023: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17024: unless (exists($domcoords{$newvals{'xmldc'}})) {
17025: $newvals{'xmldc'} = '';
17026: }
17027: %autocreatehash = (
17028: autocreate => { xml => $newvals{'xml'},
17029: req => $newvals{'req'},
17030: }
17031: );
17032: if ($newvals{'xmldc'} ne '') {
17033: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17034: }
17035: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17036: $dom);
17037: if ($putresult eq 'ok') {
17038: my @items = @types;
17039: if ($newvals{'xml'}) {
17040: push(@items,'xmldc');
17041: }
17042: foreach my $item (@items) {
17043: if (exists($currautocreate{$item})) {
17044: if ($currautocreate{$item} ne $newvals{$item}) {
17045: $changes{$item} = 1;
17046: }
17047: } elsif ($newvals{$item}) {
17048: $changes{$item} = 1;
17049: }
17050: }
17051: if (keys(%changes) > 0) {
17052: my @offon = ('off','on');
17053: $resulttext = &mt('Changes made:').'<ul>';
17054: foreach my $item (@types) {
17055: if ($changes{$item}) {
17056: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17057: $resulttext .= '<li>'.
17058: &mt("$title{$item} set to [_1]$newtxt [_2]",
17059: '<b>','</b>').
17060: '</li>';
1.125 raeburn 17061: }
17062: }
17063: if ($changes{'xmldc'}) {
17064: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17065: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17066: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17067: }
17068: $resulttext .= '</ul>';
17069: } else {
17070: $resulttext = &mt('No changes made to auto-creation settings');
17071: }
17072: } else {
17073: $resulttext = '<span class="LC_error">'.
17074: &mt('An error occurred: [_1]',$putresult).'</span>';
17075: }
17076: return $resulttext;
17077: }
17078:
1.23 raeburn 17079: sub modify_directorysrch {
1.295 raeburn 17080: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17081: my ($resulttext,%changes);
17082: my %currdirsrch;
17083: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17084: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17085: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17086: }
17087: }
1.277 raeburn 17088: my %title = ( available => 'Institutional directory search available',
17089: localonly => 'Other domains can search institution',
17090: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17091: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17092: searchby => 'Search types',
17093: searchtypes => 'Search latitude');
17094: my @offon = ('off','on');
1.24 raeburn 17095: my @otherdoms = ('Yes','No');
1.23 raeburn 17096:
1.25 raeburn 17097: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17098: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17099: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17100:
1.44 raeburn 17101: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17102: if (keys(%{$usertypes}) == 0) {
17103: @cansearch = ('default');
17104: } else {
17105: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17106: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17107: if (!grep(/^\Q$type\E$/,@cansearch)) {
17108: push(@{$changes{'cansearch'}},$type);
17109: }
1.23 raeburn 17110: }
1.26 raeburn 17111: foreach my $type (@cansearch) {
17112: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17113: push(@{$changes{'cansearch'}},$type);
17114: }
1.23 raeburn 17115: }
1.26 raeburn 17116: } else {
17117: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17118: }
17119: }
17120:
17121: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17122: foreach my $by (@{$currdirsrch{'searchby'}}) {
17123: if (!grep(/^\Q$by\E$/,@searchby)) {
17124: push(@{$changes{'searchby'}},$by);
17125: }
17126: }
17127: foreach my $by (@searchby) {
17128: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17129: push(@{$changes{'searchby'}},$by);
17130: }
17131: }
17132: } else {
17133: push(@{$changes{'searchby'}},@searchby);
17134: }
1.25 raeburn 17135:
17136: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17137: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17138: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17139: push(@{$changes{'searchtypes'}},$type);
17140: }
17141: }
17142: foreach my $type (@searchtypes) {
17143: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17144: push(@{$changes{'searchtypes'}},$type);
17145: }
17146: }
17147: } else {
17148: if (exists($currdirsrch{'searchtypes'})) {
17149: foreach my $type (@searchtypes) {
17150: if ($type ne $currdirsrch{'searchtypes'}) {
17151: push(@{$changes{'searchtypes'}},$type);
17152: }
17153: }
17154: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17155: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17156: }
17157: } else {
17158: push(@{$changes{'searchtypes'}},@searchtypes);
17159: }
17160: }
17161:
1.23 raeburn 17162: my %dirsrch_hash = (
17163: directorysrch => { available => $env{'form.dirsrch_available'},
17164: cansearch => \@cansearch,
1.277 raeburn 17165: localonly => $env{'form.dirsrch_instlocalonly'},
17166: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17167: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17168: searchby => \@searchby,
1.25 raeburn 17169: searchtypes => \@searchtypes,
1.23 raeburn 17170: }
17171: );
17172: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17173: $dom);
17174: if ($putresult eq 'ok') {
17175: if (exists($currdirsrch{'available'})) {
17176: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17177: $changes{'available'} = 1;
17178: }
17179: } else {
17180: if ($env{'form.dirsrch_available'} eq '1') {
17181: $changes{'available'} = 1;
17182: }
17183: }
1.277 raeburn 17184: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17185: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17186: $changes{'lcavailable'} = 1;
17187: }
1.277 raeburn 17188: } else {
17189: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17190: $changes{'lcavailable'} = 1;
17191: }
17192: }
1.24 raeburn 17193: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17194: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17195: $changes{'localonly'} = 1;
17196: }
1.24 raeburn 17197: } else {
1.277 raeburn 17198: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17199: $changes{'localonly'} = 1;
17200: }
17201: }
1.277 raeburn 17202: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17203: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17204: $changes{'lclocalonly'} = 1;
17205: }
1.277 raeburn 17206: } else {
17207: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17208: $changes{'lclocalonly'} = 1;
17209: }
17210: }
1.23 raeburn 17211: if (keys(%changes) > 0) {
17212: $resulttext = &mt('Changes made:').'<ul>';
17213: if ($changes{'available'}) {
17214: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17215: }
1.277 raeburn 17216: if ($changes{'lcavailable'}) {
17217: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17218: }
1.24 raeburn 17219: if ($changes{'localonly'}) {
1.277 raeburn 17220: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17221: }
1.277 raeburn 17222: if ($changes{'lclocalonly'}) {
17223: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17224: }
1.23 raeburn 17225: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17226: my $chgtext;
1.26 raeburn 17227: if (ref($usertypes) eq 'HASH') {
17228: if (keys(%{$usertypes}) > 0) {
17229: foreach my $type (@{$types}) {
17230: if (grep(/^\Q$type\E$/,@cansearch)) {
17231: $chgtext .= $usertypes->{$type}.'; ';
17232: }
17233: }
17234: if (grep(/^default$/,@cansearch)) {
17235: $chgtext .= $othertitle;
17236: } else {
17237: $chgtext =~ s/\; $//;
17238: }
1.210 raeburn 17239: $resulttext .=
1.178 raeburn 17240: '<li>'.
17241: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17242: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17243: '</li>';
1.23 raeburn 17244: }
17245: }
17246: }
17247: if (ref($changes{'searchby'}) eq 'ARRAY') {
17248: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17249: my $chgtext;
17250: foreach my $type (@{$titleorder}) {
17251: if (grep(/^\Q$type\E$/,@searchby)) {
17252: if (defined($searchtitles->{$type})) {
17253: $chgtext .= $searchtitles->{$type}.'; ';
17254: }
17255: }
17256: }
17257: $chgtext =~ s/\; $//;
17258: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17259: }
1.25 raeburn 17260: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17261: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17262: my $chgtext;
17263: foreach my $type (@{$srchtypeorder}) {
17264: if (grep(/^\Q$type\E$/,@searchtypes)) {
17265: if (defined($srchtypes_desc->{$type})) {
17266: $chgtext .= $srchtypes_desc->{$type}.'; ';
17267: }
17268: }
17269: }
17270: $chgtext =~ s/\; $//;
1.178 raeburn 17271: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17272: }
17273: $resulttext .= '</ul>';
1.295 raeburn 17274: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17275: if (ref($lastactref) eq 'HASH') {
17276: $lastactref->{'directorysrch'} = 1;
17277: }
1.23 raeburn 17278: } else {
1.277 raeburn 17279: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17280: }
17281: } else {
17282: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17283: &mt('An error occurred: [_1]',$putresult).'</span>';
17284: }
17285: return $resulttext;
17286: }
17287:
1.28 raeburn 17288: sub modify_contacts {
1.205 raeburn 17289: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17290: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17291: if (ref($domconfig{'contacts'}) eq 'HASH') {
17292: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17293: $currsetting{$key} = $domconfig{'contacts'}{$key};
17294: }
17295: }
1.286 raeburn 17296: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17297: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17298: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17299: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17300: my @toggles = ('reporterrors','reportupdates','reportstatus');
17301: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17302: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17303: foreach my $type (@mailings) {
17304: @{$newsetting{$type}} =
17305: &Apache::loncommon::get_env_multiple('form.'.$type);
17306: foreach my $item (@contacts) {
17307: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17308: $contacts_hash{contacts}{$type}{$item} = 1;
17309: } else {
17310: $contacts_hash{contacts}{$type}{$item} = 0;
17311: }
1.289 raeburn 17312: }
1.28 raeburn 17313: $others{$type} = $env{'form.'.$type.'_others'};
17314: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17315: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17316: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17317: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17318: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17319: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17320: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17321: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17322: }
1.134 raeburn 17323: }
1.28 raeburn 17324: }
17325: foreach my $item (@contacts) {
17326: $to{$item} = $env{'form.'.$item};
17327: $contacts_hash{'contacts'}{$item} = $to{$item};
17328: }
1.203 raeburn 17329: foreach my $item (@toggles) {
17330: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17331: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17332: }
17333: }
1.340 raeburn 17334: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17335: foreach my $item (@lonstatus) {
17336: if ($item eq 'excluded') {
17337: my (%serverhomes,@excluded);
17338: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17339: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17340: if (@possexcluded) {
17341: foreach my $id (sort(@possexcluded)) {
17342: if ($serverhomes{$id}) {
17343: push(@excluded,$id);
17344: }
17345: }
17346: }
17347: if (@excluded) {
17348: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17349: }
17350: } elsif ($item eq 'weights') {
1.377 raeburn 17351: foreach my $type ('E','W','N','U') {
1.340 raeburn 17352: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17353: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17354: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17355: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17356: $env{'form.error'.$item.'_'.$type};
17357: }
17358: }
17359: }
17360: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17361: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17362: if ($env{'form.error'.$item} =~ /^\d+$/) {
17363: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17364: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17365: }
17366: }
17367: }
17368: }
1.286 raeburn 17369: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17370: foreach my $field (@{$fields}) {
17371: if (ref($possoptions->{$field}) eq 'ARRAY') {
17372: my $value = $env{'form.helpform_'.$field};
17373: $value =~ s/^\s+|\s+$//g;
17374: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17375: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17376: if ($field eq 'screenshot') {
17377: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17378: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17379: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17380: }
17381: }
17382: }
17383: }
17384: }
17385: }
1.315 raeburn 17386: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17387: my (@statuses,%usertypeshash,@overrides);
17388: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17389: @statuses = @{$types};
17390: if (ref($usertypes) eq 'HASH') {
17391: %usertypeshash = %{$usertypes};
17392: }
17393: }
17394: if (@statuses) {
17395: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17396: foreach my $type (@possoverrides) {
17397: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17398: push(@overrides,$type);
17399: }
17400: }
17401: if (@overrides) {
17402: foreach my $type (@overrides) {
17403: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17404: foreach my $item (@contacts) {
17405: if (grep(/^\Q$item\E$/,@standard)) {
17406: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17407: $newsetting{'override_'.$type}{$item} = 1;
17408: } else {
17409: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17410: $newsetting{'override_'.$type}{$item} = 0;
17411: }
17412: }
17413: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17414: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17415: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17416: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17417: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17418: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17419: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17420: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17421: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17422: }
1.425 raeburn 17423: }
1.315 raeburn 17424: }
17425: }
1.28 raeburn 17426: if (keys(%currsetting) > 0) {
17427: foreach my $item (@contacts) {
17428: if ($to{$item} ne $currsetting{$item}) {
17429: $changes{$item} = 1;
17430: }
17431: }
17432: foreach my $type (@mailings) {
17433: foreach my $item (@contacts) {
17434: if (ref($currsetting{$type}) eq 'HASH') {
17435: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17436: push(@{$changes{$type}},$item);
17437: }
17438: } else {
17439: push(@{$changes{$type}},@{$newsetting{$type}});
17440: }
17441: }
17442: if ($others{$type} ne $currsetting{$type}{'others'}) {
17443: push(@{$changes{$type}},'others');
17444: }
1.289 raeburn 17445: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17446: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17447: push(@{$changes{$type}},'bcc');
17448: }
1.286 raeburn 17449: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17450: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17451: push(@{$changes{$type}},'include');
17452: }
17453: }
17454: }
17455: if (ref($fields) eq 'ARRAY') {
17456: if (ref($currsetting{'helpform'}) eq 'HASH') {
17457: foreach my $field (@{$fields}) {
17458: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17459: push(@{$changes{'helpform'}},$field);
17460: }
17461: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17462: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17463: push(@{$changes{'helpform'}},'maxsize');
17464: }
17465: }
17466: }
17467: } else {
17468: foreach my $field (@{$fields}) {
17469: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17470: push(@{$changes{'helpform'}},$field);
17471: }
17472: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17473: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17474: push(@{$changes{'helpform'}},'maxsize');
17475: }
17476: }
17477: }
1.134 raeburn 17478: }
1.28 raeburn 17479: }
1.315 raeburn 17480: if (@statuses) {
1.425 raeburn 17481: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17482: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17483: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17484: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17485: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17486: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17487: push(@{$changes{'overrides'}},$key);
17488: last;
17489: }
17490: }
17491: } else {
17492: push(@{$changes{'overrides'}},$key);
17493: }
17494: }
17495: }
17496: foreach my $key (@overrides) {
17497: unless (exists($currsetting{'overrides'}{$key})) {
17498: push(@{$changes{'overrides'}},$key);
17499: }
17500: }
17501: } else {
17502: foreach my $key (@overrides) {
1.425 raeburn 17503: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17504: }
17505: }
17506: }
1.340 raeburn 17507: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17508: foreach my $key ('excluded','weights','threshold','sysmail') {
17509: if ($key eq 'excluded') {
17510: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17511: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17512: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17513: (@{$currsetting{'lonstatus'}{$key}})) {
17514: my @diffs =
17515: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17516: $currsetting{'lonstatus'}{$key});
17517: if (@diffs) {
17518: push(@{$changes{'lonstatus'}},$key);
17519: }
17520: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17521: push(@{$changes{'lonstatus'}},$key);
17522: }
17523: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17524: (@{$currsetting{'lonstatus'}{$key}})) {
17525: push(@{$changes{'lonstatus'}},$key);
17526: }
17527: } elsif ($key eq 'weights') {
17528: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17529: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17530: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17531: foreach my $type ('E','W','N','U') {
1.340 raeburn 17532: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17533: $currsetting{'lonstatus'}{$key}{$type}) {
17534: push(@{$changes{'lonstatus'}},$key);
17535: last;
17536: }
17537: }
17538: } else {
1.341 raeburn 17539: foreach my $type ('E','W','N','U') {
1.340 raeburn 17540: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17541: push(@{$changes{'lonstatus'}},$key);
17542: last;
17543: }
17544: }
17545: }
17546: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17547: foreach my $type ('E','W','N','U') {
1.340 raeburn 17548: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17549: push(@{$changes{'lonstatus'}},$key);
17550: last;
17551: }
17552: }
17553: }
17554: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17555: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17556: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17557: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17558: push(@{$changes{'lonstatus'}},$key);
17559: }
17560: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17561: push(@{$changes{'lonstatus'}},$key);
17562: }
17563: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17564: push(@{$changes{'lonstatus'}},$key);
17565: }
17566: }
17567: }
17568: } else {
17569: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17570: foreach my $key ('excluded','weights','threshold','sysmail') {
17571: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17572: push(@{$changes{'lonstatus'}},$key);
17573: }
17574: }
17575: }
17576: }
1.28 raeburn 17577: } else {
17578: my %default;
17579: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17580: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17581: $default{'errormail'} = 'adminemail';
17582: $default{'packagesmail'} = 'adminemail';
17583: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17584: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17585: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17586: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17587: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17588: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17589: foreach my $item (@contacts) {
17590: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17591: $changes{$item} = 1;
1.203 raeburn 17592: }
1.28 raeburn 17593: }
17594: foreach my $type (@mailings) {
17595: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17596: push(@{$changes{$type}},@{$newsetting{$type}});
17597: }
17598: if ($others{$type} ne '') {
17599: push(@{$changes{$type}},'others');
1.134 raeburn 17600: }
1.286 raeburn 17601: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17602: if ($bcc{$type} ne '') {
17603: push(@{$changes{$type}},'bcc');
17604: }
1.286 raeburn 17605: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17606: push(@{$changes{$type}},'include');
17607: }
1.134 raeburn 17608: }
1.28 raeburn 17609: }
1.286 raeburn 17610: if (ref($fields) eq 'ARRAY') {
17611: foreach my $field (@{$fields}) {
17612: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17613: push(@{$changes{'helpform'}},$field);
17614: }
17615: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17616: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17617: push(@{$changes{'helpform'}},'maxsize');
17618: }
17619: }
17620: }
1.289 raeburn 17621: }
1.340 raeburn 17622: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17623: foreach my $key ('excluded','weights','threshold','sysmail') {
17624: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17625: push(@{$changes{'lonstatus'}},$key);
17626: }
17627: }
17628: }
1.28 raeburn 17629: }
1.203 raeburn 17630: foreach my $item (@toggles) {
17631: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17632: $changes{$item} = 1;
17633: } elsif ((!$env{'form.'.$item}) &&
17634: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17635: $changes{$item} = 1;
17636: }
17637: }
1.28 raeburn 17638: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17639: $dom);
17640: if ($putresult eq 'ok') {
17641: if (keys(%changes) > 0) {
1.205 raeburn 17642: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17643: if (ref($lastactref) eq 'HASH') {
17644: $lastactref->{'domainconfig'} = 1;
17645: }
1.28 raeburn 17646: my ($titles,$short_titles) = &contact_titles();
17647: $resulttext = &mt('Changes made:').'<ul>';
17648: foreach my $item (@contacts) {
17649: if ($changes{$item}) {
17650: $resulttext .= '<li>'.$titles->{$item}.
17651: &mt(' set to: ').
17652: '<span class="LC_cusr_emph">'.
17653: $to{$item}.'</span></li>';
17654: }
17655: }
17656: foreach my $type (@mailings) {
17657: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17658: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17659: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17660: } else {
17661: $resulttext .= '<li>'.$titles->{$type}.': ';
17662: }
1.28 raeburn 17663: my @text;
17664: foreach my $item (@{$newsetting{$type}}) {
17665: push(@text,$short_titles->{$item});
17666: }
17667: if ($others{$type} ne '') {
17668: push(@text,$others{$type});
17669: }
1.286 raeburn 17670: if (@text) {
17671: $resulttext .= '<span class="LC_cusr_emph">'.
17672: join(', ',@text).'</span>';
17673: }
17674: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17675: if ($bcc{$type} ne '') {
1.286 raeburn 17676: my $bcctext;
17677: if (@text) {
1.289 raeburn 17678: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17679: } else {
17680: $bcctext = '(Bcc)';
17681: }
17682: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17683: } elsif (!@text) {
17684: $resulttext .= &mt('No one');
1.425 raeburn 17685: }
1.289 raeburn 17686: if ($includestr{$type} ne '') {
1.286 raeburn 17687: if ($includeloc{$type} eq 'b') {
17688: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17689: } elsif ($includeloc{$type} eq 's') {
17690: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17691: }
1.134 raeburn 17692: }
1.286 raeburn 17693: } elsif (!@text) {
17694: $resulttext .= &mt('No recipients');
1.134 raeburn 17695: }
17696: $resulttext .= '</li>';
1.28 raeburn 17697: }
17698: }
1.315 raeburn 17699: if (ref($changes{'overrides'}) eq 'ARRAY') {
17700: my @deletions;
17701: foreach my $type (@{$changes{'overrides'}}) {
17702: if ($usertypeshash{$type}) {
17703: if (grep(/^\Q$type\E/,@overrides)) {
17704: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17705: $usertypeshash{$type}).'<ul><li>';
17706: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17707: my @text;
17708: foreach my $item (@contacts) {
1.425 raeburn 17709: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17710: push(@text,$short_titles->{$item});
17711: }
17712: }
17713: if ($newsetting{'override_'.$type}{'others'} ne '') {
17714: push(@text,$newsetting{'override_'.$type}{'others'});
17715: }
1.425 raeburn 17716:
1.315 raeburn 17717: if (@text) {
17718: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17719: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17720: }
17721: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17722: my $bcctext;
17723: if (@text) {
17724: $bcctext = ' '.&mt('with Bcc to');
17725: } else {
17726: $bcctext = '(Bcc)';
17727: }
17728: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17729: } elsif (!@text) {
17730: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17731: }
17732: $resulttext .= '</li>';
17733: if ($newsetting{'override_'.$type}{'include'} ne '') {
17734: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17735: if ($loc eq 'b') {
17736: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17737: } elsif ($loc eq 's') {
17738: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17739: }
17740: }
17741: }
17742: $resulttext .= '</li></ul></li>';
17743: } else {
17744: push(@deletions,$usertypeshash{$type});
17745: }
17746: }
17747: }
17748: if (@deletions) {
17749: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17750: join(', ',@deletions)).'</li>';
17751: }
17752: }
1.203 raeburn 17753: my @offon = ('off','on');
1.340 raeburn 17754: my $corelink = &core_link_msu();
1.203 raeburn 17755: if ($changes{'reporterrors'}) {
17756: $resulttext .= '<li>'.
17757: &mt('E-mail error reports to [_1] set to "'.
17758: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17759: $corelink).
1.203 raeburn 17760: '</li>';
17761: }
17762: if ($changes{'reportupdates'}) {
17763: $resulttext .= '<li>'.
17764: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17765: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17766: $corelink).
1.203 raeburn 17767: '</li>';
17768: }
1.340 raeburn 17769: if ($changes{'reportstatus'}) {
17770: $resulttext .= '<li>'.
17771: &mt('E-mail status if errors above threshold to [_1] set to "'.
17772: $offon[$env{'form.reportstatus'}].'".',
17773: $corelink).
17774: '</li>';
17775: }
17776: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17777: $resulttext .= '<li>'.
17778: &mt('Nightly status check e-mail settings').':<ul>';
17779: my (%defval,%use_def,%shown);
17780: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17781: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17782: $defval{'weights'} =
1.341 raeburn 17783: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17784: $defval{'excluded'} = &mt('None');
17785: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17786: foreach my $item ('threshold','sysmail','weights','excluded') {
17787: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17788: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17789: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17790: } elsif ($item eq 'weights') {
17791: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17792: foreach my $type ('E','W','N','U') {
1.340 raeburn 17793: $shown{$item} .= $lonstatus_names->{$type}.'=';
17794: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17795: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17796: } else {
17797: $shown{$item} .= $lonstatus_defs->{$type};
17798: }
17799: $shown{$item} .= ', ';
17800: }
17801: $shown{$item} =~ s/, $//;
17802: } else {
17803: $shown{$item} = $defval{$item};
17804: }
17805: } elsif ($item eq 'excluded') {
17806: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17807: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17808: } else {
17809: $shown{$item} = $defval{$item};
17810: }
17811: }
17812: } else {
17813: $shown{$item} = $defval{$item};
17814: }
17815: }
17816: } else {
17817: foreach my $item ('threshold','weights','excluded','sysmail') {
17818: $shown{$item} = $defval{$item};
17819: }
17820: }
17821: foreach my $item ('threshold','weights','excluded','sysmail') {
17822: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17823: $shown{$item}).'</li>';
17824: }
17825: $resulttext .= '</ul></li>';
17826: }
1.286 raeburn 17827: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17828: my (@optional,@required,@unused,$maxsizechg);
17829: foreach my $field (@{$changes{'helpform'}}) {
17830: if ($field eq 'maxsize') {
17831: $maxsizechg = 1;
17832: next;
17833: }
17834: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17835: push(@optional,$field);
1.286 raeburn 17836: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17837: push(@unused,$field);
17838: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17839: push(@required,$field);
1.286 raeburn 17840: }
17841: }
17842: if (@optional) {
17843: $resulttext .= '<li>'.
17844: &mt('Help form fields changed to "Optional": [_1].',
17845: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17846: '</li>';
17847: }
17848: if (@required) {
17849: $resulttext .= '<li>'.
17850: &mt('Help form fields changed to "Required": [_1].',
17851: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17852: '</li>';
17853: }
17854: if (@unused) {
17855: $resulttext .= '<li>'.
17856: &mt('Help form fields changed to "Not shown": [_1].',
17857: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17858: '</li>';
17859: }
17860: if ($maxsizechg) {
17861: $resulttext .= '<li>'.
17862: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17863: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17864: '</li>';
17865: }
17866: }
1.28 raeburn 17867: $resulttext .= '</ul>';
17868: } else {
1.288 raeburn 17869: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17870: }
17871: } else {
17872: $resulttext = '<span class="LC_error">'.
17873: &mt('An error occurred: [_1].',$putresult).'</span>';
17874: }
17875: return $resulttext;
17876: }
17877:
1.357 raeburn 17878: sub modify_privacy {
1.427 raeburn 17879: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17880: my ($resulttext,%current,%changes);
17881: if (ref($domconfig{'privacy'}) eq 'HASH') {
17882: %current = %{$domconfig{'privacy'}};
17883: }
17884: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17885: my @items = ('domain','author','course','community');
17886: my %names = &Apache::lonlocal::texthash (
17887: domain => 'Assigned domain role(s)',
17888: author => 'Assigned co-author role(s)',
17889: course => 'Assigned course role(s)',
1.416 raeburn 17890: community => 'Assigned community role(s)',
1.357 raeburn 17891: );
17892: my %roles = &Apache::lonlocal::texthash (
17893: domain => 'Domain role',
17894: author => 'Co-author role',
17895: course => 'Course role',
17896: community => 'Community role',
17897: );
17898: my %titles = &Apache::lonlocal::texthash (
17899: approval => 'Approval for role in different domain',
17900: othdom => 'User information available in other domain',
17901: priv => 'Information viewable by privileged user in same domain',
17902: unpriv => 'Information viewable by unprivileged user in same domain',
17903: instdom => 'Other domain shares institution/provider',
17904: extdom => 'Other domain has different institution/provider',
17905: none => 'Not allowed',
17906: user => 'User authorizes',
17907: domain => 'Domain Coordinator authorizes',
17908: auto => 'Unrestricted',
1.418 raeburn 17909: notify => 'Notify when role needs authorization',
1.357 raeburn 17910: );
17911: my %fieldnames = &Apache::lonlocal::texthash (
17912: id => 'Student/Employee ID',
17913: permanentemail => 'E-mail address',
17914: lastname => 'Last Name',
17915: firstname => 'First Name',
17916: middlename => 'Middle Name',
17917: generation => 'Generation',
17918: );
17919: my ($othertitle,$usertypes,$types) =
17920: &Apache::loncommon::sorted_inst_types($dom);
17921: my (%by_ip,%by_location,@intdoms,@instdoms);
17922: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17923:
17924: my %privacyhash = (
17925: 'approval' => {
17926: instdom => {},
17927: extdom => {},
17928: },
17929: 'othdom' => {},
17930: 'priv' => {},
17931: 'unpriv' => {},
17932: );
17933: foreach my $item (@items) {
17934: if (@instdoms > 1) {
1.416 raeburn 17935: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17936: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17937: }
17938: if (ref($current{'approval'}) eq 'HASH') {
17939: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17940: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17941: $changes{'approval'} = 1;
17942: }
17943: }
17944: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17945: $changes{'approval'} = 1;
17946: }
17947: }
17948: if (keys(%by_location) > 0) {
17949: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17950: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17951: }
17952: if (ref($current{'approval'}) eq 'HASH') {
17953: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17954: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17955: $changes{'approval'} = 1;
17956: }
17957: }
17958: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17959: $changes{'approval'} = 1;
17960: }
17961: }
17962: foreach my $status ('priv','unpriv') {
17963: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17964: my @newvalues;
17965: foreach my $field (@possibles) {
17966: if (grep(/^\Q$field\E$/,@fields)) {
17967: $privacyhash{$status}{$item}{$field} = 1;
17968: push(@newvalues,$field);
17969: }
17970: }
17971: @newvalues = sort(@newvalues);
17972: if (ref($current{$status}) eq 'HASH') {
17973: if (ref($current{$status}{$item}) eq 'HASH') {
17974: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17975: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17976: if (@diffs > 0) {
17977: $changes{$status} = 1;
17978: }
17979: }
17980: } else {
17981: my @stdfields;
17982: foreach my $field (@fields) {
17983: if ($field eq 'id') {
17984: next if ($status eq 'unpriv');
17985: next if (($status eq 'priv') && ($item eq 'community'));
17986: }
17987: push(@stdfields,$field);
17988: }
17989: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17990: if (@diffs > 0) {
17991: $changes{$status} = 1;
17992: }
17993: }
17994: }
17995: }
17996: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
17997: my @statuses;
17998: if (ref($types) eq 'ARRAY') {
17999: @statuses = @{$types};
18000: }
18001: foreach my $type (@statuses,'default') {
18002: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18003: my @newvalues;
18004: foreach my $field (sort(@possfields)) {
18005: if (grep(/^\Q$field\E$/,@fields)) {
18006: $privacyhash{'othdom'}{$type}{$field} = 1;
18007: push(@newvalues,$field);
18008: }
18009: }
18010: @newvalues = sort(@newvalues);
18011: if (ref($current{'othdom'}) eq 'HASH') {
18012: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18013: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18014: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18015: if (@diffs > 0) {
18016: $changes{'othdom'} = 1;
18017: }
18018: }
18019: } else {
18020: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18021: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18022: if (@diffs > 0) {
18023: $changes{'othdom'} = 1;
18024: }
18025: }
18026: }
1.417 raeburn 18027: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18028: my %notify;
18029: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18030: if (exists($domcoords{$possdc})) {
18031: $notify{$possdc} = 1;
18032: }
18033: }
18034: my $notify = join(',',sort(keys(%notify)));
18035: if ($current{'notify'} ne $notify) {
18036: $changes{'notify'} = 1;
18037: }
18038: $privacyhash{'notify'} = $notify;
1.357 raeburn 18039: }
18040: my %confighash = (
18041: privacy => \%privacyhash,
18042: );
18043: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18044: if ($putresult eq 'ok') {
18045: if (keys(%changes) > 0) {
18046: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18047: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18048: if ($changes{$key}) {
18049: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18050: if ($key eq 'approval') {
18051: if (keys(%{$privacyhash{$key}{instdom}})) {
18052: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18053: foreach my $item (@items) {
18054: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18055: }
18056: $resulttext .= '</ul></li>';
18057: }
18058: if (keys(%{$privacyhash{$key}{extdom}})) {
18059: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18060: foreach my $item (@items) {
18061: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18062: }
18063: $resulttext .= '</ul></li>';
18064: }
1.417 raeburn 18065: } elsif ($key eq 'notify') {
18066: if ($privacyhash{$key}) {
18067: foreach my $dc (split(/,/,$privacyhash{$key})) {
18068: my ($dcname,$dcdom) = split(/:/,$dc);
18069: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18070: }
18071: } else {
18072: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18073: }
1.357 raeburn 18074: } elsif ($key eq 'othdom') {
18075: my @statuses;
18076: if (ref($types) eq 'ARRAY') {
18077: @statuses = @{$types};
18078: }
18079: if (ref($privacyhash{$key}) eq 'HASH') {
18080: foreach my $status (@statuses,'default') {
18081: if ($status eq 'default') {
18082: $resulttext .= '<li>'.$othertitle.': ';
18083: } elsif (ref($usertypes) eq 'HASH') {
18084: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18085: } else {
18086: next;
18087: }
18088: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18089: if (keys(%{$privacyhash{$key}{$status}})) {
18090: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18091: } else {
18092: $resulttext .= &mt('none');
18093: }
18094: }
18095: $resulttext .= '</li>';
18096: }
18097: }
18098: } else {
18099: foreach my $item (@items) {
18100: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18101: $resulttext .= '<li>'.$names{$item}.': ';
18102: if (keys(%{$privacyhash{$key}{$item}})) {
18103: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18104: } else {
18105: $resulttext .= &mt('none');
18106: }
18107: $resulttext .= '</li>';
18108: }
18109: }
18110: }
18111: $resulttext .= '</ul></li>';
18112: }
18113: }
1.421 raeburn 18114: $resulttext .= '</ul>';
1.427 raeburn 18115: if ($changes{'approval'}) {
18116: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18117: delete($domdefaults{'userapprovals'});
18118: if (ref($privacyhash{'approval'}) eq 'HASH') {
18119: foreach my $domtype ('instdom','extdom') {
18120: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18121: foreach my $roletype ('domain','author','course','community') {
18122: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18123: $domdefaults{'userapprovals'} = 1;
18124: last;
18125: }
18126: }
18127: }
18128: last if ($domdefaults{'userapprovals'});
18129: }
18130: }
18131: my $cachetime = 24*60*60;
18132: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18133: if (ref($lastactref) eq 'HASH') {
18134: $lastactref->{'domdefaults'} = 1;
18135: }
18136: }
1.357 raeburn 18137: } else {
18138: $resulttext = &mt('No changes made to user information settings');
18139: }
18140: } else {
18141: $resulttext = '<span class="LC_error">'.
18142: &mt('An error occurred: [_1]',$putresult).'</span>';
18143: }
18144: return $resulttext;
18145: }
18146:
1.354 raeburn 18147: sub modify_passwords {
18148: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18149: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18150: $updatedefaults,$updateconf);
1.354 raeburn 18151: my $customfn = 'resetpw.html';
18152: if (ref($domconfig{'passwords'}) eq 'HASH') {
18153: %current = %{$domconfig{'passwords'}};
18154: }
18155: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18156: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18157: if (ref($types) eq 'ARRAY') {
18158: @oktypes = @{$types};
18159: }
18160: push(@oktypes,'default');
18161:
18162: my %titles = &Apache::lonlocal::texthash (
18163: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18164: intauth_check => 'Check bcrypt cost if authenticated',
18165: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18166: permanent => 'Permanent e-mail address',
18167: critical => 'Critical notification address',
18168: notify => 'Notification address',
18169: min => 'Minimum password length',
18170: max => 'Maximum password length',
18171: chars => 'Required characters',
18172: expire => 'Password expiration (days)',
1.356 raeburn 18173: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18174: reset => 'Resetting Forgotten Password',
18175: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18176: rules => 'Rules for LON-CAPA Passwords',
18177: crsownerchg => 'Course Owner Changing Student Passwords',
18178: username => 'Username',
18179: email => 'E-mail address',
18180: );
18181:
18182: #
18183: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18184: #
18185: my (%curr_defaults,%save_defaults);
18186: if (ref($domconfig{'defaults'}) eq 'HASH') {
18187: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18188: if ($key =~ /^intauth_(cost|check|switch)$/) {
18189: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18190: } else {
18191: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18192: }
18193: }
18194: }
18195: my %staticdefaults = (
18196: 'resetlink' => 2,
18197: 'resetcase' => \@oktypes,
18198: 'resetprelink' => 'both',
18199: 'resetemail' => ['critical','notify','permanent'],
18200: 'intauth_cost' => 10,
18201: 'intauth_check' => 0,
18202: 'intauth_switch' => 0,
18203: );
1.365 raeburn 18204: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18205: foreach my $type (@oktypes) {
18206: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18207: }
18208: my $linklife = $env{'form.passwords_link'};
18209: $linklife =~ s/^\s+|\s+$//g;
18210: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18211: $newvalues{'resetlink'} = $linklife;
18212: if ($current{'resetlink'}) {
18213: if ($current{'resetlink'} ne $linklife) {
18214: $changes{'reset'} = 1;
18215: }
1.368 raeburn 18216: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18217: if ($staticdefaults{'resetlink'} ne $linklife) {
18218: $changes{'reset'} = 1;
18219: }
18220: }
18221: } elsif ($current{'resetlink'}) {
18222: $changes{'reset'} = 1;
18223: }
18224: my @casesens;
18225: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18226: foreach my $case (sort(@posscase)) {
18227: if (grep(/^\Q$case\E$/,@oktypes)) {
18228: push(@casesens,$case);
18229: }
18230: }
18231: $newvalues{'resetcase'} = \@casesens;
18232: if (ref($current{'resetcase'}) eq 'ARRAY') {
18233: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18234: if (@diffs > 0) {
18235: $changes{'reset'} = 1;
18236: }
1.368 raeburn 18237: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18238: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18239: if (@diffs > 0) {
18240: $changes{'reset'} = 1;
18241: }
18242: }
18243: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18244: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18245: if (exists($current{'resetprelink'})) {
18246: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18247: $changes{'reset'} = 1;
18248: }
1.368 raeburn 18249: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18250: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18251: $changes{'reset'} = 1;
18252: }
18253: }
18254: } elsif ($current{'resetprelink'}) {
18255: $changes{'reset'} = 1;
18256: }
18257: foreach my $type (@oktypes) {
18258: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18259: my @postlink;
18260: foreach my $item (sort(@possplink)) {
18261: if ($item =~ /^(email|username)$/) {
18262: push(@postlink,$item);
18263: }
18264: }
18265: $newvalues{'resetpostlink'}{$type} = \@postlink;
18266: unless ($changes{'reset'}) {
18267: if (ref($current{'resetpostlink'}) eq 'HASH') {
18268: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18269: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18270: if (@diffs > 0) {
18271: $changes{'reset'} = 1;
18272: }
18273: } else {
18274: $changes{'reset'} = 1;
18275: }
1.368 raeburn 18276: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18277: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18278: if (@diffs > 0) {
18279: $changes{'reset'} = 1;
18280: }
18281: }
18282: }
18283: }
18284: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18285: my @resetemail;
18286: foreach my $item (sort(@possemailsrc)) {
18287: if ($item =~ /^(permanent|critical|notify)$/) {
18288: push(@resetemail,$item);
18289: }
18290: }
18291: $newvalues{'resetemail'} = \@resetemail;
18292: unless ($changes{'reset'}) {
18293: if (ref($current{'resetemail'}) eq 'ARRAY') {
18294: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18295: if (@diffs > 0) {
18296: $changes{'reset'} = 1;
18297: }
1.368 raeburn 18298: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18299: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18300: if (@diffs > 0) {
18301: $changes{'reset'} = 1;
18302: }
18303: }
18304: }
18305: if ($env{'form.passwords_stdtext'} == 0) {
18306: $newvalues{'resetremove'} = 1;
18307: unless ($current{'resetremove'}) {
18308: $changes{'reset'} = 1;
18309: }
18310: } elsif ($current{'resetremove'}) {
18311: $changes{'reset'} = 1;
18312: }
18313: if ($env{'form.passwords_customfile.filename'} ne '') {
18314: my $servadm = $r->dir_config('lonAdmEMail');
18315: my ($configuserok,$author_ok,$switchserver) =
18316: &config_check($dom,$confname,$servadm);
18317: my $error;
18318: if ($configuserok eq 'ok') {
18319: if ($switchserver) {
18320: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18321: } else {
18322: if ($author_ok eq 'ok') {
1.421 raeburn 18323: my $modified = [];
1.354 raeburn 18324: my ($result,$customurl) =
1.421 raeburn 18325: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18326: $confname,'customtext/resetpw','','',$customfn,
18327: $modified);
1.354 raeburn 18328: if ($result eq 'ok') {
18329: $newvalues{'resetcustom'} = $customurl;
18330: $changes{'reset'} = 1;
1.421 raeburn 18331: &update_modify_urls($r,$modified);
1.354 raeburn 18332: } else {
18333: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18334: }
18335: } else {
18336: $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);
18337: }
18338: }
18339: } else {
18340: $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);
18341: }
18342: if ($error) {
18343: &Apache::lonnet::logthis($error);
18344: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18345: }
18346: } elsif ($current{'resetcustom'}) {
18347: if ($env{'form.passwords_custom_del'}) {
18348: $changes{'reset'} = 1;
18349: } else {
18350: $newvalues{'resetcustom'} = $current{'resetcustom'};
18351: }
18352: }
18353: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18354: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18355: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18356: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18357: $changes{'intauth'} = 1;
18358: }
18359: } else {
18360: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18361: }
18362: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18363: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18364: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18365: $changes{'intauth'} = 1;
18366: }
18367: } else {
18368: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18369: }
18370: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18371: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18372: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18373: $changes{'intauth'} = 1;
18374: }
18375: } else {
18376: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18377: }
18378: foreach my $item ('cost','check','switch') {
18379: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18380: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18381: $updatedefaults = 1;
18382: }
18383: }
1.405 raeburn 18384: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18385: my %crsownerchg = (
18386: by => [],
18387: for => [],
18388: );
18389: foreach my $item ('by','for') {
18390: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18391: foreach my $type (sort(@posstypes)) {
18392: if (grep(/^\Q$type\E$/,@oktypes)) {
18393: push(@{$crsownerchg{$item}},$type);
18394: }
18395: }
18396: }
18397: $newvalues{'crsownerchg'} = \%crsownerchg;
18398: if (ref($current{'crsownerchg'}) eq 'HASH') {
18399: foreach my $item ('by','for') {
18400: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18401: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18402: if (@diffs > 0) {
18403: $changes{'crsownerchg'} = 1;
18404: last;
18405: }
18406: }
18407: }
1.368 raeburn 18408: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18409: foreach my $item ('by','for') {
18410: if (@{$crsownerchg{$item}} > 0) {
18411: $changes{'crsownerchg'} = 1;
18412: last;
18413: }
1.354 raeburn 18414: }
18415: }
18416:
18417: my %confighash = (
18418: defaults => \%save_defaults,
18419: passwords => \%newvalues,
18420: );
18421: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18422:
18423: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18424: if ($putresult eq 'ok') {
18425: if (keys(%changes) > 0) {
18426: $resulttext = &mt('Changes made: ').'<ul>';
18427: foreach my $key ('reset','intauth','rules','crsownerchg') {
18428: if ($changes{$key}) {
1.355 raeburn 18429: unless ($key eq 'intauth') {
18430: $updateconf = 1;
18431: }
1.354 raeburn 18432: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18433: if ($key eq 'reset') {
18434: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18435: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18436: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18437: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18438: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18439: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18440: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18441: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18442: }
1.354 raeburn 18443: } else {
18444: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18445: }
18446: if ($confighash{'passwords'}{'resetlink'}) {
18447: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18448: } else {
18449: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18450: &mt('Will default to 2 hours').'</li>';
18451: }
18452: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18453: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18454: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18455: } else {
18456: my $casesens;
18457: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18458: if ($type eq 'default') {
18459: $casesens .= $othertitle.', ';
18460: } elsif ($usertypes->{$type} ne '') {
18461: $casesens .= $usertypes->{$type}.', ';
18462: }
18463: }
18464: $casesens =~ s/\Q, \E$//;
18465: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18466: }
18467: } else {
18468: $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>';
18469: }
18470: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18471: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18472: } else {
18473: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18474: }
18475: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18476: my $output;
18477: if (ref($types) eq 'ARRAY') {
18478: foreach my $type (@{$types}) {
18479: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18480: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18481: $output .= $usertypes->{$type}.' -- '.&mt('none');
18482: } else {
18483: $output .= $usertypes->{$type}.' -- '.
18484: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18485: }
18486: }
18487: }
18488: }
18489: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18490: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18491: $output .= $othertitle.' -- '.&mt('none');
18492: } else {
18493: $output .= $othertitle.' -- '.
18494: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18495: }
18496: }
18497: if ($output) {
18498: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18499: } else {
18500: $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>';
18501: }
18502: } else {
18503: $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>';
18504: }
18505: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18506: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18507: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18508: } else {
18509: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18510: }
18511: } else {
1.379 raeburn 18512: $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 18513: }
18514: if ($confighash{'passwords'}{'resetremove'}) {
18515: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18516: } else {
18517: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18518: }
18519: if ($confighash{'passwords'}{'resetcustom'}) {
18520: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18521: &mt('custom text'),600,500,undef,undef,
18522: undef,undef,'background-color:#ffffff');
18523: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18524: } else {
18525: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18526: }
18527: } elsif ($key eq 'intauth') {
18528: foreach my $item ('cost','switch','check') {
18529: my $value = $save_defaults{$key.'_'.$item};
18530: if ($item eq 'switch') {
18531: my %optiondesc = &Apache::lonlocal::texthash (
18532: 0 => 'No',
18533: 1 => 'Yes',
18534: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18535: );
18536: if ($value =~ /^(0|1|2)$/) {
18537: $value = $optiondesc{$value};
18538: } else {
18539: $value = &mt('none -- defaults to No');
18540: }
18541: } elsif ($item eq 'check') {
18542: my %optiondesc = &Apache::lonlocal::texthash (
18543: 0 => 'No',
18544: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18545: 2 => 'Yes, disallow login if stored cost is less than domain default',
18546: );
18547: if ($value =~ /^(0|1|2)$/) {
18548: $value = $optiondesc{$value};
18549: } else {
18550: $value = &mt('none -- defaults to No');
18551: }
18552: }
18553: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18554: }
18555: } elsif ($key eq 'rules') {
1.356 raeburn 18556: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18557: if ($confighash{'passwords'}{$rule} eq '') {
18558: if ($rule eq 'min') {
1.356 raeburn 18559: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18560: ' '.&mt('Default of [_1] will be used',
18561: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18562: } else {
18563: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18564: }
18565: } else {
18566: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18567: }
18568: }
1.370 raeburn 18569: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18570: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18571: my %rulenames = &Apache::lonlocal::texthash(
18572: uc => 'At least one upper case letter',
18573: lc => 'At least one lower case letter',
18574: num => 'At least one number',
18575: spec => 'At least one non-alphanumeric',
18576: );
18577: my $needed = '<ul><li>'.
18578: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18579: '</li></ul>';
1.370 raeburn 18580: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18581: } else {
18582: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18583: }
18584: } else {
18585: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18586: }
1.354 raeburn 18587: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18588: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18589: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18590: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18591: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18592: } else {
18593: my %crsownerstr;
18594: foreach my $item ('by','for') {
18595: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18596: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18597: if ($type eq 'default') {
18598: $crsownerstr{$item} .= $othertitle.', ';
18599: } elsif ($usertypes->{$type} ne '') {
18600: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18601: }
18602: }
18603: $crsownerstr{$item} =~ s/\Q, \E$//;
18604: }
18605: }
18606: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18607: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18608: }
1.354 raeburn 18609: } else {
1.359 raeburn 18610: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18611: }
18612: }
18613: $resulttext .= '</ul></li>';
18614: }
18615: }
18616: $resulttext .= '</ul>';
18617: } else {
18618: $resulttext = &mt('No changes made to password settings');
18619: }
1.355 raeburn 18620: my $cachetime = 24*60*60;
1.354 raeburn 18621: if ($updatedefaults) {
18622: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18623: if (ref($lastactref) eq 'HASH') {
18624: $lastactref->{'domdefaults'} = 1;
18625: }
18626: }
1.355 raeburn 18627: if ($updateconf) {
18628: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18629: if (ref($lastactref) eq 'HASH') {
18630: $lastactref->{'passwdconf'} = 1;
18631: }
18632: }
1.354 raeburn 18633: } else {
18634: $resulttext = '<span class="LC_error">'.
18635: &mt('An error occurred: [_1]',$putresult).'</span>';
18636: }
18637: if ($errors) {
18638: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18639: $errors.'</ul></p>';
18640: }
18641: return $resulttext;
18642: }
18643:
1.405 raeburn 18644: sub password_rule_changes {
18645: my ($prefix,$newvalues,$current,$changes) = @_;
18646: return unless ((ref($newvalues) eq 'HASH') &&
18647: (ref($current) eq 'HASH') &&
18648: (ref($changes) eq 'HASH'));
18649: my (@rules,%staticdefaults);
18650: if ($prefix eq 'passwords') {
18651: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18652: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18653: @rules = ('min','max');
18654: }
18655: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18656: foreach my $rule (@rules) {
18657: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18658: my $ruleok;
18659: if ($rule eq 'expire') {
18660: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18661: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18662: $ruleok = 1;
18663: }
18664: } elsif ($rule eq 'min') {
18665: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18666: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18667: $ruleok = 1;
18668: }
18669: }
18670: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18671: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18672: $ruleok = 1;
18673: }
18674: if ($ruleok) {
18675: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18676: if (exists($current->{$rule})) {
18677: if ($newvalues->{$rule} ne $current->{$rule}) {
18678: $changes->{'rules'} = 1;
18679: }
18680: } elsif ($rule eq 'min') {
18681: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18682: $changes->{'rules'} = 1;
18683: }
18684: } else {
18685: $changes->{'rules'} = 1;
18686: }
18687: } elsif (exists($current->{$rule})) {
18688: $changes->{'rules'} = 1;
18689: }
18690: }
18691: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18692: my @chars;
18693: foreach my $item (sort(@posschars)) {
18694: if ($item =~ /^(uc|lc|num|spec)$/) {
18695: push(@chars,$item);
18696: }
18697: }
18698: $newvalues->{'chars'} = \@chars;
18699: unless ($changes->{'rules'}) {
18700: if (ref($current->{'chars'}) eq 'ARRAY') {
18701: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18702: if (@diffs > 0) {
18703: $changes->{'rules'} = 1;
18704: }
18705: } else {
18706: if (@chars > 0) {
18707: $changes->{'rules'} = 1;
18708: }
18709: }
18710: }
18711: return;
18712: }
18713:
1.28 raeburn 18714: sub modify_usercreation {
1.27 raeburn 18715: my ($dom,%domconfig) = @_;
1.224 raeburn 18716: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18717: my $warningmsg;
1.27 raeburn 18718: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18719: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18720: if ($key eq 'cancreate') {
18721: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18722: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18723: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18724: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18725: } else {
1.224 raeburn 18726: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18727: }
18728: }
18729: }
18730: } elsif ($key eq 'email_rule') {
18731: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18732: } else {
18733: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18734: }
1.27 raeburn 18735: }
18736: }
18737: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18738: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18739: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18740: foreach my $item(@contexts) {
1.224 raeburn 18741: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18742: }
1.34 raeburn 18743: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18744: foreach my $item (@contexts) {
1.224 raeburn 18745: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18746: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18747: }
1.27 raeburn 18748: }
1.34 raeburn 18749: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18750: foreach my $item (@contexts) {
1.43 raeburn 18751: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18752: if ($cancreate{$item} ne 'any') {
18753: push(@{$changes{'cancreate'}},$item);
18754: }
18755: } else {
18756: if ($cancreate{$item} ne 'none') {
18757: push(@{$changes{'cancreate'}},$item);
18758: }
1.27 raeburn 18759: }
18760: }
18761: } else {
1.43 raeburn 18762: foreach my $item (@contexts) {
1.34 raeburn 18763: push(@{$changes{'cancreate'}},$item);
18764: }
1.27 raeburn 18765: }
1.34 raeburn 18766:
1.27 raeburn 18767: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18768: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18769: if (!grep(/^\Q$type\E$/,@username_rule)) {
18770: push(@{$changes{'username_rule'}},$type);
18771: }
18772: }
18773: foreach my $type (@username_rule) {
18774: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18775: push(@{$changes{'username_rule'}},$type);
18776: }
18777: }
18778: } else {
18779: push(@{$changes{'username_rule'}},@username_rule);
18780: }
18781:
1.32 raeburn 18782: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18783: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18784: if (!grep(/^\Q$type\E$/,@id_rule)) {
18785: push(@{$changes{'id_rule'}},$type);
18786: }
18787: }
18788: foreach my $type (@id_rule) {
18789: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18790: push(@{$changes{'id_rule'}},$type);
18791: }
18792: }
18793: } else {
18794: push(@{$changes{'id_rule'}},@id_rule);
18795: }
18796:
1.43 raeburn 18797: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18798: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18799: my %authhash;
1.43 raeburn 18800: foreach my $item (@authen_contexts) {
1.28 raeburn 18801: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18802: foreach my $auth (@authtypes) {
18803: if (grep(/^\Q$auth\E$/,@authallowed)) {
18804: $authhash{$item}{$auth} = 1;
18805: } else {
18806: $authhash{$item}{$auth} = 0;
18807: }
18808: }
18809: }
18810: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18811: foreach my $item (@authen_contexts) {
1.28 raeburn 18812: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18813: foreach my $auth (@authtypes) {
18814: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18815: push(@{$changes{'authtypes'}},$item);
18816: last;
18817: }
18818: }
18819: }
18820: }
18821: } else {
1.43 raeburn 18822: foreach my $item (@authen_contexts) {
1.28 raeburn 18823: push(@{$changes{'authtypes'}},$item);
18824: }
18825: }
18826:
1.224 raeburn 18827: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18828: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18829: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18830: $save_usercreate{'id_rule'} = \@id_rule;
18831: $save_usercreate{'username_rule'} = \@username_rule,
18832: $save_usercreate{'authtypes'} = \%authhash;
18833:
1.27 raeburn 18834: my %usercreation_hash = (
1.224 raeburn 18835: usercreation => \%save_usercreate,
18836: );
1.27 raeburn 18837:
18838: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18839: $dom);
1.50 raeburn 18840:
1.224 raeburn 18841: if ($putresult eq 'ok') {
18842: if (keys(%changes) > 0) {
18843: $resulttext = &mt('Changes made:').'<ul>';
18844: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18845: my %lt = &usercreation_types();
18846: foreach my $type (@{$changes{'cancreate'}}) {
18847: my $chgtext = $lt{$type}.', ';
18848: if ($cancreate{$type} eq 'none') {
18849: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18850: } elsif ($cancreate{$type} eq 'any') {
18851: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18852: } elsif ($cancreate{$type} eq 'official') {
18853: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18854: } elsif ($cancreate{$type} eq 'unofficial') {
18855: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18856: }
18857: $resulttext .= '<li>'.$chgtext.'</li>';
18858: }
18859: }
18860: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18861: my ($rules,$ruleorder) =
18862: &Apache::lonnet::inst_userrules($dom,'username');
18863: my $chgtext = '<ul>';
18864: foreach my $type (@username_rule) {
18865: if (ref($rules->{$type}) eq 'HASH') {
18866: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18867: }
18868: }
18869: $chgtext .= '</ul>';
18870: if (@username_rule > 0) {
18871: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18872: } else {
18873: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18874: }
18875: }
18876: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18877: my ($idrules,$idruleorder) =
18878: &Apache::lonnet::inst_userrules($dom,'id');
18879: my $chgtext = '<ul>';
18880: foreach my $type (@id_rule) {
18881: if (ref($idrules->{$type}) eq 'HASH') {
18882: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18883: }
18884: }
18885: $chgtext .= '</ul>';
18886: if (@id_rule > 0) {
18887: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18888: } else {
18889: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18890: }
18891: }
18892: my %authname = &authtype_names();
18893: my %context_title = &context_names();
18894: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18895: my $chgtext = '<ul>';
18896: foreach my $type (@{$changes{'authtypes'}}) {
18897: my @allowed;
18898: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18899: foreach my $auth (@authtypes) {
18900: if ($authhash{$type}{$auth}) {
18901: push(@allowed,$authname{$auth});
18902: }
18903: }
18904: if (@allowed > 0) {
18905: $chgtext .= join(', ',@allowed).'</li>';
18906: } else {
18907: $chgtext .= &mt('none').'</li>';
18908: }
18909: }
18910: $chgtext .= '</ul>';
18911: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18912: $resulttext .= '</li>';
18913: }
18914: $resulttext .= '</ul>';
18915: } else {
18916: $resulttext = &mt('No changes made to user creation settings');
18917: }
18918: } else {
18919: $resulttext = '<span class="LC_error">'.
18920: &mt('An error occurred: [_1]',$putresult).'</span>';
18921: }
18922: if ($warningmsg ne '') {
18923: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18924: }
18925: return $resulttext;
18926: }
18927:
18928: sub modify_selfcreation {
1.305 raeburn 18929: my ($dom,$lastactref,%domconfig) = @_;
18930: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18931: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18932: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18933: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18934: if (ref($typesref) eq 'ARRAY') {
18935: @types = @{$typesref};
18936: }
18937: if (ref($usertypesref) eq 'HASH') {
18938: %usertypes = %{$usertypesref};
1.228 raeburn 18939: }
1.303 raeburn 18940: $usertypes{'default'} = $othertitle;
1.224 raeburn 18941: #
18942: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18943: #
18944: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18945: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18946: if ($key eq 'cancreate') {
18947: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18948: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18949: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18950: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18951: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18952: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18953: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18954: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18955: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18956: } else {
18957: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18958: }
18959: }
18960: }
18961: } elsif ($key eq 'email_rule') {
18962: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18963: } else {
18964: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18965: }
18966: }
18967: }
18968: #
18969: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18970: #
18971: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18972: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18973: if ($key eq 'selfcreate') {
18974: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18975: } else {
18976: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18977: }
18978: }
18979: }
1.305 raeburn 18980: #
18981: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18982: #
18983: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18984: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18985: if ($key eq 'inststatusguest') {
18986: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18987: } else {
18988: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18989: }
18990: }
18991: }
1.224 raeburn 18992:
18993: my @contexts = ('selfcreate');
18994: @{$cancreate{'selfcreate'}} = ();
18995: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 18996: if (@types) {
18997: @{$cancreate{'statustocreate'}} = ();
18998: }
1.236 raeburn 18999: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 19000: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 19001: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19002: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19003: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19004: my %selfcreatetypes = (
19005: sso => 'users authenticated by institutional single sign on',
19006: login => 'users authenticated by institutional log-in',
1.303 raeburn 19007: email => 'users verified by e-mail',
1.50 raeburn 19008: );
1.224 raeburn 19009: #
19010: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19011: # is permitted.
19012: #
1.305 raeburn 19013: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19014:
1.305 raeburn 19015: my (@statuses,%email_rule);
1.228 raeburn 19016: foreach my $item ('login','sso','email') {
1.224 raeburn 19017: if ($item eq 'email') {
1.236 raeburn 19018: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19019: if (@types) {
19020: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19021: foreach my $status (@poss_statuses) {
19022: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19023: push(@statuses,$status);
19024: }
19025: }
19026: $save_inststatus{'inststatusguest'} = \@statuses;
19027: } else {
19028: push(@statuses,'default');
19029: }
19030: if (@statuses) {
19031: my %curr_rule;
19032: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19033: foreach my $type (@statuses) {
19034: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19035: }
1.305 raeburn 19036: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19037: foreach my $type (@statuses) {
19038: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19039: }
19040: }
19041: push(@{$cancreate{'selfcreate'}},'email');
19042: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19043: my %curremaildom;
19044: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19045: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19046: }
19047: foreach my $type (@statuses) {
19048: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19049: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19050: }
19051: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19052: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19053: }
19054: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19055: #
19056: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19057: #
19058: my $chosen = $1;
19059: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19060: my $emaildom;
19061: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19062: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19063: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19064: if (ref($curremaildom{$type}) eq 'HASH') {
19065: if (exists($curremaildom{$type}{$chosen})) {
19066: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19067: push(@{$changes{'cancreate'}},'emaildomain');
19068: }
19069: } elsif ($emaildom ne '') {
19070: push(@{$changes{'cancreate'}},'emaildomain');
19071: }
19072: } elsif ($emaildom ne '') {
19073: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19074: }
1.305 raeburn 19075: }
19076: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19077: } elsif ($chosen eq 'custom') {
19078: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19079: $email_rule{$type} = [];
19080: if (ref($emailrules) eq 'HASH') {
19081: foreach my $rule (@possemail_rules) {
19082: if (exists($emailrules->{$rule})) {
19083: push(@{$email_rule{$type}},$rule);
19084: }
19085: }
19086: }
19087: if (@{$email_rule{$type}}) {
19088: $cancreate{'emailoptions'}{$type} = 'custom';
19089: if (ref($curr_rule{$type}) eq 'ARRAY') {
19090: if (@{$curr_rule{$type}} > 0) {
19091: foreach my $rule (@{$curr_rule{$type}}) {
19092: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19093: push(@{$changes{'email_rule'}},$type);
19094: }
19095: }
19096: }
19097: foreach my $type (@{$email_rule{$type}}) {
19098: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19099: push(@{$changes{'email_rule'}},$type);
19100: }
19101: }
19102: } else {
19103: push(@{$changes{'email_rule'}},$type);
19104: }
19105: }
19106: } else {
19107: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19108: }
19109: }
19110: }
19111: if (@types) {
19112: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19113: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19114: if (@changed) {
19115: push(@{$changes{'inststatus'}},'inststatusguest');
19116: }
19117: } else {
19118: push(@{$changes{'inststatus'}},'inststatusguest');
19119: }
19120: }
19121: } else {
19122: delete($env{'form.cancreate_email'});
19123: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19124: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19125: push(@{$changes{'inststatus'}},'inststatusguest');
19126: }
19127: }
19128: }
19129: } else {
19130: $save_inststatus{'inststatusguest'} = [];
19131: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19132: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19133: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19134: }
19135: }
1.224 raeburn 19136: }
19137: } else {
19138: if ($env{'form.cancreate_'.$item}) {
19139: push(@{$cancreate{'selfcreate'}},$item);
19140: }
19141: }
19142: }
1.305 raeburn 19143: my (%userinfo,%savecaptcha);
1.224 raeburn 19144: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19145: #
1.228 raeburn 19146: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19147: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19148: #
1.236 raeburn 19149:
1.244 raeburn 19150: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19151: push(@contexts,'emailusername');
1.305 raeburn 19152: if (@statuses) {
19153: foreach my $type (@statuses) {
1.228 raeburn 19154: if (ref($infofields) eq 'ARRAY') {
19155: foreach my $field (@{$infofields}) {
19156: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19157: $cancreate{'emailusername'}{$type}{$field} = $1;
19158: }
19159: }
1.224 raeburn 19160: }
19161: }
19162: }
19163: #
19164: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19165: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19166: #
19167:
19168: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19169: @approvalnotify = sort(@approvalnotify);
19170: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19171: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19172: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19173: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19174: push(@{$changes{'cancreate'}},'notify');
19175: }
19176: } else {
19177: if ($cancreate{'notify'}{'approval'}) {
19178: push(@{$changes{'cancreate'}},'notify');
19179: }
19180: }
19181: } elsif ($cancreate{'notify'}{'approval'}) {
19182: push(@{$changes{'cancreate'}},'notify');
19183: }
19184:
19185: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19186: }
19187: #
1.236 raeburn 19188: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19189: # institutional log-in.
19190: #
19191: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19192: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19193: ($domdefaults{'auth_def'} eq 'localauth'))) {
19194: $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.').' '.
19195: &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.');
19196: }
19197: }
19198: my @fields = ('lastname','firstname','middlename','generation',
19199: 'permanentemail','id');
1.240 raeburn 19200: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19201: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19202: #
19203: # Where usernames may created for institutional log-in and/or institutional single sign on:
19204: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19205: # may self-create accounts
19206: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19207: # which the user may supply, if institutional data is unavailable.
19208: #
19209: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19210: if (@types) {
1.305 raeburn 19211: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19212: push(@contexts,'statustocreate');
1.303 raeburn 19213: foreach my $type (@types) {
1.224 raeburn 19214: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19215: foreach my $field (@fields) {
19216: if (grep(/^\Q$field\E$/,@modifiable)) {
19217: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19218: } else {
19219: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19220: }
19221: }
19222: }
19223: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19224: foreach my $type (@types) {
1.224 raeburn 19225: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19226: foreach my $field (@fields) {
19227: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19228: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19229: push(@{$changes{'selfcreate'}},$type);
19230: last;
19231: }
19232: }
19233: }
19234: }
19235: } else {
1.303 raeburn 19236: foreach my $type (@types) {
1.224 raeburn 19237: push(@{$changes{'selfcreate'}},$type);
19238: }
19239: }
19240: }
1.240 raeburn 19241: foreach my $field (@shibfields) {
19242: if ($env{'form.shibenv_'.$field} ne '') {
19243: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19244: }
19245: }
19246: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19247: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19248: foreach my $field (@shibfields) {
19249: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19250: push(@{$changes{'cancreate'}},'shibenv');
19251: }
19252: }
19253: } else {
19254: foreach my $field (@shibfields) {
19255: if ($env{'form.shibenv_'.$field}) {
19256: push(@{$changes{'cancreate'}},'shibenv');
19257: last;
19258: }
19259: }
19260: }
19261: }
1.224 raeburn 19262: }
19263: foreach my $item (@contexts) {
19264: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19265: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19266: if (ref($cancreate{$item}) eq 'ARRAY') {
19267: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19268: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19269: push(@{$changes{'cancreate'}},$item);
19270: }
19271: }
19272: }
19273: }
19274: if (ref($cancreate{$item}) eq 'ARRAY') {
19275: foreach my $type (@{$cancreate{$item}}) {
19276: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19277: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19278: push(@{$changes{'cancreate'}},$item);
19279: }
19280: }
19281: }
19282: }
19283: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19284: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19285: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19286: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19287: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19288: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19289: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19290: push(@{$changes{'cancreate'}},$item);
19291: }
19292: }
19293: }
1.305 raeburn 19294: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19295: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19296: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19297: push(@{$changes{'cancreate'}},$item);
19298: }
1.224 raeburn 19299: }
19300: }
19301: }
1.305 raeburn 19302: foreach my $type (keys(%{$cancreate{$item}})) {
19303: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19304: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19305: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19306: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19307: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19308: push(@{$changes{'cancreate'}},$item);
19309: }
19310: }
19311: } else {
19312: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19313: push(@{$changes{'cancreate'}},$item);
19314: }
19315: }
19316: }
1.305 raeburn 19317: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19318: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19319: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19320: push(@{$changes{'cancreate'}},$item);
19321: }
1.224 raeburn 19322: }
19323: }
19324: }
19325: }
19326: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19327: if (ref($cancreate{$item}) eq 'ARRAY') {
19328: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19329: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19330: push(@{$changes{'cancreate'}},$item);
19331: }
19332: }
1.305 raeburn 19333: }
19334: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19335: if (ref($cancreate{$item}) eq 'HASH') {
19336: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19337: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19338: }
19339: }
19340: } elsif ($item eq 'emailusername') {
1.228 raeburn 19341: if (ref($cancreate{$item}) eq 'HASH') {
19342: foreach my $type (keys(%{$cancreate{$item}})) {
19343: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19344: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19345: if ($cancreate{$item}{$type}{$field}) {
19346: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19347: push(@{$changes{'cancreate'}},$item);
19348: }
19349: last;
19350: }
19351: }
19352: }
19353: }
1.224 raeburn 19354: }
19355: }
19356: }
19357: #
19358: # Populate %save_usercreate hash with updates to self-creation configuration.
19359: #
19360: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19361: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19362: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19363: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19364: if (ref($cancreate{'notify'}) eq 'HASH') {
19365: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19366: }
1.236 raeburn 19367: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19368: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19369: }
1.303 raeburn 19370: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19371: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19372: }
1.305 raeburn 19373: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19374: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19375: }
1.303 raeburn 19376: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19377: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19378: }
1.224 raeburn 19379: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19380: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19381: }
1.240 raeburn 19382: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19383: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19384: }
1.224 raeburn 19385: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19386: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19387:
19388: my %userconfig_hash = (
19389: usercreation => \%save_usercreate,
19390: usermodification => \%save_usermodify,
1.305 raeburn 19391: inststatus => \%save_inststatus,
1.224 raeburn 19392: );
1.305 raeburn 19393:
1.224 raeburn 19394: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19395: $dom);
19396: #
1.305 raeburn 19397: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19398: #
1.27 raeburn 19399: if ($putresult eq 'ok') {
19400: if (keys(%changes) > 0) {
19401: $resulttext = &mt('Changes made:').'<ul>';
19402: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19403: my %lt = &selfcreation_types();
1.34 raeburn 19404: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19405: my $chgtext = '';
1.45 raeburn 19406: if ($type eq 'selfcreate') {
1.50 raeburn 19407: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19408: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19409: } else {
1.224 raeburn 19410: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19411: '<ul>';
1.50 raeburn 19412: foreach my $case (@{$cancreate{$type}}) {
19413: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19414: }
19415: $chgtext .= '</ul>';
1.100 raeburn 19416: if (ref($cancreate{$type}) eq 'ARRAY') {
19417: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19418: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19419: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19420: $chgtext .= '<span class="LC_warning">'.
19421: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19422: '</span><br />';
19423: }
19424: }
19425: }
19426: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19427: if (!@statuses) {
19428: $chgtext .= '<span class="LC_warning">'.
19429: &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.").
19430: '</span><br />';
1.303 raeburn 19431:
1.100 raeburn 19432: }
19433: }
19434: }
1.43 raeburn 19435: }
1.240 raeburn 19436: } elsif ($type eq 'shibenv') {
19437: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19438: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19439: } else {
19440: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19441: '<ul>';
19442: foreach my $field (@shibfields) {
19443: next if ($cancreate{$type}{$field} eq '');
19444: if ($field eq 'inststatus') {
19445: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19446: } else {
19447: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19448: }
19449: }
19450: $chgtext .= '</ul>';
1.303 raeburn 19451: }
1.93 raeburn 19452: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19453: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19454: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19455: if (@{$cancreate{'selfcreate'}} > 0) {
19456: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19457: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19458: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19459: $chgtext .= '<br />'.
19460: '<span class="LC_warning">'.
19461: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19462: '</span>';
19463: }
1.303 raeburn 19464: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19465: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19466: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19467: } else {
19468: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19469: }
19470: $chgtext .= '<ul>';
19471: foreach my $case (@{$cancreate{$type}}) {
19472: if ($case eq 'default') {
19473: $chgtext .= '<li>'.$othertitle.'</li>';
19474: } else {
1.303 raeburn 19475: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19476: }
19477: }
1.100 raeburn 19478: $chgtext .= '</ul>';
19479: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19480: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19481: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19482: '</span>';
1.100 raeburn 19483: }
19484: }
19485: } else {
19486: if (@{$cancreate{$type}} == 0) {
19487: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19488: } else {
19489: $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 19490: }
19491: }
1.303 raeburn 19492: $chgtext .= '<br />';
1.93 raeburn 19493: }
1.236 raeburn 19494: } elsif ($type eq 'selfcreateprocessing') {
19495: my %choices = &Apache::lonlocal::texthash (
19496: automatic => 'Automatic approval',
19497: approval => 'Queued for approval',
19498: );
1.305 raeburn 19499: if (@types) {
19500: if (@statuses) {
1.425 raeburn 19501: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19502: '<ul>';
1.305 raeburn 19503: foreach my $status (@statuses) {
19504: if ($status eq 'default') {
19505: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19506: } else {
1.305 raeburn 19507: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19508: }
19509: }
19510: $chgtext .= '</ul>';
19511: }
19512: } else {
19513: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19514: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19515: }
19516: } elsif ($type eq 'emailverified') {
19517: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19518: all => 'Same as e-mail',
19519: first => 'Omit @domain',
19520: free => 'Free to choose',
1.303 raeburn 19521: );
1.305 raeburn 19522: if (@types) {
19523: if (@statuses) {
1.303 raeburn 19524: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19525: '<ul>';
1.305 raeburn 19526: foreach my $status (@statuses) {
1.362 raeburn 19527: if ($status eq 'default') {
1.305 raeburn 19528: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19529: } else {
1.305 raeburn 19530: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19531: }
19532: }
19533: $chgtext .= '</ul>';
19534: }
19535: } else {
1.305 raeburn 19536: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19537: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19538: }
1.305 raeburn 19539: } elsif ($type eq 'emailoptions') {
19540: my %options = &Apache::lonlocal::texthash (
19541: any => 'Any e-mail',
19542: inst => 'Institutional only',
19543: noninst => 'Non-institutional only',
19544: custom => 'Custom restrictions',
19545: );
19546: if (@types) {
19547: if (@statuses) {
19548: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19549: '<ul>';
19550: foreach my $status (@statuses) {
19551: if ($type eq 'default') {
19552: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19553: } else {
19554: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19555: }
19556: }
1.305 raeburn 19557: $chgtext .= '</ul>';
19558: }
19559: } else {
19560: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19561: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19562: } else {
19563: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19564: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19565: }
1.305 raeburn 19566: }
19567: } elsif ($type eq 'emaildomain') {
19568: my $output;
19569: if (@statuses) {
19570: foreach my $type (@statuses) {
19571: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19572: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19573: if ($type eq 'default') {
19574: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19575: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19576: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19577: } else {
19578: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19579: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19580: }
1.303 raeburn 19581: } else {
1.305 raeburn 19582: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19583: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19584: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19585: } else {
19586: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19587: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19588: }
1.303 raeburn 19589: }
1.305 raeburn 19590: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19591: if ($type eq 'default') {
19592: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19593: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19594: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19595: } else {
19596: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19597: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19598: }
1.303 raeburn 19599: } else {
1.305 raeburn 19600: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19601: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19602: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19603: } else {
19604: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19605: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19606: }
1.303 raeburn 19607: }
19608: }
19609: }
19610: }
1.305 raeburn 19611: }
19612: if ($output ne '') {
19613: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19614: '<ul>'.$output.'</ul>';
1.236 raeburn 19615: }
1.165 raeburn 19616: } elsif ($type eq 'captcha') {
1.224 raeburn 19617: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19618: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19619: } else {
19620: my %captchas = &captcha_phrases();
1.224 raeburn 19621: if ($captchas{$savecaptcha{$type}}) {
19622: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19623: } else {
1.210 raeburn 19624: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19625: }
19626: }
19627: } elsif ($type eq 'recaptchakeys') {
19628: my ($privkey,$pubkey);
1.224 raeburn 19629: if (ref($savecaptcha{$type}) eq 'HASH') {
19630: $pubkey = $savecaptcha{$type}{'public'};
19631: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19632: }
19633: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19634: if (!$pubkey) {
19635: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19636: } else {
19637: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19638: }
19639: if (!$privkey) {
19640: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19641: } else {
19642: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19643: }
19644: $chgtext .= '</ul>';
1.269 raeburn 19645: } elsif ($type eq 'recaptchaversion') {
19646: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19647: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19648: }
1.224 raeburn 19649: } elsif ($type eq 'emailusername') {
19650: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19651: if (@statuses) {
19652: foreach my $type (@statuses) {
1.228 raeburn 19653: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19654: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19655: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19656: '<ul>';
19657: foreach my $field (@{$infofields}) {
19658: if ($cancreate{'emailusername'}{$type}{$field}) {
19659: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19660: }
19661: }
1.245 raeburn 19662: $chgtext .= '</ul>';
19663: } else {
1.303 raeburn 19664: $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 19665: }
19666: } else {
1.303 raeburn 19667: $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 19668: }
19669: }
19670: }
19671: }
19672: } elsif ($type eq 'notify') {
1.303 raeburn 19673: my $numapprove = 0;
1.224 raeburn 19674: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19675: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19676: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19677: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19678: $numapprove ++;
1.224 raeburn 19679: }
19680: }
1.43 raeburn 19681: }
1.303 raeburn 19682: unless ($numapprove) {
19683: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19684: }
1.34 raeburn 19685: }
1.224 raeburn 19686: if ($chgtext) {
19687: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19688: }
19689: }
19690: }
1.305 raeburn 19691: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19692: my ($emailrules,$emailruleorder) =
19693: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19694: foreach my $type (@{$changes{'email_rule'}}) {
19695: if (ref($email_rule{$type}) eq 'ARRAY') {
19696: my $chgtext = '<ul>';
19697: foreach my $rule (@{$email_rule{$type}}) {
19698: if (ref($emailrules->{$rule}) eq 'HASH') {
19699: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19700: }
19701: }
19702: $chgtext .= '</ul>';
1.310 raeburn 19703: my $typename;
1.305 raeburn 19704: if (@types) {
19705: if ($type eq 'default') {
19706: $typename = $othertitle;
19707: } else {
19708: $typename = $usertypes{$type};
1.425 raeburn 19709: }
1.305 raeburn 19710: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19711: }
19712: if (@{$email_rule{$type}} > 0) {
19713: $resulttext .= '<li>'.
19714: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19715: $usertypes{$type}).
19716: $chgtext.
19717: '</li>';
19718: } else {
19719: $resulttext .= '<li>'.
1.310 raeburn 19720: &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 19721: '</li>'.
1.310 raeburn 19722: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19723: }
1.43 raeburn 19724: }
19725: }
1.305 raeburn 19726: }
19727: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19728: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19729: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19730: my $chgtext = '<ul>';
19731: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19732: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19733: }
19734: $chgtext .= '</ul>';
19735: $resulttext .= '<li>'.
19736: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19737: $chgtext.
19738: '</li>';
19739: } else {
19740: $resulttext .= '<li>'.
19741: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19742: '</li>';
19743: }
1.43 raeburn 19744: }
19745: }
1.224 raeburn 19746: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19747: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19748: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19749: foreach my $type (@{$changes{'selfcreate'}}) {
19750: my $typename = $type;
1.303 raeburn 19751: if (keys(%usertypes) > 0) {
19752: if ($usertypes{$type} ne '') {
19753: $typename = $usertypes{$type};
1.224 raeburn 19754: }
19755: }
19756: my @modifiable;
19757: $resulttext .= '<li>'.
19758: &mt('Self-creation of account by users with status: [_1]',
19759: '<span class="LC_cusr_emph">'.$typename.'</span>').
19760: ' - '.&mt('modifiable fields (if institutional data blank): ');
19761: foreach my $field (@fields) {
19762: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19763: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19764: }
19765: }
1.224 raeburn 19766: if (@modifiable > 0) {
19767: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19768: } else {
1.224 raeburn 19769: $resulttext .= &mt('none');
1.43 raeburn 19770: }
1.224 raeburn 19771: $resulttext .= '</li>';
1.28 raeburn 19772: }
1.224 raeburn 19773: $resulttext .= '</ul></li>';
1.28 raeburn 19774: }
1.27 raeburn 19775: $resulttext .= '</ul>';
1.305 raeburn 19776: my $cachetime = 24*60*60;
19777: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19778: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19779: if (ref($lastactref) eq 'HASH') {
19780: $lastactref->{'domdefaults'} = 1;
19781: }
1.27 raeburn 19782: } else {
1.224 raeburn 19783: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19784: }
19785: } else {
19786: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19787: &mt('An error occurred: [_1]',$putresult).'</span>';
19788: }
1.43 raeburn 19789: if ($warningmsg ne '') {
19790: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19791: }
1.23 raeburn 19792: return $resulttext;
19793: }
19794:
1.165 raeburn 19795: sub process_captcha {
1.369 raeburn 19796: my ($container,$changes,$newsettings,$currsettings) = @_;
19797: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19798: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19799: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19800: $newsettings->{'captcha'} = 'original';
19801: }
1.369 raeburn 19802: my %current;
19803: if (ref($currsettings) eq 'HASH') {
19804: %current = %{$currsettings};
19805: }
19806: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19807: if ($container eq 'cancreate') {
1.169 raeburn 19808: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19809: push(@{$changes->{'cancreate'}},'captcha');
19810: } elsif (!defined($changes->{'cancreate'})) {
19811: $changes->{'cancreate'} = ['captcha'];
19812: }
1.368 raeburn 19813: } elsif ($container eq 'passwords') {
19814: $changes->{'reset'} = 1;
1.169 raeburn 19815: } else {
19816: $changes->{'captcha'} = 1;
1.165 raeburn 19817: }
19818: }
1.269 raeburn 19819: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19820: if ($newsettings->{'captcha'} eq 'recaptcha') {
19821: $newpub = $env{'form.'.$container.'_recaptchapub'};
19822: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19823: $newpub =~ s/[^\w\-]//g;
19824: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19825: $newsettings->{'recaptchakeys'} = {
19826: public => $newpub,
19827: private => $newpriv,
19828: };
1.269 raeburn 19829: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19830: $newversion =~ s/\D//g;
19831: if ($newversion ne '2') {
19832: $newversion = 1;
19833: }
19834: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19835: }
1.369 raeburn 19836: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19837: $currpub = $current{'recaptchakeys'}{'public'};
19838: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19839: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19840: $newsettings->{'recaptchakeys'} = {
19841: public => '',
19842: private => '',
19843: }
19844: }
1.165 raeburn 19845: }
1.369 raeburn 19846: if ($current{'captcha'} eq 'recaptcha') {
19847: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19848: if ($currversion ne '2') {
19849: $currversion = 1;
19850: }
19851: }
19852: if ($currversion ne $newversion) {
19853: if ($container eq 'cancreate') {
19854: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19855: push(@{$changes->{'cancreate'}},'recaptchaversion');
19856: } elsif (!defined($changes->{'cancreate'})) {
19857: $changes->{'cancreate'} = ['recaptchaversion'];
19858: }
1.368 raeburn 19859: } elsif ($container eq 'passwords') {
19860: $changes->{'reset'} = 1;
1.269 raeburn 19861: } else {
19862: $changes->{'recaptchaversion'} = 1;
19863: }
19864: }
1.165 raeburn 19865: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19866: if ($container eq 'cancreate') {
19867: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19868: push(@{$changes->{'cancreate'}},'recaptchakeys');
19869: } elsif (!defined($changes->{'cancreate'})) {
19870: $changes->{'cancreate'} = ['recaptchakeys'];
19871: }
1.368 raeburn 19872: } elsif ($container eq 'passwords') {
19873: $changes->{'reset'} = 1;
1.169 raeburn 19874: } else {
1.210 raeburn 19875: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19876: }
19877: }
19878: return;
19879: }
19880:
1.33 raeburn 19881: sub modify_usermodification {
19882: my ($dom,%domconfig) = @_;
1.224 raeburn 19883: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19884: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19885: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19886: if ($key eq 'selfcreate') {
19887: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19888: } else {
19889: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19890: }
1.33 raeburn 19891: }
19892: }
1.443 raeburn 19893: my @contexts = ('author','coauthor','course');
1.33 raeburn 19894: my %context_title = (
19895: author => 'In author context',
1.443 raeburn 19896: coauthor => 'As co-author manager',
1.33 raeburn 19897: course => 'In course context',
19898: );
19899: my @fields = ('lastname','firstname','middlename','generation',
19900: 'permanentemail','id');
19901: my %roles = (
19902: author => ['ca','aa'],
1.443 raeburn 19903: coauthor => ['ca','aa'],
1.33 raeburn 19904: course => ['st','ep','ta','in','cr'],
19905: );
19906: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19907: foreach my $context (@contexts) {
1.443 raeburn 19908: my $prefix = 'canmodify';
19909: if ($context eq 'coauthor') {
19910: $prefix = 'cacanmodify';
19911: }
1.33 raeburn 19912: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19913: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19914: foreach my $item (@fields) {
19915: if (grep(/^\Q$item\E$/,@modifiable)) {
19916: $modifyhash{$context}{$role}{$item} = 1;
19917: } else {
19918: $modifyhash{$context}{$role}{$item} = 0;
19919: }
19920: }
19921: }
19922: if (ref($curr_usermodification{$context}) eq 'HASH') {
19923: foreach my $role (@{$roles{$context}}) {
19924: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19925: foreach my $field (@fields) {
19926: if ($modifyhash{$context}{$role}{$field} ne
19927: $curr_usermodification{$context}{$role}{$field}) {
19928: push(@{$changes{$context}},$role);
19929: last;
19930: }
19931: }
19932: }
19933: }
19934: } else {
19935: foreach my $context (@contexts) {
19936: foreach my $role (@{$roles{$context}}) {
19937: push(@{$changes{$context}},$role);
19938: }
19939: }
19940: }
19941: }
19942: my %usermodification_hash = (
19943: usermodification => \%modifyhash,
19944: );
19945: my $putresult = &Apache::lonnet::put_dom('configuration',
19946: \%usermodification_hash,$dom);
19947: if ($putresult eq 'ok') {
19948: if (keys(%changes) > 0) {
19949: $resulttext = &mt('Changes made: ').'<ul>';
19950: foreach my $context (@contexts) {
19951: if (ref($changes{$context}) eq 'ARRAY') {
19952: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19953: if (ref($changes{$context}) eq 'ARRAY') {
19954: foreach my $role (@{$changes{$context}}) {
19955: my $rolename;
1.224 raeburn 19956: if ($role eq 'cr') {
19957: $rolename = &mt('Custom');
1.33 raeburn 19958: } else {
1.224 raeburn 19959: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19960: }
19961: my @modifiable;
1.224 raeburn 19962: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19963: foreach my $field (@fields) {
19964: if ($modifyhash{$context}{$role}{$field}) {
19965: push(@modifiable,$fieldtitles{$field});
19966: }
19967: }
19968: if (@modifiable > 0) {
19969: $resulttext .= join(', ',@modifiable);
19970: } else {
19971: $resulttext .= &mt('none');
19972: }
19973: $resulttext .= '</li>';
19974: }
19975: $resulttext .= '</ul></li>';
19976: }
19977: }
19978: }
19979: $resulttext .= '</ul>';
19980: } else {
19981: $resulttext = &mt('No changes made to user modification settings');
19982: }
19983: } else {
19984: $resulttext = '<span class="LC_error">'.
19985: &mt('An error occurred: [_1]',$putresult).'</span>';
19986: }
19987: return $resulttext;
19988: }
19989:
1.43 raeburn 19990: sub modify_defaults {
1.212 raeburn 19991: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19992: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 19993: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 19994: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 19995: 'portal_def');
1.325 raeburn 19996: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 19997: foreach my $item (@items) {
19998: $newvalues{$item} = $env{'form.'.$item};
19999: if ($item eq 'auth_def') {
20000: if ($newvalues{$item} ne '') {
20001: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20002: push(@errors,$item);
20003: }
20004: }
20005: } elsif ($item eq 'lang_def') {
20006: if ($newvalues{$item} ne '') {
20007: if ($newvalues{$item} =~ /^(\w+)/) {
20008: my $langcode = $1;
1.103 raeburn 20009: if ($langcode ne 'x_chef') {
20010: if (code2language($langcode) eq '') {
20011: push(@errors,$item);
20012: }
1.43 raeburn 20013: }
20014: } else {
20015: push(@errors,$item);
20016: }
20017: }
1.54 raeburn 20018: } elsif ($item eq 'timezone_def') {
20019: if ($newvalues{$item} ne '') {
1.62 raeburn 20020: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20021: push(@errors,$item);
20022: }
20023: }
1.68 raeburn 20024: } elsif ($item eq 'datelocale_def') {
20025: if ($newvalues{$item} ne '') {
20026: my @datelocale_ids = DateTime::Locale->ids();
20027: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20028: push(@errors,$item);
20029: }
20030: }
1.141 raeburn 20031: } elsif ($item eq 'portal_def') {
20032: if ($newvalues{$item} ne '') {
1.414 raeburn 20033: 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])\/?$/) {
20034: foreach my $field ('email','web') {
20035: if ($env{'form.'.$item.'_'.$field}) {
20036: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20037: }
20038: }
20039: } else {
1.141 raeburn 20040: push(@errors,$item);
20041: }
20042: }
1.43 raeburn 20043: }
20044: if (grep(/^\Q$item\E$/,@errors)) {
20045: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20046: if ($item eq 'portal_def') {
20047: if ($domdefaults{$item}) {
20048: foreach my $field ('email','web') {
20049: if (exists($domdefaults{$item.'_'.$field})) {
20050: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20051: }
20052: }
20053: }
20054: }
1.43 raeburn 20055: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20056: $changes{$item} = 1;
20057: }
1.414 raeburn 20058: if ($item eq 'portal_def') {
20059: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20060: if ($newvalues{$item} eq '') {
1.414 raeburn 20061: foreach my $field ('email','web') {
20062: if (exists($domdefaults{$item.'_'.$field})) {
20063: delete($domdefaults{$item.'_'.$field});
20064: }
20065: }
20066: } else {
20067: unless ($changes{$item}) {
20068: foreach my $field ('email','web') {
20069: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20070: $changes{$item} = 1;
20071: last;
20072: }
20073: }
20074: }
20075: foreach my $field ('email','web') {
20076: if ($newvalues{$item.'_'.$field}) {
20077: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20078: } elsif (exists($domdefaults{$item.'_'.$field})) {
20079: delete($domdefaults{$item.'_'.$field});
20080: }
20081: }
20082: }
20083: }
20084: }
1.72 raeburn 20085: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20086: }
1.354 raeburn 20087: my %staticdefaults = (
20088: 'intauth_cost' => 10,
20089: 'intauth_check' => 0,
20090: 'intauth_switch' => 0,
20091: );
20092: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20093: if (exists($domdefaults{$item})) {
20094: $newvalues{$item} = $domdefaults{$item};
20095: } else {
20096: $newvalues{$item} = $staticdefaults{$item};
20097: }
20098: }
1.409 raeburn 20099: my ($unamemaprules,$ruleorder);
20100: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20101: if (@possunamemaprules) {
20102: ($unamemaprules,$ruleorder) =
20103: &Apache::lonnet::inst_userrules($dom,'unamemap');
20104: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20105: if (@{$ruleorder} > 0) {
20106: my %possrules;
20107: map { $possrules{$_} = 1; } @possunamemaprules;
20108: foreach my $rule (@{$ruleorder}) {
20109: if ($possrules{$rule}) {
20110: push(@{$newvalues{'unamemap_rule'}},$rule);
20111: }
20112: }
20113: }
20114: }
20115: }
20116: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20117: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20118: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20119: $newvalues{'unamemap_rule'});
20120: if (@rulediffs) {
20121: $changes{'unamemap_rule'} = 1;
20122: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20123: }
20124: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20125: $changes{'unamemap_rule'} = 1;
20126: delete($domdefaults{'unamemap_rule'});
20127: }
20128: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20129: if (@{$newvalues{'unamemap_rule'}} > 0) {
20130: $changes{'unamemap_rule'} = 1;
20131: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20132: }
20133: }
1.43 raeburn 20134: my %defaults_hash = (
1.72 raeburn 20135: defaults => \%newvalues,
20136: );
1.43 raeburn 20137: my $title = &defaults_titles();
1.236 raeburn 20138:
20139: my $currinststatus;
20140: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20141: $currinststatus = $domconfig{'inststatus'};
20142: } else {
20143: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20144: $currinststatus = {
20145: inststatustypes => $usertypes,
20146: inststatusorder => $types,
20147: inststatusguest => [],
20148: };
20149: }
20150: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20151: my @allpos;
20152: my %alltypes;
1.305 raeburn 20153: my @inststatusguest;
20154: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20155: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20156: unless (grep(/^\Q$type\E$/,@todelete)) {
20157: push(@inststatusguest,$type);
20158: }
20159: }
20160: }
20161: my ($currtitles,$currorder);
1.236 raeburn 20162: if (ref($currinststatus) eq 'HASH') {
20163: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20164: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20165: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20166: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20167: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20168: }
20169: }
20170: unless (grep(/^\Q$type\E$/,@todelete)) {
20171: my $position = $env{'form.inststatus_pos_'.$type};
20172: $position =~ s/\D+//g;
20173: $allpos[$position] = $type;
20174: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20175: $alltypes{$type} =~ s/`//g;
20176: }
20177: }
20178: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20179: $currtitles =~ s/,$//;
20180: }
20181: }
20182: if ($env{'form.addinststatus'}) {
20183: my $newtype = $env{'form.addinststatus'};
20184: $newtype =~ s/\W//g;
20185: unless (exists($alltypes{$newtype})) {
20186: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20187: $alltypes{$newtype} =~ s/`//g;
20188: my $position = $env{'form.addinststatus_pos'};
20189: $position =~ s/\D+//g;
20190: if ($position ne '') {
20191: $allpos[$position] = $newtype;
20192: }
20193: }
20194: }
1.305 raeburn 20195: my @orderedstatus;
1.236 raeburn 20196: foreach my $type (@allpos) {
20197: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20198: push(@orderedstatus,$type);
20199: }
20200: }
20201: foreach my $type (keys(%alltypes)) {
20202: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20203: delete($alltypes{$type});
20204: }
20205: }
20206: $defaults_hash{'inststatus'} = {
20207: inststatustypes => \%alltypes,
20208: inststatusorder => \@orderedstatus,
1.305 raeburn 20209: inststatusguest => \@inststatusguest,
1.236 raeburn 20210: };
20211: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20212: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20213: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20214: }
20215: }
20216: if ($currorder ne join(',',@orderedstatus)) {
20217: $changes{'inststatus'}{'inststatusorder'} = 1;
20218: }
20219: my $newtitles;
20220: foreach my $item (@orderedstatus) {
20221: $newtitles .= $alltypes{$item}.',';
20222: }
20223: $newtitles =~ s/,$//;
20224: if ($currtitles ne $newtitles) {
20225: $changes{'inststatus'}{'inststatustypes'} = 1;
20226: }
1.43 raeburn 20227: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20228: $dom);
20229: if ($putresult eq 'ok') {
20230: if (keys(%changes) > 0) {
20231: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20232: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20233: 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";
20234: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20235: if ($item eq 'inststatus') {
20236: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20237: if (@orderedstatus) {
1.236 raeburn 20238: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20239: foreach my $type (@orderedstatus) {
20240: $resulttext .= $alltypes{$type}.', ';
20241: }
20242: $resulttext =~ s/, $//;
20243: $resulttext .= '</li>';
1.305 raeburn 20244: } else {
1.425 raeburn 20245: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20246: }
20247: }
1.409 raeburn 20248: } elsif ($item eq 'unamemap_rule') {
20249: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20250: my @rulenames;
20251: if (ref($unamemaprules) eq 'HASH') {
20252: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20253: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20254: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20255: }
20256: }
20257: }
20258: if (@rulenames) {
20259: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20260: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20261: '</li>';
20262: } else {
20263: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20264: }
20265: } else {
20266: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20267: }
1.236 raeburn 20268: } else {
20269: my $value = $env{'form.'.$item};
20270: if ($value eq '') {
20271: $value = &mt('none');
20272: } elsif ($item eq 'auth_def') {
20273: my %authnames = &authtype_names();
20274: my %shortauth = (
20275: internal => 'int',
20276: krb4 => 'krb4',
20277: krb5 => 'krb5',
20278: localauth => 'loc',
1.325 raeburn 20279: lti => 'lti',
1.236 raeburn 20280: );
20281: $value = $authnames{$shortauth{$value}};
20282: }
20283: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20284: $mailmsgtext .= "$title->{$item} set to $value\n";
20285: if ($item eq 'portal_def') {
20286: if ($env{'form.'.$item} ne '') {
20287: foreach my $field ('email','web') {
20288: $value = $env{'form.'.$item.'_'.$field};
20289: if ($value) {
20290: $value = &mt('Yes');
20291: } else {
20292: $value = &mt('No');
20293: }
20294: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20295: }
20296: }
20297: }
1.43 raeburn 20298: }
20299: }
20300: $resulttext .= '</ul>';
20301: $mailmsgtext .= "\n";
20302: my $cachetime = 24*60*60;
1.72 raeburn 20303: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20304: if (ref($lastactref) eq 'HASH') {
20305: $lastactref->{'domdefaults'} = 1;
20306: }
1.68 raeburn 20307: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20308: my $notify = 1;
20309: if (ref($domconfig{'contacts'}) eq 'HASH') {
20310: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20311: $notify = 0;
20312: }
20313: }
20314: if ($notify) {
20315: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20316: "LON-CAPA Domain Settings Change - $dom",
20317: $mailmsgtext);
20318: }
1.54 raeburn 20319: }
1.43 raeburn 20320: } else {
1.54 raeburn 20321: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20322: }
20323: } else {
20324: $resulttext = '<span class="LC_error">'.
20325: &mt('An error occurred: [_1]',$putresult).'</span>';
20326: }
20327: if (@errors > 0) {
20328: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20329: foreach my $item (@errors) {
20330: $resulttext .= ' "'.$title->{$item}.'",';
20331: }
20332: $resulttext =~ s/,$//;
20333: }
20334: return $resulttext;
20335: }
20336:
1.46 raeburn 20337: sub modify_scantron {
1.205 raeburn 20338: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20339: my ($resulttext,%confhash,%changes,$errors);
20340: my $custom = 'custom.tab';
20341: my $default = 'default.tab';
20342: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20343: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20344: &config_check($dom,$confname,$servadm);
20345: if ($env{'form.scantronformat.filename'} ne '') {
20346: my $error;
20347: if ($configuserok eq 'ok') {
20348: if ($switchserver) {
1.130 raeburn 20349: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20350: } else {
20351: if ($author_ok eq 'ok') {
1.421 raeburn 20352: my $modified = [];
1.46 raeburn 20353: my ($result,$scantronurl) =
1.421 raeburn 20354: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20355: $confname,'scantron','','',$custom,
20356: $modified);
1.46 raeburn 20357: if ($result eq 'ok') {
20358: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20359: $changes{'scantronformat'} = 1;
1.421 raeburn 20360: &update_modify_urls($r,$modified);
1.46 raeburn 20361: } else {
20362: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20363: }
20364: } else {
20365: $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);
20366: }
20367: }
20368: } else {
20369: $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);
20370: }
20371: if ($error) {
20372: &Apache::lonnet::logthis($error);
20373: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20374: }
20375: }
1.48 raeburn 20376: if (ref($domconfig{'scantron'}) eq 'HASH') {
20377: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20378: if ($env{'form.scantronformat_del'}) {
20379: $confhash{'scantron'}{'scantronformat'} = '';
20380: $changes{'scantronformat'} = 1;
1.347 raeburn 20381: } else {
20382: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20383: }
20384: }
20385: }
1.347 raeburn 20386: my @options = ('hdr','pad','rem');
1.346 raeburn 20387: my @fields = &scantroncsv_fields();
20388: my %titles = &scantronconfig_titles();
1.347 raeburn 20389: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20390: my ($newdat,$currdat,%newcol,%currcol);
20391: if (grep(/^dat$/,@formats)) {
20392: $confhash{'scantron'}{config}{dat} = 1;
20393: $newdat = 1;
20394: } else {
20395: $newdat = 0;
20396: }
20397: if (grep(/^csv$/,@formats)) {
20398: my %bynum;
20399: foreach my $field (@fields) {
20400: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20401: my $posscol = $1;
20402: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20403: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20404: $bynum{$posscol} = $field;
20405: $newcol{$field} = $posscol;
20406: }
20407: }
20408: }
1.347 raeburn 20409: if (keys(%newcol)) {
20410: foreach my $option (@options) {
20411: if ($env{'form.scantroncsv_'.$option}) {
20412: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20413: }
20414: }
20415: }
1.346 raeburn 20416: }
20417: $currdat = 1;
20418: if (ref($domconfig{'scantron'}) eq 'HASH') {
20419: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20420: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20421: $currdat = 0;
20422: }
20423: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20424: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20425: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20426: }
1.346 raeburn 20427: }
20428: }
20429: }
20430: if ($currdat != $newdat) {
20431: $changes{'config'} = 1;
20432: } else {
20433: foreach my $field (@fields) {
20434: if ($currcol{$field} ne '') {
20435: if ($currcol{$field} ne $newcol{$field}) {
20436: $changes{'config'} = 1;
20437: last;
1.347 raeburn 20438: }
1.346 raeburn 20439: } elsif ($newcol{$field} ne '') {
20440: $changes{'config'} = 1;
20441: last;
20442: }
20443: }
20444: }
1.46 raeburn 20445: if (keys(%confhash) > 0) {
20446: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20447: $dom);
20448: if ($putresult eq 'ok') {
20449: if (keys(%changes) > 0) {
1.48 raeburn 20450: if (ref($confhash{'scantron'}) eq 'HASH') {
20451: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20452: if ($changes{'scantronformat'}) {
20453: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20454: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20455: } else {
20456: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20457: }
20458: }
1.347 raeburn 20459: if ($changes{'config'}) {
1.346 raeburn 20460: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20461: if ($confhash{'scantron'}{'config'}{'dat'}) {
20462: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20463: }
20464: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20465: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20466: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20467: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20468: foreach my $field (@fields) {
20469: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20470: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20471: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20472: }
20473: }
20474: $resulttext .= '</ul></li>';
20475: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20476: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20477: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20478: foreach my $option (@options) {
20479: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20480: $resulttext .= '<li>'.$titles{$option}.'</li>';
20481: }
20482: }
20483: $resulttext .= '</ul></li>';
20484: }
1.346 raeburn 20485: }
20486: }
20487: }
20488: }
20489: } else {
20490: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20491: }
1.46 raeburn 20492: }
1.48 raeburn 20493: $resulttext .= '</ul>';
20494: } else {
1.130 raeburn 20495: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20496: }
20497: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20498: if (ref($lastactref) eq 'HASH') {
20499: $lastactref->{'domainconfig'} = 1;
20500: }
1.46 raeburn 20501: } else {
1.346 raeburn 20502: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20503: }
20504: } else {
20505: $resulttext = '<span class="LC_error">'.
20506: &mt('An error occurred: [_1]',$putresult).'</span>';
20507: }
20508: } else {
1.130 raeburn 20509: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20510: }
20511: if ($errors) {
1.353 raeburn 20512: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20513: $errors.'</ul></p>';
1.46 raeburn 20514: }
20515: return $resulttext;
20516: }
20517:
1.48 raeburn 20518: sub modify_coursecategories {
1.239 raeburn 20519: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20520: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20521: $cathash);
1.48 raeburn 20522: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20523: my @catitems = ('unauth','auth');
20524: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20525: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20526: $cathash = $domconfig{'coursecategories'}{'cats'};
20527: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20528: $changes{'togglecats'} = 1;
20529: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20530: }
20531: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20532: $changes{'categorize'} = 1;
20533: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20534: }
1.120 raeburn 20535: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20536: $changes{'togglecatscomm'} = 1;
20537: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20538: }
20539: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20540: $changes{'categorizecomm'} = 1;
20541: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20542:
20543: }
20544: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20545: $changes{'togglecatsplace'} = 1;
20546: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20547: }
20548: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20549: $changes{'categorizeplace'} = 1;
20550: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20551: }
1.238 raeburn 20552: foreach my $item (@catitems) {
20553: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20554: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20555: $changes{$item} = 1;
20556: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20557: }
20558: }
20559: }
1.57 raeburn 20560: } else {
20561: $changes{'togglecats'} = 1;
20562: $changes{'categorize'} = 1;
1.124 raeburn 20563: $changes{'togglecatscomm'} = 1;
20564: $changes{'categorizecomm'} = 1;
1.272 raeburn 20565: $changes{'togglecatsplace'} = 1;
20566: $changes{'categorizeplace'} = 1;
1.87 raeburn 20567: $domconfig{'coursecategories'} = {
20568: togglecats => $env{'form.togglecats'},
20569: categorize => $env{'form.categorize'},
1.124 raeburn 20570: togglecatscomm => $env{'form.togglecatscomm'},
20571: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20572: togglecatsplace => $env{'form.togglecatsplace'},
20573: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20574: };
1.238 raeburn 20575: foreach my $item (@catitems) {
20576: if ($env{'form.coursecat_'.$item} ne 'std') {
20577: $changes{$item} = 1;
20578: }
20579: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20580: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20581: }
20582: }
1.57 raeburn 20583: }
20584: if (ref($cathash) eq 'HASH') {
20585: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20586: push (@deletecategory,'instcode::0');
20587: }
1.120 raeburn 20588: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20589: push(@deletecategory,'communities::0');
20590: }
1.272 raeburn 20591: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20592: push(@deletecategory,'placement::0');
20593: }
1.48 raeburn 20594: }
1.57 raeburn 20595: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20596: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20597: if (@deletecategory > 0) {
20598: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20599: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20600: foreach my $item (@deletecategory) {
1.57 raeburn 20601: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20602: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20603: $deletions{$item} = 1;
1.57 raeburn 20604: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20605: }
20606: }
20607: }
1.57 raeburn 20608: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20609: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20610: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20611: $reorderings{$item} = 1;
1.57 raeburn 20612: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20613: }
20614: if ($env{'form.addcategory_name_'.$item} ne '') {
20615: my $newcat = $env{'form.addcategory_name_'.$item};
20616: my $newdepth = $depth+1;
20617: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20618: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20619: $adds{$newitem} = 1;
20620: }
20621: if ($env{'form.subcat_'.$item} ne '') {
20622: my $newcat = $env{'form.subcat_'.$item};
20623: my $newdepth = $depth+1;
20624: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20625: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20626: $adds{$newitem} = 1;
20627: }
20628: }
20629: }
20630: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20631: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20632: my $newitem = 'instcode::0';
1.57 raeburn 20633: if ($cathash->{$newitem} eq '') {
20634: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20635: $adds{$newitem} = 1;
20636: }
20637: } else {
20638: my $newitem = 'instcode::0';
1.57 raeburn 20639: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20640: $adds{$newitem} = 1;
20641: }
20642: }
1.120 raeburn 20643: if ($env{'form.communities'} eq '1') {
20644: if (ref($cathash) eq 'HASH') {
20645: my $newitem = 'communities::0';
20646: if ($cathash->{$newitem} eq '') {
20647: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20648: $adds{$newitem} = 1;
20649: }
20650: } else {
20651: my $newitem = 'communities::0';
20652: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20653: $adds{$newitem} = 1;
20654: }
20655: }
1.272 raeburn 20656: if ($env{'form.placement'} eq '1') {
20657: if (ref($cathash) eq 'HASH') {
20658: my $newitem = 'placement::0';
20659: if ($cathash->{$newitem} eq '') {
20660: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20661: $adds{$newitem} = 1;
20662: }
20663: } else {
20664: my $newitem = 'placement::0';
20665: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20666: $adds{$newitem} = 1;
20667: }
20668: }
1.48 raeburn 20669: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20670: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20671: ($env{'form.addcategory_name'} ne 'communities') &&
20672: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20673: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20674: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20675: $adds{$newitem} = 1;
20676: }
1.48 raeburn 20677: }
1.57 raeburn 20678: my $putresult;
1.48 raeburn 20679: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20680: if (keys(%deletions) > 0) {
20681: foreach my $key (keys(%deletions)) {
20682: if ($predelallitems{$key} ne '') {
20683: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20684: }
20685: }
20686: }
20687: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20688: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20689: if (ref($chkcats[0]) eq 'ARRAY') {
20690: my $depth = 0;
20691: my $chg = 0;
20692: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20693: my $name = $chkcats[0][$i];
20694: my $item;
20695: if ($name eq '') {
20696: $chg ++;
20697: } else {
20698: $item = &escape($name).'::0';
20699: if ($chg) {
1.57 raeburn 20700: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20701: }
20702: $depth ++;
1.57 raeburn 20703: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20704: $depth --;
20705: }
20706: }
20707: }
1.57 raeburn 20708: }
20709: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20710: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20711: if ($putresult eq 'ok') {
1.57 raeburn 20712: my %title = (
1.120 raeburn 20713: togglecats => 'Show/Hide a course in catalog',
20714: categorize => 'Assign a category to a course',
20715: togglecatscomm => 'Show/Hide a community in catalog',
20716: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20717: );
20718: my %level = (
1.120 raeburn 20719: dom => 'set in Domain ("Modify Course/Community")',
20720: crs => 'set in Course ("Course Configuration")',
20721: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20722: none => 'No catalog',
20723: std => 'Standard catalog',
20724: domonly => 'Domain-only catalog',
20725: codesrch => 'Code search form',
1.57 raeburn 20726: );
1.48 raeburn 20727: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20728: if ($changes{'togglecats'}) {
20729: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20730: }
20731: if ($changes{'categorize'}) {
20732: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20733: }
1.120 raeburn 20734: if ($changes{'togglecatscomm'}) {
20735: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20736: }
20737: if ($changes{'categorizecomm'}) {
20738: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20739: }
1.238 raeburn 20740: if ($changes{'unauth'}) {
20741: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20742: }
20743: if ($changes{'auth'}) {
20744: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20745: }
1.57 raeburn 20746: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20747: my $cathash;
20748: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20749: $cathash = $domconfig{'coursecategories'}{'cats'};
20750: } else {
20751: $cathash = {};
20752: }
20753: my (@cats,@trails,%allitems);
20754: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20755: if (keys(%deletions) > 0) {
20756: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20757: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20758: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20759: }
20760: $resulttext .= '</ul></li>';
20761: }
20762: if (keys(%reorderings) > 0) {
20763: my %sort_by_trail;
20764: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20765: foreach my $key (keys(%reorderings)) {
20766: if ($allitems{$key} ne '') {
20767: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20768: }
1.48 raeburn 20769: }
1.57 raeburn 20770: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20771: $resulttext .= '<li>'.$trails[$trail].'</li>';
20772: }
20773: $resulttext .= '</ul></li>';
1.48 raeburn 20774: }
1.57 raeburn 20775: if (keys(%adds) > 0) {
20776: my %sort_by_trail;
20777: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20778: foreach my $key (keys(%adds)) {
20779: if ($allitems{$key} ne '') {
20780: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20781: }
20782: }
20783: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20784: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20785: }
1.57 raeburn 20786: $resulttext .= '</ul></li>';
1.48 raeburn 20787: }
1.364 raeburn 20788: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20789: if (ref($lastactref) eq 'HASH') {
20790: $lastactref->{'cats'} = 1;
20791: }
1.48 raeburn 20792: }
20793: $resulttext .= '</ul>';
1.239 raeburn 20794: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20795: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20796: if ($changes{'auth'}) {
20797: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20798: }
20799: if ($changes{'unauth'}) {
20800: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20801: }
20802: my $cachetime = 24*60*60;
20803: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20804: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20805: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20806: }
20807: }
1.48 raeburn 20808: } else {
20809: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20810: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20811: }
20812: } else {
1.120 raeburn 20813: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20814: }
20815: return $resulttext;
20816: }
20817:
1.69 raeburn 20818: sub modify_serverstatuses {
20819: my ($dom,%domconfig) = @_;
20820: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20821: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20822: %currserverstatus = %{$domconfig{'serverstatuses'}};
20823: }
20824: my @pages = &serverstatus_pages();
20825: foreach my $type (@pages) {
20826: $newserverstatus{$type}{'namedusers'} = '';
20827: $newserverstatus{$type}{'machines'} = '';
20828: if (defined($env{'form.'.$type.'_namedusers'})) {
20829: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20830: my @okusers;
20831: foreach my $user (@users) {
20832: my ($uname,$udom) = split(/:/,$user);
20833: if (($udom =~ /^$match_domain$/) &&
20834: (&Apache::lonnet::domain($udom)) &&
20835: ($uname =~ /^$match_username$/)) {
20836: if (!grep(/^\Q$user\E/,@okusers)) {
20837: push(@okusers,$user);
20838: }
20839: }
20840: }
20841: if (@okusers > 0) {
20842: @okusers = sort(@okusers);
20843: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20844: }
20845: }
20846: if (defined($env{'form.'.$type.'_machines'})) {
20847: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20848: my @okmachines;
20849: foreach my $ip (@machines) {
20850: my @parts = split(/\./,$ip);
20851: next if (@parts < 4);
20852: my $badip = 0;
20853: for (my $i=0; $i<4; $i++) {
20854: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20855: $badip = 1;
20856: last;
20857: }
20858: }
20859: if (!$badip) {
20860: push(@okmachines,$ip);
20861: }
20862: }
20863: @okmachines = sort(@okmachines);
20864: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20865: }
20866: }
20867: my %serverstatushash = (
20868: serverstatuses => \%newserverstatus,
20869: );
20870: foreach my $type (@pages) {
1.83 raeburn 20871: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20872: my (@current,@new);
1.83 raeburn 20873: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20874: if ($currserverstatus{$type}{$setting} ne '') {
20875: @current = split(/,/,$currserverstatus{$type}{$setting});
20876: }
20877: }
20878: if ($newserverstatus{$type}{$setting} ne '') {
20879: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20880: }
20881: if (@current > 0) {
20882: if (@new > 0) {
20883: foreach my $item (@current) {
20884: if (!grep(/^\Q$item\E$/,@new)) {
20885: $changes{$type}{$setting} = 1;
1.82 raeburn 20886: last;
20887: }
20888: }
1.84 raeburn 20889: foreach my $item (@new) {
20890: if (!grep(/^\Q$item\E$/,@current)) {
20891: $changes{$type}{$setting} = 1;
20892: last;
1.82 raeburn 20893: }
20894: }
20895: } else {
1.83 raeburn 20896: $changes{$type}{$setting} = 1;
1.69 raeburn 20897: }
1.83 raeburn 20898: } elsif (@new > 0) {
20899: $changes{$type}{$setting} = 1;
1.69 raeburn 20900: }
20901: }
20902: }
20903: if (keys(%changes) > 0) {
1.81 raeburn 20904: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20905: my $putresult = &Apache::lonnet::put_dom('configuration',
20906: \%serverstatushash,$dom);
20907: if ($putresult eq 'ok') {
20908: $resulttext .= &mt('Changes made:').'<ul>';
20909: foreach my $type (@pages) {
1.84 raeburn 20910: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20911: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20912: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20913: if ($newserverstatus{$type}{'namedusers'} eq '') {
20914: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20915: } else {
20916: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20917: }
1.84 raeburn 20918: }
20919: if ($changes{$type}{'machines'}) {
1.69 raeburn 20920: if ($newserverstatus{$type}{'machines'} eq '') {
20921: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20922: } else {
20923: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20924: }
20925:
20926: }
20927: $resulttext .= '</ul></li>';
20928: }
20929: }
20930: $resulttext .= '</ul>';
20931: } else {
20932: $resulttext = '<span class="LC_error">'.
20933: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20934:
20935: }
20936: } else {
20937: $resulttext = &mt('No changes made to access to server status pages');
20938: }
20939: return $resulttext;
20940: }
20941:
1.118 jms 20942: sub modify_helpsettings {
1.285 raeburn 20943: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20944: my ($resulttext,$errors,%changes,%helphash);
20945: my %defaultchecked = ('submitbugs' => 'on');
20946: my @offon = ('off','on');
1.118 jms 20947: my @toggles = ('submitbugs');
1.285 raeburn 20948: my %current = ('submitbugs' => '',
20949: 'adhoc' => {},
20950: );
1.118 jms 20951: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20952: %current = %{$domconfig{'helpsettings'}};
20953: }
1.285 raeburn 20954: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20955: foreach my $item (@toggles) {
20956: if ($defaultchecked{$item} eq 'on') {
20957: if ($current{$item} eq '') {
20958: if ($env{'form.'.$item} eq '0') {
20959: $changes{$item} = 1;
20960: }
20961: } elsif ($current{$item} ne $env{'form.'.$item}) {
20962: $changes{$item} = 1;
20963: }
20964: } elsif ($defaultchecked{$item} eq 'off') {
20965: if ($current{$item} eq '') {
20966: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20967: $changes{$item} = 1;
20968: }
1.282 raeburn 20969: } elsif ($current{$item} ne $env{'form.'.$item}) {
20970: $changes{$item} = 1;
20971: }
20972: }
20973: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20974: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20975: }
20976: }
1.285 raeburn 20977: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20978: my $confname = $dom.'-domainconfig';
20979: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20980: my (@allpos,%newsettings,%changedprivs,$newrole);
20981: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20982: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20983: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20984: my %lt = &Apache::lonlocal::texthash(
20985: s => 'system',
20986: d => 'domain',
20987: order => 'Display order',
20988: access => 'Role usage',
1.291 raeburn 20989: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20990: dh => 'All with domain helpdesk role',
20991: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20992: none => 'None',
20993: status => 'Determined based on institutional status',
20994: inc => 'Include all, but exclude specific personnel',
20995: exc => 'Exclude all, but include specific personnel',
20996: );
20997: for (my $num=0; $num<=$maxnum; $num++) {
20998: my ($prefix,$identifier,$rolename,%curr);
20999: if ($num == $maxnum) {
21000: next unless ($env{'form.newcusthelp'} == $maxnum);
21001: $identifier = 'custhelp'.$num;
21002: $prefix = 'helproles_'.$num;
21003: $rolename = $env{'form.custhelpname'.$num};
21004: $rolename=~s/[^A-Za-z0-9]//gs;
21005: next if ($rolename eq '');
21006: next if (exists($existing{'rolesdef_'.$rolename}));
21007: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21008: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21009: $newprivs{'c'},$confname,$dom);
21010: if ($result ne 'ok') {
21011: $errors .= '<li><span class="LC_error">'.
21012: &mt('An error occurred storing the new custom role: [_1]',
21013: $result).'</span></li>';
21014: next;
21015: } else {
21016: $changedprivs{$rolename} = \%newprivs;
21017: $newrole = $rolename;
21018: }
21019: } else {
21020: $prefix = 'helproles_'.$num;
21021: $rolename = $env{'form.'.$prefix};
21022: next if ($rolename eq '');
21023: next unless (exists($existing{'rolesdef_'.$rolename}));
21024: $identifier = 'custhelp'.$num;
21025: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21026: my %currprivs;
1.289 raeburn 21027: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21028: split(/\_/,$existing{'rolesdef_'.$rolename});
21029: foreach my $level ('c','d','s') {
21030: if ($newprivs{$level} ne $currprivs{$level}) {
21031: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21032: $newprivs{'c'},$confname,$dom);
21033: if ($result ne 'ok') {
21034: $errors .= '<li><span class="LC_error">'.
21035: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21036: $rolename,$result).'</span></li>';
21037: } else {
21038: $changedprivs{$rolename} = \%newprivs;
21039: }
21040: last;
21041: }
21042: }
21043: if (ref($current{'adhoc'}) eq 'HASH') {
21044: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21045: %curr = %{$current{'adhoc'}{$rolename}};
21046: }
21047: }
21048: }
21049: my $newpos = $env{'form.'.$prefix.'_pos'};
21050: $newpos =~ s/\D+//g;
21051: $allpos[$newpos] = $rolename;
21052: my $newdesc = $env{'form.'.$prefix.'_desc'};
21053: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21054: if ($curr{'desc'}) {
21055: if ($curr{'desc'} ne $newdesc) {
21056: $changes{'customrole'}{$rolename}{'desc'} = 1;
21057: $newsettings{$rolename}{'desc'} = $newdesc;
21058: }
21059: } elsif ($newdesc ne '') {
21060: $changes{'customrole'}{$rolename}{'desc'} = 1;
21061: $newsettings{$rolename}{'desc'} = $newdesc;
21062: }
21063: my $access = $env{'form.'.$prefix.'_access'};
21064: if (grep(/^\Q$access\E$/,@accesstypes)) {
21065: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21066: if ($access eq 'status') {
21067: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21068: if (scalar(@statuses) == 0) {
1.289 raeburn 21069: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21070: } else {
21071: my (@shownstatus,$numtypes);
21072: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21073: if (ref($types) eq 'ARRAY') {
21074: $numtypes = scalar(@{$types});
21075: foreach my $type (sort(@statuses)) {
21076: if ($type eq 'default') {
21077: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21078: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21079: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21080: push(@shownstatus,$usertypes->{$type});
21081: }
21082: }
21083: }
21084: if (grep(/^default$/,@statuses)) {
21085: push(@shownstatus,$othertitle);
21086: }
21087: if (scalar(@shownstatus) == 1+$numtypes) {
21088: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21089: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21090: } else {
21091: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21092: if (ref($curr{'status'}) eq 'ARRAY') {
21093: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21094: if (@diffs) {
21095: $changes{'customrole'}{$rolename}{$access} = 1;
21096: }
21097: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21098: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21099: }
1.166 raeburn 21100: }
21101: }
1.285 raeburn 21102: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21103: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21104: my @newspecstaff;
21105: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21106: foreach my $person (sort(@personnel)) {
21107: if ($domhelpdesk{$person}) {
21108: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21109: }
21110: }
21111: if (ref($curr{$access}) eq 'ARRAY') {
21112: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21113: if (@diffs) {
21114: $changes{'customrole'}{$rolename}{$access} = 1;
21115: }
21116: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21117: $changes{'customrole'}{$rolename}{$access} = 1;
21118: }
21119: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21120: my ($uname,$udom) = split(/:/,$person);
21121: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21122: }
21123: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21124: }
1.285 raeburn 21125: } else {
21126: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21127: }
21128: unless ($curr{'access'} eq $access) {
21129: $changes{'customrole'}{$rolename}{'access'} = 1;
21130: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21131: }
21132: }
1.285 raeburn 21133: if (@allpos > 0) {
21134: my $idx = 0;
21135: foreach my $rolename (@allpos) {
21136: if ($rolename ne '') {
21137: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21138: if (ref($current{'adhoc'}) eq 'HASH') {
21139: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21140: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21141: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21142: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21143: }
21144: }
1.282 raeburn 21145: }
1.285 raeburn 21146: $idx ++;
1.166 raeburn 21147: }
21148: }
1.118 jms 21149: }
1.123 jms 21150: my $putresult;
21151: if (keys(%changes) > 0) {
1.166 raeburn 21152: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21153: if ($putresult eq 'ok') {
1.285 raeburn 21154: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21155: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21156: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21157: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21158: }
21159: }
21160: my $cachetime = 24*60*60;
21161: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21162: if (ref($lastactref) eq 'HASH') {
21163: $lastactref->{'domdefaults'} = 1;
21164: }
21165: } else {
21166: $errors .= '<li><span class="LC_error">'.
21167: &mt('An error occurred storing the settings: [_1]',
21168: $putresult).'</span></li>';
21169: }
21170: }
21171: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21172: $resulttext = &mt('Changes made:').'<ul>';
21173: my (%shownprivs,@levelorder);
21174: @levelorder = ('c','d','s');
21175: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21176: foreach my $item (sort(keys(%changes))) {
21177: if ($item eq 'submitbugs') {
21178: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21179: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21180: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21181: } elsif ($item eq 'customrole') {
21182: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21183: my @keyorder = ('order','desc','access','status','exc','inc');
21184: my %keytext = &Apache::lonlocal::texthash(
21185: order => 'Order',
21186: desc => 'Role description',
21187: access => 'Role usage',
1.300 droeschl 21188: status => 'Allowed institutional types',
1.285 raeburn 21189: exc => 'Allowed personnel',
21190: inc => 'Disallowed personnel',
21191: );
1.282 raeburn 21192: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21193: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21194: if ($role eq $newrole) {
21195: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21196: $role).'<ul>';
21197: } else {
21198: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21199: $role).'<ul>';
21200: }
21201: foreach my $key (@keyorder) {
21202: if ($changes{'customrole'}{$role}{$key}) {
21203: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21204: $keytext{$key},$newsettings{$role}{$key}).
21205: '</li>';
21206: }
21207: }
21208: if (ref($changedprivs{$role}) eq 'HASH') {
21209: $shownprivs{$role} = 1;
21210: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21211: foreach my $level (@levelorder) {
21212: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21213: next if ($item eq '');
21214: my ($priv) = split(/\&/,$item,2);
21215: if (&Apache::lonnet::plaintext($priv)) {
21216: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21217: unless ($level eq 'c') {
21218: $resulttext .= ' ('.$lt{$level}.')';
21219: }
21220: $resulttext .= '</li>';
21221: }
21222: }
21223: }
21224: $resulttext .= '</ul>';
21225: }
21226: $resulttext .= '</ul></li>';
21227: }
21228: }
21229: }
21230: }
21231: }
21232: }
21233: if (keys(%changedprivs)) {
21234: foreach my $role (sort(keys(%changedprivs))) {
21235: unless ($shownprivs{$role}) {
21236: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21237: $role).'<ul>'.
21238: '<li>'.&mt('Privileges set to :').'<ul>';
21239: foreach my $level (@levelorder) {
21240: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21241: next if ($item eq '');
21242: my ($priv) = split(/\&/,$item,2);
21243: if (&Apache::lonnet::plaintext($priv)) {
21244: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21245: unless ($level eq 'c') {
21246: $resulttext .= ' ('.$lt{$level}.')';
21247: }
21248: $resulttext .= '</li>';
21249: }
1.282 raeburn 21250: }
21251: }
1.285 raeburn 21252: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21253: }
21254: }
21255: }
1.285 raeburn 21256: $resulttext .= '</ul>';
21257: } else {
21258: $resulttext = &mt('No changes made to help settings');
1.118 jms 21259: }
21260: if ($errors) {
1.168 raeburn 21261: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21262: $errors.'</ul>';
1.118 jms 21263: }
21264: return $resulttext;
21265: }
21266:
1.121 raeburn 21267: sub modify_coursedefaults {
1.212 raeburn 21268: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21269: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21270: my %defaultchecked = (
21271: 'canuse_pdfforms' => 'off',
21272: 'uselcmath' => 'on',
1.398 raeburn 21273: 'usejsme' => 'on',
21274: 'inline_chem' => 'on',
1.404 raeburn 21275: 'ltiauth' => 'off',
1.257 raeburn 21276: );
1.404 raeburn 21277: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21278: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21279: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21280: 'coursequota_official','coursequota_unofficial','coursequota_community',
21281: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21282: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21283: 'mysqltables_placement');
1.271 raeburn 21284: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21285: my %staticdefaults = (
21286: anonsurvey_threshold => 10,
21287: uploadquota => 500,
1.428 raeburn 21288: coursequota => 20,
1.257 raeburn 21289: postsubmit => 60,
1.276 raeburn 21290: mysqltables => 172800,
1.422 raeburn 21291: domexttool => 1,
1.432 raeburn 21292: crsauthor => 1,
1.438 raeburn 21293: crseditors => ['edit','xml'],
1.198 raeburn 21294: );
1.314 raeburn 21295: my %texoptions = (
21296: MathJax => 'MathJax',
21297: mimetex => &mt('Convert to Images'),
21298: tth => &mt('TeX to HTML'),
21299: );
1.438 raeburn 21300:
21301: my @editors = ('edit','xml','daxe');
21302: my %editornames = &crseditor_titles();
21303:
1.121 raeburn 21304: $defaultshash{'coursedefaults'} = {};
21305:
21306: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21307: if ($domconfig{'coursedefaults'} eq '') {
21308: $domconfig{'coursedefaults'} = {};
21309: }
21310: }
21311:
21312: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21313: foreach my $item (@toggles) {
21314: if ($defaultchecked{$item} eq 'on') {
21315: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21316: ($env{'form.'.$item} eq '0')) {
21317: $changes{$item} = 1;
1.192 raeburn 21318: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21319: $changes{$item} = 1;
21320: }
21321: } elsif ($defaultchecked{$item} eq 'off') {
21322: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21323: ($env{'form.'.$item} eq '1')) {
21324: $changes{$item} = 1;
21325: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21326: $changes{$item} = 1;
21327: }
21328: }
21329: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21330: }
1.198 raeburn 21331: foreach my $item (@numbers) {
21332: my ($currdef,$newdef);
1.208 raeburn 21333: $newdef = $env{'form.'.$item};
1.198 raeburn 21334: if ($item eq 'anonsurvey_threshold') {
21335: $currdef = $domconfig{'coursedefaults'}{$item};
21336: $newdef =~ s/\D//g;
21337: if ($newdef eq '' || $newdef < 1) {
21338: $newdef = 1;
21339: }
21340: $defaultshash{'coursedefaults'}{$item} = $newdef;
21341: } else {
1.428 raeburn 21342: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21343: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21344: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21345: }
21346: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21347: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21348: }
21349: if ($currdef ne $newdef) {
21350: if ($item eq 'anonsurvey_threshold') {
21351: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21352: $changes{$item} = 1;
21353: }
1.428 raeburn 21354: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21355: my $setting = $1;
1.276 raeburn 21356: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21357: $changes{$setting} = 1;
1.198 raeburn 21358: }
21359: }
1.139 raeburn 21360: }
21361: }
1.314 raeburn 21362: my $texengine;
21363: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21364: $texengine = $env{'form.texengine'};
1.349 raeburn 21365: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21366: if ($currdef eq '') {
21367: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21368: $changes{'texengine'} = 1;
21369: }
1.349 raeburn 21370: } elsif ($currdef ne $texengine) {
1.314 raeburn 21371: $changes{'texengine'} = 1;
21372: }
21373: }
21374: if ($texengine ne '') {
21375: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21376: }
1.264 raeburn 21377: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21378: my @currclonecode;
21379: if (ref($currclone) eq 'HASH') {
21380: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21381: @currclonecode = @{$currclone->{'instcode'}};
21382: }
21383: }
21384: my $newclone;
1.289 raeburn 21385: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21386: $newclone = $env{'form.canclone'};
21387: }
21388: if ($newclone eq 'instcode') {
21389: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21390: my (%codedefaults,@code_order,@clonecode);
21391: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21392: \@code_order);
21393: foreach my $item (@code_order) {
21394: if (grep(/^\Q$item\E$/,@newcodes)) {
21395: push(@clonecode,$item);
21396: }
21397: }
21398: if (@clonecode) {
21399: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21400: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21401: if (@diffs) {
21402: $changes{'canclone'} = 1;
21403: }
21404: } else {
21405: $newclone eq '';
21406: }
21407: } elsif ($newclone ne '') {
1.289 raeburn 21408: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21409: }
1.264 raeburn 21410: if ($newclone ne $currclone) {
21411: $changes{'canclone'} = 1;
21412: }
1.257 raeburn 21413: my %credits;
21414: foreach my $type (@types) {
21415: unless ($type eq 'community') {
21416: $credits{$type} = $env{'form.'.$type.'_credits'};
21417: $credits{$type} =~ s/[^\d.]+//g;
21418: }
21419: }
21420: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21421: ($env{'form.coursecredits'} eq '1')) {
21422: $changes{'coursecredits'} = 1;
21423: foreach my $type (keys(%credits)) {
21424: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21425: }
21426: } else {
1.289 raeburn 21427: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21428: foreach my $type (@types) {
21429: unless ($type eq 'community') {
1.289 raeburn 21430: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21431: $changes{'coursecredits'} = 1;
21432: }
21433: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21434: }
21435: }
21436: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21437: foreach my $type (@types) {
21438: unless ($type eq 'community') {
21439: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21440: $changes{'coursecredits'} = 1;
21441: last;
21442: }
21443: }
21444: }
21445: }
21446: }
21447: if ($env{'form.postsubmit'} eq '1') {
21448: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21449: my %currtimeout;
21450: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21451: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21452: $changes{'postsubmit'} = 1;
21453: }
21454: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21455: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21456: }
21457: } else {
21458: $changes{'postsubmit'} = 1;
21459: }
21460: foreach my $type (@types) {
21461: my $timeout = $env{'form.'.$type.'_timeout'};
21462: $timeout =~ s/\D//g;
21463: if ($timeout == $staticdefaults{'postsubmit'}) {
21464: $timeout = '';
21465: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21466: $timeout = '0';
21467: }
21468: unless ($timeout eq '') {
21469: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21470: }
21471: if (exists($currtimeout{$type})) {
21472: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21473: $changes{'postsubmit'} = 1;
1.257 raeburn 21474: }
21475: } elsif ($timeout ne '') {
21476: $changes{'postsubmit'} = 1;
21477: }
21478: }
21479: } else {
21480: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21481: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21482: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21483: $changes{'postsubmit'} = 1;
21484: }
21485: } else {
21486: $changes{'postsubmit'} = 1;
21487: }
1.192 raeburn 21488: }
1.438 raeburn 21489: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21490: %posscrseditors);
1.422 raeburn 21491: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21492: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21493: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21494: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21495: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21496: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21497: } else {
21498: foreach my $type (@types) {
21499: if ($staticdefaults{'domexttool'}) {
21500: $olddomexttool{$type} = 1;
21501: } else {
21502: $olddomexttool{$type} = 0;
21503: }
21504: }
21505: }
21506: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21507: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21508: } else {
21509: foreach my $type (@types) {
21510: if ($staticdefaults{'exttool'}) {
21511: $oldexttool{$type} = 1;
21512: } else {
21513: $oldexttool{$type} = 0;
21514: }
21515: }
21516: }
1.432 raeburn 21517: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21518: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21519: } else {
21520: foreach my $type (@types) {
21521: if ($staticdefaults{'crsauthor'}) {
21522: $oldcrsauthor{$type} = 1;
21523: } else {
21524: $oldcrsauthor{$type} = 0;
21525: }
21526: }
21527: }
1.438 raeburn 21528: my @newcrseditors = ();
21529: foreach my $editor (@editors) {
21530: if ($posscrseditors{$editor}) {
21531: push(@newcrseditors,$editor);
21532: }
21533: }
21534: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21535: my @diffs =
21536: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21537: \@newcrseditors);
21538: if (@diffs) {
21539: $changes{'crseditors'} = 1;
21540: }
21541: } else {
21542: my @diffs =
21543: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21544: \@newcrseditors);
21545: unless (@diffs == 0) {
21546: $changes{'crseditors'} = 1;
21547: }
21548: }
1.422 raeburn 21549: foreach my $type (@types) {
21550: unless ($newdomexttool{$type}) {
21551: $newdomexttool{$type} = 0;
21552: }
21553: unless ($newexttool{$type}) {
21554: $newexttool{$type} = 0;
21555: }
1.432 raeburn 21556: unless ($newcrsauthor{$type}) {
21557: $newcrsauthor{$type} = 0;
21558: }
1.422 raeburn 21559: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21560: $changes{'domexttool'} = 1;
21561: }
21562: if ($newexttool{$type} != $oldexttool{$type}) {
21563: $changes{'exttool'} = 1;
21564: }
1.432 raeburn 21565: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21566: $changes{'crsauthor'} = 1;
21567: }
1.422 raeburn 21568: }
21569: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21570: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21571: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21572: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21573: }
21574: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21575: $dom);
21576: if ($putresult eq 'ok') {
21577: if (keys(%changes) > 0) {
1.213 raeburn 21578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21579: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21580: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21581: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21582: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21583: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21584: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21585: 'ltiauth') {
1.257 raeburn 21586: if ($changes{$item}) {
21587: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21588: }
1.289 raeburn 21589: }
1.192 raeburn 21590: if ($changes{'coursecredits'}) {
21591: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21592: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21593: $domdefaults{$type.'credits'} =
21594: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21595: }
21596: }
21597: }
21598: if ($changes{'postsubmit'}) {
21599: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21600: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21601: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21602: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21603: $domdefaults{$type.'postsubtimeout'} =
21604: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21605: }
21606: }
1.192 raeburn 21607: }
21608: }
1.198 raeburn 21609: if ($changes{'uploadquota'}) {
21610: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21611: foreach my $type (@types) {
21612: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21613: }
21614: }
21615: }
1.428 raeburn 21616: if ($changes{'coursequota'}) {
21617: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21618: foreach my $type (@types) {
21619: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21620: }
21621: }
21622: }
1.264 raeburn 21623: if ($changes{'canclone'}) {
21624: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21625: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21626: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21627: if (@clonecodes) {
21628: $domdefaults{'canclone'} = join('+',@clonecodes);
21629: }
21630: }
21631: } else {
21632: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21633: }
21634: }
1.422 raeburn 21635: if ($changes{'domexttool'}) {
21636: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21637: foreach my $type (@types) {
21638: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21639: }
21640: }
21641: }
21642: if ($changes{'exttool'}) {
21643: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21644: foreach my $type (@types) {
21645: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21646: }
21647: }
21648: }
1.432 raeburn 21649: if ($changes{'crsauthor'}) {
21650: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21651: foreach my $type (@types) {
21652: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21653: }
21654: }
21655: }
1.438 raeburn 21656: if ($changes{'crseditors'}) {
21657: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21658: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21659: }
21660: }
1.121 raeburn 21661: my $cachetime = 24*60*60;
21662: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21663: if (ref($lastactref) eq 'HASH') {
21664: $lastactref->{'domdefaults'} = 1;
21665: }
1.121 raeburn 21666: }
21667: $resulttext = &mt('Changes made:').'<ul>';
21668: foreach my $item (sort(keys(%changes))) {
21669: if ($item eq 'canuse_pdfforms') {
21670: if ($env{'form.'.$item} eq '1') {
21671: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21672: } else {
21673: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21674: }
1.257 raeburn 21675: } elsif ($item eq 'uselcmath') {
21676: if ($env{'form.'.$item} eq '1') {
21677: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21678: } else {
21679: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21680: }
21681: } elsif ($item eq 'usejsme') {
21682: if ($env{'form.'.$item} eq '1') {
21683: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21684: } else {
1.289 raeburn 21685: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21686: }
1.398 raeburn 21687: } elsif ($item eq 'inline_chem') {
21688: if ($env{'form.'.$item} eq '1') {
21689: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21690: } else {
21691: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21692: }
1.314 raeburn 21693: } elsif ($item eq 'texengine') {
21694: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21695: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21696: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21697: }
1.139 raeburn 21698: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21699: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21700: } elsif ($item eq 'uploadquota') {
21701: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21702: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21703: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21704: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21705: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21706: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21707: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21708: '</ul>'.
21709: '</li>';
21710: } else {
21711: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21712: }
1.428 raeburn 21713: } elsif ($item eq 'coursequota') {
21714: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21715: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21716: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21717: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21718: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21719: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21720: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21721: '</ul>'.
21722: '</li>';
21723: } else {
21724: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21725: }
1.276 raeburn 21726: } elsif ($item eq 'mysqltables') {
21727: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21728: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21729: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21730: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21731: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21732: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21733: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21734: '</ul>'.
21735: '</li>';
21736: } else {
21737: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21738: }
1.257 raeburn 21739: } elsif ($item eq 'postsubmit') {
21740: if ($domdefaults{'postsubmit'} eq 'off') {
21741: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21742: } else {
21743: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21744: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21745: $resulttext .= &mt('durations:').'<ul>';
21746: foreach my $type (@types) {
21747: $resulttext .= '<li>';
21748: my $timeout;
21749: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21750: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21751: }
21752: my $display;
21753: if ($timeout eq '0') {
21754: $display = &mt('unlimited');
21755: } elsif ($timeout eq '') {
21756: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21757: } else {
21758: $display = &mt('[quant,_1,second]',$timeout);
21759: }
21760: if ($type eq 'community') {
21761: $resulttext .= &mt('Communities');
21762: } elsif ($type eq 'official') {
21763: $resulttext .= &mt('Official courses');
21764: } elsif ($type eq 'unofficial') {
21765: $resulttext .= &mt('Unofficial courses');
21766: } elsif ($type eq 'textbook') {
21767: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21768: } elsif ($type eq 'placement') {
21769: $resulttext .= &mt('Placement tests');
1.257 raeburn 21770: }
21771: $resulttext .= ' -- '.$display.'</li>';
21772: }
21773: $resulttext .= '</ul>';
21774: }
1.289 raeburn 21775: $resulttext .= '</li>';
1.257 raeburn 21776: }
1.192 raeburn 21777: } elsif ($item eq 'coursecredits') {
21778: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21779: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21780: ($domdefaults{'unofficialcredits'} eq '') &&
21781: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21782: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21783: } else {
21784: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21785: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21786: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21787: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21788: '</ul>'.
21789: '</li>';
21790: }
21791: } else {
21792: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21793: }
1.264 raeburn 21794: } elsif ($item eq 'canclone') {
21795: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21796: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21797: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21798: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21799: }
21800: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21801: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21802: } else {
1.289 raeburn 21803: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21804: }
1.404 raeburn 21805: } elsif ($item eq 'ltiauth') {
21806: if ($env{'form.'.$item} eq '1') {
21807: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21808: } else {
21809: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21810: }
1.432 raeburn 21811: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21812: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21813: my %status = (
21814: domexttool => {
21815: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21816: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21817: },
21818: exttool => {
21819: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21820: default => &mt('External Tools can not be defined in any course types, by default'),
21821: },
21822: crsauthor => {
21823: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21824: default => &mt('Standard Problems can be created within any course type, by default'),
21825: },
21826: );
21827:
21828: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21829: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21830: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21831: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21832: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21833: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21834: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21835: '</ul>'.
21836: '</li>';
21837: } else {
1.432 raeburn 21838: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21839: }
1.438 raeburn 21840: } elsif ($item eq 'crseditors') {
21841: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21842: my $shown;
21843: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21844: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21845: } else {
21846: $shown = &mt('None');
21847: }
21848: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21849: }
1.140 raeburn 21850: }
1.121 raeburn 21851: }
21852: $resulttext .= '</ul>';
21853: } else {
21854: $resulttext = &mt('No changes made to course defaults');
21855: }
21856: } else {
21857: $resulttext = '<span class="LC_error">'.
21858: &mt('An error occurred: [_1]',$putresult).'</span>';
21859: }
21860: return $resulttext;
21861: }
21862:
1.231 raeburn 21863: sub modify_selfenrollment {
21864: my ($dom,$lastactref,%domconfig) = @_;
21865: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21866: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21867: my %titles = &tool_titles();
1.232 raeburn 21868: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21869: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21870: $ordered{'default'} = ['types','registered','approval','limit'];
21871:
21872: my (%roles,%shown,%toplevel);
21873: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21874:
21875: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21876: if ($domconfig{'selfenrollment'} eq '') {
21877: $domconfig{'selfenrollment'} = {};
21878: }
21879: }
21880: %toplevel = (
21881: admin => 'Configuration Rights',
21882: default => 'Default settings',
21883: validation => 'Validation of self-enrollment requests',
21884: );
1.233 raeburn 21885: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21886:
21887: if (ref($ordered{'admin'}) eq 'ARRAY') {
21888: foreach my $item (@{$ordered{'admin'}}) {
21889: foreach my $type (@types) {
21890: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21891: $selfenrollhash{'admin'}{$type}{$item} = 1;
21892: } else {
21893: $selfenrollhash{'admin'}{$type}{$item} = 0;
21894: }
21895: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21896: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21897: if ($selfenrollhash{'admin'}{$type}{$item} ne
21898: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21899: push(@{$changes{'admin'}{$type}},$item);
21900: }
21901: } else {
21902: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21903: push(@{$changes{'admin'}{$type}},$item);
21904: }
21905: }
21906: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21907: push(@{$changes{'admin'}{$type}},$item);
21908: }
21909: }
21910: }
21911: }
21912:
21913: foreach my $item (@{$ordered{'default'}}) {
21914: foreach my $type (@types) {
21915: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21916: if ($item eq 'types') {
21917: unless (($value eq 'all') || ($value eq 'dom')) {
21918: $value = '';
21919: }
21920: } elsif ($item eq 'registered') {
21921: unless ($value eq '1') {
21922: $value = 0;
21923: }
21924: } elsif ($item eq 'approval') {
21925: unless ($value =~ /^[012]$/) {
21926: $value = 0;
21927: }
21928: } else {
21929: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21930: $value = 'none';
21931: }
21932: }
21933: $selfenrollhash{'default'}{$type}{$item} = $value;
21934: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21935: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21936: if ($selfenrollhash{'default'}{$type}{$item} ne
21937: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21938: push(@{$changes{'default'}{$type}},$item);
21939: }
21940: } else {
21941: push(@{$changes{'default'}{$type}},$item);
21942: }
21943: } else {
21944: push(@{$changes{'default'}{$type}},$item);
21945: }
21946: if ($item eq 'limit') {
21947: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21948: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21949: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21950: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21951: }
21952: } else {
21953: $selfenrollhash{'default'}{$type}{'cap'} = '';
21954: }
21955: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21956: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21957: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21958: push(@{$changes{'default'}{$type}},'cap');
21959: }
21960: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21961: push(@{$changes{'default'}{$type}},'cap');
21962: }
21963: }
21964: }
21965: }
21966:
21967: foreach my $item (@{$itemsref}) {
21968: if ($item eq 'fields') {
21969: my @changed;
21970: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21971: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21972: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21973: }
21974: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21975: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21976: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21977: $domconfig{'selfenrollment'}{'validation'}{$item});
21978: } else {
21979: @changed = @{$selfenrollhash{'validation'}{$item}};
21980: }
21981: } else {
21982: @changed = @{$selfenrollhash{'validation'}{$item}};
21983: }
21984: if (@changed) {
21985: if ($selfenrollhash{'validation'}{$item}) {
21986: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21987: } else {
21988: $changes{'validation'}{$item} = &mt('None');
21989: }
21990: }
21991: } else {
21992: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
21993: if ($item eq 'markup') {
21994: if ($env{'form.selfenroll_validation_'.$item}) {
21995: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
21996: }
21997: }
21998: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21999: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
22000: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
22001: }
22002: }
22003: }
22004: }
22005:
22006: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
22007: $dom);
22008: if ($putresult eq 'ok') {
22009: if (keys(%changes) > 0) {
22010: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22011: $resulttext = &mt('Changes made:').'<ul>';
22012: foreach my $key ('admin','default','validation') {
22013: if (ref($changes{$key}) eq 'HASH') {
22014: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22015: if ($key eq 'validation') {
22016: foreach my $item (@{$itemsref}) {
22017: if (exists($changes{$key}{$item})) {
22018: if ($item eq 'markup') {
22019: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22020: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22021: } else {
22022: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22023: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22024: }
22025: }
22026: }
22027: } else {
22028: foreach my $type (@types) {
22029: if ($type eq 'community') {
22030: $roles{'1'} = &mt('Community personnel');
22031: } else {
22032: $roles{'1'} = &mt('Course personnel');
22033: }
22034: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22035: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22036: if ($key eq 'admin') {
22037: my @mgrdc = ();
22038: if (ref($ordered{$key}) eq 'ARRAY') {
22039: foreach my $item (@{$ordered{'admin'}}) {
22040: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22041: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22042: push(@mgrdc,$item);
22043: }
22044: }
22045: }
22046: if (@mgrdc) {
22047: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22048: } else {
22049: delete($domdefaults{$type.'selfenrolladmdc'});
22050: }
22051: }
22052: } else {
22053: if (ref($ordered{$key}) eq 'ARRAY') {
22054: foreach my $item (@{$ordered{$key}}) {
22055: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22056: $domdefaults{$type.'selfenroll'.$item} =
22057: $selfenrollhash{$key}{$type}{$item};
22058: }
22059: }
22060: }
22061: }
22062: }
1.231 raeburn 22063: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22064: foreach my $item (@{$ordered{$key}}) {
22065: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22066: $resulttext .= '<li>';
22067: if ($key eq 'admin') {
22068: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22069: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22070: } else {
22071: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22072: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22073: }
22074: $resulttext .= '</li>';
22075: }
22076: }
22077: $resulttext .= '</ul></li>';
22078: }
22079: }
22080: $resulttext .= '</ul></li>';
22081: }
22082: }
1.305 raeburn 22083: }
22084: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22085: my $cachetime = 24*60*60;
22086: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22087: if (ref($lastactref) eq 'HASH') {
22088: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22089: }
1.231 raeburn 22090: }
22091: $resulttext .= '</ul>';
22092: } else {
22093: $resulttext = &mt('No changes made to self-enrollment settings');
22094: }
22095: } else {
22096: $resulttext = '<span class="LC_error">'.
22097: &mt('An error occurred: [_1]',$putresult).'</span>';
22098: }
22099: return $resulttext;
22100: }
22101:
1.373 raeburn 22102: sub modify_wafproxy {
22103: my ($dom,$action,$lastactref,%domconfig) = @_;
22104: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22105: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22106: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22107: foreach my $server (sort(keys(%servers))) {
22108: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22109: if ($serverhome eq $server) {
22110: my $serverdom = &Apache::lonnet::host_domain($server);
22111: if ($serverdom eq $dom) {
22112: $canset{$server} = 1;
22113: }
22114: }
22115: }
1.381 raeburn 22116: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22117: %{$values{$dom}} = ();
22118: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22119: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22120: }
1.388 raeburn 22121: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22122: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22123: }
1.382 raeburn 22124: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22125: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22126: }
22127: }
1.373 raeburn 22128: my $output;
22129: if (keys(%canset)) {
22130: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22131: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22132: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22133: if ($env{'form.wafproxy_'.$dom}) {
22134: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22135: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22136: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22137: $changes{'alias'} = 1;
22138: }
1.388 raeburn 22139: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22140: $wafproxy{'saml'}{$key} = 1;
22141: }
22142: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22143: $changes{'saml'} = 1;
22144: }
1.381 raeburn 22145: } else {
22146: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22147: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22148: if ($curralias{$key}) {
22149: $changes{'alias'} = 1;
22150: }
1.388 raeburn 22151: if ($currsaml{$key}) {
22152: $changes{'saml'} = 1;
22153: }
1.373 raeburn 22154: }
22155: if ($wafproxy{'alias'}{$key} eq '') {
22156: if ($curralias{$key}) {
22157: $expirecache{$key} = 1;
22158: }
22159: delete($wafproxy{'alias'}{$key});
22160: }
1.388 raeburn 22161: if ($wafproxy{'saml'}{$key} eq '') {
22162: if ($currsaml{$key}) {
22163: $expiresaml{$key} = 1;
22164: }
22165: delete($wafproxy{'saml'}{$key});
22166: }
1.373 raeburn 22167: }
22168: unless (keys(%{$wafproxy{'alias'}})) {
22169: delete($wafproxy{'alias'});
22170: }
1.388 raeburn 22171: unless (keys(%{$wafproxy{'saml'}})) {
22172: delete($wafproxy{'saml'});
22173: }
22174: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22175: my %warn = (
22176: trusted => 'trusted IP range(s)',
1.381 raeburn 22177: vpnint => 'internal IP range(s) for VPN sessions(s)',
22178: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22179: );
1.382 raeburn 22180: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22181: my $possible = $env{'form.wafproxy_'.$item};
22182: $possible =~ s/^\s+|\s+$//g;
22183: if ($possible ne '') {
1.381 raeburn 22184: if ($item eq 'remoteip') {
22185: if ($possible =~ /^[mhn]$/) {
22186: $wafproxy{$item} = $possible;
22187: }
22188: } elsif ($item eq 'ipheader') {
22189: if ($wafproxy{'remoteip'} eq 'h') {
22190: $wafproxy{$item} = $possible;
22191: }
1.382 raeburn 22192: } elsif ($item eq 'sslopt') {
22193: if ($possible =~ /^0|1$/) {
22194: $wafproxy{$item} = $possible;
22195: }
1.373 raeburn 22196: } else {
22197: my (@ok,$count);
1.381 raeburn 22198: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22199: unless ($env{'form.wafproxy_vpnaccess'}) {
22200: $possible = '';
22201: }
22202: } elsif ($item eq 'trusted') {
22203: unless ($wafproxy{'remoteip'} eq 'h') {
22204: $possible = '';
22205: }
22206: }
22207: unless ($possible eq '') {
22208: $possible =~ s/[\r\n]+/\s/g;
22209: $possible =~ s/\s*-\s*/-/g;
22210: $possible =~ s/\s+/,/g;
1.393 raeburn 22211: $possible =~ s/,+/,/g;
1.381 raeburn 22212: }
1.373 raeburn 22213: $count = 0;
1.381 raeburn 22214: if ($possible ne '') {
1.373 raeburn 22215: foreach my $poss (split(/\,/,$possible)) {
22216: $count ++;
1.393 raeburn 22217: $poss = &validate_ip_pattern($poss);
22218: if ($poss ne '') {
1.373 raeburn 22219: push(@ok,$poss);
22220: }
22221: }
22222: my $diff = $count - scalar(@ok);
22223: if ($diff) {
22224: push(@warnings,'<li>'.
22225: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22226: $diff,$warn{$item}).
22227: '</li>');
22228: }
1.393 raeburn 22229: if (@ok) {
22230: my @cidr_list;
22231: foreach my $item (@ok) {
22232: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22233: }
22234: $wafproxy{$item} = join(',',@cidr_list);
22235: }
1.373 raeburn 22236: }
22237: }
1.381 raeburn 22238: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22239: $changes{$item} = 1;
22240: }
1.381 raeburn 22241: } elsif ($currvalue{$item}) {
22242: $changes{$item} = 1;
1.425 raeburn 22243: }
1.381 raeburn 22244: }
22245: } else {
22246: if (keys(%curralias)) {
22247: $changes{'alias'} = 1;
1.388 raeburn 22248: }
22249: if (keys(%currsaml)) {
22250: $changes{'saml'} = 1;
1.425 raeburn 22251: }
1.381 raeburn 22252: if (keys(%currvalue)) {
22253: foreach my $key (keys(%currvalue)) {
22254: $changes{$key} = 1;
1.373 raeburn 22255: }
22256: }
22257: }
22258: if (keys(%changes)) {
22259: my %defaultshash = (
22260: wafproxy => \%wafproxy,
1.425 raeburn 22261: );
1.373 raeburn 22262: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22263: $dom);
22264: if ($putresult eq 'ok') {
22265: my $cachetime = 24*60*60;
22266: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22267: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22268: if ($changes{$item}) {
22269: unless ($updatedomdefs) {
22270: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22271: $updatedomdefs = 1;
22272: }
22273: if ($wafproxy{$item}) {
22274: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22275: } elsif (exists($domdefaults{'waf_'.$item})) {
22276: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22277: }
1.373 raeburn 22278: }
22279: }
22280: if ($updatedomdefs) {
22281: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22282: if (ref($lastactref) eq 'HASH') {
22283: $lastactref->{'domdefaults'} = 1;
22284: }
22285: }
22286: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22287: my %updates = %expirecache;
22288: foreach my $key (keys(%expirecache)) {
22289: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22290: }
22291: if (ref($wafproxy{'alias'}) eq 'HASH') {
22292: my $cachetime = 24*60*60;
22293: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22294: $updates{$key} = 1;
22295: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22296: $cachetime);
22297: }
22298: }
22299: if (ref($lastactref) eq 'HASH') {
22300: $lastactref->{'proxyalias'} = \%updates;
22301: }
22302: }
1.388 raeburn 22303: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22304: my %samlupdates = %expiresaml;
22305: foreach my $key (keys(%expiresaml)) {
22306: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22307: }
22308: if (ref($wafproxy{'saml'}) eq 'HASH') {
22309: my $cachetime = 24*60*60;
22310: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22311: $samlupdates{$key} = 1;
22312: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22313: $cachetime);
22314: }
22315: }
22316: if (ref($lastactref) eq 'HASH') {
22317: $lastactref->{'proxysaml'} = \%samlupdates;
22318: }
22319: }
1.373 raeburn 22320: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22321: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22322: if ($changes{$item}) {
22323: if ($item eq 'alias') {
22324: my $numaliased = 0;
22325: if (ref($wafproxy{'alias'}) eq 'HASH') {
22326: my $shown;
22327: if (keys(%{$wafproxy{'alias'}})) {
22328: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22329: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22330: &Apache::lonnet::hostname($server),
22331: $wafproxy{'alias'}{$server}).'</li>';
22332: $numaliased ++;
22333: }
22334: if ($numaliased) {
22335: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22336: '<ul>'.$shown.'</ul>').'</li>';
22337: }
22338: }
22339: }
22340: unless ($numaliased) {
22341: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22342: }
1.388 raeburn 22343: } elsif ($item eq 'saml') {
1.425 raeburn 22344: my $shown;
1.388 raeburn 22345: if (ref($wafproxy{'saml'}) eq 'HASH') {
22346: if (keys(%{$wafproxy{'saml'}})) {
22347: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22348: }
22349: }
22350: if ($shown) {
1.396 raeburn 22351: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22352: $shown).'</li>';
22353: } else {
1.396 raeburn 22354: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22355: }
1.373 raeburn 22356: } else {
1.381 raeburn 22357: if ($item eq 'remoteip') {
22358: my %ip_methods = &remoteip_methods();
22359: if ($wafproxy{$item} =~ /^[mh]$/) {
22360: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22361: $ip_methods{$wafproxy{$item}}).'</li>';
22362: } else {
22363: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22364: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22365: '</li>';
22366: } else {
22367: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22368: }
22369: }
22370: } elsif ($item eq 'ipheader') {
1.373 raeburn 22371: if ($wafproxy{$item}) {
1.381 raeburn 22372: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22373: $wafproxy{$item}).'</li>';
22374: } else {
1.381 raeburn 22375: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22376: }
22377: } elsif ($item eq 'trusted') {
22378: if ($wafproxy{$item}) {
1.381 raeburn 22379: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22380: $wafproxy{$item}).'</li>';
22381: } else {
22382: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22383: }
1.381 raeburn 22384: } elsif ($item eq 'vpnint') {
22385: if ($wafproxy{$item}) {
22386: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22387: $wafproxy{$item}).'</li>';
22388: } else {
22389: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22390: }
22391: } elsif ($item eq 'vpnext') {
1.373 raeburn 22392: if ($wafproxy{$item}) {
1.381 raeburn 22393: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22394: $wafproxy{$item}).'</li>';
22395: } else {
1.381 raeburn 22396: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22397: }
1.382 raeburn 22398: } elsif ($item eq 'sslopt') {
22399: if ($wafproxy{$item}) {
22400: $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>';
22401: } else {
22402: $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>';
22403: }
1.373 raeburn 22404: }
22405: }
22406: }
22407: }
1.420 raeburn 22408: $output .= '</ul>';
1.373 raeburn 22409: } else {
22410: $output = '<span class="LC_error">'.
22411: &mt('An error occurred: [_1]',$putresult).'</span>';
22412: }
22413: } elsif (keys(%canset)) {
22414: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22415: }
22416: if (@warnings) {
22417: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22418: join("\n",@warnings).'</ul>';
22419: }
22420: return $output;
22421: }
22422:
22423: sub validate_ip_pattern {
22424: my ($pattern) = @_;
22425: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22426: my ($start,$end) = ($1,$2);
22427: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22428: if (($start !~ m{/}) && ($end !~ m{/})) {
22429: return $start.'-'.$end;
22430: }
22431: }
22432: } elsif ($pattern ne '') {
22433: $pattern = &Net::CIDR::cidrvalidate($pattern);
22434: if ($pattern ne '') {
22435: return $pattern;
1.373 raeburn 22436: }
22437: }
1.393 raeburn 22438: return;
1.373 raeburn 22439: }
22440:
1.137 raeburn 22441: sub modify_usersessions {
1.212 raeburn 22442: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22443: my @hostingtypes = ('version','excludedomain','includedomain');
22444: my @offloadtypes = ('primary','default');
22445: my %types = (
22446: remote => \@hostingtypes,
22447: hosted => \@hostingtypes,
22448: spares => \@offloadtypes,
22449: );
22450: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22451: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22452: my (%by_ip,%by_location,@intdoms,@instdoms);
22453: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22454: my @locations = sort(keys(%by_location));
1.137 raeburn 22455: my (%defaultshash,%changes);
22456: foreach my $prefix (@prefixes) {
22457: $defaultshash{'usersessions'}{$prefix} = {};
22458: }
1.212 raeburn 22459: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22460: my $resulttext;
1.138 raeburn 22461: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22462: foreach my $prefix (@prefixes) {
1.145 raeburn 22463: next if ($prefix eq 'spares');
22464: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22465: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22466: if ($type eq 'version') {
22467: my $value = $env{'form.'.$prefix.'_'.$type};
22468: my $okvalue;
22469: if ($value ne '') {
22470: if (grep(/^\Q$value\E$/,@lcversions)) {
22471: $okvalue = $value;
22472: }
22473: }
22474: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22475: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22476: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22477: if ($inuse == 0) {
22478: $changes{$prefix}{$type} = 1;
22479: } else {
22480: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22481: $changes{$prefix}{$type} = 1;
22482: }
22483: if ($okvalue ne '') {
22484: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22485: }
22486: }
22487: } else {
22488: if (($inuse == 1) && ($okvalue ne '')) {
22489: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22490: $changes{$prefix}{$type} = 1;
22491: }
22492: }
22493: } else {
22494: if (($inuse == 1) && ($okvalue ne '')) {
22495: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22496: $changes{$prefix}{$type} = 1;
22497: }
22498: }
22499: } else {
22500: if (($inuse == 1) && ($okvalue ne '')) {
22501: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22502: $changes{$prefix}{$type} = 1;
22503: }
22504: }
22505: } else {
22506: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22507: my @okvals;
22508: foreach my $val (@vals) {
1.138 raeburn 22509: if ($val =~ /:/) {
22510: my @items = split(/:/,$val);
22511: foreach my $item (@items) {
22512: if (ref($by_location{$item}) eq 'ARRAY') {
22513: push(@okvals,$item);
22514: }
22515: }
22516: } else {
22517: if (ref($by_location{$val}) eq 'ARRAY') {
22518: push(@okvals,$val);
22519: }
1.137 raeburn 22520: }
22521: }
22522: @okvals = sort(@okvals);
22523: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22524: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22525: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22526: if ($inuse == 0) {
22527: $changes{$prefix}{$type} = 1;
22528: } else {
22529: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22530: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22531: if (@changed > 0) {
22532: $changes{$prefix}{$type} = 1;
22533: }
22534: }
22535: } else {
22536: if ($inuse == 1) {
22537: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22538: $changes{$prefix}{$type} = 1;
22539: }
22540: }
22541: } else {
22542: if ($inuse == 1) {
22543: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22544: $changes{$prefix}{$type} = 1;
22545: }
22546: }
22547: } else {
22548: if ($inuse == 1) {
22549: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22550: $changes{$prefix}{$type} = 1;
22551: }
22552: }
22553: }
22554: }
22555: }
1.145 raeburn 22556:
22557: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22558: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22559: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22560: my $savespares;
22561:
22562: foreach my $lonhost (sort(keys(%servers))) {
22563: my $serverhomeID =
22564: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22565: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22566: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22567: my %spareschg;
22568: foreach my $type (@{$types{'spares'}}) {
22569: my @okspares;
22570: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22571: foreach my $server (@checked) {
1.152 raeburn 22572: if (&Apache::lonnet::hostname($server) ne '') {
22573: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22574: unless (grep(/^\Q$server\E$/,@okspares)) {
22575: push(@okspares,$server);
22576: }
1.145 raeburn 22577: }
22578: }
22579: }
22580: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22581: my $newspare;
1.152 raeburn 22582: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22583: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22584: $newspare = $new;
22585: }
22586: }
1.152 raeburn 22587: my @spares;
22588: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22589: @spares = sort(@okspares,$newspare);
22590: } else {
22591: @spares = sort(@okspares);
22592: }
22593: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22594: if (ref($spareid{$lonhost}) eq 'HASH') {
22595: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22596: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22597: if (@diffs > 0) {
22598: $spareschg{$type} = 1;
22599: }
22600: }
22601: }
22602: }
22603: if (keys(%spareschg) > 0) {
22604: $changes{'spares'}{$lonhost} = \%spareschg;
22605: }
22606: }
1.261 raeburn 22607: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22608: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22609: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22610: my @okoffload;
22611: if (@offloadnow) {
22612: foreach my $server (@offloadnow) {
22613: if (&Apache::lonnet::hostname($server) ne '') {
22614: unless (grep(/^\Q$server\E$/,@okoffload)) {
22615: push(@okoffload,$server);
22616: }
22617: }
22618: }
22619: if (@okoffload) {
22620: foreach my $lonhost (@okoffload) {
22621: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22622: }
22623: }
22624: }
1.371 raeburn 22625: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22626: my @okoffloadoth;
22627: if (@offloadoth) {
22628: foreach my $server (@offloadoth) {
22629: if (&Apache::lonnet::hostname($server) ne '') {
22630: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22631: push(@okoffloadoth,$server);
22632: }
22633: }
22634: }
22635: if (@okoffloadoth) {
22636: foreach my $lonhost (@okoffloadoth) {
22637: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22638: }
22639: }
22640: }
1.145 raeburn 22641: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22642: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22643: if (ref($changes{'spares'}) eq 'HASH') {
22644: if (keys(%{$changes{'spares'}}) > 0) {
22645: $savespares = 1;
22646: }
22647: }
22648: } else {
22649: $savespares = 1;
22650: }
1.371 raeburn 22651: foreach my $offload ('offloadnow','offloadoth') {
22652: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22653: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22654: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22655: $changes{$offload} = 1;
22656: last;
22657: }
1.261 raeburn 22658: }
1.371 raeburn 22659: unless ($changes{$offload}) {
22660: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22661: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22662: $changes{$offload} = 1;
22663: last;
22664: }
1.261 raeburn 22665: }
22666: }
1.371 raeburn 22667: } else {
22668: if (($offload eq 'offloadnow') && (@okoffload)) {
22669: $changes{'offloadnow'} = 1;
22670: }
22671: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22672: $changes{'offloadoth'} = 1;
22673: }
1.425 raeburn 22674: }
1.371 raeburn 22675: }
22676: } else {
22677: if (@okoffload) {
1.261 raeburn 22678: $changes{'offloadnow'} = 1;
22679: }
1.371 raeburn 22680: if (@okoffloadoth) {
22681: $changes{'offloadoth'} = 1;
22682: }
1.145 raeburn 22683: }
1.147 raeburn 22684: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22685: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22686: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22687: $dom);
22688: if ($putresult eq 'ok') {
22689: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22690: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22691: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22692: }
22693: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22694: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22695: }
1.261 raeburn 22696: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22697: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22698: }
1.371 raeburn 22699: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22700: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22701: }
1.137 raeburn 22702: }
22703: my $cachetime = 24*60*60;
22704: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22705: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22706: if (ref($lastactref) eq 'HASH') {
22707: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22708: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22709: }
1.147 raeburn 22710: if (keys(%changes) > 0) {
22711: my %lt = &usersession_titles();
22712: $resulttext = &mt('Changes made:').'<ul>';
22713: foreach my $prefix (@prefixes) {
22714: if (ref($changes{$prefix}) eq 'HASH') {
22715: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22716: if ($prefix eq 'spares') {
22717: if (ref($changes{$prefix}) eq 'HASH') {
22718: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22719: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22720: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22721: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22722: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22723: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22724: foreach my $type (@{$types{$prefix}}) {
22725: if ($changes{$prefix}{$lonhost}{$type}) {
22726: my $offloadto = &mt('None');
22727: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22728: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22729: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22730: }
1.145 raeburn 22731: }
1.147 raeburn 22732: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22733: }
1.137 raeburn 22734: }
22735: }
1.147 raeburn 22736: $resulttext .= '</li>';
1.137 raeburn 22737: }
22738: }
1.147 raeburn 22739: } else {
22740: foreach my $type (@{$types{$prefix}}) {
22741: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22742: my ($newvalue,$notinuse);
1.147 raeburn 22743: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22744: if (ref($defaultshash{'usersessions'}{$prefix})) {
22745: if ($type eq 'version') {
22746: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22747: } else {
22748: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22749: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22750: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22751: }
22752: } else {
22753: $notinuse = 1;
1.147 raeburn 22754: }
1.145 raeburn 22755: }
22756: }
22757: }
1.147 raeburn 22758: if ($newvalue eq '') {
22759: if ($type eq 'version') {
22760: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22761: } elsif ($notinuse) {
22762: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22763: } else {
22764: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22765: }
1.145 raeburn 22766: } else {
1.147 raeburn 22767: if ($type eq 'version') {
1.344 raeburn 22768: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22769: }
22770: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22771: }
1.137 raeburn 22772: }
22773: }
22774: }
1.147 raeburn 22775: $resulttext .= '</ul>';
1.137 raeburn 22776: }
22777: }
1.261 raeburn 22778: if ($changes{'offloadnow'}) {
22779: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22780: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22781: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22782: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22783: $resulttext .= '<li>'.$lonhost.'</li>';
22784: }
22785: $resulttext .= '</ul>';
22786: } else {
1.371 raeburn 22787: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22788: }
22789: } else {
22790: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22791: }
22792: }
22793: if ($changes{'offloadoth'}) {
22794: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22795: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22796: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22797: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22798: $resulttext .= '<li>'.$lonhost.'</li>';
22799: }
22800: $resulttext .= '</ul>';
22801: } else {
22802: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22803: }
22804: } else {
1.371 raeburn 22805: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22806: }
22807: }
1.147 raeburn 22808: $resulttext .= '</ul>';
22809: } else {
22810: $resulttext = $nochgmsg;
1.137 raeburn 22811: }
22812: } else {
22813: $resulttext = '<span class="LC_error">'.
22814: &mt('An error occurred: [_1]',$putresult).'</span>';
22815: }
22816: } else {
1.147 raeburn 22817: $resulttext = $nochgmsg;
1.137 raeburn 22818: }
22819: return $resulttext;
22820: }
22821:
1.275 raeburn 22822: sub modify_ssl {
22823: my ($dom,$lastactref,%domconfig) = @_;
22824: my (%by_ip,%by_location,@intdoms,@instdoms);
22825: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22826: my @locations = sort(keys(%by_location));
22827: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22828: my (%defaultshash,%changes);
22829: my $action = 'ssl';
1.293 raeburn 22830: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22831: foreach my $prefix (@prefixes) {
22832: $defaultshash{$action}{$prefix} = {};
22833: }
22834: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22835: my $resulttext;
22836: my %iphost = &Apache::lonnet::get_iphost();
22837: my @reptypes = ('certreq','nocertreq');
22838: my @connecttypes = ('dom','intdom','other');
22839: my %types = (
1.293 raeburn 22840: connto => \@connecttypes,
22841: connfrom => \@connecttypes,
22842: replication => \@reptypes,
1.275 raeburn 22843: );
22844: foreach my $prefix (sort(keys(%types))) {
22845: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22846: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22847: my $value = 'yes';
22848: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22849: $value = $env{'form.'.$prefix.'_'.$type};
22850: }
1.335 raeburn 22851: if (ref($domconfig{$action}) eq 'HASH') {
22852: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22853: if ($domconfig{$action}{$prefix}{$type} ne '') {
22854: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22855: $changes{$prefix}{$type} = 1;
22856: }
22857: $defaultshash{$action}{$prefix}{$type} = $value;
22858: } else {
22859: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22860: $changes{$prefix}{$type} = 1;
22861: }
22862: } else {
22863: $defaultshash{$action}{$prefix}{$type} = $value;
22864: $changes{$prefix}{$type} = 1;
22865: }
22866: } else {
22867: $defaultshash{$action}{$prefix}{$type} = $value;
22868: $changes{$prefix}{$type} = 1;
22869: }
22870: if (($type eq 'dom') && (keys(%servers) == 1)) {
22871: delete($changes{$prefix}{$type});
22872: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22873: delete($changes{$prefix}{$type});
22874: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22875: delete($changes{$prefix}{$type});
22876: }
22877: } elsif ($prefix eq 'replication') {
22878: if (@locations > 0) {
22879: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22880: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22881: my @okvals;
22882: foreach my $val (@vals) {
22883: if ($val =~ /:/) {
22884: my @items = split(/:/,$val);
22885: foreach my $item (@items) {
22886: if (ref($by_location{$item}) eq 'ARRAY') {
22887: push(@okvals,$item);
22888: }
22889: }
22890: } else {
22891: if (ref($by_location{$val}) eq 'ARRAY') {
22892: push(@okvals,$val);
22893: }
22894: }
22895: }
22896: @okvals = sort(@okvals);
22897: if (ref($domconfig{$action}) eq 'HASH') {
22898: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22899: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22900: if ($inuse == 0) {
22901: $changes{$prefix}{$type} = 1;
22902: } else {
22903: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22904: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22905: if (@changed > 0) {
22906: $changes{$prefix}{$type} = 1;
22907: }
22908: }
22909: } else {
22910: if ($inuse == 1) {
22911: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22912: $changes{$prefix}{$type} = 1;
22913: }
22914: }
22915: } else {
22916: if ($inuse == 1) {
22917: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22918: $changes{$prefix}{$type} = 1;
22919: }
22920: }
22921: } else {
22922: if ($inuse == 1) {
22923: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22924: $changes{$prefix}{$type} = 1;
22925: }
22926: }
22927: }
22928: }
22929: }
22930: }
1.336 raeburn 22931: if (keys(%changes)) {
22932: foreach my $prefix (keys(%changes)) {
22933: if (ref($changes{$prefix}) eq 'HASH') {
22934: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22935: delete($changes{$prefix});
22936: }
22937: } else {
22938: delete($changes{$prefix});
22939: }
22940: }
22941: }
1.275 raeburn 22942: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22943: if (keys(%changes) > 0) {
22944: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22945: $dom);
22946: if ($putresult eq 'ok') {
22947: if (ref($defaultshash{$action}) eq 'HASH') {
22948: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22949: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22950: }
1.293 raeburn 22951: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22952: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22953: }
22954: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22955: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22956: }
22957: }
22958: my $cachetime = 24*60*60;
22959: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22960: if (ref($lastactref) eq 'HASH') {
22961: $lastactref->{'domdefaults'} = 1;
22962: }
22963: if (keys(%changes) > 0) {
22964: my %titles = &ssl_titles();
22965: $resulttext = &mt('Changes made:').'<ul>';
22966: foreach my $prefix (@prefixes) {
22967: if (ref($changes{$prefix}) eq 'HASH') {
22968: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22969: foreach my $type (@{$types{$prefix}}) {
22970: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22971: my ($newvalue,$notinuse);
1.275 raeburn 22972: if (ref($defaultshash{$action}) eq 'HASH') {
22973: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22974: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22975: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22976: } else {
22977: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22978: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22979: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22980: }
22981: } else {
22982: $notinuse = 1;
1.275 raeburn 22983: }
22984: }
22985: }
1.344 raeburn 22986: if ($notinuse) {
22987: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22988: } elsif ($newvalue eq '') {
1.275 raeburn 22989: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22990: } else {
22991: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22992: }
22993: }
22994: }
22995: }
22996: $resulttext .= '</ul>';
22997: }
22998: }
22999: } else {
23000: $resulttext = $nochgmsg;
23001: }
23002: } else {
23003: $resulttext = '<span class="LC_error">'.
23004: &mt('An error occurred: [_1]',$putresult).'</span>';
23005: }
23006: } else {
23007: $resulttext = $nochgmsg;
23008: }
23009: return $resulttext;
23010: }
23011:
1.279 raeburn 23012: sub modify_trust {
23013: my ($dom,$lastactref,%domconfig) = @_;
23014: my (%by_ip,%by_location,@intdoms,@instdoms);
23015: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23016: my @locations = sort(keys(%by_location));
23017: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23018: my @types = ('exc','inc');
23019: my (%defaultshash,%changes);
23020: foreach my $prefix (@prefixes) {
23021: $defaultshash{'trust'}{$prefix} = {};
23022: }
23023: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23024: my $resulttext;
23025: foreach my $prefix (@prefixes) {
23026: foreach my $type (@types) {
23027: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23028: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23029: my @okvals;
23030: foreach my $val (@vals) {
23031: if ($val =~ /:/) {
23032: my @items = split(/:/,$val);
23033: foreach my $item (@items) {
23034: if (ref($by_location{$item}) eq 'ARRAY') {
23035: push(@okvals,$item);
23036: }
23037: }
23038: } else {
23039: if (ref($by_location{$val}) eq 'ARRAY') {
23040: push(@okvals,$val);
23041: }
23042: }
23043: }
23044: @okvals = sort(@okvals);
23045: if (ref($domconfig{'trust'}) eq 'HASH') {
23046: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23047: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23048: if ($inuse == 0) {
23049: $changes{$prefix}{$type} = 1;
23050: } else {
23051: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23052: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23053: if (@changed > 0) {
23054: $changes{$prefix}{$type} = 1;
23055: }
23056: }
23057: } else {
23058: if ($inuse == 1) {
23059: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23060: $changes{$prefix}{$type} = 1;
23061: }
23062: }
23063: } else {
23064: if ($inuse == 1) {
23065: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23066: $changes{$prefix}{$type} = 1;
23067: }
23068: }
23069: } else {
23070: if ($inuse == 1) {
23071: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23072: $changes{$prefix}{$type} = 1;
23073: }
23074: }
23075: }
23076: }
23077: my $nochgmsg = &mt('No changes made to trust settings.');
23078: if (keys(%changes) > 0) {
23079: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23080: $dom);
23081: if ($putresult eq 'ok') {
23082: if (ref($defaultshash{'trust'}) eq 'HASH') {
23083: foreach my $prefix (@prefixes) {
23084: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23085: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23086: }
23087: }
23088: }
23089: my $cachetime = 24*60*60;
23090: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23091: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23092: if (ref($lastactref) eq 'HASH') {
23093: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23094: $lastactref->{'trust'} = 1;
1.279 raeburn 23095: }
23096: if (keys(%changes) > 0) {
23097: my %lt = &trust_titles();
23098: $resulttext = &mt('Changes made:').'<ul>';
23099: foreach my $prefix (@prefixes) {
23100: if (ref($changes{$prefix}) eq 'HASH') {
23101: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23102: foreach my $type (@types) {
23103: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23104: my ($newvalue,$notinuse);
1.279 raeburn 23105: if (ref($defaultshash{'trust'}) eq 'HASH') {
23106: if (ref($defaultshash{'trust'}{$prefix})) {
23107: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23108: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23109: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23110: }
1.344 raeburn 23111: } else {
23112: $notinuse = 1;
1.279 raeburn 23113: }
23114: }
23115: }
1.344 raeburn 23116: if ($notinuse) {
23117: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23118: } elsif ($newvalue eq '') {
1.279 raeburn 23119: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23120: } else {
23121: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23122: }
23123: }
23124: }
23125: $resulttext .= '</ul>';
23126: }
23127: }
23128: $resulttext .= '</ul>';
23129: } else {
23130: $resulttext = $nochgmsg;
23131: }
23132: } else {
23133: $resulttext = '<span class="LC_error">'.
23134: &mt('An error occurred: [_1]',$putresult).'</span>';
23135: }
23136: } else {
23137: $resulttext = $nochgmsg;
23138: }
23139: return $resulttext;
23140: }
23141:
1.150 raeburn 23142: sub modify_loadbalancing {
23143: my ($dom,%domconfig) = @_;
23144: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23145: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23146: my ($othertitle,$usertypes,$types) =
23147: &Apache::loncommon::sorted_inst_types($dom);
23148: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23149: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23150: my @sparestypes = ('primary','default');
23151: my %typetitles = &sparestype_titles();
23152: my $resulttext;
1.342 raeburn 23153: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23154: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23155: %existing = %{$domconfig{'loadbalancing'}};
23156: }
23157: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23158: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23159: my ($saveloadbalancing,%defaultshash,%changes);
23160: my ($alltypes,$othertypes,$titles) =
23161: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23162: my %ruletitles = &offloadtype_text();
23163: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23164: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23165: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23166: if ($balancer eq '') {
23167: next;
23168: }
1.210 raeburn 23169: if (!exists($servers{$balancer})) {
1.171 raeburn 23170: if (exists($currbalancer{$balancer})) {
23171: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23172: }
1.171 raeburn 23173: next;
23174: }
23175: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23176: push(@{$changes{'delete'}},$balancer);
23177: next;
23178: }
23179: if (!exists($currbalancer{$balancer})) {
23180: push(@{$changes{'add'}},$balancer);
23181: }
23182: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23183: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23184: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23185: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23186: $saveloadbalancing = 1;
23187: }
23188: foreach my $sparetype (@sparestypes) {
23189: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23190: my @offloadto;
23191: foreach my $target (@targets) {
23192: if (($servers{$target}) && ($target ne $balancer)) {
23193: if ($sparetype eq 'default') {
23194: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23195: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23196: }
23197: }
1.171 raeburn 23198: unless(grep(/^\Q$target\E$/,@offloadto)) {
23199: push(@offloadto,$target);
23200: }
1.150 raeburn 23201: }
23202: }
1.284 raeburn 23203: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23204: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23205: push(@offloadto,$balancer);
23206: }
23207: }
23208: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23209: }
1.342 raeburn 23210: if ($env{'form.loadbalancing_cookie_'.$i}) {
23211: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23212: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23213: unless ($currcookies{$balancer}) {
23214: $changes{'curr'}{$balancer}{'cookie'} = 1;
23215: }
23216: }
23217: } elsif (exists($currbalancer{$balancer})) {
23218: if ($currcookies{$balancer}) {
23219: $changes{'curr'}{$balancer}{'cookie'} = 1;
23220: }
23221: }
1.171 raeburn 23222: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23223: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23224: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23225: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23226: if (@targetdiffs > 0) {
1.171 raeburn 23227: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23228: }
1.171 raeburn 23229: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23230: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23231: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23232: }
23233: }
23234: }
23235: } else {
1.171 raeburn 23236: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23237: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23238: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23239: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23240: $changes{'curr'}{$balancer}{'targets'} = 1;
23241: }
1.150 raeburn 23242: }
23243: }
1.210 raeburn 23244: }
1.150 raeburn 23245: }
23246: my $ishomedom;
1.171 raeburn 23247: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23248: $ishomedom = 1;
1.150 raeburn 23249: }
23250: if (ref($alltypes) eq 'ARRAY') {
23251: foreach my $type (@{$alltypes}) {
23252: my $rule;
1.210 raeburn 23253: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23254: (!$ishomedom)) {
1.171 raeburn 23255: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23256: }
23257: if ($rule eq 'specific') {
1.255 raeburn 23258: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23259: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23260: $rule = $specifiedhost;
23261: }
1.150 raeburn 23262: }
1.171 raeburn 23263: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23264: if (ref($currrules{$balancer}) eq 'HASH') {
23265: if ($rule ne $currrules{$balancer}{$type}) {
23266: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23267: }
23268: } elsif ($rule ne '') {
1.171 raeburn 23269: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23270: }
23271: }
23272: }
1.171 raeburn 23273: }
23274: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23275: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23276: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23277: $defaultshash{'loadbalancing'} = {};
23278: }
23279: my $putresult = &Apache::lonnet::put_dom('configuration',
23280: \%defaultshash,$dom);
23281: if ($putresult eq 'ok') {
23282: if (keys(%changes) > 0) {
1.252 raeburn 23283: my %toupdate;
1.171 raeburn 23284: if (ref($changes{'delete'}) eq 'ARRAY') {
23285: foreach my $balancer (sort(@{$changes{'delete'}})) {
23286: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23287: $toupdate{$balancer} = 1;
1.150 raeburn 23288: }
1.171 raeburn 23289: }
23290: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23291: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23292: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23293: $toupdate{$balancer} = 1;
1.171 raeburn 23294: }
23295: }
23296: if (ref($changes{'curr'}) eq 'HASH') {
23297: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23298: $toupdate{$balancer} = 1;
1.171 raeburn 23299: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23300: if ($changes{'curr'}{$balancer}{'targets'}) {
23301: my %offloadstr;
23302: foreach my $sparetype (@sparestypes) {
23303: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23304: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23305: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23306: }
23307: }
1.150 raeburn 23308: }
1.171 raeburn 23309: if (keys(%offloadstr) == 0) {
23310: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23311: } else {
1.171 raeburn 23312: my $showoffload;
23313: foreach my $sparetype (@sparestypes) {
23314: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23315: if (defined($offloadstr{$sparetype})) {
23316: $showoffload .= $offloadstr{$sparetype};
23317: } else {
23318: $showoffload .= &mt('None');
23319: }
23320: $showoffload .= (' 'x3);
23321: }
23322: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23323: }
23324: }
23325: }
1.171 raeburn 23326: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23327: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23328: foreach my $type (@{$alltypes}) {
23329: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23330: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23331: my $balancetext;
23332: if ($rule eq '') {
23333: $balancetext = $ruletitles{'default'};
1.209 raeburn 23334: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23335: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23336: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23337: foreach my $sparetype (@sparestypes) {
23338: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23339: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23340: }
23341: }
1.253 raeburn 23342: foreach my $item (@{$alltypes}) {
23343: next if ($item =~ /^_LC_ipchange/);
23344: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23345: if ($hasrule eq 'homeserver') {
23346: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23347: } else {
23348: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23349: if ($servers{$hasrule}) {
23350: $toupdate{$hasrule} = 1;
23351: }
23352: }
23353: }
23354: }
1.254 raeburn 23355: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23356: $balancetext = $ruletitles{$rule};
23357: } else {
23358: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23359: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23360: if ($receiver) {
23361: $toupdate{$receiver};
23362: }
23363: }
23364: } else {
23365: $balancetext = $ruletitles{$rule};
1.252 raeburn 23366: }
1.171 raeburn 23367: } else {
23368: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23369: }
1.210 raeburn 23370: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23371: }
23372: }
23373: }
23374: }
1.342 raeburn 23375: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23376: if ($currcookies{$balancer}) {
23377: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23378: $balancer).'</li>';
23379: } else {
23380: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23381: $balancer).'</li>';
23382: }
1.342 raeburn 23383: }
1.375 raeburn 23384: }
23385: }
23386: if (keys(%toupdate)) {
23387: my %thismachine;
23388: my $updatedhere;
23389: my $cachetime = 60*60*24;
23390: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23391: foreach my $lonhost (keys(%toupdate)) {
23392: if ($thismachine{$lonhost}) {
23393: unless ($updatedhere) {
23394: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23395: $defaultshash{'loadbalancing'},
23396: $cachetime);
23397: $updatedhere = 1;
1.252 raeburn 23398: }
1.375 raeburn 23399: } else {
23400: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23401: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23402: }
1.150 raeburn 23403: }
1.171 raeburn 23404: }
23405: if ($resulttext ne '') {
23406: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23407: } else {
23408: $resulttext = $nochgmsg;
23409: }
23410: } else {
1.171 raeburn 23411: $resulttext = $nochgmsg;
1.150 raeburn 23412: }
23413: } else {
1.171 raeburn 23414: $resulttext = '<span class="LC_error">'.
23415: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23416: }
23417: } else {
1.171 raeburn 23418: $resulttext = $nochgmsg;
1.150 raeburn 23419: }
23420: return $resulttext;
23421: }
23422:
1.48 raeburn 23423: sub recurse_check {
23424: my ($chkcats,$categories,$depth,$name) = @_;
23425: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23426: my $chg = 0;
23427: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23428: my $category = $chkcats->[$depth]{$name}[$j];
23429: my $item;
23430: if ($category eq '') {
23431: $chg ++;
23432: } else {
23433: my $deeper = $depth + 1;
23434: $item = &escape($category).':'.&escape($name).':'.$depth;
23435: if ($chg) {
23436: $categories->{$item} -= $chg;
23437: }
23438: &recurse_check($chkcats,$categories,$deeper,$category);
23439: $deeper --;
23440: }
23441: }
23442: }
23443: return;
23444: }
23445:
23446: sub recurse_cat_deletes {
23447: my ($item,$coursecategories,$deletions) = @_;
23448: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23449: my $subdepth = $depth + 1;
23450: if (ref($coursecategories) eq 'HASH') {
23451: foreach my $subitem (keys(%{$coursecategories})) {
23452: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23453: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23454: delete($coursecategories->{$subitem});
23455: $deletions->{$subitem} = 1;
23456: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23457: }
1.48 raeburn 23458: }
23459: }
23460: return;
23461: }
23462:
1.125 raeburn 23463: sub active_dc_picker {
1.191 raeburn 23464: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23465: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23466: my @domcoord = keys(%domcoords);
23467: if (keys(%currhash)) {
23468: foreach my $dc (keys(%currhash)) {
23469: unless (exists($domcoords{$dc})) {
23470: push(@domcoord,$dc);
23471: }
23472: }
23473: }
23474: @domcoord = sort(@domcoord);
1.210 raeburn 23475: my $numdcs = scalar(@domcoord);
1.191 raeburn 23476: my $rows = 0;
23477: my $table;
1.125 raeburn 23478: if ($numdcs > 1) {
1.191 raeburn 23479: $table = '<table>';
23480: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23481: my $rem = $i%($numinrow);
23482: if ($rem == 0) {
23483: if ($i > 0) {
1.191 raeburn 23484: $table .= '</tr>';
1.125 raeburn 23485: }
1.191 raeburn 23486: $table .= '<tr>';
23487: $rows ++;
1.125 raeburn 23488: }
1.191 raeburn 23489: my $check = '';
23490: if ($inputtype eq 'radio') {
23491: if (keys(%currhash) == 0) {
23492: if (!$i) {
23493: $check = ' checked="checked"';
23494: }
23495: } elsif (exists($currhash{$domcoord[$i]})) {
23496: $check = ' checked="checked"';
23497: }
23498: } else {
23499: if (exists($currhash{$domcoord[$i]})) {
23500: $check = ' checked="checked"';
1.125 raeburn 23501: }
23502: }
1.191 raeburn 23503: if ($i == @domcoord - 1) {
1.125 raeburn 23504: my $colsleft = $numinrow - $rem;
23505: if ($colsleft > 1) {
1.191 raeburn 23506: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23507: } else {
1.191 raeburn 23508: $table .= '<td class="LC_left_item">';
1.125 raeburn 23509: }
23510: } else {
1.191 raeburn 23511: $table .= '<td class="LC_left_item">';
23512: }
23513: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23514: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23515: $table .= '<span class="LC_nobreak"><label>'.
23516: '<input type="'.$inputtype.'" name="'.$name.'"'.
23517: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23518: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23519: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23520: }
1.219 raeburn 23521: $table .= '</label></span></td>';
1.191 raeburn 23522: }
23523: $table .= '</tr></table>';
23524: } elsif ($numdcs == 1) {
1.219 raeburn 23525: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23526: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23527: if ($inputtype eq 'radio') {
1.247 raeburn 23528: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23529: if ($user ne $dcname.':'.$dcdom) {
23530: $table .= ' ('.$dcname.':'.$dcdom.')';
23531: }
1.191 raeburn 23532: } else {
23533: my $check;
23534: if (exists($currhash{$domcoord[0]})) {
23535: $check = ' checked="checked"';
1.125 raeburn 23536: }
1.247 raeburn 23537: $table = '<span class="LC_nobreak"><label>'.
23538: '<input type="checkbox" name="'.$name.'" '.
23539: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23540: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23541: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23542: }
1.220 raeburn 23543: $table .= '</label></span>';
1.191 raeburn 23544: $rows ++;
1.125 raeburn 23545: }
23546: }
1.191 raeburn 23547: return ($numdcs,$table,$rows);
1.125 raeburn 23548: }
23549:
1.137 raeburn 23550: sub usersession_titles {
23551: return &Apache::lonlocal::texthash(
23552: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23553: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23554: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23555: version => 'LON-CAPA version requirement',
1.138 raeburn 23556: excludedomain => 'Allow all, but exclude specific domains',
23557: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23558: primary => 'Primary (checked first)',
1.154 raeburn 23559: default => 'Default',
1.137 raeburn 23560: );
23561: }
23562:
1.152 raeburn 23563: sub id_for_thisdom {
23564: my (%servers) = @_;
23565: my %altids;
23566: foreach my $server (keys(%servers)) {
23567: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23568: if ($serverhome ne $server) {
23569: $altids{$serverhome} = $server;
23570: }
23571: }
23572: return %altids;
23573: }
23574:
1.150 raeburn 23575: sub count_servers {
23576: my ($currbalancer,%servers) = @_;
23577: my (@spares,$numspares);
23578: foreach my $lonhost (sort(keys(%servers))) {
23579: next if ($currbalancer eq $lonhost);
23580: push(@spares,$lonhost);
23581: }
23582: if ($currbalancer) {
23583: $numspares = scalar(@spares);
23584: } else {
23585: $numspares = scalar(@spares) - 1;
23586: }
23587: return ($numspares,@spares);
23588: }
23589:
23590: sub lonbalance_targets_js {
1.171 raeburn 23591: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23592: my $select = &mt('Select');
23593: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23594: if (ref($servers) eq 'HASH') {
23595: $alltargets = join("','",sort(keys(%{$servers})));
23596: my @homedoms;
23597: foreach my $server (sort(keys(%{$servers}))) {
23598: if (&Apache::lonnet::host_domain($server) eq $dom) {
23599: push(@homedoms,'1');
23600: } else {
23601: push(@homedoms,'0');
23602: }
23603: }
23604: $allishome = join("','",@homedoms);
23605: }
23606: if (ref($types) eq 'ARRAY') {
23607: if (@{$types} > 0) {
23608: @alltypes = @{$types};
23609: }
23610: }
23611: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23612: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23613: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23614: if (ref($settings) eq 'HASH') {
23615: %existing = %{$settings};
23616: }
23617: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23618: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23619: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23620: return <<"END";
23621:
23622: <script type="text/javascript">
23623: // <![CDATA[
23624:
1.171 raeburn 23625: currBalancers = new Array('$balancers');
23626:
23627: function toggleTargets(balnum) {
23628: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23629: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23630: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23631: var prevbalancer = prevhostitem.value;
23632: var baltotal = document.getElementById('loadbalancing_total').value;
23633: prevhostitem.value = balancer;
23634: if (prevbalancer != '') {
23635: var prevIdx = currBalancers.indexOf(prevbalancer);
23636: if (prevIdx != -1) {
23637: currBalancers.splice(prevIdx,1);
23638: }
23639: }
1.150 raeburn 23640: if (balancer == '') {
1.171 raeburn 23641: hideSpares(balnum);
1.150 raeburn 23642: } else {
1.171 raeburn 23643: var currIdx = currBalancers.indexOf(balancer);
23644: if (currIdx == -1) {
23645: currBalancers.push(balancer);
23646: }
1.150 raeburn 23647: var homedoms = new Array('$allishome');
1.171 raeburn 23648: var ishomedom = homedoms[lonhostitem.selectedIndex];
23649: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23650: }
1.171 raeburn 23651: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23652: return;
23653: }
23654:
1.171 raeburn 23655: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23656: var alltargets = new Array('$alltargets');
23657: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23658: var offloadtypes = new Array('primary','default');
23659:
1.171 raeburn 23660: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23661: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23662:
1.151 raeburn 23663: for (var i=0; i<offloadtypes.length; i++) {
23664: var count = 0;
23665: for (var j=0; j<alltargets.length; j++) {
23666: if (alltargets[j] != balancer) {
1.171 raeburn 23667: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23668: item.value = alltargets[j];
23669: item.style.textAlign='left';
23670: item.style.textFace='normal';
23671: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23672: if (currBalancers.indexOf(alltargets[j]) == -1) {
23673: item.disabled = '';
23674: } else {
23675: item.disabled = 'disabled';
23676: item.checked = false;
23677: }
1.151 raeburn 23678: count ++;
23679: }
1.150 raeburn 23680: }
23681: }
1.151 raeburn 23682: for (var k=0; k<insttypes.length; k++) {
23683: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23684: if (ishomedom == 1) {
1.171 raeburn 23685: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23686: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23687: } else {
1.171 raeburn 23688: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23689: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23690: }
23691: } else {
1.171 raeburn 23692: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23693: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23694: }
1.151 raeburn 23695: if ((insttypes[k] != '_LC_external') &&
23696: ((insttypes[k] != '_LC_internetdom') ||
23697: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23698: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23699: item.options.length = 0;
23700: item.options[0] = new Option("","",true,true);
1.210 raeburn 23701: var idx = 0;
1.151 raeburn 23702: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23703: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23704: idx ++;
23705: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23706: }
23707: }
23708: }
23709: }
23710: return;
23711: }
23712:
1.171 raeburn 23713: function hideSpares(balnum) {
1.150 raeburn 23714: var alltargets = new Array('$alltargets');
23715: var insttypes = new Array('$allinsttypes');
23716: var offloadtypes = new Array('primary','default');
23717:
1.171 raeburn 23718: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23719: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23720:
23721: var total = alltargets.length - 1;
23722: for (var i=0; i<offloadtypes; i++) {
23723: for (var j=0; j<total; j++) {
1.171 raeburn 23724: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23725: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23726: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23727: }
1.150 raeburn 23728: }
23729: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23730: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23731: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23732: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23733: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23734: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23735: }
23736: }
23737: return;
23738: }
23739:
1.171 raeburn 23740: function checkOffloads(item,balnum,type) {
1.150 raeburn 23741: var alltargets = new Array('$alltargets');
23742: var offloadtypes = new Array('primary','default');
23743: if (item.checked) {
23744: var total = alltargets.length - 1;
23745: var other;
23746: if (type == offloadtypes[0]) {
1.151 raeburn 23747: other = offloadtypes[1];
1.150 raeburn 23748: } else {
1.151 raeburn 23749: other = offloadtypes[0];
1.150 raeburn 23750: }
23751: for (var i=0; i<total; i++) {
1.171 raeburn 23752: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23753: if (server == item.value) {
1.171 raeburn 23754: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23755: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23756: }
23757: }
23758: }
23759: }
23760: return;
23761: }
23762:
1.171 raeburn 23763: function singleServerToggle(balnum,type) {
23764: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23765: if (offloadtoSelIdx == 0) {
1.171 raeburn 23766: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23767: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23768:
23769: } else {
1.171 raeburn 23770: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23771: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23772: }
23773: return;
23774: }
23775:
1.171 raeburn 23776: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23777: if (type == '_LC_external') {
1.171 raeburn 23778: return;
1.150 raeburn 23779: }
1.171 raeburn 23780: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23781: for (var i=0; i<typesRules.length; i++) {
23782: if (formname.elements[typesRules[i]].checked) {
23783: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23784: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23785: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23786: } else {
1.171 raeburn 23787: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23788: }
23789: }
23790: }
23791: return;
23792: }
23793:
23794: function balancerDeleteChange(balnum) {
23795: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23796: var baltotal = document.getElementById('loadbalancing_total').value;
23797: var addtarget;
23798: var removetarget;
23799: var action = 'delete';
23800: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23801: var lonhost = hostitem.value;
23802: var currIdx = currBalancers.indexOf(lonhost);
23803: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23804: if (currIdx != -1) {
23805: currBalancers.splice(currIdx,1);
23806: }
23807: addtarget = lonhost;
23808: } else {
23809: if (currIdx == -1) {
23810: currBalancers.push(lonhost);
23811: }
23812: removetarget = lonhost;
23813: action = 'undelete';
23814: }
23815: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23816: }
23817: return;
23818: }
23819:
23820: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23821: if (baltotal > 1) {
23822: var offloadtypes = new Array('primary','default');
23823: var alltargets = new Array('$alltargets');
23824: var insttypes = new Array('$allinsttypes');
23825: for (var i=0; i<baltotal; i++) {
23826: if (i != balnum) {
23827: for (var j=0; j<offloadtypes.length; j++) {
23828: var total = alltargets.length - 1;
23829: for (var k=0; k<total; k++) {
23830: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23831: var server = serveritem.value;
23832: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23833: if (server == addtarget) {
23834: serveritem.disabled = '';
23835: }
23836: }
23837: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23838: if (server == removetarget) {
23839: serveritem.disabled = 'disabled';
23840: serveritem.checked = false;
23841: }
23842: }
23843: }
23844: }
23845: for (var j=0; j<insttypes.length; j++) {
23846: if (insttypes[j] != '_LC_external') {
23847: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23848: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23849: var currSel = singleserver.selectedIndex;
23850: var currVal = singleserver.options[currSel].value;
23851: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23852: var numoptions = singleserver.options.length;
23853: var needsnew = 1;
23854: for (var k=0; k<numoptions; k++) {
23855: if (singleserver.options[k] == addtarget) {
23856: needsnew = 0;
23857: break;
23858: }
23859: }
23860: if (needsnew == 1) {
23861: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23862: }
23863: }
23864: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23865: singleserver.options.length = 0;
23866: if ((currVal) && (currVal != removetarget)) {
23867: singleserver.options[0] = new Option("","",false,false);
23868: } else {
23869: singleserver.options[0] = new Option("","",true,true);
23870: }
23871: var idx = 0;
23872: for (var m=0; m<alltargets.length; m++) {
23873: if (currBalancers.indexOf(alltargets[m]) == -1) {
23874: idx ++;
23875: if (currVal == alltargets[m]) {
23876: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23877: } else {
23878: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23879: }
23880: }
23881: }
23882: }
23883: }
23884: }
23885: }
1.150 raeburn 23886: }
23887: }
23888: }
23889: return;
23890: }
23891:
1.152 raeburn 23892: // ]]>
23893: </script>
23894:
23895: END
23896: }
23897:
23898: sub new_spares_js {
23899: my @sparestypes = ('primary','default');
23900: my $types = join("','",@sparestypes);
23901: my $select = &mt('Select');
23902: return <<"END";
23903:
23904: <script type="text/javascript">
23905: // <![CDATA[
23906:
23907: function updateNewSpares(formname,lonhost) {
23908: var types = new Array('$types');
23909: var include = new Array();
23910: var exclude = new Array();
23911: for (var i=0; i<types.length; i++) {
23912: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23913: for (var j=0; j<spareboxes.length; j++) {
23914: if (formname.elements[spareboxes[j]].checked) {
23915: exclude.push(formname.elements[spareboxes[j]].value);
23916: } else {
23917: include.push(formname.elements[spareboxes[j]].value);
23918: }
23919: }
23920: }
23921: for (var i=0; i<types.length; i++) {
23922: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23923: var selIdx = newSpare.selectedIndex;
23924: var currnew = newSpare.options[selIdx].value;
23925: var okSpares = new Array();
23926: for (var j=0; j<newSpare.options.length; j++) {
23927: var possible = newSpare.options[j].value;
23928: if (possible != '') {
23929: if (exclude.indexOf(possible) == -1) {
23930: okSpares.push(possible);
23931: } else {
23932: if (currnew == possible) {
23933: selIdx = 0;
23934: }
23935: }
23936: }
23937: }
23938: for (var k=0; k<include.length; k++) {
23939: if (okSpares.indexOf(include[k]) == -1) {
23940: okSpares.push(include[k]);
23941: }
23942: }
23943: okSpares.sort();
23944: newSpare.options.length = 0;
23945: if (selIdx == 0) {
23946: newSpare.options[0] = new Option("$select","",true,true);
23947: } else {
23948: newSpare.options[0] = new Option("$select","",false,false);
23949: }
23950: for (var m=0; m<okSpares.length; m++) {
23951: var idx = m+1;
23952: var selThis = 0;
23953: if (selIdx != 0) {
23954: if (okSpares[m] == currnew) {
23955: selThis = 1;
23956: }
23957: }
23958: if (selThis == 1) {
23959: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23960: } else {
23961: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23962: }
23963: }
23964: }
23965: return;
23966: }
23967:
23968: function checkNewSpares(lonhost,type) {
23969: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23970: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23971: if (chosen != '') {
1.152 raeburn 23972: var othertype;
23973: var othernewSpare;
23974: if (type == 'primary') {
23975: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23976: }
23977: if (type == 'default') {
23978: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23979: }
23980: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23981: othernewSpare.selectedIndex = 0;
23982: }
23983: }
23984: return;
23985: }
23986:
23987: // ]]>
23988: </script>
23989:
23990: END
23991:
23992: }
23993:
23994: sub common_domprefs_js {
23995: return <<"END";
23996:
23997: <script type="text/javascript">
23998: // <![CDATA[
23999:
1.150 raeburn 24000: function getIndicesByName(formname,item) {
1.152 raeburn 24001: var group = new Array();
1.150 raeburn 24002: for (var i=0;i<formname.elements.length;i++) {
24003: if (formname.elements[i].name == item) {
1.152 raeburn 24004: group.push(formname.elements[i].id);
1.150 raeburn 24005: }
24006: }
1.152 raeburn 24007: return group;
1.150 raeburn 24008: }
24009:
24010: // ]]>
24011: </script>
24012:
24013: END
1.152 raeburn 24014:
1.150 raeburn 24015: }
24016:
1.165 raeburn 24017: sub recaptcha_js {
24018: my %lt = &captcha_phrases();
24019: return <<"END";
24020:
24021: <script type="text/javascript">
24022: // <![CDATA[
24023:
24024: function updateCaptcha(caller,context) {
24025: var privitem;
24026: var pubitem;
24027: var privtext;
24028: var pubtext;
1.269 raeburn 24029: var versionitem;
24030: var versiontext;
1.165 raeburn 24031: if (document.getElementById(context+'_recaptchapub')) {
24032: pubitem = document.getElementById(context+'_recaptchapub');
24033: } else {
24034: return;
24035: }
24036: if (document.getElementById(context+'_recaptchapriv')) {
24037: privitem = document.getElementById(context+'_recaptchapriv');
24038: } else {
24039: return;
24040: }
24041: if (document.getElementById(context+'_recaptchapubtxt')) {
24042: pubtext = document.getElementById(context+'_recaptchapubtxt');
24043: } else {
24044: return;
24045: }
24046: if (document.getElementById(context+'_recaptchaprivtxt')) {
24047: privtext = document.getElementById(context+'_recaptchaprivtxt');
24048: } else {
24049: return;
24050: }
1.269 raeburn 24051: if (document.getElementById(context+'_recaptchaversion')) {
24052: versionitem = document.getElementById(context+'_recaptchaversion');
24053: } else {
24054: return;
24055: }
24056: if (document.getElementById(context+'_recaptchavertxt')) {
24057: versiontext = document.getElementById(context+'_recaptchavertxt');
24058: } else {
24059: return;
24060: }
1.165 raeburn 24061: if (caller.checked) {
24062: if (caller.value == 'recaptcha') {
24063: pubitem.type = 'text';
24064: privitem.type = 'text';
24065: pubitem.size = '40';
24066: privitem.size = '40';
24067: pubtext.innerHTML = "$lt{'pub'}";
24068: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24069: versionitem.type = 'text';
24070: versionitem.size = '3';
1.289 raeburn 24071: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24072: } else {
24073: pubitem.type = 'hidden';
24074: privitem.type = 'hidden';
1.269 raeburn 24075: versionitem.type = 'hidden';
1.165 raeburn 24076: pubtext.innerHTML = '';
24077: privtext.innerHTML = '';
1.269 raeburn 24078: versiontext.innerHTML = '';
1.165 raeburn 24079: }
24080: }
24081: return;
24082: }
24083:
24084: // ]]>
24085: </script>
24086:
24087: END
24088:
24089: }
24090:
1.236 raeburn 24091: sub toggle_display_js {
1.192 raeburn 24092: return <<"END";
24093:
24094: <script type="text/javascript">
24095: // <![CDATA[
24096:
1.236 raeburn 24097: function toggleDisplay(domForm,caller) {
24098: if (document.getElementById(caller)) {
24099: var divitem = document.getElementById(caller);
24100: var optionsElement = domForm.coursecredits;
1.264 raeburn 24101: var checkval = 1;
24102: var dispval = 'block';
1.303 raeburn 24103: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24104: if (caller == 'emailoptions') {
1.372 raeburn 24105: optionsElement = domForm.cancreate_email;
1.236 raeburn 24106: }
1.257 raeburn 24107: if (caller == 'studentsubmission') {
24108: optionsElement = domForm.postsubmit;
24109: }
1.264 raeburn 24110: if (caller == 'cloneinstcode') {
24111: optionsElement = domForm.canclone;
24112: checkval = 'instcode';
24113: }
1.303 raeburn 24114: if (selfcreateRegExp.test(caller)) {
24115: optionsElement = domForm.elements[caller];
24116: checkval = 'other';
24117: dispval = 'inline'
24118: }
1.236 raeburn 24119: if (optionsElement.length) {
1.192 raeburn 24120: var currval;
1.236 raeburn 24121: for (var i=0; i<optionsElement.length; i++) {
24122: if (optionsElement[i].checked) {
24123: currval = optionsElement[i].value;
1.192 raeburn 24124: }
24125: }
1.264 raeburn 24126: if (currval == checkval) {
24127: divitem.style.display = dispval;
1.192 raeburn 24128: } else {
1.236 raeburn 24129: divitem.style.display = 'none';
1.192 raeburn 24130: }
24131: }
24132: }
24133: return;
24134: }
24135:
24136: // ]]>
24137: </script>
24138:
24139: END
24140:
24141: }
24142:
1.165 raeburn 24143: sub captcha_phrases {
24144: return &Apache::lonlocal::texthash (
24145: priv => 'Private key',
24146: pub => 'Public key',
24147: original => 'original (CAPTCHA)',
24148: recaptcha => 'successor (ReCAPTCHA)',
24149: notused => 'unused',
1.289 raeburn 24150: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24151: );
24152: }
24153:
1.205 raeburn 24154: sub devalidate_remote_domconfs {
1.212 raeburn 24155: my ($dom,$cachekeys) = @_;
24156: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24157: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24158: my %thismachine;
24159: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24160: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24161: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24162: 'ipaccess','trust');
1.386 raeburn 24163: my %cache_by_lonhost;
24164: if (exists($cachekeys->{'samllanding'})) {
24165: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24166: my %landing = %{$cachekeys->{'samllanding'}};
24167: my %domservers = &Apache::lonnet::get_servers($dom);
24168: if (keys(%domservers)) {
24169: foreach my $server (keys(%domservers)) {
24170: my @cached;
24171: next if ($thismachine{$server});
24172: if ($landing{$server}) {
24173: push(@cached,&escape('samllanding').':'.&escape($server));
24174: }
24175: if (@cached) {
24176: $cache_by_lonhost{$server} = \@cached;
24177: }
24178: }
24179: }
24180: }
24181: }
1.260 raeburn 24182: if (keys(%servers)) {
1.205 raeburn 24183: foreach my $server (keys(%servers)) {
24184: next if ($thismachine{$server});
1.212 raeburn 24185: my @cached;
24186: foreach my $name (@posscached) {
24187: if ($cachekeys->{$name}) {
1.388 raeburn 24188: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24189: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24190: foreach my $key (keys(%{$cachekeys->{$name}})) {
24191: push(@cached,&escape($name).':'.&escape($key));
24192: }
24193: }
24194: } else {
24195: push(@cached,&escape($name).':'.&escape($dom));
24196: }
1.212 raeburn 24197: }
24198: }
1.386 raeburn 24199: if ((exists($cache_by_lonhost{$server})) &&
24200: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24201: push(@cached,@{$cache_by_lonhost{$server}});
24202: }
1.212 raeburn 24203: if (@cached) {
24204: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24205: }
1.205 raeburn 24206: }
24207: }
24208: return;
24209: }
24210:
1.3 raeburn 24211: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>