Annotation of loncom/interface/domainprefs.pm, revision 1.449
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.449 ! raeburn 4: # $Id: domainprefs.pm,v 1.448 2025/01/12 16:10:23 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',
1.447 raeburn 2012: 'index' => 'Course content index',
1.397 raeburn 2013: 'wishlist' => 'Stored links',
2014: 'annotate' => 'Annotations',
1.394 raeburn 2015: );
1.447 raeburn 2016: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','index','annotate','passwd'];
1.394 raeburn 2017: return ($typeorder,\%types);
2018: }
2019:
1.6 raeburn 2020: sub print_rolecolors {
1.30 raeburn 2021: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 2022: my %choices = &color_font_choices();
2023: my @bgs = ('pgbg','tabbg','sidebg');
2024: my @links = ('link','alink','vlink');
1.445 raeburn 2025: my @images = ();
1.6 raeburn 2026: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 2027: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 2028: my %defaultdesign = %Apache::loncommon::defaultdesign;
2029: my (%is_custom,%designs);
1.200 raeburn 2030: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 2031: if (ref($settings) eq 'HASH') {
2032: if (ref($settings->{$role}) eq 'HASH') {
2033: if ($settings->{$role}->{'font'} ne '') {
2034: $designs{'font'} = $settings->{$role}->{'font'};
2035: $is_custom{'font'} = 1;
2036: }
1.97 tempelho 2037: if ($settings->{$role}->{'fontmenu'} ne '') {
2038: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
2039: $is_custom{'fontmenu'} = 1;
2040: }
1.6 raeburn 2041: foreach my $item (@bgs) {
2042: if ($settings->{$role}->{$item} ne '') {
2043: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
2044: $is_custom{$item} = 1;
2045: }
2046: }
2047: foreach my $item (@links) {
2048: if ($settings->{$role}->{$item} ne '') {
2049: $designs{'links'}{$item} = $settings->{$role}->{$item};
2050: $is_custom{$item} = 1;
2051: }
2052: }
2053: }
2054: } else {
1.97 tempelho 2055: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
2056: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
2057: $is_custom{'fontmenu'} = 1;
2058: }
1.6 raeburn 2059: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
2060: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
2061: $is_custom{'font'} = 1;
2062: }
2063: foreach my $item (@bgs) {
2064: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2065: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2066: $is_custom{$item} = 1;
2067:
2068: }
2069: }
2070: foreach my $item (@links) {
2071: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
2072: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
2073: $is_custom{$item} = 1;
2074: }
2075: }
2076: }
2077: my $itemcount = 1;
1.30 raeburn 2078: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 2079: $datatable .= '</tr></table></td></tr>';
2080: return $datatable;
2081: }
2082:
1.200 raeburn 2083: sub role_defaults {
2084: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 2085: my %defaults;
2086: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 2087: return %defaults;
2088: }
2089: my %defaultdesign = %Apache::loncommon::defaultdesign;
2090: if ($role eq 'login') {
2091: %defaults = (
2092: font => $defaultdesign{$role.'.font'},
2093: );
2094: if (ref($logintext) eq 'ARRAY') {
2095: foreach my $item (@{$logintext}) {
2096: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
2097: }
2098: }
2099: foreach my $item (@{$images}) {
2100: $defaults{'showlogo'}{$item} = 1;
2101: }
2102: } else {
2103: %defaults = (
2104: font => $defaultdesign{$role.'.font'},
2105: fontmenu => $defaultdesign{$role.'.fontmenu'},
2106: );
2107: }
2108: foreach my $item (@{$bgs}) {
2109: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
2110: }
2111: foreach my $item (@{$links}) {
2112: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
2113: }
2114: foreach my $item (@{$images}) {
2115: $defaults{$item} = $defaultdesign{$role.'.'.$item};
2116: }
2117: return %defaults;
2118: }
2119:
1.6 raeburn 2120: sub display_color_options {
1.9 raeburn 2121: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 2122: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 2123: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 2124: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 2125: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 2126: '<td>'.$choices->{'font'}.'</td>';
2127: if (!$is_custom->{'font'}) {
1.329 raeburn 2128: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 2129: } else {
2130: $datatable .= '<td> </td>';
2131: }
1.174 foxr 2132: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2133:
1.8 raeburn 2134: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2135: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 2136: ' value="'.$current_color.'" /> '.
1.329 raeburn 2137: ' </span></td></tr>';
1.107 raeburn 2138: unless ($role eq 'login') {
2139: $datatable .= '<tr'.$css_class.'>'.
2140: '<td>'.$choices->{'fontmenu'}.'</td>';
2141: if (!$is_custom->{'fontmenu'}) {
1.329 raeburn 2142: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2143: } else {
2144: $datatable .= '<td> </td>';
2145: }
1.202 raeburn 2146: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 2147: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2148: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 2149: '<input class="colorchooser" type="text" size="10" name="'
2150: .$role.'_fontmenu"'.
2151: ' value="'.$current_color.'" /> '.
1.329 raeburn 2152: ' </span></td></tr>';
1.97 tempelho 2153: }
1.9 raeburn 2154: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2155: foreach my $img (@{$images}) {
1.18 albertel 2156: $itemcount ++;
1.6 raeburn 2157: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2158: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2159: '<td>'.$choices->{$img};
1.402 raeburn 2160: my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2161: if ($role eq 'login') {
2162: if ($img eq 'login') {
2163: $login_hdr_pick =
1.135 bisitz 2164: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2165: $logincolors =
2166: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 2167: $designs,$defaults);
1.402 raeburn 2168: } else {
2169: if ($img ne 'domlogo') {
2170: $datatable.= &logo_display_options($img,$defaults,$designs);
2171: }
2172: if (ref($designs->{'alttext'}) eq 'HASH') {
2173: $alttext = $designs->{'alttext'}{$img};
2174: }
1.70 raeburn 2175: }
2176: }
2177: $datatable .= '</td>';
1.6 raeburn 2178: if ($designs->{$img} ne '') {
2179: $imgfile = $designs->{$img};
1.18 albertel 2180: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2181: } else {
2182: $imgfile = $defaults->{$img};
2183: }
2184: if ($imgfile) {
1.9 raeburn 2185: my ($showfile,$fullsize);
2186: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2187: my $urldir = $1;
2188: my $filename = $2;
2189: my @info = &Apache::lonnet::stat_file($designs->{$img});
2190: if (@info) {
2191: my $thumbfile = 'tn-'.$filename;
2192: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2193: if (@thumb) {
2194: $showfile = $urldir.'/'.$thumbfile;
2195: } else {
2196: $showfile = $imgfile;
2197: }
2198: } else {
2199: $showfile = '';
2200: }
2201: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2202: $showfile = $imgfile;
1.6 raeburn 2203: my $imgdir = $1;
2204: my $filename = $2;
1.159 raeburn 2205: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2206: $showfile = "/$imgdir/tn-".$filename;
2207: } else {
1.159 raeburn 2208: my $input = $londocroot.$imgfile;
2209: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2210: if (!-e $output) {
1.9 raeburn 2211: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2212: my ($fullwidth,$fullheight) = &check_dimensions($input);
2213: if ($fullwidth ne '' && $fullheight ne '') {
2214: if ($fullwidth > $width && $fullheight > $height) {
2215: my $size = $width.'x'.$height;
1.316 raeburn 2216: my @args = ('convert','-sample',$size,$input,$output);
2217: system({$args[0]} @args);
1.159 raeburn 2218: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2219: }
2220: }
1.6 raeburn 2221: }
2222: }
1.16 raeburn 2223: }
1.6 raeburn 2224: if ($showfile) {
1.40 raeburn 2225: if ($showfile =~ m{^/(adm|res)/}) {
2226: if ($showfile =~ m{^/res/}) {
2227: my $local_showfile =
2228: &Apache::lonnet::filelocation('',$showfile);
2229: &Apache::lonnet::repcopy($local_showfile);
2230: }
2231: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2232: }
2233: if ($imgfile) {
2234: if ($imgfile =~ m{^/(adm|res)/}) {
2235: if ($imgfile =~ m{^/res/}) {
2236: my $local_imgfile =
2237: &Apache::lonnet::filelocation('',$imgfile);
2238: &Apache::lonnet::repcopy($local_imgfile);
2239: }
2240: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2241: } else {
2242: $fullsize = $imgfile;
2243: }
2244: }
1.41 raeburn 2245: $datatable .= '<td>';
2246: if ($img eq 'login') {
1.135 bisitz 2247: $datatable .= $login_hdr_pick;
2248: }
1.41 raeburn 2249: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2250: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2251: } else {
1.201 raeburn 2252: $datatable .= '<td> </td><td class="LC_left_item">'.
2253: &mt('Upload:').'<br />';
1.6 raeburn 2254: }
2255: } else {
1.201 raeburn 2256: $datatable .= '<td> </td><td class="LC_left_item">'.
2257: &mt('Upload:').'<br />';
1.6 raeburn 2258: }
1.9 raeburn 2259: if ($switchserver) {
2260: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2261: } else {
1.135 bisitz 2262: if ($img ne 'login') { # suppress file selection for Log-in header
2263: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2264: }
1.9 raeburn 2265: }
1.402 raeburn 2266: if (($role eq 'login') && ($img ne 'login')) {
2267: $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2268: '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2269: '</label></span>';
2270: }
1.9 raeburn 2271: $datatable .= '</td></tr>';
1.6 raeburn 2272: }
2273: $itemcount ++;
2274: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2275: $datatable .= '<tr'.$css_class.'>'.
2276: '<td>'.$choices->{'bgs'}.'</td>';
2277: my $bgs_def;
2278: foreach my $item (@{$bgs}) {
2279: if (!$is_custom->{$item}) {
1.329 raeburn 2280: $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 2281: }
2282: }
2283: if ($bgs_def) {
1.8 raeburn 2284: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2285: } else {
2286: $datatable .= '<td> </td>';
2287: }
2288: $datatable .= '<td class="LC_right_item">'.
2289: '<table border="0"><tr>';
1.174 foxr 2290:
1.6 raeburn 2291: foreach my $item (@{$bgs}) {
1.306 raeburn 2292: $datatable .= '<td style="text-align: center">'.$choices->{$item};
1.174 foxr 2293: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2294: if ($designs->{'bgs'}{$item}) {
1.174 foxr 2295: $datatable .= ' ';
1.6 raeburn 2296: }
1.174 foxr 2297: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2298: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2299: }
2300: $datatable .= '</tr></table></td></tr>';
2301: $itemcount ++;
2302: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2303: $datatable .= '<tr'.$css_class.'>'.
2304: '<td>'.$choices->{'links'}.'</td>';
2305: my $links_def;
2306: foreach my $item (@{$links}) {
2307: if (!$is_custom->{$item}) {
1.329 raeburn 2308: $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 2309: }
2310: }
2311: if ($links_def) {
1.8 raeburn 2312: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2313: } else {
2314: $datatable .= '<td> </td>';
2315: }
2316: $datatable .= '<td class="LC_right_item">'.
2317: '<table border="0"><tr>';
2318: foreach my $item (@{$links}) {
1.234 raeburn 2319: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.306 raeburn 2320: $datatable .= '<td style="text-align: center">'.$choices->{$item}."\n";
1.6 raeburn 2321: if ($designs->{'links'}{$item}) {
1.174 foxr 2322: $datatable.=' ';
1.6 raeburn 2323: }
1.174 foxr 2324: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2325: '" /></td>';
2326: }
1.30 raeburn 2327: $$rowtotal += $itemcount;
1.3 raeburn 2328: return $datatable;
2329: }
2330:
1.70 raeburn 2331: sub logo_display_options {
2332: my ($img,$defaults,$designs) = @_;
2333: my $checkedon;
2334: if (ref($defaults) eq 'HASH') {
2335: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2336: if ($defaults->{'showlogo'}{$img}) {
2337: $checkedon = 'checked="checked" ';
2338: }
2339: }
2340: }
2341: if (ref($designs) eq 'HASH') {
2342: if (ref($designs->{'showlogo'}) eq 'HASH') {
2343: if (defined($designs->{'showlogo'}{$img})) {
2344: if ($designs->{'showlogo'}{$img} == 0) {
2345: $checkedon = '';
2346: } elsif ($designs->{'showlogo'}{$img} == 1) {
2347: $checkedon = 'checked="checked" ';
2348: }
2349: }
2350: }
2351: }
2352: return '<br /><label> <input type="checkbox" name="'.
2353: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2354: &mt('show').'</label>'."\n";
2355: }
2356:
1.41 raeburn 2357: sub login_header_options {
1.135 bisitz 2358: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2359: my $output = '';
1.41 raeburn 2360: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2361: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2362: if (!$is_custom->{'textcol'}) {
2363: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2364: ' ';
2365: }
2366: if (!$is_custom->{'bgcol'}) {
2367: $output .= $choices->{'bgcol'}.': '.
2368: '<span id="css_'.$role.'_font" style="background-color: '.
2369: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2370: }
2371: $output .= '<br />';
2372: }
2373: $output .='<br />';
2374: return $output;
2375: }
2376:
2377: sub login_text_colors {
1.201 raeburn 2378: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2379: my $color_menu = '<table border="0"><tr>';
2380: foreach my $item (@{$logintext}) {
1.306 raeburn 2381: $color_menu .= '<td style="text-align: center">'.$choices->{$item};
1.201 raeburn 2382: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2383: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2384: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2385: }
2386: $color_menu .= '</tr></table><br />';
2387: return $color_menu;
2388: }
2389:
2390: sub image_changes {
2391: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2392: my $output;
1.135 bisitz 2393: if ($img eq 'login') {
1.331 raeburn 2394: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2395: } elsif (!$is_custom) {
1.70 raeburn 2396: if ($img ne 'domlogo') {
1.331 raeburn 2397: $output = &mt('Default image:').'<br />';
1.41 raeburn 2398: } else {
1.331 raeburn 2399: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2400: }
2401: }
1.331 raeburn 2402: if ($img ne 'login') {
1.135 bisitz 2403: if ($img_import) {
2404: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2405: }
2406: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2407: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2408: if ($is_custom) {
2409: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2410: '<input type="checkbox" name="'.
2411: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2412: '</label> '.&mt('Replace:').'</span><br />';
2413: } else {
1.306 raeburn 2414: $output .= '<td class="LC_middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2415: }
1.41 raeburn 2416: }
2417: return $output;
2418: }
2419:
1.3 raeburn 2420: sub print_quotas {
1.86 raeburn 2421: my ($dom,$settings,$rowtotal,$action) = @_;
2422: my $context;
2423: if ($action eq 'quotas') {
2424: $context = 'tools';
2425: } else {
2426: $context = $action;
2427: }
1.429 raeburn 2428: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2429: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2430: my $typecount = 0;
1.101 raeburn 2431: my ($css_class,%titles);
1.86 raeburn 2432: if ($context eq 'requestcourses') {
1.325 raeburn 2433: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 2434: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2435: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2436: %titles = &courserequest_titles();
1.163 raeburn 2437: } elsif ($context eq 'requestauthor') {
2438: @usertools = ('author');
2439: @options = ('norequest','approval','automatic');
1.210 raeburn 2440: %titles = &authorrequest_titles();
1.86 raeburn 2441: } else {
1.430 raeburn 2442: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2443: %titles = &tool_titles();
1.86 raeburn 2444: }
1.26 raeburn 2445: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2446: foreach my $type (@{$types}) {
1.429 raeburn 2447: my $currdefquota;
1.163 raeburn 2448: unless (($context eq 'requestcourses') ||
2449: ($context eq 'requestauthor')) {
1.86 raeburn 2450: if (ref($settings) eq 'HASH') {
2451: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 2452: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2453: } else {
2454: $currdefquota = $settings->{$type};
2455: }
1.78 raeburn 2456: }
1.72 raeburn 2457: }
1.3 raeburn 2458: if (defined($usertypes->{$type})) {
2459: $typecount ++;
2460: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2461: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2462: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2463: '<td class="LC_left_item">';
1.101 raeburn 2464: if ($context eq 'requestcourses') {
2465: $datatable .= '<table><tr>';
2466: }
2467: my %cell;
1.72 raeburn 2468: foreach my $item (@usertools) {
1.101 raeburn 2469: if ($context eq 'requestcourses') {
2470: my ($curroption,$currlimit);
2471: if (ref($settings) eq 'HASH') {
2472: if (ref($settings->{$item}) eq 'HASH') {
2473: $curroption = $settings->{$item}->{$type};
2474: if ($curroption =~ /^autolimit=(\d*)$/) {
2475: $currlimit = $1;
2476: }
2477: }
2478: }
2479: if (!$curroption) {
2480: $curroption = 'norequest';
2481: }
2482: $datatable .= '<th>'.$titles{$item}.'</th>';
2483: foreach my $option (@options) {
2484: my $val = $option;
2485: if ($option eq 'norequest') {
2486: $val = 0;
2487: }
2488: if ($option eq 'validate') {
2489: my $canvalidate = 0;
2490: if (ref($validations{$item}) eq 'HASH') {
2491: if ($validations{$item}{$type}) {
2492: $canvalidate = 1;
2493: }
2494: }
2495: next if (!$canvalidate);
2496: }
2497: my $checked = '';
2498: if ($option eq $curroption) {
2499: $checked = ' checked="checked"';
2500: } elsif ($option eq 'autolimit') {
2501: if ($curroption =~ /^autolimit/) {
2502: $checked = ' checked="checked"';
2503: }
2504: }
2505: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2506: '<input type="radio" name="crsreq_'.$item.
2507: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2508: $titles{$option}.'</label>';
1.101 raeburn 2509: if ($option eq 'autolimit') {
1.127 raeburn 2510: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2511: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2512: 'value="'.$currlimit.'" />';
1.101 raeburn 2513: }
1.127 raeburn 2514: $cell{$item} .= '</span> ';
1.103 raeburn 2515: if ($option eq 'autolimit') {
1.127 raeburn 2516: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2517: }
1.101 raeburn 2518: }
1.163 raeburn 2519: } elsif ($context eq 'requestauthor') {
2520: my $curroption;
2521: if (ref($settings) eq 'HASH') {
2522: $curroption = $settings->{$type};
2523: }
2524: if (!$curroption) {
2525: $curroption = 'norequest';
2526: }
2527: foreach my $option (@options) {
2528: my $val = $option;
2529: if ($option eq 'norequest') {
2530: $val = 0;
2531: }
2532: my $checked = '';
2533: if ($option eq $curroption) {
2534: $checked = ' checked="checked"';
2535: }
2536: $datatable .= '<span class="LC_nobreak"><label>'.
2537: '<input type="radio" name="authorreq_'.$type.
2538: '" value="'.$val.'"'.$checked.' />'.
2539: $titles{$option}.'</label></span> ';
2540: }
1.101 raeburn 2541: } else {
2542: my $checked = 'checked="checked" ';
1.413 raeburn 2543: if ($item eq 'timezone') {
2544: $checked = '';
2545: }
1.101 raeburn 2546: if (ref($settings) eq 'HASH') {
2547: if (ref($settings->{$item}) eq 'HASH') {
1.413 raeburn 2548: if (!$settings->{$item}->{$type}) {
1.101 raeburn 2549: $checked = '';
2550: } elsif ($settings->{$item}->{$type} == 1) {
2551: $checked = 'checked="checked" ';
2552: }
1.78 raeburn 2553: }
1.72 raeburn 2554: }
1.101 raeburn 2555: $datatable .= '<span class="LC_nobreak"><label>'.
2556: '<input type="checkbox" name="'.$context.'_'.$item.
2557: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2558: '</label></span> ';
1.72 raeburn 2559: }
1.101 raeburn 2560: }
2561: if ($context eq 'requestcourses') {
2562: $datatable .= '</tr><tr>';
2563: foreach my $item (@usertools) {
1.106 raeburn 2564: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2565: }
2566: $datatable .= '</tr></table>';
1.72 raeburn 2567: }
1.86 raeburn 2568: $datatable .= '</td>';
1.163 raeburn 2569: unless (($context eq 'requestcourses') ||
2570: ($context eq 'requestauthor')) {
1.86 raeburn 2571: $datatable .=
1.197 raeburn 2572: '<td class="LC_right_item">'.
1.429 raeburn 2573: '<span class="LC_nobreak">'.
1.3 raeburn 2574: '<input type="text" name="quota_'.$type.
1.72 raeburn 2575: '" value="'.$currdefquota.
1.197 raeburn 2576: '" size="5" /></span></td>';
1.86 raeburn 2577: }
2578: $datatable .= '</tr>';
1.3 raeburn 2579: }
2580: }
2581: }
1.163 raeburn 2582: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2583: $defaultquota = '20';
2584: if (ref($settings) eq 'HASH') {
2585: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2586: $defaultquota = $settings->{'defaultquota'}->{'default'};
2587: } elsif (defined($settings->{'default'})) {
2588: $defaultquota = $settings->{'default'};
2589: }
1.3 raeburn 2590: }
2591: }
2592: $typecount ++;
2593: $css_class = $typecount%2?' class="LC_odd_row"':'';
2594: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2595: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2596: '<td class="LC_left_item">';
1.101 raeburn 2597: if ($context eq 'requestcourses') {
2598: $datatable .= '<table><tr>';
2599: }
2600: my %defcell;
1.72 raeburn 2601: foreach my $item (@usertools) {
1.101 raeburn 2602: if ($context eq 'requestcourses') {
2603: my ($curroption,$currlimit);
2604: if (ref($settings) eq 'HASH') {
2605: if (ref($settings->{$item}) eq 'HASH') {
2606: $curroption = $settings->{$item}->{'default'};
2607: if ($curroption =~ /^autolimit=(\d*)$/) {
2608: $currlimit = $1;
2609: }
2610: }
2611: }
2612: if (!$curroption) {
2613: $curroption = 'norequest';
2614: }
2615: $datatable .= '<th>'.$titles{$item}.'</th>';
2616: foreach my $option (@options) {
2617: my $val = $option;
2618: if ($option eq 'norequest') {
2619: $val = 0;
2620: }
2621: if ($option eq 'validate') {
2622: my $canvalidate = 0;
2623: if (ref($validations{$item}) eq 'HASH') {
2624: if ($validations{$item}{'default'}) {
2625: $canvalidate = 1;
2626: }
2627: }
2628: next if (!$canvalidate);
2629: }
2630: my $checked = '';
2631: if ($option eq $curroption) {
2632: $checked = ' checked="checked"';
2633: } elsif ($option eq 'autolimit') {
2634: if ($curroption =~ /^autolimit/) {
2635: $checked = ' checked="checked"';
2636: }
2637: }
2638: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2639: '<input type="radio" name="crsreq_'.$item.
2640: '_default" value="'.$val.'"'.$checked.' />'.
2641: $titles{$option}.'</label>';
2642: if ($option eq 'autolimit') {
1.127 raeburn 2643: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2644: $item.'_limit_default" size="1" '.
2645: 'value="'.$currlimit.'" />';
2646: }
1.127 raeburn 2647: $defcell{$item} .= '</span> ';
1.104 raeburn 2648: if ($option eq 'autolimit') {
1.127 raeburn 2649: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2650: }
1.101 raeburn 2651: }
1.163 raeburn 2652: } elsif ($context eq 'requestauthor') {
2653: my $curroption;
2654: if (ref($settings) eq 'HASH') {
1.172 raeburn 2655: $curroption = $settings->{'default'};
1.163 raeburn 2656: }
2657: if (!$curroption) {
2658: $curroption = 'norequest';
2659: }
2660: foreach my $option (@options) {
2661: my $val = $option;
2662: if ($option eq 'norequest') {
2663: $val = 0;
2664: }
2665: my $checked = '';
2666: if ($option eq $curroption) {
2667: $checked = ' checked="checked"';
2668: }
2669: $datatable .= '<span class="LC_nobreak"><label>'.
2670: '<input type="radio" name="authorreq_default"'.
2671: ' value="'.$val.'"'.$checked.' />'.
2672: $titles{$option}.'</label></span> ';
2673: }
1.101 raeburn 2674: } else {
2675: my $checked = 'checked="checked" ';
2676: if (ref($settings) eq 'HASH') {
2677: if (ref($settings->{$item}) eq 'HASH') {
2678: if ($settings->{$item}->{'default'} == 0) {
2679: $checked = '';
2680: } elsif ($settings->{$item}->{'default'} == 1) {
2681: $checked = 'checked="checked" ';
2682: }
1.78 raeburn 2683: }
1.72 raeburn 2684: }
1.101 raeburn 2685: $datatable .= '<span class="LC_nobreak"><label>'.
2686: '<input type="checkbox" name="'.$context.'_'.$item.
2687: '" value="default" '.$checked.'/>'.$titles{$item}.
2688: '</label></span> ';
2689: }
2690: }
2691: if ($context eq 'requestcourses') {
2692: $datatable .= '</tr><tr>';
2693: foreach my $item (@usertools) {
1.106 raeburn 2694: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2695: }
1.101 raeburn 2696: $datatable .= '</tr></table>';
1.72 raeburn 2697: }
1.86 raeburn 2698: $datatable .= '</td>';
1.163 raeburn 2699: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 2700: $datatable .= '<td class="LC_right_item">'.
1.429 raeburn 2701: '<span class="LC_nobreak">'.
1.86 raeburn 2702: '<input type="text" name="defaultquota" value="'.
1.429 raeburn 2703: $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2704: }
2705: $datatable .= '</tr>';
1.72 raeburn 2706: $typecount ++;
2707: $css_class = $typecount%2?' class="LC_odd_row"':'';
2708: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 2709: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2710: if ($context eq 'requestcourses') {
1.109 raeburn 2711: $datatable .= &mt('(overrides affiliation, if set)').
2712: '</td>'.
2713: '<td class="LC_left_item">'.
2714: '<table><tr>';
1.101 raeburn 2715: } else {
1.109 raeburn 2716: $datatable .= &mt('(overrides affiliation, if checked)').
2717: '</td>'.
2718: '<td class="LC_left_item" colspan="2">'.
2719: '<br />';
1.101 raeburn 2720: }
2721: my %advcell;
1.72 raeburn 2722: foreach my $item (@usertools) {
1.101 raeburn 2723: if ($context eq 'requestcourses') {
2724: my ($curroption,$currlimit);
2725: if (ref($settings) eq 'HASH') {
2726: if (ref($settings->{$item}) eq 'HASH') {
2727: $curroption = $settings->{$item}->{'_LC_adv'};
2728: if ($curroption =~ /^autolimit=(\d*)$/) {
2729: $currlimit = $1;
2730: }
2731: }
2732: }
2733: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2734: my $checked = '';
2735: if ($curroption eq '') {
2736: $checked = ' checked="checked"';
2737: }
2738: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2739: '<input type="radio" name="crsreq_'.$item.
2740: '__LC_adv" value=""'.$checked.' />'.
2741: &mt('No override set').'</label></span> ';
1.101 raeburn 2742: foreach my $option (@options) {
2743: my $val = $option;
2744: if ($option eq 'norequest') {
2745: $val = 0;
2746: }
2747: if ($option eq 'validate') {
2748: my $canvalidate = 0;
2749: if (ref($validations{$item}) eq 'HASH') {
2750: if ($validations{$item}{'_LC_adv'}) {
2751: $canvalidate = 1;
2752: }
2753: }
2754: next if (!$canvalidate);
2755: }
2756: my $checked = '';
1.104 raeburn 2757: if ($val eq $curroption) {
1.101 raeburn 2758: $checked = ' checked="checked"';
2759: } elsif ($option eq 'autolimit') {
2760: if ($curroption =~ /^autolimit/) {
2761: $checked = ' checked="checked"';
2762: }
2763: }
2764: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2765: '<input type="radio" name="crsreq_'.$item.
2766: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2767: $titles{$option}.'</label>';
2768: if ($option eq 'autolimit') {
1.127 raeburn 2769: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2770: $item.'_limit__LC_adv" size="1" '.
2771: 'value="'.$currlimit.'" />';
2772: }
1.127 raeburn 2773: $advcell{$item} .= '</span> ';
1.104 raeburn 2774: if ($option eq 'autolimit') {
1.127 raeburn 2775: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2776: }
1.101 raeburn 2777: }
1.163 raeburn 2778: } elsif ($context eq 'requestauthor') {
2779: my $curroption;
2780: if (ref($settings) eq 'HASH') {
2781: $curroption = $settings->{'_LC_adv'};
2782: }
2783: my $checked = '';
2784: if ($curroption eq '') {
2785: $checked = ' checked="checked"';
2786: }
2787: $datatable .= '<span class="LC_nobreak"><label>'.
2788: '<input type="radio" name="authorreq__LC_adv"'.
2789: ' value=""'.$checked.' />'.
2790: &mt('No override set').'</label></span> ';
2791: foreach my $option (@options) {
2792: my $val = $option;
2793: if ($option eq 'norequest') {
2794: $val = 0;
2795: }
2796: my $checked = '';
2797: if ($val eq $curroption) {
2798: $checked = ' checked="checked"';
2799: }
2800: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 2801: '<input type="radio" name="authorreq__LC_adv"'.
2802: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 2803: $titles{$option}.'</label></span> ';
2804: }
1.101 raeburn 2805: } else {
2806: my $checked = 'checked="checked" ';
2807: if (ref($settings) eq 'HASH') {
2808: if (ref($settings->{$item}) eq 'HASH') {
2809: if ($settings->{$item}->{'_LC_adv'} == 0) {
2810: $checked = '';
2811: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2812: $checked = 'checked="checked" ';
2813: }
1.79 raeburn 2814: }
1.72 raeburn 2815: }
1.101 raeburn 2816: $datatable .= '<span class="LC_nobreak"><label>'.
2817: '<input type="checkbox" name="'.$context.'_'.$item.
2818: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2819: '</label></span> ';
2820: }
2821: }
2822: if ($context eq 'requestcourses') {
2823: $datatable .= '</tr><tr>';
2824: foreach my $item (@usertools) {
1.106 raeburn 2825: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2826: }
1.101 raeburn 2827: $datatable .= '</tr></table>';
1.72 raeburn 2828: }
1.98 raeburn 2829: $datatable .= '</td></tr>';
1.30 raeburn 2830: $$rowtotal += $typecount;
1.3 raeburn 2831: return $datatable;
2832: }
2833:
1.163 raeburn 2834: sub print_requestmail {
1.305 raeburn 2835: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.208 raeburn 2836: my ($now,$datatable,%currapp);
1.102 raeburn 2837: $now = time;
2838: if (ref($settings) eq 'HASH') {
2839: if (ref($settings->{'notify'}) eq 'HASH') {
2840: if ($settings->{'notify'}{'approval'} ne '') {
1.224 raeburn 2841: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2842: }
2843: }
2844: }
1.191 raeburn 2845: my $numinrow = 2;
1.224 raeburn 2846: my $css_class;
1.305 raeburn 2847: if ($$rowtotal%2) {
2848: $css_class = 'LC_odd_row';
2849: }
2850: if ($customcss) {
2851: $css_class .= " $customcss";
2852: }
2853: $css_class =~ s/^\s+//;
2854: if ($css_class) {
2855: $css_class = ' class="'.$css_class.'"';
2856: }
2857: if ($rowstyle) {
2858: $css_class .= ' style="'.$rowstyle.'"';
2859: }
1.163 raeburn 2860: my $text;
2861: if ($action eq 'requestcourses') {
2862: $text = &mt('Receive notification of course requests requiring approval');
1.224 raeburn 2863: } elsif ($action eq 'requestauthor') {
2864: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.163 raeburn 2865: } else {
1.224 raeburn 2866: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.163 raeburn 2867: }
1.224 raeburn 2868: $datatable = '<tr'.$css_class.'>'.
1.163 raeburn 2869: ' <td>'.$text.'</td>'.
1.102 raeburn 2870: ' <td class="LC_left_item">';
1.191 raeburn 2871: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.224 raeburn 2872: $action.'notifyapproval',%currapp);
1.191 raeburn 2873: if ($numdc > 0) {
2874: $datatable .= $table;
1.102 raeburn 2875: } else {
2876: $datatable .= &mt('There are no active Domain Coordinators');
2877: }
2878: $datatable .='</td></tr>';
2879: return $datatable;
2880: }
2881:
1.216 raeburn 2882: sub print_studentcode {
2883: my ($settings,$rowtotal) = @_;
2884: my $rownum = 0;
1.218 raeburn 2885: my ($output,%current);
1.325 raeburn 2886: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.248 raeburn 2887: if (ref($settings) eq 'HASH') {
2888: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2889: foreach my $type (@crstypes) {
2890: $current{$type} = $settings->{'uniquecode'}{$type};
2891: }
1.218 raeburn 2892: }
2893: }
2894: $output .= '<tr>'.
2895: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2896: '<td class="LC_left_item">';
2897: foreach my $type (@crstypes) {
2898: my $check = ' ';
2899: if ($current{$type}) {
2900: $check = ' checked="checked" ';
2901: }
2902: $output .= '<span class="LC_nobreak"><label>'.
2903: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2904: &mt($type).'</label></span>'.(' 'x2).' ';
2905: }
2906: $output .= '</td></tr>';
2907: $$rowtotal ++;
2908: return $output;
1.216 raeburn 2909: }
2910:
2911: sub print_textbookcourses {
1.242 raeburn 2912: my ($dom,$type,$settings,$rowtotal) = @_;
1.216 raeburn 2913: my $rownum = 0;
2914: my $css_class;
2915: my $itemcount = 1;
2916: my $maxnum = 0;
2917: my $bookshash;
2918: if (ref($settings) eq 'HASH') {
1.242 raeburn 2919: $bookshash = $settings->{$type};
1.216 raeburn 2920: }
2921: my %ordered;
2922: if (ref($bookshash) eq 'HASH') {
2923: foreach my $item (keys(%{$bookshash})) {
2924: if (ref($bookshash->{$item}) eq 'HASH') {
2925: my $num = $bookshash->{$item}{'order'};
2926: $ordered{$num} = $item;
2927: }
2928: }
2929: }
2930: my $confname = $dom.'-domainconfig';
2931: my $switchserver = &check_switchserver($dom,$confname);
1.242 raeburn 2932: my $maxnum = scalar(keys(%ordered));
2933: my $datatable;
1.216 raeburn 2934: if (keys(%ordered)) {
2935: my @items = sort { $a <=> $b } keys(%ordered);
2936: for (my $i=0; $i<@items; $i++) {
2937: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2938: my $key = $ordered{$items[$i]};
2939: my %coursehash=&Apache::lonnet::coursedescription($key);
2940: my $coursetitle = $coursehash{'description'};
1.243 raeburn 2941: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.216 raeburn 2942: if (ref($bookshash->{$key}) eq 'HASH') {
2943: $subject = $bookshash->{$key}->{'subject'};
2944: $title = $bookshash->{$key}->{'title'};
1.242 raeburn 2945: if ($type eq 'textbooks') {
1.243 raeburn 2946: $publisher = $bookshash->{$key}->{'publisher'};
1.242 raeburn 2947: $author = $bookshash->{$key}->{'author'};
2948: $image = $bookshash->{$key}->{'image'};
2949: if ($image ne '') {
2950: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2951: my $imagethumb = "$path/tn-".$imagefile;
2952: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2953: }
1.216 raeburn 2954: }
2955: }
1.242 raeburn 2956: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.216 raeburn 2957: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.242 raeburn 2958: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.216 raeburn 2959: for (my $k=0; $k<=$maxnum; $k++) {
2960: my $vpos = $k+1;
2961: my $selstr;
2962: if ($k == $i) {
2963: $selstr = ' selected="selected" ';
2964: }
2965: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2966: }
2967: $datatable .= '</select>'.(' 'x2).
1.242 raeburn 2968: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.216 raeburn 2969: &mt('Delete?').'</label></span></td>'.
2970: '<td colspan="2">'.
1.242 raeburn 2971: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.216 raeburn 2972: (' 'x2).
1.242 raeburn 2973: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2974: if ($type eq 'textbooks') {
2975: $datatable .= (' 'x2).
1.243 raeburn 2976: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2977: (' 'x2).
1.242 raeburn 2978: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2979: (' 'x2).
2980: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2981: if ($image) {
1.267 raeburn 2982: $datatable .= $imgsrc.
1.242 raeburn 2983: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2984: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2985: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2986: }
2987: if ($switchserver) {
2988: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2989: } else {
2990: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2991: }
1.216 raeburn 2992: }
1.242 raeburn 2993: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.216 raeburn 2994: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2995: $coursetitle.'</span></td></tr>'."\n";
2996: $itemcount ++;
2997: }
2998: }
2999: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.242 raeburn 3000: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.216 raeburn 3001: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.242 raeburn 3002: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
3003: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.216 raeburn 3004: for (my $k=0; $k<$maxnum+1; $k++) {
3005: my $vpos = $k+1;
3006: my $selstr;
3007: if ($k == $maxnum) {
3008: $selstr = ' selected="selected" ';
3009: }
3010: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
3011: }
3012: $datatable .= '</select> '."\n".
1.334 raeburn 3013: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.216 raeburn 3014: '<td colspan="2">'.
1.242 raeburn 3015: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.216 raeburn 3016: (' 'x2).
1.242 raeburn 3017: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
3018: (' 'x2);
3019: if ($type eq 'textbooks') {
1.243 raeburn 3020: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
3021: (' 'x2).
3022: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.242 raeburn 3023: (' 'x2).
3024: '<span class="LC_nobreak">'.&mt('Image:').' ';
3025: if ($switchserver) {
3026: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3027: } else {
3028: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
3029: }
1.334 raeburn 3030: $datatable .= '</span>'."\n";
1.216 raeburn 3031: }
1.334 raeburn 3032: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.242 raeburn 3033: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
3034: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.216 raeburn 3035: &Apache::loncommon::selectcourse_link
1.334 raeburn 3036: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.216 raeburn 3037: '</span></td>'."\n".
3038: '</tr>'."\n";
3039: $itemcount ++;
3040: return $datatable;
3041: }
3042:
1.217 raeburn 3043: sub textbookcourses_javascript {
1.242 raeburn 3044: my ($settings) = @_;
3045: return unless(ref($settings) eq 'HASH');
3046: my (%ordered,%total,%jstext);
3047: foreach my $type ('textbooks','templates') {
3048: $total{$type} = 0;
3049: if (ref($settings->{$type}) eq 'HASH') {
3050: foreach my $item (keys(%{$settings->{$type}})) {
3051: if (ref($settings->{$type}->{$item}) eq 'HASH') {
3052: my $num = $settings->{$type}->{$item}{'order'};
3053: $ordered{$type}{$num} = $item;
3054: }
3055: }
3056: $total{$type} = scalar(keys(%{$settings->{$type}}));
3057: }
3058: my @jsarray = ();
3059: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
3060: push(@jsarray,$ordered{$type}{$item});
3061: }
3062: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.217 raeburn 3063: }
3064: return <<"ENDSCRIPT";
3065: <script type="text/javascript">
3066: // <![CDATA[
1.242 raeburn 3067: function reorderBooks(form,item,caller) {
1.217 raeburn 3068: var changedVal;
1.242 raeburn 3069: $jstext{'textbooks'};
3070: $jstext{'templates'};
3071: var newpos;
3072: var maxh;
3073: if (caller == 'textbooks') {
3074: newpos = 'textbooks_addbook_pos';
3075: maxh = 1 + $total{'textbooks'};
3076: } else {
3077: newpos = 'templates_addbook_pos';
3078: maxh = 1 + $total{'templates'};
3079: }
1.217 raeburn 3080: var current = new Array;
3081: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3082: if (item == newpos) {
3083: changedVal = newitemVal;
3084: } else {
3085: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3086: current[newitemVal] = newpos;
3087: }
1.242 raeburn 3088: if (caller == 'textbooks') {
3089: for (var i=0; i<textbooks.length; i++) {
3090: var elementName = 'textbooks_'+textbooks[i];
3091: if (elementName != item) {
3092: if (form.elements[elementName]) {
3093: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3094: current[currVal] = elementName;
3095: }
3096: }
3097: }
3098: }
3099: if (caller == 'templates') {
3100: for (var i=0; i<templates.length; i++) {
3101: var elementName = 'templates_'+templates[i];
3102: if (elementName != item) {
3103: if (form.elements[elementName]) {
3104: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3105: current[currVal] = elementName;
3106: }
1.217 raeburn 3107: }
3108: }
3109: }
3110: var oldVal;
3111: for (var j=0; j<maxh; j++) {
3112: if (current[j] == undefined) {
3113: oldVal = j;
3114: }
3115: }
3116: if (oldVal < changedVal) {
3117: for (var k=oldVal+1; k<=changedVal ; k++) {
3118: var elementName = current[k];
3119: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3120: }
3121: } else {
3122: for (var k=changedVal; k<oldVal; k++) {
3123: var elementName = current[k];
3124: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3125: }
3126: }
3127: return;
3128: }
3129:
3130: // ]]>
3131: </script>
3132:
3133: ENDSCRIPT
3134: }
3135:
1.267 raeburn 3136: sub ltitools_javascript {
3137: my ($settings) = @_;
1.319 raeburn 3138: my $togglejs = <itools_toggle_js();
3139: unless (ref($settings) eq 'HASH') {
3140: return $togglejs;
3141: }
1.267 raeburn 3142: my (%ordered,$total,%jstext);
3143: $total = 0;
3144: foreach my $item (keys(%{$settings})) {
3145: if (ref($settings->{$item}) eq 'HASH') {
3146: my $num = $settings->{$item}{'order'};
3147: $ordered{$num} = $item;
3148: }
3149: }
3150: $total = scalar(keys(%{$settings}));
3151: my @jsarray = ();
3152: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3153: push(@jsarray,$ordered{$item});
3154: }
3155: my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3156: return <<"ENDSCRIPT";
3157: <script type="text/javascript">
3158: // <![CDATA[
1.319 raeburn 3159: function reorderLTITools(form,item) {
1.267 raeburn 3160: var changedVal;
3161: $jstext
3162: var newpos = 'ltitools_add_pos';
3163: var maxh = 1 + $total;
3164: var current = new Array;
3165: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3166: if (item == newpos) {
3167: changedVal = newitemVal;
3168: } else {
3169: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3170: current[newitemVal] = newpos;
3171: }
3172: for (var i=0; i<ltitools.length; i++) {
3173: var elementName = 'ltitools_'+ltitools[i];
3174: if (elementName != item) {
3175: if (form.elements[elementName]) {
3176: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3177: current[currVal] = elementName;
3178: }
3179: }
3180: }
3181: var oldVal;
3182: for (var j=0; j<maxh; j++) {
3183: if (current[j] == undefined) {
3184: oldVal = j;
3185: }
3186: }
3187: if (oldVal < changedVal) {
3188: for (var k=oldVal+1; k<=changedVal ; k++) {
3189: var elementName = current[k];
3190: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3191: }
3192: } else {
3193: for (var k=changedVal; k<oldVal; k++) {
3194: var elementName = current[k];
3195: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3196: }
3197: }
3198: return;
3199: }
3200:
3201: // ]]>
3202: </script>
3203:
1.319 raeburn 3204: $togglejs
3205:
3206: ENDSCRIPT
3207: }
3208:
3209: sub ltitools_toggle_js {
3210: return <<"ENDSCRIPT";
3211: <script type="text/javascript">
3212: // <![CDATA[
3213:
3214: function toggleLTITools(form,setting,item) {
3215: var radioname = '';
3216: var divid = '';
3217: if ((setting == 'passback') || (setting == 'roster')) {
3218: radioname = 'ltitools_'+setting+'_'+item;
3219: divid = 'ltitools_'+setting+'time_'+item;
3220: var num = form.elements[radioname].length;
3221: if (num) {
3222: var setvis = '';
3223: for (var i=0; i<num; i++) {
3224: if (form.elements[radioname][i].checked) {
3225: if (form.elements[radioname][i].value == '1') {
3226: if (document.getElementById(divid)) {
3227: document.getElementById(divid).style.display = 'inline-block';
3228: }
3229: setvis = 1;
3230: }
3231: break;
3232: }
3233: }
3234: }
3235: if (!setvis) {
3236: if (document.getElementById(divid)) {
3237: document.getElementById(divid).style.display = 'none';
3238: }
3239: }
3240: }
1.324 raeburn 3241: if (setting == 'user') {
3242: divid = 'ltitools_'+setting+'_div_'+item;
3243: var checkid = 'ltitools_'+setting+'_field_'+item;
3244: if (document.getElementById(divid)) {
3245: if (document.getElementById(checkid)) {
3246: if (document.getElementById(checkid).checked) {
3247: document.getElementById(divid).style.display = 'inline-block';
3248: } else {
3249: document.getElementById(divid).style.display = 'none';
3250: }
3251: }
3252: }
3253: }
1.319 raeburn 3254: return;
3255: }
3256: // ]]>
3257: </script>
3258:
1.267 raeburn 3259: ENDSCRIPT
3260: }
3261:
1.381 raeburn 3262: sub wafproxy_javascript {
3263: my ($dom) = @_;
3264: return <<"ENDSCRIPT";
3265: <script type="text/javascript">
3266: // <![CDATA[
3267: function updateWAF() {
3268: if (document.getElementById('wafproxy_remoteip')) {
3269: var wafremote = 0;
3270: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3271: wafremote = 1;
3272: }
3273: var fields = new Array('header','trust');
3274: for (var i=0; i<fields.length; i++) {
3275: if (document.getElementById('wafproxy_'+fields[i])) {
3276: if (wafremote == 1) {
3277: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3278: }
3279: else {
3280: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3281: }
3282: }
3283: }
3284: if (document.getElementById('wafproxyranges_$dom')) {
3285: if (wafremote == 1) {
3286: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3287: } else {
3288: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3289: if (document.display.wafproxy_vpnaccess[i].checked) {
3290: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3291: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3292: }
3293: }
3294: }
3295: }
3296: }
3297: }
3298: return;
3299: }
3300:
3301: function checkWAF() {
3302: if (document.getElementById('wafproxy_remoteip')) {
3303: var wafvpn = 0;
3304: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3305: if (document.display.wafproxy_vpnaccess[i].checked) {
3306: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3307: wafvpn = 1;
3308: }
3309: break;
3310: }
3311: }
3312: var vpn = new Array('vpnint','vpnext');
3313: for (var i=0; i<vpn.length; i++) {
3314: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3315: if (wafvpn == 1) {
3316: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3317: }
3318: else {
3319: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3320: }
3321: }
3322: }
3323: if (document.getElementById('wafproxyranges_$dom')) {
3324: if (wafvpn == 1) {
3325: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3326: }
3327: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3328: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3329: }
3330: }
3331: }
3332: return;
3333: }
3334:
3335: function toggleWAF() {
3336: if (document.getElementById('wafproxy_table')) {
3337: var wafproxy = 0;
3338: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3339: if (document.display.wafproxy_${dom}[i].checked) {
3340: if (document.display.wafproxy_${dom}[i].value == 1) {
3341: wafproxy = 1;
3342: break;
3343: }
3344: }
3345: }
3346: if (wafproxy == 1) {
3347: document.getElementById('wafproxy_table').style.display='inline';
3348: }
3349: else {
3350: document.getElementById('wafproxy_table').style.display='none';
3351: }
3352: if (document.getElementById('wafproxyrow_${dom}')) {
3353: if (wafproxy == 1) {
3354: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3355: }
3356: else {
3357: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3358: }
3359: }
3360: if (document.getElementById('nowafproxyrow_$dom')) {
3361: if (wafproxy == 1) {
3362: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3363: }
3364: else {
3365: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3366: }
3367: }
3368: }
3369: return;
3370: }
3371: // ]]>
3372: </script>
3373:
3374: ENDSCRIPT
3375: }
3376:
1.372 raeburn 3377: sub proctoring_javascript {
3378: my ($settings) = @_;
3379: my (%ordered,$total,%jstext);
3380: $total = 0;
3381: if (ref($settings) eq 'HASH') {
3382: foreach my $item (keys(%{$settings})) {
3383: if (ref($settings->{$item}) eq 'HASH') {
3384: my $num = $settings->{$item}{'order'};
3385: $ordered{$num} = $item;
3386: }
3387: }
3388: $total = scalar(keys(%{$settings}));
3389: } else {
3390: %ordered = (
3391: 0 => 'proctorio',
3392: 1 => 'examity',
3393: );
3394: $total = 2;
3395: }
3396: my @jsarray = ();
3397: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3398: push(@jsarray,$ordered{$item});
3399: }
3400: my $jstext = ' var proctors = Array('."'".join("','",@jsarray)."'".');'."\n";
3401: return <<"ENDSCRIPT";
3402: <script type="text/javascript">
3403: // <![CDATA[
3404: function reorderProctoring(form,item) {
3405: var changedVal;
3406: $jstext
3407: var maxh = $total;
3408: var current = new Array;
3409: var changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3410: for (var i=0; i<proctors.length; i++) {
3411: var elementName = 'proctoring_pos_'+proctors[i];
3412: if (elementName != item) {
3413: if (form.elements[elementName]) {
3414: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3415: current[currVal] = elementName;
3416: }
3417: }
3418: }
3419: var oldVal;
3420: for (var j=0; j<maxh; j++) {
3421: if (current[j] == undefined) {
3422: oldVal = j;
3423: }
3424: }
3425: if (oldVal < changedVal) {
3426: for (var k=oldVal+1; k<=changedVal ; k++) {
3427: var elementName = current[k];
3428: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3429: }
3430: } else {
3431: for (var k=changedVal; k<oldVal; k++) {
3432: var elementName = current[k];
3433: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3434: }
3435: }
3436: return;
3437: }
3438:
3439: function toggleProctoring(form,item) {
3440: var fieldsets = document.getElementsByClassName('proctoring_'+item);
3441: if (fieldsets.length) {
3442: var radioname = 'proctoring_available_'+item;
3443: var num = form.elements[radioname].length;
3444: if (num) {
3445: var setvis = '';
3446: for (var i=0; i<num; i++) {
3447: if (form.elements[radioname][i].checked) {
3448: if (form.elements[radioname][i].value == '1') {
3449: setvis = 1;
3450: break;
3451: }
3452: }
3453: }
3454: for (var j=0; j<fieldsets.length; j++) {
3455: if (setvis) {
3456: fieldsets[j].style.display = 'block';
3457: } else {
3458: fieldsets[j].style.display = 'none';
3459: }
3460: }
3461: }
3462: }
3463: return;
3464: }
3465:
3466: // ]]>
3467: </script>
3468:
3469: ENDSCRIPT
3470: }
3471:
3472:
1.320 raeburn 3473: sub lti_javascript {
1.405 raeburn 3474: my ($dom,$settings) = @_;
3475: my $togglejs = <i_toggle_js($dom);
1.419 raeburn 3476: my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
1.320 raeburn 3477: unless (ref($settings) eq 'HASH') {
1.419 raeburn 3478: return $togglejs.'
3479: <script type="text/javascript">
3480: // <![CDATA[
3481:
3482: '.$linkprot_js.'
3483:
3484: // ]]>
3485: </script>
3486: ';
1.320 raeburn 3487: }
3488: my (%ordered,$total,%jstext);
1.390 raeburn 3489: $total = scalar(keys(%{$settings}));
1.320 raeburn 3490: foreach my $item (keys(%{$settings})) {
3491: if (ref($settings->{$item}) eq 'HASH') {
3492: my $num = $settings->{$item}{'order'};
1.390 raeburn 3493: if ($num eq '') {
3494: $num = $total - 1;
3495: }
1.320 raeburn 3496: $ordered{$num} = $item;
3497: }
3498: }
3499: my @jsarray = ();
3500: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3501: push(@jsarray,$ordered{$item});
3502: }
3503: my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
3504: return <<"ENDSCRIPT";
3505: <script type="text/javascript">
3506: // <![CDATA[
3507: function reorderLTI(form,item) {
3508: var changedVal;
3509: $jstext
3510: var newpos = 'lti_pos_add';
3511: var maxh = 1 + $total;
3512: var current = new Array;
3513: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3514: if (item == newpos) {
3515: changedVal = newitemVal;
3516: } else {
3517: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3518: current[newitemVal] = newpos;
3519: }
3520: for (var i=0; i<lti.length; i++) {
3521: var elementName = 'lti_pos_'+lti[i];
3522: if (elementName != item) {
3523: if (form.elements[elementName]) {
3524: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3525: current[currVal] = elementName;
3526: }
3527: }
3528: }
3529: var oldVal;
3530: for (var j=0; j<maxh; j++) {
3531: if (current[j] == undefined) {
3532: oldVal = j;
3533: }
3534: }
3535: if (oldVal < changedVal) {
3536: for (var k=oldVal+1; k<=changedVal ; k++) {
3537: var elementName = current[k];
3538: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3539: }
3540: } else {
3541: for (var k=changedVal; k<oldVal; k++) {
3542: var elementName = current[k];
3543: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3544: }
3545: }
3546: return;
3547: }
1.406 raeburn 3548:
3549: $linkprot_js
3550:
1.320 raeburn 3551: // ]]>
3552: </script>
3553:
3554: $togglejs
3555:
3556: ENDSCRIPT
3557: }
3558:
3559: sub lti_toggle_js {
1.405 raeburn 3560: my ($dom) = @_;
1.325 raeburn 3561: my %lcauthparmtext = &Apache::lonlocal::texthash (
3562: localauth => 'Local auth argument',
3563: krb => 'Kerberos domain',
3564: );
1.391 raeburn 3565: my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3566: &js_escape(\$crsincalert);
1.405 raeburn 3567: my %servers = &Apache::lonnet::get_servers($dom,'library');
3568: my $primary = &Apache::lonnet::domain($dom,'primary');
3569: my $course_servers = "'".join("','",keys(%servers))."'";
1.320 raeburn 3570: return <<"ENDSCRIPT";
3571: <script type="text/javascript">
3572: // <![CDATA[
3573:
3574: function toggleLTI(form,setting,item) {
1.391 raeburn 3575: if ((setting == 'requser') || (setting == 'crsinc')) {
3576: var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3577: var setvis = '';
3578: var radioname = 'lti_requser_'+item;
3579: var num = form.elements[radioname].length;
3580: if (num) {
3581: for (var i=0; i<num; i++) {
3582: if (form.elements[radioname][i].checked) {
3583: if (form.elements[radioname][i].value == '1') {
3584: setvis = 1;
3585: break;
3586: }
3587: }
3588: }
3589: }
3590: if (usrfieldsets.length) {
3591: for (var j=0; j<usrfieldsets.length; j++) {
3592: if (setvis) {
3593: usrfieldsets[j].style.display = 'block';
3594: } else {
3595: usrfieldsets[j].style.display = 'none';
3596: }
3597: }
3598: }
3599: var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3600: if (crsfieldsets.length) {
3601: radioname = 'lti_crsinc_'+item;
1.345 raeburn 3602: var num = form.elements[radioname].length;
3603: if (num) {
1.391 raeburn 3604: var crsvis = '';
1.345 raeburn 3605: for (var i=0; i<num; i++) {
3606: if (form.elements[radioname][i].checked) {
3607: if (form.elements[radioname][i].value == '1') {
1.391 raeburn 3608: if (setvis == '') {
3609: if (setting == 'crsinc'){
3610: alert("$crsincalert");
3611: form.elements[radioname][0].checked = true;
3612: }
3613: } else {
3614: crsvis = 1;
3615: }
3616: break;
1.345 raeburn 3617: }
3618: }
3619: }
1.391 raeburn 3620: setvis = crsvis;
3621: }
3622: for (var j=0; j<crsfieldsets.length; j++) {
3623: if (setvis) {
3624: crsfieldsets[j].style.display = 'block';
3625: } else {
3626: crsfieldsets[j].style.display = 'none';
1.345 raeburn 3627: }
3628: }
3629: }
1.363 raeburn 3630: } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
1.320 raeburn 3631: var radioname = '';
3632: var divid = '';
3633: if (setting == 'user') {
3634: radioname = 'lti_mapuser_'+item;
3635: divid = 'lti_userfield_'+item;
1.343 raeburn 3636: } else if (setting == 'crs') {
1.320 raeburn 3637: radioname = 'lti_mapcrs_'+item;
3638: divid = 'lti_crsfield_'+item;
1.363 raeburn 3639: } else if (setting == 'callback') {
3640: radioname = 'lti_callback_'+item;
3641: divid = 'lti_callbackfield_'+item;
1.337 raeburn 3642: } else {
1.351 raeburn 3643: radioname = 'lti_passback_'+item;
1.337 raeburn 3644: divid = 'lti_passback_'+item;
1.320 raeburn 3645: }
3646: var num = form.elements[radioname].length;
3647: if (num) {
3648: var setvis = '';
3649: for (var i=0; i<num; i++) {
3650: if (form.elements[radioname][i].checked) {
1.363 raeburn 3651: if ((setting == 'passback') || (setting == 'callback')) {
1.337 raeburn 3652: if (form.elements[radioname][i].value == '1') {
3653: if (document.getElementById(divid)) {
3654: document.getElementById(divid).style.display = 'inline-block';
3655: }
3656: setvis = 1;
3657: break;
3658: }
3659: } else {
3660: if (form.elements[radioname][i].value == 'other') {
3661: if (document.getElementById(divid)) {
3662: document.getElementById(divid).style.display = 'inline-block';
3663: }
3664: setvis = 1;
3665: break;
1.320 raeburn 3666: }
3667: }
1.425 raeburn 3668: }
1.320 raeburn 3669: }
3670: if (!setvis) {
3671: if (document.getElementById(divid)) {
3672: document.getElementById(divid).style.display = 'none';
3673: }
3674: }
3675: }
3676: } else if ((setting == 'sec') || (setting == 'secsrc')) {
3677: var numsec = form.elements['lti_crssec_'+item].length;
3678: if (numsec) {
3679: var setvis = '';
3680: for (var i=0; i<numsec; i++) {
3681: if (form.elements['lti_crssec_'+item][i].checked) {
3682: if (form.elements['lti_crssec_'+item][i].value == '1') {
3683: if (document.getElementById('lti_crssecfield_'+item)) {
3684: document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3685: setvis = 1;
3686: var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3687: if (numsrcsec) {
3688: var setsrcvis = '';
3689: for (var j=0; j<numsrcsec; j++) {
3690: if (form.elements['lti_crssecsrc_'+item][j].checked) {
3691: if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3692: if (document.getElementById('lti_secsrcfield_'+item)) {
3693: document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3694: setsrcvis = 1;
3695: }
3696: }
3697: }
3698: }
3699: if (!setsrcvis) {
3700: if (document.getElementById('lti_secsrcfield_'+item)) {
3701: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3702: }
3703: }
3704: }
3705: }
3706: }
3707: }
3708: }
3709: if (!setvis) {
3710: if (document.getElementById('lti_crssecfield_'+item)) {
3711: document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3712: }
3713: if (document.getElementById('lti_secsrcfield_'+item)) {
3714: document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3715: }
3716: }
3717: }
1.325 raeburn 3718: } else if (setting == 'lcauth') {
3719: var numauth = form.elements['lti_lcauth_'+item].length;
3720: if (numauth) {
3721: for (var i=0; i<numauth; i++) {
3722: if (form.elements['lti_lcauth_'+item][i].checked) {
3723: if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3724: if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3725: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3726: } else {
3727: document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3728: if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3729: if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3730: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3731: } else {
3732: document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3733: }
3734: }
3735: }
3736: }
3737: }
3738: }
3739: }
1.326 raeburn 3740: } else if (setting == 'lcmenu') {
3741: var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3742: var divid = 'lti_menufield_'+item;
3743: var setvis = '';
3744: for (var i=0; i<menus.length; i++) {
1.425 raeburn 3745: var radioname = menus[i];
1.326 raeburn 3746: var num = form.elements[radioname].length;
3747: if (num) {
3748: for (var j=0; j<num; j++) {
3749: if (form.elements[radioname][j].checked) {
3750: if (form.elements[radioname][j].value == '1') {
3751: if (document.getElementById(divid)) {
3752: document.getElementById(divid).style.display = 'inline-block';
3753: }
3754: setvis = 1;
3755: break;
3756: }
3757: }
3758: }
3759: }
3760: if (setvis == 1) {
3761: break;
3762: }
3763: }
3764: if (!setvis) {
3765: if (document.getElementById(divid)) {
3766: document.getElementById(divid).style.display = 'none';
3767: }
3768: }
1.320 raeburn 3769: }
3770: return;
3771: }
1.405 raeburn 3772:
1.320 raeburn 3773: // ]]>
3774: </script>
3775:
3776: ENDSCRIPT
3777: }
3778:
1.385 raeburn 3779: sub autoupdate_javascript {
3780: return <<"ENDSCRIPT";
3781: <script type="text/javascript">
3782: // <![CDATA[
3783: function toggleLastActiveDays(form) {
3784: var radioname = 'lastactive';
3785: var divid = 'lastactive_div';
3786: var num = form.elements[radioname].length;
3787: if (num) {
3788: var setvis = '';
3789: for (var i=0; i<num; i++) {
3790: if (form.elements[radioname][i].checked) {
3791: if (form.elements[radioname][i].value == '1') {
3792: if (document.getElementById(divid)) {
3793: document.getElementById(divid).style.display = 'inline-block';
3794: }
3795: setvis = 1;
3796: }
3797: break;
3798: }
3799: }
3800: if (!setvis) {
3801: if (document.getElementById(divid)) {
3802: document.getElementById(divid).style.display = 'none';
3803: }
3804: }
3805: }
3806: return;
3807: }
3808: // ]]>
3809: </script>
3810:
3811: ENDSCRIPT
3812: }
3813:
1.399 raeburn 3814: sub autoenroll_javascript {
3815: return <<"ENDSCRIPT";
3816: <script type="text/javascript">
3817: // <![CDATA[
3818: function toggleFailsafe(form) {
3819: var radioname = 'autoenroll_failsafe';
3820: var divid = 'autoenroll_failsafe_div';
3821: var num = form.elements[radioname].length;
3822: if (num) {
3823: var setvis = '';
3824: for (var i=0; i<num; i++) {
3825: if (form.elements[radioname][i].checked) {
3826: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3827: if (document.getElementById(divid)) {
3828: document.getElementById(divid).style.display = 'inline-block';
3829: }
3830: setvis = 1;
3831: }
3832: break;
3833: }
3834: }
3835: if (!setvis) {
3836: if (document.getElementById(divid)) {
3837: document.getElementById(divid).style.display = 'none';
3838: }
3839: }
3840: }
3841: return;
3842: }
3843: // ]]>
3844: </script>
3845:
3846: ENDSCRIPT
3847: }
3848:
1.386 raeburn 3849: sub saml_javascript {
3850: return <<"ENDSCRIPT";
3851: <script type="text/javascript">
3852: // <![CDATA[
1.425 raeburn 3853: function toggleSamlOptions(form,hostid) {
1.386 raeburn 3854: var radioname = 'saml_'+hostid;
3855: var tablecellon = 'samloptionson_'+hostid;
3856: var tablecelloff = 'samloptionsoff_'+hostid;
3857: var num = form.elements[radioname].length;
3858: if (num) {
1.425 raeburn 3859: var setvis = '';
1.386 raeburn 3860: for (var i=0; i<num; i++) {
3861: if (form.elements[radioname][i].checked) {
1.425 raeburn 3862: if (form.elements[radioname][i].value == '1') {
1.386 raeburn 3863: if (document.getElementById(tablecellon)) {
3864: document.getElementById(tablecellon).style.display='';
3865: }
3866: if (document.getElementById(tablecelloff)) {
3867: document.getElementById(tablecelloff).style.display='none';
3868: }
3869: setvis = 1;
3870: }
3871: break;
3872: }
3873: }
3874: if (!setvis) {
3875: if (document.getElementById(tablecellon)) {
3876: document.getElementById(tablecellon).style.display='none';
3877: }
3878: if (document.getElementById(tablecelloff)) {
3879: document.getElementById(tablecelloff).style.display='';
3880: }
3881: }
3882: }
3883: return;
3884: }
3885: // ]]>
3886: </script>
3887:
3888: ENDSCRIPT
3889: }
3890:
1.394 raeburn 3891: sub ipaccess_javascript {
3892: my ($settings) = @_;
3893: my (%ordered,$total,%jstext);
3894: $total = 0;
3895: if (ref($settings) eq 'HASH') {
3896: foreach my $item (keys(%{$settings})) {
3897: if (ref($settings->{$item}) eq 'HASH') {
3898: my $num = $settings->{$item}{'order'};
3899: $ordered{$num} = $item;
3900: }
3901: }
3902: $total = scalar(keys(%{$settings}));
3903: }
3904: my @jsarray = ();
3905: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3906: push(@jsarray,$ordered{$item});
3907: }
3908: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3909: return <<"ENDSCRIPT";
3910: <script type="text/javascript">
3911: // <![CDATA[
3912: function reorderIPaccess(form,item) {
3913: var changedVal;
3914: $jstext
3915: var newpos = 'ipaccess_pos_add';
3916: var maxh = 1 + $total;
3917: var current = new Array;
3918: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3919: if (item == newpos) {
3920: changedVal = newitemVal;
3921: } else {
3922: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3923: current[newitemVal] = newpos;
3924: }
3925: for (var i=0; i<ipaccess.length; i++) {
3926: var elementName = 'ipaccess_pos_'+ipaccess[i];
3927: if (elementName != item) {
3928: if (form.elements[elementName]) {
3929: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3930: current[currVal] = elementName;
3931: }
3932: }
3933: }
3934: var oldVal;
3935: for (var j=0; j<maxh; j++) {
3936: if (current[j] == undefined) {
3937: oldVal = j;
3938: }
3939: }
3940: if (oldVal < changedVal) {
3941: for (var k=oldVal+1; k<=changedVal ; k++) {
3942: var elementName = current[k];
3943: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3944: }
3945: } else {
3946: for (var k=changedVal; k<oldVal; k++) {
3947: var elementName = current[k];
3948: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3949: }
3950: }
3951: return;
3952: }
3953: // ]]>
3954: </script>
3955:
3956: ENDSCRIPT
3957: }
3958:
1.429 raeburn 3959: sub authordefaults_javascript {
3960: my %alert = &Apache::lonlocal::texthash (
3961: reqd => 'Warning: at least one editor needs to be available.',
3962: rest => 'Unchecking this editor disallowed while others unchecked.',
3963: );
3964: &js_escape(\%alert);
3965: return <<"ENDSCRIPT";
3966: <script type="text/javascript">
3967: // <![CDATA[
3968:
3969: function checkEditors(form,checkbox,current) {
3970: if (form.elements[checkbox].length != undefined) {
3971: var count = 0;
3972: for (var i=0; i<form.elements[checkbox].length; i++) {
3973: if (form.elements[checkbox][i].checked) {
3974: count ++;
3975: }
3976: }
3977: if (count == 0) {
3978: if (current.type =='radio') {
3979: current.checked = true;
3980: alert('$alert{reqd}\\n$alert{rest}');
3981: }
3982: }
3983: }
3984: return;
3985: }
3986: // ]]>
3987: </script>
3988:
3989: ENDSCRIPT
3990: }
3991:
1.3 raeburn 3992: sub print_autoenroll {
1.30 raeburn 3993: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3994: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.399 raeburn 3995: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3996: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3997: $failsafesty = 'none';
3998: %failsafechecked = (
3999: off => ' checked="checked"',
4000: );
1.3 raeburn 4001: if (ref($settings) eq 'HASH') {
4002: if (exists($settings->{'run'})) {
4003: if ($settings->{'run'} eq '0') {
4004: $runoff = ' checked="checked" ';
4005: $runon = ' ';
4006: } else {
4007: $runon = ' checked="checked" ';
4008: $runoff = ' ';
4009: }
4010: } else {
4011: if ($autorun) {
4012: $runon = ' checked="checked" ';
4013: $runoff = ' ';
4014: } else {
4015: $runoff = ' checked="checked" ';
4016: $runon = ' ';
4017: }
4018: }
1.129 raeburn 4019: if (exists($settings->{'co-owners'})) {
4020: if ($settings->{'co-owners'} eq '0') {
4021: $coownersoff = ' checked="checked" ';
4022: $coownerson = ' ';
4023: } else {
4024: $coownerson = ' checked="checked" ';
4025: $coownersoff = ' ';
4026: }
4027: } else {
4028: $coownersoff = ' checked="checked" ';
4029: $coownerson = ' ';
4030: }
1.3 raeburn 4031: if (exists($settings->{'sender_domain'})) {
4032: $defdom = $settings->{'sender_domain'};
4033: }
1.399 raeburn 4034: if (exists($settings->{'failsafe'})) {
4035: $failsafe = $settings->{'failsafe'};
4036: if ($failsafe eq 'zero') {
1.400 raeburn 4037: $failsafechecked{'zero'} = ' checked="checked"';
1.399 raeburn 4038: $failsafechecked{'off'} = '';
4039: $failsafesty = 'inline-block';
4040: } elsif ($failsafe eq 'any') {
4041: $failsafechecked{'any'} = ' checked="checked"';
4042: $failsafechecked{'off'} = '';
4043: }
4044: $autofailsafe = $settings->{'autofailsafe'};
4045: } elsif (exists($settings->{'autofailsafe'})) {
4046: $autofailsafe = $settings->{'autofailsafe'};
4047: if ($autofailsafe ne '') {
4048: $failsafechecked{'zero'} = ' checked="checked"';
4049: $failsafe = 'zero';
1.400 raeburn 4050: $failsafechecked{'off'} = '';
1.399 raeburn 4051: }
1.274 raeburn 4052: }
1.14 raeburn 4053: } else {
4054: if ($autorun) {
4055: $runon = ' checked="checked" ';
4056: $runoff = ' ';
4057: } else {
4058: $runoff = ' checked="checked" ';
4059: $runon = ' ';
4060: }
1.3 raeburn 4061: }
4062: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 4063: my $notif_sender;
4064: if (ref($settings) eq 'HASH') {
4065: $notif_sender = $settings->{'sender_uname'};
4066: }
1.3 raeburn 4067: my $datatable='<tr class="LC_odd_row">'.
4068: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 4069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4070: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 4071: $runon.' value="1" />'.&mt('Yes').'</label> '.
4072: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 4073: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 4074: '</tr><tr>'.
4075: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 4076: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 4077: &mt('username').': '.
4078: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 4079: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 4080: ': '.$domform.'</span></td></tr>'.
4081: '<tr class="LC_odd_row">'.
4082: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
4083: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4084: '<input type="radio" name="autoassign_coowners"'.
4085: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
4086: '<label><input type="radio" name="autoassign_coowners"'.
4087: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.274 raeburn 4088: '</tr><tr>'.
4089: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.400 raeburn 4090: '<td class="LC_left_item"><span class="LC_nobreak">'.
4091: '<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> '.
4092: '<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 />'.
4093: '<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 4094: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
4095: '<span class="LC_nobreak">'.
4096: &mt('Threshold for number of students in section to drop: [_1]',
4097: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
4098: '</span></div></td></tr>';
1.274 raeburn 4099: $$rowtotal += 4;
1.3 raeburn 4100: return $datatable;
4101: }
4102:
4103: sub print_autoupdate {
1.30 raeburn 4104: my ($position,$dom,$settings,$rowtotal) = @_;
1.385 raeburn 4105: my ($enable,$datatable);
1.3 raeburn 4106: if ($position eq 'top') {
1.385 raeburn 4107: my %choices = &Apache::lonlocal::texthash (
4108: run => 'Auto-update active?',
4109: classlists => 'Update information in classlists?',
4110: unexpired => 'Skip updates for users without active or future roles?',
4111: lastactive => 'Skip updates for inactive users?',
4112: );
4113: my $itemcount = 0;
1.3 raeburn 4114: my $updateon = ' ';
4115: my $updateoff = ' checked="checked" ';
4116: if (ref($settings) eq 'HASH') {
4117: if ($settings->{'run'} eq '1') {
4118: $updateon = $updateoff;
4119: $updateoff = ' ';
4120: }
4121: }
1.385 raeburn 4122: $enable = '<tr class="LC_odd_row">'.
4123: '<td>'.$choices{'run'}.'</td>'.
4124: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 4125: '<input type="radio" name="autoupdate_run"'.
1.397 raeburn 4126: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 4127: '<label><input type="radio" name="autoupdate_run"'.
1.385 raeburn 4128: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 4129: '</tr>';
1.385 raeburn 4130: my @toggles = ('classlists','unexpired');
4131: my %defaultchecked = ('classlists' => 'off',
4132: 'unexpired' => 'off'
4133: );
4134: $$rowtotal ++;
4135: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4136: \%choices,$itemcount,'','','left','no');
4137: $datatable = $enable.$datatable;
4138: $$rowtotal += $itemcount;
4139: my $lastactiveon = ' ';
4140: my $lastactiveoff = ' checked="checked" ';
4141: my $lastactivestyle = 'none';
4142: my $lastactivedays;
4143: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
4144: if (ref($settings) eq 'HASH') {
4145: if ($settings->{'lastactive'} =~ /^\d+$/) {
4146: $lastactiveon = $lastactiveoff;
4147: $lastactiveoff = ' ';
4148: $lastactivestyle = 'inline-block';
4149: $lastactivedays = $settings->{'lastactive'};
4150: }
4151: }
4152: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4153: $datatable .= '<tr'.$css_class.'>'.
4154: '<td>'.$choices{'lastactive'}.'</td>'.
4155: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
4156: '<input type="radio" name="lastactive"'.
4157: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
4158: ' <label>'.
4159: '<input type="radio" name="lastactive"'.
4160: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
4161: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
4162: ': '.&mt('inactive = no activity in last [_1] days',
4163: '<input type="text" size="5" name="lastactivedays" value="'.
4164: $lastactivedays.'" />').
4165: '</span></td>'.
4166: '</tr>';
4167: $$rowtotal ++;
1.131 raeburn 4168: } elsif ($position eq 'middle') {
4169: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4170: my $numinrow = 3;
4171: my $locknamesettings;
4172: $datatable .= &insttypes_row($settings,$types,$usertypes,
4173: $dom,$numinrow,$othertitle,
1.305 raeburn 4174: 'lockablenames',$rowtotal);
1.131 raeburn 4175: $$rowtotal ++;
1.3 raeburn 4176: } else {
1.44 raeburn 4177: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 4178: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 4179: 'permanentemail','id');
1.33 raeburn 4180: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 4181: my $numrows = 0;
1.26 raeburn 4182: if (ref($types) eq 'ARRAY') {
4183: if (@{$types} > 0) {
4184: $datatable =
4185: &usertype_update_row($settings,$usertypes,\%fieldtitles,
4186: \@fields,$types,\$numrows);
1.30 raeburn 4187: $$rowtotal += @{$types};
1.26 raeburn 4188: }
1.3 raeburn 4189: }
4190: $datatable .=
4191: &usertype_update_row($settings,{'default' => $othertitle},
4192: \%fieldtitles,\@fields,['default'],
4193: \$numrows);
1.30 raeburn 4194: $$rowtotal ++;
1.3 raeburn 4195: }
4196: return $datatable;
4197: }
4198:
1.125 raeburn 4199: sub print_autocreate {
4200: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 4201: my (%createon,%createoff,%currhash);
1.125 raeburn 4202: my @types = ('xml','req');
4203: if (ref($settings) eq 'HASH') {
4204: foreach my $item (@types) {
4205: $createoff{$item} = ' checked="checked" ';
4206: $createon{$item} = ' ';
4207: if (exists($settings->{$item})) {
4208: if ($settings->{$item}) {
4209: $createon{$item} = ' checked="checked" ';
4210: $createoff{$item} = ' ';
4211: }
4212: }
4213: }
1.210 raeburn 4214: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 4215: $currhash{$settings->{'xmldc'}} = 1;
4216: }
1.125 raeburn 4217: } else {
4218: foreach my $item (@types) {
4219: $createoff{$item} = ' checked="checked" ';
4220: $createon{$item} = ' ';
4221: }
4222: }
4223: $$rowtotal += 2;
1.191 raeburn 4224: my $numinrow = 2;
1.125 raeburn 4225: my $datatable='<tr class="LC_odd_row">'.
4226: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
4227: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4228: '<input type="radio" name="autocreate_xml"'.
4229: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4230: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4231: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4232: '</td></tr><tr>'.
4233: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4234: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4235: '<input type="radio" name="autocreate_req"'.
4236: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4237: '<label><input type="radio" name="autocreate_req"'.
4238: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 4239: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4240: 'autocreate_xmldc',%currhash);
1.247 raeburn 4241: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4242: if ($numdc > 1) {
1.247 raeburn 4243: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4244: '</td><td class="LC_left_item">';
1.125 raeburn 4245: } else {
1.247 raeburn 4246: $datatable .= &mt('Course creation processed as:').
4247: '</td><td class="LC_right_item">';
1.125 raeburn 4248: }
1.247 raeburn 4249: $datatable .= $dctable.'</td></tr>';
1.191 raeburn 4250: $$rowtotal += $rows;
1.125 raeburn 4251: return $datatable;
4252: }
4253:
1.23 raeburn 4254: sub print_directorysrch {
1.277 raeburn 4255: my ($position,$dom,$settings,$rowtotal) = @_;
4256: my $datatable;
4257: if ($position eq 'top') {
4258: my $instsrchon = ' ';
4259: my $instsrchoff = ' checked="checked" ';
4260: my ($exacton,$containson,$beginson);
4261: my $instlocalon = ' ';
4262: my $instlocaloff = ' checked="checked" ';
4263: if (ref($settings) eq 'HASH') {
4264: if ($settings->{'available'} eq '1') {
4265: $instsrchon = $instsrchoff;
4266: $instsrchoff = ' ';
4267: }
4268: if ($settings->{'localonly'} eq '1') {
4269: $instlocalon = $instlocaloff;
4270: $instlocaloff = ' ';
4271: }
4272: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4273: foreach my $type (@{$settings->{'searchtypes'}}) {
4274: if ($type eq 'exact') {
4275: $exacton = ' checked="checked" ';
4276: } elsif ($type eq 'contains') {
4277: $containson = ' checked="checked" ';
4278: } elsif ($type eq 'begins') {
4279: $beginson = ' checked="checked" ';
4280: }
4281: }
4282: } else {
4283: if ($settings->{'searchtypes'} eq 'exact') {
4284: $exacton = ' checked="checked" ';
4285: } elsif ($settings->{'searchtypes'} eq 'contains') {
4286: $containson = ' checked="checked" ';
4287: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4288: $exacton = ' checked="checked" ';
4289: $containson = ' checked="checked" ';
4290: }
4291: }
1.277 raeburn 4292: }
4293: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4295:
4296: my $numinrow = 4;
4297: my $cansrchrow = 0;
4298: $datatable='<tr class="LC_odd_row">'.
4299: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4300: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4301: '<input type="radio" name="dirsrch_available"'.
4302: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4303: '<label><input type="radio" name="dirsrch_available"'.
4304: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4305: '</tr><tr>'.
4306: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4307: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4308: '<input type="radio" name="dirsrch_instlocalonly"'.
4309: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4310: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4311: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4312: '</tr>';
4313: $$rowtotal += 2;
4314: if (ref($usertypes) eq 'HASH') {
4315: if (keys(%{$usertypes}) > 0) {
4316: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.305 raeburn 4317: $numinrow,$othertitle,'cansearch',
4318: $rowtotal);
1.277 raeburn 4319: $cansrchrow = 1;
1.25 raeburn 4320: }
1.23 raeburn 4321: }
1.277 raeburn 4322: if ($cansrchrow) {
4323: $$rowtotal ++;
4324: $datatable .= '<tr>';
4325: } else {
4326: $datatable .= '<tr class="LC_odd_row">';
1.26 raeburn 4327: }
1.277 raeburn 4328: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4329: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4330: foreach my $title (@{$titleorder}) {
4331: if (defined($searchtitles->{$title})) {
4332: my $check = ' ';
4333: if (ref($settings) eq 'HASH') {
4334: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4335: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4336: $check = ' checked="checked" ';
4337: }
1.39 raeburn 4338: }
1.25 raeburn 4339: }
1.277 raeburn 4340: $datatable .= '<td class="LC_left_item">'.
4341: '<span class="LC_nobreak"><label>'.
4342: '<input type="checkbox" name="searchby" '.
4343: 'value="'.$title.'"'.$check.'/>'.
4344: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4345: }
4346: }
1.277 raeburn 4347: $datatable .= '</tr></table></td></tr>';
4348: $$rowtotal ++;
4349: if ($cansrchrow) {
4350: $datatable .= '<tr class="LC_odd_row">';
4351: } else {
4352: $datatable .= '<tr>';
4353: }
4354: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4355: '<td class="LC_left_item" colspan="2">'.
4356: '<span class="LC_nobreak"><label>'.
4357: '<input type="checkbox" name="searchtypes" '.
4358: $exacton.' value="exact" />'.&mt('Exact match').
4359: '</label> '.
4360: '<label><input type="checkbox" name="searchtypes" '.
4361: $beginson.' value="begins" />'.&mt('Begins with').
4362: '</label> '.
4363: '<label><input type="checkbox" name="searchtypes" '.
4364: $containson.' value="contains" />'.&mt('Contains').
4365: '</label></span></td></tr>';
4366: $$rowtotal ++;
1.26 raeburn 4367: } else {
1.277 raeburn 4368: my $domsrchon = ' checked="checked" ';
4369: my $domsrchoff = ' ';
4370: my $domlocalon = ' ';
4371: my $domlocaloff = ' checked="checked" ';
4372: if (ref($settings) eq 'HASH') {
4373: if ($settings->{'lclocalonly'} eq '1') {
4374: $domlocalon = $domlocaloff;
4375: $domlocaloff = ' ';
4376: }
4377: if ($settings->{'lcavailable'} eq '0') {
4378: $domsrchoff = $domsrchon;
4379: $domsrchon = ' ';
4380: }
4381: }
4382: $datatable='<tr class="LC_odd_row">'.
4383: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4384: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4385: '<input type="radio" name="dirsrch_domavailable"'.
4386: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4387: '<label><input type="radio" name="dirsrch_domavailable"'.
4388: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4389: '</tr><tr>'.
4390: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4391: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4392: '<input type="radio" name="dirsrch_domlocalonly"'.
4393: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4394: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4395: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4396: '</tr>';
4397: $$rowtotal += 2;
1.26 raeburn 4398: }
1.25 raeburn 4399: return $datatable;
4400: }
4401:
1.28 raeburn 4402: sub print_contacts {
1.286 raeburn 4403: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4404: my $datatable;
4405: my @contacts = ('adminemail','supportemail');
1.286 raeburn 4406: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.340 raeburn 4407: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.286 raeburn 4408: if ($position eq 'top') {
4409: if (ref($settings) eq 'HASH') {
4410: foreach my $item (@contacts) {
4411: if (exists($settings->{$item})) {
4412: $to{$item} = $settings->{$item};
4413: }
4414: }
4415: }
4416: } elsif ($position eq 'middle') {
4417: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.350 raeburn 4418: 'updatesmail','idconflictsmail','hostipmail');
1.288 raeburn 4419: foreach my $type (@mailings) {
4420: $otheremails{$type} = '';
4421: }
1.340 raeburn 4422: } elsif ($position eq 'lower') {
4423: if (ref($settings) eq 'HASH') {
4424: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4425: %lonstatus = %{$settings->{'lonstatus'}};
4426: }
4427: }
1.286 raeburn 4428: } else {
4429: @mailings = ('helpdeskmail','otherdomsmail');
1.288 raeburn 4430: foreach my $type (@mailings) {
4431: $otheremails{$type} = '';
4432: }
1.286 raeburn 4433: $bccemails{'helpdeskmail'} = '';
4434: $bccemails{'otherdomsmail'} = '';
4435: $includestr{'helpdeskmail'} = '';
4436: $includestr{'otherdomsmail'} = '';
4437: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4438: }
1.28 raeburn 4439: if (ref($settings) eq 'HASH') {
1.340 raeburn 4440: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4441: foreach my $type (@mailings) {
4442: if (exists($settings->{$type})) {
4443: if (ref($settings->{$type}) eq 'HASH') {
4444: foreach my $item (@contacts) {
4445: if ($settings->{$type}{$item}) {
4446: $checked{$type}{$item} = ' checked="checked" ';
4447: }
4448: }
4449: $otheremails{$type} = $settings->{$type}{'others'};
4450: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4451: $bccemails{$type} = $settings->{$type}{'bcc'};
4452: if ($settings->{$type}{'include'} ne '') {
4453: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4454: $includestr{$type} = &unescape($includestr{$type});
4455: }
4456: }
4457: }
4458: } elsif ($type eq 'lonstatusmail') {
4459: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4460: }
1.28 raeburn 4461: }
4462: }
1.286 raeburn 4463: if ($position eq 'bottom') {
4464: foreach my $type (@mailings) {
4465: $bccemails{$type} = $settings->{$type}{'bcc'};
4466: if ($settings->{$type}{'include'} ne '') {
4467: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4468: $includestr{$type} = &unescape($includestr{$type});
4469: }
4470: }
4471: if (ref($settings->{'helpform'}) eq 'HASH') {
4472: if (ref($fields) eq 'ARRAY') {
4473: foreach my $field (@{$fields}) {
4474: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4475: }
1.286 raeburn 4476: }
4477: if (exists($settings->{'helpform'}{'maxsize'})) {
4478: $maxsize = $settings->{'helpform'}{'maxsize'};
4479: } else {
1.289 raeburn 4480: $maxsize = '1.0';
1.286 raeburn 4481: }
4482: } else {
4483: if (ref($fields) eq 'ARRAY') {
4484: foreach my $field (@{$fields}) {
4485: $currfield{$field} = 'yes';
1.134 raeburn 4486: }
1.28 raeburn 4487: }
1.286 raeburn 4488: $maxsize = '1.0';
1.28 raeburn 4489: }
4490: }
4491: } else {
1.286 raeburn 4492: if ($position eq 'top') {
4493: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4494: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4495: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4496: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.289 raeburn 4497: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4498: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4499: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4500: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.350 raeburn 4501: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.286 raeburn 4502: } elsif ($position eq 'bottom') {
4503: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4504: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4505: if (ref($fields) eq 'ARRAY') {
4506: foreach my $field (@{$fields}) {
4507: $currfield{$field} = 'yes';
4508: }
4509: }
4510: $maxsize = '1.0';
4511: }
1.28 raeburn 4512: }
4513: my ($titles,$short_titles) = &contact_titles();
4514: my $rownum = 0;
4515: my $css_class;
1.286 raeburn 4516: if ($position eq 'top') {
4517: foreach my $item (@contacts) {
4518: $css_class = $rownum%2?' class="LC_odd_row"':'';
4519: $datatable .= '<tr'.$css_class.'>'.
4520: '<td><span class="LC_nobreak">'.$titles->{$item}.
4521: '</span></td><td class="LC_right_item">'.
4522: '<input type="text" name="'.$item.'" value="'.
4523: $to{$item}.'" /></td></tr>';
4524: $rownum ++;
4525: }
1.315 raeburn 4526: } elsif ($position eq 'bottom') {
4527: $css_class = $rownum%2?' class="LC_odd_row"':'';
4528: $datatable .= '<tr'.$css_class.'>'.
4529: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4530: &mt('(e-mail, subject, and description always shown)').
4531: '</td><td class="LC_left_item">';
4532: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4533: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4534: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4535: foreach my $field (@{$fields}) {
4536: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4537: if (($field eq 'screenshot') || ($field eq 'cc')) {
4538: $datatable .= ' '.&mt('(logged-in users)');
4539: }
4540: $datatable .='</td><td>';
4541: my $clickaction;
4542: if ($field eq 'screenshot') {
4543: $clickaction = ' onclick="screenshotSize(this);"';
4544: }
4545: if (ref($possoptions->{$field}) eq 'ARRAY') {
4546: foreach my $option (@{$possoptions->{$field}}) {
4547: my $checked;
4548: if ($currfield{$field} eq $option) {
4549: $checked = ' checked="checked"';
4550: }
4551: $datatable .= '<span class="LC_nobreak"><label>'.
4552: '<input type="radio" name="helpform_'.$field.'" '.
4553: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4554: '</label></span>'.(' 'x2);
4555: }
4556: }
4557: if ($field eq 'screenshot') {
4558: my $display;
4559: if ($currfield{$field} eq 'no') {
4560: $display = ' style="display:none"';
4561: }
1.334 raeburn 4562: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
1.315 raeburn 4563: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4564: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4565: }
4566: $datatable .= '</td></tr>';
4567: }
4568: $datatable .= '</table>';
4569: }
4570: $datatable .= '</td></tr>'."\n";
4571: $rownum ++;
4572: }
1.340 raeburn 4573: unless (($position eq 'top') || ($position eq 'lower')) {
1.286 raeburn 4574: foreach my $type (@mailings) {
4575: $css_class = $rownum%2?' class="LC_odd_row"':'';
4576: $datatable .= '<tr'.$css_class.'>'.
4577: '<td><span class="LC_nobreak">'.
4578: $titles->{$type}.': </span></td>'.
4579: '<td class="LC_left_item">';
4580: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4581: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4582: }
4583: $datatable .= '<span class="LC_nobreak">';
4584: foreach my $item (@contacts) {
4585: $datatable .= '<label>'.
4586: '<input type="checkbox" name="'.$type.'"'.
4587: $checked{$type}{$item}.
4588: ' value="'.$item.'" />'.$short_titles->{$item}.
4589: '</label> ';
4590: }
4591: $datatable .= '</span><br />'.&mt('Others').': '.
4592: '<input type="text" name="'.$type.'_others" '.
4593: 'value="'.$otheremails{$type}.'" />';
4594: my %locchecked;
4595: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4596: foreach my $loc ('s','b') {
4597: if ($includeloc{$type} eq $loc) {
4598: $locchecked{$loc} = ' checked="checked"';
4599: last;
4600: }
4601: }
4602: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4603: '<input type="text" name="'.$type.'_bcc" '.
4604: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4605: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4606: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4607: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.286 raeburn 4608: '<span class="LC_nobreak">'.&mt('Location:').' '.
4609: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4610: (' 'x2).
4611: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4612: '</span></fieldset>';
4613: }
4614: $datatable .= '</td></tr>'."\n";
4615: $rownum ++;
4616: }
1.28 raeburn 4617: }
1.286 raeburn 4618: if ($position eq 'middle') {
4619: my %choices;
1.340 raeburn 4620: my $corelink = &core_link_msu();
4621: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.286 raeburn 4622: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.340 raeburn 4623: $corelink);
4624: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4625: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.286 raeburn 4626: my %defaultchecked = ('reporterrors' => 'on',
1.340 raeburn 4627: 'reportupdates' => 'on',
4628: 'reportstatus' => 'on');
1.286 raeburn 4629: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4630: \%choices,$rownum);
4631: $datatable .= $reports;
1.340 raeburn 4632: } elsif ($position eq 'lower') {
1.378 raeburn 4633: my (%current,%excluded,%weights);
1.340 raeburn 4634: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4635: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.378 raeburn 4636: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.340 raeburn 4637: } else {
1.378 raeburn 4638: $current{'errorthreshold'} = $defaults->{'threshold'};
1.340 raeburn 4639: }
4640: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.378 raeburn 4641: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.340 raeburn 4642: } else {
1.378 raeburn 4643: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.340 raeburn 4644: }
4645: if (ref($lonstatus{'weights'}) eq 'HASH') {
1.341 raeburn 4646: foreach my $type ('E','W','N','U') {
1.340 raeburn 4647: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4648: $weights{$type} = $lonstatus{'weights'}{$type};
4649: } else {
4650: $weights{$type} = $defaults->{$type};
4651: }
4652: }
4653: } else {
1.341 raeburn 4654: foreach my $type ('E','W','N','U') {
1.340 raeburn 4655: $weights{$type} = $defaults->{$type};
4656: }
4657: }
4658: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4659: if (@{$lonstatus{'excluded'}} > 0) {
4660: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4661: }
4662: }
1.425 raeburn 4663: foreach my $item ('errorthreshold','errorsysmail') {
1.378 raeburn 4664: $css_class = $rownum%2?' class="LC_odd_row"':'';
4665: $datatable .= '<tr'.$css_class.'>'.
4666: '<td class="LC_left_item"><span class="LC_nobreak">'.
4667: $titles->{$item}.
4668: '</span></td><td class="LC_left_item">'.
4669: '<input type="text" name="'.$item.'" value="'.
4670: $current{$item}.'" size="5" /></td></tr>';
4671: $rownum ++;
4672: }
1.340 raeburn 4673: $css_class = $rownum%2?' class="LC_odd_row"':'';
4674: $datatable .= '<tr'.$css_class.'>'.
4675: '<td class="LC_left_item">'.
4676: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4677: '</span></td><td class="LC_left_item"><table><tr>';
1.341 raeburn 4678: foreach my $type ('E','W','N','U') {
1.340 raeburn 4679: $datatable .= '<td>'.$names->{$type}.'<br />'.
4680: '<input type="text" name="errorweights_'.$type.'" value="'.
4681: $weights{$type}.'" size="5" /></td>';
4682: }
4683: $datatable .= '</tr></table></tr>';
4684: $rownum ++;
4685: $css_class = $rownum%2?' class="LC_odd_row"':'';
4686: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4687: $titles->{'errorexcluded'}.'</td>'.
4688: '<td class="LC_left_item"><table>';
4689: my $numinrow = 4;
4690: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4691: for (my $i=0; $i<@ids; $i++) {
4692: my $rem = $i%($numinrow);
4693: if ($rem == 0) {
4694: if ($i > 0) {
4695: $datatable .= '</tr>';
4696: }
4697: $datatable .= '<tr>';
4698: }
4699: my $check;
4700: if ($excluded{$ids[$i]}) {
4701: $check = ' checked="checked" ';
4702: }
4703: $datatable .= '<td class="LC_left_item">'.
4704: '<span class="LC_nobreak"><label>'.
4705: '<input type="checkbox" name="errorexcluded" '.
4706: 'value="'.$ids[$i].'"'.$check.' />'.
4707: $ids[$i].'</label></span></td>';
4708: }
4709: my $colsleft = $numinrow - @ids%($numinrow);
4710: if ($colsleft > 1 ) {
4711: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4712: ' </td>';
4713: } elsif ($colsleft == 1) {
4714: $datatable .= '<td class="LC_left_item"> </td>';
4715: }
4716: $datatable .= '</tr></table></td></tr>';
4717: $rownum ++;
1.286 raeburn 4718: } elsif ($position eq 'bottom') {
1.315 raeburn 4719: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4720: my (@posstypes,%usertypeshash);
4721: if (ref($types) eq 'ARRAY') {
4722: @posstypes = @{$types};
4723: }
4724: if (@posstypes) {
4725: if (ref($usertypes) eq 'HASH') {
4726: %usertypeshash = %{$usertypes};
4727: }
4728: my @overridden;
4729: my $numinrow = 4;
4730: if (ref($settings) eq 'HASH') {
4731: if (ref($settings->{'overrides'}) eq 'HASH') {
4732: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4733: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4734: push(@overridden,$key);
4735: foreach my $item (@contacts) {
4736: if ($settings->{'overrides'}{$key}{$item}) {
4737: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4738: }
4739: }
4740: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4741: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4742: $includeloc{'override_'.$key} = '';
4743: $includestr{'override_'.$key} = '';
4744: if ($settings->{'overrides'}{$key}{'include'} ne '') {
1.425 raeburn 4745: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
1.315 raeburn 4746: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4747: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4748: }
1.286 raeburn 4749: }
4750: }
4751: }
1.315 raeburn 4752: }
4753: my $customclass = 'LC_helpdesk_override';
4754: my $optionsprefix = 'LC_options_helpdesk_';
4755:
4756: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4757: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4758: $numinrow,$othertitle,'overrides',
4759: \$rownum,$onclicktypes,$customclass);
4760: $rownum ++;
4761: $usertypeshash{'default'} = $othertitle;
4762: foreach my $status (@posstypes) {
4763: my $css_class;
4764: if ($rownum%2) {
4765: $css_class = 'LC_odd_row ';
4766: }
4767: $css_class .= $customclass;
4768: my $rowid = $optionsprefix.$status;
4769: my $hidden = 1;
4770: my $currstyle = 'display:none';
4771: if (grep(/^\Q$status\E$/,@overridden)) {
4772: $currstyle = 'display:table-row';
4773: $hidden = 0;
4774: }
4775: my $key = 'override_'.$status;
4776: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4777: $includeloc{$key},$includestr{$key},$status,$rowid,
4778: $usertypeshash{$status},$css_class,$currstyle,
4779: \@contacts,$short_titles);
4780: unless ($hidden) {
4781: $rownum ++;
1.286 raeburn 4782: }
4783: }
1.134 raeburn 4784: }
1.28 raeburn 4785: }
1.30 raeburn 4786: $$rowtotal += $rownum;
1.28 raeburn 4787: return $datatable;
4788: }
4789:
1.340 raeburn 4790: sub core_link_msu {
4791: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4792: &mt('LON-CAPA core group - MSU'),600,500);
4793: }
4794:
1.315 raeburn 4795: sub overridden_helpdesk {
4796: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4797: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4798: my $class = 'LC_left_item';
4799: if ($css_class) {
4800: $css_class = ' class="'.$css_class.'"';
4801: }
4802: if ($rowid) {
4803: $rowid = ' id="'.$rowid.'"';
4804: }
4805: if ($rowstyle) {
4806: $rowstyle = ' style="'.$rowstyle.'"';
4807: }
4808: my ($output,$description);
4809: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4810: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4811: "<td>$description</td>\n".
4812: '<td class="'.$class.'" colspan="2">'.
4813: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4814: '<span class="LC_nobreak">';
4815: if (ref($contacts) eq 'ARRAY') {
4816: foreach my $item (@{$contacts}) {
4817: my $check;
4818: if (ref($checked) eq 'HASH') {
4819: $check = $checked->{$item};
4820: }
4821: my $title;
4822: if (ref($short_titles) eq 'HASH') {
1.425 raeburn 4823: $title = $short_titles->{$item};
1.315 raeburn 4824: }
4825: $output .= '<label>'.
4826: '<input type="checkbox" name="override_'.$type.'"'.$check.
4827: ' value="'.$item.'" />'.$title.'</label> ';
4828: }
4829: }
4830: $output .= '</span><br />'.&mt('Others').': '.
4831: '<input type="text" name="override_'.$type.'_others" '.
4832: 'value="'.$otheremails.'" />';
4833: my %locchecked;
4834: foreach my $loc ('s','b') {
4835: if ($includeloc eq $loc) {
4836: $locchecked{$loc} = ' checked="checked"';
4837: last;
4838: }
4839: }
4840: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4841: '<input type="text" name="override_'.$type.'_bcc" '.
4842: 'value="'.$bccemails.'" /></fieldset>'.
4843: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4844: &mt('Text automatically added to e-mail:').' '.
1.334 raeburn 4845: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
1.315 raeburn 4846: '<span class="LC_nobreak">'.&mt('Location:').' '.
4847: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4848: (' 'x2).
4849: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4850: '</span></fieldset>'.
4851: '</td></tr>'."\n";
4852: return $output;
4853: }
4854:
1.286 raeburn 4855: sub contacts_javascript {
4856: return <<"ENDSCRIPT";
4857:
4858: <script type="text/javascript">
4859: // <![CDATA[
4860:
4861: function screenshotSize(field) {
4862: if (document.getElementById('help_screenshotsize')) {
4863: if (field.value == 'no') {
1.289 raeburn 4864: document.getElementById('help_screenshotsize').style.display="none";
1.286 raeburn 4865: } else {
4866: document.getElementById('help_screenshotsize').style.display="";
4867: }
4868: }
4869: return;
4870: }
4871:
1.315 raeburn 4872: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4873: if (form.elements[checkbox].length != undefined) {
4874: var count = 0;
4875: if (docount) {
4876: for (var i=0; i<form.elements[checkbox].length; i++) {
4877: if (form.elements[checkbox][i].checked) {
4878: count ++;
4879: }
4880: }
4881: }
4882: for (var i=0; i<form.elements[checkbox].length; i++) {
4883: var type = form.elements[checkbox][i].value;
4884: if (document.getElementById(prefix+type)) {
4885: if (form.elements[checkbox][i].checked) {
4886: document.getElementById(prefix+type).style.display = 'table-row';
4887: if (count % 2 == 1) {
4888: document.getElementById(prefix+type).className = target+' LC_odd_row';
4889: } else {
4890: document.getElementById(prefix+type).className = target;
4891: }
4892: count ++;
4893: } else {
4894: document.getElementById(prefix+type).style.display = 'none';
4895: }
4896: }
4897: }
4898: }
4899: return;
4900: }
4901:
1.286 raeburn 4902: // ]]>
4903: </script>
4904:
4905: ENDSCRIPT
4906: }
4907:
1.118 jms 4908: sub print_helpsettings {
1.282 raeburn 4909: my ($position,$dom,$settings,$rowtotal) = @_;
4910: my $confname = $dom.'-domainconfig';
1.285 raeburn 4911: my $formname = 'display';
1.168 raeburn 4912: my ($datatable,$itemcount);
1.282 raeburn 4913: if ($position eq 'top') {
4914: $itemcount = 1;
4915: my (%choices,%defaultchecked,@toggles);
4916: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4917: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4918: &mt('LON-CAPA bug tracker'),600,500));
4919: %defaultchecked = ('submitbugs' => 'on');
4920: @toggles = ('submitbugs');
4921: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4922: \%choices,$itemcount);
4923: $$rowtotal ++;
4924: } else {
4925: my $css_class;
4926: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 4927: my (%customroles,%ordered,%current);
1.301 raeburn 4928: if (ref($settings) eq 'HASH') {
4929: if (ref($settings->{'adhoc'}) eq 'HASH') {
4930: %current = %{$settings->{'adhoc'}};
4931: }
1.285 raeburn 4932: }
4933: my $count = 0;
4934: foreach my $key (sort(keys(%existing))) {
1.282 raeburn 4935: if ($key=~/^rolesdef\_(\w+)$/) {
4936: my $rolename = $1;
1.285 raeburn 4937: my (%privs,$order);
1.282 raeburn 4938: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4939: $customroles{$rolename} = \%privs;
1.285 raeburn 4940: if (ref($current{$rolename}) eq 'HASH') {
4941: $order = $current{$rolename}{'order'};
4942: }
4943: if ($order eq '') {
4944: $order = $count;
4945: }
4946: $ordered{$order} = $rolename;
4947: $count++;
4948: }
4949: }
4950: my $maxnum = scalar(keys(%ordered));
4951: my @roles_by_num = ();
4952: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4953: push(@roles_by_num,$item);
4954: }
4955: my $context = 'domprefs';
4956: my $crstype = 'Course';
4957: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 4958: my @accesstypes = ('all','dh','da','none');
1.285 raeburn 4959: my ($numstatustypes,@jsarray);
4960: if (ref($types) eq 'ARRAY') {
4961: if (@{$types} > 0) {
4962: $numstatustypes = scalar(@{$types});
4963: push(@accesstypes,'status');
4964: @jsarray = ('bystatus');
1.282 raeburn 4965: }
4966: }
1.290 raeburn 4967: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 4968: if (keys(%domhelpdesk)) {
4969: push(@accesstypes,('inc','exc'));
4970: push(@jsarray,('notinc','notexc'));
4971: }
4972: my $hiddenstr = join("','",@jsarray);
1.282 raeburn 4973: my $context = 'domprefs';
4974: my $crstype = 'Course';
1.285 raeburn 4975: my $prefix = 'helproles_';
4976: my $add_class = 'LC_hidden';
4977: foreach my $num (@roles_by_num) {
4978: my $role = $ordered{$num};
4979: my ($desc,$access,@statuses);
4980: if (ref($current{$role}) eq 'HASH') {
4981: $desc = $current{$role}{'desc'};
4982: $access = $current{$role}{'access'};
4983: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4984: @statuses = @{$current{$role}{'insttypes'}};
4985: }
4986: }
4987: if ($desc eq '') {
4988: $desc = $role;
4989: }
4990: my $identifier = 'custhelp'.$num;
1.282 raeburn 4991: my %full=();
4992: my %levels= (
4993: course => {},
4994: domain => {},
4995: system => {},
4996: );
4997: my %levelscurrent=(
4998: course => {},
4999: domain => {},
5000: system => {},
5001: );
5002: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
5003: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
5004: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.285 raeburn 5005: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
1.306 raeburn 5006: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><b>'.$role.'</b><br />'.
1.285 raeburn 5007: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
5008: for (my $k=0; $k<=$maxnum; $k++) {
5009: my $vpos = $k+1;
5010: my $selstr;
5011: if ($k == $num) {
5012: $selstr = ' selected="selected" ';
5013: }
5014: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5015: }
5016: $datatable .= '</select>'.(' 'x2).
5017: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
5018: '</td>'.
5019: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5020: &mt('Name shown to users:').
5021: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
5022: '</fieldset>'.
5023: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
5024: $othertitle,$usertypes,$types,\%domhelpdesk).
5025: '<fieldset>'.
5026: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.282 raeburn 5027: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.285 raeburn 5028: \%levelscurrent,$identifier,
5029: 'LC_hidden',$prefix.$num.'_privs').
5030: '</fieldset></td>';
1.282 raeburn 5031: $itemcount ++;
5032: }
5033: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5034: my $newcust = 'custhelp'.$count;
5035: my (%privs,%levelscurrent);
5036: my %full=();
5037: my %levels= (
5038: course => {},
5039: domain => {},
5040: system => {},
5041: );
5042: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
5043: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.285 raeburn 5044: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
1.306 raeburn 5045: $datatable .= '<tr '.$css_class.'><td style="vertical-align: top"><span class="LC_nobreak"><label>'.
1.285 raeburn 5046: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
5047: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
5048: for (my $k=0; $k<$maxnum+1; $k++) {
5049: my $vpos = $k+1;
5050: my $selstr;
5051: if ($k == $maxnum) {
5052: $selstr = ' selected="selected" ';
5053: }
5054: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5055: }
5056: $datatable .= '</select> '."\n".
1.282 raeburn 5057: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
5058: '</label></span></td>'.
1.285 raeburn 5059: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
5060: '<span class="LC_nobreak">'.
5061: &mt('Internal name:').
5062: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
5063: '</span>'.(' 'x4).
5064: '<span class="LC_nobreak">'.
5065: &mt('Name shown to users:').
5066: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
5067: '</span></fieldset>'.
5068: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
5069: $usertypes,$types,\%domhelpdesk).
5070: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.282 raeburn 5071: &Apache::lonuserutils::custom_role_header($context,$crstype,
5072: \@templateroles,$newcust).
5073: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
5074: \%levelscurrent,$newcust).
1.334 raeburn 5075: '</fieldset>'.
5076: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
5077: '</td></tr>';
1.282 raeburn 5078: $count ++;
5079: $$rowtotal += $count;
5080: }
1.166 raeburn 5081: return $datatable;
1.121 raeburn 5082: }
5083:
1.285 raeburn 5084: sub adhocbutton {
5085: my ($prefix,$num,$field,$visibility) = @_;
5086: my %lt = &Apache::lonlocal::texthash(
5087: show => 'Show details',
5088: hide => 'Hide details',
5089: );
5090: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
5091: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
5092: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
5093: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
5094: }
5095:
5096: sub helpsettings_javascript {
5097: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
5098: return unless(ref($roles_by_num) eq 'ARRAY');
5099: my %html_js_lt = &Apache::lonlocal::texthash(
5100: show => 'Show details',
5101: hide => 'Hide details',
5102: );
5103: &html_escape(\%html_js_lt);
5104: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
5105: return <<"ENDSCRIPT";
5106: <script type="text/javascript">
5107: // <![CDATA[
5108:
5109: function reorderHelpRoles(form,item) {
5110: var changedVal;
5111: $jstext
5112: var newpos = 'helproles_${total}_pos';
5113: var maxh = 1 + $total;
5114: var current = new Array();
5115: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
5116: if (item == newpos) {
5117: changedVal = newitemVal;
5118: } else {
5119: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
5120: current[newitemVal] = newpos;
5121: }
5122: for (var i=0; i<helproles.length; i++) {
5123: var elementName = 'helproles_'+helproles[i]+'_pos';
5124: if (elementName != item) {
5125: if (form.elements[elementName]) {
5126: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
5127: current[currVal] = elementName;
5128: }
5129: }
5130: }
5131: var oldVal;
5132: for (var j=0; j<maxh; j++) {
5133: if (current[j] == undefined) {
5134: oldVal = j;
5135: }
5136: }
5137: if (oldVal < changedVal) {
5138: for (var k=oldVal+1; k<=changedVal ; k++) {
5139: var elementName = current[k];
5140: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
5141: }
5142: } else {
5143: for (var k=changedVal; k<oldVal; k++) {
5144: var elementName = current[k];
5145: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
5146: }
5147: }
5148: return;
5149: }
5150:
5151: function helpdeskAccess(num) {
5152: var curraccess = null;
5153: if (document.$formname.elements['helproles_'+num+'_access'].length) {
5154: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
5155: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
5156: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
5157: }
5158: }
5159: }
5160: var shown = Array();
5161: var hidden = Array();
5162: if (curraccess == 'none') {
5163: hidden = Array('$hiddenstr');
5164: } else {
5165: if (curraccess == 'status') {
5166: shown = Array('bystatus');
5167: hidden = Array('notinc','notexc');
5168: } else {
5169: if (curraccess == 'exc') {
5170: shown = Array('notexc');
5171: hidden = Array('notinc','bystatus');
5172: }
5173: if (curraccess == 'inc') {
5174: shown = Array('notinc');
5175: hidden = Array('notexc','bystatus');
5176: }
1.293 raeburn 5177: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.285 raeburn 5178: hidden = Array('notinc','notexc','bystatus');
5179: }
5180: }
5181: }
5182: if (hidden.length > 0) {
5183: for (var i=0; i<hidden.length; i++) {
5184: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
5185: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
5186: }
5187: }
5188: }
5189: if (shown.length > 0) {
5190: for (var i=0; i<shown.length; i++) {
5191: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
5192: if (shown[i] == 'privs') {
5193: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
5194: } else {
5195: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
5196: }
5197: }
5198: }
5199: }
5200: return;
5201: }
5202:
5203: function toggleHelpdeskItem(num,field) {
5204: if (document.getElementById('helproles_'+num+'_'+field)) {
5205: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
1.289 raeburn 5206: document.getElementById('helproles_'+num+'_'+field).className =
1.285 raeburn 5207: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
5208: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5209: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
5210: }
5211: } else {
5212: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
5213: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
5214: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
5215: }
5216: }
5217: }
5218: return;
5219: }
5220:
5221: // ]]>
5222: </script>
5223:
5224: ENDSCRIPT
5225: }
5226:
5227: sub helpdeskroles_access {
5228: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5229: $usertypes,$types,$domhelpdesk) = @_;
5230: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5231: my %lt = &Apache::lonlocal::texthash(
5232: 'rou' => 'Role usage',
5233: 'whi' => 'Which helpdesk personnel may use this role?',
1.292 raeburn 5234: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5235: 'dh' => 'All with domain helpdesk role',
5236: 'da' => 'All with domain helpdesk assistant role',
1.285 raeburn 5237: 'none' => 'None',
5238: 'status' => 'Determined based on institutional status',
5239: 'inc' => 'Include all, but exclude specific personnel',
5240: 'exc' => 'Exclude all, but include specific personnel',
5241: );
5242: my %usecheck = (
5243: all => ' checked="checked"',
5244: );
5245: my %displaydiv = (
5246: status => 'none',
5247: inc => 'none',
5248: exc => 'none',
5249: priv => 'block',
5250: );
5251: my $output;
5252: if (ref($current) eq 'HASH') {
5253: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5254: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5255: $usecheck{$current->{access}} = $usecheck{'all'};
5256: delete($usecheck{'all'});
5257: if ($current->{access} =~ /^(status|inc|exc)$/) {
5258: my $access = $1;
5259: $displaydiv{$access} = 'inline';
5260: } elsif ($current->{access} eq 'none') {
5261: $displaydiv{'priv'} = 'none';
5262: }
5263: }
5264: }
5265: }
5266: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5267: '<p>'.$lt{'whi'}.'</p>';
5268: foreach my $access (@{$accesstypes}) {
5269: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5270: ' onclick="helpdeskAccess('."'$num'".');" />'.
5271: $lt{$access}.'</label>';
5272: if ($access eq 'status') {
5273: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5274: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5275: $othertitle,$usertypes,$types).
5276: '</div>';
5277: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5278: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5279: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5280: '</div>';
5281: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5282: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5283: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5284: '</div>';
5285: }
5286: $output .= '</p>';
5287: }
5288: $output .= '</fieldset>';
5289: return $output;
5290: }
5291:
1.121 raeburn 5292: sub radiobutton_prefs {
1.192 raeburn 5293: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.385 raeburn 5294: $additional,$align,$firstval) = @_;
1.121 raeburn 5295: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5296: (ref($choices) eq 'HASH'));
5297:
1.170 raeburn 5298: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 5299:
5300: foreach my $item (@{$toggles}) {
5301: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5302: $checkedon{$item} = ' checked="checked" ';
5303: $checkedoff{$item} = ' ';
1.121 raeburn 5304: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5305: $checkedoff{$item} = ' checked="checked" ';
5306: $checkedon{$item} = ' ';
5307: }
5308: }
5309: if (ref($settings) eq 'HASH') {
1.121 raeburn 5310: foreach my $item (@{$toggles}) {
1.118 jms 5311: if ($settings->{$item} eq '1') {
5312: $checkedon{$item} = ' checked="checked" ';
5313: $checkedoff{$item} = ' ';
5314: } elsif ($settings->{$item} eq '0') {
5315: $checkedoff{$item} = ' checked="checked" ';
5316: $checkedon{$item} = ' ';
5317: }
5318: }
1.121 raeburn 5319: }
1.192 raeburn 5320: if ($onclick) {
5321: $onclick = ' onclick="'.$onclick.'"';
5322: }
1.121 raeburn 5323: foreach my $item (@{$toggles}) {
1.118 jms 5324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5325: $datatable .=
1.306 raeburn 5326: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.192 raeburn 5327: '<span class="LC_nobreak">'.$choices->{$item}.
1.257 raeburn 5328: '</span></td>';
5329: if ($align eq 'left') {
5330: $datatable .= '<td class="LC_left_item">';
5331: } else {
5332: $datatable .= '<td class="LC_right_item">';
5333: }
1.385 raeburn 5334: $datatable .= '<span class="LC_nobreak">';
5335: if ($firstval eq 'no') {
5336: $datatable .=
5337: '<label><input type="radio" name="'.
5338: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5339: '</label> <label><input type="radio" name="'.$item.'" '.
5340: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5341: } else {
5342: $datatable .=
5343: '<label><input type="radio" name="'.
5344: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5345: '</label> <label><input type="radio" name="'.$item.'" '.
5346: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
5347: }
5348: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5349: $itemcount ++;
1.121 raeburn 5350: }
5351: return ($datatable,$itemcount);
5352: }
5353:
1.267 raeburn 5354: sub print_ltitools {
1.421 raeburn 5355: my ($position,$dom,$settings,$rowtotal) = @_;
5356: my (%rules,%encrypt,%privkeys,%linkprot);
1.267 raeburn 5357: if (ref($settings) eq 'HASH') {
1.421 raeburn 5358: if ($position eq 'top') {
5359: if (exists($settings->{'encrypt'})) {
5360: if (ref($settings->{'encrypt'}) eq 'HASH') {
5361: foreach my $key (keys(%{$settings->{'encrypt'}})) {
5362: $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1.324 raeburn 5363: }
5364: }
1.267 raeburn 5365: }
1.421 raeburn 5366: if (exists($settings->{'private'})) {
5367: if (ref($settings->{'private'}) eq 'HASH') {
5368: if (ref($settings->{'private'}) eq 'HASH') {
5369: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5370: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1.267 raeburn 5371: }
5372: }
5373: }
5374: }
1.421 raeburn 5375: } elsif ($position eq 'middle') {
5376: if (exists($settings->{'rules'})) {
5377: if (ref($settings->{'rules'}) eq 'HASH') {
5378: %rules = %{$settings->{'rules'}};
1.273 raeburn 5379: }
5380: }
1.421 raeburn 5381: } else {
5382: foreach my $key ('encrypt','private','rules') {
5383: if (exists($settings->{$key})) {
5384: delete($settings->{$key});
1.267 raeburn 5385: }
5386: }
5387: }
5388: }
1.421 raeburn 5389: my $datatable;
5390: my $itemcount = 1;
5391: if ($position eq 'top') {
5392: $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5393: } elsif ($position eq 'middle') {
5394: $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5395: $$rowtotal += $itemcount;
5396: } else {
5397: $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1.267 raeburn 5398: }
5399: return $datatable;
5400: }
5401:
5402: sub ltitools_names {
5403: my %lt = &Apache::lonlocal::texthash(
1.296 raeburn 5404: 'title' => 'Title',
5405: 'version' => 'Version',
5406: 'msgtype' => 'Message Type',
1.323 raeburn 5407: 'sigmethod' => 'Signature Method',
1.296 raeburn 5408: 'url' => 'URL',
5409: 'key' => 'Key',
1.322 raeburn 5410: 'lifetime' => 'Nonce lifetime (s)',
1.296 raeburn 5411: 'secret' => 'Secret',
1.425 raeburn 5412: 'icon' => 'Icon',
1.324 raeburn 5413: 'user' => 'User',
1.296 raeburn 5414: 'fullname' => 'Full Name',
5415: 'firstname' => 'First Name',
5416: 'lastname' => 'Last Name',
5417: 'email' => 'E-mail',
5418: 'roles' => 'Role',
1.298 raeburn 5419: 'window' => 'Window',
5420: 'tab' => 'Tab',
1.296 raeburn 5421: 'iframe' => 'iFrame',
5422: 'height' => 'Height',
5423: 'width' => 'Width',
5424: 'linktext' => 'Default Link Text',
5425: 'explanation' => 'Default Explanation',
5426: 'passback' => 'Tool can return grades:',
5427: 'roster' => 'Tool can retrieve roster:',
5428: 'crstarget' => 'Display target',
5429: 'crslabel' => 'Course label',
1.425 raeburn 5430: 'crstitle' => 'Course title',
1.296 raeburn 5431: 'crslinktext' => 'Link Text',
5432: 'crsexplanation' => 'Explanation',
1.318 raeburn 5433: 'crsappend' => 'Provider URL',
1.267 raeburn 5434: );
5435: return %lt;
5436: }
5437:
1.421 raeburn 5438: sub secrets_form {
5439: my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5440: my @ids=&Apache::lonnet::current_machine_ids();
5441: my %servers = &Apache::lonnet::get_servers($dom,'library');
5442: my $primary = &Apache::lonnet::domain($dom,'primary');
5443: my ($css_class,$extra,$numshown,$itemcount,$output);
5444: $itemcount = 0;
5445: foreach my $hostid (sort(keys(%servers))) {
5446: my ($showextra,$divsty,$switch);
5447: if ($hostid eq $primary) {
5448: if ($context eq 'ltisec') {
5449: if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5450: $showextra = 1;
5451: }
5452: if ($encrypt->{'ltisec_crslinkprot'}) {
5453: $showextra = 1;
5454: }
5455: } else {
5456: if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5457: $showextra = 1;
5458: }
5459: }
5460: unless (grep(/^\Q$hostid\E$/,@ids)) {
5461: $switch = 1;
5462: }
5463: if ($showextra) {
5464: $numshown ++;
5465: $divsty = 'display:inline-block';
5466: } else {
5467: $divsty = 'display:none';
5468: }
5469: $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5470: '<legend>'.$hostid.'</legend>';
5471: if ($switch) {
5472: my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5473: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5474: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5475: if (exists($privkeys->{$hostid})) {
5476: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5477: '<span class="LC_nobreak">'.
5478: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5479: '<span class="LC_nobreak">'.&mt('Change?').
5480: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5481: (' 'x2).
5482: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5483: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5484: '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5485: '</span></div>';
5486: } else {
5487: $extra .= '<span class="LC_nobreak">'.
5488: &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5489: '</span>'."\n";
5490: }
5491: } elsif (exists($privkeys->{$hostid})) {
5492: $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5493: &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5494: '<span class="LC_nobreak">'.&mt('Change?').
5495: '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5496: (' 'x2).
5497: '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5498: '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5499: '<span class="LC_nobreak">'.&mt('New Key').':'.
5500: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5501: '<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>'.
5502: '</span></div>';
5503: } else {
5504: $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5505: '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5506: '<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>';
5507: }
5508: $extra .= '</fieldset>';
5509: }
5510: }
5511: my (%choices,@toggles,%defaultchecked);
5512: if ($context eq 'ltisec') {
5513: %choices = &Apache::lonlocal::texthash (
5514: ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5515: ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5516: ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5517: );
5518: @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5519: %defaultchecked = (
5520: 'ltisec_crslinkprot' => 'off',
5521: 'ltisec_domlinkprot' => 'off',
5522: 'ltisec_consumers' => 'off',
5523: );
5524: } else {
5525: %choices = &Apache::lonlocal::texthash (
5526: toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5527: toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5528: );
5529: @toggles = qw(toolsec_crs toolsec_dom);
5530: %defaultchecked = (
5531: 'toolsec_crs' => 'off',
5532: 'toolsec_dom' => 'off',
5533: );
5534: }
5535: my ($onclick,$itemcount);
5536: $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5537: ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5538: \%choices,$itemcount,$onclick,'','left','no');
5539:
5540: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5541: my $noprivkeysty = 'display:inline-block';
5542: if ($numshown) {
5543: $noprivkeysty = 'display:none';
5544: }
5545: $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5546: '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5547: '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5548: $extra.
5549: '</td></tr>';
5550: $itemcount ++;
5551: $$rowtotal += $itemcount;
5552: return $output;
5553: }
5554:
1.372 raeburn 5555: sub print_proctoring {
5556: my ($dom,$settings,$rowtotal) = @_;
5557: my $itemcount = 1;
5558: my (%ordered,%providernames,%current,%currentdef);
5559: my $confname = $dom.'-domainconfig';
5560: my $switchserver = &check_switchserver($dom,$confname);
5561: if (ref($settings) eq 'HASH') {
5562: foreach my $item (keys(%{$settings})) {
5563: if (ref($settings->{$item}) eq 'HASH') {
5564: my $num = $settings->{$item}{'order'};
5565: $ordered{$num} = $item;
5566: }
5567: }
5568: } else {
5569: %ordered = (
5570: 1 => 'proctorio',
5571: 2 => 'examity',
5572: );
5573: }
5574: %providernames = &proctoring_providernames();
5575: my $maxnum = scalar(keys(%ordered));
5576: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
5577: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
5578: if (ref($requref) eq 'HASH') {
5579: %requserfields = %{$requref};
5580: }
5581: if (ref($opturef) eq 'HASH') {
5582: %optuserfields = %{$opturef};
5583: }
5584: if (ref($defref) eq 'HASH') {
5585: %defaults = %{$defref};
5586: }
5587: if (ref($extref) eq 'HASH') {
5588: %extended = %{$extref};
5589: }
5590: if (ref($crsref) eq 'HASH') {
5591: %crsconf = %{$crsref};
5592: }
5593: if (ref($rolesref) eq 'ARRAY') {
5594: @courseroles = @{$rolesref};
5595: }
5596: if (ref($ltiref) eq 'ARRAY') {
5597: @ltiroles = @{$ltiref};
5598: }
5599: my $datatable;
5600: my $css_class;
5601: if (keys(%ordered)) {
5602: my @items = sort { $a <=> $b } keys(%ordered);
5603: for (my $i=0; $i<@items; $i++) {
5604: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5605: my $provider = $ordered{$items[$i]};
5606: my $optionsty = 'none';
5607: my ($available,$version,$lifetime,$imgsrc,$userincdom,$showroles,
5608: %checkedfields,%rolemaps,%inuse,%crsconfig,%current);
5609: if (ref($settings) eq 'HASH') {
5610: if (ref($settings->{$provider}) eq 'HASH') {
5611: %current = %{$settings->{$provider}};
5612: if ($current{'available'}) {
5613: $optionsty = 'block';
5614: $available = 1;
5615: }
5616: if ($current{'lifetime'} =~ /^\d+$/) {
5617: $lifetime = $current{'lifetime'};
5618: }
5619: if ($current{'version'} =~ /^\d+\.\d+$/) {
5620: $version = $current{'version'};
5621: }
5622: if ($current{'image'} ne '') {
5623: $imgsrc = '<img src="'.$current{'image'}.'" alt="'.&mt('Proctoring service icon').'" />';
5624: }
5625: if (ref($current{'fields'}) eq 'ARRAY') {
5626: map { $checkedfields{$_} = 1; } @{$current{'fields'}};
5627: }
5628: $userincdom = $current{'incdom'};
5629: if (ref($current{'roles'}) eq 'HASH') {
5630: %rolemaps = %{$current{'roles'}};
5631: $checkedfields{'roles'} = 1;
5632: }
5633: if (ref($current{'defaults'}) eq 'ARRAY') {
5634: foreach my $val (@{$current{'defaults'}}) {
5635: if (grep(/^\Q$val\E$/,@{$defaults{$provider}})) {
5636: $inuse{$val} = 1;
5637: } else {
5638: foreach my $poss (keys(%{$extended{$provider}})) {
5639: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5640: if (grep(/^\Q$val\E$/,@{$extended{$provider}{$poss}})) {
5641: $inuse{$poss} = $val;
5642: last;
5643: }
5644: }
5645: }
5646: }
5647: }
5648: } elsif (ref($current{'defaults'}) eq 'HASH') {
5649: foreach my $key (keys(%{$current{'defaults'}})) {
5650: my $currval = $current{'defaults'}{$key};
5651: if (grep(/^\Q$key\E$/,@{$defaults{$provider}})) {
5652: $inuse{$key} = 1;
5653: } else {
5654: my $match;
5655: foreach my $poss (keys(%{$extended{$provider}})) {
5656: if (ref($extended{$provider}{$poss}) eq 'ARRAY') {
5657: if (grep(/^\Q$key\E$/,@{$extended{$provider}{$poss}})) {
5658: $inuse{$poss} = $key;
5659: last;
5660: }
5661: } elsif (ref($extended{$provider}{$poss}) eq 'HASH') {
5662: foreach my $inner (sort(keys(%{$extended{$provider}{$poss}}))) {
5663: if (ref($extended{$provider}{$poss}{$inner}) eq 'ARRAY') {
5664: if (grep(/^\Q$currval\E$/,@{$extended{$provider}{$poss}{$inner}})) {
5665: $currentdef{$inner} = $currval;
5666: $match = 1;
5667: last;
5668: }
5669: } elsif ($inner eq $key) {
5670: $currentdef{$key} = $currval;
5671: $match = 1;
5672: last;
5673: }
5674: }
5675: }
5676: last if ($match);
5677: }
5678: }
5679: }
5680: }
5681: if (ref($current{'crsconf'}) eq 'ARRAY') {
5682: map { $crsconfig{$_} = 1; } @{$current{'crsconf'}};
5683: }
5684: }
5685: }
5686: my %lt = &proctoring_titles($provider);
5687: my %fieldtitles = &proctoring_fieldtitles($provider);
5688: my $onclickavailable = ' onclick="toggleProctoring(this.form,'."'$provider'".');"';
5689: my %checkedavailable = (
5690: yes => '',
5691: no => ' checked="checked"',
5692: );
5693: if ($available) {
5694: $checkedavailable{'yes'} = $checkedavailable{'no'};
5695: $checkedavailable{'no'} = '';
5696: }
5697: my $chgstr = ' onchange="javascript:reorderProctoring(this.form,'."'proctoring_pos_".$provider."'".');"';
5698: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5699: .'<select name="proctoring_pos_'.$provider.'"'.$chgstr.'>';
5700: for (my $k=0; $k<$maxnum; $k++) {
5701: my $vpos = $k+1;
5702: my $selstr;
5703: if ($k == $i) {
5704: $selstr = ' selected="selected" ';
5705: }
5706: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5707: }
5708: if ($version eq '') {
5709: if ($provider eq 'proctorio') {
5710: $version = '1.0';
5711: } elsif ($provider eq 'examity') {
5712: $version = '1.1';
5713: }
5714: }
5715: if ($lifetime eq '') {
5716: $lifetime = '300';
5717: }
5718: $datatable .=
5719: '</select>'.(' 'x2).'<b>'.$providernames{$provider}.'</b></span><br />'.
5720: '<span class="LC_nobreak">'.$lt{'avai'}.' '.
5721: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="1"'.$onclickavailable.$checkedavailable{yes}.' />'.&mt('Yes').'</label> '."\n".
5722: '<label><input type="radio" name="proctoring_available_'.$provider.'" value="0"'.$onclickavailable.$checkedavailable{no}.' />'.&mt('No').'</label></span>'."\n".
5723: '</td>'.
5724: '<td colspan="2">'.
5725: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'base'}.'</legend>'.
5726: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="proctoring_'.$provider.'_version">'.
5727: '<option value="'.$version.'" selected="selected">'.$version.'</option></select></span> '."\n".
5728: (' 'x2).
5729: '<span class="LC_nobreak">'.$lt{'sigmethod'}.':<select name="proctoring_'.$provider.'_sigmethod">'.
5730: '<option value="HMAC-SHA1" selected="selected">HMAC-SHA1</option>'.
5731: '<option value="HMAC-SHA256">HMAC-SHA256</option></select></span>'.
5732: (' 'x2).
5733: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="5" name="proctoring_'.$provider.'_lifetime" value="'.$lifetime.'" /></span> '."\n".
5734: '<br />'.
5735: '<span class="LC_nobreak">'.$lt{'url'}.':<input type="text" size="40" name="proctoring_'.$provider.'_url" value="'.$current{'url'}.'" /></span> '."\n".
5736: '<br />'.
5737: '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="proctoring_'.$provider.'_key" value="'.$current{'key'}.'" /></span> '."\n".
5738: (' 'x2).
5739: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="proctoring_'.$provider.'_secret" value="'.$current{'secret'}.'" />'.
5740: '<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";
5741: $datatable .= '<span class="LC_nobreak">'.$lt{'icon'}.': ';
5742: if ($imgsrc) {
5743: $datatable .= $imgsrc.
5744: '<label><input type="checkbox" name="proctoring_image_del"'.
5745: ' value="'.$provider.'" />'.&mt('Delete?').'</label></span> '.
5746: '<span class="LC_nobreak"> '.&mt('Replace:');
5747: }
5748: $datatable .= ' ';
5749: if ($switchserver) {
5750: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
5751: } else {
5752: $datatable .= '<input type="file" name="proctoring_image_'.$provider.'" value="" />';
5753: }
5754: unless ($imgsrc) {
5755: $datatable .= '<br />('.&mt('if larger than 21x21 pixels, image will be scaled').')';
5756: }
5757: $datatable .= '</fieldset>'."\n";
5758: if (ref($requserfields{$provider}) eq 'ARRAY') {
5759: if (@{$requserfields{$provider}} > 0) {
5760: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'requ'}.'</legend>';
5761: foreach my $field (@{$requserfields{$provider}}) {
5762: $datatable .= '<span class="LC_nobreak">'.
5763: '<label><input type="checkbox" name="proctoring_reqd_'.$provider.'" value="'.$field.'" checked="checked" disabled="disabled" />'.
5764: $lt{$field}.'</label>';
5765: if ($field eq 'user') {
5766: my $seluserdom = '';
5767: my $unseluserdom = ' selected="selected"';
5768: if ($userincdom) {
5769: $seluserdom = $unseluserdom;
5770: $unseluserdom = '';
5771: }
5772: $datatable .= ': '.
5773: '<select name="proctoring_userincdom_'.$provider.'">'.
5774: '<option value="0"'.$unseluserdom.'>'.$lt{'username'}.'</option>'.
5775: '<option value="1"'.$seluserdom.'>'.$lt{'uname:dom'}.'</option>'.
5776: '</select> ';
5777: } else {
5778: $datatable .= ' ';
5779: if ($field eq 'roles') {
5780: $showroles = 1;
5781: }
5782: }
5783: $datatable .= '</span> ';
5784: }
5785: }
5786: $datatable .= '</fieldset>'."\n";
5787: }
5788: if (ref($optuserfields{$provider}) eq 'ARRAY') {
5789: if (@{$optuserfields{$provider}} > 0) {
5790: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'optu'}.'</legend>';
5791: foreach my $field (@{$optuserfields{$provider}}) {
5792: my $checked;
5793: if ($checkedfields{$field}) {
5794: $checked = ' checked="checked"';
5795: }
5796: $datatable .= '<span class="LC_nobreak">'.
5797: '<label><input type="checkbox" name="proctoring_optional_'.$provider.'" value="'.$field.'"'.$checked.' />'.$lt{$field}.'</label></span> ';
5798: }
5799: $datatable .= '</fieldset>'."\n";
5800: }
5801: }
5802: if (ref($defaults{$provider}) eq 'ARRAY') {
5803: if (@{$defaults{$provider}}) {
5804: my (%options,@selectboxes);
5805: if (ref($extended{$provider}) eq 'HASH') {
5806: %options = %{$extended{$provider}};
5807: }
5808: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'"><legend>'.$lt{'defa'}.'</legend>';
5809: my ($rem,$numinrow,$dropdowns);
5810: if ($provider eq 'proctorio') {
5811: $datatable .= '<table>';
5812: $numinrow = 4;
5813: }
5814: my $i = 0;
5815: foreach my $field (@{$defaults{$provider}}) {
5816: my $checked;
5817: if ($inuse{$field}) {
5818: $checked = ' checked="checked"';
5819: }
5820: if ($provider eq 'examity') {
5821: if ($field eq 'display') {
5822: $datatable .= '<span class="LC_nobreak">'.&mt('Display target:');
5823: foreach my $option ('iframe','tab','window') {
5824: my $checkdisp;
5825: if ($currentdef{'target'} eq $option) {
5826: $checkdisp = ' checked="checked"';
5827: }
5828: $datatable .= '<label><input type="radio" name="proctoring_target_'.$provider.'" value="'.$option.'"'.$checkdisp.' />'.
5829: $fieldtitles{$option}.'</label>'.(' 'x2);
5830: }
5831: $datatable .= (' 'x4);
5832: foreach my $dimen ('width','height') {
5833: $datatable .= '<label>'.$fieldtitles{$dimen}.' '.
5834: '<input type="text" name="proctoring_'.$dimen.'_'.$provider.'" size="5" '.
5835: 'value="'.$currentdef{$dimen}.'" /></label>'.
5836: (' 'x2);
5837: }
5838: $datatable .= '</span><br />'.
5839: '<div class="LC_left_float">'.$fieldtitles{'linktext'}.'<br />'.
5840: '<input type="text" name="proctoring_linktext_'.$provider.'" '.
5841: 'size="25" value="'.$currentdef{'linktext'}.'" /></div>'.
5842: '<div class="LC_left_float">'.$fieldtitles{'explanation'}.'<br />'.
5843: '<textarea name="proctoring_explanation_'.$provider.'" rows="5" cols="40">'.
5844: $currentdef{'explanation'}.
5845: '</textarea></div><div style=""></div><br />';
5846: }
5847: } else {
5848: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
5849: my ($output,$selnone);
5850: unless ($checked) {
5851: $selnone = ' selected="selected"';
5852: }
5853: $output .= '<span class="LC_nobreak">'.$fieldtitles{$field}.': '.
5854: '<select name="proctoring_defaults_'.$field.'_'.$provider.'">'.
5855: '<option value=""'.$selnone.'>'.&mt('Not in use').'</option>';
5856: foreach my $option (@{$options{$field}}) {
5857: my $sel;
5858: if ($inuse{$field} eq $option) {
5859: $sel = ' selected="selected"';
5860: }
5861: $output .= '<option value="'.$option.'"'.$sel.'>'.$fieldtitles{$option}.'</option>';
5862: }
5863: $output .= '</select></span>';
5864: push(@selectboxes,$output);
5865: } else {
5866: $rem = $i%($numinrow);
5867: if ($rem == 0) {
5868: if ($i > 0) {
5869: $datatable .= '</tr>';
5870: }
5871: $datatable .= '<tr>';
5872: }
5873: $datatable .= '<td class="LC_left_item">'.
5874: '<span class="LC_nobreak">'.
5875: '<label><input type="checkbox" name="proctoring_defaults_'.$provider.'" value="'.$field.'"'.$checked.' />'.
5876: $fieldtitles{$field}.'</label></span></td>';
5877: $i++;
5878: }
5879: }
5880: }
5881: if ($provider eq 'proctorio') {
5882: if ($numinrow) {
5883: $rem = $i%$numinrow;
5884: }
5885: my $colsleft = $numinrow - $rem;
5886: if ($colsleft > 1) {
5887: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5888: } else {
5889: $datatable .= '<td class="LC_left_item">';
5890: }
5891: $datatable .= ' '.
5892: '</td></tr></table>';
5893: if (@selectboxes) {
5894: $datatable .= '<hr /><table>';
5895: $numinrow = 2;
5896: for (my $i=0; $i<@selectboxes; $i++) {
5897: $rem = $i%($numinrow);
5898: if ($rem == 0) {
5899: if ($i > 0) {
5900: $datatable .= '</tr>';
5901: }
5902: $datatable .= '<tr>';
5903: }
5904: $datatable .= '<td class="LC_left_item">'.
5905: $selectboxes[$i].'</td>';
5906: }
5907: if ($numinrow) {
5908: $rem = $i%$numinrow;
5909: }
5910: $colsleft = $numinrow - $rem;
5911: if ($colsleft > 1) {
5912: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5913: } else {
5914: $datatable .= '<td class="LC_left_item">';
5915: }
5916: $datatable .= ' '.
5917: '</td></tr></table>';
5918: }
5919: }
5920: $datatable .= '</fieldset>';
5921: }
5922: if (ref($crsconf{$provider}) eq 'ARRAY') {
5923: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5924: '<legend>'.&mt('Configurable in course').'</legend>';
5925: my ($rem,$numinrow);
5926: if ($provider eq 'proctorio') {
5927: $datatable .= '<table>';
5928: $numinrow = 4;
5929: }
5930: my $i = 0;
5931: foreach my $item (@{$crsconf{$provider}}) {
5932: my $name;
5933: if ($provider eq 'examity') {
5934: $name = $lt{'crs'.$item};
5935: } elsif ($provider eq 'proctorio') {
5936: $name = $fieldtitles{$item};
5937: $rem = $i%($numinrow);
5938: if ($rem == 0) {
5939: if ($i > 0) {
5940: $datatable .= '</tr>';
5941: }
5942: $datatable .= '<tr>';
5943: }
5944: $datatable .= '<td class="LC_left_item>';
5945: }
5946: my $checked;
5947: if ($crsconfig{$item}) {
5948: $checked = ' checked="checked"';
5949: }
5950: $datatable .= '<span class="LC_nobreak"><label>'.
5951: '<input type="checkbox" name="proctoring_crsconf_'.$provider.'" value="'.$item.'"'.$checked.' />'.
5952: $name.'</label></span>';
5953: if ($provider eq 'examity') {
5954: $datatable .= ' ';
5955: }
5956: $datatable .= "\n";
5957: $i++;
5958: }
5959: if ($provider eq 'proctorio') {
5960: if ($numinrow) {
5961: $rem = $i%$numinrow;
5962: }
5963: my $colsleft = $numinrow - $rem;
5964: if ($colsleft > 1) {
5965: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
5966: } else {
5967: $datatable .= '<td class="LC_left_item">';
5968: }
5969: $datatable .= ' '.
5970: '</td></tr></table>';
5971: }
5972: $datatable .= '</fieldset>';
5973: }
5974: if ($showroles) {
5975: $datatable .= '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
5976: '<legend>'.&mt('Role mapping').'</legend><table><tr>';
5977: foreach my $role (@courseroles) {
5978: my ($selected,$selectnone);
5979: if (!$rolemaps{$role}) {
5980: $selectnone = ' selected="selected"';
5981: }
5982: $datatable .= '<td style="text-align: center">'.
5983: &Apache::lonnet::plaintext($role,'Course').'<br />'.
5984: '<select name="proctoring_roles_'.$role.'_'.$provider.'">'.
5985: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5986: foreach my $ltirole (@ltiroles) {
5987: unless ($selectnone) {
5988: if ($rolemaps{$role} eq $ltirole) {
5989: $selected = ' selected="selected"';
5990: } else {
5991: $selected = '';
5992: }
5993: }
5994: $datatable .= '<option value="'.$ltirole.'"'.$selected.'>'.$ltirole.'</option>';
5995: }
5996: $datatable .= '</select></td>';
5997: }
5998: $datatable .= '</tr></table></fieldset>'.
5999: '<fieldset class="proctoring_'.$provider.'" style="display:'.$optionsty.'">'.
6000: '<legend>'.&mt('Custom items sent on launch').'</legend>'.
6001: '<table><tr><th>'.&mt('Action').'</th><th>'.&mt('Name').'</th><th>'.&mt('Value').'</th></tr>'.
6002: '<tr><td></td><td>lms</td>'.
6003: '<td><input type="text" name="proctoring_customval_lms_'.$provider.'"'.
6004: ' value="Loncapa" disabled="disabled"/></td></tr>';
6005: if ((ref($settings) eq 'HASH') && (ref($settings->{$provider}) eq 'HASH') &&
6006: (ref($settings->{$provider}->{'custom'}) eq 'HASH')) {
6007: my %custom = %{$settings->{$provider}->{'custom'}};
6008: if (keys(%custom) > 0) {
6009: foreach my $key (sort(keys(%custom))) {
6010: next if ($key eq 'lms');
6011: $datatable .= '<tr><td><span class="LC_nobreak">'.
6012: '<label><input type="checkbox" name="proctoring_customdel_'.$provider.'" value="'.
6013: $key.'" />'.&mt('Delete').'</label></span></td><td>'.$key.'</td>'.
6014: '<td><input type="text" name="proctoring_customval_'.$key.'_'.$provider.'"'.
6015: ' value="'.$custom{$key}.'" /></td></tr>';
6016: }
6017: }
6018: }
6019: $datatable .= '<tr><td><span class="LC_nobreak">'.
6020: '<label><input type="checkbox" name="proctoring_customadd" value="'.$provider.'" />'.
6021: &mt('Add more').'</label></span></td><td><input type="text" name="proctoring_custom_name_'.$provider.'" />'.
6022: '</td><td><input type="text" name="proctoring_custom_value_'.$provider.'" /></td></tr>'.
6023: '</table></fieldset></td></tr>'."\n";
6024: }
6025: $datatable .= '</td></tr>';
6026: }
6027: $itemcount ++;
6028: }
6029: }
6030: return $datatable;
6031: }
6032:
6033: sub proctoring_data {
6034: my $requserfields = {
6035: proctorio => ['user'],
6036: examity => ['roles','user'],
6037: };
6038: my $optuserfields = {
6039: proctorio => ['fullname'],
6040: examity => ['fullname','firstname','lastname','email'],
6041: };
6042: my $defaults = {
6043: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6044: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6045: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6046: 'closetabs','onescreen','print','downloads','cache','rightclick',
6047: 'reentry','calculator','whiteboard'],
6048: examity => ['display'],
6049: };
6050: my $extended = {
6051: proctorio => {
6052: verifyid => ['verifyidauto','verifyidlive'],
6053: fullscreen => ['fullscreenlenient','fullscreenmoderate','fullscreensever'],
6054: tabslinks => ['notabs','linksonly'],
6055: reentry => ['noreentry','agentreentry'],
6056: calculator => ['calculatorbasic','calculatorsci'],
6057: },
6058: examity => {
6059: display => {
6060: target => ['iframe','tab','window'],
6061: width => '',
6062: height => '',
6063: linktext => '',
6064: explanation => '',
6065: },
6066: },
6067: };
6068: my $crsconf = {
6069: proctorio => ['recordvideo','recordaudio','recordscreen','recordwebtraffic',
6070: 'recordroomstart','verifyvideo','verifyaudio','verifydesktop',
6071: 'verifyid','verifysignature','fullscreen','clipboard','tabslinks',
6072: 'closetabs','onescreen','print','downloads','cache','rightclick',
6073: 'reentry','calculator','whiteboard'],
6074: examity => ['label','title','target','linktext','explanation','append'],
6075: };
6076: my $courseroles = ['cc','in','ta','ep','st'];
6077: my $ltiroles = ['Instructor','ContentDeveloper','TeachingAssistant','Learner'];
6078: return ($requserfields,$optuserfields,$defaults,$extended,$crsconf,$courseroles,$ltiroles);
6079: }
6080:
6081: sub proctoring_titles {
6082: my ($item) = @_;
6083: my (%common_lt,%custom_lt);
6084: %common_lt = &Apache::lonlocal::texthash (
6085: 'avai' => 'Available?',
6086: 'base' => 'Basic Settings',
6087: 'requ' => 'User data required to be sent on launch',
6088: 'optu' => 'User data optionally sent on launch',
6089: 'udsl' => 'User data sent on launch',
6090: 'defa' => 'Defaults for items configurable in course',
6091: 'sigmethod' => 'Signature Method',
6092: 'key' => 'Key',
6093: 'lifetime' => 'Nonce lifetime (s)',
6094: 'secret' => 'Secret',
6095: 'icon' => 'Icon',
6096: 'fullname' => 'Full Name',
6097: 'visible' => 'Visible input',
6098: 'username' => 'username',
6099: 'user' => 'User',
6100: );
6101: if ($item eq 'proctorio') {
6102: %custom_lt = &Apache::lonlocal::texthash (
6103: 'version' => 'OAuth version',
6104: 'url' => 'API URL',
6105: 'uname:dom' => 'username-domain',
6106: );
6107: } elsif ($item eq 'examity') {
6108: %custom_lt = &Apache::lonlocal::texthash (
6109: 'version' => 'LTI Version',
6110: 'url' => 'URL',
6111: 'uname:dom' => 'username:domain',
6112: 'msgtype' => 'Message Type',
6113: 'firstname' => 'First Name',
6114: 'lastname' => 'Last Name',
6115: 'email' => 'E-mail',
6116: 'roles' => 'Role',
6117: 'crstarget' => 'Display target',
6118: 'crslabel' => 'Course label',
6119: 'crstitle' => 'Course title',
6120: 'crslinktext' => 'Link Text',
6121: 'crsexplanation' => 'Explanation',
6122: 'crsappend' => 'Provider URL',
6123: );
6124: }
6125: my %lt = (%common_lt,%custom_lt);
6126: return %lt;
6127: }
6128:
6129: sub proctoring_fieldtitles {
6130: my ($item) = @_;
6131: if ($item eq 'proctorio') {
6132: return &Apache::lonlocal::texthash (
6133: 'recordvideo' => 'Record video',
6134: 'recordaudio' => 'Record audio',
6135: 'recordscreen' => 'Record screen',
6136: 'recordwebtraffic' => 'Record web traffic',
6137: 'recordroomstart' => 'Record room scan',
6138: 'verifyvideo' => 'Verify webcam',
6139: 'verifyaudio' => 'Verify microphone',
6140: 'verifydesktop' => 'Verify desktop recording',
6141: 'verifyid' => 'Photo ID verification',
6142: 'verifysignature' => 'Require signature',
6143: 'fullscreen' => 'Fullscreen',
6144: 'clipboard' => 'Disable copy/paste',
6145: 'tabslinks' => 'New tabs/windows',
6146: 'closetabs' => 'Close other tabs',
6147: 'onescreen' => 'Limit to single screen',
6148: 'print' => 'Disable Printing',
6149: 'downloads' => 'Disable Downloads',
6150: 'cache' => 'Empty cache after exam',
6151: 'rightclick' => 'Disable right click',
6152: 'reentry' => 'Re-entry to exam',
6153: 'calculator' => 'Onscreen calculator',
6154: 'whiteboard' => 'Onscreen whiteboard',
6155: 'verifyidauto' => 'Automated verification',
6156: 'verifyidlive' => 'Live agent verification',
6157: 'fullscreenlenient' => 'Forced, but can navigate away for up to 30s',
6158: 'fullscreenmoderate' => 'Forced, but can navigate away for up to 15s',
6159: 'fullscreensever' => 'Forced, navigation away ends exam',
6160: 'notabs' => 'Disaallowed',
6161: 'linksonly' => 'Allowed from links in exam',
6162: 'noreentry' => 'Disallowed',
6163: 'agentreentry' => 'Agent required for re-entry',
6164: 'calculatorbasic' => 'Basic',
6165: 'calculatorsci' => 'Scientific',
6166: );
6167: } elsif ($item eq 'examity') {
6168: return &Apache::lonlocal::texthash (
6169: 'target' => 'Display target',
6170: 'window' => 'Window',
6171: 'tab' => 'Tab',
6172: 'iframe' => 'iFrame',
6173: 'height' => 'Height (pixels)',
6174: 'width' => 'Width (pixels)',
6175: 'linktext' => 'Default Link Text',
6176: 'explanation' => 'Default Explanation',
6177: 'append' => 'Provider URL',
6178: );
6179: }
6180: }
6181:
6182: sub proctoring_providernames {
6183: return (
6184: proctorio => 'Proctorio',
6185: examity => 'Examity',
6186: );
6187: }
6188:
1.320 raeburn 6189: sub print_lti {
1.405 raeburn 6190: my ($position,$dom,$settings,$rowtotal) = @_;
1.320 raeburn 6191: my $itemcount = 1;
1.405 raeburn 6192: my ($datatable,$css_class);
1.434 raeburn 6193: my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
1.320 raeburn 6194: if (ref($settings) eq 'HASH') {
1.405 raeburn 6195: if ($position eq 'top') {
6196: if (exists($settings->{'encrypt'})) {
6197: if (ref($settings->{'encrypt'}) eq 'HASH') {
6198: foreach my $key (keys(%{$settings->{'encrypt'}})) {
6199: if ($key eq 'consumers') {
6200: $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
6201: } else {
6202: $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
6203: }
6204: }
6205: }
6206: }
6207: if (exists($settings->{'private'})) {
6208: if (ref($settings->{'private'}) eq 'HASH') {
6209: if (ref($settings->{'private'}) eq 'HASH') {
6210: if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
6211: map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
6212: }
6213: }
6214: }
6215: }
1.434 raeburn 6216: } elsif ($position eq 'upper') {
1.405 raeburn 6217: if (exists($settings->{'rules'})) {
6218: if (ref($settings->{'rules'}) eq 'HASH') {
6219: %rules = %{$settings->{'rules'}};
6220: }
6221: }
1.434 raeburn 6222: } elsif ($position eq 'middle') {
6223: if (exists($settings->{'suggested'})) {
6224: if (ref($settings->{'suggested'}) eq 'HASH') {
6225: %suggestions = %{$settings->{'suggested'}};
6226: }
6227: }
1.405 raeburn 6228: } elsif ($position eq 'lower') {
6229: if (exists($settings->{'linkprot'})) {
6230: if (ref($settings->{'linkprot'}) eq 'HASH') {
6231: %linkprot = %{$settings->{'linkprot'}};
1.406 raeburn 6232: if ($linkprot{'lock'}) {
6233: delete($linkprot{'lock'});
6234: }
1.405 raeburn 6235: }
6236: }
6237: } else {
1.434 raeburn 6238: foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
1.405 raeburn 6239: if (exists($settings->{$key})) {
6240: delete($settings->{$key});
1.390 raeburn 6241: }
1.320 raeburn 6242: }
6243: }
6244: }
1.405 raeburn 6245: if ($position eq 'top') {
1.421 raeburn 6246: $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
1.434 raeburn 6247: } elsif ($position eq 'upper') {
6248: $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
6249: $$rowtotal += $itemcount;
1.421 raeburn 6250: } elsif ($position eq 'middle') {
1.434 raeburn 6251: $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
1.421 raeburn 6252: $$rowtotal += $itemcount;
6253: } elsif ($position eq 'lower') {
1.434 raeburn 6254: $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
1.421 raeburn 6255: } else {
1.424 raeburn 6256: my ($switchserver,$switchmessage);
6257: $switchserver = &check_switchserver($dom);
6258: $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
1.421 raeburn 6259: my $maxnum = 0;
6260: my %ordered;
6261: if (ref($settings) eq 'HASH') {
6262: foreach my $item (keys(%{$settings})) {
6263: if (ref($settings->{$item}) eq 'HASH') {
6264: my $num = $settings->{$item}{'order'};
6265: if ($num eq '') {
6266: $num = scalar(keys(%{$settings}));
6267: }
6268: $ordered{$num} = $item;
1.405 raeburn 6269: }
1.352 raeburn 6270: }
1.405 raeburn 6271: }
6272: $maxnum = scalar(keys(%ordered));
6273: my %lt = <i_names();
6274: if (keys(%ordered)) {
6275: my @items = sort { $a <=> $b } keys(%ordered);
6276: for (my $i=0; $i<@items; $i++) {
6277: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6278: my $item = $ordered{$items[$i]};
1.424 raeburn 6279: my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
1.405 raeburn 6280: if (ref($settings->{$item}) eq 'HASH') {
6281: $key = $settings->{$item}->{'key'};
1.424 raeburn 6282: $usable = $settings->{$item}->{'usable'};
1.405 raeburn 6283: $lifetime = $settings->{$item}->{'lifetime'};
6284: $consumer = $settings->{$item}->{'consumer'};
6285: $requser = $settings->{$item}->{'requser'};
6286: $crsinc = $settings->{$item}->{'crsinc'};
6287: $current = $settings->{$item};
6288: }
6289: my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
6290: my %checkedrequser = (
6291: yes => ' checked="checked"',
6292: no => '',
6293: );
6294: if (!$requser) {
6295: $checkedrequser{'no'} = $checkedrequser{'yes'};
6296: $checkedrequser{'yes'} = '';
6297: }
6298: my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
6299: my %checkedcrsinc = (
1.391 raeburn 6300: yes => ' checked="checked"',
6301: no => '',
1.405 raeburn 6302: );
6303: if (!$crsinc) {
6304: $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
6305: $checkedcrsinc{'yes'} = '';
6306: }
6307: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
6308: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
6309: .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
6310: for (my $k=0; $k<=$maxnum; $k++) {
6311: my $vpos = $k+1;
6312: my $selstr;
6313: if ($k == $i) {
6314: $selstr = ' selected="selected" ';
6315: }
6316: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6317: }
1.405 raeburn 6318: $datatable .= '</select>'.(' 'x2).
6319: '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
6320: &mt('Delete?').'</label></span></td>'.
6321: '<td colspan="2">'.
6322: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6323: '<span class="LC_nobreak">'.$lt{'consumer'}.
6324: ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
6325: (' 'x2).
6326: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
6327: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
6328: (' 'x2).
6329: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
1.424 raeburn 6330: 'value="'.$lifetime.'" size="3" /></span><br /><br />';
6331: if ($key ne '') {
6332: $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
6333: if ($switchserver) {
6334: $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
6335: } else {
6336: $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
6337: }
6338: $datatable .= '</span> '.(' 'x2);
6339: } elsif (!$switchserver) {
6340: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
6341: '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
6342: '</span> '.(' 'x2);
6343: }
6344: if ($switchserver) {
6345: if ($usable ne '') {
6346: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6347: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6348: '<span class="LC_nobreak">'.&mt('Change secret?').
6349: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6350: (' 'x2).
6351: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
6352: '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6353: '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
6354: '</div>';
6355: } elsif ($key eq '') {
6356: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6357: } else {
6358: $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
6359: }
6360: } else {
6361: if ($usable ne '') {
6362: $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
6363: $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
6364: '<span class="LC_nobreak">'.&mt('Change?').
6365: '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
6366: (' 'x2).
6367: '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
6368: '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
6369: '<span class="LC_nobreak">'.&mt('New Secret').':'.
6370: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6371: '<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>';
6372: } else {
6373: $datatable .=
6374: '<span class="LC_nobreak">'.$lt{'secret'}.':'.
6375: '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
6376: '<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>';
6377: }
6378: }
1.425 raeburn 6379: $datatable .= '<br /><br />'.
1.405 raeburn 6380: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6381: '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
6382: '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
6383: '<br /><br />'.
6384: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6385: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
6386: '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
6387: (' 'x4).
6388: '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
6389: '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
6390: $itemcount ++;
1.320 raeburn 6391: }
6392: }
1.405 raeburn 6393: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6394: my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
6395: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6396: '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
6397: '<select name="lti_pos_add"'.$chgstr.'>';
6398: for (my $k=0; $k<$maxnum+1; $k++) {
6399: my $vpos = $k+1;
6400: my $selstr;
6401: if ($k == $maxnum) {
6402: $selstr = ' selected="selected" ';
6403: }
6404: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.320 raeburn 6405: }
1.405 raeburn 6406: $datatable .= '</select> '."\n".
6407: '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6408: '<td colspan="2">'.
6409: '<fieldset><legend>'.&mt('Required settings').'</legend>'.
6410: '<span class="LC_nobreak">'.$lt{'consumer'}.
6411: ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
6412: (' 'x2).
6413: '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
6414: '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
6415: (' 'x2).
1.424 raeburn 6416: '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
6417: if ($switchserver) {
6418: $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
6419: } else {
6420: $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
6421: (' 'x2).
6422: '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
6423: '<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";
6424: }
6425: $datatable .= '<br /><br />'.
1.405 raeburn 6426: '<span class="LC_nobreak">'.$lt{'requser'}.':'.
6427: '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6428: '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
6429: '<br /><br />'.
6430: '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
6431: '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
6432: '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
6433: '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
6434: '</td>'."\n".
6435: '</tr>'."\n";
6436: $itemcount ++;
1.320 raeburn 6437: }
1.405 raeburn 6438: $$rowtotal += $itemcount;
6439: return $datatable;
1.320 raeburn 6440: }
6441:
6442: sub lti_names {
6443: my %lt = &Apache::lonlocal::texthash(
6444: 'version' => 'LTI Version',
6445: 'url' => 'URL',
6446: 'key' => 'Key',
1.322 raeburn 6447: 'lifetime' => 'Nonce lifetime (s)',
1.345 raeburn 6448: 'consumer' => 'Consumer',
1.320 raeburn 6449: 'secret' => 'Secret',
1.345 raeburn 6450: 'requser' => "User's identity sent",
1.391 raeburn 6451: 'crsinc' => "Course's identity sent",
1.320 raeburn 6452: 'email' => 'Email address',
6453: 'sourcedid' => 'User ID',
6454: 'other' => 'Other',
6455: 'passback' => 'Can return grades to Consumer:',
6456: 'roster' => 'Can retrieve roster from Consumer:',
1.326 raeburn 6457: 'topmenu' => 'Display LON-CAPA page header',
1.345 raeburn 6458: 'inlinemenu'=> 'Display LON-CAPA inline menu',
1.320 raeburn 6459: );
6460: return %lt;
6461: }
6462:
6463: sub lti_options {
1.325 raeburn 6464: my ($num,$current,$itemcount,%lt) = @_;
1.363 raeburn 6465: my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
1.320 raeburn 6466: $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
6467: $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
1.392 raeburn 6468: $checked{'storecrs'}{'Y'} = ' checked="checked"';
6469: $checked{'makecrs'}{'N'} = ' checked="checked"';
1.320 raeburn 6470: $checked{'mapcrstype'} = {};
6471: $checked{'makeuser'} = {};
6472: $checked{'selfenroll'} = {};
6473: $checked{'crssec'} = {};
6474: $checked{'crssecsrc'} = {};
1.325 raeburn 6475: $checked{'lcauth'} = {};
1.326 raeburn 6476: $checked{'menuitem'} = {};
1.325 raeburn 6477: if ($num eq 'add') {
6478: $checked{'lcauth'}{'lti'} = ' checked="checked"';
6479: }
1.320 raeburn 6480: my $userfieldsty = 'none';
6481: my $crsfieldsty = 'none';
6482: my $crssecfieldsty = 'none';
6483: my $secsrcfieldsty = 'none';
1.363 raeburn 6484: my $callbacksty = 'none';
1.337 raeburn 6485: my $passbacksty = 'none';
1.345 raeburn 6486: my $optionsty = 'block';
1.391 raeburn 6487: my $crssty = 'block';
1.325 raeburn 6488: my $lcauthparm;
6489: my $lcauthparmstyle = 'display:none';
6490: my $lcauthparmtext;
1.326 raeburn 6491: my $menusty;
1.325 raeburn 6492: my $numinrow = 4;
1.326 raeburn 6493: my %menutitles = <imenu_titles();
1.320 raeburn 6494:
6495: if (ref($current) eq 'HASH') {
1.345 raeburn 6496: if (!$current->{'requser'}) {
6497: $optionsty = 'none';
1.391 raeburn 6498: $crssty = 'none';
6499: } elsif (!$current->{'crsinc'}) {
6500: $crssty = 'none';
1.345 raeburn 6501: }
1.320 raeburn 6502: if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
6503: $checked{'mapuser'}{'sourcedid'} = '';
6504: if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
1.425 raeburn 6505: $checked{'mapuser'}{'email'} = ' checked="checked"';
1.320 raeburn 6506: } else {
6507: $checked{'mapuser'}{'other'} = ' checked="checked"';
6508: $userfield = $current->{'mapuser'};
6509: $userfieldsty = 'inline-block';
6510: }
6511: }
6512: if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
6513: $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
6514: if ($current->{'mapcrs'} eq 'context_id') {
1.425 raeburn 6515: $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
1.320 raeburn 6516: } else {
6517: $checked{'mapcrs'}{'other'} = ' checked="checked"';
6518: $cidfield = $current->{'mapcrs'};
6519: $crsfieldsty = 'inline-block';
6520: }
6521: }
6522: if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
6523: foreach my $type (@{$current->{'mapcrstype'}}) {
6524: $checked{'mapcrstype'}{$type} = ' checked="checked"';
6525: }
6526: }
1.392 raeburn 6527: if (!$current->{'storecrs'}) {
6528: $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
6529: $checked{'storecrs'}{'Y'} = '';
6530: }
1.345 raeburn 6531: if ($current->{'makecrs'}) {
1.320 raeburn 6532: $checked{'makecrs'}{'Y'} = ' checked="checked"';
1.326 raeburn 6533: }
1.320 raeburn 6534: if (ref($current->{'makeuser'}) eq 'ARRAY') {
6535: foreach my $role (@{$current->{'makeuser'}}) {
6536: $checked{'makeuser'}{$role} = ' checked="checked"';
6537: }
6538: }
1.325 raeburn 6539: if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
6540: $checked{'lcauth'}{$1} = ' checked="checked"';
6541: unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
6542: $lcauthparm = $current->{'lcauthparm'};
1.425 raeburn 6543: $lcauthparmstyle = 'display:table-row';
1.325 raeburn 6544: if ($current->{'lcauth'} eq 'localauth') {
6545: $lcauthparmtext = &mt('Local auth argument');
6546: } else {
6547: $lcauthparmtext = &mt('Kerberos domain');
6548: }
6549: }
6550: }
1.320 raeburn 6551: if (ref($current->{'selfenroll'}) eq 'ARRAY') {
6552: foreach my $role (@{$current->{'selfenroll'}}) {
6553: $checked{'selfenroll'}{$role} = ' checked="checked"';
6554: }
6555: }
6556: if (ref($current->{'maproles'}) eq 'HASH') {
6557: %rolemaps = %{$current->{'maproles'}};
6558: }
6559: if ($current->{'section'} ne '') {
1.425 raeburn 6560: $checked{'crssec'}{'Y'} = ' checked="checked"';
1.320 raeburn 6561: $crssecfieldsty = 'inline-block';
6562: if ($current->{'section'} eq 'course_section_sourcedid') {
6563: $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
6564: } else {
6565: $checked{'crssecsrc'}{'other'} = ' checked="checked"';
6566: $crssecsrc = $current->{'section'};
6567: $secsrcfieldsty = 'inline-block';
6568: }
6569: } else {
6570: $checked{'crssec'}{'N'} = ' checked="checked"';
6571: }
1.363 raeburn 6572: if ($current->{'callback'} ne '') {
6573: $callback = $current->{'callback'};
6574: $checked{'callback'}{'Y'} = ' checked="checked"';
6575: $callbacksty = 'inline-block';
6576: } else {
6577: $checked{'callback'}{'N'} = ' checked="checked"';
6578: }
1.326 raeburn 6579: if ($current->{'topmenu'}) {
6580: $checked{'topmenu'}{'Y'} = ' checked="checked"';
6581: } else {
6582: $checked{'topmenu'}{'N'} = ' checked="checked"';
6583: }
6584: if ($current->{'inlinemenu'}) {
6585: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
6586: } else {
6587: $checked{'inlinemenu'}{'N'} = ' checked="checked"';
6588: }
6589: if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
6590: $menusty = 'inline-block';
6591: if (ref($current->{'lcmenu'}) eq 'ARRAY') {
6592: foreach my $item (@{$current->{'lcmenu'}}) {
6593: if (exists($menutitles{$item})) {
6594: $checked{'menuitem'}{$item} = ' checked="checked"';
6595: }
6596: }
6597: }
6598: } else {
6599: $menusty = 'none';
6600: }
1.320 raeburn 6601: } else {
6602: $checked{'makecrs'}{'N'} = ' checked="checked"';
6603: $checked{'crssec'}{'N'} = ' checked="checked"';
1.363 raeburn 6604: $checked{'callback'}{'N'} = ' checked="checked"';
1.326 raeburn 6605: $checked{'topmenu'}{'N'} = ' checked="checked"';
1.425 raeburn 6606: $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
1.326 raeburn 6607: $checked{'menuitem'}{'grades'} = ' checked="checked"';
1.425 raeburn 6608: $menusty = 'inline-block';
1.320 raeburn 6609: }
1.325 raeburn 6610: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 6611: my %coursetypetitles = &Apache::lonlocal::texthash (
6612: official => 'Official',
6613: unofficial => 'Unofficial',
6614: community => 'Community',
6615: textbook => 'Textbook',
6616: placement => 'Placement Test',
1.325 raeburn 6617: lti => 'LTI Provider',
1.320 raeburn 6618: );
1.325 raeburn 6619: my @authtypes = ('internal','krb4','krb5','localauth');
6620: my %shortauth = (
6621: internal => 'int',
6622: krb4 => 'krb4',
6623: krb5 => 'krb5',
6624: localauth => 'loc'
6625: );
6626: my %authnames = &authtype_names();
1.320 raeburn 6627: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
6628: my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
6629: my @courseroles = ('cc','in','ta','ep','st');
6630: my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
6631: my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
6632: my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
1.363 raeburn 6633: my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
1.320 raeburn 6634: my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
1.325 raeburn 6635: my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
1.326 raeburn 6636: my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
1.391 raeburn 6637: my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
1.392 raeburn 6638: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
1.391 raeburn 6639: '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
6640: $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
6641: '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
6642: $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
6643: '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
6644: '<span class="LC_nobreak">'.&mt('Parameter').': '.
6645: '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
6646: '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
6647: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
1.320 raeburn 6648: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
6649: foreach my $option ('sourcedid','email','other') {
6650: $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
6651: $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
6652: ($option eq 'other' ? '' : (' 'x2) );
6653: }
6654: $output .= '</span></div>'.
6655: '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
6656: '<input type="text" name="lti_customuser_'.$num.'" '.
1.372 raeburn 6657: 'value="'.$userfield.'" /></div></fieldset>'.
1.391 raeburn 6658: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
1.320 raeburn 6659: foreach my $ltirole (@ltiroles) {
6660: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
1.425 raeburn 6661: $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
1.320 raeburn 6662: }
6663: $output .= '</fieldset>'.
1.391 raeburn 6664: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
1.325 raeburn 6665: '<table>'.
6666: &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
6667: '</table>'.
6668: '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
6669: '<td class="LC_left_item">';
6670: foreach my $auth ('lti',@authtypes) {
6671: my $authtext;
6672: if ($auth eq 'lti') {
6673: $authtext = &mt('None');
6674: } else {
6675: $authtext = $authnames{$shortauth{$auth}};
6676: }
6677: $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
6678: '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
6679: $authtext.'</label></span> ';
6680: }
6681: $output .= '</td></tr>'.
6682: '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
6683: '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
6684: '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
6685: '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
6686: '</table></fieldset>'.
1.391 raeburn 6687: '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
6688: &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
6689: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
6690: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
6691: $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6692: '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
6693: $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
6694: '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6695: '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
6696: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
6697: $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
6698: '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
6699: $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
6700: $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
6701: '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
6702: '<span class="LC_nobreak">'.&mt('Menu items').': ';
6703: foreach my $type ('fullname','coursetitle','role','logout','grades') {
6704: $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
6705: $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
6706: (' 'x2);
6707: }
6708: $output .= '</span></div></fieldset>'.
6709: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
1.320 raeburn 6710: '<div class="LC_floatleft"><span class="LC_nobreak">'.
6711: &mt('Unique course identifier').': ';
6712: foreach my $option ('course_offering_sourcedid','context_id','other') {
6713: $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
6714: $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
6715: ($option eq 'other' ? '' : (' 'x2) );
6716: }
1.334 raeburn 6717: $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
1.320 raeburn 6718: '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
6719: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
6720: '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
6721: foreach my $type (@coursetypes) {
6722: $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
6723: $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
6724: (' 'x2);
6725: }
1.392 raeburn 6726: $output .= '</span><br /><br />'.
6727: '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
6728: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
6729: $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6730: '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
6731: $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6732: '</fieldset>'.
1.391 raeburn 6733: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
6734: foreach my $ltirole (@lticourseroles) {
6735: my ($selected,$selectnone);
6736: if ($rolemaps{$ltirole} eq '') {
6737: $selectnone = ' selected="selected"';
6738: }
6739: $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
6740: '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
6741: '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
6742: foreach my $role (@courseroles) {
6743: unless ($selectnone) {
6744: if ($rolemaps{$ltirole} eq $role) {
6745: $selected = ' selected="selected"';
6746: } else {
6747: $selected = '';
6748: }
6749: }
6750: $output .= '<option value="'.$role.'"'.$selected.'>'.
6751: &Apache::lonnet::plaintext($role,'Course').
6752: '</option>';
6753: }
6754: $output .= '</select></td>';
6755: }
6756: $output .= '</tr></table></fieldset>'.
6757: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
1.320 raeburn 6758: '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
6759: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
6760: $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
6761: '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
6762: $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
6763: '</fieldset>'.
1.391 raeburn 6764: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
1.320 raeburn 6765: foreach my $lticrsrole (@lticourseroles) {
6766: $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
6767: $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
6768: }
6769: $output .= '</fieldset>'.
1.391 raeburn 6770: '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
1.320 raeburn 6771: '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
6772: '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
6773: $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
6774: '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
1.334 raeburn 6775: $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
1.320 raeburn 6776: '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
6777: '<span class="LC_nobreak">'.&mt('From').':<label>'.
6778: '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
6779: $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
6780: &mt('Standard field').'</label>'.(' 'x2).
6781: '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
6782: $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
1.334 raeburn 6783: '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
1.320 raeburn 6784: '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
1.337 raeburn 6785: '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
6786: my ($pb1p1chk,$pb1p0chk,$onclickpb);
6787: foreach my $extra ('roster','passback') {
1.320 raeburn 6788: my $checkedon = '';
6789: my $checkedoff = ' checked="checked"';
1.337 raeburn 6790: if ($extra eq 'passback') {
6791: $pb1p1chk = ' checked="checked"';
6792: $pb1p0chk = '';
1.425 raeburn 6793: $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
1.337 raeburn 6794: } else {
1.425 raeburn 6795: $onclickpb = '';
1.337 raeburn 6796: }
1.320 raeburn 6797: if (ref($current) eq 'HASH') {
6798: if (($current->{$extra})) {
6799: $checkedon = $checkedoff;
6800: $checkedoff = '';
1.337 raeburn 6801: if ($extra eq 'passback') {
6802: $passbacksty = 'inline-block';
6803: }
6804: if ($current->{'passbackformat'} eq '1.0') {
6805: $pb1p0chk = ' checked="checked"';
6806: $pb1p1chk = '';
6807: }
1.320 raeburn 6808: }
6809: }
6810: $output .= $lt{$extra}.' '.
1.337 raeburn 6811: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
1.320 raeburn 6812: &mt('No').'</label>'.(' 'x2).
1.339 raeburn 6813: '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
1.320 raeburn 6814: &mt('Yes').'</label><br />';
6815: }
1.337 raeburn 6816: $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
6817: '<span class="LC_nobreak">'.&mt('Grade format').
6818: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
6819: &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
6820: '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
1.363 raeburn 6821: &mt('Outcomes Extension (1.0)').'</label></span></div>'.
1.391 raeburn 6822: '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
1.334 raeburn 6823: $output .= '</span></div></fieldset>';
1.320 raeburn 6824: # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
6825: #
6826: # $output .= '</fieldset>'.
6827: # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
6828: return $output;
6829: }
6830:
1.326 raeburn 6831: sub ltimenu_titles {
6832: return &Apache::lonlocal::texthash(
6833: fullname => 'Full name',
6834: coursetitle => 'Course title',
6835: role => 'Role',
6836: logout => 'Logout',
6837: grades => 'Grades',
6838: );
6839: }
6840:
1.434 raeburn 6841: sub linkprot_suggestions {
6842: my ($suggested,$itemcount) = @_;
6843: my $count = 0;
6844: my $next = 1;
6845: my %lt = &Apache::lonlocal::texthash(
6846: 'name' => 'Suggested Launcher',
6847: 'info' => 'Recommendations',
6848: );
6849: my ($datatable,$css_class,$dest);
6850: if (ref($suggested) eq 'HASH') {
6851: my @current = sort { $a <=> $b } keys(%{$suggested});
6852: $next += $current[-1];
6853: for (my $i=0; $i<@current; $i++) {
6854: my $num = $current[$i];
6855: my %values;
6856: if (ref($suggested->{$num}) eq 'HASH') {
6857: %values = %{$suggested->{$num}};
6858: } else {
6859: next;
6860: }
6861: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6862: $datatable .=
6863: '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6864: '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6865: &mt('Delete?').'</label></span></td><td>'."\n".
6866: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6867: '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6868: '</fieldset></div>'.
6869: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6870: '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6871: '</fieldset></div>'.
6872: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6873: '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6874: $$itemcount ++;
6875: }
6876: }
6877: $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6878: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6879: '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6880: '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6881: '<td>'."\n".
6882: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6883: '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6884: '</fieldset></div>'.
6885: '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6886: '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6887: '</fieldset></div>'.
6888: '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6889: '</td></tr>'."\n";
6890: return $datatable;
6891: }
6892:
1.121 raeburn 6893: sub print_coursedefaults {
1.139 raeburn 6894: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 6895: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6896: my $itemcount = 1;
1.192 raeburn 6897: my %choices = &Apache::lonlocal::texthash (
6898: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 6899: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.432 raeburn 6900: coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.192 raeburn 6901: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6902: coursecredits => 'Credits can be specified for courses',
1.257 raeburn 6903: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6904: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.398 raeburn 6905: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.314 raeburn 6906: texengine => 'Default method to display mathematics',
1.257 raeburn 6907: postsubmit => 'Disable submit button/keypress following student submission',
1.276 raeburn 6908: canclone => "People who may clone a course (besides course's owner and coordinators)",
6909: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.405 raeburn 6910: ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
1.422 raeburn 6911: domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6912: exttool => 'External Tools can be defined and configured in courses/communities (by type)',
1.432 raeburn 6913: crsauthor => 'Standard LON-CAPA problems can be created within a course/community (by type)',
1.438 raeburn 6914: crseditors => 'Available editors for web pages and/or problems created in a course/community',
1.192 raeburn 6915: );
1.198 raeburn 6916: my %staticdefaults = (
6917: anonsurvey_threshold => 10,
6918: uploadquota => 500,
1.428 raeburn 6919: coursequota => 20,
1.257 raeburn 6920: postsubmit => 60,
1.276 raeburn 6921: mysqltables => 172800,
1.422 raeburn 6922: domexttool => 1,
6923: exttool => 0,
1.432 raeburn 6924: crsauthor => 1,
1.438 raeburn 6925: crseditors => ['edit','xml'],
1.198 raeburn 6926: );
1.139 raeburn 6927: if ($position eq 'top') {
1.257 raeburn 6928: %defaultchecked = (
6929: 'canuse_pdfforms' => 'off',
6930: 'uselcmath' => 'on',
6931: 'usejsme' => 'on',
1.398 raeburn 6932: 'inline_chem' => 'on',
1.289 raeburn 6933: 'canclone' => 'none',
1.257 raeburn 6934: );
1.398 raeburn 6935: @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem');
1.349 raeburn 6936: my $deftex = $Apache::lonnet::deftex;
1.314 raeburn 6937: if (ref($settings) eq 'HASH') {
6938: if ($settings->{'texengine'}) {
6939: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6940: $deftex = $settings->{'texengine'};
6941: }
6942: }
6943: }
6944: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6945: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6946: '<span class="LC_nobreak">'.$choices{'texengine'}.
6947: '</span></td><td class="LC_right_item">'.
6948: '<select name="texengine">'."\n";
6949: my %texoptions = (
6950: MathJax => 'MathJax',
6951: mimetex => &mt('Convert to Images'),
6952: tth => &mt('TeX to HTML'),
6953: );
6954: foreach my $renderer ('MathJax','mimetex','tth') {
6955: my $selected = '';
6956: if ($renderer eq $deftex) {
6957: $selected = ' selected="selected"';
6958: }
6959: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6960: }
6961: $mathdisp .= '</select></td></tr>'."\n";
6962: $itemcount ++;
1.139 raeburn 6963: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.257 raeburn 6964: \%choices,$itemcount);
1.314 raeburn 6965: $datatable = $mathdisp.$datatable;
1.264 raeburn 6966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6967: $datatable .=
1.306 raeburn 6968: '<tr'.$css_class.'><td style="vertical-align: top">'.
1.264 raeburn 6969: '<span class="LC_nobreak">'.$choices{'canclone'}.
6970: '</span></td><td class="LC_left_item">';
6971: my $currcanclone = 'none';
6972: my $onclick;
6973: my @cloneoptions = ('none','domain');
1.380 raeburn 6974: my %clonetitles = &Apache::lonlocal::texthash (
1.264 raeburn 6975: none => 'No additional course requesters',
6976: domain => "Any course requester in course's domain",
6977: instcode => 'Course requests for official courses ...',
6978: );
6979: my (%codedefaults,@code_order,@posscodes);
6980: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6981: \@code_order) eq 'ok') {
6982: if (@code_order > 0) {
6983: push(@cloneoptions,'instcode');
6984: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6985: }
6986: }
6987: if (ref($settings) eq 'HASH') {
6988: if ($settings->{'canclone'}) {
6989: if (ref($settings->{'canclone'}) eq 'HASH') {
6990: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6991: if (@code_order > 0) {
6992: $currcanclone = 'instcode';
6993: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6994: }
6995: }
6996: } elsif ($settings->{'canclone'} eq 'domain') {
6997: $currcanclone = $settings->{'canclone'};
6998: }
6999: }
1.289 raeburn 7000: }
1.264 raeburn 7001: foreach my $option (@cloneoptions) {
7002: my ($checked,$additional);
7003: if ($currcanclone eq $option) {
7004: $checked = ' checked="checked"';
7005: }
7006: if ($option eq 'instcode') {
7007: if (@code_order) {
7008: my $show = 'none';
7009: if ($checked) {
7010: $show = 'block';
7011: }
1.317 raeburn 7012: $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.264 raeburn 7013: &mt('Institutional codes for new and cloned course have identical:').
7014: '<br />';
7015: foreach my $item (@code_order) {
7016: my $codechk;
7017: if ($checked) {
7018: if (grep(/^\Q$item\E$/,@posscodes)) {
7019: $codechk = ' checked="checked"';
7020: }
7021: }
7022: $additional .= '<label>'.
7023: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
7024: $item.'</label>';
7025: }
7026: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
7027: }
7028: }
7029: $datatable .=
7030: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
7031: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
7032: '</label> '.$additional.'</span><br />';
7033: }
7034: $datatable .= '</td>'.
7035: '</tr>';
7036: $itemcount ++;
1.139 raeburn 7037: } else {
7038: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.428 raeburn 7039: my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
7040: %deftimeout,%currmysql);
1.192 raeburn 7041: my $currusecredits = 0;
1.257 raeburn 7042: my $postsubmitclient = 1;
1.405 raeburn 7043: my $ltiauth = 0;
1.422 raeburn 7044: my %domexttool;
7045: my %exttool;
1.432 raeburn 7046: my %crsauthor;
1.438 raeburn 7047: my %crseditors;
1.271 raeburn 7048: my @types = ('official','unofficial','community','textbook','placement');
1.139 raeburn 7049: if (ref($settings) eq 'HASH') {
1.404 raeburn 7050: if ($settings->{'ltiauth'}) {
7051: $ltiauth = 1;
1.405 raeburn 7052: }
1.422 raeburn 7053: if (ref($settings->{'domexttool'}) eq 'HASH') {
7054: foreach my $type (@types) {
7055: if ($settings->{'domexttool'}->{$type}) {
7056: $domexttool{$type} = ' checked="checked"';
7057: }
7058: }
7059: } else {
7060: foreach my $type (@types) {
7061: if ($staticdefaults{'domexttool'}) {
7062: $domexttool{$type} = ' checked="checked"';
7063: }
7064: }
7065: }
7066: if (ref($settings->{'exttool'}) eq 'HASH') {
7067: foreach my $type (@types) {
7068: if ($settings->{'exttool'}->{$type}) {
7069: $exttool{$type} = ' checked="checked"';
7070: }
7071: }
7072: }
1.432 raeburn 7073: if (ref($settings->{'crsauthor'}) eq 'HASH') {
7074: foreach my $type (@types) {
7075: if ($settings->{'crsauthor'}->{$type}) {
7076: $crsauthor{$type} = ' checked="checked"';
7077: }
7078: }
7079: } else {
7080: foreach my $type (@types) {
7081: if ($staticdefaults{'crsauthor'}) {
7082: $crsauthor{$type} = ' checked="checked"';
7083: }
7084: }
7085: }
1.438 raeburn 7086: if (ref($settings->{'crseditors'}) eq 'ARRAY') {
7087: foreach my $editor (@{$settings->{'crseditors'}}) {
7088: $crseditors{$editor} = ' checked="checked"';
7089: }
7090: } else {
7091: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7092: $crseditors{$editor} = ' checked="checked"';
7093: }
7094: }
1.139 raeburn 7095: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 7096: if (ref($settings->{'uploadquota'}) eq 'HASH') {
7097: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
7098: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
7099: }
7100: }
1.428 raeburn 7101: if (ref($settings->{'coursequota'}) eq 'HASH') {
7102: foreach my $type (keys(%{$settings->{'coursequota'}})) {
7103: $currcoursequota{$type} = $settings->{'coursequota'}{$type};
7104: }
7105: }
1.192 raeburn 7106: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.257 raeburn 7107: foreach my $type (@types) {
7108: next if ($type eq 'community');
7109: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
7110: if ($defcredits{$type} ne '') {
7111: $currusecredits = 1;
7112: }
7113: }
7114: }
7115: if (ref($settings->{'postsubmit'}) eq 'HASH') {
7116: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
7117: $postsubmitclient = 0;
7118: foreach my $type (@types) {
7119: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7120: }
7121: } else {
7122: foreach my $type (@types) {
7123: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
7124: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
1.289 raeburn 7125: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
1.257 raeburn 7126: } else {
7127: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7128: }
7129: } else {
7130: $deftimeout{$type} = $staticdefaults{'postsubmit'};
7131: }
7132: }
7133: }
7134: } else {
7135: foreach my $type (@types) {
7136: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.192 raeburn 7137: }
7138: }
1.276 raeburn 7139: if (ref($settings->{'mysqltables'}) eq 'HASH') {
7140: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
7141: $currmysql{$type} = $settings->{'mysqltables'}{$type};
7142: }
7143: } else {
7144: foreach my $type (@types) {
7145: $currmysql{$type} = $staticdefaults{'mysqltables'};
7146: }
7147: }
1.258 raeburn 7148: } else {
7149: foreach my $type (@types) {
7150: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.422 raeburn 7151: if ($staticdefaults{'domexttool'}) {
7152: $domexttool{$type} = ' checked="checked"';
7153: }
1.432 raeburn 7154: if ($staticdefaults{'crsauthor'}) {
7155: $crsauthor{$type} = ' checked="checked"';
7156: }
1.258 raeburn 7157: }
1.438 raeburn 7158: foreach my $editor (@{$staticdefaults{'crseditors'}}) {
7159: $crseditors{$editor} = ' checked="checked"';
7160: }
1.139 raeburn 7161: }
7162: if (!$currdefresponder) {
1.198 raeburn 7163: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 7164: } elsif ($currdefresponder < 1) {
7165: $currdefresponder = 1;
7166: }
1.198 raeburn 7167: foreach my $type (@types) {
7168: if ($curruploadquota{$type} eq '') {
7169: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
7170: }
1.428 raeburn 7171: if ($currcoursequota{$type} eq '') {
7172: $currcoursequota{$type} = $staticdefaults{'coursequota'};
7173: }
1.198 raeburn 7174: }
1.139 raeburn 7175: $datatable .=
1.192 raeburn 7176: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7177: $choices{'anonsurvey_threshold'}.
1.139 raeburn 7178: '</span></td>'.
7179: '<td class="LC_right_item"><span class="LC_nobreak">'.
7180: '<input type="text" name="anonsurvey_threshold"'.
7181: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.230 raeburn 7182: '</td></tr>'."\n";
7183: $itemcount ++;
7184: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7185: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7186: $choices{'uploadquota'}.
7187: '</span></td>'.
1.306 raeburn 7188: '<td style="text-align: right" class="LC_right_item">'.
1.230 raeburn 7189: '<table><tr>';
1.198 raeburn 7190: foreach my $type (@types) {
1.306 raeburn 7191: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.198 raeburn 7192: '<input type="text" name="uploadquota_'.$type.'"'.
7193: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
7194: }
7195: $datatable .= '</tr></table></td></tr>'."\n";
1.230 raeburn 7196: $itemcount ++;
1.428 raeburn 7197: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7198: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7199: $choices{'coursequota'}.
7200: '</span></td>'.
7201: '<td style="text-align: right" class="LC_right_item">'.
7202: '<table><tr>';
7203: foreach my $type (@types) {
7204: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
7205: '<input type="text" name="coursequota_'.$type.'"'.
7206: ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
7207: }
7208: $datatable .= '</tr></table></td></tr>'."\n";
7209: $itemcount ++;
1.236 raeburn 7210: my $onclick = "toggleDisplay(this.form,'credits');";
1.210 raeburn 7211: my $display = 'none';
1.192 raeburn 7212: if ($currusecredits) {
7213: $display = 'block';
7214: }
7215: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.257 raeburn 7216: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
7217: foreach my $type (@types) {
7218: next if ($type eq 'community');
1.306 raeburn 7219: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7220: '<input type="text" name="'.$type.'_credits"'.
1.258 raeburn 7221: ' value="'.$defcredits{$type}.'" size="3" /></td>';
1.257 raeburn 7222: }
7223: $additional .= '</tr></table></div>'."\n";
1.192 raeburn 7224: %defaultchecked = ('coursecredits' => 'off');
7225: @toggles = ('coursecredits');
7226: my $current = {
7227: 'coursecredits' => $currusecredits,
7228: };
7229: (my $table,$itemcount) =
7230: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.257 raeburn 7231: \%choices,$itemcount,$onclick,$additional,'left');
7232: $datatable .= $table;
7233: $onclick = "toggleDisplay(this.form,'studentsubmission');";
7234: my $display = 'none';
7235: if ($postsubmitclient) {
7236: $display = 'block';
7237: }
7238: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.259 raeburn 7239: &mt('Number of seconds submit is disabled').'<br />'.
7240: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
7241: '<table><tr>';
1.257 raeburn 7242: foreach my $type (@types) {
1.306 raeburn 7243: $additional .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.257 raeburn 7244: '<input type="text" name="'.$type.'_timeout" value="'.
7245: $deftimeout{$type}.'" size="5" /></td>';
7246: }
7247: $additional .= '</tr></table></div>'."\n";
7248: %defaultchecked = ('postsubmit' => 'on');
7249: @toggles = ('postsubmit');
1.280 raeburn 7250: $current = {
7251: 'postsubmit' => $postsubmitclient,
7252: };
1.257 raeburn 7253: ($table,$itemcount) =
7254: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7255: \%choices,$itemcount,$onclick,$additional,'left');
1.192 raeburn 7256: $datatable .= $table;
1.276 raeburn 7257: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7258: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7259: $choices{'mysqltables'}.
7260: '</span></td>'.
1.306 raeburn 7261: '<td style="text-align: right" class="LC_right_item">'.
1.276 raeburn 7262: '<table><tr>';
7263: foreach my $type (@types) {
1.306 raeburn 7264: $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
1.276 raeburn 7265: '<input type="text" name="mysqltables_'.$type.'"'.
1.295 raeburn 7266: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.276 raeburn 7267: }
7268: $datatable .= '</tr></table></td></tr>'."\n";
7269: $itemcount ++;
1.404 raeburn 7270: %defaultchecked = ('ltiauth' => 'off');
7271: @toggles = ('ltiauth');
7272: $current = {
7273: 'ltiauth' => $ltiauth,
7274: };
7275: ($table,$itemcount) =
7276: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
7277: \%choices,$itemcount,undef,undef,'left');
7278: $datatable .= $table;
1.422 raeburn 7279: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7280: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7281: $choices{'domexttool'}.
7282: '</span></td>'.
7283: '<td style="text-align: right" class="LC_right_item">'.
7284: '<table><tr>';
7285: foreach my $type (@types) {
7286: $datatable .= '<td style="text-align: left">'.
7287: '<span class="LC_nobreak">'.
1.438 raeburn 7288: '<label><input type="checkbox" name="domexttool"'.
1.422 raeburn 7289: ' value="'.$type.'"'.$domexttool{$type}.' />'.
1.438 raeburn 7290: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7291: }
7292: $datatable .= '</tr></table></td></tr>'."\n";
1.404 raeburn 7293: $itemcount ++;
1.422 raeburn 7294: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7295: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7296: $choices{'exttool'}.
7297: '</span></td>'.
7298: '<td style="text-align: right" class="LC_right_item">'.
7299: '<table><tr>';
7300: foreach my $type (@types) {
7301: $datatable .= '<td style="text-align: left">'.
7302: '<span class="LC_nobreak">'.
1.438 raeburn 7303: '<label><input type="checkbox" name="exttool"'.
1.422 raeburn 7304: ' value="'.$type.'"'.$exttool{$type}.' />'.
1.438 raeburn 7305: &mt($type).'</label></span></td>'."\n";
1.422 raeburn 7306: }
7307: $datatable .= '</tr></table></td></tr>'."\n";
1.432 raeburn 7308: $itemcount ++;
7309: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7310: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7311: $choices{'crsauthor'}.
7312: '</span></td>'.
7313: '<td style="text-align: right" class="LC_right_item">'.
7314: '<table><tr>';
7315: foreach my $type (@types) {
7316: $datatable .= '<td style="text-align: left">'.
7317: '<span class="LC_nobreak">'.
1.438 raeburn 7318: '<label><input type="checkbox" name="crsauthor"'.
1.432 raeburn 7319: ' value="'.$type.'"'.$crsauthor{$type}.' />'.
1.438 raeburn 7320: &mt($type).'</label></span></td>'."\n";
7321: }
7322: $datatable .= '</tr></table></td></tr>'."\n";
7323: $itemcount ++;
7324: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7325: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7326: $choices{'crseditors'}.
7327: '</span></td>'.
7328: '<td style="text-align: right" class="LC_right_item">'.
7329: '<table><tr>';
7330: my @editors = ('edit','xml','daxe');
7331: my %editornames = &crseditor_titles();
7332: foreach my $editor (@editors) {
7333: $datatable .= '<td style="text-align: left">'.
7334: '<span class="LC_nobreak">'.
7335: '<label><input type="checkbox" name="crseditors"'.
7336: ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
7337: $editornames{$editor}.'</label></span></td>'."\n";
1.432 raeburn 7338: }
7339: $datatable .= '</tr></table></td></tr>'."\n";
1.139 raeburn 7340: }
1.192 raeburn 7341: $$rowtotal += $itemcount;
1.121 raeburn 7342: return $datatable;
1.118 jms 7343: }
7344:
1.438 raeburn 7345: sub crseditor_titles {
7346: return &Apache::lonlocal::texthash(
7347: edit => 'Standard editor (Edit)',
7348: xml => 'Text editor (EditXML)',
7349: daxe => 'Daxe editor (Daxe)',
7350: );
7351: }
7352:
1.429 raeburn 7353: sub print_authordefaults {
7354: my ($position,$dom,$settings,$rowtotal) = @_;
7355: my ($css_class,$datatable,%checkedon,%checkedoff);
7356: my $itemcount = 1;
7357: my %titles = &authordefaults_titles();
7358: if ($position eq 'top') {
7359: my %defaultchecked = (
7360: 'nocodemirror' => 'off',
1.437 raeburn 7361: 'daxecollapse' => 'off',
1.429 raeburn 7362: 'domcoordacc' => 'on',
7363: );
1.437 raeburn 7364: my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
1.429 raeburn 7365: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
7366: \%titles,$itemcount);
7367: my %staticdefaults = (
7368: 'copyright' => 'default',
7369: 'sourceavail' => 'closed',
7370: );
7371: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7372: my %currrights;
7373: foreach my $item ('copyright','sourceavail') {
7374: $currrights{$item} = $staticdefaults{$item};
7375: if (ref($settings) eq 'HASH') {
7376: if (exists($settings->{$item})) {
7377: $currrights{$item} = $settings->{$item};
7378: }
7379: }
7380: }
7381: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7382: '<span class="LC_nobreak">'.$titles{'copyright'}.
7383: '</span></td><td class="LC_right_item">'.
7384: &selectbox('copyright',$currrights{'copyright'},'',
7385: \&Apache::loncommon::copyrightdescription,
7386: (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
7387: '</td></tr>'."\n";
7388: $itemcount ++;
7389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7390: $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
7391: '<span class="LC_nobreak">'.$titles{'sourceavail'}.
7392: '</span></td><td class="LC_right_item">'.
7393: &selectbox('sourceavail',$currrights{'sourceavail'},'',
7394: \&Apache::loncommon::source_copyrightdescription,
7395: (&Apache::loncommon::source_copyrightids)).
7396: '</td></tr>'."\n";
7397: } else {
7398: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7399: my $curreditors;
7400: my %staticdefaults = (
7401: editors => ['edit','xml'],
7402: authorquota => 500,
7403: webdav => 0,
7404: );
7405: my $curreditors = $staticdefaults{'editors'};
7406: if ((ref($settings) eq 'HASH') &&
7407: (ref($settings->{'editors'}) eq 'ARRAY')) {
7408: $curreditors = $settings->{'editors'};
7409: } else {
7410: $curreditors = $staticdefaults{'editors'};
7411: }
7412: my @editors = ('edit','xml','daxe');
7413: $datatable = '<tr'.$css_class.'>'."\n".
7414: '<td>'.$titles{'editors'}.'</td>'."\n".
7415: '<td class="LC_left_item">'."\n".
7416: '<span class="LC_nobreak">';
7417: foreach my $editor (@editors) {
7418: my $checked;
7419: if (grep(/^\Q$editor\E$/,@{$curreditors})) {
7420: $checked = ' checked="checked"';
7421: }
7422: $datatable .= '<label>'.
7423: '<input type="checkbox" name="author_editors" '.
7424: $checked.' value="'.$editor.'" '.
7425: 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
7426: $titles{$editor}.'</label> ';
7427: }
7428: $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
7429: $itemcount ++;
7430: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7431: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7432: my @insttypes;
7433: if (ref($types) eq 'ARRAY') {
7434: @insttypes = @{$types};
7435: }
7436: my $typecount = 0;
7437: my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
7438: my @items = ('webdav','authorquota');
7439: my %quotas;
7440: if (ref($domconf{'quotas'}) eq 'HASH') {
7441: %quotas = %{$domconf{'quotas'}};
7442: foreach my $item (@items) {
7443: if (ref($quotas{$item}) eq 'HASH') {
7444: foreach my $type (@insttypes,'default') {
7445: if ($item eq 'authorquota') {
7446: if ($quotas{$item}{$type} !~ /^\d+$/) {
7447: $quotas{$item}{$type} = $staticdefaults{$item};
7448: }
7449: } elsif ($item eq 'webdav') {
7450: if ($quotas{$item}{$type} !~ /^(0|1)$/) {
7451: $quotas{$item}{$type} = $staticdefaults{$item};
7452: }
7453: }
7454: }
7455: } else {
7456: foreach my $type (@insttypes,'default') {
7457: $quotas{$item}{$type} = $staticdefaults{$item};
7458: }
7459: }
7460: }
7461: } else {
7462: foreach my $item (@items) {
7463: foreach my $type (@insttypes,'default') {
7464: $quotas{$item}{$type} = $staticdefaults{$item};
7465: }
7466: }
7467: }
7468: if (ref($usertypes) eq 'HASH') {
7469: my $numinrow = 4;
7470: my $onclick = '';
7471: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7472: $numinrow,$othertitle,'authorquota',
7473: \$itemcount,$onclick);
7474: $itemcount ++;
7475: $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
7476: $numinrow,$othertitle,'webdav',
7477: \$itemcount);
7478: $itemcount ++;
7479: }
7480: my $checkedno = ' checked="checked"';
7481: my ($checkedon,$checkedoff);
7482: if (ref($quotas{'webdav'}) eq 'HASH') {
1.436 raeburn 7483: if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
1.429 raeburn 7484: if ($quotas{'webdav'}{'_LC_adv'}) {
7485: $checkedon = $checkedno;
7486: } else {
7487: $checkedoff = $checkedno;
7488: }
7489: undef($checkedno);
7490: }
7491: }
7492: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7493: $datatable .= '<tr'.$css_class.'>'.
7494: '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
7495: $titles{'webdav_LC_adv_over'}.
7496: '</td>'.
7497: '<td class="LC_left_item">';
7498: foreach my $option ('none','off','on') {
7499: my ($text,$val,$checked);
7500: if ($option eq 'none') {
7501: $text = $titles{'none'};
7502: $val = '';
7503: $checked = $checkedno;
7504: } elsif ($option eq 'off') {
7505: $text = $titles{'overoff'};
7506: $val = 0;
7507: $checked = $checkedoff;
7508: } elsif ($option eq 'on') {
7509: $text = $titles{'overon'};
7510: $val = 1;
7511: $checked = $checkedon;
1.436 raeburn 7512: }
1.429 raeburn 7513: $datatable .= '<span class="LC_nobreak"><label>'.
7514: '<input type="radio" name="webdav_LC_adv"'.
7515: ' value="'.$val.'"'.$checked.' />'.
7516: $text.'</label></span> ';
7517: }
7518: $datatable .= '</td></tr>';
7519: $itemcount ++;
1.440 raeburn 7520: my %defchecked = (
7521: 'archive' => 'off',
7522: );
7523: my @toggles = ('archive');
7524: (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
7525: {'archive' => 'off'},
7526: \%titles,$itemcount);
7527: $datatable .= $archive."\n";
7528: $itemcount ++;
1.429 raeburn 7529: }
7530: $$rowtotal += $itemcount;
7531: return $datatable;
7532: }
7533:
7534: sub authordefaults_titles {
7535: return &Apache::lonlocal::texthash(
7536: copyright => 'Copyright/Distribution',
7537: sourceavail => ' Source Available',
7538: editors => 'Available Editors',
7539: webdav => 'WebDAV',
7540: authorquota => 'Authoring Space quotas (MB)',
7541: nocodemirror => 'Deactivate CodeMirror for EditXML editor',
1.437 raeburn 7542: daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
1.429 raeburn 7543: domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
7544: edit => 'Standard editor (Edit)',
7545: xml => 'Text editor (EditXML)',
7546: daxe => 'Daxe editor (Daxe)',
7547: webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
7548: webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
7549: none => 'No override set',
7550: overon => 'Override -- webDAV on',
1.436 raeburn 7551: overoff => 'Override -- webDAV off',
1.440 raeburn 7552: archive => 'Authors can download tar.gz file of Authoring Space',
1.429 raeburn 7553: );
7554: }
7555:
7556: sub selectbox {
7557: my ($name,$value,$readonly,$functionref,@idlist)=@_;
7558: my $selout = '<select name="'.$name.'">';
7559: foreach my $id (@idlist) {
7560: $selout.='<option value="'.$id.'"';
7561: if ($id eq $value) {
7562: $selout.=' selected="selected"';
7563: }
7564: if ($readonly) {
7565: $selout .= ' disabled="disabled"';
7566: }
7567: $selout.='>'.&{$functionref}($id).'</option>';
7568: }
7569: $selout.='</select>';
7570: return $selout;
7571: }
7572:
1.231 raeburn 7573: sub print_selfenrollment {
7574: my ($position,$dom,$settings,$rowtotal) = @_;
7575: my ($css_class,$datatable);
7576: my $itemcount = 1;
1.271 raeburn 7577: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 7578: if (($position eq 'top') || ($position eq 'middle')) {
1.232 raeburn 7579: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
7580: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
1.231 raeburn 7581: my @rows;
7582: my $key;
7583: if ($position eq 'top') {
7584: $key = 'admin';
7585: if (ref($rowsref) eq 'ARRAY') {
7586: @rows = @{$rowsref};
7587: }
7588: } elsif ($position eq 'middle') {
7589: $key = 'default';
7590: @rows = ('types','registered','approval','limit');
7591: }
7592: foreach my $row (@rows) {
7593: if (defined($titlesref->{$row})) {
7594: $itemcount ++;
7595: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7596: $datatable .= '<tr'.$css_class.'>'.
7597: '<td>'.$titlesref->{$row}.'</td>'.
7598: '<td class="LC_left_item">'.
7599: '<table><tr>';
7600: my (%current,%currentcap);
7601: if (ref($settings) eq 'HASH') {
7602: if (ref($settings->{$key}) eq 'HASH') {
7603: foreach my $type (@types) {
7604: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7605: $current{$type} = $settings->{$key}->{$type}->{$row};
7606: }
7607: if (($row eq 'limit') && ($key eq 'default')) {
7608: if (ref($settings->{$key}->{$type}) eq 'HASH') {
7609: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
7610: }
7611: }
7612: }
7613: }
7614: }
7615: my %roles = (
7616: '0' => &Apache::lonnet::plaintext('dc'),
7617: );
7618:
7619: foreach my $type (@types) {
7620: unless (($row eq 'registered') && ($key eq 'default')) {
7621: $datatable .= '<th>'.&mt($type).'</th>';
7622: }
7623: }
7624: unless (($row eq 'registered') && ($key eq 'default')) {
7625: $datatable .= '</tr><tr>';
7626: }
7627: foreach my $type (@types) {
7628: if ($type eq 'community') {
7629: $roles{'1'} = &mt('Community personnel');
7630: } else {
7631: $roles{'1'} = &mt('Course personnel');
7632: }
7633: $datatable .= '<td style="vertical-align: top">';
7634: if ($position eq 'top') {
7635: my %checked;
7636: if ($current{$type} eq '0') {
7637: $checked{'0'} = ' checked="checked"';
7638: } else {
7639: $checked{'1'} = ' checked="checked"';
7640: }
7641: foreach my $role ('1','0') {
7642: $datatable .= '<span class="LC_nobreak"><label>'.
7643: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
7644: 'value="'.$role.'"'.$checked{$role}.' />'.
7645: $roles{$role}.'</label></span> ';
7646: }
7647: } else {
7648: if ($row eq 'types') {
7649: my %checked;
7650: if ($current{$type} =~ /^(all|dom)$/) {
7651: $checked{$1} = ' checked="checked"';
7652: } else {
7653: $checked{''} = ' checked="checked"';
7654: }
7655: foreach my $val ('','dom','all') {
7656: $datatable .= '<span class="LC_nobreak"><label>'.
7657: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7658: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7659: }
7660: } elsif ($row eq 'registered') {
7661: my %checked;
7662: if ($current{$type} eq '1') {
7663: $checked{'1'} = ' checked="checked"';
7664: } else {
7665: $checked{'0'} = ' checked="checked"';
7666: }
7667: foreach my $val ('0','1') {
7668: $datatable .= '<span class="LC_nobreak"><label>'.
7669: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7670: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7671: }
7672: } elsif ($row eq 'approval') {
7673: my %checked;
7674: if ($current{$type} =~ /^([12])$/) {
7675: $checked{$1} = ' checked="checked"';
7676: } else {
7677: $checked{'0'} = ' checked="checked"';
7678: }
7679: for my $val (0..2) {
7680: $datatable .= '<span class="LC_nobreak"><label>'.
7681: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7682: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7683: }
7684: } elsif ($row eq 'limit') {
7685: my %checked;
7686: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
7687: $checked{$1} = ' checked="checked"';
7688: } else {
7689: $checked{'none'} = ' checked="checked"';
7690: }
7691: my $cap;
7692: if ($currentcap{$type} =~ /^\d+$/) {
7693: $cap = $currentcap{$type};
7694: }
7695: foreach my $val ('none','allstudents','selfenrolled') {
7696: $datatable .= '<span class="LC_nobreak"><label>'.
7697: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
7698: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
7699: }
7700: $datatable .= '<br />'.
7701: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
7702: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
7703: '</span>';
7704: }
7705: }
7706: $datatable .= '</td>';
7707: }
7708: $datatable .= '</tr>';
7709: }
7710: $datatable .= '</table></td></tr>';
7711: }
7712: } elsif ($position eq 'bottom') {
1.235 raeburn 7713: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
7714: }
7715: $$rowtotal += $itemcount;
7716: return $datatable;
7717: }
7718:
7719: sub print_validation_rows {
7720: my ($caller,$dom,$settings,$rowtotal) = @_;
7721: my ($itemsref,$namesref,$fieldsref);
7722: if ($caller eq 'selfenroll') {
7723: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
7724: } elsif ($caller eq 'requestcourses') {
7725: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
7726: }
7727: my %currvalidation;
7728: if (ref($settings) eq 'HASH') {
7729: if (ref($settings->{'validation'}) eq 'HASH') {
7730: %currvalidation = %{$settings->{'validation'}};
1.231 raeburn 7731: }
1.235 raeburn 7732: }
7733: my $datatable;
7734: my $itemcount = 0;
7735: foreach my $item (@{$itemsref}) {
7736: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7737: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
7738: $namesref->{$item}.
7739: '</span></td>'.
7740: '<td class="LC_left_item">';
7741: if (($item eq 'url') || ($item eq 'button')) {
7742: $datatable .= '<span class="LC_nobreak">'.
7743: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
7744: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
7745: } elsif ($item eq 'fields') {
7746: my @currfields;
7747: if (ref($currvalidation{$item}) eq 'ARRAY') {
7748: @currfields = @{$currvalidation{$item}};
7749: }
7750: foreach my $field (@{$fieldsref}) {
7751: my $check = '';
7752: if (grep(/^\Q$field\E$/,@currfields)) {
7753: $check = ' checked="checked"';
7754: }
7755: $datatable .= '<span class="LC_nobreak"><label>'.
7756: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
7757: ' value="'.$field.'"'.$check.' />'.$field.
7758: '</label></span> ';
7759: }
7760: } elsif ($item eq 'markup') {
1.334 raeburn 7761: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.235 raeburn 7762: $currvalidation{$item}.
1.231 raeburn 7763: '</textarea>';
1.235 raeburn 7764: }
7765: $datatable .= '</td></tr>'."\n";
7766: if (ref($rowtotal)) {
1.231 raeburn 7767: $itemcount ++;
7768: }
7769: }
1.235 raeburn 7770: if ($caller eq 'requestcourses') {
7771: my %currhash;
1.248 raeburn 7772: if (ref($settings) eq 'HASH') {
7773: if (ref($settings->{'validation'}) eq 'HASH') {
7774: if ($settings->{'validation'}{'dc'} ne '') {
7775: $currhash{$settings->{'validation'}{'dc'}} = 1;
7776: }
1.235 raeburn 7777: }
7778: }
7779: my $numinrow = 2;
7780: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
7781: 'validationdc',%currhash);
1.247 raeburn 7782: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.334 raeburn 7783: $datatable .= '<tr'.$css_class.'><td>';
1.235 raeburn 7784: if ($numdc > 1) {
1.247 raeburn 7785: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.235 raeburn 7786: } else {
1.247 raeburn 7787: $datatable .= &mt('Course creation processed as: ');
1.235 raeburn 7788: }
1.247 raeburn 7789: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.235 raeburn 7790: $itemcount ++;
7791: }
7792: if (ref($rowtotal)) {
7793: $$rowtotal += $itemcount;
7794: }
1.231 raeburn 7795: return $datatable;
7796: }
7797:
1.357 raeburn 7798: sub print_privacy {
7799: my ($position,$dom,$settings,$rowtotal) = @_;
7800: my ($datatable,$css_class,$numinrow,@items,%names,$othertitle,$usertypes,$types);
7801: my $itemcount = 0;
1.417 raeburn 7802: if ($position eq 'top') {
7803: $numinrow = 2;
7804: } else {
1.357 raeburn 7805: @items = ('domain','author','course','community');
7806: %names = &Apache::lonlocal::texthash (
7807: domain => 'Assigned domain role(s)',
7808: author => 'Assigned co-author role(s)',
7809: course => 'Assigned course role(s)',
1.416 raeburn 7810: community => 'Assigned community role(s)',
1.357 raeburn 7811: );
7812: $numinrow = 4;
7813: ($othertitle,$usertypes,$types) =
7814: &Apache::loncommon::sorted_inst_types($dom);
7815: }
7816: if (($position eq 'top') || ($position eq 'middle')) {
7817: my (%by_ip,%by_location,@intdoms,@instdoms);
7818: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
7819: if ($position eq 'top') {
7820: my %curr;
7821: my @options = ('none','user','domain','auto');
7822: my %titles = &Apache::lonlocal::texthash (
7823: none => 'Not allowed',
7824: user => 'User authorizes',
7825: domain => 'DC authorizes',
7826: auto => 'Unrestricted',
7827: instdom => 'Other domain shares institution/provider',
7828: extdom => 'Other domain has different institution/provider',
1.418 raeburn 7829: notify => 'Notify when role needs authorization',
1.357 raeburn 7830: );
7831: my %names = &Apache::lonlocal::texthash (
7832: domain => 'Domain role',
7833: author => 'Co-author role',
7834: course => 'Course role',
7835: community => 'Community role',
7836: );
7837: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7838: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7839: foreach my $domtype ('instdom','extdom') {
7840: my (%checked,$skip);
7841: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7842: $datatable .= '<tr'.$css_class.'><td>'.$titles{$domtype}.'</td>'.
7843: '<td class="LC_left_item">';
7844: if ($domtype eq 'instdom') {
7845: unless (@instdoms > 1) {
7846: $datatable .= &mt('Nothing to set, as no domains besides [_1] are hosted by [_2]',$dom,$intdom);
7847: $skip = 1;
7848: }
7849: } elsif ($domtype eq 'extdom') {
7850: if (keys(%by_location) == 0) {
7851: $datatable .= &mt('Nothing to set, as no other hosts besides [_1]',$intdom);
7852: $skip = 1;
7853: }
7854: }
7855: unless ($skip) {
7856: foreach my $roletype ('domain','author','course','community') {
7857: $checked{'auto'} = ' checked="checked"';
7858: if (ref($settings) eq 'HASH') {
7859: if (ref($settings->{approval}) eq 'HASH') {
7860: if (ref($settings->{approval}->{$domtype}) eq 'HASH') {
7861: if ($settings->{approval}->{$domtype}->{$roletype}=~ /^(none|user|domain)$/) {
7862: $checked{$1} = ' checked="checked"';
7863: $checked{'auto'} = '';
7864: }
7865: }
7866: }
7867: }
7868: $datatable .= '<fieldset><legend>'.$names{$roletype}.'</legend>';
7869: foreach my $option (@options) {
7870: $datatable .= '<span class="LC_nobreak"><label>'.
7871: '<input type="radio" name="privacy_approval_'.$domtype.'_'.$roletype.'" '.
7872: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
7873: '</label></span> ';
7874: }
7875: $datatable .= '</fieldset>';
7876: }
7877: }
7878: $datatable .= '</td></tr>';
7879: $itemcount ++;
7880: }
1.417 raeburn 7881: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7882: $datatable .= '<tr'.$css_class.'><td>'.$titles{'notify'}.'</td>'.
7883: '<td class="LC_left_item">';
7884: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7885: my %curr;
7886: if (ref($settings) eq 'HASH') {
7887: if ($settings->{'notify'} ne '') {
7888: map {$curr{$_}=1;} split(/,/,$settings->{'notify'});
7889: }
7890: }
7891: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7892: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
7893: 'privacy_notify',%curr);
7894: if ($numdc > 0) {
7895: $datatable .= $table;
7896: } else {
7897: $datatable .= &mt('There are no active Domain Coordinators');
7898: }
7899: } else {
7900: $datatable .= &mt('Nothing to set here, as there are no other domains');
7901: }
7902: $datatable .='</td></tr>';
1.357 raeburn 7903: } elsif ($position eq 'middle') {
7904: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
7905: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7906: foreach my $item (@{$types}) {
7907: $datatable .= &modifiable_userdata_row('privacy','othdom_'.$item,$settings,
7908: $numinrow,$itemcount,'','','','','',
7909: '',$usertypes->{$item});
7910: $itemcount ++;
7911: }
7912: }
7913: $datatable .= &modifiable_userdata_row('privacy','othdom_default',$settings,
7914: $numinrow,$itemcount,'','','','','',
7915: '',$othertitle);
7916: $itemcount ++;
7917: } else {
1.360 raeburn 7918: my (@insttypes,%insttitles);
7919: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7920: @insttypes = @{$types};
7921: %insttitles = %{$usertypes};
7922: }
7923: foreach my $item (@insttypes,'default') {
7924: my $title;
7925: if ($item eq 'default') {
7926: $title = $othertitle;
7927: } else {
7928: $title = $insttitles{$item};
7929: }
7930: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7931: $datatable .= '<tr'.$css_class.'>'.
7932: '<td class="LC_left_item">'.$title.'</td>'.
7933: '<td class="LC_left_item">'.
7934: &mt('Nothing to set here, as there are no other domains').
7935: '</td></tr>';
7936: $itemcount ++;
7937: }
1.357 raeburn 7938: }
7939: }
7940: } else {
7941: my $prefix;
7942: if ($position eq 'lower') {
7943: $prefix = 'priv';
7944: } else {
7945: $prefix = 'unpriv';
7946: }
7947: foreach my $item (@items) {
7948: $datatable .= &modifiable_userdata_row('privacy',$prefix.'_'.$item,$settings,
7949: $numinrow,$itemcount,'','','','','',
7950: '',$names{$item});
7951: $itemcount ++;
7952: }
7953: }
7954: if (ref($rowtotal)) {
7955: $$rowtotal += $itemcount;
7956: }
7957: return $datatable;
7958: }
7959:
1.354 raeburn 7960: sub print_passwords {
7961: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
7962: my ($datatable,$css_class);
7963: my $itemcount = 0;
7964: my %titles = &Apache::lonlocal::texthash (
7965: captcha => '"Forgot Password" CAPTCHA validation',
7966: link => 'Reset link expiration (hours)',
7967: case => 'Case-sensitive usernames/e-mail',
7968: prelink => 'Information required (form 1)',
7969: postlink => 'Information required (form 2)',
7970: emailsrc => 'LON-CAPA e-mail address type(s)',
7971: customtext => 'Domain specific text (HTML)',
7972: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
7973: intauth_check => 'Check bcrypt cost if authenticated',
7974: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
7975: permanent => 'Permanent e-mail address',
7976: critical => 'Critical notification address',
7977: notify => 'Notification address',
7978: min => 'Minimum password length',
7979: max => 'Maximum password length',
7980: chars => 'Required characters',
7981: expire => 'Password expiration (days)',
1.356 raeburn 7982: numsaved => 'Number of previous passwords to save and disallow reuse',
1.354 raeburn 7983: );
7984: if ($position eq 'top') {
7985: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7986: my $shownlinklife = 2;
7987: my $prelink = 'both';
7988: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
7989: if (ref($settings) eq 'HASH') {
7990: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
7991: $shownlinklife = $settings->{resetlink};
7992: }
7993: if (ref($settings->{resetcase}) eq 'ARRAY') {
7994: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
7995: }
7996: if ($settings->{resetprelink} =~ /^(both|either)$/) {
7997: $prelink = $settings->{resetprelink};
7998: }
7999: if (ref($settings->{resetpostlink}) eq 'HASH') {
8000: %postlink = %{$settings->{resetpostlink}};
8001: }
8002: if (ref($settings->{resetemail}) eq 'ARRAY') {
8003: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
8004: }
8005: if ($settings->{resetremove}) {
8006: $nostdtext = 1;
8007: }
8008: if ($settings->{resetcustom}) {
8009: $customurl = $settings->{resetcustom};
8010: }
8011: } else {
8012: if (ref($types) eq 'ARRAY') {
8013: foreach my $item (@{$types}) {
8014: $casesens{$item} = 1;
8015: $postlink{$item} = ['username','email'];
8016: }
8017: }
8018: $casesens{'default'} = 1;
8019: $postlink{'default'} = ['username','email'];
8020: $prelink = 'both';
8021: %emailsrc = (
8022: permanent => 1,
8023: critical => 1,
8024: notify => 1,
8025: );
8026: }
8027: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
8028: $itemcount ++;
8029: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8030: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
8031: '<td class="LC_left_item">'.
8032: '<input type="textbox" value="'.$shownlinklife.'" '.
8033: 'name="passwords_link" size="3" /></td></tr>';
8034: $itemcount ++;
8035: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8036: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
8037: '<td class="LC_left_item">';
8038: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8039: foreach my $item (@{$types}) {
8040: my $checkedcase;
8041: if ($casesens{$item}) {
8042: $checkedcase = ' checked="checked"';
8043: }
8044: $datatable .= '<span class="LC_nobreak"><label>'.
8045: '<input type="checkbox" name="passwords_case_sensitive" value="'.
8046: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.369 raeburn 8047: '</span> ';
1.354 raeburn 8048: }
8049: }
8050: my $checkedcase;
8051: if ($casesens{'default'}) {
8052: $checkedcase = ' checked="checked"';
8053: }
8054: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8055: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
8056: $othertitle.'</label></span></td>';
8057: $itemcount ++;
8058: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8059: my %checkedpre = (
8060: both => ' checked="checked"',
8061: either => '',
8062: );
8063: if ($prelink eq 'either') {
8064: $checkedpre{either} = ' checked="checked"';
8065: $checkedpre{both} = '';
8066: }
8067: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
8068: '<td class="LC_left_item"><span class="LC_nobreak">'.
8069: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
8070: &mt('Both username and e-mail address').'</label></span> '.
8071: '<span class="LC_nobreak"><label>'.
8072: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
8073: &mt('Either username or e-mail address').'</label></span></td></tr>';
8074: $itemcount ++;
8075: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8076: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
8077: '<td class="LC_left_item">';
8078: my %postlinked;
8079: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8080: foreach my $item (@{$types}) {
8081: undef(%postlinked);
8082: $datatable .= '<fieldset style="display: inline-block;">'.
8083: '<legend>'.$usertypes->{$item}.'</legend>';
8084: if (ref($postlink{$item}) eq 'ARRAY') {
8085: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
8086: }
8087: foreach my $field ('email','username') {
8088: my $checked;
8089: if ($postlinked{$field}) {
8090: $checked = ' checked="checked"';
8091: }
8092: $datatable .= '<span class="LC_nobreak"><label>'.
8093: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
8094: $field.'"'.$checked.' />'.$field.'</label>'.
8095: '<span> ';
8096: }
8097: $datatable .= '</fieldset>';
8098: }
8099: }
8100: if (ref($postlink{'default'}) eq 'ARRAY') {
8101: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
8102: }
8103: $datatable .= '<fieldset style="display: inline-block;">'.
8104: '<legend>'.$othertitle.'</legend>';
8105: foreach my $field ('email','username') {
8106: my $checked;
8107: if ($postlinked{$field}) {
8108: $checked = ' checked="checked"';
8109: }
8110: $datatable .= '<span class="LC_nobreak"><label>'.
8111: '<input type="checkbox" name="passwords_postlink_default" value="'.
8112: $field.'"'.$checked.' />'.$field.'</label>'.
8113: '<span> ';
8114: }
8115: $datatable .= '</fieldset></td></tr>';
8116: $itemcount ++;
8117: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8118: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
8119: '<td class="LC_left_item">';
8120: foreach my $type ('permanent','critical','notify') {
8121: my $checkedemail;
8122: if ($emailsrc{$type}) {
8123: $checkedemail = ' checked="checked"';
8124: }
8125: $datatable .= '<span class="LC_nobreak"><label>'.
8126: '<input type="checkbox" name="passwords_emailsrc" value="'.
8127: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
8128: '<span> ';
8129: }
8130: $datatable .= '</td></tr>';
8131: $itemcount ++;
8132: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8133: my $switchserver = &check_switchserver($dom,$confname);
8134: my ($showstd,$noshowstd);
8135: if ($nostdtext) {
8136: $noshowstd = ' checked="checked"';
8137: } else {
8138: $showstd = ' checked="checked"';
8139: }
8140: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
8141: '<td class="LC_left_item"><span class="LC_nobreak">'.
8142: &mt('Retain standard text:').
8143: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
8144: &mt('Yes').'</label>'.' '.
8145: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
8146: &mt('No').'</label></span><br />'.
8147: '<span class="LC_fontsize_small">'.
8148: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
8149: &mt('Include custom text:');
8150: if ($customurl) {
1.369 raeburn 8151: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.354 raeburn 8152: undef,undef,undef,undef,'background-color:#ffffff');
8153: $datatable .= '<span class="LC_nobreak"> '.$link.
8154: '<label><input type="checkbox" name="passwords_custom_del"'.
8155: ' value="1" />'.&mt('Delete?').'</label></span>'.
8156: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
8157: }
8158: if ($switchserver) {
8159: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
8160: } else {
8161: $datatable .='<span class="LC_nobreak"> '.
8162: '<input type="file" name="passwords_customfile" /></span>';
8163: }
8164: $datatable .= '</td></tr>';
8165: } elsif ($position eq 'middle') {
8166: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
8167: my @items = ('intauth_cost','intauth_check','intauth_switch');
8168: my %defaults;
8169: if (ref($domconf{'defaults'}) eq 'HASH') {
8170: %defaults = %{$domconf{'defaults'}};
8171: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
8172: $defaults{'intauth_cost'} = 10;
8173: }
8174: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
8175: $defaults{'intauth_check'} = 0;
8176: }
8177: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
8178: $defaults{'intauth_switch'} = 0;
8179: }
8180: } else {
8181: %defaults = (
8182: 'intauth_cost' => 10,
8183: 'intauth_check' => 0,
8184: 'intauth_switch' => 0,
8185: );
8186: }
8187: foreach my $item (@items) {
8188: if ($itemcount%2) {
8189: $css_class = '';
8190: } else {
8191: $css_class = ' class="LC_odd_row" ';
8192: }
8193: $datatable .= '<tr'.$css_class.'>'.
8194: '<td><span class="LC_nobreak">'.$titles{$item}.
8195: '</span></td><td class="LC_left_item" colspan="3">';
8196: if ($item eq 'intauth_switch') {
8197: my @options = (0,1,2);
8198: my %optiondesc = &Apache::lonlocal::texthash (
8199: 0 => 'No',
8200: 1 => 'Yes',
8201: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
8202: );
8203: $datatable .= '<table width="100%">';
8204: foreach my $option (@options) {
8205: my $checked = ' ';
8206: if ($defaults{$item} eq $option) {
8207: $checked = ' checked="checked"';
8208: }
8209: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8210: '<label><input type="radio" name="'.$item.
8211: '" value="'.$option.'"'.$checked.' />'.
8212: $optiondesc{$option}.'</label></span></td></tr>';
8213: }
8214: $datatable .= '</table>';
8215: } elsif ($item eq 'intauth_check') {
8216: my @options = (0,1,2);
8217: my %optiondesc = &Apache::lonlocal::texthash (
8218: 0 => 'No',
8219: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
8220: 2 => 'Yes, disallow login if stored cost is less than domain default',
8221: );
8222: $datatable .= '<table width="100%">';
8223: foreach my $option (@options) {
8224: my $checked = ' ';
8225: my $onclick;
8226: if ($defaults{$item} eq $option) {
8227: $checked = ' checked="checked"';
8228: }
8229: if ($option == 2) {
8230: $onclick = ' onclick="javascript:warnIntAuth(this);"';
8231: }
8232: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
8233: '<label><input type="radio" name="'.$item.
8234: '" value="'.$option.'"'.$checked.$onclick.' />'.
8235: $optiondesc{$option}.'</label></span></td></tr>';
8236: }
8237: $datatable .= '</table>';
8238: } else {
8239: $datatable .= '<input type="text" name="'.$item.'" value="'.
8240: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
8241: }
8242: $datatable .= '</td></tr>';
8243: $itemcount ++;
8244: }
8245: } elsif ($position eq 'lower') {
1.405 raeburn 8246: $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.354 raeburn 8247: } else {
1.359 raeburn 8248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
8249: my %ownerchg = (
8250: by => {},
8251: for => {},
8252: );
8253: my %ownertitles = &Apache::lonlocal::texthash (
8254: by => 'Course owner status(es) allowed',
8255: for => 'Student status(es) allowed',
8256: );
1.354 raeburn 8257: if (ref($settings) eq 'HASH') {
1.359 raeburn 8258: if (ref($settings->{crsownerchg}) eq 'HASH') {
8259: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
8260: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
8261: }
8262: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
8263: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
8264: }
1.354 raeburn 8265: }
8266: }
8267: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8268: $datatable .= '<tr '.$css_class.'>'.
8269: '<td>'.
8270: &mt('Requirements').'<ul>'.
1.359 raeburn 8271: '<li>'.&mt("Course 'type' is not a Community or Placement Test").'</li>'.
1.354 raeburn 8272: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
8273: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
1.359 raeburn 8274: '<li>'.&mt('User, course, and student share same domain').'</li>'.
1.354 raeburn 8275: '</ul>'.
8276: '</td>'.
1.359 raeburn 8277: '<td class="LC_left_item">';
8278: foreach my $item ('by','for') {
8279: $datatable .= '<fieldset style="display: inline-block;">'.
8280: '<legend>'.$ownertitles{$item}.'</legend>';
8281: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
8282: foreach my $type (@{$types}) {
8283: my $checked;
8284: if ($ownerchg{$item}{$type}) {
8285: $checked = ' checked="checked"';
8286: }
8287: $datatable .= '<span class="LC_nobreak"><label>'.
8288: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
8289: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.369 raeburn 8290: '</span> ';
1.359 raeburn 8291: }
8292: }
8293: my $checked;
8294: if ($ownerchg{$item}{'default'}) {
8295: $checked = ' checked="checked"';
8296: }
8297: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
8298: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
8299: $othertitle.'</label></span></fieldset>';
8300: }
8301: $datatable .= '</td></tr>';
1.354 raeburn 8302: }
8303: return $datatable;
8304: }
8305:
1.405 raeburn 8306: sub password_rules {
8307: my ($prefix,$itemcountref,$settings) = @_;
8308: my ($min,$max,%chars,$expire,$numsaved,$numinrow);
8309: my %titles;
8310: if ($prefix eq 'passwords') {
8311: %titles = &Apache::lonlocal::texthash (
8312: min => 'Minimum password length',
8313: max => 'Maximum password length',
8314: chars => 'Required characters',
8315: );
1.421 raeburn 8316: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 8317: %titles = &Apache::lonlocal::texthash (
8318: min => 'Minimum secret length',
8319: max => 'Maximum secret length',
8320: chars => 'Required characters',
8321: );
8322: }
8323: $min = $Apache::lonnet::passwdmin;
8324: my $datatable;
8325: my $itemcount;
8326: if (ref($itemcountref)) {
8327: $itemcount = $$itemcountref;
8328: }
8329: if (ref($settings) eq 'HASH') {
8330: if ($settings->{min}) {
8331: $min = $settings->{min};
8332: }
8333: if ($settings->{max}) {
8334: $max = $settings->{max};
8335: }
8336: if (ref($settings->{chars}) eq 'ARRAY') {
8337: map { $chars{$_} = 1; } (@{$settings->{chars}});
8338: }
1.425 raeburn 8339: if ($prefix eq 'passwords') {
1.405 raeburn 8340: if ($settings->{expire}) {
8341: $expire = $settings->{expire};
8342: }
8343: if ($settings->{numsaved}) {
8344: $numsaved = $settings->{numsaved};
8345: }
8346: }
8347: }
8348: my %rulenames = &Apache::lonlocal::texthash(
8349: uc => 'At least one upper case letter',
8350: lc => 'At least one lower case letter',
8351: num => 'At least one number',
8352: spec => 'At least one non-alphanumeric',
8353: );
8354: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
8355: $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
8356: '<td class="LC_left_item"><span class="LC_nobreak">'.
8357: '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
8358: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8359: '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
8360: '</span></td></tr>';
8361: $itemcount ++;
8362: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8363: $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
8364: '<td class="LC_left_item"><span class="LC_nobreak">'.
8365: '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
8366: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8367: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
8368: '</span></td></tr>';
8369: $itemcount ++;
8370: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8371: $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
8372: '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
8373: '</span></td>';
8374: my $numinrow = 2;
8375: my @possrules = ('uc','lc','num','spec');
8376: $datatable .= '<td class="LC_left_item"><table>';
8377: for (my $i=0; $i<@possrules; $i++) {
8378: my ($rem,$checked);
8379: if ($chars{$possrules[$i]}) {
8380: $checked = ' checked="checked"';
8381: }
8382: $rem = $i%($numinrow);
8383: if ($rem == 0) {
8384: if ($i > 0) {
8385: $datatable .= '</tr>';
8386: }
8387: $datatable .= '<tr>';
8388: }
8389: $datatable .= '<td><span class="LC_nobreak"><label>'.
8390: '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
8391: $rulenames{$possrules[$i]}.'</label></span></td>';
8392: }
8393: my $rem = @possrules%($numinrow);
8394: my $colsleft = $numinrow - $rem;
8395: if ($colsleft > 1 ) {
8396: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8397: ' </td>';
8398: } elsif ($colsleft == 1) {
8399: $datatable .= '<td class="LC_left_item"> </td>';
8400: }
8401: $datatable .='</table></td></tr>';
8402: $itemcount ++;
8403: if ($prefix eq 'passwords') {
8404: $titles{'expire'} = &mt('Password expiration (days)');
8405: $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
8406: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8407: $datatable .= '<tr'.$css_class.'><td>'.$titles{'expire'}.'</td>'.
8408: '<td class="LC_left_item"><span class="LC_nobreak">'.
8409: '<input type="text" name="'.$prefix.'_expire" value="'.$expire.'" size="4" '.
8410: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8411: '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no expiration)').'</span>'.
8412: '</span></td></tr>';
8413: $itemcount ++;
8414: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8415: $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
8416: '<td class="LC_left_item"><span class="LC_nobreak">'.
8417: '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
8418: 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
8419: '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
8420: '</span></td></tr>';
8421: $itemcount ++;
8422: }
8423: if (ref($itemcountref)) {
8424: $$itemcountref += $itemcount;
8425: }
8426: return $datatable;
8427: }
8428:
1.373 raeburn 8429: sub print_wafproxy {
8430: my ($position,$dom,$settings,$rowtotal) = @_;
8431: my $css_class;
8432: my $itemcount = 0;
8433: my $datatable;
8434: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 8435: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
1.374 raeburn 8436: my %lt = &wafproxy_titles();
1.373 raeburn 8437: foreach my $server (sort(keys(%servers))) {
8438: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
1.381 raeburn 8439: next if ($serverhome eq '');
1.373 raeburn 8440: my $serverdom;
8441: if ($serverhome ne $server) {
8442: $serverdom = &Apache::lonnet::host_domain($serverhome);
1.381 raeburn 8443: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
8444: $othercontrol{$server} = $serverdom;
8445: }
1.373 raeburn 8446: } else {
8447: $serverdom = &Apache::lonnet::host_domain($server);
1.381 raeburn 8448: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
1.373 raeburn 8449: if ($serverdom ne $dom) {
8450: $othercontrol{$server} = $serverdom;
8451: } else {
8452: $setdom = 1;
8453: if (ref($settings) eq 'HASH') {
8454: if (ref($settings->{'alias'}) eq 'HASH') {
8455: $aliases{$dom} = $settings->{'alias'};
1.381 raeburn 8456: if ($aliases{$dom} ne '') {
8457: $showdom = 1;
8458: }
1.373 raeburn 8459: }
1.388 raeburn 8460: if (ref($settings->{'saml'}) eq 'HASH') {
8461: $saml{$dom} = $settings->{'saml'};
8462: }
1.373 raeburn 8463: }
8464: }
8465: }
8466: }
1.381 raeburn 8467: if ($setdom) {
8468: %{$values{$dom}} = ();
8469: if (ref($settings) eq 'HASH') {
8470: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8471: $values{$dom}{$item} = $settings->{$item};
8472: }
8473: }
8474: }
1.373 raeburn 8475: if (keys(%othercontrol)) {
8476: %otherdoms = reverse(%othercontrol);
8477: foreach my $domain (keys(%otherdoms)) {
8478: %{$values{$domain}} = ();
8479: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
1.383 raeburn 8480: if (ref($config{'wafproxy'}) eq 'HASH') {
8481: $aliases{$domain} = $config{'wafproxy'}{'alias'};
1.425 raeburn 8482: if (exists($config{'wafproxy'}{'saml'})) {
1.388 raeburn 8483: $saml{$domain} = $config{'wafproxy'}{'saml'};
8484: }
1.383 raeburn 8485: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
8486: $values{$domain}{$item} = $config{'wafproxy'}{$item};
1.373 raeburn 8487: }
8488: }
8489: }
8490: }
8491: if ($position eq 'top') {
8492: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.381 raeburn 8493: my %aliasinfo;
1.373 raeburn 8494: foreach my $server (sort(keys(%servers))) {
1.381 raeburn 8495: $itemcount ++;
8496: my $dom_in_effect;
8497: my $aliasrows = '<tr>'.
1.383 raeburn 8498: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.433 raeburn 8499: &mt('Hostname').': '.
8500: '<span class="LC_nobreak LC_cusr_emph">'.
8501: &Apache::lonnet::hostname($server).
8502: '</span></td><td> </td>';
1.373 raeburn 8503: if ($othercontrol{$server}) {
1.381 raeburn 8504: $dom_in_effect = $othercontrol{$server};
1.388 raeburn 8505: my ($current,$forsaml);
1.383 raeburn 8506: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
8507: $current = $aliases{$dom_in_effect}{$server};
1.373 raeburn 8508: }
1.388 raeburn 8509: if (ref($saml{$dom_in_effect}) eq 'HASH') {
8510: if ($saml{$dom_in_effect}{$server}) {
8511: $forsaml = 1;
8512: }
8513: }
1.383 raeburn 8514: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8515: &mt('Alias').': ';
1.373 raeburn 8516: if ($current) {
1.381 raeburn 8517: $aliasrows .= $current;
1.388 raeburn 8518: if ($forsaml) {
1.396 raeburn 8519: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
1.388 raeburn 8520: }
1.373 raeburn 8521: } else {
1.383 raeburn 8522: $aliasrows .= &mt('None');
1.373 raeburn 8523: }
1.383 raeburn 8524: $aliasrows .= ' <span class="LC_small">('.
8525: &mt('controlled by domain: [_1]',
8526: '<b>'.$dom_in_effect.'</b>').')</span></td>';
1.373 raeburn 8527: } else {
1.381 raeburn 8528: $dom_in_effect = $dom;
1.388 raeburn 8529: my ($current,$samlon,$samloff);
8530: $samloff = ' checked="checked"';
1.373 raeburn 8531: if (ref($aliases{$dom}) eq 'HASH') {
8532: if ($aliases{$dom}{$server}) {
8533: $current = $aliases{$dom}{$server};
8534: }
8535: }
1.388 raeburn 8536: if (ref($saml{$dom}) eq 'HASH') {
8537: if ($saml{$dom}{$server}) {
8538: $samlon = $samloff;
8539: undef($samloff);
8540: }
8541: }
1.383 raeburn 8542: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
8543: &mt('Alias').': '.
1.381 raeburn 8544: '<input type="text" name="wafproxy_alias_'.$server.'" '.
1.388 raeburn 8545: 'value="'.$current.'" size="30" />'.
8546: (' 'x2).'<span class="LC_nobreak">'.
1.396 raeburn 8547: &mt('Alias used for SSO Auth').': <label>'.
1.388 raeburn 8548: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
1.425 raeburn 8549: &mt('No').'</label> <label>'.
1.388 raeburn 8550: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
8551: &mt('Yes').'</label></span>'.
1.425 raeburn 8552: '</td>';
1.381 raeburn 8553: }
8554: $aliasrows .= '</tr>';
8555: $aliasinfo{$dom_in_effect} .= $aliasrows;
8556: }
8557: if ($aliasinfo{$dom}) {
8558: my ($onclick,$wafon,$wafoff,$showtable);
8559: $onclick = ' onclick="javascript:toggleWAF();"';
8560: $wafoff = ' checked="checked"';
8561: $showtable = ' style="display:none";';
8562: if ($showdom) {
8563: $wafon = $wafoff;
8564: $wafoff = '';
8565: $showtable = ' style="display:inline;"';
8566: }
8567: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8568: $datatable = '<tr'.$css_class.'>'.
8569: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
8570: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
8571: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
8572: &mt('Yes').'</label>'.(' 'x2).'<label>'.
8573: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
8574: &mt('No').'</label></span></td>'.
8575: '<td class="LC_left_item">'.
8576: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
8577: '</table></td></tr>';
8578: $itemcount++;
8579: }
1.383 raeburn 8580: if (keys(%otherdoms)) {
8581: foreach my $key (sort(keys(%otherdoms))) {
1.381 raeburn 8582: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.383 raeburn 8583: $datatable .= '<tr'.$css_class.'>'.
8584: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
8585: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
8586: '</table></td></tr>';
1.381 raeburn 8587: $itemcount++;
1.373 raeburn 8588: }
8589: }
8590: } else {
1.383 raeburn 8591: my %ip_methods = &remoteip_methods();
1.373 raeburn 8592: if ($setdom) {
8593: $itemcount ++;
8594: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.381 raeburn 8595: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
1.382 raeburn 8596: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
1.381 raeburn 8597: $wafstyle = ' style="display:none;"';
8598: $nowafstyle = ' style="display:table-row;"';
8599: $currwafdisplay = ' style="display: none"';
8600: $wafrangestyle = ' style="display: none"';
8601: $curr_remotip = 'n';
1.382 raeburn 8602: $ssltossl = ' checked="checked"';
1.381 raeburn 8603: if ($showdom) {
8604: $wafstyle = ' style="display:table-row;"';
8605: $nowafstyle = ' style="display:none;"';
8606: if (keys(%{$values{$dom}})) {
8607: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
8608: $curr_remotip = $values{$dom}{remoteip};
8609: }
8610: if ($curr_remotip eq 'h') {
8611: $currwafdisplay = ' style="display:table-row"';
8612: $wafrangestyle = ' style="display:inline-block;"';
8613: }
1.382 raeburn 8614: if ($values{$dom}{'sslopt'}) {
8615: $alltossl = ' checked="checked"';
8616: $ssltossl = '';
8617: }
1.381 raeburn 8618: }
8619: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
8620: $vpndircheck = ' checked="checked"';
8621: $currwafvpn = ' style="display:table-row;"';
8622: $wafrangestyle = ' style="display:inline-block;"';
8623: } else {
8624: $vpnaliascheck = ' checked="checked"';
8625: $currwafvpn = ' style="display:none;"';
8626: }
8627: }
8628: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
8629: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
8630: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
8631: '</tr>'.
8632: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
1.374 raeburn 8633: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
1.381 raeburn 8634: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
1.393 raeburn 8635: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
8636: &mt('Range(s) stored in CIDR notation').'</div></td>'.
1.381 raeburn 8637: '<td class="LC_left_item"><table>'.
8638: '<tr>'.
8639: '<td valign="top">'.$lt{'remoteip'}.': '.
8640: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
8641: foreach my $option ('m','h','n') {
8642: my $sel;
8643: if ($option eq $curr_remotip) {
8644: $sel = ' selected="selected"';
8645: }
8646: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
8647: $ip_methods{$option}.'</option>';
8648: }
8649: $datatable .= '</select></td></tr>'."\n".
8650: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
8651: $lt{'ipheader'}.': '.
8652: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
8653: 'name="wafproxy_ipheader" />'.
8654: '</td></tr>'."\n".
8655: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
1.382 raeburn 8656: $lt{'trusted'}.':<br />'.
1.381 raeburn 8657: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
8658: $values{$dom}{'trusted'}.'</textarea>'.
8659: '</td></tr>'."\n".
8660: '<tr><td><hr /></td></tr>'."\n".
8661: '<tr>'.
8662: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
8663: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
8664: $lt{'vpndirect'}.'</label>'.(' 'x2).
8665: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
8666: $lt{'vpnaliased'}.'</label></span></td></tr>';
8667: foreach my $item ('vpnint','vpnext') {
8668: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
1.382 raeburn 8669: '<td valign="top">'.$lt{$item}.':<br />'.
1.381 raeburn 8670: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
8671: $values{$dom}{$item}.'</textarea>'.
8672: '</td></tr>'."\n";
1.373 raeburn 8673: }
1.382 raeburn 8674: $datatable .= '<tr><td><hr /></td></tr>'."\n".
8675: '<tr>'.
8676: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
8677: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
8678: $lt{'alltossl'}.'</label>'.(' 'x2).
8679: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
8680: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
8681: '</table></td></tr>';
1.373 raeburn 8682: }
8683: if (keys(%otherdoms)) {
8684: foreach my $domain (sort(keys(%otherdoms))) {
8685: $itemcount ++;
8686: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8687: $datatable .= '<tr'.$css_class.'>'.
1.383 raeburn 8688: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
1.374 raeburn 8689: '<td class="LC_left_item"><table>';
1.382 raeburn 8690: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 8691: my $showval = &mt('None');
1.382 raeburn 8692: if ($item eq 'ssl') {
8693: $showval = $lt{'ssltossl'};
8694: }
1.373 raeburn 8695: if ($values{$domain}{$item}) {
1.381 raeburn 8696: $showval = $values{$domain}{$item};
1.382 raeburn 8697: if ($item eq 'ssl') {
8698: $showval = $lt{'alltossl'};
1.383 raeburn 8699: } elsif ($item eq 'remoteip') {
8700: $showval = $ip_methods{$values{$domain}{$item}};
1.382 raeburn 8701: }
1.373 raeburn 8702: }
8703: $datatable .= '<tr>'.
8704: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
8705: }
1.381 raeburn 8706: $datatable .= '</table></td></tr>';
1.373 raeburn 8707: }
8708: }
8709: }
8710: $$rowtotal += $itemcount;
8711: return $datatable;
8712: }
8713:
8714: sub wafproxy_titles {
8715: return &Apache::lonlocal::texthash(
1.381 raeburn 8716: remoteip => "Method for determining user's IP",
8717: ipheader => 'Request header containing remote IP',
8718: trusted => 'Trusted IP range(s)',
8719: vpnaccess => 'Access from institutional VPN',
8720: vpndirect => 'via regular hostname (no WAF)',
8721: vpnaliased => 'via aliased hostname (WAF)',
8722: vpnint => 'Internal IP Range(s) for VPN sessions',
8723: vpnext => 'IP Range(s) for backend WAF connections',
1.382 raeburn 8724: sslopt => 'Forwarding http/https',
1.381 raeburn 8725: alltossl => 'WAF forwards both http and https requests to https',
8726: ssltossl => 'WAF forwards http requests to http and https to https',
8727: );
8728: }
8729:
8730: sub remoteip_methods {
8731: return &Apache::lonlocal::texthash(
8732: m => 'Use Apache mod_remoteip',
8733: h => 'Use headers parsed by LON-CAPA',
8734: n => 'Not in use',
1.373 raeburn 8735: );
8736: }
8737:
1.137 raeburn 8738: sub print_usersessions {
8739: my ($position,$dom,$settings,$rowtotal) = @_;
1.279 raeburn 8740: my ($css_class,$datatable,$itemcount,%checked,%choices);
1.275 raeburn 8741: my (%by_ip,%by_location,@intdoms,@instdoms);
8742: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.145 raeburn 8743:
8744: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 8745: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 8746: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 8747: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 8748: if ($position eq 'top') {
1.152 raeburn 8749: if (keys(%serverhomes) > 1) {
1.145 raeburn 8750: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.371 raeburn 8751: my ($curroffloadnow,$curroffloadoth);
1.261 raeburn 8752: if (ref($settings) eq 'HASH') {
8753: if (ref($settings->{'offloadnow'}) eq 'HASH') {
8754: $curroffloadnow = $settings->{'offloadnow'};
8755: }
1.371 raeburn 8756: if (ref($settings->{'offloadoth'}) eq 'HASH') {
8757: $curroffloadoth = $settings->{'offloadoth'};
8758: }
1.261 raeburn 8759: }
1.371 raeburn 8760: my $other_insts = scalar(keys(%by_location));
8761: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
8762: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 8763: } else {
1.140 raeburn 8764: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.279 raeburn 8765: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
8766: '</td></tr>';
1.140 raeburn 8767: }
1.137 raeburn 8768: } else {
1.279 raeburn 8769: my %titles = &usersession_titles();
8770: my ($prefix,@types);
8771: if ($position eq 'bottom') {
8772: $prefix = 'remote';
8773: @types = ('version','excludedomain','includedomain');
1.145 raeburn 8774: } else {
1.279 raeburn 8775: $prefix = 'hosted';
8776: @types = ('excludedomain','includedomain');
8777: }
8778: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
8779: }
8780: $$rowtotal += $itemcount;
8781: return $datatable;
8782: }
8783:
8784: sub rules_by_location {
8785: my ($settings,$prefix,$by_location,$by_ip,$types,$titles) = @_;
8786: my ($datatable,$itemcount,$css_class);
8787: if (keys(%{$by_location}) == 0) {
8788: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8789: $datatable = '<tr'.$css_class.'><td colspan="2">'.
8790: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
8791: '</td></tr>';
8792: $itemcount = 1;
8793: } else {
8794: $itemcount = 0;
8795: my $numinrow = 5;
8796: my (%current,%checkedon,%checkedoff);
8797: my @locations = sort(keys(%{$by_location}));
8798: foreach my $type (@{$types}) {
8799: $checkedon{$type} = '';
8800: $checkedoff{$type} = ' checked="checked"';
8801: }
8802: if (ref($settings) eq 'HASH') {
8803: if (ref($settings->{$prefix}) eq 'HASH') {
8804: foreach my $key (keys(%{$settings->{$prefix}})) {
8805: $current{$key} = $settings->{$prefix}{$key};
8806: if ($key eq 'version') {
8807: if ($current{$key} ne '') {
1.145 raeburn 8808: $checkedon{$key} = ' checked="checked"';
8809: $checkedoff{$key} = '';
8810: }
1.279 raeburn 8811: } elsif (ref($current{$key}) eq 'ARRAY') {
8812: $checkedon{$key} = ' checked="checked"';
8813: $checkedoff{$key} = '';
1.137 raeburn 8814: }
8815: }
8816: }
1.279 raeburn 8817: }
8818: foreach my $type (@{$types}) {
8819: next if ($type ne 'version' && !@locations);
8820: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
8821: $datatable .= '<tr'.$css_class.'>
8822: <td><span class="LC_nobreak">'.$titles->{$type}.'</span><br />
8823: <span class="LC_nobreak">
8824: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
8825: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
8826: if ($type eq 'version') {
8827: my @lcversions = &Apache::lonnet::all_loncaparevs();
8828: my $selector = '<select name="'.$prefix.'_version">';
8829: foreach my $version (@lcversions) {
8830: my $selected = '';
8831: if ($current{'version'} eq $version) {
8832: $selected = ' selected="selected"';
1.145 raeburn 8833: }
1.279 raeburn 8834: $selector .= ' <option value="'.$version.'"'.
8835: $selected.'>'.$version.'</option>';
8836: }
8837: $selector .= '</select> ';
8838: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
8839: } else {
8840: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
8841: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
8842: ' />'.(' 'x2).
8843: '<input type="button" value="'.&mt('uncheck all').'" '.
8844: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
8845: "\n".
8846: '</div><div><table>';
8847: my $rem;
8848: for (my $i=0; $i<@locations; $i++) {
8849: my ($showloc,$value,$checkedtype);
8850: if (ref($by_location->{$locations[$i]}) eq 'ARRAY') {
8851: my $ip = $by_location->{$locations[$i]}->[0];
8852: if (ref($by_ip->{$ip}) eq 'ARRAY') {
8853: $value = join(':',@{$by_ip->{$ip}});
8854: $showloc = join(', ',@{$by_ip->{$ip}});
8855: if (ref($current{$type}) eq 'ARRAY') {
8856: foreach my $loc (@{$by_ip->{$ip}}) {
8857: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
8858: $checkedtype = ' checked="checked"';
8859: last;
1.145 raeburn 8860: }
1.138 raeburn 8861: }
8862: }
8863: }
1.137 raeburn 8864: }
1.279 raeburn 8865: $rem = $i%($numinrow);
8866: if ($rem == 0) {
8867: if ($i > 0) {
8868: $datatable .= '</tr>';
8869: }
8870: $datatable .= '<tr>';
8871: }
8872: $datatable .= '<td class="LC_left_item">'.
8873: '<span class="LC_nobreak"><label>'.
8874: '<input type="checkbox" name="'.$prefix.'_'.$type.
8875: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
8876: '</label></span></td>';
8877: }
8878: $rem = @locations%($numinrow);
8879: my $colsleft = $numinrow - $rem;
8880: if ($colsleft > 1 ) {
8881: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8882: ' </td>';
8883: } elsif ($colsleft == 1) {
8884: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 8885: }
1.279 raeburn 8886: $datatable .= '</tr></table>';
1.137 raeburn 8887: }
1.279 raeburn 8888: $datatable .= '</td></tr>';
8889: $itemcount ++;
1.137 raeburn 8890: }
8891: }
1.279 raeburn 8892: return ($datatable,$itemcount);
1.137 raeburn 8893: }
8894:
1.275 raeburn 8895: sub print_ssl {
8896: my ($position,$dom,$settings,$rowtotal) = @_;
8897: my ($css_class,$datatable);
8898: my $itemcount = 1;
8899: if ($position eq 'top') {
1.281 raeburn 8900: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8901: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8902: my $same_institution;
8903: if ($intdom ne '') {
8904: my $internet_names = &Apache::lonnet::get_internet_names($Apache::lonnet::perlvar{'lonHostID'});
8905: if (ref($internet_names) eq 'ARRAY') {
8906: if (grep(/^\Q$intdom\E$/,@{$internet_names})) {
8907: $same_institution = 1;
8908: }
8909: }
8910: }
1.275 raeburn 8911: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.281 raeburn 8912: $datatable = '<tr'.$css_class.'><td colspan="2">';
8913: if ($same_institution) {
8914: my %domservers = &Apache::lonnet::get_servers($dom);
8915: $datatable .= &LONCAPA::SSL::print_certstatus(\%domservers,'web','domprefs');
8916: } else {
8917: $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.");
8918: }
8919: $datatable .= '</td></tr>';
1.275 raeburn 8920: $itemcount ++;
8921: } else {
8922: my %titles = &ssl_titles();
8923: my (%by_ip,%by_location,@intdoms,@instdoms);
8924: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
8925: my @alldoms = &Apache::lonnet::all_domains();
8926: my %serverhomes = %Apache::lonnet::serverhomeIDs;
8927: my @domservers = &Apache::lonnet::get_servers($dom);
8928: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8929: my %altids = &id_for_thisdom(%servers);
1.293 raeburn 8930: if (($position eq 'connto') || ($position eq 'connfrom')) {
8931: my $legacy;
8932: unless (ref($settings) eq 'HASH') {
8933: my $name;
8934: if ($position eq 'connto') {
8935: $name = 'loncAllowInsecure';
8936: } else {
8937: $name = 'londAllowInsecure';
8938: }
8939: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
8940: my @ids=&Apache::lonnet::current_machine_ids();
8941: if (($primarylibserv ne '') && (!grep(/^\Q$primarylibserv\E$/,@ids))) {
8942: my %what = (
8943: $name => 1,
8944: );
8945: my ($result,$returnhash) =
8946: &Apache::lonnet::get_remote_globals($primarylibserv,\%what);
8947: if ($result eq 'ok') {
8948: if (ref($returnhash) eq 'HASH') {
8949: $legacy = $returnhash->{$name};
8950: }
8951: }
8952: } else {
8953: $legacy = $Apache::lonnet::perlvar{$name};
8954: }
8955: }
1.275 raeburn 8956: foreach my $type ('dom','intdom','other') {
8957: my %checked;
8958: $css_class = $itemcount%2?' class="LC_odd_row"':'';
8959: $datatable .= '<tr'.$css_class.'><td>'.$titles{$type}.'</td>'.
8960: '<td class="LC_right_item">';
8961: my $skip;
8962: if ($type eq 'dom') {
8963: unless (keys(%servers) > 1) {
8964: $datatable .= &mt('Nothing to set here, as there are no other servers/VMs');
8965: $skip = 1;
8966: }
8967: }
8968: if ($type eq 'intdom') {
8969: unless (@instdoms > 1) {
8970: $datatable .= &mt('Nothing to set here, as there are no other domains for this institution');
8971: $skip = 1;
8972: }
8973: } elsif ($type eq 'other') {
8974: if (keys(%by_location) == 0) {
8975: $datatable .= &mt('Nothing to set here, as there are no other institutions');
8976: $skip = 1;
8977: }
8978: }
8979: unless ($skip) {
8980: $checked{'yes'} = ' checked="checked"';
8981: if (ref($settings) eq 'HASH') {
1.293 raeburn 8982: if (ref($settings->{$position}) eq 'HASH') {
8983: if ($settings->{$position}->{$type} =~ /^(no|req)$/) {
1.275 raeburn 8984: $checked{$1} = $checked{'yes'};
8985: delete($checked{'yes'});
8986: }
8987: }
1.293 raeburn 8988: } else {
8989: if ($legacy == 0) {
8990: $checked{'req'} = $checked{'yes'};
8991: delete($checked{'yes'});
8992: }
1.275 raeburn 8993: }
8994: foreach my $option ('no','yes','req') {
8995: $datatable .= '<span class="LC_nobreak"><label>'.
1.293 raeburn 8996: '<input type="radio" name="'.$position.'_'.$type.'" '.
1.275 raeburn 8997: 'value="'.$option.'"'.$checked{$option}.' />'.$titles{$option}.
8998: '</label></span>'.(' 'x2);
8999: }
9000: }
9001: $datatable .= '</td></tr>';
9002: $itemcount ++;
9003: }
9004: } else {
9005: my $prefix = 'replication';
9006: my @types = ('certreq','nocertreq');
1.279 raeburn 9007: if (keys(%by_location) == 0) {
9008: $datatable .= '<tr'.$css_class.'><td>'.
9009: &mt('Nothing to set here, as there are no other institutions').
9010: '</td></tr>';
9011: $itemcount ++;
1.275 raeburn 9012: } else {
1.279 raeburn 9013: ($datatable,$itemcount) =
9014: &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
1.275 raeburn 9015: }
9016: }
9017: }
9018: $$rowtotal += $itemcount;
9019: return $datatable;
9020: }
9021:
9022: sub ssl_titles {
9023: return &Apache::lonlocal::texthash (
9024: dom => 'LON-CAPA servers/VMs from same domain',
9025: intdom => 'LON-CAPA servers/VMs from same "internet" domain',
9026: other => 'External LON-CAPA servers/VMs',
1.293 raeburn 9027: connto => 'Connections to other servers',
9028: connfrom => 'Connections from other servers',
1.275 raeburn 9029: replication => 'Replicating content to other institutions',
9030: certreq => 'Client certificate required, but specific domains exempt',
9031: nocertreq => 'No client certificate required, except for specific domains',
9032: no => 'SSL not used',
9033: yes => 'SSL Optional (used if available)',
9034: req => 'SSL Required',
9035: );
1.279 raeburn 9036: }
9037:
9038: sub print_trust {
9039: my ($prefix,$dom,$settings,$rowtotal) = @_;
9040: my ($css_class,$datatable,%checked,%choices);
9041: my (%by_ip,%by_location,@intdoms,@instdoms);
9042: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
9043: my $itemcount = 1;
9044: my %titles = &trust_titles();
9045: my @types = ('exc','inc');
9046: if ($prefix eq 'top') {
9047: $prefix = 'content';
9048: } elsif ($prefix eq 'bottom') {
9049: $prefix = 'msg';
9050: }
9051: ($datatable,$itemcount) = &rules_by_location($settings,$prefix,\%by_location,\%by_ip,\@types,\%titles);
9052: $$rowtotal += $itemcount;
9053: return $datatable;
9054: }
9055:
9056: sub trust_titles {
9057: return &Apache::lonlocal::texthash(
9058: content => "Access to this domain's content by others",
9059: shared => "Access to other domain's content by this domain",
9060: enroll => "Enrollment in this domain's courses by others",
9061: othcoau => "Co-author roles in this domain for others",
9062: coaurem => "Co-author roles for this domain's users elsewhere",
9063: domroles => "Domain roles in this domain assignable to others",
9064: catalog => "Course Catalog for this domain displayed elsewhere",
9065: reqcrs => "Requests for creation of courses in this domain by others",
9066: msg => "Users in other domains can send messages to this domain",
9067: exc => "Allow all, but exclude specific domains",
9068: inc => "Deny all, but include specific domains",
9069: );
1.275 raeburn 9070: }
9071:
1.138 raeburn 9072: sub build_location_hashes {
1.275 raeburn 9073: my ($intdoms,$by_ip,$by_location,$instdoms) = @_;
1.138 raeburn 9074: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
1.275 raeburn 9075: (ref($by_location) eq 'HASH') && (ref($instdoms) eq 'ARRAY'));
1.138 raeburn 9076: my %iphost = &Apache::lonnet::get_iphost();
9077: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
9078: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
9079: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
9080: foreach my $id (@{$iphost{$primary_ip}}) {
9081: my $intdom = &Apache::lonnet::internet_dom($id);
9082: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
9083: push(@{$intdoms},$intdom);
9084: }
9085: }
9086: }
9087: foreach my $ip (keys(%iphost)) {
9088: if (ref($iphost{$ip}) eq 'ARRAY') {
9089: foreach my $id (@{$iphost{$ip}}) {
9090: my $location = &Apache::lonnet::internet_dom($id);
9091: if ($location) {
1.275 raeburn 9092: if (grep(/^\Q$location\E$/,@{$intdoms})) {
9093: my $dom = &Apache::lonnet::host_domain($id);
9094: unless (grep(/^\Q$dom\E/,@{$instdoms})) {
9095: push(@{$instdoms},$dom);
9096: }
9097: next;
9098: }
1.138 raeburn 9099: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9100: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
9101: push(@{$by_ip->{$ip}},$location);
9102: }
9103: } else {
9104: $by_ip->{$ip} = [$location];
9105: }
9106: }
9107: }
9108: }
9109: }
9110: foreach my $ip (sort(keys(%{$by_ip}))) {
9111: if (ref($by_ip->{$ip}) eq 'ARRAY') {
9112: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
9113: my $first = $by_ip->{$ip}->[0];
9114: if (ref($by_location->{$first}) eq 'ARRAY') {
9115: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
9116: push(@{$by_location->{$first}},$ip);
9117: }
9118: } else {
9119: $by_location->{$first} = [$ip];
9120: }
9121: }
9122: }
9123: return;
9124: }
9125:
1.145 raeburn 9126: sub current_offloads_to {
9127: my ($dom,$settings,$servers) = @_;
9128: my (%spareid,%otherdomconfigs);
1.152 raeburn 9129: if (ref($servers) eq 'HASH') {
1.145 raeburn 9130: foreach my $lonhost (sort(keys(%{$servers}))) {
9131: my $gotspares;
1.152 raeburn 9132: if (ref($settings) eq 'HASH') {
9133: if (ref($settings->{'spares'}) eq 'HASH') {
9134: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
9135: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
9136: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
9137: $gotspares = 1;
9138: }
1.145 raeburn 9139: }
9140: }
9141: unless ($gotspares) {
9142: my $gotspares;
9143: my $serverhomeID =
9144: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
9145: my $serverhomedom =
9146: &Apache::lonnet::host_domain($serverhomeID);
9147: if ($serverhomedom ne $dom) {
9148: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
9149: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9150: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9151: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9152: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9153: $gotspares = 1;
9154: }
9155: }
9156: } else {
9157: $otherdomconfigs{$serverhomedom} =
9158: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
9159: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
9160: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
9161: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
9162: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
9163: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
9164: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
9165: $gotspares = 1;
9166: }
9167: }
9168: }
9169: }
9170: }
9171: }
9172: }
9173: unless ($gotspares) {
9174: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
9175: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9176: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9177: } else {
9178: my $server_hostname = &Apache::lonnet::hostname($lonhost);
9179: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
9180: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
9181: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
9182: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
9183: } else {
1.150 raeburn 9184: my %what = (
9185: spareid => 1,
9186: );
9187: my ($result,$returnhash) =
9188: &Apache::lonnet::get_remote_globals($lonhost,\%what);
9189: if ($result eq 'ok') {
9190: if (ref($returnhash) eq 'HASH') {
9191: if (ref($returnhash->{'spareid'}) eq 'HASH') {
9192: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
9193: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
9194: }
9195: }
1.145 raeburn 9196: }
9197: }
9198: }
9199: }
9200: }
9201: }
9202: return %spareid;
9203: }
9204:
9205: sub spares_row {
1.371 raeburn 9206: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
9207: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 9208: my $css_class;
9209: my $numinrow = 4;
9210: my $itemcount = 1;
9211: my $datatable;
1.152 raeburn 9212: my %typetitles = &sparestype_titles();
9213: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 9214: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 9215: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
9216: my ($othercontrol,$serverdom);
9217: if ($serverhome ne $server) {
9218: $serverdom = &Apache::lonnet::host_domain($serverhome);
9219: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9220: } else {
9221: $serverdom = &Apache::lonnet::host_domain($server);
9222: if ($serverdom ne $dom) {
9223: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
9224: }
9225: }
9226: next unless (ref($spareid->{$server}) eq 'HASH');
1.371 raeburn 9227: my ($checkednow,$checkedoth);
1.261 raeburn 9228: if (ref($curroffloadnow) eq 'HASH') {
9229: if ($curroffloadnow->{$server}) {
9230: $checkednow = ' checked="checked"';
9231: }
9232: }
1.371 raeburn 9233: if (ref($curroffloadoth) eq 'HASH') {
9234: if ($curroffloadoth->{$server}) {
9235: $checkedoth = ' checked="checked"';
9236: }
9237: }
1.145 raeburn 9238: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
9239: $datatable .= '<tr'.$css_class.'>
9240: <td rowspan="2">
1.183 bisitz 9241: <span class="LC_nobreak">'.
9242: &mt('[_1] when busy, offloads to:'
1.261 raeburn 9243: ,'<b>'.$server.'</b>').'</span><br />'.
1.289 raeburn 9244: '<span class="LC_nobreak">'."\n".
1.261 raeburn 9245: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.371 raeburn 9246: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.183 bisitz 9247: "\n";
1.371 raeburn 9248: if ($other_insts) {
9249: $datatable .= '<br />'.
9250: '<span class="LC_nobreak">'."\n".
9251: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
9252: ' '.&mt('Switch other institutions on next access').'</label></span>'.
9253: "\n";
9254: }
1.145 raeburn 9255: my (%current,%canselect);
1.152 raeburn 9256: my @choices =
9257: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
9258: foreach my $type ('primary','default') {
9259: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 9260: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
9261: my @spares = @{$spareid->{$server}{$type}};
9262: if (@spares > 0) {
1.152 raeburn 9263: if ($othercontrol) {
9264: $current{$type} = join(', ',@spares);
9265: } else {
9266: $current{$type} .= '<table>';
9267: my $numspares = scalar(@spares);
9268: for (my $i=0; $i<@spares; $i++) {
9269: my $rem = $i%($numinrow);
9270: if ($rem == 0) {
9271: if ($i > 0) {
9272: $current{$type} .= '</tr>';
9273: }
9274: $current{$type} .= '<tr>';
1.145 raeburn 9275: }
1.152 raeburn 9276: $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'".');" /> '.
9277: $spareid->{$server}{$type}[$i].
9278: '</label></td>'."\n";
9279: }
9280: my $rem = @spares%($numinrow);
9281: my $colsleft = $numinrow - $rem;
9282: if ($colsleft > 1 ) {
9283: $current{$type} .= '<td colspan="'.$colsleft.
9284: '" class="LC_left_item">'.
9285: ' </td>';
9286: } elsif ($colsleft == 1) {
9287: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 9288: }
1.152 raeburn 9289: $current{$type} .= '</tr></table>';
1.150 raeburn 9290: }
1.145 raeburn 9291: }
9292: }
9293: if ($current{$type} eq '') {
9294: $current{$type} = &mt('None specified');
9295: }
1.152 raeburn 9296: if ($othercontrol) {
9297: if ($type eq 'primary') {
9298: $canselect{$type} = $othercontrol;
9299: }
9300: } else {
9301: $canselect{$type} =
9302: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
9303: '<select name="newspare_'.$type.'_'.$server.'" '.
9304: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
9305: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
9306: if (@choices > 0) {
9307: foreach my $lonhost (@choices) {
9308: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
9309: }
9310: }
9311: $canselect{$type} .= '</select>'."\n";
9312: }
9313: } else {
9314: $current{$type} = &mt('Could not be determined');
9315: if ($type eq 'primary') {
9316: $canselect{$type} = $othercontrol;
9317: }
1.145 raeburn 9318: }
1.152 raeburn 9319: if ($type eq 'default') {
9320: $datatable .= '<tr'.$css_class.'>';
9321: }
9322: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
9323: '<td>'.$current{$type}.'</td>'."\n".
9324: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 9325: }
9326: $itemcount ++;
9327: }
9328: }
9329: $$rowtotal += $itemcount;
9330: return $datatable;
9331: }
9332:
1.152 raeburn 9333: sub possible_newspares {
9334: my ($server,$currspares,$serverhomes,$altids) = @_;
9335: my $serverhostname = &Apache::lonnet::hostname($server);
9336: my %excluded;
9337: if ($serverhostname ne '') {
9338: %excluded = (
9339: $serverhostname => 1,
9340: );
9341: }
9342: if (ref($currspares) eq 'HASH') {
9343: foreach my $type (keys(%{$currspares})) {
9344: if (ref($currspares->{$type}) eq 'ARRAY') {
9345: if (@{$currspares->{$type}} > 0) {
9346: foreach my $curr (@{$currspares->{$type}}) {
9347: my $hostname = &Apache::lonnet::hostname($curr);
9348: $excluded{$hostname} = 1;
9349: }
9350: }
9351: }
9352: }
9353: }
9354: my @choices;
9355: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
9356: if (keys(%{$serverhomes}) > 1) {
9357: foreach my $name (sort(keys(%{$serverhomes}))) {
9358: unless ($excluded{$name}) {
9359: if (exists($altids->{$serverhomes->{$name}})) {
9360: push(@choices,$altids->{$serverhomes->{$name}});
9361: } else {
9362: push(@choices,$serverhomes->{$name});
1.145 raeburn 9363: }
9364: }
9365: }
9366: }
9367: }
1.152 raeburn 9368: return sort(@choices);
1.145 raeburn 9369: }
9370:
1.150 raeburn 9371: sub print_loadbalancing {
9372: my ($dom,$settings,$rowtotal) = @_;
9373: my $primary_id = &Apache::lonnet::domain($dom,'primary');
9374: my $intdom = &Apache::lonnet::internet_dom($primary_id);
9375: my $numinrow = 1;
9376: my $datatable;
9377: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.342 raeburn 9378: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 9379: if (ref($settings) eq 'HASH') {
9380: %existing = %{$settings};
9381: }
9382: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
9383: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 9384: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 9385: } else {
9386: return;
9387: }
9388: my ($othertitle,$usertypes,$types) =
9389: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 9390: my $rownum = 8;
1.150 raeburn 9391: if (ref($types) eq 'ARRAY') {
9392: $rownum += scalar(@{$types});
9393: }
1.171 raeburn 9394: my @css_class = ('LC_odd_row','LC_even_row');
9395: my $balnum = 0;
9396: my $islast;
9397: my (@toshow,$disabledtext);
9398: if (keys(%currbalancer) > 0) {
9399: @toshow = sort(keys(%currbalancer));
9400: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
9401: push(@toshow,'');
9402: }
9403: } else {
9404: @toshow = ('');
9405: $disabledtext = &mt('No existing load balancer');
9406: }
9407: foreach my $lonhost (@toshow) {
9408: if ($balnum == scalar(@toshow)-1) {
9409: $islast = 1;
9410: } else {
9411: $islast = 0;
9412: }
9413: my $cssidx = $balnum%2;
9414: my $targets_div_style = 'display: none';
9415: my $disabled_div_style = 'display: block';
9416: my $homedom_div_style = 'display: none';
9417: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
1.306 raeburn 9418: '<td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9419: '<p>';
9420: if ($lonhost eq '') {
1.210 raeburn 9421: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 9422: if (keys(%currbalancer) > 0) {
9423: $datatable .= &mt('Add balancer:');
9424: } else {
9425: $datatable .= &mt('Enable balancer:');
9426: }
9427: $datatable .= ' '.
9428: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
9429: ' id="loadbalancing_lonhost_'.$balnum.'"'.
9430: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
9431: '<option value="" selected="selected">'.&mt('None').
9432: '</option>'."\n";
9433: foreach my $server (sort(keys(%servers))) {
9434: next if ($currbalancer{$server});
9435: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
9436: }
1.210 raeburn 9437: $datatable .=
1.171 raeburn 9438: '</select>'."\n".
9439: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
9440: } else {
9441: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
9442: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
9443: &mt('Stop balancing').'</label>'.
9444: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
9445: $targets_div_style = 'display: block';
9446: $disabled_div_style = 'display: none';
9447: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
9448: $homedom_div_style = 'display: block';
9449: }
9450: }
1.306 raeburn 9451: $datatable .= '</p></td><td rowspan="'.$rownum.'" style="vertical-align: top">'.
1.171 raeburn 9452: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
9453: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
9454: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
9455: my ($numspares,@spares) = &count_servers($lonhost,%servers);
9456: my @sparestypes = ('primary','default');
9457: my %typetitles = &sparestype_titles();
1.284 raeburn 9458: my %hostherechecked = (
9459: no => ' checked="checked"',
9460: );
1.342 raeburn 9461: my %balcookiechecked = (
1.425 raeburn 9462: no => ' checked="checked"',
1.342 raeburn 9463: );
1.171 raeburn 9464: foreach my $sparetype (@sparestypes) {
9465: my $targettable;
9466: for (my $i=0; $i<$numspares; $i++) {
9467: my $checked;
9468: if (ref($currtargets{$lonhost}) eq 'HASH') {
9469: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9470: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9471: $checked = ' checked="checked"';
9472: }
9473: }
9474: }
9475: my ($chkboxval,$disabled);
9476: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
9477: $chkboxval = $spares[$i];
9478: }
9479: if (exists($currbalancer{$spares[$i]})) {
9480: $disabled = ' disabled="disabled"';
9481: }
1.210 raeburn 9482: $targettable .=
1.253 raeburn 9483: '<td><span class="LC_nobreak"><label>'.
9484: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.171 raeburn 9485: $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 9486: '</span></label></span></td>';
1.171 raeburn 9487: my $rem = $i%($numinrow);
9488: if ($rem == 0) {
9489: if (($i > 0) && ($i < $numspares-1)) {
9490: $targettable .= '</tr>';
9491: }
9492: if ($i < $numspares-1) {
9493: $targettable .= '<tr>';
1.150 raeburn 9494: }
9495: }
9496: }
1.171 raeburn 9497: if ($targettable ne '') {
9498: my $rem = $numspares%($numinrow);
9499: my $colsleft = $numinrow - $rem;
9500: if ($colsleft > 1 ) {
9501: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9502: ' </td>';
9503: } elsif ($colsleft == 1) {
9504: $targettable .= '<td class="LC_left_item"> </td>';
9505: }
9506: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
9507: '<table><tr>'.$targettable.'</tr></table><br />';
9508: }
1.284 raeburn 9509: $hostherechecked{$sparetype} = '';
9510: if (ref($currtargets{$lonhost}) eq 'HASH') {
9511: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
9512: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
9513: $hostherechecked{$sparetype} = ' checked="checked"';
9514: $hostherechecked{'no'} = '';
9515: }
9516: }
9517: }
9518: }
1.342 raeburn 9519: if ($currcookies{$lonhost}) {
9520: %balcookiechecked = (
9521: yes => ' checked="checked"',
9522: );
9523: }
1.284 raeburn 9524: $datatable .= &mt('Hosting on balancer itself').'<br />'.
9525: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
9526: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
9527: foreach my $sparetype (@sparestypes) {
9528: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
9529: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
9530: '</i></label><br />';
1.171 raeburn 9531: }
1.342 raeburn 9532: $datatable .= &mt('Use balancer cookie').'<br />'.
9533: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
9534: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
9535: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
9536: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
9537: '</div></td></tr>'.
1.171 raeburn 9538: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
9539: $othertitle,$usertypes,$types,\%servers,
9540: \%currbalancer,$lonhost,
9541: $targets_div_style,$homedom_div_style,
9542: $css_class[$cssidx],$balnum,$islast);
9543: $$rowtotal += $rownum;
9544: $balnum ++;
9545: }
9546: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
9547: return $datatable;
9548: }
9549:
9550: sub get_loadbalancers_config {
1.342 raeburn 9551: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.171 raeburn 9552: return unless ((ref($servers) eq 'HASH') &&
9553: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.342 raeburn 9554: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
9555: (ref($currcookies) eq 'HASH'));
1.171 raeburn 9556: if (keys(%{$existing}) > 0) {
9557: my $oldlonhost;
9558: foreach my $key (sort(keys(%{$existing}))) {
9559: if ($key eq 'lonhost') {
9560: $oldlonhost = $existing->{'lonhost'};
9561: $currbalancer->{$oldlonhost} = 1;
9562: } elsif ($key eq 'targets') {
9563: if ($oldlonhost) {
9564: $currtargets->{$oldlonhost} = $existing->{'targets'};
9565: }
9566: } elsif ($key eq 'rules') {
9567: if ($oldlonhost) {
9568: $currrules->{$oldlonhost} = $existing->{'rules'};
9569: }
9570: } elsif (ref($existing->{$key}) eq 'HASH') {
9571: $currbalancer->{$key} = 1;
9572: $currtargets->{$key} = $existing->{$key}{'targets'};
9573: $currrules->{$key} = $existing->{$key}{'rules'};
1.342 raeburn 9574: if ($existing->{$key}{'cookie'}) {
9575: $currcookies->{$key} = 1;
9576: }
1.150 raeburn 9577: }
9578: }
1.171 raeburn 9579: } else {
9580: my ($balancerref,$targetsref) =
9581: &Apache::lonnet::get_lonbalancer_config($servers);
9582: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
9583: foreach my $server (sort(keys(%{$balancerref}))) {
9584: $currbalancer->{$server} = 1;
9585: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 9586: }
9587: }
9588: }
1.171 raeburn 9589: return;
1.150 raeburn 9590: }
9591:
9592: sub loadbalancing_rules {
9593: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 9594: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
9595: $css_class,$balnum,$islast) = @_;
1.150 raeburn 9596: my $output;
1.171 raeburn 9597: my $num = 0;
1.210 raeburn 9598: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 9599: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
9600: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
9601: foreach my $type (@{$alltypes}) {
1.171 raeburn 9602: $num ++;
1.150 raeburn 9603: my $current;
9604: if (ref($currrules) eq 'HASH') {
9605: $current = $currrules->{$type};
9606: }
1.253 raeburn 9607: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 9608: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 9609: $current = '';
9610: }
9611: }
9612: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 9613: $servers,$currbalancer,$lonhost,$dom,
9614: $targets_div_style,$homedom_div_style,
9615: $css_class,$balnum,$num,$islast);
1.150 raeburn 9616: }
9617: }
9618: return $output;
9619: }
9620:
9621: sub loadbalancing_titles {
9622: my ($dom,$intdom,$usertypes,$types) = @_;
9623: my %othertypes = (
9624: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
9625: '_LC_author' => &mt('Users from [_1] with author role',$dom),
9626: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
9627: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 9628: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
9629: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 9630: );
1.209 raeburn 9631: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.302 raeburn 9632: my @available;
1.150 raeburn 9633: if (ref($types) eq 'ARRAY') {
1.302 raeburn 9634: @available = @{$types};
1.150 raeburn 9635: }
1.302 raeburn 9636: unless (grep(/^default$/,@available)) {
9637: push(@available,'default');
9638: }
9639: unshift(@alltypes,@available);
1.150 raeburn 9640: my %titles;
9641: foreach my $type (@alltypes) {
9642: if ($type =~ /^_LC_/) {
9643: $titles{$type} = $othertypes{$type};
9644: } elsif ($type eq 'default') {
9645: $titles{$type} = &mt('All users from [_1]',$dom);
9646: if (ref($types) eq 'ARRAY') {
9647: if (@{$types} > 0) {
9648: $titles{$type} = &mt('Other users from [_1]',$dom);
9649: }
9650: }
9651: } elsif (ref($usertypes) eq 'HASH') {
9652: $titles{$type} = $usertypes->{$type};
9653: }
9654: }
9655: return (\@alltypes,\%othertypes,\%titles);
9656: }
9657:
9658: sub loadbalance_rule_row {
1.171 raeburn 9659: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
9660: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 9661: my @rulenames;
1.150 raeburn 9662: my %ruletitles = &offloadtype_text();
1.209 raeburn 9663: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.254 raeburn 9664: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 9665: } else {
1.209 raeburn 9666: @rulenames = ('default','homeserver');
9667: if ($type eq '_LC_external') {
9668: push(@rulenames,'externalbalancer');
9669: } else {
9670: push(@rulenames,'specific');
9671: }
9672: push(@rulenames,'none');
1.150 raeburn 9673: }
9674: my $style = $targets_div_style;
1.253 raeburn 9675: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 9676: $style = $homedom_div_style;
9677: }
1.171 raeburn 9678: my $space;
9679: if ($islast && $num == 1) {
1.317 raeburn 9680: $space = '<div style="display:inline-block;"> </div>';
1.171 raeburn 9681: }
1.210 raeburn 9682: my $output =
1.306 raeburn 9683: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td style="vertical-align: top">'.$space.
1.171 raeburn 9684: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
9685: '<td valaign="top">'.$space.
9686: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 9687: for (my $i=0; $i<@rulenames; $i++) {
9688: my $rule = $rulenames[$i];
9689: my ($checked,$extra);
9690: if ($rulenames[$i] eq 'default') {
9691: $rule = '';
9692: }
9693: if ($rulenames[$i] eq 'specific') {
9694: if (ref($servers) eq 'HASH') {
9695: my $default;
9696: if (($current ne '') && (exists($servers->{$current}))) {
9697: $checked = ' checked="checked"';
9698: }
9699: unless ($checked) {
9700: $default = ' selected="selected"';
9701: }
1.210 raeburn 9702: $extra =
1.171 raeburn 9703: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
9704: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
9705: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
9706: '<option value=""'.$default.'></option>'."\n";
9707: foreach my $server (sort(keys(%{$servers}))) {
9708: if (ref($currbalancer) eq 'HASH') {
9709: next if (exists($currbalancer->{$server}));
9710: }
1.150 raeburn 9711: my $selected;
1.171 raeburn 9712: if ($server eq $current) {
1.150 raeburn 9713: $selected = ' selected="selected"';
9714: }
1.171 raeburn 9715: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 9716: }
9717: $extra .= '</select>';
9718: }
9719: } elsif ($rule eq $current) {
9720: $checked = ' checked="checked"';
9721: }
9722: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 9723: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
9724: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
9725: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.254 raeburn 9726: ')"'.$checked.' /> ';
9727: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
9728: $output .= $ruletitles{'particular'};
9729: } else {
9730: $output .= $ruletitles{$rulenames[$i]};
9731: }
9732: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 9733: }
9734: $output .= '</div></td></tr>'."\n";
9735: return $output;
9736: }
9737:
9738: sub offloadtype_text {
9739: my %ruletitles = &Apache::lonlocal::texthash (
9740: 'default' => 'Offloads to default destinations',
9741: 'homeserver' => "Offloads to user's home server",
9742: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
9743: 'specific' => 'Offloads to specific server',
1.161 raeburn 9744: 'none' => 'No offload',
1.209 raeburn 9745: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
9746: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.254 raeburn 9747: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 9748: );
9749: return %ruletitles;
9750: }
9751:
9752: sub sparestype_titles {
9753: my %typestitles = &Apache::lonlocal::texthash (
9754: 'primary' => 'primary',
9755: 'default' => 'default',
9756: );
9757: return %typestitles;
9758: }
9759:
1.28 raeburn 9760: sub contact_titles {
9761: my %titles = &Apache::lonlocal::texthash (
1.286 raeburn 9762: 'supportemail' => 'Support E-mail address',
9763: 'adminemail' => 'Default Server Admin E-mail address',
9764: 'errormail' => 'Error reports to be e-mailed to',
9765: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.315 raeburn 9766: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
9767: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.286 raeburn 9768: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
9769: 'requestsmail' => 'E-mail from course requests requiring approval',
9770: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 9771: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.350 raeburn 9772: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.378 raeburn 9773: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
9774: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.340 raeburn 9775: 'errorweights' => 'Weights used to compute error count',
9776: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 9777: );
9778: my %short_titles = &Apache::lonlocal::texthash (
9779: adminemail => 'Admin E-mail address',
9780: supportemail => 'Support E-mail',
9781: );
9782: return (\%titles,\%short_titles);
9783: }
9784:
1.286 raeburn 9785: sub helpform_fields {
9786: my %titles = &Apache::lonlocal::texthash (
9787: 'username' => 'Name',
9788: 'user' => 'Username/domain',
9789: 'phone' => 'Phone',
9790: 'cc' => 'Cc e-mail',
9791: 'course' => 'Course Details',
9792: 'section' => 'Sections',
1.289 raeburn 9793: 'screenshot' => 'File upload',
1.286 raeburn 9794: );
9795: my @fields = ('username','phone','user','course','section','cc','screenshot');
9796: my %possoptions = (
9797: username => ['yes','no','req'],
1.289 raeburn 9798: phone => ['yes','no','req'],
1.286 raeburn 9799: user => ['yes','no'],
1.289 raeburn 9800: cc => ['yes','no'],
1.286 raeburn 9801: course => ['yes','no'],
9802: section => ['yes','no'],
9803: screenshot => ['yes','no'],
9804: );
9805: my %fieldoptions = &Apache::lonlocal::texthash (
9806: 'yes' => 'Optional',
9807: 'req' => 'Required',
9808: 'no' => "Not shown",
9809: );
9810: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
9811: }
9812:
1.72 raeburn 9813: sub tool_titles {
9814: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 9815: aboutme => 'Personal web page',
1.86 raeburn 9816: blog => 'Blog',
9817: portfolio => 'Portfolio',
1.430 raeburn 9818: portaccess => 'Share portfolio files',
1.413 raeburn 9819: timezone => 'Can set time zone',
1.88 bisitz 9820: official => 'Official courses (with institutional codes)',
9821: unofficial => 'Unofficial courses',
1.98 raeburn 9822: community => 'Communities',
1.216 raeburn 9823: textbook => 'Textbook courses',
1.271 raeburn 9824: placement => 'Placement tests',
1.86 raeburn 9825: );
1.72 raeburn 9826: return %titles;
9827: }
9828:
1.101 raeburn 9829: sub courserequest_titles {
9830: my %titles = &Apache::lonlocal::texthash (
9831: official => 'Official',
9832: unofficial => 'Unofficial',
9833: community => 'Communities',
1.216 raeburn 9834: textbook => 'Textbook',
1.271 raeburn 9835: placement => 'Placement tests',
1.325 raeburn 9836: lti => 'LTI Provider',
1.101 raeburn 9837: norequest => 'Not allowed',
1.325 raeburn 9838: approval => 'Approval by DC',
1.101 raeburn 9839: validate => 'With validation',
9840: autolimit => 'Numerical limit',
1.103 raeburn 9841: unlimited => '(blank for unlimited)',
1.101 raeburn 9842: );
9843: return %titles;
9844: }
9845:
1.163 raeburn 9846: sub authorrequest_titles {
9847: my %titles = &Apache::lonlocal::texthash (
9848: norequest => 'Not allowed',
9849: approval => 'Approval by Dom. Coord.',
9850: automatic => 'Automatic approval',
9851: );
9852: return %titles;
1.210 raeburn 9853: }
1.163 raeburn 9854:
1.101 raeburn 9855: sub courserequest_conditions {
9856: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 9857: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 9858: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 9859: );
9860: return %conditions;
9861: }
9862:
9863:
1.27 raeburn 9864: sub print_usercreation {
1.30 raeburn 9865: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 9866: my $numinrow = 4;
1.28 raeburn 9867: my $datatable;
9868: if ($position eq 'top') {
1.30 raeburn 9869: $$rowtotal ++;
1.34 raeburn 9870: my $rowcount = 0;
1.32 raeburn 9871: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 9872: if (ref($rules) eq 'HASH') {
9873: if (keys(%{$rules}) > 0) {
1.32 raeburn 9874: $datatable .= &user_formats_row('username',$settings,$rules,
9875: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 9876: $$rowtotal ++;
1.32 raeburn 9877: $rowcount ++;
9878: }
9879: }
9880: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
9881: if (ref($idrules) eq 'HASH') {
9882: if (keys(%{$idrules}) > 0) {
9883: $datatable .= &user_formats_row('id',$settings,$idrules,
9884: $idruleorder,$numinrow,$rowcount);
9885: $$rowtotal ++;
9886: $rowcount ++;
1.28 raeburn 9887: }
9888: }
1.39 raeburn 9889: if ($rowcount == 0) {
9890: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
9891: $$rowtotal ++;
9892: $rowcount ++;
9893: }
1.34 raeburn 9894: } elsif ($position eq 'middle') {
1.224 raeburn 9895: my @creators = ('author','course','requestcrs');
1.37 raeburn 9896: my ($rules,$ruleorder) =
9897: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 9898: my %lt = &usercreation_types();
9899: my %checked;
9900: if (ref($settings) eq 'HASH') {
9901: if (ref($settings->{'cancreate'}) eq 'HASH') {
9902: foreach my $item (@creators) {
9903: $checked{$item} = $settings->{'cancreate'}{$item};
9904: }
9905: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
9906: foreach my $item (@creators) {
9907: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
9908: $checked{$item} = 'none';
9909: }
9910: }
9911: }
9912: }
9913: my $rownum = 0;
9914: foreach my $item (@creators) {
9915: $rownum ++;
1.224 raeburn 9916: if ($checked{$item} eq '') {
9917: $checked{$item} = 'any';
1.34 raeburn 9918: }
9919: my $css_class;
9920: if ($rownum%2) {
9921: $css_class = '';
9922: } else {
9923: $css_class = ' class="LC_odd_row" ';
9924: }
9925: $datatable .= '<tr'.$css_class.'>'.
9926: '<td><span class="LC_nobreak">'.$lt{$item}.
1.306 raeburn 9927: '</span></td><td style="text-align: right">';
1.224 raeburn 9928: my @options = ('any');
9929: if (ref($rules) eq 'HASH') {
9930: if (keys(%{$rules}) > 0) {
9931: push(@options,('official','unofficial'));
1.37 raeburn 9932: }
9933: }
1.224 raeburn 9934: push(@options,'none');
1.37 raeburn 9935: foreach my $option (@options) {
1.50 raeburn 9936: my $type = 'radio';
1.34 raeburn 9937: my $check = ' ';
1.224 raeburn 9938: if ($checked{$item} eq $option) {
9939: $check = ' checked="checked" ';
1.34 raeburn 9940: }
9941: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 9942: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 9943: $item.'" value="'.$option.'"'.$check.'/> '.
9944: $lt{$option}.'</label> </span>';
9945: }
9946: $datatable .= '</td></tr>';
9947: }
1.28 raeburn 9948: } else {
9949: my @contexts = ('author','course','domain');
1.325 raeburn 9950: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 9951: my %checked;
9952: if (ref($settings) eq 'HASH') {
9953: if (ref($settings->{'authtypes'}) eq 'HASH') {
9954: foreach my $item (@contexts) {
9955: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
9956: foreach my $auth (@authtypes) {
9957: if ($settings->{'authtypes'}{$item}{$auth}) {
9958: $checked{$item}{$auth} = ' checked="checked" ';
9959: }
9960: }
9961: }
9962: }
1.27 raeburn 9963: }
1.35 raeburn 9964: } else {
9965: foreach my $item (@contexts) {
1.36 raeburn 9966: foreach my $auth (@authtypes) {
1.35 raeburn 9967: $checked{$item}{$auth} = ' checked="checked" ';
9968: }
9969: }
1.27 raeburn 9970: }
1.28 raeburn 9971: my %title = &context_names();
9972: my %authname = &authtype_names();
9973: my $rownum = 0;
9974: my $css_class;
9975: foreach my $item (@contexts) {
9976: if ($rownum%2) {
9977: $css_class = '';
9978: } else {
9979: $css_class = ' class="LC_odd_row" ';
9980: }
1.30 raeburn 9981: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 9982: '<td>'.$title{$item}.
9983: '</td><td class="LC_left_item">'.
9984: '<span class="LC_nobreak">';
9985: foreach my $auth (@authtypes) {
9986: $datatable .= '<label>'.
9987: '<input type="checkbox" name="'.$item.'_auth" '.
9988: $checked{$item}{$auth}.' value="'.$auth.'" />'.
9989: $authname{$auth}.'</label> ';
9990: }
9991: $datatable .= '</span></td></tr>';
9992: $rownum ++;
1.27 raeburn 9993: }
1.30 raeburn 9994: $$rowtotal += $rownum;
1.27 raeburn 9995: }
9996: return $datatable;
9997: }
9998:
1.224 raeburn 9999: sub print_selfcreation {
10000: my ($position,$dom,$settings,$rowtotal) = @_;
1.305 raeburn 10001: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
10002: $emaildomain,$datatable);
1.224 raeburn 10003: if (ref($settings) eq 'HASH') {
10004: if (ref($settings->{'cancreate'}) eq 'HASH') {
10005: $createsettings = $settings->{'cancreate'};
1.236 raeburn 10006: if (ref($createsettings) eq 'HASH') {
10007: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
10008: @selfcreate = @{$createsettings->{'selfcreate'}};
10009: } elsif ($createsettings->{'selfcreate'} ne '') {
10010: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
10011: @selfcreate = ('email','login','sso');
10012: } elsif ($createsettings->{'selfcreate'} ne 'none') {
10013: @selfcreate = ($createsettings->{'selfcreate'});
10014: }
10015: }
10016: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
10017: $processing = $createsettings->{'selfcreateprocessing'};
1.224 raeburn 10018: }
1.305 raeburn 10019: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
10020: $emailoptions = $createsettings->{'emailoptions'};
10021: }
1.303 raeburn 10022: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
10023: $emailverified = $createsettings->{'emailverified'};
10024: }
10025: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
10026: $emaildomain = $createsettings->{'emaildomain'};
10027: }
1.224 raeburn 10028: }
10029: }
10030: }
10031: my %radiohash;
10032: my $numinrow = 4;
10033: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.302 raeburn 10034: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.224 raeburn 10035: if ($position eq 'top') {
10036: my %choices = &Apache::lonlocal::texthash (
10037: cancreate_login => 'Institutional Login',
10038: cancreate_sso => 'Institutional Single Sign On',
10039: );
10040: my @toggles = sort(keys(%choices));
10041: my %defaultchecked = (
10042: 'cancreate_login' => 'off',
10043: 'cancreate_sso' => 'off',
10044: );
1.228 raeburn 10045: my ($onclick,$itemcount);
1.224 raeburn 10046: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10047: \%choices,$itemcount,$onclick);
1.228 raeburn 10048: $$rowtotal += $itemcount;
1.425 raeburn 10049:
1.224 raeburn 10050: if (ref($usertypes) eq 'HASH') {
10051: if (keys(%{$usertypes}) > 0) {
10052: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
10053: $dom,$numinrow,$othertitle,
1.305 raeburn 10054: 'statustocreate',$rowtotal);
1.224 raeburn 10055: $$rowtotal ++;
10056: }
10057: }
1.240 raeburn 10058: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
10059: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10060: $fieldtitles{'inststatus'} = &mt('Institutional status');
10061: my $rem;
10062: my $numperrow = 2;
10063: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
10064: $datatable .= '<tr'.$css_class.'>'.
1.241 raeburn 10065: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.240 raeburn 10066: '<td class="LC_left_item">'."\n".
1.334 raeburn 10067: '<table>'."\n";
1.240 raeburn 10068: for (my $i=0; $i<@fields; $i++) {
10069: $rem = $i%($numperrow);
10070: if ($rem == 0) {
10071: if ($i > 0) {
10072: $datatable .= '</tr>';
10073: }
10074: $datatable .= '<tr>';
10075: }
10076: my $currval;
1.248 raeburn 10077: if (ref($createsettings) eq 'HASH') {
10078: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
10079: $currval = $createsettings->{'shibenv'}{$fields[$i]};
10080: }
1.240 raeburn 10081: }
10082: $datatable .= '<td class="LC_left_item">'.
10083: '<span class="LC_nobreak">'.
10084: '<input type="text" name="shibenv_'.$fields[$i].'" '.
10085: 'value="'.$currval.'" size="10" /> '.
10086: $fieldtitles{$fields[$i]}.'</span></td>';
10087: }
10088: my $colsleft = $numperrow - $rem;
10089: if ($colsleft > 1 ) {
10090: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10091: ' </td>';
10092: } elsif ($colsleft == 1) {
10093: $datatable .= '<td class="LC_left_item"> </td>';
10094: }
10095: $datatable .= '</tr></table></td></tr>';
10096: $$rowtotal ++;
1.224 raeburn 10097: } elsif ($position eq 'middle') {
10098: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.302 raeburn 10099: my @posstypes;
1.224 raeburn 10100: if (ref($types) eq 'ARRAY') {
1.302 raeburn 10101: @posstypes = @{$types};
10102: }
10103: unless (grep(/^default$/,@posstypes)) {
10104: push(@posstypes,'default');
10105: }
10106: my %usertypeshash;
10107: if (ref($usertypes) eq 'HASH') {
10108: %usertypeshash = %{$usertypes};
10109: }
10110: $usertypeshash{'default'} = $othertitle;
10111: foreach my $status (@posstypes) {
10112: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
10113: $numinrow,$$rowtotal,\%usertypeshash);
10114: $$rowtotal ++;
1.224 raeburn 10115: }
10116: } else {
1.236 raeburn 10117: my %choices = &Apache::lonlocal::texthash (
1.305 raeburn 10118: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.236 raeburn 10119: );
10120: my @toggles = sort(keys(%choices));
10121: my %defaultchecked = (
10122: 'cancreate_email' => 'off',
10123: );
1.305 raeburn 10124: my $customclass = 'LC_selfcreate_email';
10125: my $classprefix = 'LC_canmodify_emailusername_';
10126: my $optionsprefix = 'LC_options_emailusername_';
1.236 raeburn 10127: my $display = 'none';
1.305 raeburn 10128: my $rowstyle = 'display:none';
1.236 raeburn 10129: if (grep(/^\Qemail\E$/,@selfcreate)) {
10130: $display = 'block';
1.305 raeburn 10131: $rowstyle = 'display:table-row';
1.236 raeburn 10132: }
1.305 raeburn 10133: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
10134: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
10135: \%choices,$$rowtotal,$onclick);
10136: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
10137: $rowstyle);
10138: $$rowtotal ++;
10139: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
10140: $rowstyle);
10141: $$rowtotal ++;
10142: my (@ordered,@posstypes,%usertypeshash);
1.236 raeburn 10143: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.305 raeburn 10144: my ($emailrules,$emailruleorder) =
10145: &Apache::lonnet::inst_userrules($dom,'email');
10146: my $primary_id = &Apache::lonnet::domain($dom,'primary');
10147: my $intdom = &Apache::lonnet::internet_dom($primary_id);
10148: if (ref($types) eq 'ARRAY') {
10149: @posstypes = @{$types};
10150: }
10151: if (@posstypes) {
10152: unless (grep(/^default$/,@posstypes)) {
10153: push(@posstypes,'default');
1.302 raeburn 10154: }
10155: if (ref($usertypes) eq 'HASH') {
10156: %usertypeshash = %{$usertypes};
10157: }
1.305 raeburn 10158: my $currassign;
10159: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
10160: $currassign = {
10161: selfassign => $domdefaults{'inststatusguest'},
10162: };
10163: @ordered = @{$domdefaults{'inststatusguest'}};
10164: } else {
10165: $currassign = { selfassign => [] };
10166: }
10167: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
10168: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
10169: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
10170: $numinrow,$othertitle,'selfassign',
10171: $rowtotal,$onclicktypes,$customclass,
10172: $rowstyle);
10173: $$rowtotal ++;
1.302 raeburn 10174: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10175: foreach my $status (@posstypes) {
10176: my $css_class;
10177: if ($$rowtotal%2) {
10178: $css_class = 'LC_odd_row ';
10179: }
10180: $css_class .= $customclass;
10181: my $rowid = $optionsprefix.$status;
10182: my $hidden = 1;
10183: my $currstyle = 'display:none';
10184: if (grep(/^\Q$status\E$/,@ordered)) {
10185: $currstyle = $rowstyle;
1.425 raeburn 10186: $hidden = 0;
1.305 raeburn 10187: }
10188: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10189: $emailrules,$emailruleorder,$settings,$status,$rowid,
10190: $usertypeshash{$status},$css_class,$currstyle,$intdom);
10191: unless ($hidden) {
10192: $$rowtotal ++;
10193: }
1.224 raeburn 10194: }
1.302 raeburn 10195: } else {
1.305 raeburn 10196: my $css_class;
10197: if ($$rowtotal%2) {
10198: $css_class = 'LC_odd_row ';
10199: }
10200: $css_class .= $customclass;
1.302 raeburn 10201: $usertypeshash{'default'} = $othertitle;
1.305 raeburn 10202: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
10203: $emailrules,$emailruleorder,$settings,'default','',
10204: $othertitle,$css_class,$rowstyle,$intdom);
10205: $$rowtotal ++;
1.224 raeburn 10206: }
10207: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
1.228 raeburn 10208: $numinrow = 1;
1.305 raeburn 10209: if (@posstypes) {
10210: foreach my $status (@posstypes) {
10211: my $rowid = $classprefix.$status;
10212: my $datarowstyle = 'display:none';
1.425 raeburn 10213: if (grep(/^\Q$status\E$/,@ordered)) {
10214: $datarowstyle = $rowstyle;
1.305 raeburn 10215: }
10216: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
10217: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10218: $infotitles,$rowid,$customclass,$datarowstyle);
10219: unless ($datarowstyle eq 'display:none') {
10220: $$rowtotal ++;
10221: }
1.224 raeburn 10222: }
1.305 raeburn 10223: } else {
10224: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
10225: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
10226: $infotitles,'',$customclass,$rowstyle);
1.224 raeburn 10227: }
10228: }
10229: return $datatable;
10230: }
10231:
1.305 raeburn 10232: sub selfcreate_javascript {
10233: return <<"ENDSCRIPT";
10234:
10235: <script type="text/javascript">
10236: // <![CDATA[
10237:
10238: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
10239: var x = document.getElementsByClassName(target);
10240: var insttypes = 0;
10241: var insttypeRegExp = new RegExp(prefix);
10242: if ((x.length != undefined) && (x.length > 0)) {
10243: if (form.elements[radio].length != undefined) {
10244: for (var i=0; i<form.elements[radio].length; i++) {
10245: if (form.elements[radio][i].checked) {
10246: if (form.elements[radio][i].value == 1) {
10247: for (var j=0; j<x.length; j++) {
10248: if (x[j].id == 'undefined') {
10249: x[j].style.display = 'table-row';
10250: } else if (insttypeRegExp.test(x[j].id)) {
10251: insttypes ++;
10252: } else {
10253: x[j].style.display = 'table-row';
10254: }
10255: }
10256: } else {
10257: for (var j=0; j<x.length; j++) {
10258: x[j].style.display = 'none';
10259: }
1.236 raeburn 10260: }
1.305 raeburn 10261: break;
10262: }
10263: }
10264: if (insttypes > 0) {
10265: toggleDataRow(form,checkbox,target,altprefix);
10266: toggleDataRow(form,checkbox,target,prefix,1);
10267: }
10268: }
10269: }
10270: return;
10271: }
10272:
10273: function toggleDataRow(form,checkbox,target,prefix,docount) {
10274: if (form.elements[checkbox].length != undefined) {
10275: var count = 0;
10276: if (docount) {
10277: for (var i=0; i<form.elements[checkbox].length; i++) {
10278: if (form.elements[checkbox][i].checked) {
10279: count ++;
1.236 raeburn 10280: }
1.305 raeburn 10281: }
10282: }
10283: for (var i=0; i<form.elements[checkbox].length; i++) {
10284: var type = form.elements[checkbox][i].value;
10285: if (document.getElementById(prefix+type)) {
10286: if (form.elements[checkbox][i].checked) {
10287: document.getElementById(prefix+type).style.display = 'table-row';
10288: if (count % 2 == 1) {
10289: document.getElementById(prefix+type).className = target+' LC_odd_row';
10290: } else {
10291: document.getElementById(prefix+type).className = target;
1.236 raeburn 10292: }
1.305 raeburn 10293: count ++;
1.236 raeburn 10294: } else {
1.305 raeburn 10295: document.getElementById(prefix+type).style.display = 'none';
10296: }
10297: }
10298: }
10299: }
10300: return;
10301: }
10302:
10303: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
10304: var caller = radio+'_'+status;
10305: if (form.elements[caller].length != undefined) {
10306: for (var i=0; i<form.elements[caller].length; i++) {
10307: if (form.elements[caller][i].checked) {
10308: if (document.getElementById(altprefix+'_inst_'+status)) {
10309: var curr = form.elements[caller][i].value;
10310: if (prefix) {
10311: document.getElementById(prefix+'_'+status).style.display = 'none';
10312: }
10313: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
10314: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
10315: if (curr == 'custom') {
1.425 raeburn 10316: if (prefix) {
1.305 raeburn 10317: document.getElementById(prefix+'_'+status).style.display = 'inline';
10318: }
10319: } else if (curr == 'inst') {
10320: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
10321: } else if (curr == 'noninst') {
10322: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.236 raeburn 10323: }
1.305 raeburn 10324: break;
1.236 raeburn 10325: }
10326: }
10327: }
10328: }
10329: }
10330:
1.305 raeburn 10331: // ]]>
10332: </script>
10333:
10334: ENDSCRIPT
10335: }
10336:
10337: sub noninst_users {
10338: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
1.425 raeburn 10339: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
1.305 raeburn 10340: my $class = 'LC_left_item';
10341: if ($css_class) {
1.425 raeburn 10342: $css_class = ' class="'.$css_class.'"';
1.305 raeburn 10343: }
10344: if ($rowid) {
10345: $rowid = ' id="'.$rowid.'"';
10346: }
10347: if ($rowstyle) {
10348: $rowstyle = ' style="'.$rowstyle.'"';
10349: }
10350: my ($output,$description);
10351: if ($type eq 'default') {
10352: $description = &mt('Requests for: [_1]',$typetitle);
10353: } else {
10354: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
10355: }
10356: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
1.425 raeburn 10357: "<td>$description</td>\n".
1.305 raeburn 10358: '<td class="'.$class.'" colspan="2">'.
10359: '<table><tr>';
1.425 raeburn 10360: my %headers = &Apache::lonlocal::texthash(
1.305 raeburn 10361: approve => 'Processing',
10362: email => 'E-mail',
10363: username => 'Username',
10364: );
10365: foreach my $item ('approve','email','username') {
10366: $output .= '<th>'.$headers{$item}.'</th>';
1.303 raeburn 10367: }
1.305 raeburn 10368: $output .= '</tr><tr>';
10369: foreach my $item ('approve','email','username') {
1.306 raeburn 10370: $output .= '<td style="vertical-align: top">';
1.305 raeburn 10371: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
10372: if ($item eq 'approve') {
10373: %choices = &Apache::lonlocal::texthash (
10374: automatic => 'Automatically approved',
10375: approval => 'Queued for approval',
10376: );
10377: @options = ('automatic','approval');
10378: $hashref = $processing;
10379: $defoption = 'automatic';
10380: $name = 'cancreate_emailprocess_'.$type;
10381: } elsif ($item eq 'email') {
10382: %choices = &Apache::lonlocal::texthash (
10383: any => 'Any e-mail',
10384: inst => 'Institutional only',
10385: noninst => 'Non-institutional only',
10386: custom => 'Custom restrictions',
10387: );
10388: @options = ('any','inst','noninst');
10389: my $showcustom;
10390: if (ref($emailrules) eq 'HASH') {
10391: if (keys(%{$emailrules}) > 0) {
10392: push(@options,'custom');
10393: $showcustom = 'cancreate_emailrule';
10394: if (ref($settings) eq 'HASH') {
10395: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
10396: foreach my $rule (@{$settings->{'email_rule'}}) {
10397: if (exists($emailrules->{$rule})) {
10398: $hascustom ++;
10399: }
10400: }
10401: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
10402: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
10403: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
10404: if (exists($emailrules->{$rule})) {
10405: $hascustom ++;
10406: }
10407: }
10408: }
10409: }
10410: }
10411: }
10412: }
10413: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
10414: "'cancreate_emaildomain','$type'".');"';
10415: $hashref = $emailoptions;
10416: $defoption = 'any';
10417: $name = 'cancreate_emailoptions_'.$type;
10418: } elsif ($item eq 'username') {
10419: %choices = &Apache::lonlocal::texthash (
10420: all => 'Same as e-mail',
10421: first => 'Omit @domain',
10422: free => 'Free to choose',
10423: );
10424: @options = ('all','first','free');
10425: $hashref = $emailverified;
10426: $defoption = 'all';
10427: $name = 'cancreate_usernameoptions_'.$type;
10428: }
10429: foreach my $option (@options) {
10430: my $checked;
10431: if (ref($hashref) eq 'HASH') {
10432: if ($type eq '') {
10433: if (!exists($hashref->{'default'})) {
10434: if ($option eq $defoption) {
10435: $checked = ' checked="checked"';
10436: }
10437: } else {
10438: if ($hashref->{'default'} eq $option) {
10439: $checked = ' checked="checked"';
10440: }
1.303 raeburn 10441: }
10442: } else {
1.305 raeburn 10443: if (!exists($hashref->{$type})) {
10444: if ($option eq $defoption) {
10445: $checked = ' checked="checked"';
10446: }
10447: } else {
10448: if ($hashref->{$type} eq $option) {
10449: $checked = ' checked="checked"';
10450: }
1.303 raeburn 10451: }
10452: }
1.305 raeburn 10453: } elsif (($item eq 'email') && ($hascustom)) {
10454: if ($option eq 'custom') {
10455: $checked = ' checked="checked"';
10456: }
10457: } elsif ($option eq $defoption) {
10458: $checked = ' checked="checked"';
10459: }
10460: $output .= '<span class="LC_nobreak"><label>'.
10461: '<input type="radio" name="'.$name.'"'.
10462: $checked.' value="'.$option.'"'.$onclick.' />'.
10463: $choices{$option}.'</label></span><br />';
10464: if ($item eq 'email') {
10465: if ($option eq 'custom') {
10466: my $id = 'cancreate_emailrule_'.$type;
10467: my $display = 'none';
10468: if ($checked) {
10469: $display = 'inline';
1.303 raeburn 10470: }
1.305 raeburn 10471: my $numinrow = 2;
10472: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
10473: '<legend>'.&mt('Disallow').'</legend><table>'.
10474: &user_formats_row('email',$settings,$emailrules,
10475: $emailruleorder,$numinrow,'',$type);
10476: '</table></fieldset>';
10477: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
10478: my %text = &Apache::lonlocal::texthash (
10479: inst => 'must end:',
10480: noninst => 'cannot end:',
10481: );
10482: my $value;
10483: if (ref($emaildomain) eq 'HASH') {
10484: if (ref($emaildomain->{$type}) eq 'HASH') {
1.425 raeburn 10485: $value = $emaildomain->{$type}->{$option};
1.303 raeburn 10486: }
10487: }
1.305 raeburn 10488: if ($value eq '') {
10489: $value = '@'.$intdom;
10490: }
10491: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
10492: my $display = 'none';
10493: if ($checked) {
10494: $display = 'inline';
10495: }
10496: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
10497: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
10498: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
10499: '</div>';
1.303 raeburn 10500: }
10501: }
10502: }
1.305 raeburn 10503: $output .= '</td>'."\n";
1.303 raeburn 10504: }
1.305 raeburn 10505: $output .= "</tr></table></td></tr>\n";
1.303 raeburn 10506: return $output;
10507: }
10508:
1.165 raeburn 10509: sub captcha_choice {
1.305 raeburn 10510: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.269 raeburn 10511: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
10512: $vertext,$currver);
1.165 raeburn 10513: my %lt = &captcha_phrases();
10514: $keyentry = 'hidden';
1.354 raeburn 10515: my $colspan=2;
1.165 raeburn 10516: if ($context eq 'cancreate') {
1.224 raeburn 10517: $rowname = &mt('CAPTCHA validation');
1.169 raeburn 10518: } elsif ($context eq 'login') {
10519: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.354 raeburn 10520: } elsif ($context eq 'passwords') {
10521: $rowname = &mt('"Forgot Password" CAPTCHA validation');
10522: $colspan=1;
1.165 raeburn 10523: }
10524: if (ref($settings) eq 'HASH') {
10525: if ($settings->{'captcha'}) {
10526: $checked{$settings->{'captcha'}} = ' checked="checked"';
10527: } else {
10528: $checked{'original'} = ' checked="checked"';
10529: }
10530: if ($settings->{'captcha'} eq 'recaptcha') {
10531: $pubtext = $lt{'pub'};
10532: $privtext = $lt{'priv'};
10533: $keyentry = 'text';
1.269 raeburn 10534: $vertext = $lt{'ver'};
10535: $currver = $settings->{'recaptchaversion'};
10536: if ($currver ne '2') {
10537: $currver = 1;
10538: }
1.165 raeburn 10539: }
10540: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
10541: $currpub = $settings->{'recaptchakeys'}{'public'};
10542: $currpriv = $settings->{'recaptchakeys'}{'private'};
10543: }
10544: } else {
10545: $checked{'original'} = ' checked="checked"';
10546: }
1.305 raeburn 10547: my $css_class;
10548: if ($itemcount%2) {
10549: $css_class = 'LC_odd_row';
10550: }
10551: if ($customcss) {
10552: $css_class .= " $customcss";
10553: }
10554: $css_class =~ s/^\s+//;
10555: if ($css_class) {
10556: $css_class = ' class="'.$css_class.'"';
10557: }
10558: if ($rowstyle) {
10559: $css_class .= ' style="'.$rowstyle.'"';
10560: }
1.169 raeburn 10561: my $output = '<tr'.$css_class.'>'.
1.354 raeburn 10562: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.165 raeburn 10563: '<table><tr><td>'."\n";
10564: foreach my $option ('original','recaptcha','notused') {
10565: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
10566: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
10567: $lt{$option}.'</label></span>';
10568: unless ($option eq 'notused') {
10569: $output .= (' 'x2)."\n";
10570: }
10571: }
10572: #
10573: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
10574: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 10575: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 10576: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 10577: #
1.165 raeburn 10578: $output .= '</td></tr>'."\n".
1.305 raeburn 10579: '<tr><td class="LC_zero_height">'."\n".
1.165 raeburn 10580: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
10581: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
10582: $currpub.'" size="40" /></span><br />'."\n".
10583: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
10584: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.269 raeburn 10585: $currpriv.'" size="40" /></span><br />'.
10586: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
10587: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
10588: $currver.'" size="3" /></span><br />'.
10589: '</td></tr></table>'."\n".
1.165 raeburn 10590: '</td></tr>';
10591: return $output;
10592: }
10593:
1.32 raeburn 10594: sub user_formats_row {
1.305 raeburn 10595: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 10596: my $output;
10597: my %text = (
10598: 'username' => 'new usernames',
10599: 'id' => 'IDs',
10600: );
1.409 raeburn 10601: unless (($type eq 'email') || ($type eq 'unamemap')) {
1.305 raeburn 10602: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
10603: $output = '<tr '.$css_class.'>'.
10604: '<td><span class="LC_nobreak">'.
10605: &mt("Format rules to check for $text{$type}: ").
10606: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 10607: }
1.27 raeburn 10608: my $rem;
10609: if (ref($ruleorder) eq 'ARRAY') {
10610: for (my $i=0; $i<@{$ruleorder}; $i++) {
10611: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
10612: my $rem = $i%($numinrow);
10613: if ($rem == 0) {
10614: if ($i > 0) {
10615: $output .= '</tr>';
10616: }
10617: $output .= '<tr>';
10618: }
10619: my $check = ' ';
1.39 raeburn 10620: if (ref($settings) eq 'HASH') {
10621: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
10622: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
10623: $check = ' checked="checked" ';
10624: }
1.305 raeburn 10625: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
10626: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
10627: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
10628: $check = ' checked="checked" ';
10629: }
10630: }
1.27 raeburn 10631: }
10632: }
1.305 raeburn 10633: my $name = $type.'_rule';
10634: if ($type eq 'email') {
10635: $name .= '_'.$status;
10636: }
1.27 raeburn 10637: $output .= '<td class="LC_left_item">'.
10638: '<span class="LC_nobreak"><label>'.
1.311 raeburn 10639: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 10640: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
10641: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
10642: }
10643: }
10644: $rem = @{$ruleorder}%($numinrow);
10645: }
1.305 raeburn 10646: my $colsleft;
10647: if ($rem) {
10648: $colsleft = $numinrow - $rem;
10649: }
1.27 raeburn 10650: if ($colsleft > 1 ) {
10651: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10652: ' </td>';
10653: } elsif ($colsleft == 1) {
10654: $output .= '<td class="LC_left_item"> </td>';
10655: }
1.409 raeburn 10656: $output .= '</tr>';
10657: unless (($type eq 'email') || ($type eq 'unamemap')) {
10658: $output .= '</table></td></tr>';
1.305 raeburn 10659: }
1.27 raeburn 10660: return $output;
10661: }
10662:
1.34 raeburn 10663: sub usercreation_types {
10664: my %lt = &Apache::lonlocal::texthash (
10665: author => 'When adding a co-author',
10666: course => 'When adding a user to a course',
1.100 raeburn 10667: requestcrs => 'When requesting a course',
1.34 raeburn 10668: any => 'Any',
10669: official => 'Institutional only ',
10670: unofficial => 'Non-institutional only',
10671: none => 'None',
10672: );
10673: return %lt;
1.48 raeburn 10674: }
1.34 raeburn 10675:
1.224 raeburn 10676: sub selfcreation_types {
10677: my %lt = &Apache::lonlocal::texthash (
10678: selfcreate => 'User creates own account',
10679: any => 'Any',
10680: official => 'Institutional only ',
10681: unofficial => 'Non-institutional only',
10682: email => 'E-mail address',
10683: login => 'Institutional Login',
10684: sso => 'SSO',
10685: );
10686: }
10687:
1.28 raeburn 10688: sub authtype_names {
10689: my %lt = &Apache::lonlocal::texthash(
10690: int => 'Internal',
10691: krb4 => 'Kerberos 4',
10692: krb5 => 'Kerberos 5',
10693: loc => 'Local',
1.325 raeburn 10694: lti => 'LTI',
1.28 raeburn 10695: );
10696: return %lt;
10697: }
10698:
10699: sub context_names {
10700: my %context_title = &Apache::lonlocal::texthash(
10701: author => 'Creating users when an Author',
10702: course => 'Creating users when in a course',
10703: domain => 'Creating users when a Domain Coordinator',
10704: );
10705: return %context_title;
10706: }
10707:
1.33 raeburn 10708: sub print_usermodification {
10709: my ($position,$dom,$settings,$rowtotal) = @_;
10710: my $numinrow = 4;
10711: my ($context,$datatable,$rowcount);
10712: if ($position eq 'top') {
10713: $rowcount = 0;
10714: $context = 'author';
10715: foreach my $role ('ca','aa') {
10716: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10717: $numinrow,$rowcount);
10718: $$rowtotal ++;
10719: $rowcount ++;
10720: }
1.443 raeburn 10721: } elsif ($position eq 'middle') {
10722: $rowcount = 0;
10723: $context = 'coauthor';
10724: foreach my $role ('ca','aa') {
10725: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10726: $numinrow,$rowcount);
10727: $$rowtotal ++;
10728: $rowcount ++;
10729: }
1.230 raeburn 10730: } elsif ($position eq 'bottom') {
1.33 raeburn 10731: $context = 'course';
10732: $rowcount = 0;
10733: foreach my $role ('st','ep','ta','in','cr') {
10734: $datatable .= &modifiable_userdata_row($context,$role,$settings,
10735: $numinrow,$rowcount);
10736: $$rowtotal ++;
10737: $rowcount ++;
10738: }
10739: }
10740: return $datatable;
10741: }
10742:
1.43 raeburn 10743: sub print_defaults {
1.236 raeburn 10744: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 10745: my $rownum = 0;
1.294 raeburn 10746: my ($datatable,$css_class,$titles);
10747: unless ($position eq 'bottom') {
10748: $titles = &defaults_titles($dom);
10749: }
1.236 raeburn 10750: if ($position eq 'top') {
10751: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
10752: 'datelocale_def','portal_def');
10753: my %defaults;
10754: if (ref($settings) eq 'HASH') {
10755: %defaults = %{$settings};
1.43 raeburn 10756: } else {
1.236 raeburn 10757: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
10758: foreach my $item (@items) {
10759: $defaults{$item} = $domdefaults{$item};
10760: }
1.43 raeburn 10761: }
1.236 raeburn 10762: foreach my $item (@items) {
10763: if ($rownum%2) {
10764: $css_class = '';
10765: } else {
10766: $css_class = ' class="LC_odd_row" ';
10767: }
10768: $datatable .= '<tr'.$css_class.'>'.
10769: '<td><span class="LC_nobreak">'.$titles->{$item}.
10770: '</span></td><td class="LC_right_item" colspan="3">';
10771: if ($item eq 'auth_def') {
1.325 raeburn 10772: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.236 raeburn 10773: my %shortauth = (
10774: internal => 'int',
10775: krb4 => 'krb4',
10776: krb5 => 'krb5',
1.325 raeburn 10777: localauth => 'loc',
10778: lti => 'lti',
1.236 raeburn 10779: );
10780: my %authnames = &authtype_names();
10781: foreach my $auth (@authtypes) {
10782: my $checked = ' ';
10783: if ($defaults{$item} eq $auth) {
10784: $checked = ' checked="checked" ';
10785: }
10786: $datatable .= '<label><input type="radio" name="'.$item.
10787: '" value="'.$auth.'"'.$checked.'/>'.
10788: $authnames{$shortauth{$auth}}.'</label> ';
10789: }
10790: } elsif ($item eq 'timezone_def') {
10791: my $includeempty = 1;
10792: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
10793: } elsif ($item eq 'datelocale_def') {
10794: my $includeempty = 1;
10795: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
10796: } elsif ($item eq 'lang_def') {
1.263 raeburn 10797: my $includeempty = 1;
10798: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.414 raeburn 10799: } elsif ($item eq 'portal_def') {
10800: $datatable .= '<input type="text" name="'.$item.'" value="'.
10801: $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
10802: my $portalsty = 'none';
10803: if ($defaults{$item}) {
10804: $portalsty = 'block';
10805: }
10806: foreach my $field ('email','web') {
10807: my $checkedoff = ' checked="checked"';
10808: my $checkedon;
10809: if ($defaults{$item.'_'.$field}) {
10810: $checkedon = $checkedoff;
10811: $checkedoff = '';
1.425 raeburn 10812: }
1.414 raeburn 10813: $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
10814: '<span class="LC_nobreak">'.$titles->{$field}.' '.
10815: '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
10816: (' 'x2).
10817: '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
10818: '</div>';
10819: }
1.236 raeburn 10820: } else {
1.414 raeburn 10821: $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.43 raeburn 10822: }
1.236 raeburn 10823: $datatable .= '</td></tr>';
10824: $rownum ++;
10825: }
1.409 raeburn 10826: } elsif ($position eq 'middle') {
1.294 raeburn 10827: my %defaults;
10828: if (ref($settings) eq 'HASH') {
1.354 raeburn 10829: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10830: my $maxnum = @{$settings->{'inststatusorder'}};
10831: for (my $i=0; $i<$maxnum; $i++) {
10832: $css_class = $rownum%2?' class="LC_odd_row"':'';
10833: my $item = $settings->{'inststatusorder'}->[$i];
10834: my $title = $settings->{'inststatustypes'}->{$item};
10835: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
10836: $datatable .= '<tr'.$css_class.'>'.
10837: '<td><span class="LC_nobreak">'.
10838: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
10839: for (my $k=0; $k<=$maxnum; $k++) {
10840: my $vpos = $k+1;
10841: my $selstr;
10842: if ($k == $i) {
10843: $selstr = ' selected="selected" ';
10844: }
10845: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10846: }
10847: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
10848: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
10849: &mt('delete').'</span></td>'.
1.380 raeburn 10850: '<td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.354 raeburn 10851: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
10852: '</span></td></tr>';
10853: }
10854: $css_class = $rownum%2?' class="LC_odd_row"':'';
10855: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
10856: $datatable .= '<tr '.$css_class.'>'.
10857: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
10858: for (my $k=0; $k<=$maxnum; $k++) {
10859: my $vpos = $k+1;
10860: my $selstr;
10861: if ($k == $maxnum) {
10862: $selstr = ' selected="selected" ';
10863: }
10864: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10865: }
10866: $datatable .= '</select> '.&mt('Internal ID:').
10867: '<input type="text" size="10" name="addinststatus" value="" />'.
10868: ' '.&mt('(new)').
10869: '</span></td><td class="LC_left_item" colspan="2"><span class="LC_nobreak">'.
1.380 raeburn 10870: &mt('Name displayed').':'.
1.354 raeburn 10871: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
10872: '</tr>'."\n";
10873: $rownum ++;
1.294 raeburn 10874: }
1.354 raeburn 10875: }
1.409 raeburn 10876: } else {
10877: my ($unamemaprules,$ruleorder) =
10878: &Apache::lonnet::inst_userrules($dom,'unamemap');
10879: $css_class = $rownum%2?' class="LC_odd_row"':'';
10880: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10881: my $numinrow = 2;
10882: $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
10883: &user_formats_row('unamemap',$settings,$unamemaprules,
10884: $ruleorder,$numinrow).
10885: '</table></td></tr>';
10886: }
10887: if ($datatable eq '') {
10888: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
10889: &mt('No rules set for domain in customized localenroll.pm').
10890: '</td></tr>';
10891: }
1.354 raeburn 10892: }
10893: $$rowtotal += $rownum;
1.43 raeburn 10894: return $datatable;
10895: }
10896:
1.168 raeburn 10897: sub get_languages_hash {
10898: my %langchoices;
10899: foreach my $id (&Apache::loncommon::languageids()) {
10900: my $code = &Apache::loncommon::supportedlanguagecode($id);
10901: if ($code ne '') {
10902: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
10903: }
10904: }
10905: return %langchoices;
10906: }
10907:
1.43 raeburn 10908: sub defaults_titles {
1.141 raeburn 10909: my ($dom) = @_;
1.43 raeburn 10910: my %titles = &Apache::lonlocal::texthash (
10911: 'auth_def' => 'Default authentication type',
10912: 'auth_arg_def' => 'Default authentication argument',
10913: 'lang_def' => 'Default language',
1.54 raeburn 10914: 'timezone_def' => 'Default timezone',
1.68 raeburn 10915: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 10916: 'portal_def' => 'Portal/Default URL',
1.414 raeburn 10917: 'email' => 'Email links use portal URL',
10918: 'web' => 'Public web links use portal URL',
1.294 raeburn 10919: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
10920: 'intauth_check' => 'Check bcrypt cost if authenticated',
10921: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 10922: );
1.141 raeburn 10923: if ($dom) {
10924: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
10925: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
10926: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
10927: $protocol = 'http' if ($protocol ne 'https');
10928: if ($uint_dom) {
10929: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
10930: $uint_dom);
10931: }
10932: }
1.43 raeburn 10933: return (\%titles);
10934: }
10935:
1.346 raeburn 10936: sub print_scantron {
10937: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
10938: if ($position eq 'top') {
10939: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
10940: } else {
10941: return &print_scantronconfig($dom,$settings,\$rowtotal);
10942: }
10943: }
10944:
10945: sub scantron_javascript {
10946: return <<"ENDSCRIPT";
10947:
10948: <script type="text/javascript">
10949: // <![CDATA[
10950:
10951: function toggleScantron(form) {
1.347 raeburn 10952: var csvfieldset = new Array();
1.346 raeburn 10953: if (document.getElementById('scantroncsv_cols')) {
1.347 raeburn 10954: csvfieldset.push(document.getElementById('scantroncsv_cols'));
10955: }
10956: if (document.getElementById('scantroncsv_options')) {
10957: csvfieldset.push(document.getElementById('scantroncsv_options'));
10958: }
10959: if (csvfieldset.length) {
1.346 raeburn 10960: if (document.getElementById('scantronconfcsv')) {
1.347 raeburn 10961: var scantroncsv = document.getElementById('scantronconfcsv');
1.346 raeburn 10962: if (scantroncsv.checked) {
1.347 raeburn 10963: for (var i=0; i<csvfieldset.length; i++) {
10964: csvfieldset[i].style.display = 'block';
10965: }
1.346 raeburn 10966: } else {
1.347 raeburn 10967: for (var i=0; i<csvfieldset.length; i++) {
10968: csvfieldset[i].style.display = 'none';
10969: }
1.346 raeburn 10970: var csvselects = document.getElementsByClassName('scantronconfig_csv');
10971: if (csvselects.length) {
10972: for (var j=0; j<csvselects.length; j++) {
10973: csvselects[j].selectedIndex = 0;
10974: }
10975: }
10976: }
10977: }
10978: }
10979: return;
10980: }
10981: // ]]>
10982: </script>
10983:
10984: ENDSCRIPT
10985:
10986: }
10987:
1.46 raeburn 10988: sub print_scantronformat {
10989: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
10990: my $itemcount = 1;
1.60 raeburn 10991: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
10992: %confhash);
1.46 raeburn 10993: my $switchserver = &check_switchserver($dom,$confname);
10994: my %lt = &Apache::lonlocal::texthash (
1.95 www 10995: default => 'Default bubblesheet format file error',
10996: custom => 'Custom bubblesheet format file error',
1.46 raeburn 10997: );
10998: my %scantronfiles = (
10999: default => 'default.tab',
11000: custom => 'custom.tab',
11001: );
11002: foreach my $key (keys(%scantronfiles)) {
11003: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
11004: .$scantronfiles{$key};
11005: }
11006: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
11007: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
11008: if (!$switchserver) {
11009: my $servadm = $r->dir_config('lonAdmEMail');
11010: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
11011: if ($configuserok eq 'ok') {
11012: if ($author_ok eq 'ok') {
11013: my %legacyfile = (
1.346 raeburn 11014: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
11015: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 11016: );
11017: my %md5chk;
11018: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 11019: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
11020: chomp($md5chk{$type});
1.46 raeburn 11021: }
11022: if ($md5chk{'default'} ne $md5chk{'custom'}) {
11023: foreach my $type (keys(%legacyfile)) {
1.346 raeburn 11024: ($scantronurls{$type},my $error) =
1.46 raeburn 11025: &legacy_scantronformat($r,$dom,$confname,
11026: $type,$legacyfile{$type},
11027: $scantronurls{$type},
11028: $scantronfiles{$type});
1.60 raeburn 11029: if ($error ne '') {
11030: $error{$type} = $error;
11031: }
11032: }
11033: if (keys(%error) == 0) {
11034: $is_custom = 1;
1.346 raeburn 11035: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 11036: $scantronurls{'custom'};
1.346 raeburn 11037: my $putresult =
1.60 raeburn 11038: &Apache::lonnet::put_dom('configuration',
11039: \%confhash,$dom);
11040: if ($putresult ne 'ok') {
1.346 raeburn 11041: $error{'custom'} =
1.60 raeburn 11042: '<span class="LC_error">'.
11043: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11044: }
1.46 raeburn 11045: }
11046: } else {
1.60 raeburn 11047: ($scantronurls{'default'},my $error) =
1.46 raeburn 11048: &legacy_scantronformat($r,$dom,$confname,
11049: 'default',$legacyfile{'default'},
11050: $scantronurls{'default'},
11051: $scantronfiles{'default'});
1.60 raeburn 11052: if ($error eq '') {
11053: $confhash{'scantron'}{'scantronformat'} = '';
11054: my $putresult =
11055: &Apache::lonnet::put_dom('configuration',
11056: \%confhash,$dom);
11057: if ($putresult ne 'ok') {
11058: $error{'default'} =
11059: '<span class="LC_error">'.
11060: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
11061: }
11062: } else {
11063: $error{'default'} = $error;
11064: }
1.46 raeburn 11065: }
11066: }
11067: }
11068: } else {
1.95 www 11069: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 11070: }
11071: }
11072: if (ref($settings) eq 'HASH') {
11073: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
11074: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
11075: if ((!@info) || ($info[0] eq 'no_such_dir')) {
11076: $scantronurl = '';
11077: } else {
11078: $scantronurl = $settings->{'scantronformat'};
11079: }
11080: $is_custom = 1;
11081: } else {
11082: $scantronurl = $scantronurls{'default'};
11083: }
11084: } else {
1.60 raeburn 11085: if ($is_custom) {
11086: $scantronurl = $scantronurls{'custom'};
11087: } else {
11088: $scantronurl = $scantronurls{'default'};
11089: }
1.46 raeburn 11090: }
11091: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11092: $datatable .= '<tr'.$css_class.'>';
11093: if (!$is_custom) {
1.65 raeburn 11094: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
11095: '<span class="LC_nobreak">';
1.46 raeburn 11096: if ($scantronurl) {
1.199 raeburn 11097: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
11098: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 11099: } else {
11100: $datatable = &mt('File unavailable for display');
11101: }
1.65 raeburn 11102: $datatable .= '</span></td>';
1.60 raeburn 11103: if (keys(%error) == 0) {
1.306 raeburn 11104: $datatable .= '<td style="vertical-align: bottom">';
1.60 raeburn 11105: if (!$switchserver) {
11106: $datatable .= &mt('Upload:').'<br />';
11107: }
11108: } else {
11109: my $errorstr;
11110: foreach my $key (sort(keys(%error))) {
11111: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11112: }
11113: $datatable .= '<td>'.$errorstr;
11114: }
1.46 raeburn 11115: } else {
11116: if (keys(%error) > 0) {
11117: my $errorstr;
11118: foreach my $key (sort(keys(%error))) {
11119: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
11120: }
1.60 raeburn 11121: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 11122: } elsif ($scantronurl) {
1.199 raeburn 11123: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
11124: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 11125: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 11126: $link.
11127: '<label><input type="checkbox" name="scantronformat_del"'.
11128: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 11129: '<td><span class="LC_nobreak"> '.
11130: &mt('Replace:').'</span><br />';
1.46 raeburn 11131: }
11132: }
11133: if (keys(%error) == 0) {
11134: if ($switchserver) {
11135: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
11136: } else {
1.65 raeburn 11137: $datatable .='<span class="LC_nobreak"> '.
11138: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 11139: }
11140: }
11141: $datatable .= '</td></tr>';
11142: $$rowtotal ++;
11143: return $datatable;
11144: }
11145:
11146: sub legacy_scantronformat {
11147: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
11148: my ($url,$error);
11149: my @statinfo = &Apache::lonnet::stat_file($newurl);
11150: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.421 raeburn 11151: my $modified = [];
1.46 raeburn 11152: (my $result,$url) =
1.421 raeburn 11153: &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
11154: 'scantron','','',$newfile,$modified);
11155: if ($result eq 'ok') {
11156: &update_modify_urls($r,$modified);
11157: } else {
1.130 raeburn 11158: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 11159: }
11160: }
11161: return ($url,$error);
11162: }
1.43 raeburn 11163:
1.346 raeburn 11164: sub print_scantronconfig {
11165: my ($dom,$settings,$rowtotal) = @_;
11166: my $itemcount = 2;
11167: my $is_checked = ' checked="checked"';
1.347 raeburn 11168: my %optionson = (
11169: hdr => ' checked="checked"',
11170: pad => ' checked="checked"',
11171: rem => ' checked="checked"',
11172: );
11173: my %optionsoff = (
11174: hdr => '',
11175: pad => '',
11176: rem => '',
11177: );
1.346 raeburn 11178: my $currcsvsty = 'none';
1.347 raeburn 11179: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
1.346 raeburn 11180: my @fields = &scantroncsv_fields();
11181: my %titles = &scantronconfig_titles();
11182: if (ref($settings) eq 'HASH') {
11183: if (ref($settings->{config}) eq 'HASH') {
11184: if ($settings->{config}->{dat}) {
11185: $checked{'dat'} = $is_checked;
11186: }
11187: if (ref($settings->{config}->{csv}) eq 'HASH') {
1.347 raeburn 11188: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
11189: %csvfields = %{$settings->{config}->{csv}->{fields}};
11190: if (keys(%csvfields) > 0) {
11191: $checked{'csv'} = $is_checked;
11192: $currcsvsty = 'block';
11193: }
11194: }
11195: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
11196: %csvoptions = %{$settings->{config}->{csv}->{options}};
11197: foreach my $option (keys(%optionson)) {
11198: unless ($csvoptions{$option}) {
11199: $optionsoff{$option} = $optionson{$option};
11200: $optionson{$option} = '';
11201: }
11202: }
1.346 raeburn 11203: }
11204: }
11205: } else {
11206: $checked{'dat'} = $is_checked;
11207: }
11208: } else {
11209: $checked{'dat'} = $is_checked;
11210: }
11211: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
11212: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11213: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
11214: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
11215: foreach my $item ('dat','csv') {
11216: my $id;
11217: if ($item eq 'csv') {
11218: $id = 'id="scantronconfcsv" ';
1.347 raeburn 11219: }
1.346 raeburn 11220: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
11221: $titles{$item}.'</label>'.(' 'x3);
11222: if ($item eq 'csv') {
11223: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
11224: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
11225: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
11226: foreach my $col (@fields) {
11227: my $selnone;
11228: if ($csvfields{$col} eq '') {
11229: $selnone = ' selected="selected"';
11230: }
11231: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
11232: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
11233: '<option value=""'.$selnone.'></option>';
11234: for (my $i=0; $i<20; $i++) {
11235: my $shown = $i+1;
11236: my $sel;
11237: unless ($selnone) {
11238: if (exists($csvfields{$col})) {
11239: if ($csvfields{$col} == $i) {
11240: $sel = ' selected="selected"';
11241: }
11242: }
11243: }
11244: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
11245: }
11246: $datatable .= '</select></td></tr>';
11247: }
1.347 raeburn 11248: $datatable .= '</table></fieldset>'.
11249: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
11250: '<legend>'.&mt('CSV Options').'</legend>';
11251: foreach my $option ('hdr','pad','rem') {
11252: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
11253: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
11254: &mt('Yes').'</label>'.(' 'x2)."\n".
11255: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
11256: }
11257: $datatable .= '</fieldset>';
1.346 raeburn 11258: $itemcount ++;
11259: }
11260: }
11261: $datatable .= '</td></tr>';
11262: $$rowtotal ++;
11263: return $datatable;
11264: }
11265:
11266: sub scantronconfig_titles {
11267: return &Apache::lonlocal::texthash(
11268: dat => 'Standard format (.dat)',
11269: csv => 'Comma separated values (.csv)',
1.347 raeburn 11270: hdr => 'Remove first line in file (contains column titles)',
11271: pad => 'Prepend 0s to PaperID',
1.348 raeburn 11272: rem => 'Remove leading spaces (except Question Response columns)',
1.346 raeburn 11273: CODE => 'CODE',
11274: ID => 'Student ID',
11275: PaperID => 'Paper ID',
11276: FirstName => 'First Name',
11277: LastName => 'Last Name',
11278: FirstQuestion => 'First Question Response',
11279: Section => 'Section',
11280: );
11281: }
11282:
11283: sub scantroncsv_fields {
11284: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
11285: }
11286:
1.49 raeburn 11287: sub print_coursecategories {
1.57 raeburn 11288: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
11289: my $datatable;
11290: if ($position eq 'top') {
1.238 raeburn 11291: my (%checked);
11292: my @catitems = ('unauth','auth');
11293: my @cattypes = ('std','domonly','codesrch','none');
11294: $checked{'unauth'} = 'std';
11295: $checked{'auth'} = 'std';
11296: if (ref($settings) eq 'HASH') {
11297: foreach my $type (@cattypes) {
11298: if ($type eq $settings->{'unauth'}) {
11299: $checked{'unauth'} = $type;
11300: }
11301: if ($type eq $settings->{'auth'}) {
11302: $checked{'auth'} = $type;
11303: }
11304: }
11305: }
11306: my %lt = &Apache::lonlocal::texthash (
11307: unauth => 'Catalog type for unauthenticated users',
11308: auth => 'Catalog type for authenticated users',
11309: none => 'No catalog',
11310: std => 'Standard catalog',
11311: domonly => 'Domain-only catalog',
11312: codesrch => "Code search form",
11313: );
11314: my $itemcount = 0;
11315: foreach my $item (@catitems) {
11316: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
11317: $datatable .= '<tr '.$css_class.'>'.
11318: '<td>'.$lt{$item}.'</td>'.
11319: '<td class="LC_right_item"><span class="LC_nobreak">';
11320: foreach my $type (@cattypes) {
11321: my $ischecked;
11322: if ($checked{$item} eq $type) {
11323: $ischecked=' checked="checked"';
11324: }
11325: $datatable .= '<label>'.
11326: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
11327: ' />'.$lt{$type}.'</label> ';
11328: }
1.327 raeburn 11329: $datatable .= '</span></td></tr>';
1.238 raeburn 11330: $itemcount ++;
11331: }
11332: $$rowtotal += $itemcount;
11333: } elsif ($position eq 'middle') {
1.57 raeburn 11334: my $toggle_cats_crs = ' ';
11335: my $toggle_cats_dom = ' checked="checked" ';
11336: my $can_cat_crs = ' ';
11337: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 11338: my $toggle_catscomm_comm = ' ';
11339: my $toggle_catscomm_dom = ' checked="checked" ';
11340: my $can_catcomm_comm = ' ';
11341: my $can_catcomm_dom = ' checked="checked" ';
1.272 raeburn 11342: my $toggle_catsplace_place = ' ';
11343: my $toggle_catsplace_dom = ' checked="checked" ';
11344: my $can_catplace_place = ' ';
11345: my $can_catplace_dom = ' checked="checked" ';
1.120 raeburn 11346:
1.57 raeburn 11347: if (ref($settings) eq 'HASH') {
11348: if ($settings->{'togglecats'} eq 'crs') {
11349: $toggle_cats_crs = $toggle_cats_dom;
11350: $toggle_cats_dom = ' ';
11351: }
11352: if ($settings->{'categorize'} eq 'crs') {
11353: $can_cat_crs = $can_cat_dom;
11354: $can_cat_dom = ' ';
11355: }
1.120 raeburn 11356: if ($settings->{'togglecatscomm'} eq 'comm') {
11357: $toggle_catscomm_comm = $toggle_catscomm_dom;
11358: $toggle_catscomm_dom = ' ';
11359: }
11360: if ($settings->{'categorizecomm'} eq 'comm') {
11361: $can_catcomm_comm = $can_catcomm_dom;
11362: $can_catcomm_dom = ' ';
11363: }
1.272 raeburn 11364: if ($settings->{'togglecatsplace'} eq 'place') {
11365: $toggle_catsplace_place = $toggle_catsplace_dom;
11366: $toggle_catsplace_dom = ' ';
11367: }
11368: if ($settings->{'categorizeplace'} eq 'place') {
11369: $can_catplace_place = $can_catplace_dom;
11370: $can_catplace_dom = ' ';
11371: }
1.57 raeburn 11372: }
11373: my %title = &Apache::lonlocal::texthash (
1.272 raeburn 11374: togglecats => 'Show/Hide a course in catalog',
11375: togglecatscomm => 'Show/Hide a community in catalog',
11376: togglecatsplace => 'Show/Hide a placement test in catalog',
11377: categorize => 'Assign a category to a course',
11378: categorizecomm => 'Assign a category to a community',
11379: categorizeplace => 'Assign a category to a placement test',
1.57 raeburn 11380: );
11381: my %level = &Apache::lonlocal::texthash (
1.272 raeburn 11382: dom => 'Set in Domain',
11383: crs => 'Set in Course',
11384: comm => 'Set in Community',
11385: place => 'Set in Placement Test',
1.57 raeburn 11386: );
11387: $datatable = '<tr class="LC_odd_row">'.
11388: '<td>'.$title{'togglecats'}.'</td>'.
11389: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11390: '<input type="radio" name="togglecats"'.
11391: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11392: '<label><input type="radio" name="togglecats"'.
11393: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
11394: '</tr><tr>'.
11395: '<td>'.$title{'categorize'}.'</td>'.
11396: '<td class="LC_right_item"><span class="LC_nobreak">'.
11397: '<label><input type="radio" name="categorize"'.
11398: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11399: '<label><input type="radio" name="categorize"'.
11400: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 11401: '</tr><tr class="LC_odd_row">'.
11402: '<td>'.$title{'togglecatscomm'}.'</td>'.
11403: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11404: '<input type="radio" name="togglecatscomm"'.
11405: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11406: '<label><input type="radio" name="togglecatscomm"'.
11407: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
11408: '</tr><tr>'.
11409: '<td>'.$title{'categorizecomm'}.'</td>'.
11410: '<td class="LC_right_item"><span class="LC_nobreak">'.
11411: '<label><input type="radio" name="categorizecomm"'.
11412: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11413: '<label><input type="radio" name="categorizecomm"'.
11414: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.327 raeburn 11415: '</tr><tr class="LC_odd_row">'.
1.272 raeburn 11416: '<td>'.$title{'togglecatsplace'}.'</td>'.
11417: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
11418: '<input type="radio" name="togglecatsplace"'.
11419: $toggle_catsplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11420: '<label><input type="radio" name="togglecatscomm"'.
11421: $toggle_catsplace_place.' value="comm" />'.$level{'place'}.'</label></span></td>'.
11422: '</tr><tr>'.
11423: '<td>'.$title{'categorizeplace'}.'</td>'.
11424: '<td class="LC_right_item"><span class="LC_nobreak">'.
11425: '<label><input type="radio" name="categorizeplace"'.
11426: $can_catplace_dom.' value="dom" />'.$level{'dom'}.'</label> '.
11427: '<label><input type="radio" name="categorizeplace"'.
11428: $can_catplace_place.'value="place" />'.$level{'place'}.'</label></span></td>'.
1.57 raeburn 11429: '</tr>';
1.272 raeburn 11430: $$rowtotal += 6;
1.57 raeburn 11431: } else {
11432: my $css_class;
11433: my $itemcount = 1;
11434: my $cathash;
11435: if (ref($settings) eq 'HASH') {
11436: $cathash = $settings->{'cats'};
11437: }
11438: if (ref($cathash) eq 'HASH') {
11439: my (@cats,@trails,%allitems,%idx,@jsarray);
11440: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
11441: \%allitems,\%idx,\@jsarray);
11442: my $maxdepth = scalar(@cats);
11443: my $colattrib = '';
11444: if ($maxdepth > 2) {
11445: $colattrib = ' colspan="2" ';
11446: }
11447: my @path;
11448: if (@cats > 0) {
11449: if (ref($cats[0]) eq 'ARRAY') {
11450: my $numtop = @{$cats[0]};
11451: my $maxnum = $numtop;
1.120 raeburn 11452: my %default_names = (
11453: instcode => &mt('Official courses'),
11454: communities => &mt('Communities'),
1.272 raeburn 11455: placement => &mt('Placement Tests'),
1.120 raeburn 11456: );
11457:
11458: if ((!grep(/^instcode$/,@{$cats[0]})) ||
11459: ($cathash->{'instcode::0'} eq '') ||
11460: (!grep(/^communities$/,@{$cats[0]})) ||
1.272 raeburn 11461: ($cathash->{'communities::0'} eq '') ||
11462: (!grep(/^placement$/,@{$cats[0]})) ||
11463: ($cathash->{'placement::0'} eq '')) {
1.57 raeburn 11464: $maxnum ++;
11465: }
11466: my $lastidx;
11467: for (my $i=0; $i<$numtop; $i++) {
11468: my $parent = $cats[0][$i];
11469: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11470: my $item = &escape($parent).'::0';
11471: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
11472: $lastidx = $idx{$item};
11473: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
11474: .'<select name="'.$item.'"'.$chgstr.'>';
11475: for (my $k=0; $k<=$maxnum; $k++) {
11476: my $vpos = $k+1;
11477: my $selstr;
11478: if ($k == $i) {
11479: $selstr = ' selected="selected" ';
11480: }
11481: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11482: }
1.214 raeburn 11483: $datatable .= '</select></span></td><td>';
1.272 raeburn 11484: if ($parent eq 'instcode' || $parent eq 'communities' || $parent eq 'placement') {
1.120 raeburn 11485: $datatable .= '<span class="LC_nobreak">'
11486: .$default_names{$parent}.'</span>';
11487: if ($parent eq 'instcode') {
11488: $datatable .= '<br /><span class="LC_nobreak">('
11489: .&mt('with institutional codes')
11490: .')</span></td><td'.$colattrib.'>';
11491: } else {
11492: $datatable .= '<table><tr><td>';
11493: }
11494: $datatable .= '<span class="LC_nobreak">'
11495: .'<label><input type="radio" name="'
11496: .$parent.'" value="1" checked="checked" />'
11497: .&mt('Display').'</label>';
11498: if ($parent eq 'instcode') {
11499: $datatable .= ' ';
11500: } else {
11501: $datatable .= '</span></td></tr><tr><td>'
11502: .'<span class="LC_nobreak">';
11503: }
11504: $datatable .= '<label><input type="radio" name="'
11505: .$parent.'" value="0" />'
11506: .&mt('Do not display').'</label></span>';
1.272 raeburn 11507: if (($parent eq 'communities') || ($parent eq 'placement')) {
1.120 raeburn 11508: $datatable .= '</td></tr></table>';
11509: }
11510: $datatable .= '</td>';
1.57 raeburn 11511: } else {
11512: $datatable .= $parent
1.214 raeburn 11513: .' <span class="LC_nobreak"><label>'
11514: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 11515: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
11516: }
11517: my $depth = 1;
11518: push(@path,$parent);
11519: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
11520: pop(@path);
11521: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
11522: $itemcount ++;
11523: }
1.48 raeburn 11524: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 11525: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
11526: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 11527: for (my $k=0; $k<=$maxnum; $k++) {
11528: my $vpos = $k+1;
11529: my $selstr;
1.57 raeburn 11530: if ($k == $numtop) {
1.48 raeburn 11531: $selstr = ' selected="selected" ';
11532: }
11533: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
11534: }
1.59 bisitz 11535: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 11536: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
11537: .'</tr>'."\n";
1.48 raeburn 11538: $itemcount ++;
1.272 raeburn 11539: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11540: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
11541: $css_class = $itemcount%2?' class="LC_odd_row"':'';
11542: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
11543: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
11544: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
11545: for (my $k=0; $k<=$maxnum; $k++) {
11546: my $vpos = $k+1;
11547: my $selstr;
11548: if ($k == $maxnum) {
11549: $selstr = ' selected="selected" ';
11550: }
11551: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 11552: }
1.120 raeburn 11553: $datatable .= '</select></span></td>'.
11554: '<td><span class="LC_nobreak">'.
11555: $default_names{$default}.'</span>';
11556: if ($default eq 'instcode') {
11557: $datatable .= '<br /><span class="LC_nobreak">('
11558: .&mt('with institutional codes').')</span>';
11559: }
11560: $datatable .= '</td>'
11561: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
11562: .&mt('Display').'</label> '
11563: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
11564: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 11565: }
11566: }
11567: }
1.57 raeburn 11568: } else {
11569: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 11570: }
11571: } else {
1.327 raeburn 11572: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 11573: .&initialize_categories($itemcount);
1.48 raeburn 11574: }
1.57 raeburn 11575: $$rowtotal += $itemcount;
1.48 raeburn 11576: }
11577: return $datatable;
11578: }
11579:
1.69 raeburn 11580: sub print_serverstatuses {
11581: my ($dom,$settings,$rowtotal) = @_;
11582: my $datatable;
11583: my @pages = &serverstatus_pages();
11584: my (%namedaccess,%machineaccess);
11585: foreach my $type (@pages) {
11586: $namedaccess{$type} = '';
11587: $machineaccess{$type}= '';
11588: }
11589: if (ref($settings) eq 'HASH') {
11590: foreach my $type (@pages) {
11591: if (exists($settings->{$type})) {
11592: if (ref($settings->{$type}) eq 'HASH') {
11593: foreach my $key (keys(%{$settings->{$type}})) {
11594: if ($key eq 'namedusers') {
11595: $namedaccess{$type} = $settings->{$type}->{$key};
11596: } elsif ($key eq 'machines') {
11597: $machineaccess{$type} = $settings->{$type}->{$key};
11598: }
11599: }
11600: }
11601: }
11602: }
11603: }
1.81 raeburn 11604: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 11605: my $rownum = 0;
11606: my $css_class;
11607: foreach my $type (@pages) {
11608: $rownum ++;
11609: $css_class = $rownum%2?' class="LC_odd_row"':'';
11610: $datatable .= '<tr'.$css_class.'>'.
11611: '<td><span class="LC_nobreak">'.
11612: $titles->{$type}.'</span></td>'.
11613: '<td class="LC_left_item">'.
11614: '<input type="text" name="'.$type.'_namedusers" '.
11615: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
11616: '<td class="LC_right_item">'.
11617: '<span class="LC_nobreak">'.
11618: '<input type="text" name="'.$type.'_machines" '.
11619: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.334 raeburn 11620: '</span></td></tr>'."\n";
1.69 raeburn 11621: }
11622: $$rowtotal += $rownum;
11623: return $datatable;
11624: }
11625:
11626: sub serverstatus_pages {
11627: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.275 raeburn 11628: 'checksums','clusterstatus','certstatus','metadata_keywords',
11629: 'metadata_harvest','takeoffline','takeonline','showenv','toggledebug',
11630: 'ping','domconf','uniquecodes','diskusage','coursecatalog');
1.69 raeburn 11631: }
11632:
1.236 raeburn 11633: sub defaults_javascript {
11634: my ($settings) = @_;
1.354 raeburn 11635: return unless (ref($settings) eq 'HASH');
1.414 raeburn 11636: my $portal_js = <<"ENDPORTAL";
11637:
11638: function portalExtras(caller) {
11639: var x = caller.value;
11640: var y = new Array('email','web');
1.425 raeburn 11641: for (var i=0; i<y.length; i++) {
1.414 raeburn 11642: if (document.getElementById('portal_def_'+y[i]+'_div')) {
11643: var z = document.getElementById('portal_def_'+y[i]+'_div');
11644: if (x.length > 0) {
11645: z.style.display = 'block';
11646: } else {
11647: z.style.display = 'none';
11648: }
11649: }
11650: }
11651: }
11652: ENDPORTAL
1.236 raeburn 11653: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
11654: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
11655: if ($maxnum eq '') {
11656: $maxnum = 0;
11657: }
11658: $maxnum ++;
1.249 raeburn 11659: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.236 raeburn 11660: return <<"ENDSCRIPT";
11661: <script type="text/javascript">
11662: // <![CDATA[
11663: function reorderTypes(form,caller) {
11664: var changedVal;
11665: $jstext
11666: var newpos = 'addinststatus_pos';
11667: var current = new Array;
11668: var maxh = $maxnum;
11669: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11670: var oldVal;
11671: if (caller == newpos) {
11672: changedVal = newitemVal;
11673: } else {
11674: var curritem = 'inststatus_pos_'+caller;
11675: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
11676: current[newitemVal] = newpos;
11677: }
11678: for (var i=0; i<inststatuses.length; i++) {
11679: if (inststatuses[i] != caller) {
11680: var elementName = 'inststatus_pos_'+inststatuses[i];
11681: if (form.elements[elementName]) {
11682: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11683: current[currVal] = elementName;
11684: }
11685: }
11686: }
11687: for (var j=0; j<maxh; j++) {
11688: if (current[j] == undefined) {
11689: oldVal = j;
11690: }
11691: }
11692: if (oldVal < changedVal) {
11693: for (var k=oldVal+1; k<=changedVal ; k++) {
11694: var elementName = current[k];
11695: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11696: }
11697: } else {
11698: for (var k=changedVal; k<oldVal; k++) {
11699: var elementName = current[k];
11700: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11701: }
11702: }
11703: return;
11704: }
11705:
1.414 raeburn 11706: $portal_js
11707:
11708: // ]]>
11709: </script>
11710:
11711: ENDSCRIPT
11712: } else {
11713: return <<"ENDSCRIPT";
11714: <script type="text/javascript">
11715: // <![CDATA[
11716: $portal_js
1.236 raeburn 11717: // ]]>
11718: </script>
11719:
11720: ENDSCRIPT
11721: }
1.354 raeburn 11722: return;
11723: }
11724:
11725: sub passwords_javascript {
1.405 raeburn 11726: my ($prefix) = @_;
11727: my %intalert;
11728: if ($prefix eq 'passwords') {
11729: %intalert = &Apache::lonlocal::texthash (
11730: 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.',
11731: authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
11732: passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
11733: passmax => 'Warning: maximum password length must be a positive integer (or blank).',
11734: passexp => 'Warning: days before password expiration must be a positive integer (or blank).',
11735: passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
11736: );
1.421 raeburn 11737: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 11738: %intalert = &Apache::lonlocal::texthash (
11739: passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
11740: passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
11741: );
11742: }
1.365 raeburn 11743: &js_escape(\%intalert);
11744: my $defmin = $Apache::lonnet::passwdmin;
1.425 raeburn 11745: my $intauthjs;
1.405 raeburn 11746: if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.354 raeburn 11747:
11748: function warnIntAuth(field) {
11749: if (field.name == 'intauth_check') {
11750: if (field.value == '2') {
1.365 raeburn 11751: alert('$intalert{authcheck}');
1.354 raeburn 11752: }
11753: }
11754: if (field.name == 'intauth_cost') {
11755: field.value.replace(/\s/g,'');
11756: if (field.value != '') {
11757: var regexdigit=/^\\d+\$/;
11758: if (!regexdigit.test(field.value)) {
1.365 raeburn 11759: alert('$intalert{authcost}');
11760: }
11761: }
11762: }
11763: return;
11764: }
11765:
1.405 raeburn 11766: ENDSCRIPT
11767:
11768: }
11769:
11770: $intauthjs .= <<"ENDSCRIPT";
11771:
11772: function warnInt$prefix(field) {
1.365 raeburn 11773: field.value.replace(/^\s+/,'');
11774: field.value.replace(/\s+\$/,'');
11775: var regexdigit=/^\\d+\$/;
1.408 raeburn 11776: if (field.name == '${prefix}_min') {
1.365 raeburn 11777: if (field.value == '') {
11778: alert('$intalert{passmin}');
11779: field.value = '$defmin';
11780: } else {
11781: if (!regexdigit.test(field.value)) {
11782: alert('$intalert{passmin}');
11783: field.value = '$defmin';
11784: }
1.366 raeburn 11785: var minval = parseInt(field.value,10);
1.365 raeburn 11786: if (minval < $defmin) {
11787: alert('$intalert{passmin}');
11788: field.value = '$defmin';
11789: }
11790: }
11791: } else {
11792: if (field.value == '0') {
11793: field.value = '';
11794: }
11795: if (field.value != '') {
1.408 raeburn 11796: if (field.name == '${prefix}_expire') {
1.365 raeburn 11797: var regexpposnum=/^\\d+(|\\.\\d*)\$/;
11798: if (!regexpposnum.test(field.value)) {
11799: alert('$intalert{passexp}');
11800: field.value = '';
11801: } else {
11802: var expval = parseFloat(field.value);
11803: if (expval == 0) {
11804: alert('$intalert{passexp}');
11805: field.value = '';
11806: }
11807: }
11808: } else {
11809: if (!regexdigit.test(field.value)) {
1.408 raeburn 11810: if (field.name == '${prefix}_max') {
1.365 raeburn 11811: alert('$intalert{passmax}');
11812: } else {
1.408 raeburn 11813: if (field.name == '${prefix}_numsaved') {
1.365 raeburn 11814: alert('$intalert{passnum}');
11815: }
11816: }
1.370 raeburn 11817: field.value = '';
1.365 raeburn 11818: }
1.354 raeburn 11819: }
11820: }
11821: }
11822: return;
11823: }
11824:
11825: ENDSCRIPT
11826: return &Apache::lonhtmlcommon::scripttag($intauthjs);
1.236 raeburn 11827: }
11828:
1.49 raeburn 11829: sub coursecategories_javascript {
11830: my ($settings) = @_;
1.57 raeburn 11831: my ($output,$jstext,$cathash);
1.49 raeburn 11832: if (ref($settings) eq 'HASH') {
1.57 raeburn 11833: $cathash = $settings->{'cats'};
11834: }
11835: if (ref($cathash) eq 'HASH') {
1.49 raeburn 11836: my (@cats,@jsarray,%idx);
1.57 raeburn 11837: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 11838: if (@jsarray > 0) {
11839: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
11840: for (my $i=0; $i<@jsarray; $i++) {
11841: if (ref($jsarray[$i]) eq 'ARRAY') {
11842: my $catstr = join('","',@{$jsarray[$i]});
11843: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
11844: }
11845: }
11846: }
11847: } else {
11848: $jstext = ' var categories = Array(1);'."\n".
11849: ' categories[0] = Array("instcode_pos");'."\n";
11850: }
1.237 bisitz 11851: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
11852: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.272 raeburn 11853: my $placement_reserved = &mt('The name: [_1] is a reserved category.','"placement"');
1.265 damieng 11854: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
11855: &js_escape(\$instcode_reserved);
11856: &js_escape(\$communities_reserved);
1.272 raeburn 11857: &js_escape(\$placement_reserved);
1.265 damieng 11858: &js_escape(\$choose_again);
1.49 raeburn 11859: $output = <<"ENDSCRIPT";
11860: <script type="text/javascript">
1.109 raeburn 11861: // <![CDATA[
1.49 raeburn 11862: function reorderCats(form,parent,item,idx) {
11863: var changedVal;
11864: $jstext
11865: var newpos = 'addcategory_pos';
11866: if (parent == '') {
11867: var has_instcode = 0;
11868: var maxtop = categories[idx].length;
11869: for (var j=0; j<maxtop; j++) {
11870: if (categories[idx][j] == 'instcode::0') {
11871: has_instcode == 1;
11872: }
11873: }
11874: if (has_instcode == 0) {
11875: categories[idx][maxtop] = 'instcode_pos';
11876: }
11877: } else {
11878: newpos += '_'+parent;
11879: }
11880: var maxh = 1 + categories[idx].length;
11881: var current = new Array;
11882: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
11883: if (item == newpos) {
11884: changedVal = newitemVal;
11885: } else {
11886: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
11887: current[newitemVal] = newpos;
11888: }
11889: for (var i=0; i<categories[idx].length; i++) {
11890: var elementName = categories[idx][i];
11891: if (elementName != item) {
11892: if (form.elements[elementName]) {
11893: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
11894: current[currVal] = elementName;
11895: }
11896: }
11897: }
11898: var oldVal;
11899: for (var j=0; j<maxh; j++) {
11900: if (current[j] == undefined) {
11901: oldVal = j;
11902: }
11903: }
11904: if (oldVal < changedVal) {
11905: for (var k=oldVal+1; k<=changedVal ; k++) {
11906: var elementName = current[k];
11907: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
11908: }
11909: } else {
11910: for (var k=changedVal; k<oldVal; k++) {
11911: var elementName = current[k];
11912: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
11913: }
11914: }
11915: return;
11916: }
1.120 raeburn 11917:
11918: function categoryCheck(form) {
11919: if (form.elements['addcategory_name'].value == 'instcode') {
11920: alert('$instcode_reserved\\n$choose_again');
11921: return false;
11922: }
11923: if (form.elements['addcategory_name'].value == 'communities') {
11924: alert('$communities_reserved\\n$choose_again');
11925: return false;
11926: }
1.272 raeburn 11927: if (form.elements['addcategory_name'].value == 'placement') {
11928: alert('$placement_reserved\\n$choose_again');
11929: return false;
11930: }
1.120 raeburn 11931: return true;
11932: }
11933:
1.109 raeburn 11934: // ]]>
1.49 raeburn 11935: </script>
11936:
11937: ENDSCRIPT
11938: return $output;
11939: }
11940:
1.48 raeburn 11941: sub initialize_categories {
11942: my ($itemcount) = @_;
1.120 raeburn 11943: my ($datatable,$css_class,$chgstr);
1.380 raeburn 11944: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 11945: instcode => 'Official courses (with institutional codes)',
11946: communities => 'Communities',
1.272 raeburn 11947: placement => 'Placement Tests',
1.120 raeburn 11948: );
1.328 raeburn 11949: my %selnum = (
11950: instcode => '0',
11951: communities => '1',
11952: placement => '2',
11953: );
11954: my %selected;
1.272 raeburn 11955: foreach my $default ('instcode','communities','placement') {
1.120 raeburn 11956: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.327 raeburn 11957: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.328 raeburn 11958: map { $selected{$selnum{$_}} = '' } keys(%selnum);
11959: $selected{$selnum{$default}} = ' selected="selected"';
1.120 raeburn 11960: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.328 raeburn 11961: .'<select name="'.$default.'_pos"'.$chgstr.'>'
11962: .'<option value="0"'.$selected{'0'}.'>1</option>'
11963: .'<option value="1"'.$selected{'1'}.'>2</option>'
11964: .'<option value="2"'.$selected{'2'}.'>3</option>'
11965: .'<option value="3">4</option></select> '
1.120 raeburn 11966: .$default_names{$default}
11967: .'</span></td><td><span class="LC_nobreak">'
11968: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
11969: .&mt('Display').'</label> <label>'
11970: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 11971: .'</label></span></td></tr>';
1.120 raeburn 11972: $itemcount ++;
11973: }
1.48 raeburn 11974: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 11975: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 11976: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 11977: .'<select name="addcategory_pos"'.$chgstr.'>'
11978: .'<option value="0">1</option>'
11979: .'<option value="1">2</option>'
1.328 raeburn 11980: .'<option value="2">3</option>'
11981: .'<option value="3" selected="selected">4</option></select> '
1.327 raeburn 11982: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
11983: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
11984: .'</td></tr>';
1.48 raeburn 11985: return $datatable;
11986: }
11987:
11988: sub build_category_rows {
1.49 raeburn 11989: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
11990: my ($text,$name,$item,$chgstr);
1.48 raeburn 11991: if (ref($cats) eq 'ARRAY') {
11992: my $maxdepth = scalar(@{$cats});
11993: if (ref($cats->[$depth]) eq 'HASH') {
11994: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
11995: my $numchildren = @{$cats->[$depth]{$parent}};
11996: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 11997: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 11998: my ($idxnum,$parent_name,$parent_item);
11999: my $higher = $depth - 1;
12000: if ($higher == 0) {
12001: $parent_name = &escape($parent).'::'.$higher;
12002: } else {
12003: if (ref($path) eq 'ARRAY') {
12004: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12005: }
12006: }
12007: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 12008: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 12009: if ($j < $numchildren) {
1.48 raeburn 12010: $name = $cats->[$depth]{$parent}[$j];
12011: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 12012: $idxnum = $idx->{$item};
12013: } else {
12014: $name = $parent_name;
12015: $item = $parent_item;
1.48 raeburn 12016: }
1.49 raeburn 12017: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
12018: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 12019: for (my $i=0; $i<=$numchildren; $i++) {
12020: my $vpos = $i+1;
12021: my $selstr;
12022: if ($j == $i) {
12023: $selstr = ' selected="selected" ';
12024: }
12025: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
12026: }
12027: $text .= '</select> ';
12028: if ($j < $numchildren) {
12029: my $deeper = $depth+1;
12030: $text .= $name.' '
12031: .'<label><input type="checkbox" name="deletecategory" value="'
12032: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
12033: if(ref($path) eq 'ARRAY') {
12034: push(@{$path},$name);
1.49 raeburn 12035: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 12036: pop(@{$path});
12037: }
12038: } else {
1.330 raeburn 12039: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 12040: if ($j == $numchildren) {
12041: $text .= $name;
12042: } else {
12043: $text .= $item;
12044: }
12045: $text .= '" value="" />';
12046: }
12047: $text .= '</td></tr>';
12048: }
12049: $text .= '</table></td>';
12050: } else {
12051: my $higher = $depth-1;
12052: if ($higher == 0) {
12053: $name = &escape($parent).'::'.$higher;
12054: } else {
12055: if (ref($path) eq 'ARRAY') {
12056: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
12057: }
12058: }
12059: my $colspan;
12060: if ($parent ne 'instcode') {
12061: $colspan = $maxdepth - $depth - 1;
1.330 raeburn 12062: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 12063: }
12064: }
12065: }
12066: }
12067: return $text;
12068: }
12069:
1.33 raeburn 12070: sub modifiable_userdata_row {
1.305 raeburn 12071: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.357 raeburn 12072: $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.228 raeburn 12073: my ($role,$rolename,$statustype);
12074: $role = $item;
1.224 raeburn 12075: if ($context eq 'cancreate') {
1.305 raeburn 12076: if ($item =~ /^(emailusername)_(.+)$/) {
12077: $role = $1;
12078: $statustype = $2;
1.228 raeburn 12079: if (ref($usertypes) eq 'HASH') {
12080: if ($usertypes->{$statustype}) {
12081: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
12082: } else {
12083: $rolename = &mt('Data provided by user');
12084: }
12085: }
1.224 raeburn 12086: }
12087: } elsif ($context eq 'selfcreate') {
1.63 raeburn 12088: if (ref($usertypes) eq 'HASH') {
12089: $rolename = $usertypes->{$role};
12090: } else {
12091: $rolename = $role;
12092: }
1.325 raeburn 12093: } elsif ($context eq 'lti') {
12094: $rolename = &mt('Institutional data used (if available)');
1.357 raeburn 12095: } elsif ($context eq 'privacy') {
12096: $rolename = $itemdesc;
1.33 raeburn 12097: } else {
1.63 raeburn 12098: if ($role eq 'cr') {
12099: $rolename = &mt('Custom role');
12100: } else {
12101: $rolename = &Apache::lonnet::plaintext($role);
12102: }
1.33 raeburn 12103: }
1.224 raeburn 12104: my (@fields,%fieldtitles);
12105: if (ref($fieldsref) eq 'ARRAY') {
12106: @fields = @{$fieldsref};
12107: } else {
12108: @fields = ('lastname','firstname','middlename','generation',
12109: 'permanentemail','id');
12110: }
12111: if ((ref($titlesref) eq 'HASH')) {
12112: %fieldtitles = %{$titlesref};
12113: } else {
12114: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
12115: }
1.33 raeburn 12116: my $output;
1.305 raeburn 12117: my $css_class;
12118: if ($rowcount%2) {
12119: $css_class = 'LC_odd_row';
12120: }
12121: if ($customcss) {
12122: $css_class .= " $customcss";
12123: }
12124: $css_class =~ s/^\s+//;
12125: if ($css_class) {
12126: $css_class = ' class="'.$css_class.'"';
12127: }
12128: if ($rowstyle) {
12129: $css_class .= ' style="'.$rowstyle.'"';
12130: }
12131: if ($rowid) {
12132: $rowid = ' id="'.$rowid.'"';
12133: }
12134: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 12135: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
12136: '<td class="LC_left_item" colspan="2"><table>';
12137: my $rem;
12138: my %checks;
12139: if (ref($settings) eq 'HASH') {
1.325 raeburn 12140: my $hashref;
12141: if ($context eq 'lti') {
12142: if (ref($settings) eq 'HASH') {
1.449 ! raeburn 12143: my %instdata;
! 12144: if (ref($settings->{'instdata'}) eq 'ARRAY') {
! 12145: map { $instdata{$_} = 1; } @{$settings->{'instdata'}};
! 12146: }
! 12147: $hashref = \%instdata;
1.325 raeburn 12148: }
1.357 raeburn 12149: } elsif ($context eq 'privacy') {
12150: my ($key,$inner) = split(/_/,$role);
12151: if (ref($settings) eq 'HASH') {
12152: if (ref($settings->{$key}) eq 'HASH') {
12153: $hashref = $settings->{$key}->{$inner};
12154: }
12155: }
1.325 raeburn 12156: } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 12157: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.448 raeburn 12158: $hashref = $settings->{$context}->{$role};
1.325 raeburn 12159: }
12160: if ($role eq 'emailusername') {
12161: if ($statustype) {
12162: if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
12163: $hashref = $settings->{$context}->{$role}->{$statustype};
1.228 raeburn 12164: }
1.325 raeburn 12165: }
12166: }
12167: }
1.425 raeburn 12168: if (ref($hashref) eq 'HASH') {
1.325 raeburn 12169: foreach my $field (@fields) {
12170: if ($hashref->{$field}) {
12171: if ($role eq 'emailusername') {
12172: $checks{$field} = $hashref->{$field};
12173: } else {
12174: $checks{$field} = ' checked="checked" ';
1.33 raeburn 12175: }
12176: }
12177: }
12178: }
12179: }
1.305 raeburn 12180: my $total = scalar(@fields);
12181: for (my $i=0; $i<$total; $i++) {
12182: $rem = $i%($numinrow);
1.33 raeburn 12183: if ($rem == 0) {
12184: if ($i > 0) {
12185: $output .= '</tr>';
12186: }
12187: $output .= '<tr>';
12188: }
12189: my $check = ' ';
1.228 raeburn 12190: unless ($role eq 'emailusername') {
12191: if (exists($checks{$fields[$i]})) {
1.354 raeburn 12192: $check = $checks{$fields[$i]};
1.357 raeburn 12193: } elsif ($context eq 'privacy') {
12194: if ($role =~ /^priv_(domain|course)$/) {
12195: if (ref($settings) ne 'HASH') {
12196: $check = ' checked="checked" ';
12197: }
12198: } elsif ($role =~ /^priv_(author|community)$/) {
12199: if (ref($settings) ne 'HASH') {
12200: unless ($fields[$i] eq 'id') {
12201: $check = ' checked="checked" ';
12202: }
12203: }
12204: } elsif ($role =~ /^(unpriv|othdom)_/) {
12205: if (ref($settings) ne 'HASH') {
12206: if (($fields[$i] eq 'lastname') || ($fields[$i] eq 'firstname')) {
12207: $check = ' checked="checked" ';
12208: }
12209: }
12210: }
1.325 raeburn 12211: } elsif ($context ne 'lti') {
1.228 raeburn 12212: if ($role eq 'st') {
12213: if (ref($settings) ne 'HASH') {
12214: $check = ' checked="checked" ';
12215: }
1.33 raeburn 12216: }
12217: }
12218: }
12219: $output .= '<td class="LC_left_item">'.
1.228 raeburn 12220: '<span class="LC_nobreak">';
1.325 raeburn 12221: my $prefix = 'canmodify';
1.228 raeburn 12222: if ($role eq 'emailusername') {
12223: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
12224: $checks{$fields[$i]} = 'omit';
12225: }
12226: foreach my $option ('required','optional','omit') {
12227: my $checked='';
12228: if ($checks{$fields[$i]} eq $option) {
12229: $checked='checked="checked" ';
12230: }
12231: $output .= '<label>'.
1.325 raeburn 12232: '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.228 raeburn 12233: &mt($option).'</label>'.(' ' x2);
12234: }
12235: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
12236: } else {
1.325 raeburn 12237: if ($context eq 'lti') {
12238: $prefix = 'lti';
1.443 raeburn 12239: } elsif ($context eq 'coauthor') {
12240: $prefix = 'cacanmodify';
1.357 raeburn 12241: } elsif ($context eq 'privacy') {
12242: $prefix = 'privacy';
1.325 raeburn 12243: }
1.228 raeburn 12244: $output .= '<label>'.
1.325 raeburn 12245: '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.228 raeburn 12246: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
12247: '</label>';
12248: }
12249: $output .= '</span></td>';
1.33 raeburn 12250: }
1.305 raeburn 12251: $rem = $total%$numinrow;
12252: my $colsleft;
12253: if ($rem) {
12254: $colsleft = $numinrow - $rem;
12255: }
12256: if ($colsleft > 1) {
1.33 raeburn 12257: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
12258: ' </td>';
12259: } elsif ($colsleft == 1) {
12260: $output .= '<td class="LC_left_item"> </td>';
12261: }
12262: $output .= '</tr></table></td></tr>';
12263: return $output;
12264: }
1.28 raeburn 12265:
1.93 raeburn 12266: sub insttypes_row {
1.305 raeburn 12267: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
12268: $customcss,$rowstyle) = @_;
1.93 raeburn 12269: my %lt = &Apache::lonlocal::texthash (
1.429 raeburn 12270: cansearch => 'Users allowed to search',
1.93 raeburn 12271: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.429 raeburn 12272: lockablenames => 'User preference to lock name',
12273: selfassign => 'Self-reportable affiliations',
12274: overrides => "Override domain's helpdesk settings based on requester's affiliation",
12275: webdav => 'WebDAV access available',
12276: authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 12277: );
1.429 raeburn 12278: my ($showdom,$defaultquota);
1.93 raeburn 12279: if ($context eq 'cansearch') {
12280: $showdom = ' ('.$dom.')';
1.429 raeburn 12281: } elsif ($context eq 'authorquota') {
12282: $defaultquota = 500;
1.93 raeburn 12283: }
1.165 raeburn 12284: my $class = 'LC_left_item';
12285: if ($context eq 'statustocreate') {
12286: $class = 'LC_right_item';
12287: }
1.305 raeburn 12288: my $css_class;
12289: if ($$rowtotal%2) {
12290: $css_class = 'LC_odd_row';
12291: }
12292: if ($customcss) {
12293: $css_class .= ' '.$customcss;
12294: }
12295: $css_class =~ s/^\s+//;
12296: if ($css_class) {
12297: $css_class = ' class="'.$css_class.'"';
12298: }
12299: if ($rowstyle) {
12300: $css_class .= ' style="'.$rowstyle.'"';
12301: }
12302: if ($onclick) {
12303: $onclick = 'onclick="'.$onclick.'" ';
1.224 raeburn 12304: }
12305: my $output = '<tr'.$css_class.'>'.
12306: '<td>'.$lt{$context}.$showdom.
12307: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 12308: my $rem;
12309: if (ref($types) eq 'ARRAY') {
12310: for (my $i=0; $i<@{$types}; $i++) {
12311: if (defined($usertypes->{$types->[$i]})) {
12312: my $rem = $i%($numinrow);
12313: if ($rem == 0) {
12314: if ($i > 0) {
12315: $output .= '</tr>';
12316: }
12317: $output .= '<tr>';
1.23 raeburn 12318: }
1.429 raeburn 12319: if ($context eq 'authorquota') {
12320: my $currquota;
12321: if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
12322: $currquota = $settings->{$context}->{$types->[$i]};
12323: } else {
12324: $currquota = $defaultquota;
12325: }
12326: $output .= '<td class="LC_left_item">'."\n".
12327: '<label><span class="LC_nobreak">'."\n".
12328: $usertypes->{$types->[$i]}.'</span><br />'."\n".
12329: '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
12330: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12331: '</label></td>';
12332: } else {
12333: my $check = ' ';
12334: if (ref($settings) eq 'HASH') {
12335: if (ref($settings->{$context}) eq 'ARRAY') {
12336: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
12337: $check = ' checked="checked" ';
12338: }
12339: } elsif (ref($settings->{$context}) eq 'HASH') {
12340: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
12341: $check = ' checked="checked" ';
12342: } elsif ($context eq 'webdav') {
12343: if ($settings->{$context}->{$types->[$i]}) {
12344: $check = ' checked="checked" ';
12345: }
12346: }
12347: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12348: $check = ' checked="checked" ';
12349: }
1.26 raeburn 12350: }
1.429 raeburn 12351: $output .= '<td class="LC_left_item">'.
12352: '<span class="LC_nobreak"><label>'.
12353: '<input type="checkbox" name="'.$context.'" '.
12354: 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
12355: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 12356: }
12357: }
12358: }
1.26 raeburn 12359: $rem = @{$types}%($numinrow);
1.23 raeburn 12360: }
12361: my $colsleft = $numinrow - $rem;
1.315 raeburn 12362: if ($context eq 'overrides') {
12363: if ($colsleft > 1) {
12364: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12365: } else {
12366: $output .= '<td class="LC_left_item">';
12367: }
1.425 raeburn 12368: $output .= ' ';
1.23 raeburn 12369: } else {
1.334 raeburn 12370: if ($rem == 0) {
1.315 raeburn 12371: $output .= '<tr>';
12372: }
12373: if ($colsleft > 1) {
12374: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
12375: } else {
12376: $output .= '<td class="LC_left_item">';
12377: }
1.429 raeburn 12378: if ($context eq 'authorquota') {
12379: my $currquota = 500;
12380: if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
12381: if ($settings->{$context}{'default'} =~ /^\d+$/) {
12382: $currquota = $settings->{$context}{'default'};
12383: }
12384: }
12385: $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
12386: '<input type="text" name="'.$context.'_default" '.
12387: 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
12388: '</label>';
12389: } else {
12390: my $defcheck = ' ';
12391: if (ref($settings) eq 'HASH') {
12392: if (ref($settings->{$context}) eq 'ARRAY') {
12393: if (grep(/^default$/,@{$settings->{$context}})) {
12394: $defcheck = ' checked="checked" ';
12395: }
12396: } elsif (ref($settings->{$context}) eq 'HASH') {
12397: if (ref($settings->{$context}->{'default'}) eq 'HASH') {
12398: $defcheck = ' checked="checked" ';
12399: } elsif ($context eq 'webdav') {
12400: if ($settings->{$context}->{'default'}) {
12401: $defcheck = ' checked="checked" ';
12402: }
12403: }
12404: } elsif ($context eq 'statustocreate') {
1.315 raeburn 12405: $defcheck = ' checked="checked" ';
12406: }
1.99 raeburn 12407: }
1.429 raeburn 12408: $output .= '<span class="LC_nobreak"><label>'.
12409: '<input type="checkbox" name="'.$context.'" '.
12410: 'value="default"'.$defcheck.$onclick.'/>'.
12411: $othertitle.'</label></span>';
1.26 raeburn 12412: }
1.23 raeburn 12413: }
1.315 raeburn 12414: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 12415: return $output;
1.23 raeburn 12416: }
12417:
12418: sub sorted_searchtitles {
12419: my %searchtitles = &Apache::lonlocal::texthash(
12420: 'uname' => 'username',
12421: 'lastname' => 'last name',
12422: 'lastfirst' => 'last name, first name',
12423: );
12424: my @titleorder = ('uname','lastname','lastfirst');
12425: return (\%searchtitles,\@titleorder);
12426: }
12427:
1.25 raeburn 12428: sub sorted_searchtypes {
12429: my %srchtypes_desc = (
12430: exact => 'is exact match',
12431: contains => 'contains ..',
12432: begins => 'begins with ..',
12433: );
12434: my @srchtypeorder = ('exact','begins','contains');
12435: return (\%srchtypes_desc,\@srchtypeorder);
12436: }
12437:
1.3 raeburn 12438: sub usertype_update_row {
12439: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
12440: my $datatable;
12441: my $numinrow = 4;
12442: foreach my $type (@{$types}) {
12443: if (defined($usertypes->{$type})) {
12444: $$rownums ++;
12445: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
12446: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
12447: '</td><td class="LC_left_item"><table>';
12448: for (my $i=0; $i<@{$fields}; $i++) {
12449: my $rem = $i%($numinrow);
12450: if ($rem == 0) {
12451: if ($i > 0) {
12452: $datatable .= '</tr>';
12453: }
12454: $datatable .= '<tr>';
12455: }
12456: my $check = ' ';
1.39 raeburn 12457: if (ref($settings) eq 'HASH') {
12458: if (ref($settings->{'fields'}) eq 'HASH') {
12459: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
12460: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
12461: $check = ' checked="checked" ';
12462: }
1.3 raeburn 12463: }
12464: }
12465: }
12466:
12467: if ($i == @{$fields}-1) {
12468: my $colsleft = $numinrow - $rem;
12469: if ($colsleft > 1) {
12470: $datatable .= '<td colspan="'.$colsleft.'">';
12471: } else {
12472: $datatable .= '<td>';
12473: }
12474: } else {
12475: $datatable .= '<td>';
12476: }
1.8 raeburn 12477: $datatable .= '<span class="LC_nobreak"><label>'.
12478: '<input type="checkbox" name="updateable_'.$type.
12479: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
12480: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 12481: }
12482: $datatable .= '</tr></table></td></tr>';
12483: }
12484: }
12485: return $datatable;
1.1 raeburn 12486: }
12487:
12488: sub modify_login {
1.205 raeburn 12489: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 12490: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.386 raeburn 12491: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.412 raeburn 12492: %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.168 raeburn 12493: %title = ( coursecatalog => 'Display course catalog',
12494: adminmail => 'Display administrator E-mail address',
1.188 raeburn 12495: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 12496: newuser => 'Link for visitors to create a user account',
1.386 raeburn 12497: loginheader => 'Log-in box header',
12498: saml => 'Dual SSO and non-SSO login');
1.168 raeburn 12499: @offon = ('off','on');
1.112 raeburn 12500: if (ref($domconfig{login}) eq 'HASH') {
12501: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
12502: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
12503: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
12504: }
12505: }
1.386 raeburn 12506: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
12507: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
12508: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
12509: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
12510: $saml{$lonhost} = 1;
12511: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
12512: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
12513: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
12514: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
12515: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.412 raeburn 12516: $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.386 raeburn 12517: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
12518: }
12519: }
12520: }
1.112 raeburn 12521: }
1.9 raeburn 12522: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
12523: \%domconfig,\%loginhash);
1.188 raeburn 12524: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12525: foreach my $item (@toggles) {
12526: $loginhash{login}{$item} = $env{'form.'.$item};
12527: }
1.41 raeburn 12528: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 12529: if (ref($colchanges{'login'}) eq 'HASH') {
12530: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
12531: \%loginhash);
12532: }
1.110 raeburn 12533:
1.149 raeburn 12534: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.256 raeburn 12535: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 12536: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 12537: if (keys(%servers) > 1) {
12538: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 12539: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
12540: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
12541: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
12542: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
12543: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
12544: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12545: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12546: $changes{'loginvia'}{$lonhost} = 1;
12547: } else {
12548: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
12549: $changes{'loginvia'}{$lonhost} = 1;
12550: }
12551: } else {
12552: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12553: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
12554: $changes{'loginvia'}{$lonhost} = 1;
12555: }
12556: }
12557: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
12558: foreach my $item (@loginvia_attribs) {
12559: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
12560: }
12561: } else {
12562: foreach my $item (@loginvia_attribs) {
12563: my $new = $env{'form.'.$lonhost.'_'.$item};
12564: if (($item eq 'serverpath') && ($new eq 'custom')) {
12565: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
12566: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12567: $new = '/';
12568: }
12569: }
12570: if (($item eq 'custompath') &&
12571: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12572: $new = '';
12573: }
12574: if ($new ne $curr_loginvia{$lonhost}{$item}) {
12575: $changes{'loginvia'}{$lonhost} = 1;
12576: }
12577: if ($item eq 'exempt') {
1.256 raeburn 12578: $new = &check_exempt_addresses($new);
1.128 raeburn 12579: }
12580: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12581: }
12582: }
1.112 raeburn 12583: } else {
1.128 raeburn 12584: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
12585: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 12586: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 12587: foreach my $item (@loginvia_attribs) {
12588: my $new = $env{'form.'.$lonhost.'_'.$item};
12589: if (($item eq 'serverpath') && ($new eq 'custom')) {
12590: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
12591: $new = '/';
12592: }
12593: }
12594: if (($item eq 'custompath') &&
12595: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
12596: $new = '';
12597: }
12598: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
12599: }
1.110 raeburn 12600: }
12601: }
12602: }
12603: }
1.119 raeburn 12604:
1.168 raeburn 12605: my $servadm = $r->dir_config('lonAdmEMail');
12606: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
12607: if (ref($domconfig{'login'}) eq 'HASH') {
12608: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
12609: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
12610: if ($lang eq 'nolang') {
12611: push(@currlangs,$lang);
12612: } elsif (defined($langchoices{$lang})) {
12613: push(@currlangs,$lang);
12614: } else {
12615: next;
12616: }
12617: }
12618: }
12619: }
12620: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
12621: if (@currlangs > 0) {
12622: foreach my $lang (@currlangs) {
12623: if (grep(/^\Q$lang\E$/,@delurls)) {
12624: $changes{'helpurl'}{$lang} = 1;
12625: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
12626: $changes{'helpurl'}{$lang} = 1;
12627: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
12628: push(@newlangs,$lang);
12629: } else {
12630: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12631: }
12632: }
12633: }
12634: unless (grep(/^nolang$/,@currlangs)) {
12635: if ($env{'form.loginhelpurl_nolang.filename'}) {
12636: $changes{'helpurl'}{'nolang'} = 1;
12637: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
12638: push(@newlangs,'nolang');
12639: }
12640: }
12641: if ($env{'form.loginhelpurl_add_lang'}) {
12642: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
12643: ($env{'form.loginhelpurl_add_file.filename'})) {
12644: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
12645: $addedfile = $env{'form.loginhelpurl_add_lang'};
12646: }
12647: }
12648: if ((@newlangs > 0) || ($addedfile)) {
12649: my $error;
12650: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12651: if ($configuserok eq 'ok') {
12652: if ($switchserver) {
12653: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
12654: } elsif ($author_ok eq 'ok') {
12655: my @allnew = @newlangs;
12656: if ($addedfile ne '') {
12657: push(@allnew,$addedfile);
12658: }
1.421 raeburn 12659: my $modified = [];
1.168 raeburn 12660: foreach my $lang (@allnew) {
12661: my $formelem = 'loginhelpurl_'.$lang;
12662: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
12663: $formelem = 'loginhelpurl_add_file';
12664: }
1.425 raeburn 12665: (my $result,$newurl{$lang}) =
1.421 raeburn 12666: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12667: "help/$lang",'','',$newfile{$lang},
12668: $modified);
1.168 raeburn 12669: if ($result eq 'ok') {
12670: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
12671: $changes{'helpurl'}{$lang} = 1;
12672: } else {
12673: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
12674: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 12675: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 12676: (!grep(/^\Q$lang\E$/,@delurls))) {
12677: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
12678: }
12679: }
12680: }
1.421 raeburn 12681: &update_modify_urls($r,$modified);
1.168 raeburn 12682: } else {
12683: $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);
12684: }
12685: } else {
12686: $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);
12687: }
12688: if ($error) {
12689: &Apache::lonnet::logthis($error);
12690: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12691: }
12692: }
1.256 raeburn 12693:
12694: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
12695: if (ref($domconfig{'login'}) eq 'HASH') {
12696: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
12697: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
12698: if ($domservers{$lonhost}) {
12699: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12700: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.268 raeburn 12701: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.256 raeburn 12702: }
12703: }
12704: }
12705: }
12706: }
12707: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
12708: foreach my $lonhost (sort(keys(%domservers))) {
12709: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12710: $changes{'headtag'}{$lonhost} = 1;
12711: } else {
12712: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
12713: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
12714: }
12715: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
12716: push(@newhosts,$lonhost);
12717: } elsif ($currheadtagurls{$lonhost}) {
12718: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
12719: if ($currexempt{$lonhost}) {
1.289 raeburn 12720: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
1.256 raeburn 12721: $changes{'headtag'}{$lonhost} = 1;
12722: }
12723: } elsif ($possexempt{$lonhost}) {
12724: $changes{'headtag'}{$lonhost} = 1;
12725: }
12726: if ($possexempt{$lonhost}) {
12727: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12728: }
12729: }
12730: }
12731: }
12732: if (@newhosts) {
12733: my $error;
12734: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12735: if ($configuserok eq 'ok') {
12736: if ($switchserver) {
12737: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
12738: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12739: my $modified = [];
1.256 raeburn 12740: foreach my $lonhost (@newhosts) {
12741: my $formelem = 'loginheadtag_'.$lonhost;
1.425 raeburn 12742: (my $result,$newheadtagurls{$lonhost}) =
1.421 raeburn 12743: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12744: "login/headtag/$lonhost",'','',
12745: $env{'form.loginheadtag_'.$lonhost.'.filename'},
12746: $modified);
1.256 raeburn 12747: if ($result eq 'ok') {
12748: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
12749: $changes{'headtag'}{$lonhost} = 1;
12750: if ($possexempt{$lonhost}) {
12751: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
12752: }
12753: } else {
12754: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
12755: $newheadtagurls{$lonhost},$result);
12756: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12757: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
12758: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
12759: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
12760: }
12761: }
12762: }
1.421 raeburn 12763: &update_modify_urls($r,$modified);
1.256 raeburn 12764: } else {
12765: $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);
12766: }
12767: } else {
12768: $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);
12769: }
12770: if ($error) {
12771: &Apache::lonnet::logthis($error);
12772: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12773: }
12774: }
1.386 raeburn 12775: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
12776: my @newsamlimgs;
12777: foreach my $lonhost (keys(%domservers)) {
12778: if ($env{'form.saml_'.$lonhost}) {
12779: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
12780: push(@newsamlimgs,$lonhost);
12781: }
1.412 raeburn 12782: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12783: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
12784: }
12785: if ($saml{$lonhost}) {
1.412 raeburn 12786: if ($env{'form.saml_window_'.$lonhost} ne '1') {
12787: $env{'form.saml_window_'.$lonhost} = '';
12788: }
1.386 raeburn 12789: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
12790: #FIXME Need to obsolete published image
12791: delete($currsaml{$lonhost}{'img'});
12792: $changes{'saml'}{$lonhost} = 1;
12793: }
12794: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
12795: $changes{'saml'}{$lonhost} = 1;
12796: }
12797: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
12798: $changes{'saml'}{$lonhost} = 1;
12799: }
12800: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
12801: $changes{'saml'}{$lonhost} = 1;
12802: }
12803: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
12804: $changes{'saml'}{$lonhost} = 1;
12805: }
1.412 raeburn 12806: if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
12807: $changes{'saml'}{$lonhost} = 1;
12808: }
1.386 raeburn 12809: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
12810: $changes{'saml'}{$lonhost} = 1;
12811: }
12812: } else {
12813: $changes{'saml'}{$lonhost} = 1;
12814: }
1.412 raeburn 12815: foreach my $item ('text','alt','url','title','window','notsso') {
1.386 raeburn 12816: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
12817: }
12818: } else {
1.425 raeburn 12819: if ($saml{$lonhost}) {
1.389 raeburn 12820: $changes{'saml'}{$lonhost} = 1;
12821: delete($currsaml{$lonhost});
12822: }
1.386 raeburn 12823: }
12824: }
12825: foreach my $posshost (keys(%currsaml)) {
1.425 raeburn 12826: unless (exists($domservers{$posshost})) {
12827: delete($currsaml{$posshost});
1.386 raeburn 12828: }
12829: }
12830: %{$loginhash{'login'}{'saml'}} = %currsaml;
12831: if (@newsamlimgs) {
12832: my $error;
12833: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
12834: if ($configuserok eq 'ok') {
12835: if ($switchserver) {
12836: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
12837: } elsif ($author_ok eq 'ok') {
1.421 raeburn 12838: my $modified = [];
1.386 raeburn 12839: foreach my $lonhost (@newsamlimgs) {
12840: my $formelem = 'saml_img_'.$lonhost;
1.425 raeburn 12841: my ($result,$imgurl) =
1.421 raeburn 12842: &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
12843: "login/saml/$lonhost",'','',
12844: $env{'form.saml_img_'.$lonhost.'.filename'},
12845: $modified);
1.386 raeburn 12846: if ($result eq 'ok') {
12847: $currsaml{$lonhost}{'img'} = $imgurl;
12848: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
12849: $changes{'saml'}{$lonhost} = 1;
12850: } else {
12851: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
12852: $lonhost,$result);
12853: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
12854: }
12855: }
1.421 raeburn 12856: &update_modify_urls($r,$modified);
1.386 raeburn 12857: } else {
12858: $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);
12859: }
12860: } else {
12861: $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);
12862: }
12863: if ($error) {
12864: &Apache::lonnet::logthis($error);
12865: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12866: }
12867: }
1.169 raeburn 12868: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 12869:
12870: my $defaulthelpfile = '/adm/loginproblems.html';
12871: my $defaulttext = &mt('Default in use');
12872:
1.1 raeburn 12873: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
12874: $dom);
12875: if ($putresult eq 'ok') {
1.188 raeburn 12876: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 12877: my %defaultchecked = (
12878: 'coursecatalog' => 'on',
1.188 raeburn 12879: 'helpdesk' => 'on',
1.42 raeburn 12880: 'adminmail' => 'off',
1.43 raeburn 12881: 'newuser' => 'off',
1.42 raeburn 12882: );
1.55 raeburn 12883: if (ref($domconfig{'login'}) eq 'HASH') {
12884: foreach my $item (@toggles) {
12885: if ($defaultchecked{$item} eq 'on') {
12886: if (($domconfig{'login'}{$item} eq '0') &&
12887: ($env{'form.'.$item} eq '1')) {
12888: $changes{$item} = 1;
12889: } elsif (($domconfig{'login'}{$item} eq '' ||
12890: $domconfig{'login'}{$item} eq '1') &&
12891: ($env{'form.'.$item} eq '0')) {
12892: $changes{$item} = 1;
12893: }
12894: } elsif ($defaultchecked{$item} eq 'off') {
12895: if (($domconfig{'login'}{$item} eq '1') &&
12896: ($env{'form.'.$item} eq '0')) {
12897: $changes{$item} = 1;
12898: } elsif (($domconfig{'login'}{$item} eq '' ||
12899: $domconfig{'login'}{$item} eq '0') &&
12900: ($env{'form.'.$item} eq '1')) {
12901: $changes{$item} = 1;
12902: }
1.42 raeburn 12903: }
12904: }
1.41 raeburn 12905: }
1.6 raeburn 12906: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 12907: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.386 raeburn 12908: if (exists($changes{'saml'})) {
12909: my $hostid_in_use;
12910: my @hosts = &Apache::lonnet::current_machine_ids();
12911: if (@hosts > 1) {
12912: foreach my $hostid (@hosts) {
12913: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
12914: $hostid_in_use = $hostid;
12915: last;
12916: }
12917: }
12918: } else {
12919: $hostid_in_use = $r->dir_config('lonHostID');
12920: }
12921: if (($hostid_in_use) &&
12922: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
1.387 raeburn 12923: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
1.386 raeburn 12924: }
12925: if (ref($lastactref) eq 'HASH') {
12926: if (ref($changes{'saml'}) eq 'HASH') {
12927: my %updates;
12928: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
12929: $lastactref->{'samllanding'} = \%updates;
12930: }
12931: }
12932: }
1.212 raeburn 12933: if (ref($lastactref) eq 'HASH') {
12934: $lastactref->{'domainconfig'} = 1;
12935: }
1.1 raeburn 12936: $resulttext = &mt('Changes made:').'<ul>';
12937: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 12938: if ($item eq 'loginvia') {
1.112 raeburn 12939: if (ref($changes{$item}) eq 'HASH') {
12940: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
12941: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 12942: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
12943: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
12944: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
12945: $protocol = 'http' if ($protocol ne 'https');
12946: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
12947:
12948: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
12949: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
12950: } else {
12951: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
12952: }
12953: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
12954: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
12955: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
12956: }
12957: $resulttext .= '</li>';
12958: } else {
12959: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
12960: }
1.112 raeburn 12961: } else {
1.128 raeburn 12962: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 12963: }
12964: }
1.128 raeburn 12965: $resulttext .= '</ul></li>';
1.112 raeburn 12966: }
1.168 raeburn 12967: } elsif ($item eq 'helpurl') {
12968: if (ref($changes{$item}) eq 'HASH') {
12969: foreach my $lang (sort(keys(%{$changes{$item}}))) {
12970: if (grep(/^\Q$lang\E$/,@delurls)) {
12971: my ($chg,$link);
12972: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
12973: if ($lang eq 'nolang') {
12974: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
12975: } else {
12976: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
12977: }
12978: $resulttext .= '<li>'.$chg.'</li>';
12979: } else {
12980: my $chg;
12981: if ($lang eq 'nolang') {
12982: $chg = &mt('custom log-in help file for no preferred language');
12983: } else {
12984: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
12985: }
12986: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
12987: $loginhash{'login'}{'helpurl'}{$lang}.
12988: '?inhibitmenu=yes',$chg,600,500).
12989: '</li>';
12990: }
12991: }
12992: }
1.256 raeburn 12993: } elsif ($item eq 'headtag') {
12994: if (ref($changes{$item}) eq 'HASH') {
12995: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
12996: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
12997: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
12998: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
12999: $resulttext .= '<li><a href="'.
13000: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
13001: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
13002: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
13003: if ($possexempt{$lonhost}) {
13004: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
13005: } else {
13006: $resulttext .= &mt('included for any client IP');
13007: }
13008: $resulttext .= '</li>';
13009: }
13010: }
13011: }
1.386 raeburn 13012: } elsif ($item eq 'saml') {
13013: if (ref($changes{$item}) eq 'HASH') {
13014: my %notlt = (
13015: text => 'Text for log-in by SSO',
13016: img => 'SSO button image',
13017: alt => 'Alt text for button image',
13018: url => 'SSO URL',
13019: title => 'Tooltip for SSO link',
1.412 raeburn 13020: window => 'Pop-up window if iframe',
1.386 raeburn 13021: notsso => 'Text for non-SSO log-in',
13022: );
13023: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
13024: if (ref($currsaml{$lonhost}) eq 'HASH') {
13025: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
13026: '<ul>';
1.412 raeburn 13027: foreach my $key ('text','img','alt','url','title','window','notsso') {
1.386 raeburn 13028: if ($currsaml{$lonhost}{$key} eq '') {
13029: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
13030: } else {
13031: my $value = "'$currsaml{$lonhost}{$key}'";
13032: if ($key eq 'img') {
13033: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.412 raeburn 13034: } elsif ($key eq 'window') {
13035: $value = 'On';
1.386 raeburn 13036: }
13037: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
13038: $value).'</li>';
13039: }
13040: }
13041: $resulttext .= '</ul></li>';
13042: } else {
13043: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
13044: }
13045: }
13046: }
1.169 raeburn 13047: } elsif ($item eq 'captcha') {
13048: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 13049: my $chgtxt;
1.169 raeburn 13050: if ($loginhash{'login'}{$item} eq 'notused') {
13051: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
13052: } else {
13053: my %captchas = &captcha_phrases();
13054: if ($captchas{$loginhash{'login'}{$item}}) {
13055: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
13056: } else {
13057: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
13058: }
13059: }
13060: $resulttext .= '<li>'.$chgtxt.'</li>';
13061: }
13062: } elsif ($item eq 'recaptchakeys') {
13063: if (ref($loginhash{'login'}) eq 'HASH') {
13064: my ($privkey,$pubkey);
13065: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
13066: $pubkey = $loginhash{'login'}{$item}{'public'};
13067: $privkey = $loginhash{'login'}{$item}{'private'};
13068: }
13069: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
13070: if (!$pubkey) {
13071: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
13072: } else {
13073: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
13074: }
13075: if (!$privkey) {
13076: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
13077: } else {
1.251 raeburn 13078: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.169 raeburn 13079: }
13080: $chgtxt .= '</ul>';
13081: $resulttext .= '<li>'.$chgtxt.'</li>';
13082: }
1.269 raeburn 13083: } elsif ($item eq 'recaptchaversion') {
13084: if (ref($loginhash{'login'}) eq 'HASH') {
13085: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
1.270 raeburn 13086: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
1.269 raeburn 13087: '</li>';
13088: }
13089: }
1.41 raeburn 13090: } else {
13091: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
13092: }
1.1 raeburn 13093: }
1.6 raeburn 13094: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 13095: } else {
13096: $resulttext = &mt('No changes made to log-in page settings');
13097: }
13098: } else {
1.11 albertel 13099: $resulttext = '<span class="LC_error">'.
13100: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13101: }
1.6 raeburn 13102: if ($errors) {
1.9 raeburn 13103: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 13104: $errors.'</ul>';
13105: }
13106: return $resulttext;
13107: }
13108:
1.256 raeburn 13109: sub check_exempt_addresses {
13110: my ($iplist) = @_;
13111: $iplist =~ s/^\s+//;
13112: $iplist =~ s/\s+$//;
13113: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
13114: my (@okips,$new);
13115: foreach my $ip (@poss_ips) {
13116: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
13117: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
13118: push(@okips,$ip);
13119: }
13120: }
13121: }
13122: if (@okips > 0) {
13123: $new = join(',',@okips);
13124: } else {
13125: $new = '';
13126: }
13127: return $new;
13128: }
13129:
1.6 raeburn 13130: sub color_font_choices {
13131: my %choices =
13132: &Apache::lonlocal::texthash (
13133: bgs => "Background colors",
13134: links => "Link colors",
1.55 raeburn 13135: images => "Images",
1.6 raeburn 13136: font => "Font color",
1.201 raeburn 13137: fontmenu => "Font menu",
1.76 raeburn 13138: pgbg => "Page",
1.6 raeburn 13139: tabbg => "Header",
13140: sidebg => "Border",
13141: link => "Link",
13142: alink => "Active link",
13143: vlink => "Visited link",
13144: );
13145: return %choices;
13146: }
13147:
1.394 raeburn 13148: sub modify_ipaccess {
13149: my ($dom,$lastactref,%domconfig) = @_;
13150: my (@allpos,%changes,%confhash,$errors,$resulttext);
13151: my (@items,%deletions,%itemids,@warnings);
13152: my ($typeorder,$types) = &commblocktype_text();
13153: if ($env{'form.ipaccess_add'}) {
13154: my $name = $env{'form.ipaccess_name_add'};
13155: my ($newid,$error) = &get_ipaccess_id($dom,$name);
13156: if ($newid) {
13157: $itemids{'add'} = $newid;
13158: push(@items,'add');
13159: $changes{$newid} = 1;
13160: } else {
13161: $error = &mt('Failed to acquire unique ID for new IP access control item');
13162: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13163: }
13164: }
13165: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13166: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
13167: if (@todelete) {
13168: map { $deletions{$_} = 1; } @todelete;
13169: }
13170: my $maxnum = $env{'form.ipaccess_maxnum'};
13171: for (my $i=0; $i<$maxnum; $i++) {
13172: my $itemid = $env{'form.ipaccess_id_'.$i};
13173: $itemid =~ s/\D+//g;
13174: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13175: if ($deletions{$itemid}) {
13176: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
13177: } else {
13178: push(@items,$i);
13179: $itemids{$i} = $itemid;
13180: }
13181: }
13182: }
13183: }
13184: foreach my $idx (@items) {
13185: my $itemid = $itemids{$idx};
13186: next unless ($itemid);
1.446 raeburn 13187: my ($position,%current);
13188: if ($idx eq 'add') {
13189: $position = $env{'form.ipaccess_pos_add'};
13190: } else {
13191: $position = $env{'form.ipaccess_pos_'.$itemid};
1.394 raeburn 13192: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13193: %current = %{$domconfig{'ipaccess'}{$itemid}};
13194: }
13195: }
13196: $position =~ s/\D+//g;
13197: if ($position ne '') {
13198: $allpos[$position] = $itemid;
13199: }
13200: my $name = $env{'form.ipaccess_name_'.$idx};
13201: $name =~ s/^\s+|\s+$//g;
13202: $confhash{$itemid}{'name'} = $name;
13203: my $possrange = $env{'form.ipaccess_range_'.$idx};
13204: $possrange =~ s/^\s+|\s+$//g;
13205: unless ($possrange eq '') {
13206: $possrange =~ s/[\r\n]+/\s/g;
13207: $possrange =~ s/\s*-\s*/-/g;
13208: $possrange =~ s/\s+/,/g;
13209: $possrange =~ s/,+/,/g;
13210: if ($possrange ne '') {
13211: my (@ok,$count);
1.425 raeburn 13212: $count = 0;
1.394 raeburn 13213: foreach my $poss (split(/\,/,$possrange)) {
13214: $count ++;
13215: $poss = &validate_ip_pattern($poss);
13216: if ($poss ne '') {
13217: push(@ok,$poss);
13218: }
13219: }
13220: my $diff = $count - scalar(@ok);
13221: if ($diff) {
13222: $errors .= '<li><span class="LC_error">'.
13223: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
13224: $diff,$name).
13225: '</span></li>';
13226: }
13227: if (@ok) {
13228: my @cidr_list;
13229: foreach my $item (@ok) {
13230: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
13231: }
13232: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
13233: }
13234: }
13235: }
13236: foreach my $field ('name','ip') {
13237: unless (($idx eq 'add') || ($changes{$itemid})) {
13238: if ($current{$field} ne $confhash{$itemid}{$field}) {
13239: $changes{$itemid} = 1;
13240: last;
13241: }
13242: }
13243: }
13244: $confhash{$itemid}{'commblocks'} = {};
1.425 raeburn 13245:
1.394 raeburn 13246: my %commblocks;
1.425 raeburn 13247: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
1.394 raeburn 13248: foreach my $type (@{$typeorder}) {
13249: if ($commblocks{$type}) {
13250: $confhash{$itemid}{'commblocks'}{$type} = 'on';
13251: }
13252: unless (($idx eq 'add') || ($changes{$itemid})) {
13253: if (ref($current{'commblocks'}) eq 'HASH') {
13254: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
13255: $changes{$itemid} = 1;
13256: }
13257: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
13258: $changes{$itemid} = 1;
13259: }
13260: }
13261: }
13262: $confhash{$itemid}{'courses'} = {};
13263: my %crsdeletions;
13264: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
13265: if (@delcrs) {
13266: map { $crsdeletions{$_} = 1; } @delcrs;
13267: }
13268: if (ref($current{'courses'}) eq 'HASH') {
13269: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
13270: if ($crsdeletions{$cid}) {
13271: $changes{$itemid} = 1;
13272: } else {
13273: $confhash{$itemid}{'courses'}{$cid} = 1;
13274: }
13275: }
13276: }
13277: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
13278: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
1.425 raeburn 13279: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
1.394 raeburn 13280: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
13281: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
13282: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
13283: $errors .= '<li><span class="LC_error">'.
13284: &mt('Invalid courseID [_1] omitted from list of allowed courses',
13285: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
13286: '</span></li>';
13287: } else {
13288: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
13289: $changes{$itemid} = 1;
13290: }
13291: }
13292: }
13293: if (@allpos > 0) {
13294: my $idx = 0;
13295: foreach my $itemid (@allpos) {
13296: if ($itemid ne '') {
13297: $confhash{$itemid}{'order'} = $idx;
13298: unless ($changes{$itemid}) {
13299: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
13300: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
13301: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
13302: $changes{$itemid} = 1;
13303: }
13304: }
13305: }
13306: }
13307: $idx ++;
13308: }
13309: }
13310: }
13311: if (keys(%changes)) {
13312: my %defaultshash = (
13313: ipaccess => \%confhash,
13314: );
13315: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
13316: $dom);
13317: if ($putresult eq 'ok') {
13318: my $cachetime = 1800;
13319: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
13320: if (ref($lastactref) eq 'HASH') {
13321: $lastactref->{'ipaccess'} = 1;
13322: }
13323: $resulttext = &mt('Changes made:').'<ul>';
13324: my %bynum;
13325: foreach my $itemid (sort(keys(%changes))) {
13326: if (ref($confhash{$itemid}) eq 'HASH') {
13327: my $position = $confhash{$itemid}{'order'};
13328: if ($position =~ /^\d+$/) {
13329: $bynum{$position} = $itemid;
13330: }
13331: }
13332: }
13333: if (keys(%deletions)) {
13334: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13335: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13336: }
13337: }
13338: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13339: my $itemid = $bynum{$pos};
13340: if (ref($confhash{$itemid}) eq 'HASH') {
13341: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
13342: my $position = $pos + 1;
13343: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
13344: if ($confhash{$itemid}{'ip'} eq '') {
13345: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
13346: } else {
13347: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
13348: }
13349: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
13350: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
13351: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
13352: '</li>';
13353: } else {
13354: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
13355: }
13356: if (keys(%{$confhash{$itemid}{'courses'}})) {
13357: my @courses;
13358: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
1.425 raeburn 13359: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1.394 raeburn 13360: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
13361: }
13362: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
13363: join('</li><li>',@courses).'</li></ul>';
13364: } else {
13365: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
13366: }
1.395 raeburn 13367: $resulttext .= '</ul></li>';
1.394 raeburn 13368: }
13369: }
1.395 raeburn 13370: $resulttext .= '</ul>';
1.394 raeburn 13371: } else {
13372: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13373: }
13374: } else {
13375: $resulttext = &mt('No changes made');
13376: }
13377: if ($errors) {
13378: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13379: $errors.'</ul></p>';
13380: }
13381: return $resulttext;
13382: }
13383:
13384: sub get_ipaccess_id {
13385: my ($domain,$location) = @_;
13386: # get lock on ipaccess db
13387: my $lockhash = {
13388: lock => $env{'user.name'}.
13389: ':'.$env{'user.domain'},
13390: };
13391: my $tries = 0;
13392: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13393: my ($id,$error);
13394:
13395: while (($gotlock ne 'ok') && ($tries<10)) {
13396: $tries ++;
13397: sleep (0.1);
13398: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
13399: }
13400: if ($gotlock eq 'ok') {
13401: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
13402: if ($currids{'lock'}) {
13403: delete($currids{'lock'});
13404: if (keys(%currids)) {
13405: my @curr = sort { $a <=> $b } keys(%currids);
13406: if ($curr[-1] =~ /^\d+$/) {
13407: $id = 1 + $curr[-1];
13408: }
13409: } else {
13410: $id = 1;
13411: }
13412: if ($id) {
13413: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
13414: $error = 'nostore';
13415: }
13416: } else {
13417: $error = 'nonumber';
13418: }
13419: }
13420: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
13421: } else {
13422: $error = 'nolock';
13423: }
13424: return ($id,$error);
13425: }
13426:
1.429 raeburn 13427: sub modify_authordefaults {
13428: my ($dom,$lastactref,%domconfig) = @_;
13429: #
13430: # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
13431: #
13432: my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
13433: if (ref($domconfig{'quotas'}) eq 'HASH') {
13434: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13435: if ($key =~ /^webdav|authorquota$/) {
13436: $curr_quotas{$key} = $domconfig{'quotas'}{$key};
13437: } else {
13438: $save_quotas{$key} = $domconfig{'quotas'}{$key};
13439: }
13440: }
13441: }
13442: my %staticdefaults = (
13443: 'copyright' => 'default',
13444: 'sourceavail' => 'closed',
13445: 'nocodemirror' => 'off',
1.437 raeburn 13446: 'daxecollapse' => 'off',
1.429 raeburn 13447: 'domcoordacc' => 'on',
1.439 raeburn 13448: 'editors' => ['edit','xml'],
1.429 raeburn 13449: 'authorquota' => 500,
13450: 'webdav' => 0,
1.440 raeburn 13451: 'archive' => 'off',
1.429 raeburn 13452: );
13453: my %titles = &authordefaults_titles();
1.440 raeburn 13454: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.429 raeburn 13455: if ($env{'form.'.$item} =~ /^(0|1)$/) {
13456: $confhash{$item} = $env{'form.'.$item};
13457: }
13458: }
13459: if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
13460: $confhash{'copyright'} = $1;
13461: }
13462: if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
13463: $confhash{'sourceavail'} = $1;
13464: }
13465: my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
13466: my @okeditors = ('edit','xml','daxe');
13467: my @editors;
13468: foreach my $item (@posseditors) {
13469: if (grep(/^\Q$item\E$/,@okeditors)) {
13470: push(@editors,$item);
13471: }
13472: }
13473: $confhash{'editors'} = \@editors;
1.436 raeburn 13474:
1.429 raeburn 13475: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
13476: my @insttypes;
13477: if (ref($types) eq 'ARRAY') {
13478: @insttypes = @{$types};
13479: }
13480: my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
13481: my %webdav;
13482: map { $webdav{$_} = 1; } @webdavon;
13483: foreach my $type (@insttypes,'default') {
13484: my $possquota = $env{'form.authorquota_'.$type};
13485: if ($possquota =~ /^\d+$/) {
13486: $save_quotas{'authorquota'}{$type} = $possquota;
13487: }
13488: if ($webdav{$type}) {
13489: $save_quotas{'webdav'}{$type} = 1;
13490: } else {
13491: $save_quotas{'webdav'}{$type} = 0;
13492: }
13493: }
13494: if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
13495: $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
13496: }
13497: if (ref($domconfig{'authordefaults'}) eq 'HASH') {
1.440 raeburn 13498: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
1.429 raeburn 13499: if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
13500: $changes{$item} = 1;
13501: }
13502: }
13503: if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
1.436 raeburn 13504: my @diffs =
1.429 raeburn 13505: &Apache::loncommon::compare_arrays($confhash{'editors'},
13506: $domconfig{'authordefaults'}{'editors'});
13507: unless (@diffs == 0) {
13508: $changes{'editors'} = 1;
13509: }
13510: } else {
13511: my @diffs =
13512: &Apache::loncommon::compare_arrays($confhash{'editors'},
13513: $staticdefaults{'editors'});
13514: unless (@diffs == 0) {
13515: $changes{'editors'} = 1;
13516: }
13517: }
13518: } else {
13519: my @offon = ('off','on');
1.440 raeburn 13520: foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
1.436 raeburn 13521: if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
1.429 raeburn 13522: $changes{$item} = 1;
13523: }
13524: }
13525: foreach my $item ('copyright','sourceavail') {
13526: if ($confhash{$item} ne $staticdefaults{$item}) {
13527: $changes{$item} = 1;
13528: }
13529: }
1.439 raeburn 13530: my @diffs =
13531: &Apache::loncommon::compare_arrays($confhash{'editors'},
13532: $staticdefaults{'editors'});
13533: unless (@diffs == 0) {
13534: $changes{'editors'} = 1;
13535: }
1.429 raeburn 13536: }
13537: foreach my $key ('authorquota','webdav') {
13538: if (ref($curr_quotas{$key}) eq 'HASH') {
13539: foreach my $type (@insttypes,'default') {
13540: if (exists($save_quotas{$key}{$type})) {
13541: if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
13542: $changes{$key}{$type} = 1;
13543: }
13544: } elsif (exists($curr_quotas{$key}{$type})) {
13545: $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
13546: } else {
13547: $save_quotas{$key}{$type} = $staticdefaults{$key};
13548: }
13549: }
13550: } else {
13551: foreach my $type (@insttypes,'default') {
13552: if (exists($save_quotas{$key}{$type})) {
13553: unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
13554: $changes{$key}{$type} = 1;
13555: }
13556: } else {
13557: $save_quotas{$key}{$type} = $staticdefaults{$key};
13558: }
13559: }
13560: }
13561: }
13562: if (ref($curr_quotas{'webdav'}) eq 'HASH') {
13563: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
1.436 raeburn 13564: if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
1.429 raeburn 13565: $changes{'webdav_LC_adv'} = 1;
13566: }
13567: } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
13568: $changes{'webdav_LC_adv'} = 1;
13569: }
13570: } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13571: $changes{'webdav_LC_adv'} = 1;
13572: }
13573: my %confighash = (
13574: quotas => \%save_quotas,
13575: authordefaults => \%confhash,
13576: );
13577: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
13578: $dom);
13579: my $resulttext;
13580: if ($putresult eq 'ok') {
13581: if (keys(%changes)) {
1.431 raeburn 13582: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.429 raeburn 13583: if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
1.436 raeburn 13584: ($changes{'webdav_LC_adv'})) {
1.429 raeburn 13585: if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
13586: $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
13587: }
13588: if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
13589: (ref($save_quotas{'webdav'}) eq 'HASH')) {
13590: $domdefaults{'webdav'} = $save_quotas{'webdav'};
13591: }
13592: }
13593: $resulttext = &mt('Changes made:').'<ul>';
13594: my $authoroverride;
1.437 raeburn 13595: foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
1.429 raeburn 13596: if (exists($changes{$key})) {
1.431 raeburn 13597: $domdefaults{$key} = $confhash{$key};
1.429 raeburn 13598: my $shown;
13599: unless ($authoroverride) {
13600: $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
13601: $authoroverride = 1;
13602: }
1.437 raeburn 13603: if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
1.429 raeburn 13604: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
13605: } elsif ($key eq 'copyright') {
13606: $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
13607: } elsif ($key eq 'sourceavail') {
13608: $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
13609: }
1.436 raeburn 13610: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.429 raeburn 13611: }
13612: }
13613: if ($authoroverride) {
13614: $resulttext .= '</ul></li>';
13615: }
13616: my $domcoordoverride;
1.440 raeburn 13617: foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
1.429 raeburn 13618: if (exists($changes{$key})) {
13619: my $shown;
13620: unless ($domcoordoverride) {
13621: $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
13622: $domcoordoverride = 1;
13623: }
13624: if ($key eq 'editors') {
1.431 raeburn 13625: if (ref($confhash{'editors'}) eq 'ARRAY') {
13626: $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
13627: if (@{$confhash{'editors'}}) {
13628: $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
13629: } else {
13630: $shown = &mt('None');
13631: }
1.429 raeburn 13632: }
13633: } elsif ($key eq 'authorquota') {
13634: foreach my $type (@insttypes) {
13635: $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
13636: }
13637: $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
13638: } elsif ($key eq 'webdav') {
13639: foreach my $type (@insttypes) {
13640: $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
13641: }
13642: $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
13643: } elsif ($key eq 'webdav_LC_adv') {
13644: if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
13645: $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
13646: } else {
13647: $shown = $titles{'none'};
13648: }
1.440 raeburn 13649: } elsif ($key eq 'archive') {
1.441 raeburn 13650: $domdefaults{$key} = $confhash{$key};
1.440 raeburn 13651: $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
1.429 raeburn 13652: }
13653: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
1.436 raeburn 13654: }
1.429 raeburn 13655: }
13656: if ($domcoordoverride) {
13657: $resulttext .= '</ul></li>';
13658: }
1.439 raeburn 13659: $resulttext .= '</ul>';
1.431 raeburn 13660: my $cachetime = 24*60*60;
13661: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13662: if (ref($lastactref) eq 'HASH') {
13663: $lastactref->{'domdefaults'} = 1;
13664: }
1.429 raeburn 13665: } else {
13666: $resulttext = &mt('No changes made to Authoring Space defaults');
13667: }
13668: }
13669: return $resulttext;
13670: }
13671:
1.6 raeburn 13672: sub modify_rolecolors {
1.205 raeburn 13673: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 13674: my ($resulttext,%rolehash);
13675: $rolehash{'rolecolors'} = {};
1.55 raeburn 13676: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
13677: if ($domconfig{'rolecolors'} eq '') {
13678: $domconfig{'rolecolors'} = {};
13679: }
13680: }
1.9 raeburn 13681: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 13682: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
13683: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
13684: $dom);
13685: if ($putresult eq 'ok') {
13686: if (keys(%changes) > 0) {
1.41 raeburn 13687: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 13688: if (ref($lastactref) eq 'HASH') {
13689: $lastactref->{'domainconfig'} = 1;
13690: }
1.6 raeburn 13691: $resulttext = &display_colorchgs($dom,\%changes,$roles,
13692: $rolehash{'rolecolors'});
13693: } else {
13694: $resulttext = &mt('No changes made to default color schemes');
13695: }
13696: } else {
1.11 albertel 13697: $resulttext = '<span class="LC_error">'.
13698: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 13699: }
13700: if ($errors) {
13701: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13702: $errors.'</ul>';
13703: }
13704: return $resulttext;
13705: }
13706:
13707: sub modify_colors {
1.9 raeburn 13708: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 13709: my (%changes,%choices);
1.51 raeburn 13710: my @bgs;
1.6 raeburn 13711: my @links = ('link','alink','vlink');
1.41 raeburn 13712: my @logintext;
1.6 raeburn 13713: my @images;
13714: my $servadm = $r->dir_config('lonAdmEMail');
13715: my $errors;
1.200 raeburn 13716: my %defaults;
1.6 raeburn 13717: foreach my $role (@{$roles}) {
13718: if ($role eq 'login') {
1.12 raeburn 13719: %choices = &login_choices();
1.41 raeburn 13720: @logintext = ('textcol','bgcol');
1.12 raeburn 13721: } else {
13722: %choices = &color_font_choices();
13723: }
13724: if ($role eq 'login') {
1.41 raeburn 13725: @images = ('img','logo','domlogo','login');
1.51 raeburn 13726: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 13727: } else {
1.445 raeburn 13728: @images = ();
1.200 raeburn 13729: @bgs = ('pgbg','tabbg','sidebg');
13730: }
13731: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.444 raeburn 13732: $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
13733: if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
13734: $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
13735: }
13736: unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.200 raeburn 13737: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
13738: }
13739: if ($role eq 'login') {
13740: foreach my $item (@logintext) {
1.234 raeburn 13741: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13742: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13743: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13744: }
13745: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.200 raeburn 13746: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13747: }
13748: }
13749: } else {
1.234 raeburn 13750: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
13751: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
13752: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
13753: }
1.445 raeburn 13754: unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.200 raeburn 13755: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
13756: }
1.6 raeburn 13757: }
1.200 raeburn 13758: foreach my $item (@bgs) {
1.234 raeburn 13759: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13760: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13761: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13762: }
13763: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.200 raeburn 13764: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13765: }
13766: }
13767: foreach my $item (@links) {
1.234 raeburn 13768: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
13769: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
13770: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
13771: }
13772: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.200 raeburn 13773: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
13774: }
1.6 raeburn 13775: }
1.46 raeburn 13776: my ($configuserok,$author_ok,$switchserver) =
13777: &config_check($dom,$confname,$servadm);
1.9 raeburn 13778: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 13779: if (ref($domconfig->{$role}) ne 'HASH') {
13780: $domconfig->{$role} = {};
13781: }
1.8 raeburn 13782: foreach my $img (@images) {
1.402 raeburn 13783: if ($role eq 'login') {
13784: if (($img eq 'img') || ($img eq 'logo')) {
13785: if (defined($env{'form.login_showlogo_'.$img})) {
13786: $confhash->{$role}{'showlogo'}{$img} = 1;
13787: } else {
13788: $confhash->{$role}{'showlogo'}{$img} = 0;
13789: }
13790: }
13791: if ($env{'form.login_alt_'.$img} ne '') {
13792: $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
1.70 raeburn 13793: }
1.402 raeburn 13794: }
1.18 albertel 13795: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
13796: && !defined($domconfig->{$role}{$img})
13797: && !$env{'form.'.$role.'_del_'.$img}
13798: && $env{'form.'.$role.'_import_'.$img}) {
13799: # import the old configured image from the .tab setting
13800: # if they haven't provided a new one
13801: $domconfig->{$role}{$img} =
13802: $env{'form.'.$role.'_import_'.$img};
13803: }
1.6 raeburn 13804: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 13805: my $error;
1.6 raeburn 13806: if ($configuserok eq 'ok') {
1.9 raeburn 13807: if ($switchserver) {
1.12 raeburn 13808: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 13809: } else {
13810: if ($author_ok eq 'ok') {
1.421 raeburn 13811: my $modified = [];
1.9 raeburn 13812: my ($result,$logourl) =
1.421 raeburn 13813: &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
13814: $dom,$confname,$img,$width,$height,
13815: '',$modified);
1.9 raeburn 13816: if ($result eq 'ok') {
13817: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 13818: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13819: &update_modify_urls($r,$modified);
1.9 raeburn 13820: } else {
1.12 raeburn 13821: $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 13822: }
13823: } else {
1.46 raeburn 13824: $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 13825: }
13826: }
13827: } else {
1.46 raeburn 13828: $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 13829: }
13830: if ($error) {
1.8 raeburn 13831: &Apache::lonnet::logthis($error);
1.11 albertel 13832: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 13833: }
13834: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 13835: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
13836: my $error;
13837: if ($configuserok eq 'ok') {
13838: # is confname an author?
13839: if ($switchserver eq '') {
13840: if ($author_ok eq 'ok') {
1.421 raeburn 13841: my $modified = [];
1.9 raeburn 13842: my ($result,$logourl) =
1.421 raeburn 13843: &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
13844: $dom,$confname,$img,$width,$height,
13845: '',$modified);
1.9 raeburn 13846: if ($result eq 'ok') {
13847: $confhash->{$role}{$img} = $logourl;
1.18 albertel 13848: $changes{$role}{'images'}{$img} = 1;
1.421 raeburn 13849: &update_modify_urls($r,$modified);
1.9 raeburn 13850: }
13851: }
13852: }
13853: }
1.6 raeburn 13854: }
13855: }
13856: }
13857: if (ref($domconfig) eq 'HASH') {
13858: if (ref($domconfig->{$role}) eq 'HASH') {
13859: foreach my $img (@images) {
13860: if ($domconfig->{$role}{$img} ne '') {
13861: if ($env{'form.'.$role.'_del_'.$img}) {
13862: $confhash->{$role}{$img} = '';
1.12 raeburn 13863: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13864: } else {
1.9 raeburn 13865: if ($confhash->{$role}{$img} eq '') {
13866: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
13867: }
1.6 raeburn 13868: }
13869: } else {
13870: if ($env{'form.'.$role.'_del_'.$img}) {
13871: $confhash->{$role}{$img} = '';
1.12 raeburn 13872: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 13873: }
13874: }
1.402 raeburn 13875: if ($role eq 'login') {
13876: if (($img eq 'logo') || ($img eq 'img')) {
13877: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
13878: if ($confhash->{$role}{'showlogo'}{$img} ne
13879: $domconfig->{$role}{'showlogo'}{$img}) {
13880: $changes{$role}{'showlogo'}{$img} = 1;
13881: }
13882: } else {
13883: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
13884: $changes{$role}{'showlogo'}{$img} = 1;
13885: }
1.70 raeburn 13886: }
1.402 raeburn 13887: }
13888: if ($img ne 'login') {
13889: if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
13890: if ($confhash->{$role}{'alttext'}{$img} ne
13891: $domconfig->{$role}{'alttext'}{$img}) {
13892: $changes{$role}{'alttext'}{$img} = 1;
13893: }
13894: } else {
13895: if ($confhash->{$role}{'alttext'}{$img} ne '') {
13896: $changes{$role}{'alttext'}{$img} = 1;
13897: }
1.70 raeburn 13898: }
13899: }
13900: }
13901: }
1.6 raeburn 13902: if ($domconfig->{$role}{'font'} ne '') {
13903: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
13904: $changes{$role}{'font'} = 1;
13905: }
13906: } else {
13907: if ($confhash->{$role}{'font'}) {
13908: $changes{$role}{'font'} = 1;
13909: }
13910: }
1.107 raeburn 13911: if ($role ne 'login') {
13912: if ($domconfig->{$role}{'fontmenu'} ne '') {
13913: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
13914: $changes{$role}{'fontmenu'} = 1;
13915: }
13916: } else {
13917: if ($confhash->{$role}{'fontmenu'}) {
13918: $changes{$role}{'fontmenu'} = 1;
13919: }
1.97 tempelho 13920: }
13921: }
1.6 raeburn 13922: foreach my $item (@bgs) {
13923: if ($domconfig->{$role}{$item} ne '') {
13924: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13925: $changes{$role}{'bgs'}{$item} = 1;
13926: }
13927: } else {
13928: if ($confhash->{$role}{$item}) {
13929: $changes{$role}{'bgs'}{$item} = 1;
13930: }
13931: }
13932: }
13933: foreach my $item (@links) {
13934: if ($domconfig->{$role}{$item} ne '') {
13935: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13936: $changes{$role}{'links'}{$item} = 1;
13937: }
13938: } else {
13939: if ($confhash->{$role}{$item}) {
13940: $changes{$role}{'links'}{$item} = 1;
13941: }
13942: }
13943: }
1.41 raeburn 13944: foreach my $item (@logintext) {
13945: if ($domconfig->{$role}{$item} ne '') {
13946: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
13947: $changes{$role}{'logintext'}{$item} = 1;
13948: }
13949: } else {
13950: if ($confhash->{$role}{$item}) {
13951: $changes{$role}{'logintext'}{$item} = 1;
13952: }
13953: }
13954: }
1.6 raeburn 13955: } else {
13956: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13957: \@logintext,$confhash,\%changes);
1.6 raeburn 13958: }
13959: } else {
13960: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 13961: \@logintext,$confhash,\%changes);
1.6 raeburn 13962: }
13963: }
13964: return ($errors,%changes);
13965: }
13966:
1.46 raeburn 13967: sub config_check {
13968: my ($dom,$confname,$servadm) = @_;
13969: my ($configuserok,$author_ok,$switchserver,%currroles);
13970: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
13971: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
13972: $confname,$servadm);
13973: if ($configuserok eq 'ok') {
13974: $switchserver = &check_switchserver($dom,$confname);
13975: if ($switchserver eq '') {
13976: $author_ok = &check_authorstatus($dom,$confname,%currroles);
13977: }
13978: }
13979: return ($configuserok,$author_ok,$switchserver);
13980: }
13981:
1.6 raeburn 13982: sub default_change_checker {
1.41 raeburn 13983: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 13984: foreach my $item (@{$links}) {
13985: if ($confhash->{$role}{$item}) {
13986: $changes->{$role}{'links'}{$item} = 1;
13987: }
13988: }
13989: foreach my $item (@{$bgs}) {
13990: if ($confhash->{$role}{$item}) {
13991: $changes->{$role}{'bgs'}{$item} = 1;
13992: }
13993: }
1.41 raeburn 13994: foreach my $item (@{$logintext}) {
13995: if ($confhash->{$role}{$item}) {
13996: $changes->{$role}{'logintext'}{$item} = 1;
13997: }
13998: }
1.6 raeburn 13999: foreach my $img (@{$images}) {
14000: if ($env{'form.'.$role.'_del_'.$img}) {
14001: $confhash->{$role}{$img} = '';
1.12 raeburn 14002: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 14003: }
1.70 raeburn 14004: if ($role eq 'login') {
14005: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
14006: $changes->{$role}{'showlogo'}{$img} = 1;
14007: }
1.402 raeburn 14008: if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
14009: if ($confhash->{$role}{'alttext'}{$img} ne '') {
14010: $changes->{$role}{'alttext'}{$img} = 1;
14011: }
14012: }
1.70 raeburn 14013: }
1.6 raeburn 14014: }
14015: if ($confhash->{$role}{'font'}) {
14016: $changes->{$role}{'font'} = 1;
14017: }
1.48 raeburn 14018: }
1.6 raeburn 14019:
14020: sub display_colorchgs {
14021: my ($dom,$changes,$roles,$confhash) = @_;
14022: my (%choices,$resulttext);
14023: if (!grep(/^login$/,@{$roles})) {
14024: $resulttext = &mt('Changes made:').'<br />';
14025: }
14026: foreach my $role (@{$roles}) {
14027: if ($role eq 'login') {
14028: %choices = &login_choices();
14029: } else {
14030: %choices = &color_font_choices();
14031: }
14032: if (ref($changes->{$role}) eq 'HASH') {
14033: if ($role ne 'login') {
14034: $resulttext .= '<h4>'.&mt($role).'</h4>';
14035: }
14036: foreach my $key (sort(keys(%{$changes->{$role}}))) {
14037: if ($role ne 'login') {
14038: $resulttext .= '<ul>';
14039: }
14040: if (ref($changes->{$role}{$key}) eq 'HASH') {
14041: if ($role ne 'login') {
14042: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
14043: }
14044: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 14045: if (($role eq 'login') && ($key eq 'showlogo')) {
14046: if ($confhash->{$role}{$key}{$item}) {
14047: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
14048: } else {
14049: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
14050: }
1.402 raeburn 14051: } elsif (($role eq 'login') && ($key eq 'alttext')) {
14052: if ($confhash->{$role}{$key}{$item} ne '') {
1.403 raeburn 14053: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
1.402 raeburn 14054: $confhash->{$role}{$key}{$item}).'</li>';
14055: } else {
14056: $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
14057: }
1.70 raeburn 14058: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 14059: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
14060: } else {
1.12 raeburn 14061: my $newitem = $confhash->{$role}{$item};
14062: if ($key eq 'images') {
1.306 raeburn 14063: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" style="vertical-align: bottom" />';
1.12 raeburn 14064: }
14065: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 14066: }
14067: }
14068: if ($role ne 'login') {
14069: $resulttext .= '</ul></li>';
14070: }
14071: } else {
14072: if ($confhash->{$role}{$key} eq '') {
14073: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
14074: } else {
14075: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
14076: }
14077: }
14078: if ($role ne 'login') {
14079: $resulttext .= '</ul>';
14080: }
14081: }
14082: }
14083: }
1.3 raeburn 14084: return $resulttext;
1.1 raeburn 14085: }
14086:
1.9 raeburn 14087: sub thumb_dimensions {
14088: return ('200','50');
14089: }
14090:
1.16 raeburn 14091: sub check_dimensions {
14092: my ($inputfile) = @_;
14093: my ($fullwidth,$fullheight);
14094: if ($inputfile =~ m|^[/\w.\-]+$|) {
14095: if (open(PIPE,"identify $inputfile 2>&1 |")) {
14096: my $imageinfo = <PIPE>;
14097: if (!close(PIPE)) {
14098: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
14099: }
14100: chomp($imageinfo);
14101: my ($fullsize) =
1.21 raeburn 14102: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 14103: if ($fullsize) {
14104: ($fullwidth,$fullheight) = split(/x/,$fullsize);
14105: }
14106: }
14107: }
14108: return ($fullwidth,$fullheight);
14109: }
14110:
1.9 raeburn 14111: sub check_configuser {
14112: my ($uhome,$dom,$confname,$servadm) = @_;
14113: my ($configuserok,%currroles);
14114: if ($uhome eq 'no_host') {
14115: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.361 raeburn 14116: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 14117: $configuserok =
14118: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
14119: $configpass,'','','','','',undef,$servadm);
14120: } else {
14121: $configuserok = 'ok';
14122: %currroles =
14123: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
14124: }
14125: return ($configuserok,%currroles);
14126: }
14127:
14128: sub check_authorstatus {
14129: my ($dom,$confname,%currroles) = @_;
14130: my $author_ok;
1.40 raeburn 14131: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 14132: my $start = time;
14133: my $end = 0;
14134: $author_ok =
14135: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 14136: 'au',$end,$start,'','','domconfig');
1.9 raeburn 14137: } else {
14138: $author_ok = 'ok';
14139: }
14140: return $author_ok;
14141: }
14142:
1.421 raeburn 14143: sub update_modify_urls {
14144: my ($r,$modified) = @_;
14145: if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
14146: push(@{$modified_urls},$modified);
14147: unless ($registered_cleanup) {
14148: my $handlers = $r->get_handlers('PerlCleanupHandler');
14149: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
14150: $registered_cleanup=1;
1.9 raeburn 14151: }
14152: }
1.155 raeburn 14153: }
14154:
14155: sub notifysubscribed {
14156: foreach my $targetsource (@{$modified_urls}){
14157: next unless (ref($targetsource) eq 'ARRAY');
14158: my ($target,$source)=@{$targetsource};
14159: if ($source ne '') {
1.316 raeburn 14160: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 14161: print $logfh "\nCleanup phase: Notifications\n";
14162: my @subscribed=&subscribed_hosts($target);
14163: foreach my $subhost (@subscribed) {
14164: print $logfh "\nNotifying host ".$subhost.':';
14165: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
14166: print $logfh $reply;
14167: }
14168: my @subscribedmeta=&subscribed_hosts("$target.meta");
14169: foreach my $subhost (@subscribedmeta) {
14170: print $logfh "\nNotifying host for metadata only ".$subhost.':';
14171: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
14172: $subhost);
14173: print $logfh $reply;
14174: }
14175: print $logfh "\n============ Done ============\n";
1.160 raeburn 14176: close($logfh);
1.155 raeburn 14177: }
14178: }
14179: }
14180: return OK;
14181: }
14182:
14183: sub subscribed_hosts {
14184: my ($target) = @_;
14185: my @subscribed;
1.316 raeburn 14186: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 14187: while (my $subline=<$fh>) {
14188: if ($subline =~ /^($match_lonid):/) {
14189: my $host = $1;
14190: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
14191: unless (grep(/^\Q$host\E$/,@subscribed)) {
14192: push(@subscribed,$host);
14193: }
14194: }
14195: }
14196: }
14197: }
14198: return @subscribed;
1.9 raeburn 14199: }
14200:
14201: sub check_switchserver {
14202: my ($dom,$confname) = @_;
1.424 raeburn 14203: my ($allowed,$switchserver,$home);
14204: if ($confname eq '') {
1.9 raeburn 14205: $home = &Apache::lonnet::domain($dom,'primary');
1.424 raeburn 14206: } else {
14207: $home = &Apache::lonnet::homeserver($confname,$dom);
14208: if ($home eq 'no_host') {
14209: $home = &Apache::lonnet::domain($dom,'primary');
14210: }
1.9 raeburn 14211: }
14212: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 14213: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
14214: if (!$allowed) {
1.426 raeburn 14215: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
14216: &HTML::Entities::encode($env{'request.role'},'\'<>"&').
14217: '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 14218: }
14219: return $switchserver;
14220: }
14221:
1.1 raeburn 14222: sub modify_quotas {
1.216 raeburn 14223: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 14224: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.216 raeburn 14225: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.235 raeburn 14226: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
14227: $validationfieldsref);
1.86 raeburn 14228: if ($action eq 'quotas') {
1.429 raeburn 14229: $context = 'tools';
1.163 raeburn 14230: } else {
1.86 raeburn 14231: $context = $action;
14232: }
14233: if ($context eq 'requestcourses') {
1.325 raeburn 14234: @usertools = ('official','unofficial','community','textbook','placement','lti');
1.106 raeburn 14235: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 14236: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
14237: %titles = &courserequest_titles();
14238: $toolregexp = join('|',@usertools);
14239: %conditions = &courserequest_conditions();
1.216 raeburn 14240: $confname = $dom.'-domainconfig';
14241: my $servadm = $r->dir_config('lonAdmEMail');
14242: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.235 raeburn 14243: ($validationitemsref,$validationnamesref,$validationfieldsref) =
14244: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.163 raeburn 14245: } elsif ($context eq 'requestauthor') {
14246: @usertools = ('author');
14247: %titles = &authorrequest_titles();
1.86 raeburn 14248: } else {
1.430 raeburn 14249: @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 14250: %titles = &tool_titles();
1.86 raeburn 14251: }
1.212 raeburn 14252: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 14253: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14254: foreach my $key (keys(%env)) {
1.101 raeburn 14255: if ($context eq 'requestcourses') {
14256: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
14257: my $item = $1;
14258: my $type = $2;
14259: if ($type =~ /^limit_(.+)/) {
14260: $limithash{$item}{$1} = $env{$key};
14261: } else {
14262: $confhash{$item}{$type} = $env{$key};
14263: }
14264: }
1.163 raeburn 14265: } elsif ($context eq 'requestauthor') {
14266: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
14267: $confhash{$1} = $env{$key};
14268: }
1.101 raeburn 14269: } else {
1.86 raeburn 14270: if ($key =~ /^form\.quota_(.+)$/) {
14271: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 14272: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 14273: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
14274: }
1.72 raeburn 14275: }
14276: }
1.163 raeburn 14277: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.224 raeburn 14278: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 14279: @approvalnotify = sort(@approvalnotify);
14280: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.325 raeburn 14281: my @crstypes = ('official','unofficial','community','textbook','placement','lti');
1.218 raeburn 14282: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
14283: foreach my $type (@hasuniquecode) {
14284: if (grep(/^\Q$type\E$/,@crstypes)) {
14285: $confhash{'uniquecode'}{$type} = 1;
14286: }
1.216 raeburn 14287: }
1.242 raeburn 14288: my (%newbook,%allpos);
1.216 raeburn 14289: if ($context eq 'requestcourses') {
1.242 raeburn 14290: foreach my $type ('textbooks','templates') {
14291: @{$allpos{$type}} = ();
14292: my $invalid;
14293: if ($type eq 'textbooks') {
14294: $invalid = &mt('Invalid LON-CAPA course for textbook');
14295: } else {
14296: $invalid = &mt('Invalid LON-CAPA course for template');
14297: }
14298: if ($env{'form.'.$type.'_addbook'}) {
14299: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
14300: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
14301: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
14302: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
14303: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
14304: } else {
14305: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
14306: my $position = $env{'form.'.$type.'_addbook_pos'};
14307: $position =~ s/\D+//g;
14308: if ($position ne '') {
14309: $allpos{$type}[$position] = $newbook{$type};
14310: }
1.216 raeburn 14311: }
1.242 raeburn 14312: } else {
14313: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.216 raeburn 14314: }
14315: }
1.242 raeburn 14316: }
1.216 raeburn 14317: }
1.102 raeburn 14318: if (ref($domconfig{$action}) eq 'HASH') {
14319: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
14320: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
14321: $changes{'notify'}{'approval'} = 1;
14322: }
14323: } else {
1.144 raeburn 14324: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14325: $changes{'notify'}{'approval'} = 1;
14326: }
14327: }
1.218 raeburn 14328: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
14329: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14330: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
14331: unless ($confhash{'uniquecode'}{$crstype}) {
14332: $changes{'uniquecode'} = 1;
14333: }
14334: }
14335: unless ($changes{'uniquecode'}) {
14336: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
14337: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
14338: $changes{'uniquecode'} = 1;
14339: }
14340: }
14341: }
14342: } else {
14343: $changes{'uniquecode'} = 1;
14344: }
14345: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
14346: $changes{'uniquecode'} = 1;
1.216 raeburn 14347: }
14348: if ($context eq 'requestcourses') {
1.242 raeburn 14349: foreach my $type ('textbooks','templates') {
14350: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14351: my %deletions;
14352: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
14353: if (@todelete) {
14354: map { $deletions{$_} = 1; } @todelete;
14355: }
14356: my %imgdeletions;
14357: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
14358: if (@todeleteimages) {
14359: map { $imgdeletions{$_} = 1; } @todeleteimages;
14360: }
14361: my $maxnum = $env{'form.'.$type.'_maxnum'};
14362: for (my $i=0; $i<=$maxnum; $i++) {
14363: my $itemid = $env{'form.'.$type.'_id_'.$i};
14364: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
14365: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
14366: if ($deletions{$key}) {
14367: if ($domconfig{$action}{$type}{$key}{'image'}) {
14368: #FIXME need to obsolete item in RES space
14369: }
14370: next;
14371: } else {
14372: my $newpos = $env{'form.'.$itemid};
14373: $newpos =~ s/\D+//g;
1.243 raeburn 14374: foreach my $item ('subject','title','publisher','author') {
1.289 raeburn 14375: next if ((($item eq 'author') || ($item eq 'publisher')) &&
1.243 raeburn 14376: ($type eq 'templates'));
1.242 raeburn 14377: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
14378: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
14379: $changes{$type}{$key} = 1;
14380: }
14381: }
14382: $allpos{$type}[$newpos] = $key;
14383: }
14384: if ($imgdeletions{$key}) {
14385: $changes{$type}{$key} = 1;
1.216 raeburn 14386: #FIXME need to obsolete item in RES space
1.242 raeburn 14387: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
14388: my ($cdom,$cnum) = split(/_/,$key);
1.313 raeburn 14389: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14390: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14391: } else {
14392: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
14393: $cdom,$cnum,$type,$configuserok,
14394: $switchserver,$author_ok);
14395: if ($imgurl) {
14396: $confhash{$type}{$key}{'image'} = $imgurl;
14397: $changes{$type}{$key} = 1;
14398: }
14399: if ($error) {
14400: &Apache::lonnet::logthis($error);
14401: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14402: }
14403: }
1.242 raeburn 14404: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
14405: $confhash{$type}{$key}{'image'} =
14406: $domconfig{$action}{$type}{$key}{'image'};
1.216 raeburn 14407: }
14408: }
14409: }
14410: }
14411: }
14412: }
1.102 raeburn 14413: } else {
1.144 raeburn 14414: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 14415: $changes{'notify'}{'approval'} = 1;
14416: }
1.218 raeburn 14417: if (ref($confhash{'uniquecode'} eq 'HASH')) {
1.216 raeburn 14418: $changes{'uniquecode'} = 1;
14419: }
14420: }
14421: if ($context eq 'requestcourses') {
1.242 raeburn 14422: foreach my $type ('textbooks','templates') {
14423: if ($newbook{$type}) {
14424: $changes{$type}{$newbook{$type}} = 1;
1.243 raeburn 14425: foreach my $item ('subject','title','publisher','author') {
14426: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14427: ($type eq 'template'));
1.242 raeburn 14428: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
14429: if ($env{'form.'.$type.'_addbook_'.$item}) {
14430: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
14431: }
14432: }
14433: if ($type eq 'textbooks') {
14434: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
14435: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.313 raeburn 14436: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
14437: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
14438: } else {
14439: my ($imageurl,$error) =
14440: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
14441: $configuserok,$switchserver,$author_ok);
14442: if ($imageurl) {
14443: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
14444: }
14445: if ($error) {
14446: &Apache::lonnet::logthis($error);
14447: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14448: }
1.242 raeburn 14449: }
14450: }
1.216 raeburn 14451: }
14452: }
1.242 raeburn 14453: if (@{$allpos{$type}} > 0) {
14454: my $idx = 0;
14455: foreach my $item (@{$allpos{$type}}) {
14456: if ($item ne '') {
14457: $confhash{$type}{$item}{'order'} = $idx;
14458: if (ref($domconfig{$action}) eq 'HASH') {
14459: if (ref($domconfig{$action}{$type}) eq 'HASH') {
14460: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
14461: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
14462: $changes{$type}{$item} = 1;
14463: }
1.216 raeburn 14464: }
14465: }
14466: }
1.242 raeburn 14467: $idx ++;
1.216 raeburn 14468: }
14469: }
14470: }
14471: }
1.235 raeburn 14472: if (ref($validationitemsref) eq 'ARRAY') {
14473: foreach my $item (@{$validationitemsref}) {
14474: if ($item eq 'fields') {
14475: my @changed;
14476: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
14477: if (@{$confhash{'validation'}{$item}} > 0) {
14478: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
14479: }
1.266 raeburn 14480: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14481: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14482: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
14483: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
14484: $domconfig{'requestcourses'}{'validation'}{$item});
14485: } else {
14486: @changed = @{$confhash{'validation'}{$item}};
14487: }
1.235 raeburn 14488: } else {
14489: @changed = @{$confhash{'validation'}{$item}};
14490: }
14491: } else {
14492: @changed = @{$confhash{'validation'}{$item}};
14493: }
14494: if (@changed) {
14495: if ($confhash{'validation'}{$item}) {
14496: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
14497: } else {
14498: $changes{'validation'}{$item} = &mt('None');
14499: }
14500: }
14501: } else {
14502: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
14503: if ($item eq 'markup') {
14504: if ($env{'form.requestcourses_validation_'.$item}) {
14505: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
14506: }
14507: }
1.266 raeburn 14508: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14509: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14510: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
14511: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14512: }
14513: } else {
14514: if ($confhash{'validation'}{$item} ne '') {
14515: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14516: }
1.235 raeburn 14517: }
14518: } else {
14519: if ($confhash{'validation'}{$item} ne '') {
14520: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
14521: }
14522: }
14523: }
14524: }
14525: }
14526: if ($env{'form.validationdc'}) {
14527: my $newval = $env{'form.validationdc'};
1.285 raeburn 14528: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.235 raeburn 14529: if (exists($domcoords{$newval})) {
14530: $confhash{'validation'}{'dc'} = $newval;
14531: }
14532: }
14533: if (ref($confhash{'validation'}) eq 'HASH') {
1.266 raeburn 14534: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14535: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14536: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14537: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
14538: if ($confhash{'validation'}{'dc'} eq '') {
14539: $changes{'validation'}{'dc'} = &mt('None');
14540: } else {
14541: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14542: }
1.235 raeburn 14543: }
1.266 raeburn 14544: } elsif ($confhash{'validation'}{'dc'} ne '') {
14545: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.235 raeburn 14546: }
14547: } elsif ($confhash{'validation'}{'dc'} ne '') {
14548: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
14549: }
14550: } elsif ($confhash{'validation'}{'dc'} ne '') {
14551: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.289 raeburn 14552: }
1.266 raeburn 14553: } else {
14554: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
14555: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
14556: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
14557: $changes{'validation'}{'dc'} = &mt('None');
14558: }
14559: }
1.235 raeburn 14560: }
14561: }
1.102 raeburn 14562: }
14563: } else {
1.86 raeburn 14564: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
14565: }
1.72 raeburn 14566: foreach my $item (@usertools) {
14567: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 14568: my $unset;
1.101 raeburn 14569: if ($context eq 'requestcourses') {
1.104 raeburn 14570: $unset = '0';
14571: if ($type eq '_LC_adv') {
14572: $unset = '';
14573: }
1.101 raeburn 14574: if ($confhash{$item}{$type} eq 'autolimit') {
14575: $confhash{$item}{$type} .= '=';
14576: unless ($limithash{$item}{$type} =~ /\D/) {
14577: $confhash{$item}{$type} .= $limithash{$item}{$type};
14578: }
14579: }
1.163 raeburn 14580: } elsif ($context eq 'requestauthor') {
14581: $unset = '0';
14582: if ($type eq '_LC_adv') {
14583: $unset = '';
14584: }
1.72 raeburn 14585: } else {
1.101 raeburn 14586: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
14587: $confhash{$item}{$type} = 1;
14588: } else {
14589: $confhash{$item}{$type} = 0;
14590: }
1.72 raeburn 14591: }
1.86 raeburn 14592: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 14593: if ($action eq 'requestauthor') {
14594: if ($domconfig{$action}{$type} ne $confhash{$type}) {
14595: $changes{$type} = 1;
14596: }
14597: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 14598: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
14599: $changes{$item}{$type} = 1;
14600: }
14601: } else {
14602: if ($context eq 'requestcourses') {
1.104 raeburn 14603: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 14604: $changes{$item}{$type} = 1;
14605: }
14606: } else {
14607: if (!$confhash{$item}{$type}) {
14608: $changes{$item}{$type} = 1;
14609: }
14610: }
14611: }
14612: } else {
14613: if ($context eq 'requestcourses') {
1.104 raeburn 14614: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 14615: $changes{$item}{$type} = 1;
14616: }
1.163 raeburn 14617: } elsif ($context eq 'requestauthor') {
14618: if ($confhash{$type} ne $unset) {
14619: $changes{$type} = 1;
14620: }
1.72 raeburn 14621: } else {
14622: if (!$confhash{$item}{$type}) {
14623: $changes{$item}{$type} = 1;
14624: }
14625: }
14626: }
1.1 raeburn 14627: }
14628: }
1.163 raeburn 14629: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 14630: if (ref($domconfig{'quotas'}) eq 'HASH') {
14631: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14632: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
14633: if (exists($confhash{'defaultquota'}{$key})) {
14634: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
14635: $changes{'defaultquota'}{$key} = 1;
14636: }
14637: } else {
14638: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 14639: }
14640: }
1.86 raeburn 14641: } else {
14642: foreach my $key (keys(%{$domconfig{'quotas'}})) {
14643: if (exists($confhash{'defaultquota'}{$key})) {
14644: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
14645: $changes{'defaultquota'}{$key} = 1;
14646: }
14647: } else {
14648: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 14649: }
1.1 raeburn 14650: }
14651: }
1.197 raeburn 14652: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.429 raeburn 14653: $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
14654: }
14655: if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
14656: $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.197 raeburn 14657: }
1.1 raeburn 14658: }
1.86 raeburn 14659: if (ref($confhash{'defaultquota'}) eq 'HASH') {
14660: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
14661: if (ref($domconfig{'quotas'}) eq 'HASH') {
14662: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
14663: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
14664: $changes{'defaultquota'}{$key} = 1;
14665: }
14666: } else {
14667: if (!exists($domconfig{'quotas'}{$key})) {
14668: $changes{'defaultquota'}{$key} = 1;
14669: }
1.72 raeburn 14670: }
14671: } else {
1.86 raeburn 14672: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 14673: }
1.1 raeburn 14674: }
14675: }
14676: }
1.72 raeburn 14677:
1.163 raeburn 14678: if ($context eq 'requestauthor') {
14679: $domdefaults{'requestauthor'} = \%confhash;
14680: } else {
14681: foreach my $key (keys(%confhash)) {
1.242 raeburn 14682: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.216 raeburn 14683: $domdefaults{$key} = $confhash{$key};
14684: }
1.163 raeburn 14685: }
1.72 raeburn 14686: }
1.163 raeburn 14687:
1.1 raeburn 14688: my %quotahash = (
1.86 raeburn 14689: $action => { %confhash }
1.1 raeburn 14690: );
14691: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
14692: $dom);
14693: if ($putresult eq 'ok') {
14694: if (keys(%changes) > 0) {
1.72 raeburn 14695: my $cachetime = 24*60*60;
14696: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 14697: if (ref($lastactref) eq 'HASH') {
14698: $lastactref->{'domdefaults'} = 1;
14699: }
1.1 raeburn 14700: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 14701: unless (($context eq 'requestcourses') ||
1.163 raeburn 14702: ($context eq 'requestauthor')) {
1.86 raeburn 14703: if (ref($changes{'defaultquota'}) eq 'HASH') {
14704: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
14705: foreach my $type (@{$types},'default') {
14706: if (defined($changes{'defaultquota'}{$type})) {
14707: my $typetitle = $usertypes->{$type};
14708: if ($type eq 'default') {
14709: $typetitle = $othertitle;
14710: }
1.213 raeburn 14711: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 14712: }
14713: }
1.86 raeburn 14714: $resulttext .= '</ul></li>';
1.72 raeburn 14715: }
14716: }
1.80 raeburn 14717: my %newenv;
1.72 raeburn 14718: foreach my $item (@usertools) {
1.163 raeburn 14719: my (%haschgs,%inconf);
14720: if ($context eq 'requestauthor') {
14721: %haschgs = %changes;
1.210 raeburn 14722: %inconf = %confhash;
1.163 raeburn 14723: } else {
14724: if (ref($changes{$item}) eq 'HASH') {
14725: %haschgs = %{$changes{$item}};
14726: }
14727: if (ref($confhash{$item}) eq 'HASH') {
14728: %inconf = %{$confhash{$item}};
14729: }
14730: }
14731: if (keys(%haschgs) > 0) {
1.80 raeburn 14732: my $newacc =
14733: &Apache::lonnet::usertools_access($env{'user.name'},
14734: $env{'user.domain'},
1.86 raeburn 14735: $item,'reload',$context);
1.210 raeburn 14736: if (($context eq 'requestcourses') ||
1.163 raeburn 14737: ($context eq 'requestauthor')) {
1.108 raeburn 14738: if ($env{'environment.canrequest.'.$item} ne $newacc) {
14739: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 14740: }
14741: } else {
14742: if ($env{'environment.availabletools.'.$item} ne $newacc) {
14743: $newenv{'environment.availabletools.'.$item} = $newacc;
14744: }
1.80 raeburn 14745: }
1.163 raeburn 14746: unless ($context eq 'requestauthor') {
14747: $resulttext .= '<li>'.$titles{$item}.'<ul>';
14748: }
1.72 raeburn 14749: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 14750: if ($haschgs{$type}) {
1.72 raeburn 14751: my $typetitle = $usertypes->{$type};
14752: if ($type eq 'default') {
14753: $typetitle = $othertitle;
14754: } elsif ($type eq '_LC_adv') {
14755: $typetitle = 'LON-CAPA Advanced Users';
14756: }
1.163 raeburn 14757: if ($inconf{$type}) {
1.101 raeburn 14758: if ($context eq 'requestcourses') {
14759: my $cond;
1.163 raeburn 14760: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 14761: if ($1 eq '') {
14762: $cond = &mt('(Automatic processing of any request).');
14763: } else {
14764: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
14765: }
14766: } else {
1.163 raeburn 14767: $cond = $conditions{$inconf{$type}};
1.101 raeburn 14768: }
14769: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 14770: } elsif ($context eq 'requestauthor') {
14771: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
14772: $titles{$inconf{$type}},$typetitle);
14773:
1.101 raeburn 14774: } else {
14775: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
14776: }
1.72 raeburn 14777: } else {
1.104 raeburn 14778: if ($type eq '_LC_adv') {
1.163 raeburn 14779: if ($inconf{$type} eq '0') {
1.104 raeburn 14780: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14781: } else {
14782: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
14783: }
14784: } else {
14785: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
14786: }
1.72 raeburn 14787: }
14788: }
1.26 raeburn 14789: }
1.163 raeburn 14790: unless ($context eq 'requestauthor') {
14791: $resulttext .= '</ul></li>';
14792: }
1.26 raeburn 14793: }
1.1 raeburn 14794: }
1.163 raeburn 14795: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 14796: if (ref($changes{'notify'}) eq 'HASH') {
14797: if ($changes{'notify'}{'approval'}) {
14798: if (ref($confhash{'notify'}) eq 'HASH') {
14799: if ($confhash{'notify'}{'approval'}) {
14800: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
14801: } else {
1.163 raeburn 14802: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 14803: }
14804: }
14805: }
14806: }
14807: }
1.216 raeburn 14808: if ($action eq 'requestcourses') {
14809: my @offon = ('off','on');
14810: if ($changes{'uniquecode'}) {
1.218 raeburn 14811: if (ref($confhash{'uniquecode'}) eq 'HASH') {
14812: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
14813: $resulttext .= '<li>'.
14814: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
14815: '</li>';
14816: } else {
14817: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
14818: '</li>';
14819: }
1.216 raeburn 14820: }
1.242 raeburn 14821: foreach my $type ('textbooks','templates') {
14822: if (ref($changes{$type}) eq 'HASH') {
14823: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
14824: foreach my $key (sort(keys(%{$changes{$type}}))) {
14825: my %coursehash = &Apache::lonnet::coursedescription($key);
14826: my $coursetitle = $coursehash{'description'};
14827: my $position = $confhash{$type}{$key}{'order'} + 1;
14828: $resulttext .= '<li>';
1.243 raeburn 14829: foreach my $item ('subject','title','publisher','author') {
14830: next if ((($item eq 'author') || ($item eq 'publisher')) &&
14831: ($type eq 'templates'));
1.242 raeburn 14832: my $name = $item.':';
14833: $name =~ s/^(\w)/\U$1/;
14834: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
14835: }
14836: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
14837: if ($type eq 'textbooks') {
14838: if ($confhash{$type}{$key}{'image'}) {
14839: $resulttext .= ' '.&mt('Image: [_1]',
14840: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
14841: ' alt="Textbook cover" />').'<br />';
14842: }
14843: }
14844: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.216 raeburn 14845: }
1.242 raeburn 14846: $resulttext .= '</ul></li>';
1.216 raeburn 14847: }
14848: }
1.235 raeburn 14849: if (ref($changes{'validation'}) eq 'HASH') {
14850: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
14851: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
14852: foreach my $item (@{$validationitemsref}) {
14853: if (exists($changes{'validation'}{$item})) {
14854: if ($item eq 'markup') {
14855: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14856: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
14857: } else {
14858: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
14859: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
14860: }
14861: }
14862: }
14863: if (exists($changes{'validation'}{'dc'})) {
14864: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
14865: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
14866: }
1.442 raeburn 14867: $resulttext .= '</ul></li>';
1.235 raeburn 14868: }
14869: }
1.216 raeburn 14870: }
1.1 raeburn 14871: $resulttext .= '</ul>';
1.80 raeburn 14872: if (keys(%newenv)) {
14873: &Apache::lonnet::appenv(\%newenv);
14874: }
1.1 raeburn 14875: } else {
1.86 raeburn 14876: if ($context eq 'requestcourses') {
14877: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 14878: } elsif ($context eq 'requestauthor') {
14879: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 14880: } else {
1.90 weissno 14881: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 14882: }
1.1 raeburn 14883: }
14884: } else {
1.11 albertel 14885: $resulttext = '<span class="LC_error">'.
14886: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14887: }
1.216 raeburn 14888: if ($errors) {
14889: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
14890: '<ul>'.$errors.'</ul></p>';
14891: }
1.3 raeburn 14892: return $resulttext;
1.1 raeburn 14893: }
14894:
1.216 raeburn 14895: sub process_textbook_image {
1.242 raeburn 14896: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.216 raeburn 14897: my $filename = $env{'form.'.$caller.'.filename'};
14898: my ($error,$url);
14899: my ($width,$height) = (50,50);
14900: if ($configuserok eq 'ok') {
14901: if ($switchserver) {
14902: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
14903: $switchserver);
14904: } elsif ($author_ok eq 'ok') {
1.421 raeburn 14905: my $modified = [];
1.216 raeburn 14906: my ($result,$imageurl) =
1.421 raeburn 14907: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
14908: "$type/$cdom/$cnum/cover",$width,$height,
14909: '',$modified);
1.216 raeburn 14910: if ($result eq 'ok') {
14911: $url = $imageurl;
1.421 raeburn 14912: &update_modify_urls($r,$modified);
1.216 raeburn 14913: } else {
14914: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
14915: }
14916: } else {
14917: $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);
14918: }
14919: } else {
14920: $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);
14921: }
14922: return ($url,$error);
14923: }
14924:
1.267 raeburn 14925: sub modify_ltitools {
14926: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.421 raeburn 14927: my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
14928: &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
14929:
1.267 raeburn 14930: my $confname = $dom.'-domainconfig';
14931: my $servadm = $r->dir_config('lonAdmEMail');
14932: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.421 raeburn 14933:
14934: my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
14935: my $toolserror =
14936: &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
14937: $lastactref,$configuserok,$switchserver,$author_ok);
14938:
14939: my $home = &Apache::lonnet::domain($dom,'primary');
14940: unless (($home eq 'no_host') || ($home eq '')) {
14941: my @ids=&Apache::lonnet::current_machine_ids();
14942: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
14943: }
14944:
14945: if (keys(%ltitoolschg)) {
14946: foreach my $id (keys(%ltitoolschg)) {
14947: if (ref($ltitoolschg{$id}) eq 'HASH') {
14948: foreach my $inner (keys(%{$ltitoolschg{$id}})) {
14949: if (($inner eq 'secret') || ($inner eq 'key')) {
14950: if ($is_home) {
14951: $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
14952: }
14953: }
14954: }
1.267 raeburn 14955: }
1.421 raeburn 14956: }
14957: $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
14958: if (keys(%ltitoolschg)) {
14959: %newltitools = %ltitoolschg;
14960: }
14961: }
14962: if (ref($domconfig{'ltitools'}) eq 'HASH') {
14963: foreach my $id (%{$domconfig{'ltitools'}}) {
14964: next if ($id !~ /^\d+$/);
14965: unless (exists($ltitoolschg{$id})) {
14966: if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
14967: foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
14968: if (($inner eq 'secret') || ($inner eq 'key')) {
14969: if ($is_home) {
14970: $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14971: }
14972: } else {
14973: $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
14974: }
14975: }
14976: } else {
14977: $newltitools{$id} = $domconfig{'ltitools'}{$id};
1.322 raeburn 14978: }
1.421 raeburn 14979: }
14980: }
14981: }
14982: if ($toolserror) {
14983: $errors = '<li>'.$toolserror.'</li>';
14984: }
14985: if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
14986: $resulttext = &mt('No changes made.');
14987: if ($errors) {
14988: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
14989: $errors.'</ul>';
14990: }
14991: return $resulttext;
14992: }
14993: my %ltitoolshash = (
14994: $action => { %newltitools }
14995: );
14996: if (keys(%secchanges)) {
14997: $ltitoolshash{'toolsec'} = \%newtoolsec;
14998: }
14999: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
15000: if ($putresult eq 'ok') {
15001: my %keystore;
15002: if ($is_home) {
15003: my %toolsenchash = (
15004: $action => { %newtoolsenc }
15005: );
15006: &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
1.423 raeburn 15007: my $cachetime = 24*60*60;
15008: &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
1.421 raeburn 15009: &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
15010: }
15011: $resulttext = &mt('Changes made:').'<ul>';
15012: if (keys(%secchanges) > 0) {
1.423 raeburn 15013: $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
1.421 raeburn 15014: }
15015: if (keys(%ltitoolschg) > 0) {
15016: $resulttext .= $ltitoolsoutput;
15017: }
1.423 raeburn 15018: my $cachetime = 24*60*60;
15019: &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
15020: if (ref($lastactref) eq 'HASH') {
15021: $lastactref->{'ltitools'} = 1;
15022: }
1.421 raeburn 15023: } else {
15024: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15025: }
15026: if ($errors) {
15027: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15028: $errors.'</ul></p>';
15029: }
15030: return $resulttext;
15031: }
15032:
15033: sub fetch_secrets {
15034: my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
15035: my %keyset;
15036: %{$currsec} = ();
15037: $newsec->{'private'}{'keys'} = [];
15038: $newsec->{'encrypt'} = {};
15039: $newsec->{'rules'} = {};
15040: if ($context eq 'ltisec') {
15041: $newsec->{'linkprot'} = {};
15042: }
15043: if (ref($domconfig->{$context}) eq 'HASH') {
15044: %{$currsec} = %{$domconfig->{$context}};
15045: if ($context eq 'ltisec') {
15046: if (ref($currsec->{'linkprot'}) eq 'HASH') {
15047: foreach my $id (keys(%{$currsec->{'linkprot'}})) {
15048: unless ($id =~ /^\d+$/) {
15049: delete($currsec->{'linkprot'}{$id});
1.297 raeburn 15050: }
1.267 raeburn 15051: }
15052: }
1.421 raeburn 15053: }
15054: if (ref($currsec->{'private'}) eq 'HASH') {
15055: if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
15056: $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
15057: map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1.267 raeburn 15058: }
1.421 raeburn 15059: }
15060: }
15061: my @items= ('crs','dom');
15062: if ($context eq 'ltisec') {
15063: push(@items,'consumers');
15064: }
15065: foreach my $item (@items) {
15066: my $formelement;
15067: if (($context eq 'toolsec') || ($item eq 'consumers')) {
15068: $formelement = 'form.'.$context.'_'.$item;
15069: } else {
15070: $formelement = 'form.'.$context.'_'.$item.'linkprot';
15071: }
15072: if ($env{$formelement}) {
15073: $newsec->{'encrypt'}{$item} = 1;
15074: if (ref($currsec->{'encrypt'}) eq 'HASH') {
15075: unless ($currsec->{'encrypt'}{$item}) {
15076: $secchanges->{'encrypt'} = 1;
15077: }
15078: } else {
15079: $secchanges->{'encrypt'} = 1;
1.267 raeburn 15080: }
1.421 raeburn 15081: } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
15082: if ($currsec->{'encrypt'}{$item}) {
15083: $secchanges->{'encrypt'} = 1;
1.323 raeburn 15084: }
1.421 raeburn 15085: }
15086: }
15087: my $secrets;
15088: if ($context eq 'ltisec') {
15089: $secrets = 'ltisecrets';
15090: } else {
15091: $secrets = 'toolsecrets';
15092: }
15093: unless (exists($currsec->{'rules'})) {
15094: $currsec->{'rules'} = {};
15095: }
15096: &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
15097:
15098: my @ids=&Apache::lonnet::current_machine_ids();
15099: my %servers = &Apache::lonnet::get_servers($dom,'library');
15100:
15101: foreach my $hostid (keys(%servers)) {
15102: if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
15103: my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
15104: if (exists($env{$keyitem})) {
15105: $env{$keyitem} =~ s/(`)/'/g;
15106: if ($keyset{$hostid}) {
15107: if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
15108: if ($env{$keyitem} ne '') {
15109: $secchanges->{'private'} = 1;
15110: $newkeyset->{$hostid} = $env{$keyitem};
15111: }
1.296 raeburn 15112: }
1.421 raeburn 15113: } elsif ($env{$keyitem} ne '') {
15114: unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
15115: push(@{$newsec->{'private'}{'keys'}},$hostid);
1.296 raeburn 15116: }
1.421 raeburn 15117: $secchanges->{'private'} = 1;
15118: $newkeyset->{$hostid} = $env{$keyitem};
1.267 raeburn 15119: }
15120: }
1.421 raeburn 15121: }
15122: }
15123: }
15124:
15125: sub store_security {
1.424 raeburn 15126: my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
1.421 raeburn 15127: return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
15128: (ref($keystore) eq 'HASH'));
15129: if (keys(%{$secchanges})) {
15130: if ($secchanges->{'private'}) {
15131: my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
15132: foreach my $hostid (keys(%{$newkeyset})) {
15133: my $storehash = {
15134: key => $newkeyset->{$hostid},
15135: who => $env{'user.name'}.':'.$env{'user.domain'},
15136: };
15137: $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
15138: $dom,$hostid);
15139: }
15140: }
15141: }
15142: }
15143:
15144: sub lti_security_results {
1.423 raeburn 15145: my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
1.421 raeburn 15146: my $output;
1.423 raeburn 15147: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
15148: my $needs_update;
1.421 raeburn 15149: foreach my $item (keys(%{$secchanges})) {
15150: if ($item eq 'encrypt') {
1.423 raeburn 15151: $needs_update = 1;
1.421 raeburn 15152: my %encrypted;
15153: if ($context eq 'lti') {
15154: %encrypted = (
15155: crs => {
15156: on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
15157: off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
15158: },
15159: dom => {
15160: on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
15161: off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
15162: },
15163: consumers => {
15164: on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
15165: off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
15166: },
15167: );
1.267 raeburn 15168: } else {
1.421 raeburn 15169: %encrypted = (
15170: crs => {
15171: on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
15172: off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
15173: },
15174: dom => {
15175: on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
15176: off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
15177: },
15178: );
15179: }
15180: my @types= ('crs','dom');
15181: if ($context eq 'lti') {
1.423 raeburn 15182: foreach my $type (@types) {
15183: undef($domdefaults{'linkprotenc_'.$type});
15184: }
1.421 raeburn 15185: push(@types,'consumers');
1.423 raeburn 15186: undef($domdefaults{'ltienc_consumers'});
15187: } elsif ($context eq 'ltitools') {
15188: foreach my $type (@types) {
15189: undef($domdefaults{'toolenc_'.$type});
15190: }
1.267 raeburn 15191: }
1.421 raeburn 15192: foreach my $type (@types) {
15193: my $shown = $encrypted{$type}{'off'};
15194: if (ref($newsec->{$item}) eq 'HASH') {
15195: if ($newsec->{$item}{$type}) {
1.423 raeburn 15196: if ($context eq 'lti') {
15197: if ($type eq 'consumers') {
15198: $domdefaults{'ltienc_consumers'} = 1;
15199: } else {
15200: $domdefaults{'linkprotenc_'.$type} = 1;
15201: }
15202: } elsif ($context eq 'ltitools') {
15203: $domdefaults{'toolenc_'.$type} = 1;
15204: }
1.421 raeburn 15205: $shown = $encrypted{$type}{'on'};
1.319 raeburn 15206: }
1.267 raeburn 15207: }
1.421 raeburn 15208: $output .= '<li>'.$shown.'</li>';
1.267 raeburn 15209: }
1.421 raeburn 15210: } elsif ($item eq 'rules') {
15211: my %titles = &Apache::lonlocal::texthash(
15212: min => 'Minimum password length',
15213: max => 'Maximum password length',
15214: chars => 'Required characters',
15215: );
15216: foreach my $rule ('min','max') {
15217: if ($newsec->{rules}{$rule} eq '') {
15218: if ($rule eq 'min') {
15219: $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
15220: ' '.&mt('Default of [_1] will be used',
15221: $Apache::lonnet::passwdmin).'</li>';
15222: } else {
15223: $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15224: }
15225: } else {
15226: $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
15227: }
15228: }
15229: if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
15230: if (@{$newsec->{'rules'}{'chars'}} > 0) {
15231: my %rulenames = &Apache::lonlocal::texthash(
15232: uc => 'At least one upper case letter',
15233: lc => 'At least one lower case letter',
15234: num => 'At least one number',
15235: spec => 'At least one non-alphanumeric',
15236: );
15237: my $needed = '<ul><li>'.
15238: join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
15239: '</li></ul>';
15240: $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15241: } else {
15242: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15243: }
1.421 raeburn 15244: } else {
15245: $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1.267 raeburn 15246: }
1.421 raeburn 15247: } elsif ($item eq 'private') {
1.423 raeburn 15248: $needs_update = 1;
15249: if ($context eq 'lti') {
15250: undef($domdefaults{'ltiprivhosts'});
15251: } elsif ($context eq 'ltitools') {
15252: undef($domdefaults{'toolprivhosts'});
15253: }
1.421 raeburn 15254: if (keys(%{$newkeyset})) {
1.423 raeburn 15255: my @privhosts;
1.421 raeburn 15256: foreach my $hostid (sort(keys(%{$newkeyset}))) {
15257: if ($keystore->{$hostid} eq 'ok') {
15258: $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
1.423 raeburn 15259: unless (grep(/^\Q$hostid\E$/,@privhosts)) {
15260: push(@privhosts,$hostid);
15261: }
15262: }
15263: }
15264: if (@privhosts) {
15265: if ($context eq 'lti') {
15266: $domdefaults{'ltiprivhosts'} = \@privhosts;
15267: } elsif ($context eq 'ltitools') {
15268: $domdefaults{'toolprivhosts'} = \@privhosts;
1.267 raeburn 15269: }
15270: }
15271: }
1.421 raeburn 15272: } elsif ($item eq 'linkprot') {
15273: next;
1.434 raeburn 15274: } elsif ($item eq 'suggested') {
15275: if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
15276: (ref($newsec->{'suggested'}) eq 'HASH')) {
15277: my $suggestions;
15278: foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
15279: if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
15280: my $name = $newsec->{'suggested'}->{$id}->{'name'};
15281: my $info = $newsec->{'suggested'}->{$id}->{'info'};
15282: $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
15283: &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
15284: '</li>';
15285: } else {
15286: $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
15287: $newsec->{'suggested'}->{$id}).'</li>';
15288: }
15289: }
15290: if ($suggestions) {
15291: $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
15292: '<ul>'.$suggestions.'</ul>'.
15293: '</li>';
15294: }
15295: }
1.267 raeburn 15296: }
15297: }
1.423 raeburn 15298: if ($needs_update) {
15299: my $cachetime = 24*60*60;
15300: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15301: }
1.421 raeburn 15302: return $output;
15303: }
15304:
15305: sub modify_proctoring {
15306: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15307: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15308: my (@allpos,%changes,%confhash,%encconfhash,$errors,$resulttext,%imgdeletions);
15309: my $confname = $dom.'-domainconfig';
15310: my $servadm = $r->dir_config('lonAdmEMail');
1.372 raeburn 15311: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
15312: my %providernames = &proctoring_providernames();
15313: my $maxnum = scalar(keys(%providernames));
15314:
15315: my (%requserfields,%optuserfields,%defaults,%extended,%crsconf,@courseroles,@ltiroles);
15316: my ($requref,$opturef,$defref,$extref,$crsref,$rolesref,$ltiref) = &proctoring_data();
15317: if (ref($requref) eq 'HASH') {
15318: %requserfields = %{$requref};
15319: }
15320: if (ref($opturef) eq 'HASH') {
15321: %optuserfields = %{$opturef};
15322: }
15323: if (ref($defref) eq 'HASH') {
15324: %defaults = %{$defref};
15325: }
15326: if (ref($extref) eq 'HASH') {
15327: %extended = %{$extref};
15328: }
15329: if (ref($crsref) eq 'HASH') {
15330: %crsconf = %{$crsref};
15331: }
15332: if (ref($rolesref) eq 'ARRAY') {
15333: @courseroles = @{$rolesref};
15334: }
15335: if (ref($ltiref) eq 'ARRAY') {
15336: @ltiroles = @{$ltiref};
15337: }
15338:
15339: if (ref($domconfig{$action}) eq 'HASH') {
15340: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.proctoring_image_del');
15341: if (@todeleteimages) {
15342: map { $imgdeletions{$_} = 1; } @todeleteimages;
15343: }
15344: }
15345: my %customadds;
15346: my @newcustom = &Apache::loncommon::get_env_multiple('form.proctoring_customadd');
15347: if (@newcustom) {
15348: map { $customadds{$_} = 1; } @newcustom;
15349: }
15350: foreach my $provider (sort(keys(%providernames))) {
15351: $confhash{$provider} = {};
15352: my $pos = $env{'form.proctoring_pos_'.$provider};
15353: $pos =~ s/\D+//g;
15354: $allpos[$pos] = $provider;
15355: my (%current,%currentenc);
15356: my $showroles = 0;
15357: if (ref($domconfig{$action}) eq 'HASH') {
15358: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15359: %current = %{$domconfig{$action}{$provider}};
15360: foreach my $item ('key','secret') {
15361: $currentenc{$item} = $current{$item};
15362: delete($current{$item});
15363: }
15364: }
15365: }
15366: if ($env{'form.proctoring_available_'.$provider}) {
15367: $confhash{$provider}{'available'} = 1;
15368: unless ($current{'available'}) {
15369: $changes{$provider} = 1;
15370: }
15371: } else {
15372: %{$confhash{$provider}} = %current;
15373: %{$encconfhash{$provider}} = %currentenc;
15374: $confhash{$provider}{'available'} = 0;
15375: if ($current{'available'}) {
15376: $changes{$provider} = 1;
15377: }
15378: }
15379: if ($confhash{$provider}{'available'}) {
15380: foreach my $field ('lifetime','version','sigmethod','url','key','secret') {
15381: my $possval = $env{'form.proctoring_'.$provider.'_'.$field};
15382: if ($field eq 'lifetime') {
15383: if ($possval =~ /^\d+$/) {
15384: $confhash{$provider}{$field} = $possval;
15385: }
15386: } elsif ($field eq 'version') {
15387: if ($possval =~ /^\d+\.\d+$/) {
15388: $confhash{$provider}{$field} = $possval;
15389: }
15390: } elsif ($field eq 'sigmethod') {
15391: if ($possval =~ /^\QHMAC-SHA\E(1|256)$/) {
15392: $confhash{$provider}{$field} = $possval;
15393: }
15394: } elsif ($field eq 'url') {
15395: $confhash{$provider}{$field} = $possval;
15396: } elsif (($field eq 'key') || ($field eq 'secret')) {
15397: $encconfhash{$provider}{$field} = $possval;
15398: unless ($currentenc{$field} eq $possval) {
15399: $changes{$provider} = 1;
15400: }
15401: }
15402: unless (($field eq 'key') || ($field eq 'secret')) {
15403: unless ($current{$field} eq $confhash{$provider}{$field}) {
15404: $changes{$provider} = 1;
15405: }
15406: }
15407: }
15408: if ($imgdeletions{$provider}) {
15409: $changes{$provider} = 1;
15410: } elsif ($env{'form.proctoring_image_'.$provider.'.filename'} ne '') {
15411: my ($imageurl,$error) =
15412: &process_proctoring_image($r,$dom,$confname,'proctoring_image_'.$provider,$provider,
15413: $configuserok,$switchserver,$author_ok);
15414: if ($imageurl) {
15415: $confhash{$provider}{'image'} = $imageurl;
15416: $changes{$provider} = 1;
15417: }
15418: if ($error) {
15419: &Apache::lonnet::logthis($error);
15420: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15421: }
15422: } elsif (exists($current{'image'})) {
15423: $confhash{$provider}{'image'} = $current{'image'};
15424: }
15425: if (ref($requserfields{$provider}) eq 'ARRAY') {
15426: if (@{$requserfields{$provider}} > 0) {
15427: if (grep(/^user$/,@{$requserfields{$provider}})) {
15428: if ($env{'form.proctoring_userincdom_'.$provider}) {
15429: $confhash{$provider}{'incdom'} = 1;
15430: }
15431: unless ($current{'incdom'} eq $confhash{$provider}{'incdom'}) {
15432: $changes{$provider} = 1;
15433: }
15434: }
15435: if (grep(/^roles$/,@{$requserfields{$provider}})) {
15436: $showroles = 1;
15437: }
15438: }
15439: }
15440: $confhash{$provider}{'fields'} = [];
15441: if (ref($optuserfields{$provider}) eq 'ARRAY') {
15442: if (@{$optuserfields{$provider}} > 0) {
15443: my @optfields = &Apache::loncommon::get_env_multiple('form.proctoring_optional_'.$provider);
15444: foreach my $field (@{$optuserfields{$provider}}) {
15445: if (grep(/^\Q$field\E$/,@optfields)) {
15446: push(@{$confhash{$provider}{'fields'}},$field);
15447: }
15448: }
15449: }
15450: if (ref($current{'fields'}) eq 'ARRAY') {
15451: unless ($changes{$provider}) {
15452: my @new = sort(@{$confhash{$provider}{'fields'}});
15453: my @old = sort(@{$current{'fields'}});
15454: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15455: if (@diffs) {
15456: $changes{$provider} = 1;
15457: }
15458: }
15459: } elsif (@{$confhash{$provider}{'fields'}}) {
15460: $changes{$provider} = 1;
15461: }
15462: }
15463: if (ref($defaults{$provider}) eq 'ARRAY') {
15464: if (@{$defaults{$provider}} > 0) {
15465: my %options;
15466: if (ref($extended{$provider}) eq 'HASH') {
15467: %options = %{$extended{$provider}};
15468: }
15469: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_defaults_'.$provider);
15470: foreach my $field (@{$defaults{$provider}}) {
15471: if ((exists($options{$field})) && (ref($options{$field}) eq 'ARRAY')) {
15472: my $poss = $env{'form.proctoring_defaults_'.$field.'_'.$provider};
15473: if (grep(/^\Q$poss\E$/,@{$options{$field}})) {
15474: push(@{$confhash{$provider}{'defaults'}},$poss);
15475: }
15476: } elsif ((exists($options{$field})) && (ref($options{$field}) eq 'HASH')) {
15477: foreach my $inner (keys(%{$options{$field}})) {
15478: if (ref($options{$field}{$inner}) eq 'ARRAY') {
15479: my $poss = $env{'form.proctoring_'.$inner.'_'.$provider};
15480: if (grep(/^\Q$poss\E$/,@{$options{$field}{$inner}})) {
15481: $confhash{$provider}{'defaults'}{$inner} = $poss;
15482: }
15483: } else {
15484: $confhash{$provider}{'defaults'}{$inner} = $env{'form.proctoring_'.$inner.'_'.$provider};
15485: }
15486: }
15487: } else {
15488: if (grep(/^\Q$field\E$/,@checked)) {
15489: push(@{$confhash{$provider}{'defaults'}},$field);
15490: }
15491: }
15492: }
15493: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15494: if (ref($current{'defaults'}) eq 'ARRAY') {
15495: unless ($changes{$provider}) {
15496: my @new = sort(@{$confhash{$provider}{'defaults'}});
15497: my @old = sort(@{$current{'defaults'}});
15498: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15499: if (@diffs) {
15500: $changes{$provider} = 1;
15501: }
15502: }
15503: } elsif (ref($current{'defaults'}) eq 'ARRAY') {
15504: if (@{$current{'defaults'}}) {
15505: $changes{$provider} = 1;
15506: }
15507: }
15508: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15509: if (ref($current{'defaults'}) eq 'HASH') {
15510: unless ($changes{$provider}) {
15511: foreach my $key (keys(%{$confhash{$provider}{'defaults'}})) {
15512: unless ($confhash{$provider}{'defaults'}{$key} eq $current{'defaults'}{$key}) {
15513: $changes{$provider} = 1;
15514: last;
15515: }
15516: }
15517: }
15518: unless ($changes{$provider}) {
15519: foreach my $key (keys(%{$current{'defaults'}})) {
15520: unless ($current{'defaults'}{$key} eq $confhash{$provider}{'defaults'}{$key}) {
15521: $changes{$provider} = 1;
15522: last;
15523: }
15524: }
15525: }
15526: } elsif (keys(%{$confhash{$provider}{'defaults'}})) {
15527: $changes{$provider} = 1;
15528: }
15529: }
15530: }
15531: }
15532: if (ref($crsconf{$provider}) eq 'ARRAY') {
15533: if (@{$crsconf{$provider}} > 0) {
15534: $confhash{$provider}{'crsconf'} = [];
15535: my @checked = &Apache::loncommon::get_env_multiple('form.proctoring_crsconf_'.$provider);
15536: foreach my $crsfield (@{$crsconf{$provider}}) {
15537: if (grep(/^\Q$crsfield\E$/,@checked)) {
15538: push(@{$confhash{$provider}{'crsconf'}},$crsfield);
15539: }
15540: }
15541: if (ref($current{'crsconf'}) eq 'ARRAY') {
15542: unless ($changes{$provider}) {
15543: my @new = sort(@{$confhash{$provider}{'crsconf'}});
15544: my @old = sort(@{$current{'crsconf'}});
15545: my @diffs = &Apache::loncommon::compare_arrays(\@new,\@old);
15546: if (@diffs) {
15547: $changes{$provider} = 1;
15548: }
15549: }
15550: } elsif (@{$confhash{$provider}{'crsconf'}}) {
15551: $changes{$provider} = 1;
15552: }
15553: }
15554: }
15555: if ($showroles) {
15556: $confhash{$provider}{'roles'} = {};
15557: foreach my $role (@courseroles) {
15558: my $poss = $env{'form.proctoring_roles_'.$role.'_'.$provider};
15559: if (grep(/^\Q$poss\E$/,@ltiroles)) {
15560: $confhash{$provider}{'roles'}{$role} = $poss;
15561: }
15562: }
15563: unless ($changes{$provider}) {
15564: if (ref($current{'roles'}) eq 'HASH') {
15565: foreach my $role (keys(%{$current{'roles'}})) {
15566: unless ($current{'roles'}{$role} eq $confhash{$provider}{'roles'}{$role}) {
15567: $changes{$provider} = 1;
15568: last
15569: }
15570: }
15571: unless ($changes{$provider}) {
15572: foreach my $role (keys(%{$confhash{$provider}{'roles'}})) {
15573: unless ($confhash{$provider}{'roles'}{$role} eq $current{'roles'}{$role}) {
15574: $changes{$provider} = 1;
15575: last;
15576: }
15577: }
15578: }
15579: } elsif (keys(%{$confhash{$provider}{'roles'}})) {
15580: $changes{$provider} = 1;
15581: }
15582: }
15583: }
15584: if (ref($current{'custom'}) eq 'HASH') {
15585: my @customdels = &Apache::loncommon::get_env_multiple('form.proctoring_customdel_'.$provider);
15586: foreach my $key (keys(%{$current{'custom'}})) {
15587: if (grep(/^\Q$key\E$/,@customdels)) {
15588: $changes{$provider} = 1;
15589: } else {
15590: $confhash{$provider}{'custom'}{$key} = $env{'form.proctoring_customval_'.$key.'_'.$provider};
15591: if ($confhash{$provider}{'custom'}{$key} ne $current{'custom'}{$key}) {
15592: $changes{$provider} = 1;
15593: }
15594: }
15595: }
15596: }
15597: if ($customadds{$provider}) {
15598: my $name = $env{'form.proctoring_custom_name_'.$provider};
15599: $name =~ s/(`)/'/g;
15600: $name =~ s/^\s+//;
15601: $name =~ s/\s+$//;
15602: my $value = $env{'form.proctoring_custom_value_'.$provider};
15603: $value =~ s/(`)/'/g;
15604: $value =~ s/^\s+//;
15605: $value =~ s/\s+$//;
15606: if ($name ne '') {
15607: $confhash{$provider}{'custom'}{$name} = $value;
15608: $changes{$provider} = 1;
15609: }
15610: }
15611: }
15612: }
15613: if (@allpos > 0) {
15614: my $idx = 0;
15615: foreach my $provider (@allpos) {
15616: if ($provider ne '') {
15617: $confhash{$provider}{'order'} = $idx;
15618: unless ($changes{$provider}) {
15619: if (ref($domconfig{$action}) eq 'HASH') {
15620: if (ref($domconfig{$action}{$provider}) eq 'HASH') {
15621: if ($domconfig{$action}{$provider}{'order'} ne $idx) {
15622: $changes{$provider} = 1;
15623: }
15624: }
15625: }
15626: }
15627: $idx ++;
15628: }
15629: }
15630: }
15631: my %proc_hash = (
15632: $action => { %confhash }
15633: );
15634: my $putresult = &Apache::lonnet::put_dom('configuration',\%proc_hash,
15635: $dom);
15636: if ($putresult eq 'ok') {
15637: my %proc_enchash = (
15638: $action => { %encconfhash }
15639: );
1.384 raeburn 15640: &Apache::lonnet::put_dom('encconfig',\%proc_enchash,$dom,undef,1);
1.372 raeburn 15641: if (keys(%changes) > 0) {
15642: my $cachetime = 24*60*60;
15643: my %procall = %confhash;
15644: foreach my $provider (keys(%procall)) {
15645: if (ref($encconfhash{$provider}) eq 'HASH') {
15646: foreach my $key ('key','secret') {
15647: $procall{$provider}{$key} = $encconfhash{$provider}{$key};
15648: }
15649: }
15650: }
15651: &Apache::lonnet::do_cache_new('proctoring',$dom,\%procall,$cachetime);
15652: if (ref($lastactref) eq 'HASH') {
15653: $lastactref->{'proctoring'} = 1;
15654: }
15655: $resulttext = &mt('Configuration for Provider(s) with changes:').'<ul>';
15656: my %bynum;
15657: foreach my $provider (sort(keys(%changes))) {
15658: my $position = $confhash{$provider}{'order'};
15659: $bynum{$position} = $provider;
15660: }
15661: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
15662: my $provider = $bynum{$pos};
15663: my %lt = &proctoring_titles($provider);
15664: my %fieldtitles = &proctoring_fieldtitles($provider);
15665: if (!$confhash{$provider}{'available'}) {
15666: $resulttext .= '<li>'.&mt('Proctoring integration unavailable for: [_1]','<b>'.$providernames{$provider}.'</b>').'</li>';
15667: } else {
15668: $resulttext .= '<li>'.&mt('Proctoring integration available for: [_1]','<b>'.$providernames{$provider}.'</b>');
15669: if ($confhash{$provider}{'image'}) {
15670: $resulttext .= ' '.
15671: '<img src="'.$confhash{$provider}{'image'}.'"'.
15672: ' alt="'.&mt('Proctoring icon').'" />';
15673: }
15674: $resulttext .= '<ul>';
15675: my $position = $pos + 1;
15676: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
15677: foreach my $key ('version','sigmethod','url','lifetime') {
15678: if ($confhash{$provider}{$key} ne '') {
15679: $resulttext .= '<li>'.$lt{$key}.': '.$confhash{$provider}{$key}.'</li>';
15680: }
15681: }
15682: if ($encconfhash{$provider}{'key'} ne '') {
15683: $resulttext .= '<li>'.$lt{'key'}.': '.$encconfhash{$provider}{'key'}.'</li>';
15684: }
15685: if ($encconfhash{$provider}{'secret'} ne '') {
15686: $resulttext .= '<li>'.$lt{'secret'}.': ';
15687: my $num = length($encconfhash{$provider}{'secret'});
15688: $resulttext .= ('*'x$num).'</li>';
15689: }
15690: my (@fields,$showroles);
15691: if (ref($requserfields{$provider}) eq 'ARRAY') {
15692: push(@fields,@{$requserfields{$provider}});
15693: }
15694: if (ref($confhash{$provider}{'fields'}) eq 'ARRAY') {
15695: push(@fields,@{$confhash{$provider}{'fields'}});
15696: } elsif (ref($confhash{$provider}{'fields'}) eq 'HASH') {
15697: push(@fields,(keys(%{$confhash{$provider}{'fields'}})));
15698: }
15699: if (@fields) {
15700: if (grep(/^roles$/,@fields)) {
15701: $showroles = 1;
15702: }
15703: $resulttext .= '<li>'.$lt{'udsl'}.': "'.
15704: join('", "', map { $lt{$_}; } @fields).'"</li>';
15705: }
15706: if (ref($requserfields{$provider}) eq 'ARRAY') {
15707: if (grep(/^user$/,@{$requserfields{$provider}})) {
15708: if ($confhash{$provider}{'incdom'}) {
15709: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'uname:dom'}).'</li>';
15710: } else {
15711: $resulttext .= '<li>'.&mt('[_1] sent as [_2]',$lt{'user'},$lt{'username'}).'</li>';
15712: }
15713: }
15714: }
15715: if (ref($confhash{$provider}{'defaults'}) eq 'ARRAY') {
15716: if (@{$confhash{$provider}{'defaults'}} > 0) {
15717: $resulttext .= '<li>'.$lt{'defa'};
15718: foreach my $field (@{$confhash{$provider}{'defaults'}}) {
15719: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15720: }
15721: $resulttext =~ s/,$//;
15722: $resulttext .= '</li>';
15723: }
15724: } elsif (ref($confhash{$provider}{'defaults'}) eq 'HASH') {
15725: if (keys(%{$confhash{$provider}{'defaults'}})) {
15726: $resulttext .= '<li>'.$lt{'defa'}.': <ul>';
15727: foreach my $key (sort(keys(%{$confhash{$provider}{'defaults'}}))) {
15728: if ($confhash{$provider}{'defaults'}{$key} ne '') {
15729: $resulttext .= '<li>'.$fieldtitles{$key}.' = '.$confhash{$provider}{'defaults'}{$key}.'</li>';
15730: }
15731: }
15732: $resulttext .= '</ul></li>';
15733: }
15734: }
15735: if (ref($crsconf{$provider}) eq 'ARRAY') {
15736: if (@{$crsconf{$provider}} > 0) {
15737: $resulttext .= '<li>'.&mt('Configurable in course:');
15738: my $numconfig = 0;
15739: if (ref($confhash{$provider}{'crsconf'}) eq 'ARRAY') {
15740: if (@{$confhash{$provider}{'crsconf'}} > 0) {
15741: foreach my $field (@{$confhash{$provider}{'crsconf'}}) {
15742: $numconfig ++;
15743: if ($provider eq 'examity') {
15744: $resulttext .= ' "'.$lt{'crs'.$field}.'",';
15745: } else {
15746: $resulttext .= ' "'.$fieldtitles{$field}.'",';
15747: }
15748: }
15749: $resulttext =~ s/,$//;
15750: }
15751: }
15752: if (!$numconfig) {
15753: $resulttext .= ' '.&mt('None');
15754: }
15755: $resulttext .= '</li>';
15756: }
15757: }
15758: if ($showroles) {
15759: if (ref($confhash{$provider}{'roles'}) eq 'HASH') {
15760: my $rolemaps;
15761: foreach my $role (@courseroles) {
15762: if ($confhash{$provider}{'roles'}{$role}) {
15763: $rolemaps .= (' 'x2).&Apache::lonnet::plaintext($role,'Course').'='.
15764: $confhash{$provider}{'roles'}{$role}.',';
15765: }
15766: }
15767: if ($rolemaps) {
15768: $rolemaps =~ s/,$//;
15769: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
15770: }
15771: }
15772: }
15773: if (ref($confhash{$provider}{'custom'}) eq 'HASH') {
15774: my $customlist;
15775: if (keys(%{$confhash{$provider}{'custom'}})) {
15776: foreach my $key (sort(keys(%{$confhash{$provider}{'custom'}}))) {
15777: $customlist .= $key.'='.$confhash{$provider}{'custom'}{$key}.', ';
15778: }
15779: $customlist =~ s/,$//;
15780: }
15781: if ($customlist) {
15782: $resulttext .= '<li>'.&mt('Custom items').': '.$customlist.'</li>';
15783: }
15784: }
15785: $resulttext .= '</ul></li>';
15786: }
15787: }
15788: $resulttext .= '</ul>';
15789: } else {
15790: $resulttext = &mt('No changes made.');
15791: }
15792: } else {
15793: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
15794: }
15795: if ($errors) {
15796: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
15797: $errors.'</ul>';
15798: }
15799: return $resulttext;
15800: }
15801:
15802: sub process_proctoring_image {
15803: my ($r,$dom,$confname,$caller,$provider,$configuserok,$switchserver,$author_ok) = @_;
15804: my $filename = $env{'form.'.$caller.'.filename'};
15805: my ($error,$url);
15806: my ($width,$height) = (21,21);
15807: if ($configuserok eq 'ok') {
15808: if ($switchserver) {
15809: $error = &mt('Upload of Remote Proctoring Provider icon is not permitted to this server: [_1]',
15810: $switchserver);
15811: } elsif ($author_ok eq 'ok') {
1.421 raeburn 15812: my $modified = [];
1.372 raeburn 15813: my ($result,$imageurl,$madethumb) =
1.421 raeburn 15814: &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
15815: "proctoring/$provider/icon",$width,$height,
15816: '',$modified);
1.372 raeburn 15817: if ($result eq 'ok') {
15818: if ($madethumb) {
15819: my ($path,$imagefile) = ($imageurl =~ m{^(.+)/([^/]+)$});
15820: my $imagethumb = "$path/tn-".$imagefile;
15821: $url = $imagethumb;
15822: } else {
15823: $url = $imageurl;
15824: }
1.421 raeburn 15825: &update_modify_urls($r,$modified);
1.372 raeburn 15826: } else {
15827: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
15828: }
15829: } else {
15830: $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);
15831: }
15832: } else {
15833: $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);
15834: }
15835: return ($url,$error);
15836: }
15837:
1.320 raeburn 15838: sub modify_lti {
15839: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
15840: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 15841: my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
1.320 raeburn 15842: my (%posslti,%posslticrs,%posscrstype);
15843: my @courseroles = ('cc','in','ta','ep','st');
15844: my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
15845: my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
1.392 raeburn 15846: my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
1.320 raeburn 15847: my %coursetypetitles = &Apache::lonlocal::texthash (
15848: official => 'Official',
15849: unofficial => 'Unofficial',
15850: community => 'Community',
15851: textbook => 'Textbook',
15852: placement => 'Placement Test',
1.392 raeburn 15853: lti => 'LTI Provider',
1.320 raeburn 15854: );
1.325 raeburn 15855: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.320 raeburn 15856: my %lt = <i_names();
15857: map { $posslti{$_} = 1; } @ltiroles;
15858: map { $posslticrs{$_} = 1; } @lticourseroles;
15859: map { $posscrstype{$_} = 1; } @coursetypes;
1.325 raeburn 15860:
1.326 raeburn 15861: my %menutitles = <imenu_titles();
1.421 raeburn 15862: my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
1.326 raeburn 15863:
1.421 raeburn 15864: &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
1.405 raeburn 15865:
1.406 raeburn 15866: my (%linkprotchg,$linkprotoutput,$is_home);
15867: my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
15868: \%linkprotchg,'domain');
15869: my $home = &Apache::lonnet::domain($dom,'primary');
15870: unless (($home eq 'no_host') || ($home eq '')) {
15871: my @ids=&Apache::lonnet::current_machine_ids();
15872: foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
15873: }
15874:
15875: if (keys(%linkprotchg)) {
15876: $secchanges{'linkprot'} = 1;
15877: my %oldlinkprot;
15878: if (ref($currltisec{'linkprot'}) eq 'HASH') {
15879: %oldlinkprot = %{$currltisec{'linkprot'}};
15880: }
15881: foreach my $id (keys(%linkprotchg)) {
15882: if (ref($linkprotchg{$id}) eq 'HASH') {
15883: foreach my $inner (keys(%{$linkprotchg{$id}})) {
15884: if (($inner eq 'secret') || ($inner eq 'key')) {
15885: if ($is_home) {
15886: $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
15887: }
15888: }
15889: }
15890: } else {
15891: $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
15892: }
15893: }
15894: $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
15895: if (keys(%linkprotchg)) {
15896: %{$newltisec{'linkprot'}} = %linkprotchg;
15897: }
15898: }
15899: if (ref($currltisec{'linkprot'}) eq 'HASH') {
1.434 raeburn 15900: foreach my $id (keys(%{$currltisec{'linkprot'}})) {
1.406 raeburn 15901: next if ($id !~ /^\d+$/);
15902: unless (exists($linkprotchg{$id})) {
15903: if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
15904: foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
15905: if (($inner eq 'secret') || ($inner eq 'key')) {
15906: if ($is_home) {
15907: $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15908: }
15909: } else {
15910: $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
15911: }
15912: }
15913: } else {
15914: $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
15915: }
15916: }
15917: }
15918: }
15919: if ($proterror) {
15920: $errors .= '<li>'.$proterror.'</li>';
15921: }
1.434 raeburn 15922:
15923: my (%delsuggested,%suggids,@suggested);;
15924: if (ref($currltisec{'suggested'}) eq 'HASH') {
15925: my $maxnum = $env{'form.linkprot_suggested_maxnum'};
15926: my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
15927: for (my $i=0; $i<$maxnum; $i++) {
15928: my $itemid = $env{'form.linkprot_suggested_id_'.$i};
15929: $itemid =~ s/\D+//g;
15930: if ($itemid) {
15931: if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
15932: push(@suggested,$i);
15933: $suggids{$i} = $itemid;
15934: if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
15935: if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
15936: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15937: }
15938: } else {
15939: if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
15940: $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
15941: } else {
15942: $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
15943: $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
15944: $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
15945: $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
15946: if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
15947: ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
15948: $secchanges{'suggested'}{$itemid} = 1;
15949: }
15950: }
15951: }
15952: }
15953: }
15954: }
15955: }
15956: foreach my $key (keys(%delsuggested)) {
15957: $newltisec{'suggested'}{$key} = $delsuggested{$key};
15958: $secchanges{'suggested'}{$key} = 1;
15959: }
15960: if (($env{'form.linkprot_suggested_add'}) &&
15961: ($env{'form.linkprot_suggested_name_add'} ne '')) {
15962: $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
15963: $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
15964: my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
15965: if ($newsuggid) {
15966: $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
15967: $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
15968: $secchanges{'suggested'}{$newsuggid} = 1;
15969: } else {
15970: my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
15971: if ($errormsg) {
15972: $error .= ' ('.$errormsg.')';
15973: }
15974: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15975: }
15976: }
1.320 raeburn 15977: my (@items,%deletions,%itemids);
15978: if ($env{'form.lti_add'}) {
15979: my $consumer = $env{'form.lti_consumer_add'};
15980: $consumer =~ s/(`)/'/g;
1.434 raeburn 15981: ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
1.320 raeburn 15982: if ($newid) {
15983: $itemids{'add'} = $newid;
15984: push(@items,'add');
15985: $changes{$newid} = 1;
15986: } else {
15987: my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1.434 raeburn 15988: if ($errormsg) {
15989: $error .= ' ('.$errormsg.')';
15990: }
1.320 raeburn 15991: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15992: }
15993: }
15994: if (ref($domconfig{$action}) eq 'HASH') {
15995: my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
15996: if (@todelete) {
15997: map { $deletions{$_} = 1; } @todelete;
15998: }
15999: my $maxnum = $env{'form.lti_maxnum'};
1.390 raeburn 16000: for (my $i=0; $i<$maxnum; $i++) {
1.320 raeburn 16001: my $itemid = $env{'form.lti_id_'.$i};
16002: $itemid =~ s/\D+//g;
16003: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16004: if ($deletions{$itemid}) {
16005: $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
16006: } else {
1.390 raeburn 16007: push(@items,$i);
16008: $itemids{$i} = $itemid;
1.320 raeburn 16009: }
16010: }
16011: }
16012: }
1.424 raeburn 16013: my (%keystore,$secstored);
16014: if ($is_home) {
16015: &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
16016: }
16017:
16018: my ($cipher,$privnum);
16019: if ((@items > 0) && ($is_home)) {
16020: ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
16021: $newltisec{'encrypt'},$keystore{$home});
16022: }
1.320 raeburn 16023: foreach my $idx (@items) {
16024: my $itemid = $itemids{$idx};
16025: next unless ($itemid);
1.424 raeburn 16026: my %currlti;
16027: unless ($idx eq 'add') {
16028: if (ref($domconfig{$action}) eq 'HASH') {
16029: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16030: %currlti = %{$domconfig{$action}{$itemid}};
16031: }
16032: }
16033: }
1.390 raeburn 16034: my $position = $env{'form.lti_pos_'.$itemid};
1.320 raeburn 16035: $position =~ s/\D+//g;
16036: if ($position ne '') {
16037: $allpos[$position] = $itemid;
16038: }
1.424 raeburn 16039: foreach my $item ('consumer','lifetime','requser','crsinc') {
1.320 raeburn 16040: my $formitem = 'form.lti_'.$item.'_'.$idx;
16041: $env{$formitem} =~ s/(`)/'/g;
16042: if ($item eq 'lifetime') {
16043: $env{$formitem} =~ s/[^\d.]//g;
16044: }
16045: if ($env{$formitem} ne '') {
1.424 raeburn 16046: $confhash{$itemid}{$item} = $env{$formitem};
16047: unless (($idx eq 'add') || ($changes{$itemid})) {
16048: if ($currlti{$item} ne $confhash{$itemid}{$item}) {
16049: $changes{$itemid} = 1;
1.320 raeburn 16050: }
16051: }
16052: }
16053: }
16054: if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
16055: $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
16056: }
1.345 raeburn 16057: if ($confhash{$itemid}{'requser'}) {
16058: if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
1.405 raeburn 16059: $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
1.345 raeburn 16060: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
16061: $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
16062: } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
16063: my $mapuser = $env{'form.lti_customuser_'.$idx};
16064: $mapuser =~ s/(`)/'/g;
1.405 raeburn 16065: $mapuser =~ s/^\s+|\s+$//g;
16066: $confhash{$itemid}{'mapuser'} = $mapuser;
1.345 raeburn 16067: }
16068: my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
16069: my @makeuser;
16070: foreach my $ltirole (sort(@possmakeuser)) {
16071: if ($posslti{$ltirole}) {
16072: push(@makeuser,$ltirole);
16073: }
16074: }
16075: $confhash{$itemid}{'makeuser'} = \@makeuser;
16076: if (@makeuser) {
16077: my $lcauth = $env{'form.lti_lcauth_'.$idx};
16078: if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
16079: $confhash{$itemid}{'lcauth'} = $lcauth;
16080: if ($lcauth ne 'internal') {
16081: my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
16082: $lcauthparm =~ s/^(\s+|\s+)$//g;
16083: $lcauthparm =~ s/`//g;
16084: if ($lcauthparm ne '') {
16085: $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
16086: }
16087: }
16088: } else {
16089: $confhash{$itemid}{'lcauth'} = 'lti';
16090: }
1.320 raeburn 16091: }
1.345 raeburn 16092: my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
16093: if (@possinstdata) {
1.449 ! raeburn 16094: foreach my $field (sort(@possinstdata)) {
1.345 raeburn 16095: if (exists($fieldtitles{$field})) {
1.449 ! raeburn 16096: push(@{$confhash{$itemid}{'instdata'}},$field);
1.325 raeburn 16097: }
16098: }
16099: }
1.363 raeburn 16100: if ($env{'form.lti_callback_'.$idx}) {
16101: if ($env{'form.lti_callbackparam_'.$idx}) {
16102: my $callback = $env{'form.lti_callbackparam_'.$idx};
16103: $callback =~ s/^\s+|\s+$//g;
16104: $confhash{$itemid}{'callback'} = $callback;
16105: }
16106: }
1.391 raeburn 16107: foreach my $field ('topmenu','inlinemenu') {
1.345 raeburn 16108: if ($env{'form.lti_'.$field.'_'.$idx}) {
16109: $confhash{$itemid}{$field} = 1;
16110: }
1.320 raeburn 16111: }
1.345 raeburn 16112: if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
16113: $confhash{$itemid}{lcmenu} = [];
16114: my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
16115: foreach my $field (@possmenu) {
16116: if (exists($menutitles{$field})) {
16117: if ($field eq 'grades') {
16118: next unless ($env{'form.lti_inlinemenu_'.$idx});
16119: }
16120: push(@{$confhash{$itemid}{lcmenu}},$field);
1.326 raeburn 16121: }
16122: }
16123: }
1.391 raeburn 16124: if ($confhash{$itemid}{'crsinc'}) {
16125: if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
16126: ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
16127: $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
16128: } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
16129: my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
16130: $mapcrs =~ s/(`)/'/g;
16131: $mapcrs =~ s/^\s+|\s+$//g;
16132: $confhash{$itemid}{'mapcrs'} = $mapcrs;
16133: }
16134: my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
16135: my @crstypes;
16136: foreach my $type (sort(@posstypes)) {
16137: if ($posscrstype{$type}) {
16138: push(@crstypes,$type);
16139: }
16140: }
16141: $confhash{$itemid}{'mapcrstype'} = \@crstypes;
1.392 raeburn 16142: if ($env{'form.lti_storecrs_'.$idx}) {
16143: $confhash{$itemid}{'storecrs'} = 1;
16144: }
1.391 raeburn 16145: if ($env{'form.lti_makecrs_'.$idx}) {
16146: $confhash{$itemid}{'makecrs'} = 1;
16147: }
16148: foreach my $ltirole (@lticourseroles) {
16149: my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
16150: if (grep(/^\Q$possrole\E$/,@courseroles)) {
16151: $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
16152: }
16153: }
16154: my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
16155: my @selfenroll;
16156: foreach my $type (sort(@possenroll)) {
16157: if ($posslticrs{$type}) {
16158: push(@selfenroll,$type);
16159: }
16160: }
16161: $confhash{$itemid}{'selfenroll'} = \@selfenroll;
16162: if ($env{'form.lti_crssec_'.$idx}) {
16163: if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
16164: $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
16165: } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
16166: my $section = $env{'form.lti_customsection_'.$idx};
16167: $section =~ s/(`)/'/g;
16168: $section =~ s/^\s+|\s+$//g;
16169: if ($section ne '') {
16170: $confhash{$itemid}{'section'} = $section;
16171: }
16172: }
16173: }
16174: foreach my $field ('passback','roster') {
16175: if ($env{'form.lti_'.$field.'_'.$idx}) {
16176: $confhash{$itemid}{$field} = 1;
16177: }
16178: }
16179: if ($env{'form.lti_passback_'.$idx}) {
16180: if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
16181: $confhash{$itemid}{'passbackformat'} = '1.0';
16182: } else {
16183: $confhash{$itemid}{'passbackformat'} = '1.1';
1.337 raeburn 16184: }
16185: }
1.391 raeburn 16186: }
16187: unless (($idx eq 'add') || ($changes{$itemid})) {
16188: if ($confhash{$itemid}{'crsinc'}) {
1.392 raeburn 16189: foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
1.424 raeburn 16190: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.320 raeburn 16191: $changes{$itemid} = 1;
16192: }
1.345 raeburn 16193: }
16194: unless ($changes{$itemid}) {
1.424 raeburn 16195: if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
16196: if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1.320 raeburn 16197: $changes{$itemid} = 1;
16198: }
16199: }
1.345 raeburn 16200: }
1.391 raeburn 16201: foreach my $field ('mapcrstype','selfenroll') {
16202: unless ($changes{$itemid}) {
1.424 raeburn 16203: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16204: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16205: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16206: $confhash{$itemid}{$field});
16207: if (@diffs) {
16208: $changes{$itemid} = 1;
16209: }
1.424 raeburn 16210: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16211: $changes{$itemid} = 1;
16212: }
16213: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16214: if (@{$confhash{$itemid}{$field}} > 0) {
1.320 raeburn 16215: $changes{$itemid} = 1;
16216: }
16217: }
1.391 raeburn 16218: }
16219: }
16220: unless ($changes{$itemid}) {
1.424 raeburn 16221: if (ref($currlti{'maproles'}) eq 'HASH') {
1.391 raeburn 16222: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
1.424 raeburn 16223: foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
16224: if ($currlti{'maproles'}{$ltirole} ne
1.391 raeburn 16225: $confhash{$itemid}{'maproles'}{$ltirole}) {
1.345 raeburn 16226: $changes{$itemid} = 1;
16227: last;
16228: }
16229: }
1.391 raeburn 16230: unless ($changes{$itemid}) {
16231: foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
16232: if ($confhash{$itemid}{'maproles'}{$ltirole} ne
1.424 raeburn 16233: $currlti{'maproles'}{$ltirole}) {
1.391 raeburn 16234: $changes{$itemid} = 1;
16235: last;
16236: }
16237: }
16238: }
1.424 raeburn 16239: } elsif (keys(%{$currlti{'maproles'}}) > 0) {
1.391 raeburn 16240: $changes{$itemid} = 1;
1.345 raeburn 16241: }
1.391 raeburn 16242: } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16243: unless ($changes{$itemid}) {
16244: if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
16245: $changes{$itemid} = 1;
16246: }
16247: }
16248: }
16249: }
16250: }
16251: unless ($changes{$itemid}) {
16252: foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
1.424 raeburn 16253: if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1.345 raeburn 16254: $changes{$itemid} = 1;
1.320 raeburn 16255: }
1.391 raeburn 16256: }
16257: unless ($changes{$itemid}) {
1.449 ! raeburn 16258: foreach my $field ('makeuser','lcmenu','instdata') {
1.424 raeburn 16259: if (ref($currlti{$field}) eq 'ARRAY') {
1.391 raeburn 16260: if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
1.424 raeburn 16261: my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
1.391 raeburn 16262: $confhash{$itemid}{$field});
16263: if (@diffs) {
16264: $changes{$itemid} = 1;
16265: }
1.424 raeburn 16266: } elsif (@{$currlti{$field}} > 0) {
1.391 raeburn 16267: $changes{$itemid} = 1;
16268: }
16269: } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
16270: if (@{$confhash{$itemid}{$field}} > 0) {
16271: $changes{$itemid} = 1;
16272: }
1.345 raeburn 16273: }
1.320 raeburn 16274: }
16275: }
16276: }
16277: }
16278: }
1.424 raeburn 16279: if ($is_home) {
16280: my $keyitem = 'form.lti_key_'.$idx;
16281: $env{$keyitem} =~ s/(`)/'/g;
16282: if ($env{$keyitem} ne '') {
16283: $ltienc{$itemid}{'key'} = $env{$keyitem};
16284: unless ($changes{$itemid}) {
16285: if ($currlti{'key'} ne $env{$keyitem}) {
16286: $changes{$itemid} = 1;
16287: }
16288: }
16289: }
16290: my $secretitem = 'form.lti_secret_'.$idx;
16291: $env{$secretitem} =~ s/(`)/'/g;
16292: if ($currlti{'usable'}) {
16293: if ($env{'form.lti_changesecret_'.$idx}) {
16294: if ($env{$secretitem} ne '') {
16295: if ($privnum && $cipher) {
16296: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16297: $confhash{$itemid}{'cipher'} = $privnum;
16298: } else {
16299: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16300: }
16301: $changes{$itemid} = 1;
16302: }
16303: } else {
16304: $ltienc{$itemid}{'secret'} = $currlti{'secret'};
16305: $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
16306: }
16307: if (ref($ltienc{$itemid}) eq 'HASH') {
16308: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
16309: $confhash{$itemid}{'usable'} = 1;
16310: }
16311: }
16312: } elsif ($env{$secretitem} ne '') {
16313: if ($privnum && $cipher) {
16314: $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
16315: $confhash{$itemid}{'cipher'} = $privnum;
16316: } else {
16317: $ltienc{$itemid}{'secret'} = $env{$secretitem};
16318: }
16319: if (ref($ltienc{$itemid}) eq 'HASH') {
16320: if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
16321: $confhash{$itemid}{'usable'} = 1;
16322: }
16323: }
16324: $changes{$itemid} = 1;
16325: }
16326: }
16327: unless ($changes{$itemid}) {
16328: foreach my $key (keys(%currlti)) {
16329: if (ref($currlti{$key}) eq 'HASH') {
16330: if (ref($confhash{$itemid}{$key}) eq 'HASH') {
16331: foreach my $innerkey (keys(%{$currlti{$key}})) {
16332: unless (exists($confhash{$itemid}{$key}{$innerkey})) {
16333: $changes{$itemid} = 1;
16334: last;
16335: }
16336: }
16337: } elsif (keys(%{$currlti{$key}}) > 0) {
16338: $changes{$itemid} = 1;
16339: }
16340: }
16341: last if ($changes{$itemid});
16342: }
16343: }
1.320 raeburn 16344: }
16345: if (@allpos > 0) {
16346: my $idx = 0;
16347: foreach my $itemid (@allpos) {
16348: if ($itemid ne '') {
16349: $confhash{$itemid}{'order'} = $idx;
16350: if (ref($domconfig{$action}) eq 'HASH') {
16351: if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
16352: if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
16353: $changes{$itemid} = 1;
16354: }
16355: }
16356: }
16357: $idx ++;
16358: }
16359: }
16360: }
1.424 raeburn 16361:
16362: if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
16363: return &mt('No changes made.');
16364: }
16365:
1.320 raeburn 16366: my %ltihash = (
1.405 raeburn 16367: $action => { %confhash }
16368: );
1.424 raeburn 16369: my %ltienchash;
16370:
16371: if ($is_home) {
16372: %ltienchash = (
16373: $action => { %ltienc }
16374: );
16375: }
1.405 raeburn 16376: if (keys(%secchanges)) {
16377: $ltihash{'ltisec'} = \%newltisec;
1.406 raeburn 16378: if ($secchanges{'linkprot'}) {
16379: if ($is_home) {
16380: $ltienchash{'linkprot'} = \%newltienc;
16381: }
16382: }
1.405 raeburn 16383: }
16384: my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1.320 raeburn 16385: if ($putresult eq 'ok') {
1.424 raeburn 16386: if (keys(%ltienchash)) {
16387: &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
1.405 raeburn 16388: }
16389: $resulttext = &mt('Changes made:').'<ul>';
16390: if (keys(%secchanges) > 0) {
1.423 raeburn 16391: $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
1.421 raeburn 16392: if (exists($secchanges{'linkprot'})) {
16393: $resulttext .= $linkprotoutput;
1.405 raeburn 16394: }
16395: }
1.320 raeburn 16396: if (keys(%changes) > 0) {
16397: my $cachetime = 24*60*60;
1.424 raeburn 16398: &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1.320 raeburn 16399: if (ref($lastactref) eq 'HASH') {
16400: $lastactref->{'lti'} = 1;
16401: }
16402: my %bynum;
16403: foreach my $itemid (sort(keys(%changes))) {
1.424 raeburn 16404: if (ref($confhash{$itemid}) eq 'HASH') {
16405: my $position = $confhash{$itemid}{'order'};
16406: $bynum{$position} = $itemid;
16407: }
1.320 raeburn 16408: }
16409: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
16410: my $itemid = $bynum{$pos};
1.424 raeburn 16411: if (ref($confhash{$itemid}) eq 'HASH') {
1.390 raeburn 16412: $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1.320 raeburn 16413: my $position = $pos + 1;
16414: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
16415: foreach my $item ('version','lifetime') {
16416: if ($confhash{$itemid}{$item} ne '') {
16417: $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
16418: }
16419: }
1.424 raeburn 16420: if ($ltienc{$itemid}{'key'} ne '') {
16421: $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
1.320 raeburn 16422: }
1.424 raeburn 16423: if ($ltienc{$itemid}{'secret'} ne '') {
16424: $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1.320 raeburn 16425: }
1.345 raeburn 16426: if ($confhash{$itemid}{'requser'}) {
1.391 raeburn 16427: if ($confhash{$itemid}{'callback'}) {
16428: $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
16429: } else {
1.392 raeburn 16430: $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
1.391 raeburn 16431: }
1.345 raeburn 16432: if ($confhash{$itemid}{'mapuser'}) {
16433: my $shownmapuser;
16434: if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
16435: $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
16436: } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
16437: $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
16438: } else {
16439: $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
1.320 raeburn 16440: }
1.345 raeburn 16441: $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
1.320 raeburn 16442: }
1.345 raeburn 16443: if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
16444: if (@{$confhash{$itemid}{'makeuser'}} > 0) {
16445: $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
16446: join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
16447: if ($confhash{$itemid}{'lcauth'} eq 'lti') {
16448: $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
16449: } else {
16450: $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
16451: $confhash{$itemid}{'lcauth'});
16452: if ($confhash{$itemid}{'lcauth'} eq 'internal') {
16453: $resulttext .= '; '.&mt('a randomly generated password will be created');
16454: } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
16455: if ($confhash{$itemid}{'lcauthparm'} ne '') {
16456: $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
16457: }
16458: } else {
16459: $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
16460: }
16461: }
16462: $resulttext .= '</li>';
16463: } else {
16464: $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
16465: }
1.320 raeburn 16466: }
1.345 raeburn 16467: if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
16468: if (@{$confhash{$itemid}{'instdata'}} > 0) {
16469: $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
16470: join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
1.325 raeburn 16471: } else {
1.449 ! raeburn 16472: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.325 raeburn 16473: }
1.449 ! raeburn 16474: } else {
! 16475: $resulttext .= '<li>'.&mt('No institutional data used when creating a new user').'</li>';
1.320 raeburn 16476: }
1.391 raeburn 16477: foreach my $item ('topmenu','inlinemenu') {
1.345 raeburn 16478: $resulttext .= '<li>'.$lt{$item}.': ';
16479: if ($confhash{$itemid}{$item}) {
16480: $resulttext .= &mt('Yes');
16481: } else {
16482: $resulttext .= &mt('No');
1.337 raeburn 16483: }
1.345 raeburn 16484: $resulttext .= '</li>';
1.320 raeburn 16485: }
1.345 raeburn 16486: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16487: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16488: $resulttext .= '<li>'.&mt('Menu items:').' '.
1.391 raeburn 16489: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16490: } else {
16491: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16492: }
16493: }
16494: if ($confhash{$itemid}{'crsinc'}) {
16495: if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
16496: my $rolemaps;
16497: foreach my $role (@ltiroles) {
16498: if ($confhash{$itemid}{'maproles'}{$role}) {
16499: $rolemaps .= (' 'x2).$role.'='.
16500: &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
16501: 'Course').',';
16502: }
16503: }
16504: if ($rolemaps) {
16505: $rolemaps =~ s/,$//;
16506: $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
16507: }
16508: }
16509: if ($confhash{$itemid}{'mapcrs'}) {
16510: $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
16511: }
16512: if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
16513: if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
16514: $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
16515: join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
16516: '</li>';
16517: } else {
16518: $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
16519: }
16520: }
1.392 raeburn 16521: if ($confhash{$itemid}{'storecrs'}) {
16522: $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
16523: }
1.391 raeburn 16524: if ($confhash{$itemid}{'makecrs'}) {
16525: $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
16526: } else {
16527: $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
16528: }
16529: if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
16530: if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
16531: $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
16532: join(', ',@{$confhash{$itemid}{'selfenroll'}})).
16533: '</li>';
16534: } else {
16535: $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
16536: }
16537: }
16538: if ($confhash{$itemid}{'section'}) {
16539: if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
16540: $resulttext .= '<li>'.&mt('User section from standard field:').
16541: ' (course_section_sourcedid)'.'</li>';
16542: } else {
16543: $resulttext .= '<li>'.&mt('User section from:').' '.
16544: $confhash{$itemid}{'section'}.'</li>';
16545: }
1.345 raeburn 16546: } else {
1.391 raeburn 16547: $resulttext .= '<li>'.&mt('No section assignment').'</li>';
16548: }
16549: foreach my $item ('passback','roster','topmenu','inlinemenu') {
16550: $resulttext .= '<li>'.$lt{$item}.': ';
16551: if ($confhash{$itemid}{$item}) {
16552: $resulttext .= &mt('Yes');
16553: if ($item eq 'passback') {
16554: if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
16555: $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
16556: } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
16557: $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
16558: }
16559: }
16560: } else {
16561: $resulttext .= &mt('No');
16562: }
16563: $resulttext .= '</li>';
16564: }
16565: if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
16566: if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
16567: $resulttext .= '<li>'.&mt('Menu items:').' '.
16568: join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
16569: } else {
16570: $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
16571: }
1.345 raeburn 16572: }
1.326 raeburn 16573: }
16574: }
1.320 raeburn 16575: $resulttext .= '</ul></li>';
16576: }
16577: }
1.424 raeburn 16578: if (keys(%deletions)) {
16579: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
16580: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
16581: }
16582: }
1.320 raeburn 16583: }
1.405 raeburn 16584: $resulttext .= '</ul>';
1.424 raeburn 16585: if (ref($lastactref) eq 'HASH') {
1.434 raeburn 16586: if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
16587: &Apache::lonnet::get_domain_defaults($dom,1);
1.424 raeburn 16588: $lastactref->{'domdefaults'} = 1;
16589: }
16590: }
1.320 raeburn 16591: } else {
16592: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
16593: }
16594: if ($errors) {
16595: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
16596: $errors.'</ul>';
16597: }
16598: return $resulttext;
16599: }
16600:
1.424 raeburn 16601: sub get_priv_creds {
16602: my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
16603: my ($needenc,$cipher,$privnum);
16604: my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
16605: if (($encchg) && (ref($encrypt) eq 'HASH')) {
16606: $needenc = $encrypt->{'consumers'}
16607: } else {
16608: $needenc = $domdefs{'ltienc_consumers'};
16609: }
16610: if ($needenc) {
16611: if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
16612: (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
16613: my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
16614: my $privkey = $privhash{'key'};
16615: $privnum = $privhash{'version'};
16616: if (($privnum) && ($privkey ne '')) {
16617: $cipher = Crypt::CBC->new({'key' => $privkey,
16618: 'cipher' => 'DES'});
16619: }
16620: }
16621: }
16622: return ($cipher,$privnum);
16623: }
16624:
1.320 raeburn 16625: sub get_lti_id {
1.434 raeburn 16626: my ($domain,$consumer,$dbname) = @_;
16627: unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
16628: return ('','invalid db');
16629: }
16630: # get lock on db
1.320 raeburn 16631: my $lockhash = {
16632: lock => $env{'user.name'}.
16633: ':'.$env{'user.domain'},
16634: };
16635: my $tries = 0;
1.434 raeburn 16636: my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16637: my ($id,$error);
16638:
16639: while (($gotlock ne 'ok') && ($tries<10)) {
16640: $tries ++;
16641: sleep (0.1);
1.434 raeburn 16642: $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1.320 raeburn 16643: }
16644: if ($gotlock eq 'ok') {
1.434 raeburn 16645: my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1.320 raeburn 16646: if ($currids{'lock'}) {
16647: delete($currids{'lock'});
16648: if (keys(%currids)) {
16649: my @curr = sort { $a <=> $b } keys(%currids);
16650: if ($curr[-1] =~ /^\d+$/) {
16651: $id = 1 + $curr[-1];
16652: }
16653: } else {
16654: $id = 1;
16655: }
16656: if ($id) {
1.434 raeburn 16657: unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1.320 raeburn 16658: $error = 'nostore';
16659: }
16660: } else {
16661: $error = 'nonumber';
16662: }
16663: }
1.434 raeburn 16664: my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1.320 raeburn 16665: } else {
16666: $error = 'nolock';
16667: }
16668: return ($id,$error);
16669: }
16670:
1.3 raeburn 16671: sub modify_autoenroll {
1.205 raeburn 16672: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 16673: my ($resulttext,%changes);
16674: my %currautoenroll;
16675: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
16676: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
16677: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
16678: }
16679: }
16680: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
16681: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 16682: sender => 'Sender for notification messages',
1.274 raeburn 16683: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.399 raeburn 16684: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 16685: my @offon = ('off','on');
1.17 raeburn 16686: my $sender_uname = $env{'form.sender_uname'};
16687: my $sender_domain = $env{'form.sender_domain'};
16688: if ($sender_domain eq '') {
16689: $sender_uname = '';
16690: } elsif ($sender_uname eq '') {
16691: $sender_domain = '';
16692: }
1.129 raeburn 16693: my $coowners = $env{'form.autoassign_coowners'};
1.399 raeburn 16694: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
16695: $autofailsafe =~ s{^\s+|\s+$}{}g;
16696: if ($autofailsafe =~ /\D/) {
16697: undef($autofailsafe);
16698: }
1.274 raeburn 16699: my $failsafe = $env{'form.autoenroll_failsafe'};
1.399 raeburn 16700: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
16701: $failsafe = 'off';
1.400 raeburn 16702: undef($autofailsafe);
1.274 raeburn 16703: }
1.1 raeburn 16704: my %autoenrollhash = (
1.129 raeburn 16705: autoenroll => { 'run' => $env{'form.autoenroll_run'},
16706: 'sender_uname' => $sender_uname,
16707: 'sender_domain' => $sender_domain,
16708: 'co-owners' => $coowners,
1.399 raeburn 16709: 'autofailsafe' => $autofailsafe,
1.400 raeburn 16710: 'failsafe' => $failsafe,
1.1 raeburn 16711: }
16712: );
1.4 raeburn 16713: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
16714: $dom);
1.1 raeburn 16715: if ($putresult eq 'ok') {
16716: if (exists($currautoenroll{'run'})) {
16717: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
16718: $changes{'run'} = 1;
16719: }
16720: } elsif ($autorun) {
16721: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 16722: $changes{'run'} = 1;
1.1 raeburn 16723: }
16724: }
1.17 raeburn 16725: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 16726: $changes{'sender'} = 1;
16727: }
1.17 raeburn 16728: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 16729: $changes{'sender'} = 1;
16730: }
1.129 raeburn 16731: if ($currautoenroll{'co-owners'} ne '') {
16732: if ($currautoenroll{'co-owners'} ne $coowners) {
16733: $changes{'coowners'} = 1;
16734: }
16735: } elsif ($coowners) {
16736: $changes{'coowners'} = 1;
1.274 raeburn 16737: }
1.399 raeburn 16738: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.274 raeburn 16739: $changes{'autofailsafe'} = 1;
16740: }
1.399 raeburn 16741: if ($currautoenroll{'failsafe'} ne $failsafe) {
16742: $changes{'failsafe'} = 1;
16743: }
1.1 raeburn 16744: if (keys(%changes) > 0) {
16745: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 16746: if ($changes{'run'}) {
1.1 raeburn 16747: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
16748: }
16749: if ($changes{'sender'}) {
1.17 raeburn 16750: if ($sender_uname eq '' || $sender_domain eq '') {
16751: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
16752: } else {
16753: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
16754: }
1.1 raeburn 16755: }
1.129 raeburn 16756: if ($changes{'coowners'}) {
16757: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
16758: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 16759: if (ref($lastactref) eq 'HASH') {
16760: $lastactref->{'domainconfig'} = 1;
16761: }
1.129 raeburn 16762: }
1.274 raeburn 16763: if ($changes{'autofailsafe'}) {
1.399 raeburn 16764: if ($autofailsafe ne '') {
16765: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.274 raeburn 16766: } else {
1.399 raeburn 16767: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.274 raeburn 16768: }
1.399 raeburn 16769: }
16770: if ($changes{'failsafe'}) {
16771: if ($failsafe eq 'off') {
16772: unless ($changes{'autofailsafe'}) {
16773: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
16774: }
16775: } elsif ($failsafe eq 'zero') {
16776: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
16777: } else {
16778: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
16779: }
16780: }
16781: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.274 raeburn 16782: &Apache::lonnet::get_domain_defaults($dom,1);
16783: if (ref($lastactref) eq 'HASH') {
16784: $lastactref->{'domdefaults'} = 1;
16785: }
16786: }
1.1 raeburn 16787: $resulttext .= '</ul>';
16788: } else {
16789: $resulttext = &mt('No changes made to auto-enrollment settings');
16790: }
16791: } else {
1.11 albertel 16792: $resulttext = '<span class="LC_error">'.
16793: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 16794: }
1.3 raeburn 16795: return $resulttext;
1.1 raeburn 16796: }
16797:
16798: sub modify_autoupdate {
1.3 raeburn 16799: my ($dom,%domconfig) = @_;
1.1 raeburn 16800: my ($resulttext,%currautoupdate,%fields,%changes);
16801: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
16802: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
16803: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
16804: }
16805: }
16806: my @offon = ('off','on');
16807: my %title = &Apache::lonlocal::texthash (
1.385 raeburn 16808: run => 'Auto-update:',
16809: classlists => 'Updates to user information in classlists?',
16810: unexpired => 'Skip updates for users without active or future roles?',
16811: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 16812: );
1.44 raeburn 16813: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 16814: my %fieldtitles = &Apache::lonlocal::texthash (
16815: id => 'Student/Employee ID',
1.20 raeburn 16816: permanentemail => 'E-mail address',
1.1 raeburn 16817: lastname => 'Last Name',
16818: firstname => 'First Name',
16819: middlename => 'Middle Name',
1.132 raeburn 16820: generation => 'Generation',
1.1 raeburn 16821: );
1.142 raeburn 16822: $othertitle = &mt('All users');
1.1 raeburn 16823: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 16824: $othertitle = &mt('Other users');
1.1 raeburn 16825: }
16826: foreach my $key (keys(%env)) {
16827: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 16828: my ($usertype,$item) = ($1,$2);
16829: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
16830: if ($usertype eq 'default') {
16831: push(@{$fields{$1}},$2);
16832: } elsif (ref($types) eq 'ARRAY') {
16833: if (grep(/^\Q$usertype\E$/,@{$types})) {
16834: push(@{$fields{$1}},$2);
16835: }
16836: }
16837: }
1.1 raeburn 16838: }
16839: }
1.131 raeburn 16840: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
16841: @lockablenames = sort(@lockablenames);
16842: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
16843: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16844: if (@changed) {
16845: $changes{'lockablenames'} = 1;
16846: }
16847: } else {
16848: if (@lockablenames) {
16849: $changes{'lockablenames'} = 1;
16850: }
16851: }
1.1 raeburn 16852: my %updatehash = (
16853: autoupdate => { run => $env{'form.autoupdate_run'},
16854: classlists => $env{'form.classlists'},
1.385 raeburn 16855: unexpired => $env{'form.unexpired'},
1.1 raeburn 16856: fields => {%fields},
1.131 raeburn 16857: lockablenames => \@lockablenames,
1.1 raeburn 16858: }
16859: );
1.385 raeburn 16860: my $lastactivedays;
16861: if ($env{'form.lastactive'}) {
16862: $lastactivedays = $env{'form.lastactivedays'};
16863: $lastactivedays =~ s/^\s+|\s+$//g;
16864: unless ($lastactivedays =~ /^\d+$/) {
16865: undef($lastactivedays);
16866: $env{'form.lastactive'} = 0;
16867: }
16868: }
16869: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 16870: foreach my $key (keys(%currautoupdate)) {
1.385 raeburn 16871: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 16872: if (exists($updatehash{autoupdate}{$key})) {
16873: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
16874: $changes{$key} = 1;
16875: }
16876: }
16877: } elsif ($key eq 'fields') {
16878: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 16879: foreach my $item (@{$types},'default') {
1.1 raeburn 16880: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
16881: my $change = 0;
16882: foreach my $type (@{$currautoupdate{$key}{$item}}) {
16883: if (!exists($fields{$item})) {
16884: $change = 1;
1.132 raeburn 16885: last;
1.1 raeburn 16886: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 16887: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 16888: $change = 1;
1.132 raeburn 16889: last;
1.1 raeburn 16890: }
16891: }
16892: }
16893: if ($change) {
16894: push(@{$changes{$key}},$item);
16895: }
1.26 raeburn 16896: }
1.1 raeburn 16897: }
16898: }
1.131 raeburn 16899: } elsif ($key eq 'lockablenames') {
16900: if (ref($currautoupdate{$key}) eq 'ARRAY') {
16901: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
16902: if (@changed) {
16903: $changes{'lockablenames'} = 1;
16904: }
16905: } else {
16906: if (@lockablenames) {
16907: $changes{'lockablenames'} = 1;
16908: }
16909: }
16910: }
16911: }
16912: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
16913: if (@lockablenames) {
16914: $changes{'lockablenames'} = 1;
1.1 raeburn 16915: }
16916: }
1.385 raeburn 16917: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
16918: if ($updatehash{'autoupdate'}{'unexpired'}) {
16919: $changes{'unexpired'} = 1;
16920: }
16921: }
16922: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
16923: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
16924: $changes{'lastactive'} = 1;
16925: }
16926: }
1.26 raeburn 16927: foreach my $item (@{$types},'default') {
16928: if (defined($fields{$item})) {
16929: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 16930: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
16931: my $change = 0;
16932: if (ref($fields{$item}) eq 'ARRAY') {
16933: foreach my $type (@{$fields{$item}}) {
16934: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
16935: $change = 1;
16936: last;
16937: }
16938: }
16939: }
16940: if ($change) {
16941: push(@{$changes{'fields'}},$item);
16942: }
16943: } else {
1.26 raeburn 16944: push(@{$changes{'fields'}},$item);
16945: }
16946: } else {
16947: push(@{$changes{'fields'}},$item);
1.1 raeburn 16948: }
16949: }
16950: }
16951: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
16952: $dom);
16953: if ($putresult eq 'ok') {
16954: if (keys(%changes) > 0) {
16955: $resulttext = &mt('Changes made:').'<ul>';
16956: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 16957: if ($key eq 'lockablenames') {
16958: $resulttext .= '<li>';
16959: if (@lockablenames) {
16960: $usertypes->{'default'} = $othertitle;
16961: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
16962: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
16963: } else {
16964: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
16965: }
16966: $resulttext .= '</li>';
16967: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 16968: foreach my $item (@{$changes{$key}}) {
16969: my @newvalues;
16970: foreach my $type (@{$fields{$item}}) {
16971: push(@newvalues,$fieldtitles{$type});
16972: }
1.3 raeburn 16973: my $newvaluestr;
16974: if (@newvalues > 0) {
16975: $newvaluestr = join(', ',@newvalues);
16976: } else {
16977: $newvaluestr = &mt('none');
1.6 raeburn 16978: }
1.1 raeburn 16979: if ($item eq 'default') {
1.26 raeburn 16980: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 16981: } else {
1.26 raeburn 16982: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 16983: }
16984: }
16985: } else {
16986: my $newvalue;
16987: if ($key eq 'run') {
16988: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.385 raeburn 16989: } elsif ($key eq 'lastactive') {
16990: $newvalue = $offon[$env{'form.lastactive'}];
16991: unless ($lastactivedays eq '') {
16992: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
16993: }
1.1 raeburn 16994: } else {
16995: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 16996: }
1.1 raeburn 16997: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
16998: }
16999: }
17000: $resulttext .= '</ul>';
17001: } else {
1.3 raeburn 17002: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 17003: }
17004: } else {
1.11 albertel 17005: $resulttext = '<span class="LC_error">'.
17006: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 17007: }
1.3 raeburn 17008: return $resulttext;
1.1 raeburn 17009: }
17010:
1.125 raeburn 17011: sub modify_autocreate {
17012: my ($dom,%domconfig) = @_;
17013: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
17014: if (ref($domconfig{'autocreate'}) eq 'HASH') {
17015: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
17016: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
17017: }
17018: }
17019: my %title= ( xml => 'Auto-creation of courses in XML course description files',
17020: req => 'Auto-creation of validated requests for official courses',
17021: xmldc => 'Identity of course creator of courses from XML files',
17022: );
17023: my @types = ('xml','req');
17024: foreach my $item (@types) {
17025: $newvals{$item} = $env{'form.autocreate_'.$item};
17026: $newvals{$item} =~ s/\D//g;
17027: $newvals{$item} = 0 if ($newvals{$item} eq '');
17028: }
17029: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.285 raeburn 17030: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 17031: unless (exists($domcoords{$newvals{'xmldc'}})) {
17032: $newvals{'xmldc'} = '';
17033: }
17034: %autocreatehash = (
17035: autocreate => { xml => $newvals{'xml'},
17036: req => $newvals{'req'},
17037: }
17038: );
17039: if ($newvals{'xmldc'} ne '') {
17040: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
17041: }
17042: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
17043: $dom);
17044: if ($putresult eq 'ok') {
17045: my @items = @types;
17046: if ($newvals{'xml'}) {
17047: push(@items,'xmldc');
17048: }
17049: foreach my $item (@items) {
17050: if (exists($currautocreate{$item})) {
17051: if ($currautocreate{$item} ne $newvals{$item}) {
17052: $changes{$item} = 1;
17053: }
17054: } elsif ($newvals{$item}) {
17055: $changes{$item} = 1;
17056: }
17057: }
17058: if (keys(%changes) > 0) {
17059: my @offon = ('off','on');
17060: $resulttext = &mt('Changes made:').'<ul>';
17061: foreach my $item (@types) {
17062: if ($changes{$item}) {
17063: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 17064: $resulttext .= '<li>'.
17065: &mt("$title{$item} set to [_1]$newtxt [_2]",
17066: '<b>','</b>').
17067: '</li>';
1.125 raeburn 17068: }
17069: }
17070: if ($changes{'xmldc'}) {
17071: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
17072: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 17073: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 17074: }
17075: $resulttext .= '</ul>';
17076: } else {
17077: $resulttext = &mt('No changes made to auto-creation settings');
17078: }
17079: } else {
17080: $resulttext = '<span class="LC_error">'.
17081: &mt('An error occurred: [_1]',$putresult).'</span>';
17082: }
17083: return $resulttext;
17084: }
17085:
1.23 raeburn 17086: sub modify_directorysrch {
1.295 raeburn 17087: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 17088: my ($resulttext,%changes);
17089: my %currdirsrch;
17090: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
17091: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
17092: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
17093: }
17094: }
1.277 raeburn 17095: my %title = ( available => 'Institutional directory search available',
17096: localonly => 'Other domains can search institution',
17097: lcavailable => 'LON-CAPA directory search available',
1.289 raeburn 17098: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 17099: searchby => 'Search types',
17100: searchtypes => 'Search latitude');
17101: my @offon = ('off','on');
1.24 raeburn 17102: my @otherdoms = ('Yes','No');
1.23 raeburn 17103:
1.25 raeburn 17104: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 17105: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
17106: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
17107:
1.44 raeburn 17108: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 17109: if (keys(%{$usertypes}) == 0) {
17110: @cansearch = ('default');
17111: } else {
17112: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
17113: foreach my $type (@{$currdirsrch{'cansearch'}}) {
17114: if (!grep(/^\Q$type\E$/,@cansearch)) {
17115: push(@{$changes{'cansearch'}},$type);
17116: }
1.23 raeburn 17117: }
1.26 raeburn 17118: foreach my $type (@cansearch) {
17119: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
17120: push(@{$changes{'cansearch'}},$type);
17121: }
1.23 raeburn 17122: }
1.26 raeburn 17123: } else {
17124: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 17125: }
17126: }
17127:
17128: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
17129: foreach my $by (@{$currdirsrch{'searchby'}}) {
17130: if (!grep(/^\Q$by\E$/,@searchby)) {
17131: push(@{$changes{'searchby'}},$by);
17132: }
17133: }
17134: foreach my $by (@searchby) {
17135: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
17136: push(@{$changes{'searchby'}},$by);
17137: }
17138: }
17139: } else {
17140: push(@{$changes{'searchby'}},@searchby);
17141: }
1.25 raeburn 17142:
17143: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
17144: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
17145: if (!grep(/^\Q$type\E$/,@searchtypes)) {
17146: push(@{$changes{'searchtypes'}},$type);
17147: }
17148: }
17149: foreach my $type (@searchtypes) {
17150: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
17151: push(@{$changes{'searchtypes'}},$type);
17152: }
17153: }
17154: } else {
17155: if (exists($currdirsrch{'searchtypes'})) {
17156: foreach my $type (@searchtypes) {
17157: if ($type ne $currdirsrch{'searchtypes'}) {
17158: push(@{$changes{'searchtypes'}},$type);
17159: }
17160: }
17161: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
17162: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
17163: }
17164: } else {
17165: push(@{$changes{'searchtypes'}},@searchtypes);
17166: }
17167: }
17168:
1.23 raeburn 17169: my %dirsrch_hash = (
17170: directorysrch => { available => $env{'form.dirsrch_available'},
17171: cansearch => \@cansearch,
1.277 raeburn 17172: localonly => $env{'form.dirsrch_instlocalonly'},
17173: lclocalonly => $env{'form.dirsrch_domlocalonly'},
17174: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 17175: searchby => \@searchby,
1.25 raeburn 17176: searchtypes => \@searchtypes,
1.23 raeburn 17177: }
17178: );
17179: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
17180: $dom);
17181: if ($putresult eq 'ok') {
17182: if (exists($currdirsrch{'available'})) {
17183: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
17184: $changes{'available'} = 1;
17185: }
17186: } else {
17187: if ($env{'form.dirsrch_available'} eq '1') {
17188: $changes{'available'} = 1;
17189: }
17190: }
1.277 raeburn 17191: if (exists($currdirsrch{'lcavailable'})) {
1.289 raeburn 17192: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
17193: $changes{'lcavailable'} = 1;
17194: }
1.277 raeburn 17195: } else {
17196: if ($env{'form.dirsrch_lcavailable'} eq '1') {
17197: $changes{'lcavailable'} = 1;
17198: }
17199: }
1.24 raeburn 17200: if (exists($currdirsrch{'localonly'})) {
1.289 raeburn 17201: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
17202: $changes{'localonly'} = 1;
17203: }
1.24 raeburn 17204: } else {
1.277 raeburn 17205: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
1.24 raeburn 17206: $changes{'localonly'} = 1;
17207: }
17208: }
1.277 raeburn 17209: if (exists($currdirsrch{'lclocalonly'})) {
1.289 raeburn 17210: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
17211: $changes{'lclocalonly'} = 1;
17212: }
1.277 raeburn 17213: } else {
17214: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
17215: $changes{'lclocalonly'} = 1;
17216: }
17217: }
1.23 raeburn 17218: if (keys(%changes) > 0) {
17219: $resulttext = &mt('Changes made:').'<ul>';
17220: if ($changes{'available'}) {
17221: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
17222: }
1.277 raeburn 17223: if ($changes{'lcavailable'}) {
17224: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
17225: }
1.24 raeburn 17226: if ($changes{'localonly'}) {
1.277 raeburn 17227: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
1.24 raeburn 17228: }
1.277 raeburn 17229: if ($changes{'lclocalonly'}) {
17230: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.289 raeburn 17231: }
1.23 raeburn 17232: if (ref($changes{'cansearch'}) eq 'ARRAY') {
17233: my $chgtext;
1.26 raeburn 17234: if (ref($usertypes) eq 'HASH') {
17235: if (keys(%{$usertypes}) > 0) {
17236: foreach my $type (@{$types}) {
17237: if (grep(/^\Q$type\E$/,@cansearch)) {
17238: $chgtext .= $usertypes->{$type}.'; ';
17239: }
17240: }
17241: if (grep(/^default$/,@cansearch)) {
17242: $chgtext .= $othertitle;
17243: } else {
17244: $chgtext =~ s/\; $//;
17245: }
1.210 raeburn 17246: $resulttext .=
1.178 raeburn 17247: '<li>'.
17248: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
17249: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
17250: '</li>';
1.23 raeburn 17251: }
17252: }
17253: }
17254: if (ref($changes{'searchby'}) eq 'ARRAY') {
17255: my ($searchtitles,$titleorder) = &sorted_searchtitles();
17256: my $chgtext;
17257: foreach my $type (@{$titleorder}) {
17258: if (grep(/^\Q$type\E$/,@searchby)) {
17259: if (defined($searchtitles->{$type})) {
17260: $chgtext .= $searchtitles->{$type}.'; ';
17261: }
17262: }
17263: }
17264: $chgtext =~ s/\; $//;
17265: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
17266: }
1.25 raeburn 17267: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
17268: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
17269: my $chgtext;
17270: foreach my $type (@{$srchtypeorder}) {
17271: if (grep(/^\Q$type\E$/,@searchtypes)) {
17272: if (defined($srchtypes_desc->{$type})) {
17273: $chgtext .= $srchtypes_desc->{$type}.'; ';
17274: }
17275: }
17276: }
17277: $chgtext =~ s/\; $//;
1.178 raeburn 17278: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 17279: }
17280: $resulttext .= '</ul>';
1.295 raeburn 17281: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
17282: if (ref($lastactref) eq 'HASH') {
17283: $lastactref->{'directorysrch'} = 1;
17284: }
1.23 raeburn 17285: } else {
1.277 raeburn 17286: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 17287: }
17288: } else {
17289: $resulttext = '<span class="LC_error">'.
1.27 raeburn 17290: &mt('An error occurred: [_1]',$putresult).'</span>';
17291: }
17292: return $resulttext;
17293: }
17294:
1.28 raeburn 17295: sub modify_contacts {
1.205 raeburn 17296: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 17297: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
17298: if (ref($domconfig{'contacts'}) eq 'HASH') {
17299: foreach my $key (keys(%{$domconfig{'contacts'}})) {
17300: $currsetting{$key} = $domconfig{'contacts'}{$key};
17301: }
17302: }
1.286 raeburn 17303: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 17304: my @contacts = ('supportemail','adminemail');
1.286 raeburn 17305: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.350 raeburn 17306: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.340 raeburn 17307: my @toggles = ('reporterrors','reportupdates','reportstatus');
17308: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.286 raeburn 17309: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 17310: foreach my $type (@mailings) {
17311: @{$newsetting{$type}} =
17312: &Apache::loncommon::get_env_multiple('form.'.$type);
17313: foreach my $item (@contacts) {
17314: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
17315: $contacts_hash{contacts}{$type}{$item} = 1;
17316: } else {
17317: $contacts_hash{contacts}{$type}{$item} = 0;
17318: }
1.289 raeburn 17319: }
1.28 raeburn 17320: $others{$type} = $env{'form.'.$type.'_others'};
17321: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.286 raeburn 17322: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17323: $bcc{$type} = $env{'form.'.$type.'_bcc'};
17324: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.286 raeburn 17325: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
17326: $includestr{$type} = $env{'form.'.$type.'_includestr'};
17327: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
17328: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17329: }
1.134 raeburn 17330: }
1.28 raeburn 17331: }
17332: foreach my $item (@contacts) {
17333: $to{$item} = $env{'form.'.$item};
17334: $contacts_hash{'contacts'}{$item} = $to{$item};
17335: }
1.203 raeburn 17336: foreach my $item (@toggles) {
17337: if ($env{'form.'.$item} =~ /^(0|1)$/) {
17338: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
17339: }
17340: }
1.340 raeburn 17341: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
17342: foreach my $item (@lonstatus) {
17343: if ($item eq 'excluded') {
17344: my (%serverhomes,@excluded);
17345: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
17346: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
17347: if (@possexcluded) {
17348: foreach my $id (sort(@possexcluded)) {
17349: if ($serverhomes{$id}) {
17350: push(@excluded,$id);
17351: }
17352: }
17353: }
17354: if (@excluded) {
17355: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
17356: }
17357: } elsif ($item eq 'weights') {
1.377 raeburn 17358: foreach my $type ('E','W','N','U') {
1.340 raeburn 17359: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
17360: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
17361: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
17362: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
17363: $env{'form.error'.$item.'_'.$type};
17364: }
17365: }
17366: }
17367: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
17368: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
17369: if ($env{'form.error'.$item} =~ /^\d+$/) {
17370: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
17371: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
17372: }
17373: }
17374: }
17375: }
1.286 raeburn 17376: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
17377: foreach my $field (@{$fields}) {
17378: if (ref($possoptions->{$field}) eq 'ARRAY') {
17379: my $value = $env{'form.helpform_'.$field};
17380: $value =~ s/^\s+|\s+$//g;
17381: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.315 raeburn 17382: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.286 raeburn 17383: if ($field eq 'screenshot') {
17384: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
17385: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.315 raeburn 17386: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.286 raeburn 17387: }
17388: }
17389: }
17390: }
17391: }
17392: }
1.315 raeburn 17393: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17394: my (@statuses,%usertypeshash,@overrides);
17395: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
17396: @statuses = @{$types};
17397: if (ref($usertypes) eq 'HASH') {
17398: %usertypeshash = %{$usertypes};
17399: }
17400: }
17401: if (@statuses) {
17402: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
17403: foreach my $type (@possoverrides) {
17404: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
17405: push(@overrides,$type);
17406: }
17407: }
17408: if (@overrides) {
17409: foreach my $type (@overrides) {
17410: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
17411: foreach my $item (@contacts) {
17412: if (grep(/^\Q$item\E$/,@standard)) {
17413: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
17414: $newsetting{'override_'.$type}{$item} = 1;
17415: } else {
17416: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
17417: $newsetting{'override_'.$type}{$item} = 0;
17418: }
17419: }
17420: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
17421: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17422: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
17423: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
17424: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
17425: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
17426: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
17427: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
17428: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
17429: }
1.425 raeburn 17430: }
1.315 raeburn 17431: }
17432: }
1.28 raeburn 17433: if (keys(%currsetting) > 0) {
17434: foreach my $item (@contacts) {
17435: if ($to{$item} ne $currsetting{$item}) {
17436: $changes{$item} = 1;
17437: }
17438: }
17439: foreach my $type (@mailings) {
17440: foreach my $item (@contacts) {
17441: if (ref($currsetting{$type}) eq 'HASH') {
17442: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
17443: push(@{$changes{$type}},$item);
17444: }
17445: } else {
17446: push(@{$changes{$type}},@{$newsetting{$type}});
17447: }
17448: }
17449: if ($others{$type} ne $currsetting{$type}{'others'}) {
17450: push(@{$changes{$type}},'others');
17451: }
1.289 raeburn 17452: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17453: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
17454: push(@{$changes{$type}},'bcc');
17455: }
1.286 raeburn 17456: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
17457: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
17458: push(@{$changes{$type}},'include');
17459: }
17460: }
17461: }
17462: if (ref($fields) eq 'ARRAY') {
17463: if (ref($currsetting{'helpform'}) eq 'HASH') {
17464: foreach my $field (@{$fields}) {
17465: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
17466: push(@{$changes{'helpform'}},$field);
17467: }
17468: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17469: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
17470: push(@{$changes{'helpform'}},'maxsize');
17471: }
17472: }
17473: }
17474: } else {
17475: foreach my $field (@{$fields}) {
17476: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17477: push(@{$changes{'helpform'}},$field);
17478: }
17479: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17480: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17481: push(@{$changes{'helpform'}},'maxsize');
17482: }
17483: }
17484: }
1.134 raeburn 17485: }
1.28 raeburn 17486: }
1.315 raeburn 17487: if (@statuses) {
1.425 raeburn 17488: if (ref($currsetting{'overrides'}) eq 'HASH') {
1.315 raeburn 17489: foreach my $key (keys(%{$currsetting{'overrides'}})) {
17490: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
17491: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
17492: foreach my $item (@contacts,'bcc','others','include') {
1.425 raeburn 17493: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
1.315 raeburn 17494: push(@{$changes{'overrides'}},$key);
17495: last;
17496: }
17497: }
17498: } else {
17499: push(@{$changes{'overrides'}},$key);
17500: }
17501: }
17502: }
17503: foreach my $key (@overrides) {
17504: unless (exists($currsetting{'overrides'}{$key})) {
17505: push(@{$changes{'overrides'}},$key);
17506: }
17507: }
17508: } else {
17509: foreach my $key (@overrides) {
1.425 raeburn 17510: push(@{$changes{'overrides'}},$key);
1.315 raeburn 17511: }
17512: }
17513: }
1.340 raeburn 17514: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
17515: foreach my $key ('excluded','weights','threshold','sysmail') {
17516: if ($key eq 'excluded') {
17517: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17518: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
17519: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17520: (@{$currsetting{'lonstatus'}{$key}})) {
17521: my @diffs =
17522: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
17523: $currsetting{'lonstatus'}{$key});
17524: if (@diffs) {
17525: push(@{$changes{'lonstatus'}},$key);
17526: }
17527: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
17528: push(@{$changes{'lonstatus'}},$key);
17529: }
17530: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
17531: (@{$currsetting{'lonstatus'}{$key}})) {
17532: push(@{$changes{'lonstatus'}},$key);
17533: }
17534: } elsif ($key eq 'weights') {
17535: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
17536: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
17537: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17538: foreach my $type ('E','W','N','U') {
1.340 raeburn 17539: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
17540: $currsetting{'lonstatus'}{$key}{$type}) {
17541: push(@{$changes{'lonstatus'}},$key);
17542: last;
17543: }
17544: }
17545: } else {
1.341 raeburn 17546: foreach my $type ('E','W','N','U') {
1.340 raeburn 17547: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
17548: push(@{$changes{'lonstatus'}},$key);
17549: last;
17550: }
17551: }
17552: }
17553: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
1.341 raeburn 17554: foreach my $type ('E','W','N','U') {
1.340 raeburn 17555: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
17556: push(@{$changes{'lonstatus'}},$key);
17557: last;
17558: }
17559: }
17560: }
17561: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
17562: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17563: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17564: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
17565: push(@{$changes{'lonstatus'}},$key);
17566: }
17567: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
17568: push(@{$changes{'lonstatus'}},$key);
17569: }
17570: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
17571: push(@{$changes{'lonstatus'}},$key);
17572: }
17573: }
17574: }
17575: } else {
17576: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17577: foreach my $key ('excluded','weights','threshold','sysmail') {
17578: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17579: push(@{$changes{'lonstatus'}},$key);
17580: }
17581: }
17582: }
17583: }
1.28 raeburn 17584: } else {
17585: my %default;
17586: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
17587: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
17588: $default{'errormail'} = 'adminemail';
17589: $default{'packagesmail'} = 'adminemail';
17590: $default{'helpdeskmail'} = 'supportemail';
1.286 raeburn 17591: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 17592: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 17593: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 17594: $default{'updatesmail'} = 'adminemail';
1.350 raeburn 17595: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 17596: foreach my $item (@contacts) {
17597: if ($to{$item} ne $default{$item}) {
1.286 raeburn 17598: $changes{$item} = 1;
1.203 raeburn 17599: }
1.28 raeburn 17600: }
17601: foreach my $type (@mailings) {
17602: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
17603: push(@{$changes{$type}},@{$newsetting{$type}});
17604: }
17605: if ($others{$type} ne '') {
17606: push(@{$changes{$type}},'others');
1.134 raeburn 17607: }
1.286 raeburn 17608: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17609: if ($bcc{$type} ne '') {
17610: push(@{$changes{$type}},'bcc');
17611: }
1.286 raeburn 17612: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
17613: push(@{$changes{$type}},'include');
17614: }
1.134 raeburn 17615: }
1.28 raeburn 17616: }
1.286 raeburn 17617: if (ref($fields) eq 'ARRAY') {
17618: foreach my $field (@{$fields}) {
17619: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
17620: push(@{$changes{'helpform'}},$field);
17621: }
17622: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
17623: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
17624: push(@{$changes{'helpform'}},'maxsize');
17625: }
17626: }
17627: }
1.289 raeburn 17628: }
1.340 raeburn 17629: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
17630: foreach my $key ('excluded','weights','threshold','sysmail') {
17631: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
17632: push(@{$changes{'lonstatus'}},$key);
17633: }
17634: }
17635: }
1.28 raeburn 17636: }
1.203 raeburn 17637: foreach my $item (@toggles) {
17638: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
17639: $changes{$item} = 1;
17640: } elsif ((!$env{'form.'.$item}) &&
17641: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
17642: $changes{$item} = 1;
17643: }
17644: }
1.28 raeburn 17645: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
17646: $dom);
17647: if ($putresult eq 'ok') {
17648: if (keys(%changes) > 0) {
1.205 raeburn 17649: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 17650: if (ref($lastactref) eq 'HASH') {
17651: $lastactref->{'domainconfig'} = 1;
17652: }
1.28 raeburn 17653: my ($titles,$short_titles) = &contact_titles();
17654: $resulttext = &mt('Changes made:').'<ul>';
17655: foreach my $item (@contacts) {
17656: if ($changes{$item}) {
17657: $resulttext .= '<li>'.$titles->{$item}.
17658: &mt(' set to: ').
17659: '<span class="LC_cusr_emph">'.
17660: $to{$item}.'</span></li>';
17661: }
17662: }
17663: foreach my $type (@mailings) {
17664: if (ref($changes{$type}) eq 'ARRAY') {
1.286 raeburn 17665: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.289 raeburn 17666: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
1.286 raeburn 17667: } else {
17668: $resulttext .= '<li>'.$titles->{$type}.': ';
17669: }
1.28 raeburn 17670: my @text;
17671: foreach my $item (@{$newsetting{$type}}) {
17672: push(@text,$short_titles->{$item});
17673: }
17674: if ($others{$type} ne '') {
17675: push(@text,$others{$type});
17676: }
1.286 raeburn 17677: if (@text) {
17678: $resulttext .= '<span class="LC_cusr_emph">'.
17679: join(', ',@text).'</span>';
17680: }
17681: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 17682: if ($bcc{$type} ne '') {
1.286 raeburn 17683: my $bcctext;
17684: if (@text) {
1.289 raeburn 17685: $bcctext = ' '.&mt('with Bcc to');
1.286 raeburn 17686: } else {
17687: $bcctext = '(Bcc)';
17688: }
17689: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
17690: } elsif (!@text) {
17691: $resulttext .= &mt('No one');
1.425 raeburn 17692: }
1.289 raeburn 17693: if ($includestr{$type} ne '') {
1.286 raeburn 17694: if ($includeloc{$type} eq 'b') {
17695: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
17696: } elsif ($includeloc{$type} eq 's') {
17697: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
17698: }
1.134 raeburn 17699: }
1.286 raeburn 17700: } elsif (!@text) {
17701: $resulttext .= &mt('No recipients');
1.134 raeburn 17702: }
17703: $resulttext .= '</li>';
1.28 raeburn 17704: }
17705: }
1.315 raeburn 17706: if (ref($changes{'overrides'}) eq 'ARRAY') {
17707: my @deletions;
17708: foreach my $type (@{$changes{'overrides'}}) {
17709: if ($usertypeshash{$type}) {
17710: if (grep(/^\Q$type\E/,@overrides)) {
17711: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
17712: $usertypeshash{$type}).'<ul><li>';
17713: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
17714: my @text;
17715: foreach my $item (@contacts) {
1.425 raeburn 17716: if ($newsetting{'override_'.$type}{$item}) {
1.315 raeburn 17717: push(@text,$short_titles->{$item});
17718: }
17719: }
17720: if ($newsetting{'override_'.$type}{'others'} ne '') {
17721: push(@text,$newsetting{'override_'.$type}{'others'});
17722: }
1.425 raeburn 17723:
1.315 raeburn 17724: if (@text) {
17725: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
17726: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
17727: }
17728: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
17729: my $bcctext;
17730: if (@text) {
17731: $bcctext = ' '.&mt('with Bcc to');
17732: } else {
17733: $bcctext = '(Bcc)';
17734: }
17735: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
17736: } elsif (!@text) {
17737: $resulttext .= &mt('Helpdesk e-mail sent to no one');
17738: }
17739: $resulttext .= '</li>';
17740: if ($newsetting{'override_'.$type}{'include'} ne '') {
17741: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
17742: if ($loc eq 'b') {
17743: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
17744: } elsif ($loc eq 's') {
17745: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
17746: }
17747: }
17748: }
17749: $resulttext .= '</li></ul></li>';
17750: } else {
17751: push(@deletions,$usertypeshash{$type});
17752: }
17753: }
17754: }
17755: if (@deletions) {
17756: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
17757: join(', ',@deletions)).'</li>';
17758: }
17759: }
1.203 raeburn 17760: my @offon = ('off','on');
1.340 raeburn 17761: my $corelink = &core_link_msu();
1.203 raeburn 17762: if ($changes{'reporterrors'}) {
17763: $resulttext .= '<li>'.
17764: &mt('E-mail error reports to [_1] set to "'.
17765: $offon[$env{'form.reporterrors'}].'".',
1.340 raeburn 17766: $corelink).
1.203 raeburn 17767: '</li>';
17768: }
17769: if ($changes{'reportupdates'}) {
17770: $resulttext .= '<li>'.
17771: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
17772: $offon[$env{'form.reportupdates'}].'".',
1.340 raeburn 17773: $corelink).
1.203 raeburn 17774: '</li>';
17775: }
1.340 raeburn 17776: if ($changes{'reportstatus'}) {
17777: $resulttext .= '<li>'.
17778: &mt('E-mail status if errors above threshold to [_1] set to "'.
17779: $offon[$env{'form.reportstatus'}].'".',
17780: $corelink).
17781: '</li>';
17782: }
17783: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
17784: $resulttext .= '<li>'.
17785: &mt('Nightly status check e-mail settings').':<ul>';
17786: my (%defval,%use_def,%shown);
17787: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
17788: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
17789: $defval{'weights'} =
1.341 raeburn 17790: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
1.340 raeburn 17791: $defval{'excluded'} = &mt('None');
17792: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
17793: foreach my $item ('threshold','sysmail','weights','excluded') {
17794: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
17795: if (($item eq 'threshold') || ($item eq 'sysmail')) {
17796: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
17797: } elsif ($item eq 'weights') {
17798: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
1.341 raeburn 17799: foreach my $type ('E','W','N','U') {
1.340 raeburn 17800: $shown{$item} .= $lonstatus_names->{$type}.'=';
17801: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
17802: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
17803: } else {
17804: $shown{$item} .= $lonstatus_defs->{$type};
17805: }
17806: $shown{$item} .= ', ';
17807: }
17808: $shown{$item} =~ s/, $//;
17809: } else {
17810: $shown{$item} = $defval{$item};
17811: }
17812: } elsif ($item eq 'excluded') {
17813: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
17814: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
17815: } else {
17816: $shown{$item} = $defval{$item};
17817: }
17818: }
17819: } else {
17820: $shown{$item} = $defval{$item};
17821: }
17822: }
17823: } else {
17824: foreach my $item ('threshold','weights','excluded','sysmail') {
17825: $shown{$item} = $defval{$item};
17826: }
17827: }
17828: foreach my $item ('threshold','weights','excluded','sysmail') {
17829: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
17830: $shown{$item}).'</li>';
17831: }
17832: $resulttext .= '</ul></li>';
17833: }
1.286 raeburn 17834: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
17835: my (@optional,@required,@unused,$maxsizechg);
17836: foreach my $field (@{$changes{'helpform'}}) {
17837: if ($field eq 'maxsize') {
17838: $maxsizechg = 1;
17839: next;
17840: }
17841: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
1.289 raeburn 17842: push(@optional,$field);
1.286 raeburn 17843: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
17844: push(@unused,$field);
17845: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
1.289 raeburn 17846: push(@required,$field);
1.286 raeburn 17847: }
17848: }
17849: if (@optional) {
17850: $resulttext .= '<li>'.
17851: &mt('Help form fields changed to "Optional": [_1].',
17852: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
17853: '</li>';
17854: }
17855: if (@required) {
17856: $resulttext .= '<li>'.
17857: &mt('Help form fields changed to "Required": [_1].',
17858: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
17859: '</li>';
17860: }
17861: if (@unused) {
17862: $resulttext .= '<li>'.
17863: &mt('Help form fields changed to "Not shown": [_1].',
17864: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
17865: '</li>';
17866: }
17867: if ($maxsizechg) {
17868: $resulttext .= '<li>'.
17869: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
17870: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
17871: '</li>';
17872: }
17873: }
1.28 raeburn 17874: $resulttext .= '</ul>';
17875: } else {
1.288 raeburn 17876: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 17877: }
17878: } else {
17879: $resulttext = '<span class="LC_error">'.
17880: &mt('An error occurred: [_1].',$putresult).'</span>';
17881: }
17882: return $resulttext;
17883: }
17884:
1.357 raeburn 17885: sub modify_privacy {
1.427 raeburn 17886: my ($dom,$lastactref,%domconfig) = @_;
1.357 raeburn 17887: my ($resulttext,%current,%changes);
17888: if (ref($domconfig{'privacy'}) eq 'HASH') {
17889: %current = %{$domconfig{'privacy'}};
17890: }
17891: my @fields = ('lastname','firstname','middlename','generation','permanentemail','id');
17892: my @items = ('domain','author','course','community');
17893: my %names = &Apache::lonlocal::texthash (
17894: domain => 'Assigned domain role(s)',
17895: author => 'Assigned co-author role(s)',
17896: course => 'Assigned course role(s)',
1.416 raeburn 17897: community => 'Assigned community role(s)',
1.357 raeburn 17898: );
17899: my %roles = &Apache::lonlocal::texthash (
17900: domain => 'Domain role',
17901: author => 'Co-author role',
17902: course => 'Course role',
17903: community => 'Community role',
17904: );
17905: my %titles = &Apache::lonlocal::texthash (
17906: approval => 'Approval for role in different domain',
17907: othdom => 'User information available in other domain',
17908: priv => 'Information viewable by privileged user in same domain',
17909: unpriv => 'Information viewable by unprivileged user in same domain',
17910: instdom => 'Other domain shares institution/provider',
17911: extdom => 'Other domain has different institution/provider',
17912: none => 'Not allowed',
17913: user => 'User authorizes',
17914: domain => 'Domain Coordinator authorizes',
17915: auto => 'Unrestricted',
1.418 raeburn 17916: notify => 'Notify when role needs authorization',
1.357 raeburn 17917: );
17918: my %fieldnames = &Apache::lonlocal::texthash (
17919: id => 'Student/Employee ID',
17920: permanentemail => 'E-mail address',
17921: lastname => 'Last Name',
17922: firstname => 'First Name',
17923: middlename => 'Middle Name',
17924: generation => 'Generation',
17925: );
17926: my ($othertitle,$usertypes,$types) =
17927: &Apache::loncommon::sorted_inst_types($dom);
17928: my (%by_ip,%by_location,@intdoms,@instdoms);
17929: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
17930:
17931: my %privacyhash = (
17932: 'approval' => {
17933: instdom => {},
17934: extdom => {},
17935: },
17936: 'othdom' => {},
17937: 'priv' => {},
17938: 'unpriv' => {},
17939: );
17940: foreach my $item (@items) {
17941: if (@instdoms > 1) {
1.416 raeburn 17942: if ($env{'form.privacy_approval_instdom_'.$item} =~ /^(none|user|domain|auto)$/) {
1.357 raeburn 17943: $privacyhash{'approval'}{'instdom'}{$item} = $env{'form.privacy_approval_instdom_'.$item};
17944: }
17945: if (ref($current{'approval'}) eq 'HASH') {
17946: if (ref($current{'approval'}{'instdom'}) eq 'HASH') {
17947: unless ($privacyhash{'approval'}{'instdom'}{$item} eq $current{'approval'}{'instdom'}{$item}) {
17948: $changes{'approval'} = 1;
17949: }
17950: }
17951: } elsif ($privacyhash{'approval'}{'instdom'}{$item} ne 'auto') {
17952: $changes{'approval'} = 1;
17953: }
17954: }
17955: if (keys(%by_location) > 0) {
17956: if ($env{'form.privacy_approval_extdom_'.$item} =~ /^(none|user|domain|auto)$/) {
17957: $privacyhash{'approval'}{'extdom'}{$item} = $env{'form.privacy_approval_extdom_'.$item};
17958: }
17959: if (ref($current{'approval'}) eq 'HASH') {
17960: if (ref($current{'approval'}{'extdom'}) eq 'HASH') {
17961: unless ($privacyhash{'approval'}{'extdom'}{$item} eq $current{'approval'}{'extdom'}{$item}) {
17962: $changes{'approval'} = 1;
17963: }
17964: }
17965: } elsif ($privacyhash{'approval'}{'extdom'}{$item} ne 'auto') {
17966: $changes{'approval'} = 1;
17967: }
17968: }
17969: foreach my $status ('priv','unpriv') {
17970: my @possibles = sort(&Apache::loncommon::get_env_multiple('form.privacy_'.$status.'_'.$item));
17971: my @newvalues;
17972: foreach my $field (@possibles) {
17973: if (grep(/^\Q$field\E$/,@fields)) {
17974: $privacyhash{$status}{$item}{$field} = 1;
17975: push(@newvalues,$field);
17976: }
17977: }
17978: @newvalues = sort(@newvalues);
17979: if (ref($current{$status}) eq 'HASH') {
17980: if (ref($current{$status}{$item}) eq 'HASH') {
17981: my @currvalues = sort(keys(%{$current{$status}{$item}}));
17982: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
17983: if (@diffs > 0) {
17984: $changes{$status} = 1;
17985: }
17986: }
17987: } else {
17988: my @stdfields;
17989: foreach my $field (@fields) {
17990: if ($field eq 'id') {
17991: next if ($status eq 'unpriv');
17992: next if (($status eq 'priv') && ($item eq 'community'));
17993: }
17994: push(@stdfields,$field);
17995: }
17996: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
17997: if (@diffs > 0) {
17998: $changes{$status} = 1;
17999: }
18000: }
18001: }
18002: }
18003: if ((@instdoms > 1) || (keys(%by_location) > 0)) {
18004: my @statuses;
18005: if (ref($types) eq 'ARRAY') {
18006: @statuses = @{$types};
18007: }
18008: foreach my $type (@statuses,'default') {
18009: my @possfields = &Apache::loncommon::get_env_multiple('form.privacy_othdom_'.$type);
18010: my @newvalues;
18011: foreach my $field (sort(@possfields)) {
18012: if (grep(/^\Q$field\E$/,@fields)) {
18013: $privacyhash{'othdom'}{$type}{$field} = 1;
18014: push(@newvalues,$field);
18015: }
18016: }
18017: @newvalues = sort(@newvalues);
18018: if (ref($current{'othdom'}) eq 'HASH') {
18019: if (ref($current{'othdom'}{$type}) eq 'HASH') {
18020: my @currvalues = sort(keys(%{$current{'othdom'}{$type}}));
18021: my @diffs = &Apache::loncommon::compare_arrays(\@currvalues,\@newvalues);
18022: if (@diffs > 0) {
18023: $changes{'othdom'} = 1;
18024: }
18025: }
18026: } else {
18027: my @stdfields = ('lastname','firstname','middlename','generation','permanentemail');
18028: my @diffs = &Apache::loncommon::compare_arrays(\@stdfields,\@newvalues);
18029: if (@diffs > 0) {
18030: $changes{'othdom'} = 1;
18031: }
18032: }
18033: }
1.417 raeburn 18034: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
18035: my %notify;
18036: foreach my $possdc (&Apache::loncommon::get_env_multiple('form.privacy_notify')) {
18037: if (exists($domcoords{$possdc})) {
18038: $notify{$possdc} = 1;
18039: }
18040: }
18041: my $notify = join(',',sort(keys(%notify)));
18042: if ($current{'notify'} ne $notify) {
18043: $changes{'notify'} = 1;
18044: }
18045: $privacyhash{'notify'} = $notify;
1.357 raeburn 18046: }
18047: my %confighash = (
18048: privacy => \%privacyhash,
18049: );
18050: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18051: if ($putresult eq 'ok') {
18052: if (keys(%changes) > 0) {
18053: $resulttext = &mt('Changes made: ').'<ul>';
1.417 raeburn 18054: foreach my $key ('approval','notify','othdom','priv','unpriv') {
1.357 raeburn 18055: if ($changes{$key}) {
18056: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18057: if ($key eq 'approval') {
18058: if (keys(%{$privacyhash{$key}{instdom}})) {
18059: $resulttext .= '<li>'.$titles{'instdom'}.'<ul>';
18060: foreach my $item (@items) {
18061: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{instdom}{$item}}.'</li>';
18062: }
18063: $resulttext .= '</ul></li>';
18064: }
18065: if (keys(%{$privacyhash{$key}{extdom}})) {
18066: $resulttext .= '<li>'.$titles{'extdom'}.'<ul>';
18067: foreach my $item (@items) {
18068: $resulttext .= '<li>'.$roles{$item}.': '.$titles{$privacyhash{$key}{extdom}{$item}}.'</li>';
18069: }
18070: $resulttext .= '</ul></li>';
18071: }
1.417 raeburn 18072: } elsif ($key eq 'notify') {
18073: if ($privacyhash{$key}) {
18074: foreach my $dc (split(/,/,$privacyhash{$key})) {
18075: my ($dcname,$dcdom) = split(/:/,$dc);
18076: $resulttext .= '<li>'.&Apache::loncommon::plainname($dcname,$dcdom).'</li>';
18077: }
18078: } else {
18079: $resulttext .= '<li>'.&mt('No DCs to notify').'</li>';
18080: }
1.357 raeburn 18081: } elsif ($key eq 'othdom') {
18082: my @statuses;
18083: if (ref($types) eq 'ARRAY') {
18084: @statuses = @{$types};
18085: }
18086: if (ref($privacyhash{$key}) eq 'HASH') {
18087: foreach my $status (@statuses,'default') {
18088: if ($status eq 'default') {
18089: $resulttext .= '<li>'.$othertitle.': ';
18090: } elsif (ref($usertypes) eq 'HASH') {
18091: $resulttext .= '<li>'.$usertypes->{$status}.': ';
18092: } else {
18093: next;
18094: }
18095: if (ref($privacyhash{$key}{$status}) eq 'HASH') {
18096: if (keys(%{$privacyhash{$key}{$status}})) {
18097: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$status}}))));
18098: } else {
18099: $resulttext .= &mt('none');
18100: }
18101: }
18102: $resulttext .= '</li>';
18103: }
18104: }
18105: } else {
18106: foreach my $item (@items) {
18107: if (ref($privacyhash{$key}{$item}) eq 'HASH') {
18108: $resulttext .= '<li>'.$names{$item}.': ';
18109: if (keys(%{$privacyhash{$key}{$item}})) {
18110: $resulttext .= join(', ', map { $fieldnames{$_}; } (sort(keys(%{$privacyhash{$key}{$item}}))));
18111: } else {
18112: $resulttext .= &mt('none');
18113: }
18114: $resulttext .= '</li>';
18115: }
18116: }
18117: }
18118: $resulttext .= '</ul></li>';
18119: }
18120: }
1.421 raeburn 18121: $resulttext .= '</ul>';
1.427 raeburn 18122: if ($changes{'approval'}) {
18123: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18124: delete($domdefaults{'userapprovals'});
18125: if (ref($privacyhash{'approval'}) eq 'HASH') {
18126: foreach my $domtype ('instdom','extdom') {
18127: if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
18128: foreach my $roletype ('domain','author','course','community') {
18129: if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
18130: $domdefaults{'userapprovals'} = 1;
18131: last;
18132: }
18133: }
18134: }
18135: last if ($domdefaults{'userapprovals'});
18136: }
18137: }
18138: my $cachetime = 24*60*60;
18139: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18140: if (ref($lastactref) eq 'HASH') {
18141: $lastactref->{'domdefaults'} = 1;
18142: }
18143: }
1.357 raeburn 18144: } else {
18145: $resulttext = &mt('No changes made to user information settings');
18146: }
18147: } else {
18148: $resulttext = '<span class="LC_error">'.
18149: &mt('An error occurred: [_1]',$putresult).'</span>';
18150: }
18151: return $resulttext;
18152: }
18153:
1.354 raeburn 18154: sub modify_passwords {
18155: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.355 raeburn 18156: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
18157: $updatedefaults,$updateconf);
1.354 raeburn 18158: my $customfn = 'resetpw.html';
18159: if (ref($domconfig{'passwords'}) eq 'HASH') {
18160: %current = %{$domconfig{'passwords'}};
18161: }
18162: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
18163: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
18164: if (ref($types) eq 'ARRAY') {
18165: @oktypes = @{$types};
18166: }
18167: push(@oktypes,'default');
18168:
18169: my %titles = &Apache::lonlocal::texthash (
18170: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
18171: intauth_check => 'Check bcrypt cost if authenticated',
18172: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
18173: permanent => 'Permanent e-mail address',
18174: critical => 'Critical notification address',
18175: notify => 'Notification address',
18176: min => 'Minimum password length',
18177: max => 'Maximum password length',
18178: chars => 'Required characters',
18179: expire => 'Password expiration (days)',
1.356 raeburn 18180: numsaved => 'Number of previous passwords to save',
1.354 raeburn 18181: reset => 'Resetting Forgotten Password',
18182: intauth => 'Encryption of Stored Passwords (Internal Auth)',
18183: rules => 'Rules for LON-CAPA Passwords',
18184: crsownerchg => 'Course Owner Changing Student Passwords',
18185: username => 'Username',
18186: email => 'E-mail address',
18187: );
18188:
18189: #
18190: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
18191: #
18192: my (%curr_defaults,%save_defaults);
18193: if (ref($domconfig{'defaults'}) eq 'HASH') {
18194: foreach my $key (keys(%{$domconfig{'defaults'}})) {
18195: if ($key =~ /^intauth_(cost|check|switch)$/) {
18196: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
18197: } else {
18198: $save_defaults{$key} = $domconfig{'defaults'}{$key};
18199: }
18200: }
18201: }
18202: my %staticdefaults = (
18203: 'resetlink' => 2,
18204: 'resetcase' => \@oktypes,
18205: 'resetprelink' => 'both',
18206: 'resetemail' => ['critical','notify','permanent'],
18207: 'intauth_cost' => 10,
18208: 'intauth_check' => 0,
18209: 'intauth_switch' => 0,
18210: );
1.365 raeburn 18211: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.354 raeburn 18212: foreach my $type (@oktypes) {
18213: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
18214: }
18215: my $linklife = $env{'form.passwords_link'};
18216: $linklife =~ s/^\s+|\s+$//g;
18217: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
18218: $newvalues{'resetlink'} = $linklife;
18219: if ($current{'resetlink'}) {
18220: if ($current{'resetlink'} ne $linklife) {
18221: $changes{'reset'} = 1;
18222: }
1.368 raeburn 18223: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18224: if ($staticdefaults{'resetlink'} ne $linklife) {
18225: $changes{'reset'} = 1;
18226: }
18227: }
18228: } elsif ($current{'resetlink'}) {
18229: $changes{'reset'} = 1;
18230: }
18231: my @casesens;
18232: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
18233: foreach my $case (sort(@posscase)) {
18234: if (grep(/^\Q$case\E$/,@oktypes)) {
18235: push(@casesens,$case);
18236: }
18237: }
18238: $newvalues{'resetcase'} = \@casesens;
18239: if (ref($current{'resetcase'}) eq 'ARRAY') {
18240: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
18241: if (@diffs > 0) {
18242: $changes{'reset'} = 1;
18243: }
1.368 raeburn 18244: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18245: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
18246: if (@diffs > 0) {
18247: $changes{'reset'} = 1;
18248: }
18249: }
18250: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
18251: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
18252: if (exists($current{'resetprelink'})) {
18253: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
18254: $changes{'reset'} = 1;
18255: }
1.368 raeburn 18256: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18257: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
18258: $changes{'reset'} = 1;
18259: }
18260: }
18261: } elsif ($current{'resetprelink'}) {
18262: $changes{'reset'} = 1;
18263: }
18264: foreach my $type (@oktypes) {
18265: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
18266: my @postlink;
18267: foreach my $item (sort(@possplink)) {
18268: if ($item =~ /^(email|username)$/) {
18269: push(@postlink,$item);
18270: }
18271: }
18272: $newvalues{'resetpostlink'}{$type} = \@postlink;
18273: unless ($changes{'reset'}) {
18274: if (ref($current{'resetpostlink'}) eq 'HASH') {
18275: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
18276: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
18277: if (@diffs > 0) {
18278: $changes{'reset'} = 1;
18279: }
18280: } else {
18281: $changes{'reset'} = 1;
18282: }
1.368 raeburn 18283: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18284: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
18285: if (@diffs > 0) {
18286: $changes{'reset'} = 1;
18287: }
18288: }
18289: }
18290: }
18291: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
18292: my @resetemail;
18293: foreach my $item (sort(@possemailsrc)) {
18294: if ($item =~ /^(permanent|critical|notify)$/) {
18295: push(@resetemail,$item);
18296: }
18297: }
18298: $newvalues{'resetemail'} = \@resetemail;
18299: unless ($changes{'reset'}) {
18300: if (ref($current{'resetemail'}) eq 'ARRAY') {
18301: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
18302: if (@diffs > 0) {
18303: $changes{'reset'} = 1;
18304: }
1.368 raeburn 18305: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.354 raeburn 18306: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
18307: if (@diffs > 0) {
18308: $changes{'reset'} = 1;
18309: }
18310: }
18311: }
18312: if ($env{'form.passwords_stdtext'} == 0) {
18313: $newvalues{'resetremove'} = 1;
18314: unless ($current{'resetremove'}) {
18315: $changes{'reset'} = 1;
18316: }
18317: } elsif ($current{'resetremove'}) {
18318: $changes{'reset'} = 1;
18319: }
18320: if ($env{'form.passwords_customfile.filename'} ne '') {
18321: my $servadm = $r->dir_config('lonAdmEMail');
18322: my ($configuserok,$author_ok,$switchserver) =
18323: &config_check($dom,$confname,$servadm);
18324: my $error;
18325: if ($configuserok eq 'ok') {
18326: if ($switchserver) {
18327: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
18328: } else {
18329: if ($author_ok eq 'ok') {
1.421 raeburn 18330: my $modified = [];
1.354 raeburn 18331: my ($result,$customurl) =
1.421 raeburn 18332: &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
18333: $confname,'customtext/resetpw','','',$customfn,
18334: $modified);
1.354 raeburn 18335: if ($result eq 'ok') {
18336: $newvalues{'resetcustom'} = $customurl;
18337: $changes{'reset'} = 1;
1.421 raeburn 18338: &update_modify_urls($r,$modified);
1.354 raeburn 18339: } else {
18340: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
18341: }
18342: } else {
18343: $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);
18344: }
18345: }
18346: } else {
18347: $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);
18348: }
18349: if ($error) {
18350: &Apache::lonnet::logthis($error);
18351: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18352: }
18353: } elsif ($current{'resetcustom'}) {
18354: if ($env{'form.passwords_custom_del'}) {
18355: $changes{'reset'} = 1;
18356: } else {
18357: $newvalues{'resetcustom'} = $current{'resetcustom'};
18358: }
18359: }
18360: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
18361: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
18362: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
18363: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
18364: $changes{'intauth'} = 1;
18365: }
18366: } else {
18367: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
18368: }
18369: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
18370: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
18371: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
18372: $changes{'intauth'} = 1;
18373: }
18374: } else {
18375: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18376: }
18377: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
18378: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
18379: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
18380: $changes{'intauth'} = 1;
18381: }
18382: } else {
18383: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
18384: }
18385: foreach my $item ('cost','check','switch') {
18386: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
18387: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
18388: $updatedefaults = 1;
18389: }
18390: }
1.405 raeburn 18391: &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.359 raeburn 18392: my %crsownerchg = (
18393: by => [],
18394: for => [],
18395: );
18396: foreach my $item ('by','for') {
18397: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
18398: foreach my $type (sort(@posstypes)) {
18399: if (grep(/^\Q$type\E$/,@oktypes)) {
18400: push(@{$crsownerchg{$item}},$type);
18401: }
18402: }
18403: }
18404: $newvalues{'crsownerchg'} = \%crsownerchg;
18405: if (ref($current{'crsownerchg'}) eq 'HASH') {
18406: foreach my $item ('by','for') {
18407: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
18408: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
18409: if (@diffs > 0) {
18410: $changes{'crsownerchg'} = 1;
18411: last;
18412: }
18413: }
18414: }
1.368 raeburn 18415: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.359 raeburn 18416: foreach my $item ('by','for') {
18417: if (@{$crsownerchg{$item}} > 0) {
18418: $changes{'crsownerchg'} = 1;
18419: last;
18420: }
1.354 raeburn 18421: }
18422: }
18423:
18424: my %confighash = (
18425: defaults => \%save_defaults,
18426: passwords => \%newvalues,
18427: );
18428: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
18429:
18430: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
18431: if ($putresult eq 'ok') {
18432: if (keys(%changes) > 0) {
18433: $resulttext = &mt('Changes made: ').'<ul>';
18434: foreach my $key ('reset','intauth','rules','crsownerchg') {
18435: if ($changes{$key}) {
1.355 raeburn 18436: unless ($key eq 'intauth') {
18437: $updateconf = 1;
18438: }
1.354 raeburn 18439: $resulttext .= '<li>'.$titles{$key}.':<ul>';
18440: if ($key eq 'reset') {
18441: if ($confighash{'passwords'}{'captcha'} eq 'original') {
18442: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
18443: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
18444: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.369 raeburn 18445: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
18446: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
18447: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
18448: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
18449: }
1.354 raeburn 18450: } else {
18451: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
18452: }
18453: if ($confighash{'passwords'}{'resetlink'}) {
18454: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
18455: } else {
18456: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
18457: &mt('Will default to 2 hours').'</li>';
18458: }
18459: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
18460: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
18461: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
18462: } else {
18463: my $casesens;
18464: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
18465: if ($type eq 'default') {
18466: $casesens .= $othertitle.', ';
18467: } elsif ($usertypes->{$type} ne '') {
18468: $casesens .= $usertypes->{$type}.', ';
18469: }
18470: }
18471: $casesens =~ s/\Q, \E$//;
18472: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
18473: }
18474: } else {
18475: $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>';
18476: }
18477: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
18478: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
18479: } else {
18480: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
18481: }
18482: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
18483: my $output;
18484: if (ref($types) eq 'ARRAY') {
18485: foreach my $type (@{$types}) {
18486: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
18487: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
18488: $output .= $usertypes->{$type}.' -- '.&mt('none');
18489: } else {
18490: $output .= $usertypes->{$type}.' -- '.
18491: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
18492: }
18493: }
18494: }
18495: }
18496: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
18497: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
18498: $output .= $othertitle.' -- '.&mt('none');
18499: } else {
18500: $output .= $othertitle.' -- '.
18501: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
18502: }
18503: }
18504: if ($output) {
18505: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
18506: } else {
18507: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
18508: }
18509: } else {
18510: $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>';
18511: }
18512: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
18513: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
18514: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
18515: } else {
18516: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
18517: }
18518: } else {
1.379 raeburn 18519: $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 18520: }
18521: if ($confighash{'passwords'}{'resetremove'}) {
18522: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
18523: } else {
18524: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
18525: }
18526: if ($confighash{'passwords'}{'resetcustom'}) {
18527: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.369 raeburn 18528: &mt('custom text'),600,500,undef,undef,
18529: undef,undef,'background-color:#ffffff');
18530: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.354 raeburn 18531: } else {
18532: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
18533: }
18534: } elsif ($key eq 'intauth') {
18535: foreach my $item ('cost','switch','check') {
18536: my $value = $save_defaults{$key.'_'.$item};
18537: if ($item eq 'switch') {
18538: my %optiondesc = &Apache::lonlocal::texthash (
18539: 0 => 'No',
18540: 1 => 'Yes',
18541: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
18542: );
18543: if ($value =~ /^(0|1|2)$/) {
18544: $value = $optiondesc{$value};
18545: } else {
18546: $value = &mt('none -- defaults to No');
18547: }
18548: } elsif ($item eq 'check') {
18549: my %optiondesc = &Apache::lonlocal::texthash (
18550: 0 => 'No',
18551: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
18552: 2 => 'Yes, disallow login if stored cost is less than domain default',
18553: );
18554: if ($value =~ /^(0|1|2)$/) {
18555: $value = $optiondesc{$value};
18556: } else {
18557: $value = &mt('none -- defaults to No');
18558: }
18559: }
18560: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
18561: }
18562: } elsif ($key eq 'rules') {
1.356 raeburn 18563: foreach my $rule ('min','max','expire','numsaved') {
1.354 raeburn 18564: if ($confighash{'passwords'}{$rule} eq '') {
18565: if ($rule eq 'min') {
1.356 raeburn 18566: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.365 raeburn 18567: ' '.&mt('Default of [_1] will be used',
18568: $Apache::lonnet::passwdmin).'</li>';
1.356 raeburn 18569: } else {
18570: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
1.354 raeburn 18571: }
18572: } else {
18573: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
18574: }
18575: }
1.370 raeburn 18576: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
18577: if (@{$confighash{'passwords'}{'chars'}} > 0) {
18578: my %rulenames = &Apache::lonlocal::texthash(
18579: uc => 'At least one upper case letter',
18580: lc => 'At least one lower case letter',
18581: num => 'At least one number',
18582: spec => 'At least one non-alphanumeric',
18583: );
18584: my $needed = '<ul><li>'.
18585: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
1.425 raeburn 18586: '</li></ul>';
1.370 raeburn 18587: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
18588: } else {
18589: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18590: }
18591: } else {
18592: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
18593: }
1.354 raeburn 18594: } elsif ($key eq 'crsownerchg') {
1.359 raeburn 18595: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
18596: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
18597: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
18598: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
18599: } else {
18600: my %crsownerstr;
18601: foreach my $item ('by','for') {
18602: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
18603: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
18604: if ($type eq 'default') {
18605: $crsownerstr{$item} .= $othertitle.', ';
18606: } elsif ($usertypes->{$type} ne '') {
18607: $crsownerstr{$item} .= $usertypes->{$type}.', ';
18608: }
18609: }
18610: $crsownerstr{$item} =~ s/\Q, \E$//;
18611: }
18612: }
18613: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
18614: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
18615: }
1.354 raeburn 18616: } else {
1.359 raeburn 18617: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
1.354 raeburn 18618: }
18619: }
18620: $resulttext .= '</ul></li>';
18621: }
18622: }
18623: $resulttext .= '</ul>';
18624: } else {
18625: $resulttext = &mt('No changes made to password settings');
18626: }
1.355 raeburn 18627: my $cachetime = 24*60*60;
1.354 raeburn 18628: if ($updatedefaults) {
18629: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18630: if (ref($lastactref) eq 'HASH') {
18631: $lastactref->{'domdefaults'} = 1;
18632: }
18633: }
1.355 raeburn 18634: if ($updateconf) {
18635: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
18636: if (ref($lastactref) eq 'HASH') {
18637: $lastactref->{'passwdconf'} = 1;
18638: }
18639: }
1.354 raeburn 18640: } else {
18641: $resulttext = '<span class="LC_error">'.
18642: &mt('An error occurred: [_1]',$putresult).'</span>';
18643: }
18644: if ($errors) {
18645: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18646: $errors.'</ul></p>';
18647: }
18648: return $resulttext;
18649: }
18650:
1.405 raeburn 18651: sub password_rule_changes {
18652: my ($prefix,$newvalues,$current,$changes) = @_;
18653: return unless ((ref($newvalues) eq 'HASH') &&
18654: (ref($current) eq 'HASH') &&
18655: (ref($changes) eq 'HASH'));
18656: my (@rules,%staticdefaults);
18657: if ($prefix eq 'passwords') {
18658: @rules = ('min','max','expire','numsaved');
1.421 raeburn 18659: } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
1.405 raeburn 18660: @rules = ('min','max');
18661: }
18662: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
18663: foreach my $rule (@rules) {
18664: $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
18665: my $ruleok;
18666: if ($rule eq 'expire') {
18667: if (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+(|\.\d*)$/) &&
18668: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18669: $ruleok = 1;
18670: }
18671: } elsif ($rule eq 'min') {
18672: if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
18673: if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
18674: $ruleok = 1;
18675: }
18676: }
18677: } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
18678: ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
18679: $ruleok = 1;
18680: }
18681: if ($ruleok) {
18682: $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
18683: if (exists($current->{$rule})) {
18684: if ($newvalues->{$rule} ne $current->{$rule}) {
18685: $changes->{'rules'} = 1;
18686: }
18687: } elsif ($rule eq 'min') {
18688: if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
18689: $changes->{'rules'} = 1;
18690: }
18691: } else {
18692: $changes->{'rules'} = 1;
18693: }
18694: } elsif (exists($current->{$rule})) {
18695: $changes->{'rules'} = 1;
18696: }
18697: }
18698: my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
18699: my @chars;
18700: foreach my $item (sort(@posschars)) {
18701: if ($item =~ /^(uc|lc|num|spec)$/) {
18702: push(@chars,$item);
18703: }
18704: }
18705: $newvalues->{'chars'} = \@chars;
18706: unless ($changes->{'rules'}) {
18707: if (ref($current->{'chars'}) eq 'ARRAY') {
18708: my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
18709: if (@diffs > 0) {
18710: $changes->{'rules'} = 1;
18711: }
18712: } else {
18713: if (@chars > 0) {
18714: $changes->{'rules'} = 1;
18715: }
18716: }
18717: }
18718: return;
18719: }
18720:
1.28 raeburn 18721: sub modify_usercreation {
1.27 raeburn 18722: my ($dom,%domconfig) = @_;
1.224 raeburn 18723: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 18724: my $warningmsg;
1.27 raeburn 18725: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18726: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.224 raeburn 18727: if ($key eq 'cancreate') {
18728: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18729: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.303 raeburn 18730: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
18731: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18732: } else {
1.224 raeburn 18733: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18734: }
18735: }
18736: }
18737: } elsif ($key eq 'email_rule') {
18738: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18739: } else {
18740: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18741: }
1.27 raeburn 18742: }
18743: }
18744: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 18745: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.224 raeburn 18746: my @contexts = ('author','course','requestcrs');
1.34 raeburn 18747: foreach my $item(@contexts) {
1.224 raeburn 18748: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 18749: }
1.34 raeburn 18750: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
18751: foreach my $item (@contexts) {
1.224 raeburn 18752: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
18753: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 18754: }
1.27 raeburn 18755: }
1.34 raeburn 18756: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
18757: foreach my $item (@contexts) {
1.43 raeburn 18758: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 18759: if ($cancreate{$item} ne 'any') {
18760: push(@{$changes{'cancreate'}},$item);
18761: }
18762: } else {
18763: if ($cancreate{$item} ne 'none') {
18764: push(@{$changes{'cancreate'}},$item);
18765: }
1.27 raeburn 18766: }
18767: }
18768: } else {
1.43 raeburn 18769: foreach my $item (@contexts) {
1.34 raeburn 18770: push(@{$changes{'cancreate'}},$item);
18771: }
1.27 raeburn 18772: }
1.34 raeburn 18773:
1.27 raeburn 18774: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
18775: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
18776: if (!grep(/^\Q$type\E$/,@username_rule)) {
18777: push(@{$changes{'username_rule'}},$type);
18778: }
18779: }
18780: foreach my $type (@username_rule) {
18781: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
18782: push(@{$changes{'username_rule'}},$type);
18783: }
18784: }
18785: } else {
18786: push(@{$changes{'username_rule'}},@username_rule);
18787: }
18788:
1.32 raeburn 18789: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
18790: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
18791: if (!grep(/^\Q$type\E$/,@id_rule)) {
18792: push(@{$changes{'id_rule'}},$type);
18793: }
18794: }
18795: foreach my $type (@id_rule) {
18796: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
18797: push(@{$changes{'id_rule'}},$type);
18798: }
18799: }
18800: } else {
18801: push(@{$changes{'id_rule'}},@id_rule);
18802: }
18803:
1.43 raeburn 18804: my @authen_contexts = ('author','course','domain');
1.325 raeburn 18805: my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 18806: my %authhash;
1.43 raeburn 18807: foreach my $item (@authen_contexts) {
1.28 raeburn 18808: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
18809: foreach my $auth (@authtypes) {
18810: if (grep(/^\Q$auth\E$/,@authallowed)) {
18811: $authhash{$item}{$auth} = 1;
18812: } else {
18813: $authhash{$item}{$auth} = 0;
18814: }
18815: }
18816: }
18817: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 18818: foreach my $item (@authen_contexts) {
1.28 raeburn 18819: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
18820: foreach my $auth (@authtypes) {
18821: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
18822: push(@{$changes{'authtypes'}},$item);
18823: last;
18824: }
18825: }
18826: }
18827: }
18828: } else {
1.43 raeburn 18829: foreach my $item (@authen_contexts) {
1.28 raeburn 18830: push(@{$changes{'authtypes'}},$item);
18831: }
18832: }
18833:
1.224 raeburn 18834: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
18835: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
18836: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
18837: $save_usercreate{'id_rule'} = \@id_rule;
18838: $save_usercreate{'username_rule'} = \@username_rule,
18839: $save_usercreate{'authtypes'} = \%authhash;
18840:
1.27 raeburn 18841: my %usercreation_hash = (
1.224 raeburn 18842: usercreation => \%save_usercreate,
18843: );
1.27 raeburn 18844:
18845: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
18846: $dom);
1.50 raeburn 18847:
1.224 raeburn 18848: if ($putresult eq 'ok') {
18849: if (keys(%changes) > 0) {
18850: $resulttext = &mt('Changes made:').'<ul>';
18851: if (ref($changes{'cancreate'}) eq 'ARRAY') {
18852: my %lt = &usercreation_types();
18853: foreach my $type (@{$changes{'cancreate'}}) {
18854: my $chgtext = $lt{$type}.', ';
18855: if ($cancreate{$type} eq 'none') {
18856: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
18857: } elsif ($cancreate{$type} eq 'any') {
18858: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
18859: } elsif ($cancreate{$type} eq 'official') {
18860: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
18861: } elsif ($cancreate{$type} eq 'unofficial') {
18862: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
18863: }
18864: $resulttext .= '<li>'.$chgtext.'</li>';
18865: }
18866: }
18867: if (ref($changes{'username_rule'}) eq 'ARRAY') {
18868: my ($rules,$ruleorder) =
18869: &Apache::lonnet::inst_userrules($dom,'username');
18870: my $chgtext = '<ul>';
18871: foreach my $type (@username_rule) {
18872: if (ref($rules->{$type}) eq 'HASH') {
18873: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
18874: }
18875: }
18876: $chgtext .= '</ul>';
18877: if (@username_rule > 0) {
18878: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18879: } else {
18880: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
18881: }
18882: }
18883: if (ref($changes{'id_rule'}) eq 'ARRAY') {
18884: my ($idrules,$idruleorder) =
18885: &Apache::lonnet::inst_userrules($dom,'id');
18886: my $chgtext = '<ul>';
18887: foreach my $type (@id_rule) {
18888: if (ref($idrules->{$type}) eq 'HASH') {
18889: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
18890: }
18891: }
18892: $chgtext .= '</ul>';
18893: if (@id_rule > 0) {
18894: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
18895: } else {
18896: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
18897: }
18898: }
18899: my %authname = &authtype_names();
18900: my %context_title = &context_names();
18901: if (ref($changes{'authtypes'}) eq 'ARRAY') {
18902: my $chgtext = '<ul>';
18903: foreach my $type (@{$changes{'authtypes'}}) {
18904: my @allowed;
18905: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
18906: foreach my $auth (@authtypes) {
18907: if ($authhash{$type}{$auth}) {
18908: push(@allowed,$authname{$auth});
18909: }
18910: }
18911: if (@allowed > 0) {
18912: $chgtext .= join(', ',@allowed).'</li>';
18913: } else {
18914: $chgtext .= &mt('none').'</li>';
18915: }
18916: }
18917: $chgtext .= '</ul>';
18918: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
18919: $resulttext .= '</li>';
18920: }
18921: $resulttext .= '</ul>';
18922: } else {
18923: $resulttext = &mt('No changes made to user creation settings');
18924: }
18925: } else {
18926: $resulttext = '<span class="LC_error">'.
18927: &mt('An error occurred: [_1]',$putresult).'</span>';
18928: }
18929: if ($warningmsg ne '') {
18930: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
18931: }
18932: return $resulttext;
18933: }
18934:
18935: sub modify_selfcreation {
1.305 raeburn 18936: my ($dom,$lastactref,%domconfig) = @_;
18937: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
18938: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
18939: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.303 raeburn 18940: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
18941: if (ref($typesref) eq 'ARRAY') {
18942: @types = @{$typesref};
18943: }
18944: if (ref($usertypesref) eq 'HASH') {
18945: %usertypes = %{$usertypesref};
1.228 raeburn 18946: }
1.303 raeburn 18947: $usertypes{'default'} = $othertitle;
1.224 raeburn 18948: #
18949: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
18950: #
18951: if (ref($domconfig{'usercreation'}) eq 'HASH') {
18952: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
18953: if ($key eq 'cancreate') {
18954: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
18955: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
18956: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.303 raeburn 18957: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
18958: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
18959: ($item eq 'emailusername') || ($item eq 'shibenv') ||
18960: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
1.305 raeburn 18961: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.224 raeburn 18962: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18963: } else {
18964: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
18965: }
18966: }
18967: }
18968: } elsif ($key eq 'email_rule') {
18969: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
18970: } else {
18971: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
18972: }
18973: }
18974: }
18975: #
18976: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
18977: #
18978: if (ref($domconfig{'usermodification'}) eq 'HASH') {
18979: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
18980: if ($key eq 'selfcreate') {
18981: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
18982: } else {
18983: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
18984: }
18985: }
18986: }
1.305 raeburn 18987: #
18988: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
18989: #
18990: if (ref($domconfig{'inststatus'}) eq 'HASH') {
18991: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
18992: if ($key eq 'inststatusguest') {
18993: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
18994: } else {
18995: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
18996: }
18997: }
18998: }
1.224 raeburn 18999:
19000: my @contexts = ('selfcreate');
19001: @{$cancreate{'selfcreate'}} = ();
19002: %{$cancreate{'emailusername'}} = ();
1.305 raeburn 19003: if (@types) {
19004: @{$cancreate{'statustocreate'}} = ();
19005: }
1.236 raeburn 19006: %{$cancreate{'selfcreateprocessing'}} = ();
1.240 raeburn 19007: %{$cancreate{'shibenv'}} = ();
1.303 raeburn 19008: %{$cancreate{'emailverified'}} = ();
1.305 raeburn 19009: %{$cancreate{'emailoptions'}} = ();
1.303 raeburn 19010: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 19011: my %selfcreatetypes = (
19012: sso => 'users authenticated by institutional single sign on',
19013: login => 'users authenticated by institutional log-in',
1.303 raeburn 19014: email => 'users verified by e-mail',
1.50 raeburn 19015: );
1.224 raeburn 19016: #
19017: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
19018: # is permitted.
19019: #
1.305 raeburn 19020: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.236 raeburn 19021:
1.305 raeburn 19022: my (@statuses,%email_rule);
1.228 raeburn 19023: foreach my $item ('login','sso','email') {
1.224 raeburn 19024: if ($item eq 'email') {
1.236 raeburn 19025: if ($env{'form.cancreate_email'}) {
1.305 raeburn 19026: if (@types) {
19027: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
19028: foreach my $status (@poss_statuses) {
19029: if (grep(/^\Q$status\E$/,(@types,'default'))) {
19030: push(@statuses,$status);
19031: }
19032: }
19033: $save_inststatus{'inststatusguest'} = \@statuses;
19034: } else {
19035: push(@statuses,'default');
19036: }
19037: if (@statuses) {
19038: my %curr_rule;
19039: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
19040: foreach my $type (@statuses) {
19041: $curr_rule{$type} = $curr_usercreation{'email_rule'};
1.303 raeburn 19042: }
1.305 raeburn 19043: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
19044: foreach my $type (@statuses) {
19045: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
19046: }
19047: }
19048: push(@{$cancreate{'selfcreate'}},'email');
19049: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
19050: my %curremaildom;
19051: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
19052: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
19053: }
19054: foreach my $type (@statuses) {
19055: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
19056: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
19057: }
19058: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
19059: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
19060: }
19061: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
19062: #
19063: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
19064: #
19065: my $chosen = $1;
19066: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
19067: my $emaildom;
19068: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
1.425 raeburn 19069: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
1.305 raeburn 19070: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
19071: if (ref($curremaildom{$type}) eq 'HASH') {
19072: if (exists($curremaildom{$type}{$chosen})) {
19073: if ($curremaildom{$type}{$chosen} ne $emaildom) {
19074: push(@{$changes{'cancreate'}},'emaildomain');
19075: }
19076: } elsif ($emaildom ne '') {
19077: push(@{$changes{'cancreate'}},'emaildomain');
19078: }
19079: } elsif ($emaildom ne '') {
19080: push(@{$changes{'cancreate'}},'emaildomain');
1.425 raeburn 19081: }
1.305 raeburn 19082: }
19083: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19084: } elsif ($chosen eq 'custom') {
19085: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
19086: $email_rule{$type} = [];
19087: if (ref($emailrules) eq 'HASH') {
19088: foreach my $rule (@possemail_rules) {
19089: if (exists($emailrules->{$rule})) {
19090: push(@{$email_rule{$type}},$rule);
19091: }
19092: }
19093: }
19094: if (@{$email_rule{$type}}) {
19095: $cancreate{'emailoptions'}{$type} = 'custom';
19096: if (ref($curr_rule{$type}) eq 'ARRAY') {
19097: if (@{$curr_rule{$type}} > 0) {
19098: foreach my $rule (@{$curr_rule{$type}}) {
19099: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
19100: push(@{$changes{'email_rule'}},$type);
19101: }
19102: }
19103: }
19104: foreach my $type (@{$email_rule{$type}}) {
19105: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
19106: push(@{$changes{'email_rule'}},$type);
19107: }
19108: }
19109: } else {
19110: push(@{$changes{'email_rule'}},$type);
19111: }
19112: }
19113: } else {
19114: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
19115: }
19116: }
19117: }
19118: if (@types) {
19119: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19120: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
19121: if (@changed) {
19122: push(@{$changes{'inststatus'}},'inststatusguest');
19123: }
19124: } else {
19125: push(@{$changes{'inststatus'}},'inststatusguest');
19126: }
19127: }
19128: } else {
19129: delete($env{'form.cancreate_email'});
19130: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19131: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19132: push(@{$changes{'inststatus'}},'inststatusguest');
19133: }
19134: }
19135: }
19136: } else {
19137: $save_inststatus{'inststatusguest'} = [];
19138: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
19139: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
19140: push(@{$changes{'inststatus'}},'inststatusguest');
1.236 raeburn 19141: }
19142: }
1.224 raeburn 19143: }
19144: } else {
19145: if ($env{'form.cancreate_'.$item}) {
19146: push(@{$cancreate{'selfcreate'}},$item);
19147: }
19148: }
19149: }
1.305 raeburn 19150: my (%userinfo,%savecaptcha);
1.224 raeburn 19151: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
19152: #
1.228 raeburn 19153: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
19154: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.224 raeburn 19155: #
1.236 raeburn 19156:
1.244 raeburn 19157: if ($env{'form.cancreate_email'}) {
1.228 raeburn 19158: push(@contexts,'emailusername');
1.305 raeburn 19159: if (@statuses) {
19160: foreach my $type (@statuses) {
1.228 raeburn 19161: if (ref($infofields) eq 'ARRAY') {
19162: foreach my $field (@{$infofields}) {
19163: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
19164: $cancreate{'emailusername'}{$type}{$field} = $1;
19165: }
19166: }
1.224 raeburn 19167: }
19168: }
19169: }
19170: #
19171: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.303 raeburn 19172: # queued requests for self-creation of account verified by e-mail.
1.224 raeburn 19173: #
19174:
19175: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
19176: @approvalnotify = sort(@approvalnotify);
19177: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
19178: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19179: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
19180: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
19181: push(@{$changes{'cancreate'}},'notify');
19182: }
19183: } else {
19184: if ($cancreate{'notify'}{'approval'}) {
19185: push(@{$changes{'cancreate'}},'notify');
19186: }
19187: }
19188: } elsif ($cancreate{'notify'}{'approval'}) {
19189: push(@{$changes{'cancreate'}},'notify');
19190: }
19191:
19192: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
19193: }
19194: #
1.236 raeburn 19195: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.224 raeburn 19196: # institutional log-in.
19197: #
19198: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
19199: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
19200: ($domdefaults{'auth_def'} eq 'localauth'))) {
19201: $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.').' '.
19202: &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.');
19203: }
19204: }
19205: my @fields = ('lastname','firstname','middlename','generation',
19206: 'permanentemail','id');
1.240 raeburn 19207: my @shibfields = (@fields,'inststatus');
1.224 raeburn 19208: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19209: #
19210: # Where usernames may created for institutional log-in and/or institutional single sign on:
19211: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
19212: # may self-create accounts
19213: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
19214: # which the user may supply, if institutional data is unavailable.
19215: #
19216: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.303 raeburn 19217: if (@types) {
1.305 raeburn 19218: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
19219: push(@contexts,'statustocreate');
1.303 raeburn 19220: foreach my $type (@types) {
1.224 raeburn 19221: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
19222: foreach my $field (@fields) {
19223: if (grep(/^\Q$field\E$/,@modifiable)) {
19224: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
19225: } else {
19226: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
19227: }
19228: }
19229: }
19230: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.303 raeburn 19231: foreach my $type (@types) {
1.224 raeburn 19232: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
19233: foreach my $field (@fields) {
19234: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
19235: $curr_usermodify{'selfcreate'}{$type}{$field}) {
19236: push(@{$changes{'selfcreate'}},$type);
19237: last;
19238: }
19239: }
19240: }
19241: }
19242: } else {
1.303 raeburn 19243: foreach my $type (@types) {
1.224 raeburn 19244: push(@{$changes{'selfcreate'}},$type);
19245: }
19246: }
19247: }
1.240 raeburn 19248: foreach my $field (@shibfields) {
19249: if ($env{'form.shibenv_'.$field} ne '') {
19250: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
19251: }
19252: }
19253: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
19254: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
19255: foreach my $field (@shibfields) {
19256: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
19257: push(@{$changes{'cancreate'}},'shibenv');
19258: }
19259: }
19260: } else {
19261: foreach my $field (@shibfields) {
19262: if ($env{'form.shibenv_'.$field}) {
19263: push(@{$changes{'cancreate'}},'shibenv');
19264: last;
19265: }
19266: }
19267: }
19268: }
1.224 raeburn 19269: }
19270: foreach my $item (@contexts) {
19271: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
19272: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
19273: if (ref($cancreate{$item}) eq 'ARRAY') {
19274: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
19275: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19276: push(@{$changes{'cancreate'}},$item);
19277: }
19278: }
19279: }
19280: }
19281: if (ref($cancreate{$item}) eq 'ARRAY') {
19282: foreach my $type (@{$cancreate{$item}}) {
19283: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
19284: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19285: push(@{$changes{'cancreate'}},$item);
19286: }
19287: }
19288: }
19289: }
19290: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
19291: if (ref($cancreate{$item}) eq 'HASH') {
1.305 raeburn 19292: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
19293: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19294: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
19295: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19296: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19297: push(@{$changes{'cancreate'}},$item);
19298: }
19299: }
19300: }
1.305 raeburn 19301: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19302: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19303: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19304: push(@{$changes{'cancreate'}},$item);
19305: }
1.224 raeburn 19306: }
19307: }
19308: }
1.305 raeburn 19309: foreach my $type (keys(%{$cancreate{$item}})) {
19310: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19311: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19312: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
19313: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.228 raeburn 19314: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19315: push(@{$changes{'cancreate'}},$item);
19316: }
19317: }
19318: } else {
19319: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19320: push(@{$changes{'cancreate'}},$item);
19321: }
19322: }
19323: }
1.305 raeburn 19324: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19325: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.228 raeburn 19326: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19327: push(@{$changes{'cancreate'}},$item);
19328: }
1.224 raeburn 19329: }
19330: }
19331: }
19332: }
19333: } elsif ($curr_usercreation{'cancreate'}{$item}) {
19334: if (ref($cancreate{$item}) eq 'ARRAY') {
19335: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
19336: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19337: push(@{$changes{'cancreate'}},$item);
19338: }
19339: }
1.305 raeburn 19340: }
19341: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
19342: if (ref($cancreate{$item}) eq 'HASH') {
19343: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19344: push(@{$changes{'cancreate'}},$item);
1.224 raeburn 19345: }
19346: }
19347: } elsif ($item eq 'emailusername') {
1.228 raeburn 19348: if (ref($cancreate{$item}) eq 'HASH') {
19349: foreach my $type (keys(%{$cancreate{$item}})) {
19350: if (ref($cancreate{$item}{$type}) eq 'HASH') {
19351: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
19352: if ($cancreate{$item}{$type}{$field}) {
19353: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
19354: push(@{$changes{'cancreate'}},$item);
19355: }
19356: last;
19357: }
19358: }
19359: }
19360: }
1.224 raeburn 19361: }
19362: }
19363: }
19364: #
19365: # Populate %save_usercreate hash with updates to self-creation configuration.
19366: #
19367: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
19368: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.269 raeburn 19369: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.224 raeburn 19370: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
19371: if (ref($cancreate{'notify'}) eq 'HASH') {
19372: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
19373: }
1.236 raeburn 19374: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
19375: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
19376: }
1.303 raeburn 19377: if (ref($cancreate{'emailverified'}) eq 'HASH') {
19378: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
19379: }
1.305 raeburn 19380: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
19381: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
19382: }
1.303 raeburn 19383: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
19384: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
19385: }
1.224 raeburn 19386: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19387: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
19388: }
1.240 raeburn 19389: if (ref($cancreate{'shibenv'}) eq 'HASH') {
19390: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
19391: }
1.224 raeburn 19392: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.305 raeburn 19393: $save_usercreate{'email_rule'} = \%email_rule;
1.224 raeburn 19394:
19395: my %userconfig_hash = (
19396: usercreation => \%save_usercreate,
19397: usermodification => \%save_usermodify,
1.305 raeburn 19398: inststatus => \%save_inststatus,
1.224 raeburn 19399: );
1.305 raeburn 19400:
1.224 raeburn 19401: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
19402: $dom);
19403: #
1.305 raeburn 19404: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.224 raeburn 19405: #
1.27 raeburn 19406: if ($putresult eq 'ok') {
19407: if (keys(%changes) > 0) {
19408: $resulttext = &mt('Changes made:').'<ul>';
19409: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.224 raeburn 19410: my %lt = &selfcreation_types();
1.34 raeburn 19411: foreach my $type (@{$changes{'cancreate'}}) {
1.303 raeburn 19412: my $chgtext = '';
1.45 raeburn 19413: if ($type eq 'selfcreate') {
1.50 raeburn 19414: if (@{$cancreate{$type}} == 0) {
1.224 raeburn 19415: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 19416: } else {
1.224 raeburn 19417: $chgtext .= &mt('Self-creation of a new account is permitted for:').
19418: '<ul>';
1.50 raeburn 19419: foreach my $case (@{$cancreate{$type}}) {
19420: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
19421: }
19422: $chgtext .= '</ul>';
1.100 raeburn 19423: if (ref($cancreate{$type}) eq 'ARRAY') {
19424: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
19425: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
19426: if (@{$cancreate{'statustocreate'}} == 0) {
1.303 raeburn 19427: $chgtext .= '<span class="LC_warning">'.
19428: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
19429: '</span><br />';
19430: }
19431: }
19432: }
19433: if (grep(/^email$/,@{$cancreate{$type}})) {
1.305 raeburn 19434: if (!@statuses) {
19435: $chgtext .= '<span class="LC_warning">'.
19436: &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.").
19437: '</span><br />';
1.303 raeburn 19438:
1.100 raeburn 19439: }
19440: }
19441: }
1.43 raeburn 19442: }
1.240 raeburn 19443: } elsif ($type eq 'shibenv') {
19444: if (keys(%{$cancreate{$type}}) == 0) {
1.303 raeburn 19445: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.240 raeburn 19446: } else {
19447: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
19448: '<ul>';
19449: foreach my $field (@shibfields) {
19450: next if ($cancreate{$type}{$field} eq '');
19451: if ($field eq 'inststatus') {
19452: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
19453: } else {
19454: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
19455: }
19456: }
19457: $chgtext .= '</ul>';
1.303 raeburn 19458: }
1.93 raeburn 19459: } elsif ($type eq 'statustocreate') {
1.96 raeburn 19460: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
19461: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
19462: if (@{$cancreate{'selfcreate'}} > 0) {
19463: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 19464: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 19465: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.224 raeburn 19466: $chgtext .= '<br />'.
19467: '<span class="LC_warning">'.
19468: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
19469: '</span>';
19470: }
1.303 raeburn 19471: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 19472: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 19473: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
19474: } else {
19475: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
19476: }
19477: $chgtext .= '<ul>';
19478: foreach my $case (@{$cancreate{$type}}) {
19479: if ($case eq 'default') {
19480: $chgtext .= '<li>'.$othertitle.'</li>';
19481: } else {
1.303 raeburn 19482: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 19483: }
19484: }
1.100 raeburn 19485: $chgtext .= '</ul>';
19486: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.303 raeburn 19487: $chgtext .= '<span class="LC_warning">'.
1.224 raeburn 19488: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
19489: '</span>';
1.100 raeburn 19490: }
19491: }
19492: } else {
19493: if (@{$cancreate{$type}} == 0) {
19494: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
19495: } else {
19496: $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 19497: }
19498: }
1.303 raeburn 19499: $chgtext .= '<br />';
1.93 raeburn 19500: }
1.236 raeburn 19501: } elsif ($type eq 'selfcreateprocessing') {
19502: my %choices = &Apache::lonlocal::texthash (
19503: automatic => 'Automatic approval',
19504: approval => 'Queued for approval',
19505: );
1.305 raeburn 19506: if (@types) {
19507: if (@statuses) {
1.425 raeburn 19508: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
1.309 raeburn 19509: '<ul>';
1.305 raeburn 19510: foreach my $status (@statuses) {
19511: if ($status eq 'default') {
19512: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19513: } else {
1.305 raeburn 19514: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
1.303 raeburn 19515: }
19516: }
19517: $chgtext .= '</ul>';
19518: }
19519: } else {
19520: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
19521: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
19522: }
19523: } elsif ($type eq 'emailverified') {
19524: my %options = &Apache::lonlocal::texthash (
1.305 raeburn 19525: all => 'Same as e-mail',
19526: first => 'Omit @domain',
19527: free => 'Free to choose',
1.303 raeburn 19528: );
1.305 raeburn 19529: if (@types) {
19530: if (@statuses) {
1.303 raeburn 19531: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
19532: '<ul>';
1.305 raeburn 19533: foreach my $status (@statuses) {
1.362 raeburn 19534: if ($status eq 'default') {
1.305 raeburn 19535: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19536: } else {
1.305 raeburn 19537: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
1.303 raeburn 19538: }
19539: }
19540: $chgtext .= '</ul>';
19541: }
19542: } else {
1.305 raeburn 19543: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
1.304 raeburn 19544: $options{$cancreate{'emailverified'}{'default'}});
1.303 raeburn 19545: }
1.305 raeburn 19546: } elsif ($type eq 'emailoptions') {
19547: my %options = &Apache::lonlocal::texthash (
19548: any => 'Any e-mail',
19549: inst => 'Institutional only',
19550: noninst => 'Non-institutional only',
19551: custom => 'Custom restrictions',
19552: );
19553: if (@types) {
19554: if (@statuses) {
19555: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
19556: '<ul>';
19557: foreach my $status (@statuses) {
19558: if ($type eq 'default') {
19559: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
19560: } else {
19561: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
1.303 raeburn 19562: }
19563: }
1.305 raeburn 19564: $chgtext .= '</ul>';
19565: }
19566: } else {
19567: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
19568: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
19569: } else {
19570: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
19571: $options{$cancreate{'emailoptions'}{'default'}});
1.303 raeburn 19572: }
1.305 raeburn 19573: }
19574: } elsif ($type eq 'emaildomain') {
19575: my $output;
19576: if (@statuses) {
19577: foreach my $type (@statuses) {
19578: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
19579: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
19580: if ($type eq 'default') {
19581: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19582: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19583: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19584: } else {
19585: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
19586: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
19587: }
1.303 raeburn 19588: } else {
1.305 raeburn 19589: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19590: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
19591: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19592: } else {
19593: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
1.421 raeburn 19594: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
1.305 raeburn 19595: }
1.303 raeburn 19596: }
1.305 raeburn 19597: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
19598: if ($type eq 'default') {
19599: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19600: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19601: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
19602: } else {
19603: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
19604: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
19605: }
1.303 raeburn 19606: } else {
1.305 raeburn 19607: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
19608: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
19609: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
19610: } else {
19611: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
1.421 raeburn 19612: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
1.305 raeburn 19613: }
1.303 raeburn 19614: }
19615: }
19616: }
19617: }
1.305 raeburn 19618: }
19619: if ($output ne '') {
19620: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
19621: '<ul>'.$output.'</ul>';
1.236 raeburn 19622: }
1.165 raeburn 19623: } elsif ($type eq 'captcha') {
1.224 raeburn 19624: if ($savecaptcha{$type} eq 'notused') {
1.165 raeburn 19625: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
19626: } else {
19627: my %captchas = &captcha_phrases();
1.224 raeburn 19628: if ($captchas{$savecaptcha{$type}}) {
19629: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.165 raeburn 19630: } else {
1.210 raeburn 19631: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 19632: }
19633: }
19634: } elsif ($type eq 'recaptchakeys') {
19635: my ($privkey,$pubkey);
1.224 raeburn 19636: if (ref($savecaptcha{$type}) eq 'HASH') {
19637: $pubkey = $savecaptcha{$type}{'public'};
19638: $privkey = $savecaptcha{$type}{'private'};
1.165 raeburn 19639: }
19640: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
19641: if (!$pubkey) {
19642: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
19643: } else {
19644: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
19645: }
19646: if (!$privkey) {
19647: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
19648: } else {
19649: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
19650: }
19651: $chgtext .= '</ul>';
1.269 raeburn 19652: } elsif ($type eq 'recaptchaversion') {
19653: if ($savecaptcha{'captcha'} eq 'recaptcha') {
1.270 raeburn 19654: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
1.269 raeburn 19655: }
1.224 raeburn 19656: } elsif ($type eq 'emailusername') {
19657: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.305 raeburn 19658: if (@statuses) {
19659: foreach my $type (@statuses) {
1.228 raeburn 19660: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
19661: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.303 raeburn 19662: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.228 raeburn 19663: '<ul>';
19664: foreach my $field (@{$infofields}) {
19665: if ($cancreate{'emailusername'}{$type}{$field}) {
19666: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
19667: }
19668: }
1.245 raeburn 19669: $chgtext .= '</ul>';
19670: } else {
1.303 raeburn 19671: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.228 raeburn 19672: }
19673: } else {
1.303 raeburn 19674: $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 19675: }
19676: }
19677: }
19678: }
19679: } elsif ($type eq 'notify') {
1.303 raeburn 19680: my $numapprove = 0;
1.224 raeburn 19681: if (ref($changes{'cancreate'}) eq 'ARRAY') {
19682: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
19683: if ($cancreate{'notify'}{'approval'}) {
1.303 raeburn 19684: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
19685: $numapprove ++;
1.224 raeburn 19686: }
19687: }
1.43 raeburn 19688: }
1.303 raeburn 19689: unless ($numapprove) {
19690: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
19691: }
1.34 raeburn 19692: }
1.224 raeburn 19693: if ($chgtext) {
19694: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 19695: }
19696: }
19697: }
1.305 raeburn 19698: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 19699: my ($emailrules,$emailruleorder) =
19700: &Apache::lonnet::inst_userrules($dom,'email');
1.305 raeburn 19701: foreach my $type (@{$changes{'email_rule'}}) {
19702: if (ref($email_rule{$type}) eq 'ARRAY') {
19703: my $chgtext = '<ul>';
19704: foreach my $rule (@{$email_rule{$type}}) {
19705: if (ref($emailrules->{$rule}) eq 'HASH') {
19706: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
19707: }
19708: }
19709: $chgtext .= '</ul>';
1.310 raeburn 19710: my $typename;
1.305 raeburn 19711: if (@types) {
19712: if ($type eq 'default') {
19713: $typename = $othertitle;
19714: } else {
19715: $typename = $usertypes{$type};
1.425 raeburn 19716: }
1.305 raeburn 19717: $chgtext .= &mt('(Affiliation: [_1])',$typename);
19718: }
19719: if (@{$email_rule{$type}} > 0) {
19720: $resulttext .= '<li>'.
19721: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
19722: $usertypes{$type}).
19723: $chgtext.
19724: '</li>';
19725: } else {
19726: $resulttext .= '<li>'.
1.310 raeburn 19727: &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 19728: '</li>'.
1.310 raeburn 19729: &mt('(Affiliation: [_1])',$typename);
1.305 raeburn 19730: }
1.43 raeburn 19731: }
19732: }
1.305 raeburn 19733: }
19734: if (ref($changes{'inststatus'}) eq 'ARRAY') {
19735: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
19736: if (@{$save_inststatus{'inststatusguest'}} > 0) {
19737: my $chgtext = '<ul>';
19738: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
19739: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
19740: }
19741: $chgtext .= '</ul>';
19742: $resulttext .= '<li>'.
19743: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
19744: $chgtext.
19745: '</li>';
19746: } else {
19747: $resulttext .= '<li>'.
19748: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
19749: '</li>';
19750: }
1.43 raeburn 19751: }
19752: }
1.224 raeburn 19753: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
19754: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
19755: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19756: foreach my $type (@{$changes{'selfcreate'}}) {
19757: my $typename = $type;
1.303 raeburn 19758: if (keys(%usertypes) > 0) {
19759: if ($usertypes{$type} ne '') {
19760: $typename = $usertypes{$type};
1.224 raeburn 19761: }
19762: }
19763: my @modifiable;
19764: $resulttext .= '<li>'.
19765: &mt('Self-creation of account by users with status: [_1]',
19766: '<span class="LC_cusr_emph">'.$typename.'</span>').
19767: ' - '.&mt('modifiable fields (if institutional data blank): ');
19768: foreach my $field (@fields) {
19769: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
19770: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
1.28 raeburn 19771: }
19772: }
1.224 raeburn 19773: if (@modifiable > 0) {
19774: $resulttext .= join(', ',@modifiable);
1.43 raeburn 19775: } else {
1.224 raeburn 19776: $resulttext .= &mt('none');
1.43 raeburn 19777: }
1.224 raeburn 19778: $resulttext .= '</li>';
1.28 raeburn 19779: }
1.224 raeburn 19780: $resulttext .= '</ul></li>';
1.28 raeburn 19781: }
1.27 raeburn 19782: $resulttext .= '</ul>';
1.305 raeburn 19783: my $cachetime = 24*60*60;
19784: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
19785: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19786: if (ref($lastactref) eq 'HASH') {
19787: $lastactref->{'domdefaults'} = 1;
19788: }
1.27 raeburn 19789: } else {
1.224 raeburn 19790: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 19791: }
19792: } else {
19793: $resulttext = '<span class="LC_error">'.
1.23 raeburn 19794: &mt('An error occurred: [_1]',$putresult).'</span>';
19795: }
1.43 raeburn 19796: if ($warningmsg ne '') {
19797: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
19798: }
1.23 raeburn 19799: return $resulttext;
19800: }
19801:
1.165 raeburn 19802: sub process_captcha {
1.369 raeburn 19803: my ($container,$changes,$newsettings,$currsettings) = @_;
19804: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.165 raeburn 19805: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
19806: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
19807: $newsettings->{'captcha'} = 'original';
19808: }
1.369 raeburn 19809: my %current;
19810: if (ref($currsettings) eq 'HASH') {
19811: %current = %{$currsettings};
19812: }
19813: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 19814: if ($container eq 'cancreate') {
1.169 raeburn 19815: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19816: push(@{$changes->{'cancreate'}},'captcha');
19817: } elsif (!defined($changes->{'cancreate'})) {
19818: $changes->{'cancreate'} = ['captcha'];
19819: }
1.368 raeburn 19820: } elsif ($container eq 'passwords') {
19821: $changes->{'reset'} = 1;
1.169 raeburn 19822: } else {
19823: $changes->{'captcha'} = 1;
1.165 raeburn 19824: }
19825: }
1.269 raeburn 19826: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.165 raeburn 19827: if ($newsettings->{'captcha'} eq 'recaptcha') {
19828: $newpub = $env{'form.'.$container.'_recaptchapub'};
19829: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.250 raeburn 19830: $newpub =~ s/[^\w\-]//g;
19831: $newpriv =~ s/[^\w\-]//g;
1.169 raeburn 19832: $newsettings->{'recaptchakeys'} = {
19833: public => $newpub,
19834: private => $newpriv,
19835: };
1.269 raeburn 19836: $newversion = $env{'form.'.$container.'_recaptchaversion'};
19837: $newversion =~ s/\D//g;
19838: if ($newversion ne '2') {
19839: $newversion = 1;
19840: }
19841: $newsettings->{'recaptchaversion'} = $newversion;
1.165 raeburn 19842: }
1.369 raeburn 19843: if (ref($current{'recaptchakeys'}) eq 'HASH') {
19844: $currpub = $current{'recaptchakeys'}{'public'};
19845: $currpriv = $current{'recaptchakeys'}{'private'};
1.179 raeburn 19846: unless ($newsettings->{'captcha'} eq 'recaptcha') {
19847: $newsettings->{'recaptchakeys'} = {
19848: public => '',
19849: private => '',
19850: }
19851: }
1.165 raeburn 19852: }
1.369 raeburn 19853: if ($current{'captcha'} eq 'recaptcha') {
19854: $currversion = $current{'recaptchaversion'};
1.269 raeburn 19855: if ($currversion ne '2') {
19856: $currversion = 1;
19857: }
19858: }
19859: if ($currversion ne $newversion) {
19860: if ($container eq 'cancreate') {
19861: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19862: push(@{$changes->{'cancreate'}},'recaptchaversion');
19863: } elsif (!defined($changes->{'cancreate'})) {
19864: $changes->{'cancreate'} = ['recaptchaversion'];
19865: }
1.368 raeburn 19866: } elsif ($container eq 'passwords') {
19867: $changes->{'reset'} = 1;
1.269 raeburn 19868: } else {
19869: $changes->{'recaptchaversion'} = 1;
19870: }
19871: }
1.165 raeburn 19872: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 19873: if ($container eq 'cancreate') {
19874: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
19875: push(@{$changes->{'cancreate'}},'recaptchakeys');
19876: } elsif (!defined($changes->{'cancreate'})) {
19877: $changes->{'cancreate'} = ['recaptchakeys'];
19878: }
1.368 raeburn 19879: } elsif ($container eq 'passwords') {
19880: $changes->{'reset'} = 1;
1.169 raeburn 19881: } else {
1.210 raeburn 19882: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 19883: }
19884: }
19885: return;
19886: }
19887:
1.33 raeburn 19888: sub modify_usermodification {
19889: my ($dom,%domconfig) = @_;
1.224 raeburn 19890: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 19891: if (ref($domconfig{'usermodification'}) eq 'HASH') {
19892: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.224 raeburn 19893: if ($key eq 'selfcreate') {
19894: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
19895: } else {
19896: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
19897: }
1.33 raeburn 19898: }
19899: }
1.443 raeburn 19900: my @contexts = ('author','coauthor','course');
1.33 raeburn 19901: my %context_title = (
19902: author => 'In author context',
1.443 raeburn 19903: coauthor => 'As co-author manager',
1.33 raeburn 19904: course => 'In course context',
19905: );
19906: my @fields = ('lastname','firstname','middlename','generation',
19907: 'permanentemail','id');
19908: my %roles = (
19909: author => ['ca','aa'],
1.443 raeburn 19910: coauthor => ['ca','aa'],
1.33 raeburn 19911: course => ['st','ep','ta','in','cr'],
19912: );
19913: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
19914: foreach my $context (@contexts) {
1.443 raeburn 19915: my $prefix = 'canmodify';
19916: if ($context eq 'coauthor') {
19917: $prefix = 'cacanmodify';
19918: }
1.33 raeburn 19919: foreach my $role (@{$roles{$context}}) {
1.443 raeburn 19920: my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 19921: foreach my $item (@fields) {
19922: if (grep(/^\Q$item\E$/,@modifiable)) {
19923: $modifyhash{$context}{$role}{$item} = 1;
19924: } else {
19925: $modifyhash{$context}{$role}{$item} = 0;
19926: }
19927: }
19928: }
19929: if (ref($curr_usermodification{$context}) eq 'HASH') {
19930: foreach my $role (@{$roles{$context}}) {
19931: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
19932: foreach my $field (@fields) {
19933: if ($modifyhash{$context}{$role}{$field} ne
19934: $curr_usermodification{$context}{$role}{$field}) {
19935: push(@{$changes{$context}},$role);
19936: last;
19937: }
19938: }
19939: }
19940: }
19941: } else {
19942: foreach my $context (@contexts) {
19943: foreach my $role (@{$roles{$context}}) {
19944: push(@{$changes{$context}},$role);
19945: }
19946: }
19947: }
19948: }
19949: my %usermodification_hash = (
19950: usermodification => \%modifyhash,
19951: );
19952: my $putresult = &Apache::lonnet::put_dom('configuration',
19953: \%usermodification_hash,$dom);
19954: if ($putresult eq 'ok') {
19955: if (keys(%changes) > 0) {
19956: $resulttext = &mt('Changes made: ').'<ul>';
19957: foreach my $context (@contexts) {
19958: if (ref($changes{$context}) eq 'ARRAY') {
19959: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
19960: if (ref($changes{$context}) eq 'ARRAY') {
19961: foreach my $role (@{$changes{$context}}) {
19962: my $rolename;
1.224 raeburn 19963: if ($role eq 'cr') {
19964: $rolename = &mt('Custom');
1.33 raeburn 19965: } else {
1.224 raeburn 19966: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 19967: }
19968: my @modifiable;
1.224 raeburn 19969: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 19970: foreach my $field (@fields) {
19971: if ($modifyhash{$context}{$role}{$field}) {
19972: push(@modifiable,$fieldtitles{$field});
19973: }
19974: }
19975: if (@modifiable > 0) {
19976: $resulttext .= join(', ',@modifiable);
19977: } else {
19978: $resulttext .= &mt('none');
19979: }
19980: $resulttext .= '</li>';
19981: }
19982: $resulttext .= '</ul></li>';
19983: }
19984: }
19985: }
19986: $resulttext .= '</ul>';
19987: } else {
19988: $resulttext = &mt('No changes made to user modification settings');
19989: }
19990: } else {
19991: $resulttext = '<span class="LC_error">'.
19992: &mt('An error occurred: [_1]',$putresult).'</span>';
19993: }
19994: return $resulttext;
19995: }
19996:
1.43 raeburn 19997: sub modify_defaults {
1.212 raeburn 19998: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 19999: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 raeburn 20000: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.294 raeburn 20001: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.354 raeburn 20002: 'portal_def');
1.325 raeburn 20003: my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 20004: foreach my $item (@items) {
20005: $newvalues{$item} = $env{'form.'.$item};
20006: if ($item eq 'auth_def') {
20007: if ($newvalues{$item} ne '') {
20008: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
20009: push(@errors,$item);
20010: }
20011: }
20012: } elsif ($item eq 'lang_def') {
20013: if ($newvalues{$item} ne '') {
20014: if ($newvalues{$item} =~ /^(\w+)/) {
20015: my $langcode = $1;
1.103 raeburn 20016: if ($langcode ne 'x_chef') {
20017: if (code2language($langcode) eq '') {
20018: push(@errors,$item);
20019: }
1.43 raeburn 20020: }
20021: } else {
20022: push(@errors,$item);
20023: }
20024: }
1.54 raeburn 20025: } elsif ($item eq 'timezone_def') {
20026: if ($newvalues{$item} ne '') {
1.62 raeburn 20027: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 20028: push(@errors,$item);
20029: }
20030: }
1.68 raeburn 20031: } elsif ($item eq 'datelocale_def') {
20032: if ($newvalues{$item} ne '') {
20033: my @datelocale_ids = DateTime::Locale->ids();
20034: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
20035: push(@errors,$item);
20036: }
20037: }
1.141 raeburn 20038: } elsif ($item eq 'portal_def') {
20039: if ($newvalues{$item} ne '') {
1.414 raeburn 20040: 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])\/?$/) {
20041: foreach my $field ('email','web') {
20042: if ($env{'form.'.$item.'_'.$field}) {
20043: $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
20044: }
20045: }
20046: } else {
1.141 raeburn 20047: push(@errors,$item);
20048: }
20049: }
1.43 raeburn 20050: }
20051: if (grep(/^\Q$item\E$/,@errors)) {
20052: $newvalues{$item} = $domdefaults{$item};
1.414 raeburn 20053: if ($item eq 'portal_def') {
20054: if ($domdefaults{$item}) {
20055: foreach my $field ('email','web') {
20056: if (exists($domdefaults{$item.'_'.$field})) {
20057: $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
20058: }
20059: }
20060: }
20061: }
1.43 raeburn 20062: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
20063: $changes{$item} = 1;
20064: }
1.414 raeburn 20065: if ($item eq 'portal_def') {
20066: unless (grep(/^\Q$item\E$/,@errors)) {
1.425 raeburn 20067: if ($newvalues{$item} eq '') {
1.414 raeburn 20068: foreach my $field ('email','web') {
20069: if (exists($domdefaults{$item.'_'.$field})) {
20070: delete($domdefaults{$item.'_'.$field});
20071: }
20072: }
20073: } else {
20074: unless ($changes{$item}) {
20075: foreach my $field ('email','web') {
20076: if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
20077: $changes{$item} = 1;
20078: last;
20079: }
20080: }
20081: }
20082: foreach my $field ('email','web') {
20083: if ($newvalues{$item.'_'.$field}) {
20084: $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
20085: } elsif (exists($domdefaults{$item.'_'.$field})) {
20086: delete($domdefaults{$item.'_'.$field});
20087: }
20088: }
20089: }
20090: }
20091: }
1.72 raeburn 20092: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 20093: }
1.354 raeburn 20094: my %staticdefaults = (
20095: 'intauth_cost' => 10,
20096: 'intauth_check' => 0,
20097: 'intauth_switch' => 0,
20098: );
20099: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
20100: if (exists($domdefaults{$item})) {
20101: $newvalues{$item} = $domdefaults{$item};
20102: } else {
20103: $newvalues{$item} = $staticdefaults{$item};
20104: }
20105: }
1.409 raeburn 20106: my ($unamemaprules,$ruleorder);
20107: my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
20108: if (@possunamemaprules) {
20109: ($unamemaprules,$ruleorder) =
20110: &Apache::lonnet::inst_userrules($dom,'unamemap');
20111: if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
20112: if (@{$ruleorder} > 0) {
20113: my %possrules;
20114: map { $possrules{$_} = 1; } @possunamemaprules;
20115: foreach my $rule (@{$ruleorder}) {
20116: if ($possrules{$rule}) {
20117: push(@{$newvalues{'unamemap_rule'}},$rule);
20118: }
20119: }
20120: }
20121: }
20122: }
20123: if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
20124: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20125: my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
20126: $newvalues{'unamemap_rule'});
20127: if (@rulediffs) {
20128: $changes{'unamemap_rule'} = 1;
20129: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20130: }
20131: } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
20132: $changes{'unamemap_rule'} = 1;
20133: delete($domdefaults{'unamemap_rule'});
20134: }
20135: } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20136: if (@{$newvalues{'unamemap_rule'}} > 0) {
20137: $changes{'unamemap_rule'} = 1;
20138: $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
20139: }
20140: }
1.43 raeburn 20141: my %defaults_hash = (
1.72 raeburn 20142: defaults => \%newvalues,
20143: );
1.43 raeburn 20144: my $title = &defaults_titles();
1.236 raeburn 20145:
20146: my $currinststatus;
20147: if (ref($domconfig{'inststatus'}) eq 'HASH') {
20148: $currinststatus = $domconfig{'inststatus'};
20149: } else {
20150: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
20151: $currinststatus = {
20152: inststatustypes => $usertypes,
20153: inststatusorder => $types,
20154: inststatusguest => [],
20155: };
20156: }
20157: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
20158: my @allpos;
20159: my %alltypes;
1.305 raeburn 20160: my @inststatusguest;
20161: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
20162: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
20163: unless (grep(/^\Q$type\E$/,@todelete)) {
20164: push(@inststatusguest,$type);
20165: }
20166: }
20167: }
20168: my ($currtitles,$currorder);
1.236 raeburn 20169: if (ref($currinststatus) eq 'HASH') {
20170: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
20171: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
20172: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
20173: if ($currinststatus->{inststatustypes}->{$type} ne '') {
20174: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
20175: }
20176: }
20177: unless (grep(/^\Q$type\E$/,@todelete)) {
20178: my $position = $env{'form.inststatus_pos_'.$type};
20179: $position =~ s/\D+//g;
20180: $allpos[$position] = $type;
20181: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
20182: $alltypes{$type} =~ s/`//g;
20183: }
20184: }
20185: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
20186: $currtitles =~ s/,$//;
20187: }
20188: }
20189: if ($env{'form.addinststatus'}) {
20190: my $newtype = $env{'form.addinststatus'};
20191: $newtype =~ s/\W//g;
20192: unless (exists($alltypes{$newtype})) {
20193: $alltypes{$newtype} = $env{'form.addinststatus_title'};
20194: $alltypes{$newtype} =~ s/`//g;
20195: my $position = $env{'form.addinststatus_pos'};
20196: $position =~ s/\D+//g;
20197: if ($position ne '') {
20198: $allpos[$position] = $newtype;
20199: }
20200: }
20201: }
1.305 raeburn 20202: my @orderedstatus;
1.236 raeburn 20203: foreach my $type (@allpos) {
20204: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
20205: push(@orderedstatus,$type);
20206: }
20207: }
20208: foreach my $type (keys(%alltypes)) {
20209: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
20210: delete($alltypes{$type});
20211: }
20212: }
20213: $defaults_hash{'inststatus'} = {
20214: inststatustypes => \%alltypes,
20215: inststatusorder => \@orderedstatus,
1.305 raeburn 20216: inststatusguest => \@inststatusguest,
1.236 raeburn 20217: };
20218: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
20219: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
20220: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
20221: }
20222: }
20223: if ($currorder ne join(',',@orderedstatus)) {
20224: $changes{'inststatus'}{'inststatusorder'} = 1;
20225: }
20226: my $newtitles;
20227: foreach my $item (@orderedstatus) {
20228: $newtitles .= $alltypes{$item}.',';
20229: }
20230: $newtitles =~ s/,$//;
20231: if ($currtitles ne $newtitles) {
20232: $changes{'inststatus'}{'inststatustypes'} = 1;
20233: }
1.43 raeburn 20234: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
20235: $dom);
20236: if ($putresult eq 'ok') {
20237: if (keys(%changes) > 0) {
20238: $resulttext = &mt('Changes made:').'<ul>';
1.212 raeburn 20239: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 20240: 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";
20241: foreach my $item (sort(keys(%changes))) {
1.236 raeburn 20242: if ($item eq 'inststatus') {
20243: if (ref($changes{'inststatus'}) eq 'HASH') {
1.305 raeburn 20244: if (@orderedstatus) {
1.236 raeburn 20245: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
20246: foreach my $type (@orderedstatus) {
20247: $resulttext .= $alltypes{$type}.', ';
20248: }
20249: $resulttext =~ s/, $//;
20250: $resulttext .= '</li>';
1.305 raeburn 20251: } else {
1.425 raeburn 20252: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.236 raeburn 20253: }
20254: }
1.409 raeburn 20255: } elsif ($item eq 'unamemap_rule') {
20256: if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
20257: my @rulenames;
20258: if (ref($unamemaprules) eq 'HASH') {
20259: foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
20260: if (ref($unamemaprules->{$rule}) eq 'HASH') {
20261: push(@rulenames,$unamemaprules->{$rule}->{'name'});
20262: }
20263: }
20264: }
20265: if (@rulenames) {
20266: $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
20267: '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
20268: '</li>';
20269: } else {
20270: $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
20271: }
20272: } else {
20273: $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
20274: }
1.236 raeburn 20275: } else {
20276: my $value = $env{'form.'.$item};
20277: if ($value eq '') {
20278: $value = &mt('none');
20279: } elsif ($item eq 'auth_def') {
20280: my %authnames = &authtype_names();
20281: my %shortauth = (
20282: internal => 'int',
20283: krb4 => 'krb4',
20284: krb5 => 'krb5',
20285: localauth => 'loc',
1.325 raeburn 20286: lti => 'lti',
1.236 raeburn 20287: );
20288: $value = $authnames{$shortauth{$value}};
20289: }
20290: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.414 raeburn 20291: $mailmsgtext .= "$title->{$item} set to $value\n";
20292: if ($item eq 'portal_def') {
20293: if ($env{'form.'.$item} ne '') {
20294: foreach my $field ('email','web') {
20295: $value = $env{'form.'.$item.'_'.$field};
20296: if ($value) {
20297: $value = &mt('Yes');
20298: } else {
20299: $value = &mt('No');
20300: }
20301: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
20302: }
20303: }
20304: }
1.43 raeburn 20305: }
20306: }
20307: $resulttext .= '</ul>';
20308: $mailmsgtext .= "\n";
20309: my $cachetime = 24*60*60;
1.72 raeburn 20310: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 20311: if (ref($lastactref) eq 'HASH') {
20312: $lastactref->{'domdefaults'} = 1;
20313: }
1.68 raeburn 20314: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 20315: my $notify = 1;
20316: if (ref($domconfig{'contacts'}) eq 'HASH') {
20317: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
20318: $notify = 0;
20319: }
20320: }
20321: if ($notify) {
20322: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
20323: "LON-CAPA Domain Settings Change - $dom",
20324: $mailmsgtext);
20325: }
1.54 raeburn 20326: }
1.43 raeburn 20327: } else {
1.54 raeburn 20328: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 20329: }
20330: } else {
20331: $resulttext = '<span class="LC_error">'.
20332: &mt('An error occurred: [_1]',$putresult).'</span>';
20333: }
20334: if (@errors > 0) {
20335: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
20336: foreach my $item (@errors) {
20337: $resulttext .= ' "'.$title->{$item}.'",';
20338: }
20339: $resulttext =~ s/,$//;
20340: }
20341: return $resulttext;
20342: }
20343:
1.46 raeburn 20344: sub modify_scantron {
1.205 raeburn 20345: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 20346: my ($resulttext,%confhash,%changes,$errors);
20347: my $custom = 'custom.tab';
20348: my $default = 'default.tab';
20349: my $servadm = $r->dir_config('lonAdmEMail');
1.346 raeburn 20350: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 20351: &config_check($dom,$confname,$servadm);
20352: if ($env{'form.scantronformat.filename'} ne '') {
20353: my $error;
20354: if ($configuserok eq 'ok') {
20355: if ($switchserver) {
1.130 raeburn 20356: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 20357: } else {
20358: if ($author_ok eq 'ok') {
1.421 raeburn 20359: my $modified = [];
1.46 raeburn 20360: my ($result,$scantronurl) =
1.421 raeburn 20361: &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
20362: $confname,'scantron','','',$custom,
20363: $modified);
1.46 raeburn 20364: if ($result eq 'ok') {
20365: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 20366: $changes{'scantronformat'} = 1;
1.421 raeburn 20367: &update_modify_urls($r,$modified);
1.46 raeburn 20368: } else {
20369: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
20370: }
20371: } else {
20372: $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);
20373: }
20374: }
20375: } else {
20376: $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);
20377: }
20378: if ($error) {
20379: &Apache::lonnet::logthis($error);
20380: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
20381: }
20382: }
1.48 raeburn 20383: if (ref($domconfig{'scantron'}) eq 'HASH') {
20384: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
20385: if ($env{'form.scantronformat_del'}) {
20386: $confhash{'scantron'}{'scantronformat'} = '';
20387: $changes{'scantronformat'} = 1;
1.347 raeburn 20388: } else {
20389: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
1.46 raeburn 20390: }
20391: }
20392: }
1.347 raeburn 20393: my @options = ('hdr','pad','rem');
1.346 raeburn 20394: my @fields = &scantroncsv_fields();
20395: my %titles = &scantronconfig_titles();
1.347 raeburn 20396: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
1.346 raeburn 20397: my ($newdat,$currdat,%newcol,%currcol);
20398: if (grep(/^dat$/,@formats)) {
20399: $confhash{'scantron'}{config}{dat} = 1;
20400: $newdat = 1;
20401: } else {
20402: $newdat = 0;
20403: }
20404: if (grep(/^csv$/,@formats)) {
20405: my %bynum;
20406: foreach my $field (@fields) {
20407: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
20408: my $posscol = $1;
20409: if (($posscol < 20) && (!$bynum{$posscol})) {
1.347 raeburn 20410: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
1.346 raeburn 20411: $bynum{$posscol} = $field;
20412: $newcol{$field} = $posscol;
20413: }
20414: }
20415: }
1.347 raeburn 20416: if (keys(%newcol)) {
20417: foreach my $option (@options) {
20418: if ($env{'form.scantroncsv_'.$option}) {
20419: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
20420: }
20421: }
20422: }
1.346 raeburn 20423: }
20424: $currdat = 1;
20425: if (ref($domconfig{'scantron'}) eq 'HASH') {
20426: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
1.347 raeburn 20427: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
1.346 raeburn 20428: $currdat = 0;
20429: }
20430: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20431: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20432: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
20433: }
1.346 raeburn 20434: }
20435: }
20436: }
20437: if ($currdat != $newdat) {
20438: $changes{'config'} = 1;
20439: } else {
20440: foreach my $field (@fields) {
20441: if ($currcol{$field} ne '') {
20442: if ($currcol{$field} ne $newcol{$field}) {
20443: $changes{'config'} = 1;
20444: last;
1.347 raeburn 20445: }
1.346 raeburn 20446: } elsif ($newcol{$field} ne '') {
20447: $changes{'config'} = 1;
20448: last;
20449: }
20450: }
20451: }
1.46 raeburn 20452: if (keys(%confhash) > 0) {
20453: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
20454: $dom);
20455: if ($putresult eq 'ok') {
20456: if (keys(%changes) > 0) {
1.48 raeburn 20457: if (ref($confhash{'scantron'}) eq 'HASH') {
20458: $resulttext = &mt('Changes made:').'<ul>';
1.346 raeburn 20459: if ($changes{'scantronformat'}) {
20460: if ($confhash{'scantron'}{'scantronformat'} eq '') {
20461: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
20462: } else {
20463: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
20464: }
20465: }
1.347 raeburn 20466: if ($changes{'config'}) {
1.346 raeburn 20467: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
20468: if ($confhash{'scantron'}{'config'}{'dat'}) {
20469: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
20470: }
20471: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
1.347 raeburn 20472: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
20473: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
20474: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
20475: foreach my $field (@fields) {
20476: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
20477: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
20478: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
20479: }
20480: }
20481: $resulttext .= '</ul></li>';
20482: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
20483: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
20484: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
20485: foreach my $option (@options) {
20486: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
20487: $resulttext .= '<li>'.$titles{$option}.'</li>';
20488: }
20489: }
20490: $resulttext .= '</ul></li>';
20491: }
1.346 raeburn 20492: }
20493: }
20494: }
20495: }
20496: } else {
20497: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
20498: }
1.46 raeburn 20499: }
1.48 raeburn 20500: $resulttext .= '</ul>';
20501: } else {
1.130 raeburn 20502: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 20503: }
20504: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 raeburn 20505: if (ref($lastactref) eq 'HASH') {
20506: $lastactref->{'domainconfig'} = 1;
20507: }
1.46 raeburn 20508: } else {
1.346 raeburn 20509: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 20510: }
20511: } else {
20512: $resulttext = '<span class="LC_error">'.
20513: &mt('An error occurred: [_1]',$putresult).'</span>';
20514: }
20515: } else {
1.130 raeburn 20516: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 20517: }
20518: if ($errors) {
1.353 raeburn 20519: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
20520: $errors.'</ul></p>';
1.46 raeburn 20521: }
20522: return $resulttext;
20523: }
20524:
1.48 raeburn 20525: sub modify_coursecategories {
1.239 raeburn 20526: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 20527: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
20528: $cathash);
1.48 raeburn 20529: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.238 raeburn 20530: my @catitems = ('unauth','auth');
20531: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 20532: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 20533: $cathash = $domconfig{'coursecategories'}{'cats'};
20534: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
20535: $changes{'togglecats'} = 1;
20536: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
20537: }
20538: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
20539: $changes{'categorize'} = 1;
20540: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
20541: }
1.120 raeburn 20542: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
20543: $changes{'togglecatscomm'} = 1;
20544: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
20545: }
20546: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
20547: $changes{'categorizecomm'} = 1;
20548: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
1.272 raeburn 20549:
20550: }
20551: if ($domconfig{'coursecategories'}{'togglecatsplace'} ne $env{'form.togglecatsplace'}) {
20552: $changes{'togglecatsplace'} = 1;
20553: $domconfig{'coursecategories'}{'togglecatsplace'} = $env{'form.togglecatsplace'};
20554: }
20555: if ($domconfig{'coursecategories'}{'categorizeplace'} ne $env{'form.categorizeplace'}) {
20556: $changes{'categorizeplace'} = 1;
20557: $domconfig{'coursecategories'}{'categorizeplace'} = $env{'form.categorizeplace'};
1.120 raeburn 20558: }
1.238 raeburn 20559: foreach my $item (@catitems) {
20560: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20561: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
20562: $changes{$item} = 1;
20563: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20564: }
20565: }
20566: }
1.57 raeburn 20567: } else {
20568: $changes{'togglecats'} = 1;
20569: $changes{'categorize'} = 1;
1.124 raeburn 20570: $changes{'togglecatscomm'} = 1;
20571: $changes{'categorizecomm'} = 1;
1.272 raeburn 20572: $changes{'togglecatsplace'} = 1;
20573: $changes{'categorizeplace'} = 1;
1.87 raeburn 20574: $domconfig{'coursecategories'} = {
20575: togglecats => $env{'form.togglecats'},
20576: categorize => $env{'form.categorize'},
1.124 raeburn 20577: togglecatscomm => $env{'form.togglecatscomm'},
20578: categorizecomm => $env{'form.categorizecomm'},
1.272 raeburn 20579: togglecatsplace => $env{'form.togglecatsplace'},
20580: categorizeplace => $env{'form.categorizeplace'},
1.120 raeburn 20581: };
1.238 raeburn 20582: foreach my $item (@catitems) {
20583: if ($env{'form.coursecat_'.$item} ne 'std') {
20584: $changes{$item} = 1;
20585: }
20586: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
20587: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
20588: }
20589: }
1.57 raeburn 20590: }
20591: if (ref($cathash) eq 'HASH') {
20592: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 20593: push (@deletecategory,'instcode::0');
20594: }
1.120 raeburn 20595: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
20596: push(@deletecategory,'communities::0');
20597: }
1.272 raeburn 20598: if (($domconfig{'coursecategories'}{'cats'}{'placement::0'} ne '') && ($env{'form.placement'} == 0)) {
20599: push(@deletecategory,'placement::0');
20600: }
1.48 raeburn 20601: }
1.57 raeburn 20602: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
20603: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20604: if (@deletecategory > 0) {
20605: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 20606: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 20607: foreach my $item (@deletecategory) {
1.57 raeburn 20608: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
20609: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 20610: $deletions{$item} = 1;
1.57 raeburn 20611: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 20612: }
20613: }
20614: }
1.57 raeburn 20615: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 20616: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 20617: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 20618: $reorderings{$item} = 1;
1.57 raeburn 20619: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 20620: }
20621: if ($env{'form.addcategory_name_'.$item} ne '') {
20622: my $newcat = $env{'form.addcategory_name_'.$item};
20623: my $newdepth = $depth+1;
20624: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20625: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 20626: $adds{$newitem} = 1;
20627: }
20628: if ($env{'form.subcat_'.$item} ne '') {
20629: my $newcat = $env{'form.subcat_'.$item};
20630: my $newdepth = $depth+1;
20631: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 20632: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 20633: $adds{$newitem} = 1;
20634: }
20635: }
20636: }
20637: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 20638: if (ref($cathash) eq 'HASH') {
1.48 raeburn 20639: my $newitem = 'instcode::0';
1.57 raeburn 20640: if ($cathash->{$newitem} eq '') {
20641: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20642: $adds{$newitem} = 1;
20643: }
20644: } else {
20645: my $newitem = 'instcode::0';
1.57 raeburn 20646: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 20647: $adds{$newitem} = 1;
20648: }
20649: }
1.120 raeburn 20650: if ($env{'form.communities'} eq '1') {
20651: if (ref($cathash) eq 'HASH') {
20652: my $newitem = 'communities::0';
20653: if ($cathash->{$newitem} eq '') {
20654: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20655: $adds{$newitem} = 1;
20656: }
20657: } else {
20658: my $newitem = 'communities::0';
20659: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
20660: $adds{$newitem} = 1;
20661: }
20662: }
1.272 raeburn 20663: if ($env{'form.placement'} eq '1') {
20664: if (ref($cathash) eq 'HASH') {
20665: my $newitem = 'placement::0';
20666: if ($cathash->{$newitem} eq '') {
20667: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20668: $adds{$newitem} = 1;
20669: }
20670: } else {
20671: my $newitem = 'placement::0';
20672: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.placement_pos'};
20673: $adds{$newitem} = 1;
20674: }
20675: }
1.48 raeburn 20676: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 20677: if (($env{'form.addcategory_name'} ne 'instcode') &&
1.272 raeburn 20678: ($env{'form.addcategory_name'} ne 'communities') &&
20679: ($env{'form.addcategory_name'} ne 'placement')) {
1.120 raeburn 20680: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
20681: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
20682: $adds{$newitem} = 1;
20683: }
1.48 raeburn 20684: }
1.57 raeburn 20685: my $putresult;
1.48 raeburn 20686: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20687: if (keys(%deletions) > 0) {
20688: foreach my $key (keys(%deletions)) {
20689: if ($predelallitems{$key} ne '') {
20690: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
20691: }
20692: }
20693: }
20694: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 20695: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 20696: if (ref($chkcats[0]) eq 'ARRAY') {
20697: my $depth = 0;
20698: my $chg = 0;
20699: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
20700: my $name = $chkcats[0][$i];
20701: my $item;
20702: if ($name eq '') {
20703: $chg ++;
20704: } else {
20705: $item = &escape($name).'::0';
20706: if ($chg) {
1.57 raeburn 20707: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 20708: }
20709: $depth ++;
1.57 raeburn 20710: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 20711: $depth --;
20712: }
20713: }
20714: }
1.57 raeburn 20715: }
20716: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20717: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 20718: if ($putresult eq 'ok') {
1.57 raeburn 20719: my %title = (
1.120 raeburn 20720: togglecats => 'Show/Hide a course in catalog',
20721: categorize => 'Assign a category to a course',
20722: togglecatscomm => 'Show/Hide a community in catalog',
20723: categorizecomm => 'Assign a category to a community',
1.57 raeburn 20724: );
20725: my %level = (
1.120 raeburn 20726: dom => 'set in Domain ("Modify Course/Community")',
20727: crs => 'set in Course ("Course Configuration")',
20728: comm => 'set in Community ("Community Configuration")',
1.238 raeburn 20729: none => 'No catalog',
20730: std => 'Standard catalog',
20731: domonly => 'Domain-only catalog',
20732: codesrch => 'Code search form',
1.57 raeburn 20733: );
1.48 raeburn 20734: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 20735: if ($changes{'togglecats'}) {
20736: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
20737: }
20738: if ($changes{'categorize'}) {
20739: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 20740: }
1.120 raeburn 20741: if ($changes{'togglecatscomm'}) {
20742: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
20743: }
20744: if ($changes{'categorizecomm'}) {
20745: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
20746: }
1.238 raeburn 20747: if ($changes{'unauth'}) {
20748: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
20749: }
20750: if ($changes{'auth'}) {
20751: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
20752: }
1.57 raeburn 20753: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
20754: my $cathash;
20755: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
20756: $cathash = $domconfig{'coursecategories'}{'cats'};
20757: } else {
20758: $cathash = {};
20759: }
20760: my (@cats,@trails,%allitems);
20761: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
20762: if (keys(%deletions) > 0) {
20763: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
20764: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
20765: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
20766: }
20767: $resulttext .= '</ul></li>';
20768: }
20769: if (keys(%reorderings) > 0) {
20770: my %sort_by_trail;
20771: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
20772: foreach my $key (keys(%reorderings)) {
20773: if ($allitems{$key} ne '') {
20774: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20775: }
1.48 raeburn 20776: }
1.57 raeburn 20777: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20778: $resulttext .= '<li>'.$trails[$trail].'</li>';
20779: }
20780: $resulttext .= '</ul></li>';
1.48 raeburn 20781: }
1.57 raeburn 20782: if (keys(%adds) > 0) {
20783: my %sort_by_trail;
20784: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
20785: foreach my $key (keys(%adds)) {
20786: if ($allitems{$key} ne '') {
20787: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
20788: }
20789: }
20790: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
20791: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 20792: }
1.57 raeburn 20793: $resulttext .= '</ul></li>';
1.48 raeburn 20794: }
1.364 raeburn 20795: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
20796: if (ref($lastactref) eq 'HASH') {
20797: $lastactref->{'cats'} = 1;
20798: }
1.48 raeburn 20799: }
20800: $resulttext .= '</ul>';
1.239 raeburn 20801: if ($changes{'unauth'} || $changes{'auth'}) {
1.246 raeburn 20802: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20803: if ($changes{'auth'}) {
20804: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
20805: }
20806: if ($changes{'unauth'}) {
20807: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
20808: }
20809: my $cachetime = 24*60*60;
20810: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.239 raeburn 20811: if (ref($lastactref) eq 'HASH') {
1.246 raeburn 20812: $lastactref->{'domdefaults'} = 1;
1.239 raeburn 20813: }
20814: }
1.48 raeburn 20815: } else {
20816: $resulttext = '<span class="LC_error">'.
1.57 raeburn 20817: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 20818: }
20819: } else {
1.120 raeburn 20820: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 20821: }
20822: return $resulttext;
20823: }
20824:
1.69 raeburn 20825: sub modify_serverstatuses {
20826: my ($dom,%domconfig) = @_;
20827: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
20828: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
20829: %currserverstatus = %{$domconfig{'serverstatuses'}};
20830: }
20831: my @pages = &serverstatus_pages();
20832: foreach my $type (@pages) {
20833: $newserverstatus{$type}{'namedusers'} = '';
20834: $newserverstatus{$type}{'machines'} = '';
20835: if (defined($env{'form.'.$type.'_namedusers'})) {
20836: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
20837: my @okusers;
20838: foreach my $user (@users) {
20839: my ($uname,$udom) = split(/:/,$user);
20840: if (($udom =~ /^$match_domain$/) &&
20841: (&Apache::lonnet::domain($udom)) &&
20842: ($uname =~ /^$match_username$/)) {
20843: if (!grep(/^\Q$user\E/,@okusers)) {
20844: push(@okusers,$user);
20845: }
20846: }
20847: }
20848: if (@okusers > 0) {
20849: @okusers = sort(@okusers);
20850: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
20851: }
20852: }
20853: if (defined($env{'form.'.$type.'_machines'})) {
20854: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
20855: my @okmachines;
20856: foreach my $ip (@machines) {
20857: my @parts = split(/\./,$ip);
20858: next if (@parts < 4);
20859: my $badip = 0;
20860: for (my $i=0; $i<4; $i++) {
20861: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
20862: $badip = 1;
20863: last;
20864: }
20865: }
20866: if (!$badip) {
20867: push(@okmachines,$ip);
20868: }
20869: }
20870: @okmachines = sort(@okmachines);
20871: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
20872: }
20873: }
20874: my %serverstatushash = (
20875: serverstatuses => \%newserverstatus,
20876: );
20877: foreach my $type (@pages) {
1.83 raeburn 20878: foreach my $setting ('namedusers','machines') {
1.84 raeburn 20879: my (@current,@new);
1.83 raeburn 20880: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 20881: if ($currserverstatus{$type}{$setting} ne '') {
20882: @current = split(/,/,$currserverstatus{$type}{$setting});
20883: }
20884: }
20885: if ($newserverstatus{$type}{$setting} ne '') {
20886: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 20887: }
20888: if (@current > 0) {
20889: if (@new > 0) {
20890: foreach my $item (@current) {
20891: if (!grep(/^\Q$item\E$/,@new)) {
20892: $changes{$type}{$setting} = 1;
1.82 raeburn 20893: last;
20894: }
20895: }
1.84 raeburn 20896: foreach my $item (@new) {
20897: if (!grep(/^\Q$item\E$/,@current)) {
20898: $changes{$type}{$setting} = 1;
20899: last;
1.82 raeburn 20900: }
20901: }
20902: } else {
1.83 raeburn 20903: $changes{$type}{$setting} = 1;
1.69 raeburn 20904: }
1.83 raeburn 20905: } elsif (@new > 0) {
20906: $changes{$type}{$setting} = 1;
1.69 raeburn 20907: }
20908: }
20909: }
20910: if (keys(%changes) > 0) {
1.81 raeburn 20911: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 20912: my $putresult = &Apache::lonnet::put_dom('configuration',
20913: \%serverstatushash,$dom);
20914: if ($putresult eq 'ok') {
20915: $resulttext .= &mt('Changes made:').'<ul>';
20916: foreach my $type (@pages) {
1.84 raeburn 20917: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 20918: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 20919: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 20920: if ($newserverstatus{$type}{'namedusers'} eq '') {
20921: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
20922: } else {
20923: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
20924: }
1.84 raeburn 20925: }
20926: if ($changes{$type}{'machines'}) {
1.69 raeburn 20927: if ($newserverstatus{$type}{'machines'} eq '') {
20928: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
20929: } else {
20930: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
20931: }
20932:
20933: }
20934: $resulttext .= '</ul></li>';
20935: }
20936: }
20937: $resulttext .= '</ul>';
20938: } else {
20939: $resulttext = '<span class="LC_error">'.
20940: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
20941:
20942: }
20943: } else {
20944: $resulttext = &mt('No changes made to access to server status pages');
20945: }
20946: return $resulttext;
20947: }
20948:
1.118 jms 20949: sub modify_helpsettings {
1.285 raeburn 20950: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.166 raeburn 20951: my ($resulttext,$errors,%changes,%helphash);
20952: my %defaultchecked = ('submitbugs' => 'on');
20953: my @offon = ('off','on');
1.118 jms 20954: my @toggles = ('submitbugs');
1.285 raeburn 20955: my %current = ('submitbugs' => '',
20956: 'adhoc' => {},
20957: );
1.118 jms 20958: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.282 raeburn 20959: %current = %{$domconfig{'helpsettings'}};
20960: }
1.285 raeburn 20961: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.282 raeburn 20962: foreach my $item (@toggles) {
20963: if ($defaultchecked{$item} eq 'on') {
20964: if ($current{$item} eq '') {
20965: if ($env{'form.'.$item} eq '0') {
20966: $changes{$item} = 1;
20967: }
20968: } elsif ($current{$item} ne $env{'form.'.$item}) {
20969: $changes{$item} = 1;
20970: }
20971: } elsif ($defaultchecked{$item} eq 'off') {
20972: if ($current{$item} eq '') {
20973: if ($env{'form.'.$item} eq '1') {
1.166 raeburn 20974: $changes{$item} = 1;
20975: }
1.282 raeburn 20976: } elsif ($current{$item} ne $env{'form.'.$item}) {
20977: $changes{$item} = 1;
20978: }
20979: }
20980: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
20981: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
20982: }
20983: }
1.285 raeburn 20984: my $maxnum = $env{'form.helproles_maxnum'};
1.282 raeburn 20985: my $confname = $dom.'-domainconfig';
20986: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.285 raeburn 20987: my (@allpos,%newsettings,%changedprivs,$newrole);
20988: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.292 raeburn 20989: my @accesstypes = ('all','dh','da','none','status','inc','exc');
1.290 raeburn 20990: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.285 raeburn 20991: my %lt = &Apache::lonlocal::texthash(
20992: s => 'system',
20993: d => 'domain',
20994: order => 'Display order',
20995: access => 'Role usage',
1.291 raeburn 20996: all => 'All with domain helpdesk or helpdesk assistant role',
1.292 raeburn 20997: dh => 'All with domain helpdesk role',
20998: da => 'All with domain helpdesk assistant role',
1.285 raeburn 20999: none => 'None',
21000: status => 'Determined based on institutional status',
21001: inc => 'Include all, but exclude specific personnel',
21002: exc => 'Exclude all, but include specific personnel',
21003: );
21004: for (my $num=0; $num<=$maxnum; $num++) {
21005: my ($prefix,$identifier,$rolename,%curr);
21006: if ($num == $maxnum) {
21007: next unless ($env{'form.newcusthelp'} == $maxnum);
21008: $identifier = 'custhelp'.$num;
21009: $prefix = 'helproles_'.$num;
21010: $rolename = $env{'form.custhelpname'.$num};
21011: $rolename=~s/[^A-Za-z0-9]//gs;
21012: next if ($rolename eq '');
21013: next if (exists($existing{'rolesdef_'.$rolename}));
21014: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21015: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21016: $newprivs{'c'},$confname,$dom);
21017: if ($result ne 'ok') {
21018: $errors .= '<li><span class="LC_error">'.
21019: &mt('An error occurred storing the new custom role: [_1]',
21020: $result).'</span></li>';
21021: next;
21022: } else {
21023: $changedprivs{$rolename} = \%newprivs;
21024: $newrole = $rolename;
21025: }
21026: } else {
21027: $prefix = 'helproles_'.$num;
21028: $rolename = $env{'form.'.$prefix};
21029: next if ($rolename eq '');
21030: next unless (exists($existing{'rolesdef_'.$rolename}));
21031: $identifier = 'custhelp'.$num;
21032: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
21033: my %currprivs;
1.289 raeburn 21034: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
1.285 raeburn 21035: split(/\_/,$existing{'rolesdef_'.$rolename});
21036: foreach my $level ('c','d','s') {
21037: if ($newprivs{$level} ne $currprivs{$level}) {
21038: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
21039: $newprivs{'c'},$confname,$dom);
21040: if ($result ne 'ok') {
21041: $errors .= '<li><span class="LC_error">'.
21042: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
21043: $rolename,$result).'</span></li>';
21044: } else {
21045: $changedprivs{$rolename} = \%newprivs;
21046: }
21047: last;
21048: }
21049: }
21050: if (ref($current{'adhoc'}) eq 'HASH') {
21051: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21052: %curr = %{$current{'adhoc'}{$rolename}};
21053: }
21054: }
21055: }
21056: my $newpos = $env{'form.'.$prefix.'_pos'};
21057: $newpos =~ s/\D+//g;
21058: $allpos[$newpos] = $rolename;
21059: my $newdesc = $env{'form.'.$prefix.'_desc'};
21060: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
21061: if ($curr{'desc'}) {
21062: if ($curr{'desc'} ne $newdesc) {
21063: $changes{'customrole'}{$rolename}{'desc'} = 1;
21064: $newsettings{$rolename}{'desc'} = $newdesc;
21065: }
21066: } elsif ($newdesc ne '') {
21067: $changes{'customrole'}{$rolename}{'desc'} = 1;
21068: $newsettings{$rolename}{'desc'} = $newdesc;
21069: }
21070: my $access = $env{'form.'.$prefix.'_access'};
21071: if (grep(/^\Q$access\E$/,@accesstypes)) {
21072: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
21073: if ($access eq 'status') {
21074: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
21075: if (scalar(@statuses) == 0) {
1.289 raeburn 21076: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
1.285 raeburn 21077: } else {
21078: my (@shownstatus,$numtypes);
21079: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21080: if (ref($types) eq 'ARRAY') {
21081: $numtypes = scalar(@{$types});
21082: foreach my $type (sort(@statuses)) {
21083: if ($type eq 'default') {
21084: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21085: } elsif (grep(/^\Q$type\E$/,@{$types})) {
21086: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
21087: push(@shownstatus,$usertypes->{$type});
21088: }
21089: }
21090: }
21091: if (grep(/^default$/,@statuses)) {
21092: push(@shownstatus,$othertitle);
21093: }
21094: if (scalar(@shownstatus) == 1+$numtypes) {
21095: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
21096: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
21097: } else {
21098: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
21099: if (ref($curr{'status'}) eq 'ARRAY') {
21100: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21101: if (@diffs) {
21102: $changes{'customrole'}{$rolename}{$access} = 1;
21103: }
21104: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21105: $changes{'customrole'}{$rolename}{$access} = 1;
1.282 raeburn 21106: }
1.166 raeburn 21107: }
21108: }
1.285 raeburn 21109: } elsif (($access eq 'inc') || ($access eq 'exc')) {
21110: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
21111: my @newspecstaff;
21112: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
21113: foreach my $person (sort(@personnel)) {
21114: if ($domhelpdesk{$person}) {
21115: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
21116: }
21117: }
21118: if (ref($curr{$access}) eq 'ARRAY') {
21119: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
21120: if (@diffs) {
21121: $changes{'customrole'}{$rolename}{$access} = 1;
21122: }
21123: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21124: $changes{'customrole'}{$rolename}{$access} = 1;
21125: }
21126: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
21127: my ($uname,$udom) = split(/:/,$person);
21128: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
21129: }
21130: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.166 raeburn 21131: }
1.285 raeburn 21132: } else {
21133: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
21134: }
21135: unless ($curr{'access'} eq $access) {
21136: $changes{'customrole'}{$rolename}{'access'} = 1;
21137: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.282 raeburn 21138: }
21139: }
1.285 raeburn 21140: if (@allpos > 0) {
21141: my $idx = 0;
21142: foreach my $rolename (@allpos) {
21143: if ($rolename ne '') {
21144: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
21145: if (ref($current{'adhoc'}) eq 'HASH') {
21146: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
21147: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
21148: $changes{'customrole'}{$rolename}{'order'} = 1;
1.289 raeburn 21149: $newsettings{$rolename}{'order'} = $idx+1;
1.285 raeburn 21150: }
21151: }
1.282 raeburn 21152: }
1.285 raeburn 21153: $idx ++;
1.166 raeburn 21154: }
21155: }
1.118 jms 21156: }
1.123 jms 21157: my $putresult;
21158: if (keys(%changes) > 0) {
1.166 raeburn 21159: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 21160: if ($putresult eq 'ok') {
1.285 raeburn 21161: if (ref($helphash{'helpsettings'}) eq 'HASH') {
21162: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
21163: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
21164: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
21165: }
21166: }
21167: my $cachetime = 24*60*60;
21168: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
21169: if (ref($lastactref) eq 'HASH') {
21170: $lastactref->{'domdefaults'} = 1;
21171: }
21172: } else {
21173: $errors .= '<li><span class="LC_error">'.
21174: &mt('An error occurred storing the settings: [_1]',
21175: $putresult).'</span></li>';
21176: }
21177: }
21178: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
21179: $resulttext = &mt('Changes made:').'<ul>';
21180: my (%shownprivs,@levelorder);
21181: @levelorder = ('c','d','s');
21182: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.166 raeburn 21183: foreach my $item (sort(keys(%changes))) {
21184: if ($item eq 'submitbugs') {
21185: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
21186: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
21187: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.282 raeburn 21188: } elsif ($item eq 'customrole') {
21189: if (ref($changes{'customrole'}) eq 'HASH') {
1.285 raeburn 21190: my @keyorder = ('order','desc','access','status','exc','inc');
21191: my %keytext = &Apache::lonlocal::texthash(
21192: order => 'Order',
21193: desc => 'Role description',
21194: access => 'Role usage',
1.300 droeschl 21195: status => 'Allowed institutional types',
1.285 raeburn 21196: exc => 'Allowed personnel',
21197: inc => 'Disallowed personnel',
21198: );
1.282 raeburn 21199: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.285 raeburn 21200: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
21201: if ($role eq $newrole) {
21202: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
21203: $role).'<ul>';
21204: } else {
21205: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21206: $role).'<ul>';
21207: }
21208: foreach my $key (@keyorder) {
21209: if ($changes{'customrole'}{$role}{$key}) {
21210: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
21211: $keytext{$key},$newsettings{$role}{$key}).
21212: '</li>';
21213: }
21214: }
21215: if (ref($changedprivs{$role}) eq 'HASH') {
21216: $shownprivs{$role} = 1;
21217: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
21218: foreach my $level (@levelorder) {
21219: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21220: next if ($item eq '');
21221: my ($priv) = split(/\&/,$item,2);
21222: if (&Apache::lonnet::plaintext($priv)) {
21223: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21224: unless ($level eq 'c') {
21225: $resulttext .= ' ('.$lt{$level}.')';
21226: }
21227: $resulttext .= '</li>';
21228: }
21229: }
21230: }
21231: $resulttext .= '</ul>';
21232: }
21233: $resulttext .= '</ul></li>';
21234: }
21235: }
21236: }
21237: }
21238: }
21239: }
21240: if (keys(%changedprivs)) {
21241: foreach my $role (sort(keys(%changedprivs))) {
21242: unless ($shownprivs{$role}) {
21243: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
21244: $role).'<ul>'.
21245: '<li>'.&mt('Privileges set to :').'<ul>';
21246: foreach my $level (@levelorder) {
21247: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
21248: next if ($item eq '');
21249: my ($priv) = split(/\&/,$item,2);
21250: if (&Apache::lonnet::plaintext($priv)) {
21251: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
21252: unless ($level eq 'c') {
21253: $resulttext .= ' ('.$lt{$level}.')';
21254: }
21255: $resulttext .= '</li>';
21256: }
1.282 raeburn 21257: }
21258: }
1.285 raeburn 21259: $resulttext .= '</ul></li></ul></li>';
1.166 raeburn 21260: }
21261: }
21262: }
1.285 raeburn 21263: $resulttext .= '</ul>';
21264: } else {
21265: $resulttext = &mt('No changes made to help settings');
1.118 jms 21266: }
21267: if ($errors) {
1.168 raeburn 21268: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.285 raeburn 21269: $errors.'</ul>';
1.118 jms 21270: }
21271: return $resulttext;
21272: }
21273:
1.121 raeburn 21274: sub modify_coursedefaults {
1.212 raeburn 21275: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 21276: my ($resulttext,$errors,%changes,%defaultshash);
1.257 raeburn 21277: my %defaultchecked = (
21278: 'canuse_pdfforms' => 'off',
21279: 'uselcmath' => 'on',
1.398 raeburn 21280: 'usejsme' => 'on',
21281: 'inline_chem' => 'on',
1.404 raeburn 21282: 'ltiauth' => 'off',
1.257 raeburn 21283: );
1.404 raeburn 21284: my @toggles = ('canuse_pdfforms','uselcmath','usejsme','inline_chem','ltiauth');
1.198 raeburn 21285: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.276 raeburn 21286: 'uploadquota_community','uploadquota_textbook','uploadquota_placement',
1.428 raeburn 21287: 'coursequota_official','coursequota_unofficial','coursequota_community',
21288: 'coursequota_textbook','coursequota_placement','mysqltables_official',
21289: 'mysqltables_unofficial','mysqltables_community','mysqltables_textbook',
21290: 'mysqltables_placement');
1.271 raeburn 21291: my @types = ('official','unofficial','community','textbook','placement');
1.198 raeburn 21292: my %staticdefaults = (
21293: anonsurvey_threshold => 10,
21294: uploadquota => 500,
1.428 raeburn 21295: coursequota => 20,
1.257 raeburn 21296: postsubmit => 60,
1.276 raeburn 21297: mysqltables => 172800,
1.422 raeburn 21298: domexttool => 1,
1.432 raeburn 21299: crsauthor => 1,
1.438 raeburn 21300: crseditors => ['edit','xml'],
1.198 raeburn 21301: );
1.314 raeburn 21302: my %texoptions = (
21303: MathJax => 'MathJax',
21304: mimetex => &mt('Convert to Images'),
21305: tth => &mt('TeX to HTML'),
21306: );
1.438 raeburn 21307:
21308: my @editors = ('edit','xml','daxe');
21309: my %editornames = &crseditor_titles();
21310:
1.121 raeburn 21311: $defaultshash{'coursedefaults'} = {};
21312:
21313: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
21314: if ($domconfig{'coursedefaults'} eq '') {
21315: $domconfig{'coursedefaults'} = {};
21316: }
21317: }
21318:
21319: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
21320: foreach my $item (@toggles) {
21321: if ($defaultchecked{$item} eq 'on') {
21322: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21323: ($env{'form.'.$item} eq '0')) {
21324: $changes{$item} = 1;
1.192 raeburn 21325: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 21326: $changes{$item} = 1;
21327: }
21328: } elsif ($defaultchecked{$item} eq 'off') {
21329: if (($domconfig{'coursedefaults'}{$item} eq '') &&
21330: ($env{'form.'.$item} eq '1')) {
21331: $changes{$item} = 1;
21332: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
21333: $changes{$item} = 1;
21334: }
21335: }
21336: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
21337: }
1.198 raeburn 21338: foreach my $item (@numbers) {
21339: my ($currdef,$newdef);
1.208 raeburn 21340: $newdef = $env{'form.'.$item};
1.198 raeburn 21341: if ($item eq 'anonsurvey_threshold') {
21342: $currdef = $domconfig{'coursedefaults'}{$item};
21343: $newdef =~ s/\D//g;
21344: if ($newdef eq '' || $newdef < 1) {
21345: $newdef = 1;
21346: }
21347: $defaultshash{'coursedefaults'}{$item} = $newdef;
21348: } else {
1.428 raeburn 21349: my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.276 raeburn 21350: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
21351: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.198 raeburn 21352: }
21353: $newdef =~ s/[^\w.\-]//g;
1.276 raeburn 21354: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.198 raeburn 21355: }
21356: if ($currdef ne $newdef) {
21357: if ($item eq 'anonsurvey_threshold') {
21358: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
21359: $changes{$item} = 1;
21360: }
1.428 raeburn 21361: } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.289 raeburn 21362: my $setting = $1;
1.276 raeburn 21363: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
21364: $changes{$setting} = 1;
1.198 raeburn 21365: }
21366: }
1.139 raeburn 21367: }
21368: }
1.314 raeburn 21369: my $texengine;
21370: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
21371: $texengine = $env{'form.texengine'};
1.349 raeburn 21372: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
21373: if ($currdef eq '') {
21374: unless ($texengine eq $Apache::lonnet::deftex) {
1.314 raeburn 21375: $changes{'texengine'} = 1;
21376: }
1.349 raeburn 21377: } elsif ($currdef ne $texengine) {
1.314 raeburn 21378: $changes{'texengine'} = 1;
21379: }
21380: }
21381: if ($texengine ne '') {
21382: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
21383: }
1.264 raeburn 21384: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
21385: my @currclonecode;
21386: if (ref($currclone) eq 'HASH') {
21387: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
21388: @currclonecode = @{$currclone->{'instcode'}};
21389: }
21390: }
21391: my $newclone;
1.289 raeburn 21392: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
1.264 raeburn 21393: $newclone = $env{'form.canclone'};
21394: }
21395: if ($newclone eq 'instcode') {
21396: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
21397: my (%codedefaults,@code_order,@clonecode);
21398: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
21399: \@code_order);
21400: foreach my $item (@code_order) {
21401: if (grep(/^\Q$item\E$/,@newcodes)) {
21402: push(@clonecode,$item);
21403: }
21404: }
21405: if (@clonecode) {
21406: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
21407: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
21408: if (@diffs) {
21409: $changes{'canclone'} = 1;
21410: }
21411: } else {
21412: $newclone eq '';
21413: }
21414: } elsif ($newclone ne '') {
1.289 raeburn 21415: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
21416: }
1.264 raeburn 21417: if ($newclone ne $currclone) {
21418: $changes{'canclone'} = 1;
21419: }
1.257 raeburn 21420: my %credits;
21421: foreach my $type (@types) {
21422: unless ($type eq 'community') {
21423: $credits{$type} = $env{'form.'.$type.'_credits'};
21424: $credits{$type} =~ s/[^\d.]+//g;
21425: }
21426: }
21427: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
21428: ($env{'form.coursecredits'} eq '1')) {
21429: $changes{'coursecredits'} = 1;
21430: foreach my $type (keys(%credits)) {
21431: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21432: }
21433: } else {
1.289 raeburn 21434: if ($env{'form.coursecredits'} eq '1') {
1.257 raeburn 21435: foreach my $type (@types) {
21436: unless ($type eq 'community') {
1.289 raeburn 21437: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
1.257 raeburn 21438: $changes{'coursecredits'} = 1;
21439: }
21440: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
21441: }
21442: }
21443: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21444: foreach my $type (@types) {
21445: unless ($type eq 'community') {
21446: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
21447: $changes{'coursecredits'} = 1;
21448: last;
21449: }
21450: }
21451: }
21452: }
21453: }
21454: if ($env{'form.postsubmit'} eq '1') {
21455: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
21456: my %currtimeout;
21457: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21458: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
21459: $changes{'postsubmit'} = 1;
21460: }
21461: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21462: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
21463: }
21464: } else {
21465: $changes{'postsubmit'} = 1;
21466: }
21467: foreach my $type (@types) {
21468: my $timeout = $env{'form.'.$type.'_timeout'};
21469: $timeout =~ s/\D//g;
21470: if ($timeout == $staticdefaults{'postsubmit'}) {
21471: $timeout = '';
21472: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
21473: $timeout = '0';
21474: }
21475: unless ($timeout eq '') {
21476: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
21477: }
21478: if (exists($currtimeout{$type})) {
21479: if ($timeout ne $currtimeout{$type}) {
1.289 raeburn 21480: $changes{'postsubmit'} = 1;
1.257 raeburn 21481: }
21482: } elsif ($timeout ne '') {
21483: $changes{'postsubmit'} = 1;
21484: }
21485: }
21486: } else {
21487: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
21488: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21489: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
21490: $changes{'postsubmit'} = 1;
21491: }
21492: } else {
21493: $changes{'postsubmit'} = 1;
21494: }
1.192 raeburn 21495: }
1.438 raeburn 21496: my (%newdomexttool,%newexttool,%newcrsauthor,%olddomexttool,%oldexttool,%oldcrsauthor,
21497: %posscrseditors);
1.422 raeburn 21498: map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
1.425 raeburn 21499: map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
1.432 raeburn 21500: map { $newcrsauthor{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crsauthor');
1.438 raeburn 21501: map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
1.422 raeburn 21502: if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21503: %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
21504: } else {
21505: foreach my $type (@types) {
21506: if ($staticdefaults{'domexttool'}) {
21507: $olddomexttool{$type} = 1;
21508: } else {
21509: $olddomexttool{$type} = 0;
21510: }
21511: }
21512: }
21513: if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
1.425 raeburn 21514: %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
1.422 raeburn 21515: } else {
21516: foreach my $type (@types) {
21517: if ($staticdefaults{'exttool'}) {
21518: $oldexttool{$type} = 1;
21519: } else {
21520: $oldexttool{$type} = 0;
21521: }
21522: }
21523: }
1.432 raeburn 21524: if (ref($domconfig{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21525: %oldcrsauthor = %{$domconfig{'coursedefaults'}{'crsauthor'}};
21526: } else {
21527: foreach my $type (@types) {
21528: if ($staticdefaults{'crsauthor'}) {
21529: $oldcrsauthor{$type} = 1;
21530: } else {
21531: $oldcrsauthor{$type} = 0;
21532: }
21533: }
21534: }
1.438 raeburn 21535: my @newcrseditors = ();
21536: foreach my $editor (@editors) {
21537: if ($posscrseditors{$editor}) {
21538: push(@newcrseditors,$editor);
21539: }
21540: }
21541: if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21542: my @diffs =
21543: &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
21544: \@newcrseditors);
21545: if (@diffs) {
21546: $changes{'crseditors'} = 1;
21547: }
21548: } else {
21549: my @diffs =
21550: &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
21551: \@newcrseditors);
21552: unless (@diffs == 0) {
21553: $changes{'crseditors'} = 1;
21554: }
21555: }
1.422 raeburn 21556: foreach my $type (@types) {
21557: unless ($newdomexttool{$type}) {
21558: $newdomexttool{$type} = 0;
21559: }
21560: unless ($newexttool{$type}) {
21561: $newexttool{$type} = 0;
21562: }
1.432 raeburn 21563: unless ($newcrsauthor{$type}) {
21564: $newcrsauthor{$type} = 0;
21565: }
1.422 raeburn 21566: if ($newdomexttool{$type} != $olddomexttool{$type}) {
21567: $changes{'domexttool'} = 1;
21568: }
21569: if ($newexttool{$type} != $oldexttool{$type}) {
21570: $changes{'exttool'} = 1;
21571: }
1.432 raeburn 21572: if ($newcrsauthor{$type} != $oldcrsauthor{$type}) {
21573: $changes{'crsauthor'} = 1;
21574: }
1.422 raeburn 21575: }
21576: $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
21577: $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.432 raeburn 21578: $defaultshash{'coursedefaults'}{'crsauthor'} = \%newcrsauthor;
1.438 raeburn 21579: $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 21580: }
21581: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
21582: $dom);
21583: if ($putresult eq 'ok') {
21584: if (keys(%changes) > 0) {
1.213 raeburn 21585: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.257 raeburn 21586: if (($changes{'canuse_pdfforms'}) || ($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.264 raeburn 21587: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.398 raeburn 21588: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.422 raeburn 21589: ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
1.432 raeburn 21590: ($changes{'exttool'}) || ($changes{'coursequota'}) || ($changes{'crsauthor'})) {
1.422 raeburn 21591: foreach my $item ('canuse_pdfforms','uselcmath','usejsme','inline_chem','texengine',
21592: 'ltiauth') {
1.257 raeburn 21593: if ($changes{$item}) {
21594: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
21595: }
1.289 raeburn 21596: }
1.192 raeburn 21597: if ($changes{'coursecredits'}) {
21598: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.257 raeburn 21599: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
21600: $domdefaults{$type.'credits'} =
21601: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
21602: }
21603: }
21604: }
21605: if ($changes{'postsubmit'}) {
21606: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
21607: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
21608: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21609: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
21610: $domdefaults{$type.'postsubtimeout'} =
21611: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21612: }
21613: }
1.192 raeburn 21614: }
21615: }
1.198 raeburn 21616: if ($changes{'uploadquota'}) {
21617: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21618: foreach my $type (@types) {
21619: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
21620: }
21621: }
21622: }
1.428 raeburn 21623: if ($changes{'coursequota'}) {
21624: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21625: foreach my $type (@types) {
21626: $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
21627: }
21628: }
21629: }
1.264 raeburn 21630: if ($changes{'canclone'}) {
21631: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21632: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21633: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
21634: if (@clonecodes) {
21635: $domdefaults{'canclone'} = join('+',@clonecodes);
21636: }
21637: }
21638: } else {
21639: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
21640: }
21641: }
1.422 raeburn 21642: if ($changes{'domexttool'}) {
21643: if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
21644: foreach my $type (@types) {
21645: $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
21646: }
21647: }
21648: }
21649: if ($changes{'exttool'}) {
21650: if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
21651: foreach my $type (@types) {
21652: $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
21653: }
21654: }
21655: }
1.432 raeburn 21656: if ($changes{'crsauthor'}) {
21657: if (ref($defaultshash{'coursedefaults'}{'crsauthor'}) eq 'HASH') {
21658: foreach my $type (@types) {
21659: $domdefaults{$type.'crsauthor'}=$defaultshash{'coursedefaults'}{'crsauthor'}{$type};
21660: }
21661: }
21662: }
1.438 raeburn 21663: if ($changes{'crseditors'}) {
21664: if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
21665: $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
21666: }
21667: }
1.121 raeburn 21668: my $cachetime = 24*60*60;
21669: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 raeburn 21670: if (ref($lastactref) eq 'HASH') {
21671: $lastactref->{'domdefaults'} = 1;
21672: }
1.121 raeburn 21673: }
21674: $resulttext = &mt('Changes made:').'<ul>';
21675: foreach my $item (sort(keys(%changes))) {
21676: if ($item eq 'canuse_pdfforms') {
21677: if ($env{'form.'.$item} eq '1') {
21678: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
21679: } else {
21680: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
21681: }
1.257 raeburn 21682: } elsif ($item eq 'uselcmath') {
21683: if ($env{'form.'.$item} eq '1') {
21684: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
21685: } else {
21686: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
21687: }
21688: } elsif ($item eq 'usejsme') {
21689: if ($env{'form.'.$item} eq '1') {
21690: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
21691: } else {
1.289 raeburn 21692: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.257 raeburn 21693: }
1.398 raeburn 21694: } elsif ($item eq 'inline_chem') {
21695: if ($env{'form.'.$item} eq '1') {
21696: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
21697: } else {
21698: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
21699: }
1.314 raeburn 21700: } elsif ($item eq 'texengine') {
21701: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
21702: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
21703: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
21704: }
1.139 raeburn 21705: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 21706: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 21707: } elsif ($item eq 'uploadquota') {
21708: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
21709: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
21710: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
21711: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.216 raeburn 21712: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.271 raeburn 21713: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'placement'}.'</b>').'</li>'.
1.198 raeburn 21714: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
21715: '</ul>'.
21716: '</li>';
21717: } else {
21718: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
21719: }
1.428 raeburn 21720: } elsif ($item eq 'coursequota') {
21721: if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
21722: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
21723: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
21724: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
21725: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
21726: '<li>'.&mt('Placement tests: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'placement'}.'</b>').'</li>'.
21727: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
21728: '</ul>'.
21729: '</li>';
21730: } else {
21731: $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
21732: }
1.276 raeburn 21733: } elsif ($item eq 'mysqltables') {
21734: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
21735: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
21736: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
21737: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
21738: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
21739: '<li>'.&mt('Placement tests: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'placement'}.'</b>').'</li>'.
21740: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
21741: '</ul>'.
21742: '</li>';
21743: } else {
21744: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
21745: }
1.257 raeburn 21746: } elsif ($item eq 'postsubmit') {
21747: if ($domdefaults{'postsubmit'} eq 'off') {
21748: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
21749: } else {
21750: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
1.289 raeburn 21751: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
1.257 raeburn 21752: $resulttext .= &mt('durations:').'<ul>';
21753: foreach my $type (@types) {
21754: $resulttext .= '<li>';
21755: my $timeout;
21756: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
21757: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
21758: }
21759: my $display;
21760: if ($timeout eq '0') {
21761: $display = &mt('unlimited');
21762: } elsif ($timeout eq '') {
21763: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
21764: } else {
21765: $display = &mt('[quant,_1,second]',$timeout);
21766: }
21767: if ($type eq 'community') {
21768: $resulttext .= &mt('Communities');
21769: } elsif ($type eq 'official') {
21770: $resulttext .= &mt('Official courses');
21771: } elsif ($type eq 'unofficial') {
21772: $resulttext .= &mt('Unofficial courses');
21773: } elsif ($type eq 'textbook') {
21774: $resulttext .= &mt('Textbook courses');
1.271 raeburn 21775: } elsif ($type eq 'placement') {
21776: $resulttext .= &mt('Placement tests');
1.257 raeburn 21777: }
21778: $resulttext .= ' -- '.$display.'</li>';
21779: }
21780: $resulttext .= '</ul>';
21781: }
1.289 raeburn 21782: $resulttext .= '</li>';
1.257 raeburn 21783: }
1.192 raeburn 21784: } elsif ($item eq 'coursecredits') {
21785: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
21786: if (($domdefaults{'officialcredits'} eq '') &&
1.216 raeburn 21787: ($domdefaults{'unofficialcredits'} eq '') &&
21788: ($domdefaults{'textbookcredits'} eq '')) {
1.192 raeburn 21789: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21790: } else {
21791: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
21792: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
21793: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.216 raeburn 21794: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.192 raeburn 21795: '</ul>'.
21796: '</li>';
21797: }
21798: } else {
21799: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
21800: }
1.264 raeburn 21801: } elsif ($item eq 'canclone') {
21802: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
21803: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
21804: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
21805: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
21806: }
21807: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
21808: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
21809: } else {
1.289 raeburn 21810: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
1.264 raeburn 21811: }
1.404 raeburn 21812: } elsif ($item eq 'ltiauth') {
21813: if ($env{'form.'.$item} eq '1') {
21814: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
21815: } else {
21816: $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
21817: }
1.432 raeburn 21818: } elsif (($item eq 'domexttool') || ($item eq 'exttool') || ($item eq 'crsauthor')) {
1.422 raeburn 21819: my @noyes = (&mt('no'),&mt('yes'));
1.432 raeburn 21820: my %status = (
21821: domexttool => {
21822: ishash => &mt('External Tools defined in the domain may be used as follows:'),
21823: default => &mt('External Tools defined in the domain may be used in all course types, by default'),
21824: },
21825: exttool => {
21826: ishash => &mt('External Tools can be defined and configured in course containers as follows:'),
21827: default => &mt('External Tools can not be defined in any course types, by default'),
21828: },
21829: crsauthor => {
21830: ishash => &mt('Standard Problems can be created within course containers as follows:'),
21831: default => &mt('Standard Problems can be created within any course type, by default'),
21832: },
21833: );
21834:
21835: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'HASH') {
21836: $resulttext .= '<li>'.$status{$item}{'ishash'}.'<ul>'.
21837: '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'official'}].'</b>').'</li>'.
21838: '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'unofficial'}].'</b>').'</li>'.
21839: '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'textbook'}].'</b>').'</li>'.
21840: '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'placement'}].'</b>').'</li>'.
21841: '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{$item}{'community'}].'</b>').'</li>'.
1.422 raeburn 21842: '</ul>'.
21843: '</li>';
21844: } else {
1.432 raeburn 21845: $resulttext .= '<li>'.$status{$item}{'default'}.'</li>';
1.422 raeburn 21846: }
1.438 raeburn 21847: } elsif ($item eq 'crseditors') {
21848: if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
21849: my $shown;
21850: if (@{$defaultshash{'coursedefaults'}{$item}}) {
21851: $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
21852: } else {
21853: $shown = &mt('None');
21854: }
21855: $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
21856: }
1.140 raeburn 21857: }
1.121 raeburn 21858: }
21859: $resulttext .= '</ul>';
21860: } else {
21861: $resulttext = &mt('No changes made to course defaults');
21862: }
21863: } else {
21864: $resulttext = '<span class="LC_error">'.
21865: &mt('An error occurred: [_1]',$putresult).'</span>';
21866: }
21867: return $resulttext;
21868: }
21869:
1.231 raeburn 21870: sub modify_selfenrollment {
21871: my ($dom,$lastactref,%domconfig) = @_;
21872: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
1.271 raeburn 21873: my @types = ('official','unofficial','community','textbook','placement');
1.231 raeburn 21874: my %titles = &tool_titles();
1.232 raeburn 21875: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
21876: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
1.231 raeburn 21877: $ordered{'default'} = ['types','registered','approval','limit'];
21878:
21879: my (%roles,%shown,%toplevel);
21880: $roles{'0'} = &Apache::lonnet::plaintext('dc');
21881:
21882: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
21883: if ($domconfig{'selfenrollment'} eq '') {
21884: $domconfig{'selfenrollment'} = {};
21885: }
21886: }
21887: %toplevel = (
21888: admin => 'Configuration Rights',
21889: default => 'Default settings',
21890: validation => 'Validation of self-enrollment requests',
21891: );
1.233 raeburn 21892: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
1.231 raeburn 21893:
21894: if (ref($ordered{'admin'}) eq 'ARRAY') {
21895: foreach my $item (@{$ordered{'admin'}}) {
21896: foreach my $type (@types) {
21897: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
21898: $selfenrollhash{'admin'}{$type}{$item} = 1;
21899: } else {
21900: $selfenrollhash{'admin'}{$type}{$item} = 0;
21901: }
21902: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
21903: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
21904: if ($selfenrollhash{'admin'}{$type}{$item} ne
21905: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
21906: push(@{$changes{'admin'}{$type}},$item);
21907: }
21908: } else {
21909: if (!$selfenrollhash{'admin'}{$type}{$item}) {
21910: push(@{$changes{'admin'}{$type}},$item);
21911: }
21912: }
21913: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
21914: push(@{$changes{'admin'}{$type}},$item);
21915: }
21916: }
21917: }
21918: }
21919:
21920: foreach my $item (@{$ordered{'default'}}) {
21921: foreach my $type (@types) {
21922: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
21923: if ($item eq 'types') {
21924: unless (($value eq 'all') || ($value eq 'dom')) {
21925: $value = '';
21926: }
21927: } elsif ($item eq 'registered') {
21928: unless ($value eq '1') {
21929: $value = 0;
21930: }
21931: } elsif ($item eq 'approval') {
21932: unless ($value =~ /^[012]$/) {
21933: $value = 0;
21934: }
21935: } else {
21936: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21937: $value = 'none';
21938: }
21939: }
21940: $selfenrollhash{'default'}{$type}{$item} = $value;
21941: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
21942: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21943: if ($selfenrollhash{'default'}{$type}{$item} ne
21944: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
21945: push(@{$changes{'default'}{$type}},$item);
21946: }
21947: } else {
21948: push(@{$changes{'default'}{$type}},$item);
21949: }
21950: } else {
21951: push(@{$changes{'default'}{$type}},$item);
21952: }
21953: if ($item eq 'limit') {
21954: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
21955: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
21956: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
21957: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
21958: }
21959: } else {
21960: $selfenrollhash{'default'}{$type}{'cap'} = '';
21961: }
21962: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
21963: if ($selfenrollhash{'default'}{$type}{'cap'} ne
21964: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
21965: push(@{$changes{'default'}{$type}},'cap');
21966: }
21967: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
21968: push(@{$changes{'default'}{$type}},'cap');
21969: }
21970: }
21971: }
21972: }
21973:
21974: foreach my $item (@{$itemsref}) {
21975: if ($item eq 'fields') {
21976: my @changed;
21977: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
21978: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
21979: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
21980: }
21981: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
21982: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
21983: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
21984: $domconfig{'selfenrollment'}{'validation'}{$item});
21985: } else {
21986: @changed = @{$selfenrollhash{'validation'}{$item}};
21987: }
21988: } else {
21989: @changed = @{$selfenrollhash{'validation'}{$item}};
21990: }
21991: if (@changed) {
21992: if ($selfenrollhash{'validation'}{$item}) {
21993: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
21994: } else {
21995: $changes{'validation'}{$item} = &mt('None');
21996: }
21997: }
21998: } else {
21999: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
22000: if ($item eq 'markup') {
22001: if ($env{'form.selfenroll_validation_'.$item}) {
22002: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
22003: }
22004: }
22005: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
22006: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
22007: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
22008: }
22009: }
22010: }
22011: }
22012:
22013: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
22014: $dom);
22015: if ($putresult eq 'ok') {
22016: if (keys(%changes) > 0) {
22017: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22018: $resulttext = &mt('Changes made:').'<ul>';
22019: foreach my $key ('admin','default','validation') {
22020: if (ref($changes{$key}) eq 'HASH') {
22021: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
22022: if ($key eq 'validation') {
22023: foreach my $item (@{$itemsref}) {
22024: if (exists($changes{$key}{$item})) {
22025: if ($item eq 'markup') {
22026: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22027: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
22028: } else {
22029: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
22030: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
22031: }
22032: }
22033: }
22034: } else {
22035: foreach my $type (@types) {
22036: if ($type eq 'community') {
22037: $roles{'1'} = &mt('Community personnel');
22038: } else {
22039: $roles{'1'} = &mt('Course personnel');
22040: }
22041: if (ref($changes{$key}{$type}) eq 'ARRAY') {
1.232 raeburn 22042: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22043: if ($key eq 'admin') {
22044: my @mgrdc = ();
22045: if (ref($ordered{$key}) eq 'ARRAY') {
22046: foreach my $item (@{$ordered{'admin'}}) {
22047: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
22048: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
22049: push(@mgrdc,$item);
22050: }
22051: }
22052: }
22053: if (@mgrdc) {
22054: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
22055: } else {
22056: delete($domdefaults{$type.'selfenrolladmdc'});
22057: }
22058: }
22059: } else {
22060: if (ref($ordered{$key}) eq 'ARRAY') {
22061: foreach my $item (@{$ordered{$key}}) {
22062: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22063: $domdefaults{$type.'selfenroll'.$item} =
22064: $selfenrollhash{$key}{$type}{$item};
22065: }
22066: }
22067: }
22068: }
22069: }
1.231 raeburn 22070: $resulttext .= '<li>'.$titles{$type}.'<ul>';
22071: foreach my $item (@{$ordered{$key}}) {
22072: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
22073: $resulttext .= '<li>';
22074: if ($key eq 'admin') {
22075: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
22076: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
22077: } else {
22078: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
22079: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
22080: }
22081: $resulttext .= '</li>';
22082: }
22083: }
22084: $resulttext .= '</ul></li>';
22085: }
22086: }
22087: $resulttext .= '</ul></li>';
22088: }
22089: }
1.305 raeburn 22090: }
22091: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
22092: my $cachetime = 24*60*60;
22093: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22094: if (ref($lastactref) eq 'HASH') {
22095: $lastactref->{'domdefaults'} = 1;
1.232 raeburn 22096: }
1.231 raeburn 22097: }
22098: $resulttext .= '</ul>';
22099: } else {
22100: $resulttext = &mt('No changes made to self-enrollment settings');
22101: }
22102: } else {
22103: $resulttext = '<span class="LC_error">'.
22104: &mt('An error occurred: [_1]',$putresult).'</span>';
22105: }
22106: return $resulttext;
22107: }
22108:
1.373 raeburn 22109: sub modify_wafproxy {
22110: my ($dom,$action,$lastactref,%domconfig) = @_;
22111: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.388 raeburn 22112: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
22113: %wafproxy,%changes,%expirecache,%expiresaml);
1.373 raeburn 22114: foreach my $server (sort(keys(%servers))) {
22115: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
22116: if ($serverhome eq $server) {
22117: my $serverdom = &Apache::lonnet::host_domain($server);
22118: if ($serverdom eq $dom) {
22119: $canset{$server} = 1;
22120: }
22121: }
22122: }
1.381 raeburn 22123: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
22124: %{$values{$dom}} = ();
22125: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
22126: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
22127: }
1.388 raeburn 22128: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
22129: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
22130: }
1.382 raeburn 22131: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.381 raeburn 22132: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
22133: }
22134: }
1.373 raeburn 22135: my $output;
22136: if (keys(%canset)) {
22137: %{$wafproxy{'alias'}} = ();
1.388 raeburn 22138: %{$wafproxy{'saml'}} = ();
1.373 raeburn 22139: foreach my $key (sort(keys(%canset))) {
1.381 raeburn 22140: if ($env{'form.wafproxy_'.$dom}) {
22141: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
22142: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
22143: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
22144: $changes{'alias'} = 1;
22145: }
1.388 raeburn 22146: if ($env{'form.wafproxy_alias_saml_'.$key}) {
22147: $wafproxy{'saml'}{$key} = 1;
22148: }
22149: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
22150: $changes{'saml'} = 1;
22151: }
1.381 raeburn 22152: } else {
22153: $wafproxy{'alias'}{$key} = '';
1.388 raeburn 22154: $wafproxy{'saml'}{$key} = '';
1.381 raeburn 22155: if ($curralias{$key}) {
22156: $changes{'alias'} = 1;
22157: }
1.388 raeburn 22158: if ($currsaml{$key}) {
22159: $changes{'saml'} = 1;
22160: }
1.373 raeburn 22161: }
22162: if ($wafproxy{'alias'}{$key} eq '') {
22163: if ($curralias{$key}) {
22164: $expirecache{$key} = 1;
22165: }
22166: delete($wafproxy{'alias'}{$key});
22167: }
1.388 raeburn 22168: if ($wafproxy{'saml'}{$key} eq '') {
22169: if ($currsaml{$key}) {
22170: $expiresaml{$key} = 1;
22171: }
22172: delete($wafproxy{'saml'}{$key});
22173: }
1.373 raeburn 22174: }
22175: unless (keys(%{$wafproxy{'alias'}})) {
22176: delete($wafproxy{'alias'});
22177: }
1.388 raeburn 22178: unless (keys(%{$wafproxy{'saml'}})) {
22179: delete($wafproxy{'saml'});
22180: }
22181: # Localization for values in %warn occurs in &mt() calls separately.
1.373 raeburn 22182: my %warn = (
22183: trusted => 'trusted IP range(s)',
1.381 raeburn 22184: vpnint => 'internal IP range(s) for VPN sessions(s)',
22185: vpnext => 'IP range(s) for backend WAF connections',
1.373 raeburn 22186: );
1.382 raeburn 22187: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22188: my $possible = $env{'form.wafproxy_'.$item};
22189: $possible =~ s/^\s+|\s+$//g;
22190: if ($possible ne '') {
1.381 raeburn 22191: if ($item eq 'remoteip') {
22192: if ($possible =~ /^[mhn]$/) {
22193: $wafproxy{$item} = $possible;
22194: }
22195: } elsif ($item eq 'ipheader') {
22196: if ($wafproxy{'remoteip'} eq 'h') {
22197: $wafproxy{$item} = $possible;
22198: }
1.382 raeburn 22199: } elsif ($item eq 'sslopt') {
22200: if ($possible =~ /^0|1$/) {
22201: $wafproxy{$item} = $possible;
22202: }
1.373 raeburn 22203: } else {
22204: my (@ok,$count);
1.381 raeburn 22205: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
22206: unless ($env{'form.wafproxy_vpnaccess'}) {
22207: $possible = '';
22208: }
22209: } elsif ($item eq 'trusted') {
22210: unless ($wafproxy{'remoteip'} eq 'h') {
22211: $possible = '';
22212: }
22213: }
22214: unless ($possible eq '') {
22215: $possible =~ s/[\r\n]+/\s/g;
22216: $possible =~ s/\s*-\s*/-/g;
22217: $possible =~ s/\s+/,/g;
1.393 raeburn 22218: $possible =~ s/,+/,/g;
1.381 raeburn 22219: }
1.373 raeburn 22220: $count = 0;
1.381 raeburn 22221: if ($possible ne '') {
1.373 raeburn 22222: foreach my $poss (split(/\,/,$possible)) {
22223: $count ++;
1.393 raeburn 22224: $poss = &validate_ip_pattern($poss);
22225: if ($poss ne '') {
1.373 raeburn 22226: push(@ok,$poss);
22227: }
22228: }
22229: my $diff = $count - scalar(@ok);
22230: if ($diff) {
22231: push(@warnings,'<li>'.
22232: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
22233: $diff,$warn{$item}).
22234: '</li>');
22235: }
1.393 raeburn 22236: if (@ok) {
22237: my @cidr_list;
22238: foreach my $item (@ok) {
22239: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
22240: }
22241: $wafproxy{$item} = join(',',@cidr_list);
22242: }
1.373 raeburn 22243: }
22244: }
1.381 raeburn 22245: if ($wafproxy{$item} ne $currvalue{$item}) {
1.373 raeburn 22246: $changes{$item} = 1;
22247: }
1.381 raeburn 22248: } elsif ($currvalue{$item}) {
22249: $changes{$item} = 1;
1.425 raeburn 22250: }
1.381 raeburn 22251: }
22252: } else {
22253: if (keys(%curralias)) {
22254: $changes{'alias'} = 1;
1.388 raeburn 22255: }
22256: if (keys(%currsaml)) {
22257: $changes{'saml'} = 1;
1.425 raeburn 22258: }
1.381 raeburn 22259: if (keys(%currvalue)) {
22260: foreach my $key (keys(%currvalue)) {
22261: $changes{$key} = 1;
1.373 raeburn 22262: }
22263: }
22264: }
22265: if (keys(%changes)) {
22266: my %defaultshash = (
22267: wafproxy => \%wafproxy,
1.425 raeburn 22268: );
1.373 raeburn 22269: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22270: $dom);
22271: if ($putresult eq 'ok') {
22272: my $cachetime = 24*60*60;
22273: my (%domdefaults,$updatedomdefs);
1.382 raeburn 22274: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22275: if ($changes{$item}) {
22276: unless ($updatedomdefs) {
22277: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
22278: $updatedomdefs = 1;
22279: }
22280: if ($wafproxy{$item}) {
22281: $domdefaults{'waf_'.$item} = $wafproxy{$item};
22282: } elsif (exists($domdefaults{'waf_'.$item})) {
22283: delete($domdefaults{'waf_'.$item});
1.425 raeburn 22284: }
1.373 raeburn 22285: }
22286: }
22287: if ($updatedomdefs) {
22288: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22289: if (ref($lastactref) eq 'HASH') {
22290: $lastactref->{'domdefaults'} = 1;
22291: }
22292: }
22293: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
22294: my %updates = %expirecache;
22295: foreach my $key (keys(%expirecache)) {
22296: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
22297: }
22298: if (ref($wafproxy{'alias'}) eq 'HASH') {
22299: my $cachetime = 24*60*60;
22300: foreach my $key (keys(%{$wafproxy{'alias'}})) {
22301: $updates{$key} = 1;
22302: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
22303: $cachetime);
22304: }
22305: }
22306: if (ref($lastactref) eq 'HASH') {
22307: $lastactref->{'proxyalias'} = \%updates;
22308: }
22309: }
1.388 raeburn 22310: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
22311: my %samlupdates = %expiresaml;
22312: foreach my $key (keys(%expiresaml)) {
22313: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
22314: }
22315: if (ref($wafproxy{'saml'}) eq 'HASH') {
22316: my $cachetime = 24*60*60;
22317: foreach my $key (keys(%{$wafproxy{'saml'}})) {
22318: $samlupdates{$key} = 1;
22319: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
22320: $cachetime);
22321: }
22322: }
22323: if (ref($lastactref) eq 'HASH') {
22324: $lastactref->{'proxysaml'} = \%samlupdates;
22325: }
22326: }
1.373 raeburn 22327: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.401 raeburn 22328: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.373 raeburn 22329: if ($changes{$item}) {
22330: if ($item eq 'alias') {
22331: my $numaliased = 0;
22332: if (ref($wafproxy{'alias'}) eq 'HASH') {
22333: my $shown;
22334: if (keys(%{$wafproxy{'alias'}})) {
22335: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
22336: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
22337: &Apache::lonnet::hostname($server),
22338: $wafproxy{'alias'}{$server}).'</li>';
22339: $numaliased ++;
22340: }
22341: if ($numaliased) {
22342: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
22343: '<ul>'.$shown.'</ul>').'</li>';
22344: }
22345: }
22346: }
22347: unless ($numaliased) {
22348: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
22349: }
1.388 raeburn 22350: } elsif ($item eq 'saml') {
1.425 raeburn 22351: my $shown;
1.388 raeburn 22352: if (ref($wafproxy{'saml'}) eq 'HASH') {
22353: if (keys(%{$wafproxy{'saml'}})) {
22354: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
22355: }
22356: }
22357: if ($shown) {
1.396 raeburn 22358: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
1.388 raeburn 22359: $shown).'</li>';
22360: } else {
1.396 raeburn 22361: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
1.388 raeburn 22362: }
1.373 raeburn 22363: } else {
1.381 raeburn 22364: if ($item eq 'remoteip') {
22365: my %ip_methods = &remoteip_methods();
22366: if ($wafproxy{$item} =~ /^[mh]$/) {
22367: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
22368: $ip_methods{$wafproxy{$item}}).'</li>';
22369: } else {
22370: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
22371: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
22372: '</li>';
22373: } else {
22374: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
22375: }
22376: }
22377: } elsif ($item eq 'ipheader') {
1.373 raeburn 22378: if ($wafproxy{$item}) {
1.381 raeburn 22379: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
1.373 raeburn 22380: $wafproxy{$item}).'</li>';
22381: } else {
1.381 raeburn 22382: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
1.373 raeburn 22383: }
22384: } elsif ($item eq 'trusted') {
22385: if ($wafproxy{$item}) {
1.381 raeburn 22386: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
1.373 raeburn 22387: $wafproxy{$item}).'</li>';
22388: } else {
22389: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
22390: }
1.381 raeburn 22391: } elsif ($item eq 'vpnint') {
22392: if ($wafproxy{$item}) {
22393: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
22394: $wafproxy{$item}).'</li>';
22395: } else {
22396: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
22397: }
22398: } elsif ($item eq 'vpnext') {
1.373 raeburn 22399: if ($wafproxy{$item}) {
1.381 raeburn 22400: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
1.373 raeburn 22401: $wafproxy{$item}).'</li>';
22402: } else {
1.381 raeburn 22403: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
1.373 raeburn 22404: }
1.382 raeburn 22405: } elsif ($item eq 'sslopt') {
22406: if ($wafproxy{$item}) {
22407: $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>';
22408: } else {
22409: $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>';
22410: }
1.373 raeburn 22411: }
22412: }
22413: }
22414: }
1.420 raeburn 22415: $output .= '</ul>';
1.373 raeburn 22416: } else {
22417: $output = '<span class="LC_error">'.
22418: &mt('An error occurred: [_1]',$putresult).'</span>';
22419: }
22420: } elsif (keys(%canset)) {
22421: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
22422: }
22423: if (@warnings) {
22424: $output .= '<br />'.&mt('Warnings:').'<ul>'.
22425: join("\n",@warnings).'</ul>';
22426: }
22427: return $output;
22428: }
22429:
22430: sub validate_ip_pattern {
22431: my ($pattern) = @_;
22432: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
22433: my ($start,$end) = ($1,$2);
22434: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
1.393 raeburn 22435: if (($start !~ m{/}) && ($end !~ m{/})) {
22436: return $start.'-'.$end;
22437: }
22438: }
22439: } elsif ($pattern ne '') {
22440: $pattern = &Net::CIDR::cidrvalidate($pattern);
22441: if ($pattern ne '') {
22442: return $pattern;
1.373 raeburn 22443: }
22444: }
1.393 raeburn 22445: return;
1.373 raeburn 22446: }
22447:
1.137 raeburn 22448: sub modify_usersessions {
1.212 raeburn 22449: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 22450: my @hostingtypes = ('version','excludedomain','includedomain');
22451: my @offloadtypes = ('primary','default');
22452: my %types = (
22453: remote => \@hostingtypes,
22454: hosted => \@hostingtypes,
22455: spares => \@offloadtypes,
22456: );
22457: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 22458: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.275 raeburn 22459: my (%by_ip,%by_location,@intdoms,@instdoms);
22460: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
1.138 raeburn 22461: my @locations = sort(keys(%by_location));
1.137 raeburn 22462: my (%defaultshash,%changes);
22463: foreach my $prefix (@prefixes) {
22464: $defaultshash{'usersessions'}{$prefix} = {};
22465: }
1.212 raeburn 22466: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 22467: my $resulttext;
1.138 raeburn 22468: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 22469: foreach my $prefix (@prefixes) {
1.145 raeburn 22470: next if ($prefix eq 'spares');
22471: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 22472: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22473: if ($type eq 'version') {
22474: my $value = $env{'form.'.$prefix.'_'.$type};
22475: my $okvalue;
22476: if ($value ne '') {
22477: if (grep(/^\Q$value\E$/,@lcversions)) {
22478: $okvalue = $value;
22479: }
22480: }
22481: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22482: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22483: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
22484: if ($inuse == 0) {
22485: $changes{$prefix}{$type} = 1;
22486: } else {
22487: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
22488: $changes{$prefix}{$type} = 1;
22489: }
22490: if ($okvalue ne '') {
22491: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22492: }
22493: }
22494: } else {
22495: if (($inuse == 1) && ($okvalue ne '')) {
22496: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22497: $changes{$prefix}{$type} = 1;
22498: }
22499: }
22500: } else {
22501: if (($inuse == 1) && ($okvalue ne '')) {
22502: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22503: $changes{$prefix}{$type} = 1;
22504: }
22505: }
22506: } else {
22507: if (($inuse == 1) && ($okvalue ne '')) {
22508: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
22509: $changes{$prefix}{$type} = 1;
22510: }
22511: }
22512: } else {
22513: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22514: my @okvals;
22515: foreach my $val (@vals) {
1.138 raeburn 22516: if ($val =~ /:/) {
22517: my @items = split(/:/,$val);
22518: foreach my $item (@items) {
22519: if (ref($by_location{$item}) eq 'ARRAY') {
22520: push(@okvals,$item);
22521: }
22522: }
22523: } else {
22524: if (ref($by_location{$val}) eq 'ARRAY') {
22525: push(@okvals,$val);
22526: }
1.137 raeburn 22527: }
22528: }
22529: @okvals = sort(@okvals);
22530: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22531: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
22532: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22533: if ($inuse == 0) {
22534: $changes{$prefix}{$type} = 1;
22535: } else {
22536: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22537: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
22538: if (@changed > 0) {
22539: $changes{$prefix}{$type} = 1;
22540: }
22541: }
22542: } else {
22543: if ($inuse == 1) {
22544: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22545: $changes{$prefix}{$type} = 1;
22546: }
22547: }
22548: } else {
22549: if ($inuse == 1) {
22550: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22551: $changes{$prefix}{$type} = 1;
22552: }
22553: }
22554: } else {
22555: if ($inuse == 1) {
22556: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
22557: $changes{$prefix}{$type} = 1;
22558: }
22559: }
22560: }
22561: }
22562: }
1.145 raeburn 22563:
22564: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 22565: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 22566: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
22567: my $savespares;
22568:
22569: foreach my $lonhost (sort(keys(%servers))) {
22570: my $serverhomeID =
22571: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 22572: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 22573: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
22574: my %spareschg;
22575: foreach my $type (@{$types{'spares'}}) {
22576: my @okspares;
22577: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
22578: foreach my $server (@checked) {
1.152 raeburn 22579: if (&Apache::lonnet::hostname($server) ne '') {
22580: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
22581: unless (grep(/^\Q$server\E$/,@okspares)) {
22582: push(@okspares,$server);
22583: }
1.145 raeburn 22584: }
22585: }
22586: }
22587: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
22588: my $newspare;
1.152 raeburn 22589: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
22590: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 22591: $newspare = $new;
22592: }
22593: }
1.152 raeburn 22594: my @spares;
22595: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
22596: @spares = sort(@okspares,$newspare);
22597: } else {
22598: @spares = sort(@okspares);
22599: }
22600: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 22601: if (ref($spareid{$lonhost}) eq 'HASH') {
22602: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 22603: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 22604: if (@diffs > 0) {
22605: $spareschg{$type} = 1;
22606: }
22607: }
22608: }
22609: }
22610: if (keys(%spareschg) > 0) {
22611: $changes{'spares'}{$lonhost} = \%spareschg;
22612: }
22613: }
1.261 raeburn 22614: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.371 raeburn 22615: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.261 raeburn 22616: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
22617: my @okoffload;
22618: if (@offloadnow) {
22619: foreach my $server (@offloadnow) {
22620: if (&Apache::lonnet::hostname($server) ne '') {
22621: unless (grep(/^\Q$server\E$/,@okoffload)) {
22622: push(@okoffload,$server);
22623: }
22624: }
22625: }
22626: if (@okoffload) {
22627: foreach my $lonhost (@okoffload) {
22628: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
22629: }
22630: }
22631: }
1.371 raeburn 22632: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
22633: my @okoffloadoth;
22634: if (@offloadoth) {
22635: foreach my $server (@offloadoth) {
22636: if (&Apache::lonnet::hostname($server) ne '') {
22637: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
22638: push(@okoffloadoth,$server);
22639: }
22640: }
22641: }
22642: if (@okoffloadoth) {
22643: foreach my $lonhost (@okoffloadoth) {
22644: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
22645: }
22646: }
22647: }
1.145 raeburn 22648: if (ref($domconfig{'usersessions'}) eq 'HASH') {
22649: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
22650: if (ref($changes{'spares'}) eq 'HASH') {
22651: if (keys(%{$changes{'spares'}}) > 0) {
22652: $savespares = 1;
22653: }
22654: }
22655: } else {
22656: $savespares = 1;
22657: }
1.371 raeburn 22658: foreach my $offload ('offloadnow','offloadoth') {
22659: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
22660: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
22661: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
22662: $changes{$offload} = 1;
22663: last;
22664: }
1.261 raeburn 22665: }
1.371 raeburn 22666: unless ($changes{$offload}) {
22667: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
22668: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
22669: $changes{$offload} = 1;
22670: last;
22671: }
1.261 raeburn 22672: }
22673: }
1.371 raeburn 22674: } else {
22675: if (($offload eq 'offloadnow') && (@okoffload)) {
22676: $changes{'offloadnow'} = 1;
22677: }
22678: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
22679: $changes{'offloadoth'} = 1;
22680: }
1.425 raeburn 22681: }
1.371 raeburn 22682: }
22683: } else {
22684: if (@okoffload) {
1.261 raeburn 22685: $changes{'offloadnow'} = 1;
22686: }
1.371 raeburn 22687: if (@okoffloadoth) {
22688: $changes{'offloadoth'} = 1;
22689: }
1.145 raeburn 22690: }
1.147 raeburn 22691: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
22692: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 22693: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22694: $dom);
22695: if ($putresult eq 'ok') {
22696: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22697: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
22698: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
22699: }
22700: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
22701: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
22702: }
1.261 raeburn 22703: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22704: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
22705: }
1.371 raeburn 22706: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22707: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
22708: }
1.137 raeburn 22709: }
22710: my $cachetime = 24*60*60;
22711: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.295 raeburn 22712: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.212 raeburn 22713: if (ref($lastactref) eq 'HASH') {
22714: $lastactref->{'domdefaults'} = 1;
1.295 raeburn 22715: $lastactref->{'usersessions'} = 1;
1.212 raeburn 22716: }
1.147 raeburn 22717: if (keys(%changes) > 0) {
22718: my %lt = &usersession_titles();
22719: $resulttext = &mt('Changes made:').'<ul>';
22720: foreach my $prefix (@prefixes) {
22721: if (ref($changes{$prefix}) eq 'HASH') {
22722: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
22723: if ($prefix eq 'spares') {
22724: if (ref($changes{$prefix}) eq 'HASH') {
22725: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
22726: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 22727: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 22728: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
22729: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 22730: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
22731: foreach my $type (@{$types{$prefix}}) {
22732: if ($changes{$prefix}{$lonhost}{$type}) {
22733: my $offloadto = &mt('None');
22734: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
22735: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
22736: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
22737: }
1.145 raeburn 22738: }
1.147 raeburn 22739: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 22740: }
1.137 raeburn 22741: }
22742: }
1.147 raeburn 22743: $resulttext .= '</li>';
1.137 raeburn 22744: }
22745: }
1.147 raeburn 22746: } else {
22747: foreach my $type (@{$types{$prefix}}) {
22748: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22749: my ($newvalue,$notinuse);
1.147 raeburn 22750: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
22751: if (ref($defaultshash{'usersessions'}{$prefix})) {
22752: if ($type eq 'version') {
22753: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
1.344 raeburn 22754: } else {
22755: if (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
22756: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
22757: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
22758: }
22759: } else {
22760: $notinuse = 1;
1.147 raeburn 22761: }
1.145 raeburn 22762: }
22763: }
22764: }
1.147 raeburn 22765: if ($newvalue eq '') {
22766: if ($type eq 'version') {
22767: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
1.344 raeburn 22768: } elsif ($notinuse) {
22769: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
1.147 raeburn 22770: } else {
22771: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
22772: }
1.145 raeburn 22773: } else {
1.147 raeburn 22774: if ($type eq 'version') {
1.344 raeburn 22775: $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 22776: }
22777: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 22778: }
1.137 raeburn 22779: }
22780: }
22781: }
1.147 raeburn 22782: $resulttext .= '</ul>';
1.137 raeburn 22783: }
22784: }
1.261 raeburn 22785: if ($changes{'offloadnow'}) {
22786: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
22787: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.371 raeburn 22788: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.261 raeburn 22789: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
22790: $resulttext .= '<li>'.$lonhost.'</li>';
22791: }
22792: $resulttext .= '</ul>';
22793: } else {
1.371 raeburn 22794: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
22795: }
22796: } else {
22797: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
22798: }
22799: }
22800: if ($changes{'offloadoth'}) {
22801: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
22802: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
22803: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
22804: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
22805: $resulttext .= '<li>'.$lonhost.'</li>';
22806: }
22807: $resulttext .= '</ul>';
22808: } else {
22809: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.261 raeburn 22810: }
22811: } else {
1.371 raeburn 22812: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.261 raeburn 22813: }
22814: }
1.147 raeburn 22815: $resulttext .= '</ul>';
22816: } else {
22817: $resulttext = $nochgmsg;
1.137 raeburn 22818: }
22819: } else {
22820: $resulttext = '<span class="LC_error">'.
22821: &mt('An error occurred: [_1]',$putresult).'</span>';
22822: }
22823: } else {
1.147 raeburn 22824: $resulttext = $nochgmsg;
1.137 raeburn 22825: }
22826: return $resulttext;
22827: }
22828:
1.275 raeburn 22829: sub modify_ssl {
22830: my ($dom,$lastactref,%domconfig) = @_;
22831: my (%by_ip,%by_location,@intdoms,@instdoms);
22832: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
22833: my @locations = sort(keys(%by_location));
22834: my %servers = &Apache::lonnet::internet_dom_servers($dom);
22835: my (%defaultshash,%changes);
22836: my $action = 'ssl';
1.293 raeburn 22837: my @prefixes = ('connto','connfrom','replication');
1.275 raeburn 22838: foreach my $prefix (@prefixes) {
22839: $defaultshash{$action}{$prefix} = {};
22840: }
22841: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
22842: my $resulttext;
22843: my %iphost = &Apache::lonnet::get_iphost();
22844: my @reptypes = ('certreq','nocertreq');
22845: my @connecttypes = ('dom','intdom','other');
22846: my %types = (
1.293 raeburn 22847: connto => \@connecttypes,
22848: connfrom => \@connecttypes,
22849: replication => \@reptypes,
1.275 raeburn 22850: );
22851: foreach my $prefix (sort(keys(%types))) {
22852: foreach my $type (@{$types{$prefix}}) {
1.293 raeburn 22853: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22854: my $value = 'yes';
22855: if ($env{'form.'.$prefix.'_'.$type} =~ /^(no|req)$/) {
22856: $value = $env{'form.'.$prefix.'_'.$type};
22857: }
1.335 raeburn 22858: if (ref($domconfig{$action}) eq 'HASH') {
22859: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22860: if ($domconfig{$action}{$prefix}{$type} ne '') {
22861: if ($value ne $domconfig{$action}{$prefix}{$type}) {
22862: $changes{$prefix}{$type} = 1;
22863: }
22864: $defaultshash{$action}{$prefix}{$type} = $value;
22865: } else {
22866: $defaultshash{$action}{$prefix}{$type} = $value;
1.275 raeburn 22867: $changes{$prefix}{$type} = 1;
22868: }
22869: } else {
22870: $defaultshash{$action}{$prefix}{$type} = $value;
22871: $changes{$prefix}{$type} = 1;
22872: }
22873: } else {
22874: $defaultshash{$action}{$prefix}{$type} = $value;
22875: $changes{$prefix}{$type} = 1;
22876: }
22877: if (($type eq 'dom') && (keys(%servers) == 1)) {
22878: delete($changes{$prefix}{$type});
22879: } elsif (($type eq 'intdom') && (@instdoms == 1)) {
22880: delete($changes{$prefix}{$type});
22881: } elsif (($type eq 'other') && (keys(%by_location) == 0)) {
22882: delete($changes{$prefix}{$type});
22883: }
22884: } elsif ($prefix eq 'replication') {
22885: if (@locations > 0) {
22886: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
22887: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
22888: my @okvals;
22889: foreach my $val (@vals) {
22890: if ($val =~ /:/) {
22891: my @items = split(/:/,$val);
22892: foreach my $item (@items) {
22893: if (ref($by_location{$item}) eq 'ARRAY') {
22894: push(@okvals,$item);
22895: }
22896: }
22897: } else {
22898: if (ref($by_location{$val}) eq 'ARRAY') {
22899: push(@okvals,$val);
22900: }
22901: }
22902: }
22903: @okvals = sort(@okvals);
22904: if (ref($domconfig{$action}) eq 'HASH') {
22905: if (ref($domconfig{$action}{$prefix}) eq 'HASH') {
22906: if (ref($domconfig{$action}{$prefix}{$type}) eq 'ARRAY') {
22907: if ($inuse == 0) {
22908: $changes{$prefix}{$type} = 1;
22909: } else {
22910: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22911: my @changed = &Apache::loncommon::compare_arrays($domconfig{$action}{$prefix}{$type},$defaultshash{$action}{$prefix}{$type});
22912: if (@changed > 0) {
22913: $changes{$prefix}{$type} = 1;
22914: }
22915: }
22916: } else {
22917: if ($inuse == 1) {
22918: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22919: $changes{$prefix}{$type} = 1;
22920: }
22921: }
22922: } else {
22923: if ($inuse == 1) {
22924: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22925: $changes{$prefix}{$type} = 1;
22926: }
22927: }
22928: } else {
22929: if ($inuse == 1) {
22930: $defaultshash{$action}{$prefix}{$type} = \@okvals;
22931: $changes{$prefix}{$type} = 1;
22932: }
22933: }
22934: }
22935: }
22936: }
22937: }
1.336 raeburn 22938: if (keys(%changes)) {
22939: foreach my $prefix (keys(%changes)) {
22940: if (ref($changes{$prefix}) eq 'HASH') {
22941: if (scalar(keys(%{$changes{$prefix}})) == 0) {
22942: delete($changes{$prefix});
22943: }
22944: } else {
22945: delete($changes{$prefix});
22946: }
22947: }
22948: }
1.275 raeburn 22949: my $nochgmsg = &mt('No changes made to LON-CAPA SSL settings');
22950: if (keys(%changes) > 0) {
22951: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
22952: $dom);
22953: if ($putresult eq 'ok') {
22954: if (ref($defaultshash{$action}) eq 'HASH') {
22955: if (ref($defaultshash{$action}{'replication'}) eq 'HASH') {
22956: $domdefaults{'replication'} = $defaultshash{$action}{'replication'};
22957: }
1.293 raeburn 22958: if (ref($defaultshash{$action}{'connto'}) eq 'HASH') {
1.335 raeburn 22959: $domdefaults{'connto'} = $defaultshash{$action}{'connto'};
1.293 raeburn 22960: }
22961: if (ref($defaultshash{$action}{'connfrom'}) eq 'HASH') {
1.335 raeburn 22962: $domdefaults{'connfrom'} = $defaultshash{$action}{'connfrom'};
1.275 raeburn 22963: }
22964: }
22965: my $cachetime = 24*60*60;
22966: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
22967: if (ref($lastactref) eq 'HASH') {
22968: $lastactref->{'domdefaults'} = 1;
22969: }
22970: if (keys(%changes) > 0) {
22971: my %titles = &ssl_titles();
22972: $resulttext = &mt('Changes made:').'<ul>';
22973: foreach my $prefix (@prefixes) {
22974: if (ref($changes{$prefix}) eq 'HASH') {
22975: $resulttext .= '<li>'.$titles{$prefix}.'<ul>';
22976: foreach my $type (@{$types{$prefix}}) {
22977: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 22978: my ($newvalue,$notinuse);
1.275 raeburn 22979: if (ref($defaultshash{$action}) eq 'HASH') {
22980: if (ref($defaultshash{$action}{$prefix})) {
1.293 raeburn 22981: if (($prefix eq 'connto') || ($prefix eq 'connfrom')) {
1.275 raeburn 22982: $newvalue = $titles{$defaultshash{$action}{$prefix}{$type}};
1.344 raeburn 22983: } else {
22984: if (ref($defaultshash{$action}{$prefix}{$type}) eq 'ARRAY') {
22985: if (@{$defaultshash{$action}{$prefix}{$type}} > 0) {
22986: $newvalue = join(', ',@{$defaultshash{$action}{$prefix}{$type}});
22987: }
22988: } else {
22989: $notinuse = 1;
1.275 raeburn 22990: }
22991: }
22992: }
1.344 raeburn 22993: if ($notinuse) {
22994: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$titles{$type}).'</li>';
22995: } elsif ($newvalue eq '') {
1.275 raeburn 22996: $resulttext .= '<li>'.&mt('[_1] set to: none',$titles{$type}).'</li>';
22997: } else {
22998: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$titles{$type},$newvalue).'</li>';
22999: }
23000: }
23001: }
23002: }
23003: $resulttext .= '</ul>';
23004: }
23005: }
23006: } else {
23007: $resulttext = $nochgmsg;
23008: }
23009: } else {
23010: $resulttext = '<span class="LC_error">'.
23011: &mt('An error occurred: [_1]',$putresult).'</span>';
23012: }
23013: } else {
23014: $resulttext = $nochgmsg;
23015: }
23016: return $resulttext;
23017: }
23018:
1.279 raeburn 23019: sub modify_trust {
23020: my ($dom,$lastactref,%domconfig) = @_;
23021: my (%by_ip,%by_location,@intdoms,@instdoms);
23022: &build_location_hashes(\@intdoms,\%by_ip,\%by_location,\@instdoms);
23023: my @locations = sort(keys(%by_location));
23024: my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
23025: my @types = ('exc','inc');
23026: my (%defaultshash,%changes);
23027: foreach my $prefix (@prefixes) {
23028: $defaultshash{'trust'}{$prefix} = {};
23029: }
23030: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
23031: my $resulttext;
23032: foreach my $prefix (@prefixes) {
23033: foreach my $type (@types) {
23034: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
23035: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
23036: my @okvals;
23037: foreach my $val (@vals) {
23038: if ($val =~ /:/) {
23039: my @items = split(/:/,$val);
23040: foreach my $item (@items) {
23041: if (ref($by_location{$item}) eq 'ARRAY') {
23042: push(@okvals,$item);
23043: }
23044: }
23045: } else {
23046: if (ref($by_location{$val}) eq 'ARRAY') {
23047: push(@okvals,$val);
23048: }
23049: }
23050: }
23051: @okvals = sort(@okvals);
23052: if (ref($domconfig{'trust'}) eq 'HASH') {
23053: if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
23054: if (ref($domconfig{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23055: if ($inuse == 0) {
23056: $changes{$prefix}{$type} = 1;
23057: } else {
23058: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23059: my @changed = &Apache::loncommon::compare_arrays($domconfig{'trust'}{$prefix}{$type},$defaultshash{'trust'}{$prefix}{$type});
23060: if (@changed > 0) {
23061: $changes{$prefix}{$type} = 1;
23062: }
23063: }
23064: } else {
23065: if ($inuse == 1) {
23066: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23067: $changes{$prefix}{$type} = 1;
23068: }
23069: }
23070: } else {
23071: if ($inuse == 1) {
23072: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23073: $changes{$prefix}{$type} = 1;
23074: }
23075: }
23076: } else {
23077: if ($inuse == 1) {
23078: $defaultshash{'trust'}{$prefix}{$type} = \@okvals;
23079: $changes{$prefix}{$type} = 1;
23080: }
23081: }
23082: }
23083: }
23084: my $nochgmsg = &mt('No changes made to trust settings.');
23085: if (keys(%changes) > 0) {
23086: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
23087: $dom);
23088: if ($putresult eq 'ok') {
23089: if (ref($defaultshash{'trust'}) eq 'HASH') {
23090: foreach my $prefix (@prefixes) {
23091: if (ref($defaultshash{'trust'}{$prefix}) eq 'HASH') {
23092: $domdefaults{'trust'.$prefix} = $defaultshash{'trust'}{$prefix};
23093: }
23094: }
23095: }
23096: my $cachetime = 24*60*60;
23097: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.410 raeburn 23098: &Apache::lonnet::do_cache_new('trust',$dom,$defaultshash{'trust'},3600);
1.279 raeburn 23099: if (ref($lastactref) eq 'HASH') {
23100: $lastactref->{'domdefaults'} = 1;
1.410 raeburn 23101: $lastactref->{'trust'} = 1;
1.279 raeburn 23102: }
23103: if (keys(%changes) > 0) {
23104: my %lt = &trust_titles();
23105: $resulttext = &mt('Changes made:').'<ul>';
23106: foreach my $prefix (@prefixes) {
23107: if (ref($changes{$prefix}) eq 'HASH') {
23108: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
23109: foreach my $type (@types) {
23110: if (defined($changes{$prefix}{$type})) {
1.344 raeburn 23111: my ($newvalue,$notinuse);
1.279 raeburn 23112: if (ref($defaultshash{'trust'}) eq 'HASH') {
23113: if (ref($defaultshash{'trust'}{$prefix})) {
23114: if (ref($defaultshash{'trust'}{$prefix}{$type}) eq 'ARRAY') {
23115: if (@{$defaultshash{'trust'}{$prefix}{$type}} > 0) {
23116: $newvalue = join(', ',@{$defaultshash{'trust'}{$prefix}{$type}});
23117: }
1.344 raeburn 23118: } else {
23119: $notinuse = 1;
1.279 raeburn 23120: }
23121: }
23122: }
1.344 raeburn 23123: if ($notinuse) {
23124: $resulttext .= '<li>'.&mt('[_1] set to: not in use',$lt{$type}).'</li>';
23125: } elsif ($newvalue eq '') {
1.279 raeburn 23126: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
23127: } else {
23128: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
23129: }
23130: }
23131: }
23132: $resulttext .= '</ul>';
23133: }
23134: }
23135: $resulttext .= '</ul>';
23136: } else {
23137: $resulttext = $nochgmsg;
23138: }
23139: } else {
23140: $resulttext = '<span class="LC_error">'.
23141: &mt('An error occurred: [_1]',$putresult).'</span>';
23142: }
23143: } else {
23144: $resulttext = $nochgmsg;
23145: }
23146: return $resulttext;
23147: }
23148:
1.150 raeburn 23149: sub modify_loadbalancing {
23150: my ($dom,%domconfig) = @_;
23151: my $primary_id = &Apache::lonnet::domain($dom,'primary');
23152: my $intdom = &Apache::lonnet::internet_dom($primary_id);
23153: my ($othertitle,$usertypes,$types) =
23154: &Apache::loncommon::sorted_inst_types($dom);
23155: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.253 raeburn 23156: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 23157: my @sparestypes = ('primary','default');
23158: my %typetitles = &sparestype_titles();
23159: my $resulttext;
1.342 raeburn 23160: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23161: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23162: %existing = %{$domconfig{'loadbalancing'}};
23163: }
23164: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.342 raeburn 23165: \%currtargets,\%currrules,\%currcookies);
1.171 raeburn 23166: my ($saveloadbalancing,%defaultshash,%changes);
23167: my ($alltypes,$othertypes,$titles) =
23168: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
23169: my %ruletitles = &offloadtype_text();
23170: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
23171: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
23172: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
23173: if ($balancer eq '') {
23174: next;
23175: }
1.210 raeburn 23176: if (!exists($servers{$balancer})) {
1.171 raeburn 23177: if (exists($currbalancer{$balancer})) {
23178: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 23179: }
1.171 raeburn 23180: next;
23181: }
23182: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
23183: push(@{$changes{'delete'}},$balancer);
23184: next;
23185: }
23186: if (!exists($currbalancer{$balancer})) {
23187: push(@{$changes{'add'}},$balancer);
23188: }
23189: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
23190: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
23191: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
23192: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
23193: $saveloadbalancing = 1;
23194: }
23195: foreach my $sparetype (@sparestypes) {
23196: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
23197: my @offloadto;
23198: foreach my $target (@targets) {
23199: if (($servers{$target}) && ($target ne $balancer)) {
23200: if ($sparetype eq 'default') {
23201: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
23202: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 23203: }
23204: }
1.171 raeburn 23205: unless(grep(/^\Q$target\E$/,@offloadto)) {
23206: push(@offloadto,$target);
23207: }
1.150 raeburn 23208: }
23209: }
1.284 raeburn 23210: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
23211: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
23212: push(@offloadto,$balancer);
23213: }
23214: }
23215: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 23216: }
1.342 raeburn 23217: if ($env{'form.loadbalancing_cookie_'.$i}) {
23218: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
1.425 raeburn 23219: if (exists($currbalancer{$balancer})) {
1.342 raeburn 23220: unless ($currcookies{$balancer}) {
23221: $changes{'curr'}{$balancer}{'cookie'} = 1;
23222: }
23223: }
23224: } elsif (exists($currbalancer{$balancer})) {
23225: if ($currcookies{$balancer}) {
23226: $changes{'curr'}{$balancer}{'cookie'} = 1;
23227: }
23228: }
1.171 raeburn 23229: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 23230: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23231: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
23232: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 23233: if (@targetdiffs > 0) {
1.171 raeburn 23234: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23235: }
1.171 raeburn 23236: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23237: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23238: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 23239: }
23240: }
23241: }
23242: } else {
1.171 raeburn 23243: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 23244: foreach my $sparetype (@sparestypes) {
1.171 raeburn 23245: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23246: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23247: $changes{'curr'}{$balancer}{'targets'} = 1;
23248: }
1.150 raeburn 23249: }
23250: }
1.210 raeburn 23251: }
1.150 raeburn 23252: }
23253: my $ishomedom;
1.171 raeburn 23254: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
23255: $ishomedom = 1;
1.150 raeburn 23256: }
23257: if (ref($alltypes) eq 'ARRAY') {
23258: foreach my $type (@{$alltypes}) {
23259: my $rule;
1.210 raeburn 23260: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 23261: (!$ishomedom)) {
1.171 raeburn 23262: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
23263: }
23264: if ($rule eq 'specific') {
1.255 raeburn 23265: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.289 raeburn 23266: if (exists($servers{$specifiedhost})) {
1.255 raeburn 23267: $rule = $specifiedhost;
23268: }
1.150 raeburn 23269: }
1.171 raeburn 23270: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
23271: if (ref($currrules{$balancer}) eq 'HASH') {
23272: if ($rule ne $currrules{$balancer}{$type}) {
23273: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23274: }
23275: } elsif ($rule ne '') {
1.171 raeburn 23276: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 23277: }
23278: }
23279: }
1.171 raeburn 23280: }
23281: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
23282: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
23283: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
23284: $defaultshash{'loadbalancing'} = {};
23285: }
23286: my $putresult = &Apache::lonnet::put_dom('configuration',
23287: \%defaultshash,$dom);
23288: if ($putresult eq 'ok') {
23289: if (keys(%changes) > 0) {
1.252 raeburn 23290: my %toupdate;
1.171 raeburn 23291: if (ref($changes{'delete'}) eq 'ARRAY') {
23292: foreach my $balancer (sort(@{$changes{'delete'}})) {
23293: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.252 raeburn 23294: $toupdate{$balancer} = 1;
1.150 raeburn 23295: }
1.171 raeburn 23296: }
23297: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 23298: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 23299: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.252 raeburn 23300: $toupdate{$balancer} = 1;
1.171 raeburn 23301: }
23302: }
23303: if (ref($changes{'curr'}) eq 'HASH') {
23304: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.253 raeburn 23305: $toupdate{$balancer} = 1;
1.171 raeburn 23306: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
23307: if ($changes{'curr'}{$balancer}{'targets'}) {
23308: my %offloadstr;
23309: foreach my $sparetype (@sparestypes) {
23310: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23311: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
23312: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23313: }
23314: }
1.150 raeburn 23315: }
1.171 raeburn 23316: if (keys(%offloadstr) == 0) {
23317: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 23318: } else {
1.171 raeburn 23319: my $showoffload;
23320: foreach my $sparetype (@sparestypes) {
23321: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
23322: if (defined($offloadstr{$sparetype})) {
23323: $showoffload .= $offloadstr{$sparetype};
23324: } else {
23325: $showoffload .= &mt('None');
23326: }
23327: $showoffload .= (' 'x3);
23328: }
23329: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 23330: }
23331: }
23332: }
1.171 raeburn 23333: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
23334: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
23335: foreach my $type (@{$alltypes}) {
23336: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
23337: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23338: my $balancetext;
23339: if ($rule eq '') {
23340: $balancetext = $ruletitles{'default'};
1.209 raeburn 23341: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.289 raeburn 23342: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.254 raeburn 23343: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.252 raeburn 23344: foreach my $sparetype (@sparestypes) {
23345: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
23346: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
23347: }
23348: }
1.253 raeburn 23349: foreach my $item (@{$alltypes}) {
23350: next if ($item =~ /^_LC_ipchange/);
23351: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
23352: if ($hasrule eq 'homeserver') {
23353: map { $toupdate{$_} = 1; } (keys(%libraryservers));
23354: } else {
23355: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
23356: if ($servers{$hasrule}) {
23357: $toupdate{$hasrule} = 1;
23358: }
23359: }
23360: }
23361: }
1.254 raeburn 23362: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
23363: $balancetext = $ruletitles{$rule};
23364: } else {
23365: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
23366: $balancetext = $ruletitles{'particular'}.' '.$receiver;
23367: if ($receiver) {
23368: $toupdate{$receiver};
23369: }
23370: }
23371: } else {
23372: $balancetext = $ruletitles{$rule};
1.252 raeburn 23373: }
1.171 raeburn 23374: } else {
23375: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
23376: }
1.210 raeburn 23377: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 23378: }
23379: }
23380: }
23381: }
1.342 raeburn 23382: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.389 raeburn 23383: if ($currcookies{$balancer}) {
23384: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
23385: $balancer).'</li>';
23386: } else {
23387: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
23388: $balancer).'</li>';
23389: }
1.342 raeburn 23390: }
1.375 raeburn 23391: }
23392: }
23393: if (keys(%toupdate)) {
23394: my %thismachine;
23395: my $updatedhere;
23396: my $cachetime = 60*60*24;
23397: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
23398: foreach my $lonhost (keys(%toupdate)) {
23399: if ($thismachine{$lonhost}) {
23400: unless ($updatedhere) {
23401: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
23402: $defaultshash{'loadbalancing'},
23403: $cachetime);
23404: $updatedhere = 1;
1.252 raeburn 23405: }
1.375 raeburn 23406: } else {
23407: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
23408: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.252 raeburn 23409: }
1.150 raeburn 23410: }
1.171 raeburn 23411: }
23412: if ($resulttext ne '') {
23413: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 23414: } else {
23415: $resulttext = $nochgmsg;
23416: }
23417: } else {
1.171 raeburn 23418: $resulttext = $nochgmsg;
1.150 raeburn 23419: }
23420: } else {
1.171 raeburn 23421: $resulttext = '<span class="LC_error">'.
23422: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 23423: }
23424: } else {
1.171 raeburn 23425: $resulttext = $nochgmsg;
1.150 raeburn 23426: }
23427: return $resulttext;
23428: }
23429:
1.48 raeburn 23430: sub recurse_check {
23431: my ($chkcats,$categories,$depth,$name) = @_;
23432: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
23433: my $chg = 0;
23434: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
23435: my $category = $chkcats->[$depth]{$name}[$j];
23436: my $item;
23437: if ($category eq '') {
23438: $chg ++;
23439: } else {
23440: my $deeper = $depth + 1;
23441: $item = &escape($category).':'.&escape($name).':'.$depth;
23442: if ($chg) {
23443: $categories->{$item} -= $chg;
23444: }
23445: &recurse_check($chkcats,$categories,$deeper,$category);
23446: $deeper --;
23447: }
23448: }
23449: }
23450: return;
23451: }
23452:
23453: sub recurse_cat_deletes {
23454: my ($item,$coursecategories,$deletions) = @_;
23455: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
23456: my $subdepth = $depth + 1;
23457: if (ref($coursecategories) eq 'HASH') {
23458: foreach my $subitem (keys(%{$coursecategories})) {
23459: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
23460: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
23461: delete($coursecategories->{$subitem});
23462: $deletions->{$subitem} = 1;
23463: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 23464: }
1.48 raeburn 23465: }
23466: }
23467: return;
23468: }
23469:
1.125 raeburn 23470: sub active_dc_picker {
1.191 raeburn 23471: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.287 raeburn 23472: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.191 raeburn 23473: my @domcoord = keys(%domcoords);
23474: if (keys(%currhash)) {
23475: foreach my $dc (keys(%currhash)) {
23476: unless (exists($domcoords{$dc})) {
23477: push(@domcoord,$dc);
23478: }
23479: }
23480: }
23481: @domcoord = sort(@domcoord);
1.210 raeburn 23482: my $numdcs = scalar(@domcoord);
1.191 raeburn 23483: my $rows = 0;
23484: my $table;
1.125 raeburn 23485: if ($numdcs > 1) {
1.191 raeburn 23486: $table = '<table>';
23487: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 23488: my $rem = $i%($numinrow);
23489: if ($rem == 0) {
23490: if ($i > 0) {
1.191 raeburn 23491: $table .= '</tr>';
1.125 raeburn 23492: }
1.191 raeburn 23493: $table .= '<tr>';
23494: $rows ++;
1.125 raeburn 23495: }
1.191 raeburn 23496: my $check = '';
23497: if ($inputtype eq 'radio') {
23498: if (keys(%currhash) == 0) {
23499: if (!$i) {
23500: $check = ' checked="checked"';
23501: }
23502: } elsif (exists($currhash{$domcoord[$i]})) {
23503: $check = ' checked="checked"';
23504: }
23505: } else {
23506: if (exists($currhash{$domcoord[$i]})) {
23507: $check = ' checked="checked"';
1.125 raeburn 23508: }
23509: }
1.191 raeburn 23510: if ($i == @domcoord - 1) {
1.125 raeburn 23511: my $colsleft = $numinrow - $rem;
23512: if ($colsleft > 1) {
1.191 raeburn 23513: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 23514: } else {
1.191 raeburn 23515: $table .= '<td class="LC_left_item">';
1.125 raeburn 23516: }
23517: } else {
1.191 raeburn 23518: $table .= '<td class="LC_left_item">';
23519: }
23520: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
23521: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
23522: $table .= '<span class="LC_nobreak"><label>'.
23523: '<input type="'.$inputtype.'" name="'.$name.'"'.
23524: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
23525: if ($user ne $dcname.':'.$dcdom) {
1.219 raeburn 23526: $table .= ' ('.$dcname.':'.$dcdom.')';
1.191 raeburn 23527: }
1.219 raeburn 23528: $table .= '</label></span></td>';
1.191 raeburn 23529: }
23530: $table .= '</tr></table>';
23531: } elsif ($numdcs == 1) {
1.219 raeburn 23532: my ($dcname,$dcdom) = split(':',$domcoord[0]);
23533: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.191 raeburn 23534: if ($inputtype eq 'radio') {
1.247 raeburn 23535: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.219 raeburn 23536: if ($user ne $dcname.':'.$dcdom) {
23537: $table .= ' ('.$dcname.':'.$dcdom.')';
23538: }
1.191 raeburn 23539: } else {
23540: my $check;
23541: if (exists($currhash{$domcoord[0]})) {
23542: $check = ' checked="checked"';
1.125 raeburn 23543: }
1.247 raeburn 23544: $table = '<span class="LC_nobreak"><label>'.
23545: '<input type="checkbox" name="'.$name.'" '.
23546: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.219 raeburn 23547: if ($user ne $dcname.':'.$dcdom) {
1.220 raeburn 23548: $table .= ' ('.$dcname.':'.$dcdom.')';
1.219 raeburn 23549: }
1.220 raeburn 23550: $table .= '</label></span>';
1.191 raeburn 23551: $rows ++;
1.125 raeburn 23552: }
23553: }
1.191 raeburn 23554: return ($numdcs,$table,$rows);
1.125 raeburn 23555: }
23556:
1.137 raeburn 23557: sub usersession_titles {
23558: return &Apache::lonlocal::texthash(
23559: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
23560: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 23561: spares => 'Servers offloaded to, when busy',
1.137 raeburn 23562: version => 'LON-CAPA version requirement',
1.138 raeburn 23563: excludedomain => 'Allow all, but exclude specific domains',
23564: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 23565: primary => 'Primary (checked first)',
1.154 raeburn 23566: default => 'Default',
1.137 raeburn 23567: );
23568: }
23569:
1.152 raeburn 23570: sub id_for_thisdom {
23571: my (%servers) = @_;
23572: my %altids;
23573: foreach my $server (keys(%servers)) {
23574: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
23575: if ($serverhome ne $server) {
23576: $altids{$serverhome} = $server;
23577: }
23578: }
23579: return %altids;
23580: }
23581:
1.150 raeburn 23582: sub count_servers {
23583: my ($currbalancer,%servers) = @_;
23584: my (@spares,$numspares);
23585: foreach my $lonhost (sort(keys(%servers))) {
23586: next if ($currbalancer eq $lonhost);
23587: push(@spares,$lonhost);
23588: }
23589: if ($currbalancer) {
23590: $numspares = scalar(@spares);
23591: } else {
23592: $numspares = scalar(@spares) - 1;
23593: }
23594: return ($numspares,@spares);
23595: }
23596:
23597: sub lonbalance_targets_js {
1.171 raeburn 23598: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 23599: my $select = &mt('Select');
23600: my ($alltargets,$allishome,$allinsttypes,@alltypes);
23601: if (ref($servers) eq 'HASH') {
23602: $alltargets = join("','",sort(keys(%{$servers})));
23603: my @homedoms;
23604: foreach my $server (sort(keys(%{$servers}))) {
23605: if (&Apache::lonnet::host_domain($server) eq $dom) {
23606: push(@homedoms,'1');
23607: } else {
23608: push(@homedoms,'0');
23609: }
23610: }
23611: $allishome = join("','",@homedoms);
23612: }
23613: if (ref($types) eq 'ARRAY') {
23614: if (@{$types} > 0) {
23615: @alltypes = @{$types};
23616: }
23617: }
23618: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
23619: $allinsttypes = join("','",@alltypes);
1.342 raeburn 23620: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.171 raeburn 23621: if (ref($settings) eq 'HASH') {
23622: %existing = %{$settings};
23623: }
23624: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.342 raeburn 23625: \%currtargets,\%currrules,\%currcookies);
1.210 raeburn 23626: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 23627: return <<"END";
23628:
23629: <script type="text/javascript">
23630: // <![CDATA[
23631:
1.171 raeburn 23632: currBalancers = new Array('$balancers');
23633:
23634: function toggleTargets(balnum) {
23635: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23636: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
23637: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
23638: var prevbalancer = prevhostitem.value;
23639: var baltotal = document.getElementById('loadbalancing_total').value;
23640: prevhostitem.value = balancer;
23641: if (prevbalancer != '') {
23642: var prevIdx = currBalancers.indexOf(prevbalancer);
23643: if (prevIdx != -1) {
23644: currBalancers.splice(prevIdx,1);
23645: }
23646: }
1.150 raeburn 23647: if (balancer == '') {
1.171 raeburn 23648: hideSpares(balnum);
1.150 raeburn 23649: } else {
1.171 raeburn 23650: var currIdx = currBalancers.indexOf(balancer);
23651: if (currIdx == -1) {
23652: currBalancers.push(balancer);
23653: }
1.150 raeburn 23654: var homedoms = new Array('$allishome');
1.171 raeburn 23655: var ishomedom = homedoms[lonhostitem.selectedIndex];
23656: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 23657: }
1.171 raeburn 23658: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 23659: return;
23660: }
23661:
1.171 raeburn 23662: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 23663: var alltargets = new Array('$alltargets');
23664: var insttypes = new Array('$allinsttypes');
1.151 raeburn 23665: var offloadtypes = new Array('primary','default');
23666:
1.171 raeburn 23667: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
23668: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 23669:
1.151 raeburn 23670: for (var i=0; i<offloadtypes.length; i++) {
23671: var count = 0;
23672: for (var j=0; j<alltargets.length; j++) {
23673: if (alltargets[j] != balancer) {
1.171 raeburn 23674: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
23675: item.value = alltargets[j];
23676: item.style.textAlign='left';
23677: item.style.textFace='normal';
23678: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
23679: if (currBalancers.indexOf(alltargets[j]) == -1) {
23680: item.disabled = '';
23681: } else {
23682: item.disabled = 'disabled';
23683: item.checked = false;
23684: }
1.151 raeburn 23685: count ++;
23686: }
1.150 raeburn 23687: }
23688: }
1.151 raeburn 23689: for (var k=0; k<insttypes.length; k++) {
23690: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 23691: if (ishomedom == 1) {
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: } else {
1.171 raeburn 23695: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23696: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 23697: }
23698: } else {
1.171 raeburn 23699: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
23700: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 23701: }
1.151 raeburn 23702: if ((insttypes[k] != '_LC_external') &&
23703: ((insttypes[k] != '_LC_internetdom') ||
23704: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 23705: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
23706: item.options.length = 0;
23707: item.options[0] = new Option("","",true,true);
1.210 raeburn 23708: var idx = 0;
1.151 raeburn 23709: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 23710: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
23711: idx ++;
23712: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 23713: }
23714: }
23715: }
23716: }
23717: return;
23718: }
23719:
1.171 raeburn 23720: function hideSpares(balnum) {
1.150 raeburn 23721: var alltargets = new Array('$alltargets');
23722: var insttypes = new Array('$allinsttypes');
23723: var offloadtypes = new Array('primary','default');
23724:
1.171 raeburn 23725: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
23726: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 23727:
23728: var total = alltargets.length - 1;
23729: for (var i=0; i<offloadtypes; i++) {
23730: for (var j=0; j<total; j++) {
1.171 raeburn 23731: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
23732: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
23733: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 23734: }
1.150 raeburn 23735: }
23736: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 23737: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
23738: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 23739: if (insttypes[k] != '_LC_external') {
1.171 raeburn 23740: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
23741: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 23742: }
23743: }
23744: return;
23745: }
23746:
1.171 raeburn 23747: function checkOffloads(item,balnum,type) {
1.150 raeburn 23748: var alltargets = new Array('$alltargets');
23749: var offloadtypes = new Array('primary','default');
23750: if (item.checked) {
23751: var total = alltargets.length - 1;
23752: var other;
23753: if (type == offloadtypes[0]) {
1.151 raeburn 23754: other = offloadtypes[1];
1.150 raeburn 23755: } else {
1.151 raeburn 23756: other = offloadtypes[0];
1.150 raeburn 23757: }
23758: for (var i=0; i<total; i++) {
1.171 raeburn 23759: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 23760: if (server == item.value) {
1.171 raeburn 23761: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
23762: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 23763: }
23764: }
23765: }
23766: }
23767: return;
23768: }
23769:
1.171 raeburn 23770: function singleServerToggle(balnum,type) {
23771: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 23772: if (offloadtoSelIdx == 0) {
1.171 raeburn 23773: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
23774: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23775:
23776: } else {
1.171 raeburn 23777: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
23778: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 23779: }
23780: return;
23781: }
23782:
1.171 raeburn 23783: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 23784: if (type == '_LC_external') {
1.171 raeburn 23785: return;
1.150 raeburn 23786: }
1.171 raeburn 23787: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 23788: for (var i=0; i<typesRules.length; i++) {
23789: if (formname.elements[typesRules[i]].checked) {
23790: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 23791: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
23792: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 23793: } else {
1.171 raeburn 23794: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
23795: }
23796: }
23797: }
23798: return;
23799: }
23800:
23801: function balancerDeleteChange(balnum) {
23802: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
23803: var baltotal = document.getElementById('loadbalancing_total').value;
23804: var addtarget;
23805: var removetarget;
23806: var action = 'delete';
23807: if (document.getElementById('loadbalancing_delete_'+balnum)) {
23808: var lonhost = hostitem.value;
23809: var currIdx = currBalancers.indexOf(lonhost);
23810: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
23811: if (currIdx != -1) {
23812: currBalancers.splice(currIdx,1);
23813: }
23814: addtarget = lonhost;
23815: } else {
23816: if (currIdx == -1) {
23817: currBalancers.push(lonhost);
23818: }
23819: removetarget = lonhost;
23820: action = 'undelete';
23821: }
23822: balancerChange(balnum,baltotal,action,addtarget,removetarget);
23823: }
23824: return;
23825: }
23826:
23827: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
23828: if (baltotal > 1) {
23829: var offloadtypes = new Array('primary','default');
23830: var alltargets = new Array('$alltargets');
23831: var insttypes = new Array('$allinsttypes');
23832: for (var i=0; i<baltotal; i++) {
23833: if (i != balnum) {
23834: for (var j=0; j<offloadtypes.length; j++) {
23835: var total = alltargets.length - 1;
23836: for (var k=0; k<total; k++) {
23837: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
23838: var server = serveritem.value;
23839: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23840: if (server == addtarget) {
23841: serveritem.disabled = '';
23842: }
23843: }
23844: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23845: if (server == removetarget) {
23846: serveritem.disabled = 'disabled';
23847: serveritem.checked = false;
23848: }
23849: }
23850: }
23851: }
23852: for (var j=0; j<insttypes.length; j++) {
23853: if (insttypes[j] != '_LC_external') {
23854: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
23855: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
23856: var currSel = singleserver.selectedIndex;
23857: var currVal = singleserver.options[currSel].value;
23858: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
23859: var numoptions = singleserver.options.length;
23860: var needsnew = 1;
23861: for (var k=0; k<numoptions; k++) {
23862: if (singleserver.options[k] == addtarget) {
23863: needsnew = 0;
23864: break;
23865: }
23866: }
23867: if (needsnew == 1) {
23868: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
23869: }
23870: }
23871: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
23872: singleserver.options.length = 0;
23873: if ((currVal) && (currVal != removetarget)) {
23874: singleserver.options[0] = new Option("","",false,false);
23875: } else {
23876: singleserver.options[0] = new Option("","",true,true);
23877: }
23878: var idx = 0;
23879: for (var m=0; m<alltargets.length; m++) {
23880: if (currBalancers.indexOf(alltargets[m]) == -1) {
23881: idx ++;
23882: if (currVal == alltargets[m]) {
23883: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
23884: } else {
23885: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
23886: }
23887: }
23888: }
23889: }
23890: }
23891: }
23892: }
1.150 raeburn 23893: }
23894: }
23895: }
23896: return;
23897: }
23898:
1.152 raeburn 23899: // ]]>
23900: </script>
23901:
23902: END
23903: }
23904:
23905: sub new_spares_js {
23906: my @sparestypes = ('primary','default');
23907: my $types = join("','",@sparestypes);
23908: my $select = &mt('Select');
23909: return <<"END";
23910:
23911: <script type="text/javascript">
23912: // <![CDATA[
23913:
23914: function updateNewSpares(formname,lonhost) {
23915: var types = new Array('$types');
23916: var include = new Array();
23917: var exclude = new Array();
23918: for (var i=0; i<types.length; i++) {
23919: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
23920: for (var j=0; j<spareboxes.length; j++) {
23921: if (formname.elements[spareboxes[j]].checked) {
23922: exclude.push(formname.elements[spareboxes[j]].value);
23923: } else {
23924: include.push(formname.elements[spareboxes[j]].value);
23925: }
23926: }
23927: }
23928: for (var i=0; i<types.length; i++) {
23929: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
23930: var selIdx = newSpare.selectedIndex;
23931: var currnew = newSpare.options[selIdx].value;
23932: var okSpares = new Array();
23933: for (var j=0; j<newSpare.options.length; j++) {
23934: var possible = newSpare.options[j].value;
23935: if (possible != '') {
23936: if (exclude.indexOf(possible) == -1) {
23937: okSpares.push(possible);
23938: } else {
23939: if (currnew == possible) {
23940: selIdx = 0;
23941: }
23942: }
23943: }
23944: }
23945: for (var k=0; k<include.length; k++) {
23946: if (okSpares.indexOf(include[k]) == -1) {
23947: okSpares.push(include[k]);
23948: }
23949: }
23950: okSpares.sort();
23951: newSpare.options.length = 0;
23952: if (selIdx == 0) {
23953: newSpare.options[0] = new Option("$select","",true,true);
23954: } else {
23955: newSpare.options[0] = new Option("$select","",false,false);
23956: }
23957: for (var m=0; m<okSpares.length; m++) {
23958: var idx = m+1;
23959: var selThis = 0;
23960: if (selIdx != 0) {
23961: if (okSpares[m] == currnew) {
23962: selThis = 1;
23963: }
23964: }
23965: if (selThis == 1) {
23966: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
23967: } else {
23968: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
23969: }
23970: }
23971: }
23972: return;
23973: }
23974:
23975: function checkNewSpares(lonhost,type) {
23976: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
23977: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.372 raeburn 23978: if (chosen != '') {
1.152 raeburn 23979: var othertype;
23980: var othernewSpare;
23981: if (type == 'primary') {
23982: othernewSpare = document.getElementById('newspare_default_'+lonhost);
23983: }
23984: if (type == 'default') {
23985: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
23986: }
23987: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
23988: othernewSpare.selectedIndex = 0;
23989: }
23990: }
23991: return;
23992: }
23993:
23994: // ]]>
23995: </script>
23996:
23997: END
23998:
23999: }
24000:
24001: sub common_domprefs_js {
24002: return <<"END";
24003:
24004: <script type="text/javascript">
24005: // <![CDATA[
24006:
1.150 raeburn 24007: function getIndicesByName(formname,item) {
1.152 raeburn 24008: var group = new Array();
1.150 raeburn 24009: for (var i=0;i<formname.elements.length;i++) {
24010: if (formname.elements[i].name == item) {
1.152 raeburn 24011: group.push(formname.elements[i].id);
1.150 raeburn 24012: }
24013: }
1.152 raeburn 24014: return group;
1.150 raeburn 24015: }
24016:
24017: // ]]>
24018: </script>
24019:
24020: END
1.152 raeburn 24021:
1.150 raeburn 24022: }
24023:
1.165 raeburn 24024: sub recaptcha_js {
24025: my %lt = &captcha_phrases();
24026: return <<"END";
24027:
24028: <script type="text/javascript">
24029: // <![CDATA[
24030:
24031: function updateCaptcha(caller,context) {
24032: var privitem;
24033: var pubitem;
24034: var privtext;
24035: var pubtext;
1.269 raeburn 24036: var versionitem;
24037: var versiontext;
1.165 raeburn 24038: if (document.getElementById(context+'_recaptchapub')) {
24039: pubitem = document.getElementById(context+'_recaptchapub');
24040: } else {
24041: return;
24042: }
24043: if (document.getElementById(context+'_recaptchapriv')) {
24044: privitem = document.getElementById(context+'_recaptchapriv');
24045: } else {
24046: return;
24047: }
24048: if (document.getElementById(context+'_recaptchapubtxt')) {
24049: pubtext = document.getElementById(context+'_recaptchapubtxt');
24050: } else {
24051: return;
24052: }
24053: if (document.getElementById(context+'_recaptchaprivtxt')) {
24054: privtext = document.getElementById(context+'_recaptchaprivtxt');
24055: } else {
24056: return;
24057: }
1.269 raeburn 24058: if (document.getElementById(context+'_recaptchaversion')) {
24059: versionitem = document.getElementById(context+'_recaptchaversion');
24060: } else {
24061: return;
24062: }
24063: if (document.getElementById(context+'_recaptchavertxt')) {
24064: versiontext = document.getElementById(context+'_recaptchavertxt');
24065: } else {
24066: return;
24067: }
1.165 raeburn 24068: if (caller.checked) {
24069: if (caller.value == 'recaptcha') {
24070: pubitem.type = 'text';
24071: privitem.type = 'text';
24072: pubitem.size = '40';
24073: privitem.size = '40';
24074: pubtext.innerHTML = "$lt{'pub'}";
24075: privtext.innerHTML = "$lt{'priv'}";
1.269 raeburn 24076: versionitem.type = 'text';
24077: versionitem.size = '3';
1.289 raeburn 24078: versiontext.innerHTML = "$lt{'ver'}";
1.165 raeburn 24079: } else {
24080: pubitem.type = 'hidden';
24081: privitem.type = 'hidden';
1.269 raeburn 24082: versionitem.type = 'hidden';
1.165 raeburn 24083: pubtext.innerHTML = '';
24084: privtext.innerHTML = '';
1.269 raeburn 24085: versiontext.innerHTML = '';
1.165 raeburn 24086: }
24087: }
24088: return;
24089: }
24090:
24091: // ]]>
24092: </script>
24093:
24094: END
24095:
24096: }
24097:
1.236 raeburn 24098: sub toggle_display_js {
1.192 raeburn 24099: return <<"END";
24100:
24101: <script type="text/javascript">
24102: // <![CDATA[
24103:
1.236 raeburn 24104: function toggleDisplay(domForm,caller) {
24105: if (document.getElementById(caller)) {
24106: var divitem = document.getElementById(caller);
24107: var optionsElement = domForm.coursecredits;
1.264 raeburn 24108: var checkval = 1;
24109: var dispval = 'block';
1.303 raeburn 24110: var selfcreateRegExp = /^cancreate_emailverified/;
1.236 raeburn 24111: if (caller == 'emailoptions') {
1.372 raeburn 24112: optionsElement = domForm.cancreate_email;
1.236 raeburn 24113: }
1.257 raeburn 24114: if (caller == 'studentsubmission') {
24115: optionsElement = domForm.postsubmit;
24116: }
1.264 raeburn 24117: if (caller == 'cloneinstcode') {
24118: optionsElement = domForm.canclone;
24119: checkval = 'instcode';
24120: }
1.303 raeburn 24121: if (selfcreateRegExp.test(caller)) {
24122: optionsElement = domForm.elements[caller];
24123: checkval = 'other';
24124: dispval = 'inline'
24125: }
1.236 raeburn 24126: if (optionsElement.length) {
1.192 raeburn 24127: var currval;
1.236 raeburn 24128: for (var i=0; i<optionsElement.length; i++) {
24129: if (optionsElement[i].checked) {
24130: currval = optionsElement[i].value;
1.192 raeburn 24131: }
24132: }
1.264 raeburn 24133: if (currval == checkval) {
24134: divitem.style.display = dispval;
1.192 raeburn 24135: } else {
1.236 raeburn 24136: divitem.style.display = 'none';
1.192 raeburn 24137: }
24138: }
24139: }
24140: return;
24141: }
24142:
24143: // ]]>
24144: </script>
24145:
24146: END
24147:
24148: }
24149:
1.165 raeburn 24150: sub captcha_phrases {
24151: return &Apache::lonlocal::texthash (
24152: priv => 'Private key',
24153: pub => 'Public key',
24154: original => 'original (CAPTCHA)',
24155: recaptcha => 'successor (ReCAPTCHA)',
24156: notused => 'unused',
1.289 raeburn 24157: ver => 'ReCAPTCHA version (1 or 2)',
1.165 raeburn 24158: );
24159: }
24160:
1.205 raeburn 24161: sub devalidate_remote_domconfs {
1.212 raeburn 24162: my ($dom,$cachekeys) = @_;
24163: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 24164: my %servers = &Apache::lonnet::internet_dom_servers($dom);
24165: my %thismachine;
24166: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.355 raeburn 24167: my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.394 raeburn 24168: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
1.410 raeburn 24169: 'ipaccess','trust');
1.386 raeburn 24170: my %cache_by_lonhost;
24171: if (exists($cachekeys->{'samllanding'})) {
24172: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
24173: my %landing = %{$cachekeys->{'samllanding'}};
24174: my %domservers = &Apache::lonnet::get_servers($dom);
24175: if (keys(%domservers)) {
24176: foreach my $server (keys(%domservers)) {
24177: my @cached;
24178: next if ($thismachine{$server});
24179: if ($landing{$server}) {
24180: push(@cached,&escape('samllanding').':'.&escape($server));
24181: }
24182: if (@cached) {
24183: $cache_by_lonhost{$server} = \@cached;
24184: }
24185: }
24186: }
24187: }
24188: }
1.260 raeburn 24189: if (keys(%servers)) {
1.205 raeburn 24190: foreach my $server (keys(%servers)) {
24191: next if ($thismachine{$server});
1.212 raeburn 24192: my @cached;
24193: foreach my $name (@posscached) {
24194: if ($cachekeys->{$name}) {
1.388 raeburn 24195: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
1.386 raeburn 24196: if (ref($cachekeys->{$name}) eq 'HASH') {
1.373 raeburn 24197: foreach my $key (keys(%{$cachekeys->{$name}})) {
24198: push(@cached,&escape($name).':'.&escape($key));
24199: }
24200: }
24201: } else {
24202: push(@cached,&escape($name).':'.&escape($dom));
24203: }
1.212 raeburn 24204: }
24205: }
1.386 raeburn 24206: if ((exists($cache_by_lonhost{$server})) &&
24207: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
24208: push(@cached,@{$cache_by_lonhost{$server}});
24209: }
1.212 raeburn 24210: if (@cached) {
24211: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
24212: }
1.205 raeburn 24213: }
24214: }
24215: return;
24216: }
24217:
1.3 raeburn 24218: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>